예제 #1
0
// Подключение к каналу виртуального пользователя.
void OnVirtualUserChannelConnect(BYTE *InBuffer) {
	String name, channel_name;

	try {
		// virtual user.
		GetStreamString (&InBuffer, &name);
		// channel.
		GetStreamString(&InBuffer, &channel_name);
		// topic.
		GetStreamString(&InBuffer, NULL);
		// greeting.
		GetStreamString(&InBuffer, NULL);

		LogicalConnections::iterator connection = FindConnectionByUser(name);
		OnlineUsersList::iterator user = GetConnectionUser(connection);
		ChannelsList::iterator channel = FindChannelByName(channel_name);
		StringList channel_users;
		if (!IsChannelMonitored(channel_name)) {
			AddChannelWatcher(name, channel_name);
			Channel channel_info = GetChannelInfo(channel_name);
			channel_users = GetChannelUsersList(name, channel_name);
			channel_info.online_users = channel_users.size();
			UpdateChannel(channel, GetChannelInfo(channel_name));
			for (unsigned int i = 0; i < channel_info.online_users; i++) {
				AddUserChannel(name, channel_name);
			}
		} else {
			AddUserChannel(name, channel_name);
			channel_users = GetChannelUsers(channel_name);
        }

		MapList params;
		params.insert(pair<String, String>("channel", channel_name));
		params.insert(pair<String, String>("topic", channel->topic));
		params.insert(pair<String, String>("greeting", channel->greeting));
		params.insert(pair<String, String>("users", "[" + implode(channel_users) + "]"));

		String json_object = SetParametersObject(params, true);
		SendNotification("virtual_user_channel_connect", json_object, connection, false);
	} catch (Exception *E) {
		throw(Format(e_virtual_user_channel_connect, ARRAYOFCONST((E->Message))));
	}
}
예제 #2
0
void CIrcChannelTabCtrl::RemoveChannel( CString sChannel )
{
    Channel* pToDel = FindChannelByName( sChannel );
    if( !pToDel )
        return;
    TCITEM item;
    item.mask = TCIF_PARAM;
    item.lParam = -1;
    int iIndex;
    for(iIndex = 0; iIndex < GetItemCount(); iIndex++)
    {
        GetItem(iIndex,&item);
        if (((Channel*)item.lParam) == pToDel)
            break;
    }
    if (((Channel*)item.lParam) != pToDel)
        return;
    DeleteItem(iIndex);

    if( pToDel == m_pCurrentChannel )
    {
        m_pParent->m_listctrlNickList.DeleteAllItems();
        if( GetItemCount() > 2 && iIndex > 1 )
        {
            if ( iIndex == 2 )
                iIndex++;
            SetCurSel(iIndex-1);
            SetCurFocus(iIndex-1);
            OnTcnSelchangeTab2( NULL, NULL );
        }
        else
        {
            SetCurSel(0);
            SetCurFocus(0);
            OnTcnSelchangeTab2( NULL, NULL );
        }
    }
    m_pParent->m_listctrlNickList.DeleteAllNick(pToDel->m_sName);
    m_ptrlistChannel.RemoveAt(m_ptrlistChannel.Find(pToDel));
    delete pToDel;
}
예제 #3
0
void CIrcChannelTabCtrl::SetActivity( CString sChannel, bool bFlag)
{
    Channel* pRefresh = FindChannelByName( sChannel );
    if( !pRefresh )
    {
        pRefresh = (Channel*)m_ptrlistChannel.GetHead();
        if( !pRefresh )
            return;
    }
    TCITEM item;
    item.mask = TCIF_PARAM;
    item.lParam = -1;
    int iIndex;
    for (iIndex = 0; iIndex < GetItemCount(); iIndex++)
    {
        GetItem(iIndex,&item);
        if (((Channel*)item.lParam) == pRefresh)
            break;
    }
    if (((Channel*)item.lParam) != pRefresh)
        return;
    if( bFlag )
    {
        item.mask = TCIF_IMAGE;
        item.iImage = 2; // 'MessagePending'
        SetItem( iIndex, &item );
        HighlightItem(iIndex, TRUE);
    }
    else
    {
        item.mask = TCIF_IMAGE;
        item.iImage = 1; // 'Message'
        SetItem( iIndex, &item );
        HighlightItem(iIndex, FALSE);
    }
}
예제 #4
0
bool CIrcChannelTabCtrl::ChangeChanMode( CString sChannel, CString sParam, CString sDir, CString sCommand )
{
    //Must have a Command.
    if( sCommand.IsEmpty() )
        return false;

    //Must be a channel!
    if( sChannel.IsEmpty() || sChannel.Left(1) != _T("#") )
        return false;

    //Get Channel.
    Channel* pUpdate = FindChannelByName( sChannel );
    //Make sure we have this channel in our list.
    if( !pUpdate )
        return false;

    //Update modes.
    int iCommandIndex = m_sChannelModeSettingsTypeA.Find(sCommand);
    if( iCommandIndex != -1 )
    {
        //Remove the setting. This takes care of "-" and makes sure we don't add the same symbol twice.
        pUpdate->m_sModesA.Replace(sCommand, _T(""));
        if( sDir == _T("+") )
        {
            //Update mode.
            if( pUpdate->m_sModesA.IsEmpty() )
                pUpdate->m_sModesA = sCommand;
            else
            {
                //The chan does have other modes.. Lets make sure we put things in order..
                int iChannelModeSettingsTypeALength = m_sChannelModeSettingsTypeA.GetLength();
                //This will pad the mode string..
                for( int iIndex = 0; iIndex < iChannelModeSettingsTypeALength; iIndex++)
                {
                    if( pUpdate->m_sModesA.Find(m_sChannelModeSettingsTypeA[iIndex]) == -1 )
                        pUpdate->m_sModesA.Insert(iIndex, _T(" "));
                }
                //Insert the new mode
                pUpdate->m_sModesA.Insert(iCommandIndex, sCommand);
                //Remove pads
                pUpdate->m_sModesA.Remove(_T(' '));
            }
        }
        return true;
    }
    iCommandIndex = m_sChannelModeSettingsTypeB.Find(sCommand);
    if( iCommandIndex != -1 )
    {
        //Remove the setting. This takes care of "-" and makes sure we don't add the same symbol twice.
        pUpdate->m_sModesB.Replace(sCommand, _T(""));
        if( sDir == _T("+") )
        {
            //Update mode.
            if( pUpdate->m_sModesB.IsEmpty() )
                pUpdate->m_sModesB = sCommand;
            else
            {
                //The chan does have other modes.. Lets make sure we put things in order..
                int iChannelModeSettingsTypeBLength = m_sChannelModeSettingsTypeB.GetLength();
                //This will pad the mode string..
                for( int iIndex = 0; iIndex < iChannelModeSettingsTypeBLength; iIndex++)
                {
                    if( pUpdate->m_sModesB.Find(m_sChannelModeSettingsTypeB[iIndex]) == -1 )
                        pUpdate->m_sModesB.Insert(iIndex, _T(" "));
                }
                //Insert the new mode
                pUpdate->m_sModesB.Insert(iCommandIndex, sCommand);
                //Remove pads
                pUpdate->m_sModesB.Remove(_T(' '));
            }
        }
        return true;
    }
    iCommandIndex = m_sChannelModeSettingsTypeC.Find(sCommand);
    if( iCommandIndex != -1 )
    {
        //Remove the setting. This takes care of "-" and makes sure we don't add the same symbol twice.
        pUpdate->m_sModesC.Replace(sCommand, _T(""));
        if( sDir == _T("+") )
        {
            //Update mode.
            if( pUpdate->m_sModesC.IsEmpty() )
                pUpdate->m_sModesC = sCommand;
            else
            {
                //The chan does have other modes.. Lets make sure we put things in order..
                int iChannelModeSettingsTypeCLength = m_sChannelModeSettingsTypeC.GetLength();
                //This will pad the mode string..
                for( int iIndex = 0; iIndex < iChannelModeSettingsTypeCLength; iIndex++)
                {
                    if( pUpdate->m_sModesC.Find(m_sChannelModeSettingsTypeC[iIndex]) == -1 )
                        pUpdate->m_sModesC.Insert(iIndex, _T(" "));
                }
                //Insert the new mode
                pUpdate->m_sModesC.Insert(iCommandIndex, sCommand);
                //Remove pads
                pUpdate->m_sModesC.Remove(_T(' '));
            }
        }
        return true;
    }
    iCommandIndex = m_sChannelModeSettingsTypeD.Find(sCommand);
    if( iCommandIndex != -1 )
    {
        //Remove the setting. This takes care of "-" and makes sure we don't add the same symbol twice.
        pUpdate->m_sModesD.Replace(sCommand, _T(""));
        if( sDir == _T("+") )
        {
            //Update mode.
            if( pUpdate->m_sModesD.IsEmpty() )
                pUpdate->m_sModesD = sCommand;
            else
            {
                //The chan does have other modes.. Lets make sure we put things in order..
                int iChannelModeSettingsTypeDLength = m_sChannelModeSettingsTypeD.GetLength();
                //This will pad the mode string..
                for( int iIndex = 0; iIndex < iChannelModeSettingsTypeDLength; iIndex++)
                {
                    if( pUpdate->m_sModesD.Find(m_sChannelModeSettingsTypeD[iIndex]) == -1 )
                        pUpdate->m_sModesD.Insert(iIndex, _T(" "));
                }
                //Insert the new mode
                pUpdate->m_sModesD.Insert(iCommandIndex, sCommand);
                //Remove pads
                pUpdate->m_sModesD.Remove(_T(' '));
            }
        }
        return true;
    }
    return false;
}
예제 #5
0
void CIrcChannelTabCtrl::OnContextMenu(CWnd*, CPoint point)
{
    int iCurTab = GetTabUnderMouse(point);
    if (iCurTab < 2)
    {
        return;
    }
    TCITEM item;
    item.mask = TCIF_PARAM;
    GetItem(iCurTab, &item);

    Channel* pChan = FindChannelByName(((Channel*)item.lParam)->m_sName);
    if( !pChan )
    {
        return;
    }

    CTitleMenu menuChat;
    menuChat.CreatePopupMenu();
    menuChat.AddMenuTitle(GetResString(IDS_IRC)+_T(" : ")+pChan->m_sName);
    menuChat.AppendMenu(MF_STRING, Irc_Close, GetResString(IDS_FD_CLOSE));
    if (iCurTab < 2) // no 'Close' for status log and channel list
        menuChat.EnableMenuItem(Irc_Close, MF_GRAYED);

    int iCurIndex = 0;
    int iLength = m_sChannelModeSettingsTypeA.GetLength();
    CString sMode;
    for( int iIndex = 0; iIndex < iLength; iIndex++)
    {
        sMode = m_sChannelModeSettingsTypeA.Mid(iIndex,1);
        if( pChan->m_sModesA.Find(sMode) == -1 )
        {
            menuChat.AppendMenu(MF_STRING, Irc_ChanCommands+iCurIndex, _T("ModeA Set +") + sMode + _T(" ( Not Supported Yet )") );
            menuChat.EnableMenuItem(Irc_ChanCommands+iCurIndex, MF_GRAYED);
        }
        else
        {
            menuChat.AppendMenu(MF_STRING, Irc_ChanCommands+iCurIndex+50, _T("ModeA Set -") + sMode + _T(" ( Not Supported Yet )") );
            menuChat.EnableMenuItem(Irc_ChanCommands+iCurIndex+50, MF_GRAYED);
        }
        iCurIndex++;
    }
    iLength = m_sChannelModeSettingsTypeB.GetLength();
    for( int iIndex = 0; iIndex < iLength; iIndex++)
    {
        sMode = m_sChannelModeSettingsTypeB.Mid(iIndex,1);
        if( pChan->m_sModesB.Find(sMode) == -1 )
        {
            menuChat.AppendMenu(MF_STRING, Irc_ChanCommands+iCurIndex, _T("ModeB Set +") + sMode + _T(" ( Not Supported Yet )") );
            menuChat.EnableMenuItem(Irc_ChanCommands+iCurIndex, MF_GRAYED);
        }
        else
        {
            menuChat.AppendMenu(MF_STRING, Irc_ChanCommands+iCurIndex+50, _T("ModeB Set -") + sMode + _T(" ( Not Supported Yet )") );
            menuChat.EnableMenuItem(Irc_ChanCommands+iCurIndex+50, MF_GRAYED);
        }
        iCurIndex++;
    }
    iLength = m_sChannelModeSettingsTypeC.GetLength();
    for( int iIndex = 0; iIndex < iLength; iIndex++)
    {
        sMode = m_sChannelModeSettingsTypeC.Mid(iIndex,1);
        if( pChan->m_sModesC.Find(sMode) == -1 )
        {
            menuChat.AppendMenu(MF_STRING, Irc_ChanCommands+iCurIndex, _T("ModeC Set +") + sMode + _T(" ( Not Supported Yet )") );
            menuChat.EnableMenuItem(Irc_ChanCommands+iCurIndex, MF_GRAYED);
        }
        else
        {
            menuChat.AppendMenu(MF_STRING, Irc_ChanCommands+iCurIndex+50, _T("ModeC Set -") + sMode + _T(" ( Remove ") + sMode + _T(" )") );
        }
        iCurIndex++;
    }
    iLength = m_sChannelModeSettingsTypeD.GetLength();
    for( int iIndex = 0; iIndex < iLength; iIndex++)
    {
        sMode = m_sChannelModeSettingsTypeD.Mid(iIndex,1);
        if( pChan->m_sModesD.Find(sMode) == -1 )
        {
            menuChat.AppendMenu(MF_STRING, Irc_ChanCommands+iCurIndex, _T("ModeD Set +") + sMode + _T(" ( Add ") + sMode + _T(" )") );
        }
        else
        {
            menuChat.AppendMenu(MF_STRING, Irc_ChanCommands+iCurIndex+50, _T("ModeD Set -") + sMode + _T(" ( Remove ") + sMode + _T(" )") );
        }
        iCurIndex++;
    }

    menuChat.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);
    VERIFY( menuChat.DestroyMenu() );
}