⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ircnicklistctrl.cpp

📁 另外一款开放源码的高质量p2p源码软件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	POSITION pos1, pos2;
	for( pos1 = update->nicks.GetHeadPosition();(pos2=pos1)!=NULL;)
	{
		//Go through channel nicks.
		update->nicks.GetNext(pos1);
		Nick* curr_nick = (Nick*)update->nicks.GetAt(pos2);
		if( curr_nick->nick == oldnick )
		{
			//Found nick to change.
			if((update = m_pParent->m_channelselect.m_pCurrentChannel) != NULL)
			{
				//This channle is in focuse, update nick in nickList
				LVFINDINFO find;
				find.flags = LVFI_PARAM;
				find.lParam = (LPARAM)curr_nick;
				sint32 itemnr = FindItem(&find);
				if (itemnr != (-1))
					SetItemText(itemnr,0,(LPCTSTR)newnick);
			}
			//Set new nick name..
			curr_nick->nick = newnick;
			return true;
		}
	}
	return false;
}

bool CIrcNickListCtrl::ChangeNickMode( CString channel, CString nick, CString mode )
{
	if( channel.Left(1) != "#" )
	{
		//Not a channel, this shouldn't happen
		return true;
	}
	if( nick == "" )
	{
		//No name, this shouldn't happen..
		return true;
	}
	//We are changing a mode to something..
	Channel* update = m_pParent->m_channelselect.FindChannelByName( channel );
	if( !update )
	{
		//No channel found, this shouldn't happen.
		return false;
	}
	POSITION pos1, pos2;
	for( pos1 = update->nicks.GetHeadPosition();(pos2=pos1)!=NULL;)
	{
		//Go through nicks
		update->nicks.GetNext(pos1);
		Nick* curr_nick = (Nick*)update->nicks.GetAt(pos2);
		if( curr_nick->nick == nick )
		{
			//Found nick.
			//Update modes.
			int modeLevel = m_sUserModeSettings.Find(mode[1]);
			if( modeLevel != -1 )
			{
				CString modeSymbol = m_sUserModeSymbols.Mid(modeLevel,1);
				//Remove the symbol. This takes care of "-" and makes sure we don't add the same symbol twice.
				curr_nick->modes.Remove(modeSymbol[0]);
				if( mode.Left(1) == "+" )
				{
					//The nick doesn't have any other modes.. Just set it..
					if( curr_nick->modes == "" )
						curr_nick->modes = modeSymbol;
					else
					{
						//The nick does have other modes.. Lets make sure we put things in order..
						int index = 0;
						//This will pad the mode string..
						while( index < m_sUserModeSymbols.GetLength() )
						{
							if( curr_nick->modes.Find(m_sUserModeSymbols[index]) == -1 )
							{
								curr_nick->modes.Insert(index, _T(" "));
							}
							index++;
						}
						//Insert the new mode
						curr_nick->modes.Insert(modeLevel, modeSymbol[0]);
						//Remove pads
						curr_nick->modes.Remove(' ');
					}
				}
			}
			else
			{
				//This should never happen
				curr_nick->modes = "";
				curr_nick->level = -1;
				ASSERT(0);
			}

			//Update user level
			if( curr_nick->modes.GetLength() > 0 )
				curr_nick->level = m_sUserModeSymbols.Find(curr_nick->modes[0]);
			else
				curr_nick->level = -1;

			sint32 itemnr = -1;
			if( (update = m_pParent->m_channelselect.m_pCurrentChannel) != NULL )
			{
				//Channel was in focus, update the nickList.
				LVFINDINFO find;
				find.flags = LVFI_PARAM;
				find.lParam = (LPARAM)curr_nick;
				itemnr = FindItem(&find);
				if( itemnr != (-1) )
				{
					SetItemText(itemnr,1,(LPCTSTR)curr_nick->modes);
				}
			}
			return true;
		}
	}
	//Nick was not found in list??
	return false;
}

void CIrcNickListCtrl::ChangeAllNick( CString oldnick, CString newnick )
{
	//Change a nick in ALL the channels..
	Channel* currchannel = m_pParent->m_channelselect.FindChannelByName( oldnick );
	if( currchannel )
	{
		//We had a private room open with this nick.. Update the title of the channel!
		currchannel->name = newnick;
		TCITEM item;
		item.mask = TCIF_PARAM;
		item.lParam = -1;
		//Find channel tab..
		int i;
		for (i = 0; i < m_pParent->m_channelselect.GetItemCount();i++)
		{
			m_pParent->m_channelselect.GetItem(i,&item);
			if (((Channel*)item.lParam) == currchannel)
			{
				//Found tab, update it..
				item.mask = TCIF_TEXT;
				item.pszText = newnick.GetBuffer();
				m_pParent->m_channelselect.SetItem( i, &item);
				break;
			}
		}
	}
	//Go through all other channel nicklists..
	POSITION pos1, pos2;
	for (pos1 = m_pParent->m_channelselect.channelPtrList.GetHeadPosition();( pos2 = pos1 ) != NULL;)
	{
		m_pParent->m_channelselect.channelPtrList.GetNext(pos1);
		Channel* cur_channel = (Channel*)(m_pParent->m_channelselect.channelPtrList).GetAt(pos2);
		if(ChangeNick( cur_channel->name, oldnick, newnick ))
		{
			//Nick change successful, add a message to inform you..
			if( !thePrefs.GetIrcIgnoreMiscMessage() )
				m_pParent->AddInfoMessage( cur_channel->name, GetResString(IDS_IRC_NOWKNOWNAS), oldnick, newnick);
		}
	}
}

void CIrcNickListCtrl::UpdateNickCount()
{
	//Get the header control
	CHeaderCtrl* pHeaderCtrl;
	HDITEM hdi;
	hdi.mask = HDI_TEXT;
	CString strRes;
	pHeaderCtrl = GetHeaderCtrl();
	if( GetItemCount() )
	{
		//Set nick count to current channel.
		strRes.Format(_T("%s[%i]"), GetResString(IDS_IRC_NICK), GetItemCount());
	}
	else
	{
		//No nicks in the list.. Your in Status or ChannleList
		strRes.Format(_T("%s"), GetResString(IDS_IRC_NICK));
	}
	hdi.pszText = strRes.GetBuffer();
	pHeaderCtrl->SetItem(0, &hdi);
	strRes.ReleaseBuffer();
}

void CIrcNickListCtrl::Localize()
{
	CHeaderCtrl* pHeaderCtrl = GetHeaderCtrl();
	CString strRes;
	strRes = GetResString(IDS_STATUS);
	HDITEM hdi;
	hdi.pszText = const_cast<LPTSTR>((LPCTSTR)strRes);
	hdi.mask = HDI_TEXT;
	pHeaderCtrl->SetItem(1, &hdi);
	UpdateNickCount();
}

BOOL CIrcNickListCtrl::OnCommand(WPARAM wParam,LPARAM lParam )
{
	int nickItem = GetNextItem(-1, LVIS_SELECTED | LVIS_FOCUSED);
	int chanItem = m_pParent->m_channelselect.GetCurSel(); 

	switch( wParam )
	{
		case Irc_Priv: 
		{
			//Right clicked and choose start private chan.
			Nick* nick = (Nick*)GetItemData(nickItem);
			if(nick)
			{
				//Send a message with the nick as the channel name, this will create a new window with the default message.
				m_pParent->AddInfoMessage( nick->nick, GetResString(IDS_IRC_PRIVATECHANSTART));
			}
            return true;
		}
		case Irc_Kick: 
		{
			//Kick someone from a channel
			Nick* nick = (Nick*)GetItemData(nickItem);
			TCITEM item;
			item.mask = TCIF_PARAM;
			m_pParent->m_channelselect.GetItem(chanItem,&item);
			Channel* chan = (Channel*)item.lParam;
			if( nick && chan )
			{
				//We have a nick and chan, send the command.
				CString send;
				send.Format(_T("KICK %s %s"), chan->name, nick->nick );
				m_pParent->m_pIrcMain->SendString(send);
			}
			return true;
		}
		case Irc_Ban: 
		{
			//Kick someone from a channel
			Nick* nick = (Nick*)GetItemData(nickItem);
			TCITEM item;
			item.mask = TCIF_PARAM;
			m_pParent->m_channelselect.GetItem(chanItem,&item);
			Channel* chan = (Channel*)item.lParam;
			if( nick && chan )
			{
				//We have a nick and chan, send the command.
				CString send;
				send.Format(_T("cs ban %s %s"), chan->name, nick->nick );
				m_pParent->m_pIrcMain->SendString(send);
			}
			return true;
		}
		case Irc_Slap: 
		{
			//Do a silly slap on someone
			Nick* nick = (Nick*)GetItemData(nickItem);
			TCITEM item;
			item.mask = TCIF_PARAM;
			m_pParent->m_channelselect.GetItem(chanItem,&item);
			Channel* chan = (Channel*)item.lParam;
			if( nick && chan )
			{
				//We have a nick and chan, send the command.
				CString send;
				send.Format( GetResString(IDS_IRC_SLAPMSGSEND), chan->name, nick->nick );
				m_pParent->AddInfoMessage( chan->name, GetResString(IDS_IRC_SLAPMSG), m_pParent->m_pIrcMain->GetNick(), nick->nick);
				m_pParent->m_pIrcMain->SendString(send);
			}
			return true;
		}
		case Irc_AddFriend: 
		{
			//Attempt to add this person as a friend.
			Nick* nick = (Nick*)GetItemData(nickItem);
			TCITEM item;
			item.mask = TCIF_PARAM;
			m_pParent->m_channelselect.GetItem(chanItem,&item);
			Channel* chan = (Channel*)item.lParam;
			if( nick && chan )
			{
				//We have a nick and chan, send the command.
				//SetVerify() sets a new challenge which is required by the other end to respond with for some protection.
				CString send;
				send.Format(_T("PRIVMSG %s :\001RQSFRIEND|%i|\001"), nick->nick, m_pParent->m_pIrcMain->SetVerify() );
				m_pParent->m_pIrcMain->SendString(send);
			}
			return true;
		}
		case Irc_SendLink: 
		{
			//Send a ED2K link to someone..
			if(!m_pParent->GetSendFileString())
			{
				//There is no link in the buffer, abort.
				return true;
			}
			Nick* nick = (Nick*)GetItemData(nickItem);
			TCITEM item;
			item.mask = TCIF_PARAM;
			m_pParent->m_channelselect.GetItem(chanItem,&item);
			Channel* chan = (Channel*)item.lParam;
			if( nick && chan )
			{
				//We have a nick and chan, send the command.
				//We send our nick and ClientID to allow the other end to only accept links from friends..
				CString send;
				send.Format(_T("PRIVMSG %s :\001SENDLINK|%s|%s\001"), nick->nick, EncodeBase16((const unsigned char*)thePrefs.GetUserHash(), 16), m_pParent->GetSendFileString() );
				m_pParent->m_pIrcMain->SendString(send);
			}
			return true;
		}
	}
	if( wParam >= Irc_OpCommands && wParam < Irc_OpCommands+25)
	{
		int index = wParam - Irc_OpCommands;
		CString mode = m_sUserModeSettings.Mid(index,1);
		Nick* nick = (Nick*)GetItemData(nickItem);
		TCITEM item;
		item.mask = TCIF_PARAM;
		m_pParent->m_channelselect.GetItem(chanItem,&item);
		Channel* chan = (Channel*)item.lParam;
		if( nick && chan )
		{
			//We have a nick and chan, send the command.
			CString send;
			send.Format(_T("MODE %s +%s %s"), chan->name, mode, nick->nick );
			m_pParent->m_pIrcMain->SendString(send);
		}
		return true;
	}
	if( wParam >= Irc_OpCommands+25 && wParam < Irc_OpCommands+50)
	{
		int index = wParam - Irc_OpCommands-25;
		CString mode = m_sUserModeSettings.Mid(index,1);
		Nick* nick = (Nick*)GetItemData(nickItem);
		TCITEM item;
		item.mask = TCIF_PARAM;
		m_pParent->m_channelselect.GetItem(chanItem,&item);
		Channel* chan = (Channel*)item.lParam;
		if( nick && chan )
		{
			//We have a nick and chan, send the command.
			CString send;
			send.Format(_T("MODE %s -%s %s"), chan->name, mode, nick->nick );
			m_pParent->m_pIrcMain->SendString(send);
		}
		return true;
	}
	return true;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -