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

📄 ircwnd.cpp

📁 eMule0.44b的原代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	{
		//We had no valid item here.. Something isn't right..
		//TODO: this should never happen, so maybe we should remove this tab?
		return;
	}
	Channel* partChannel = (Channel*)item.lParam;
	if( partChannel->type == 4 &&  m_bConnected)
	{
		//If this was a channel and we were connected, do not just delete the channel!!
		//Send a part command and the server must respond with a successful part which will remove the channel!
		CString part;
		part = _T("PART ") + partChannel->name;
		m_pIrcMain->SendString( part );
		return;
	}
	else if (partChannel->type == 5 || partChannel->type == 4)
	{
		//If this is a private room, we just remove it as the server doesn't track this.
		//If this was a channel, but we are disconnected, remove the channel..
		m_channelselect.RemoveChannel(partChannel->name);
		return;
	}
}

/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
// Messages
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////

void CIrcWnd::AddStatus( CString line,...)
{
	//Add entry to status window with arguments..
	va_list argptr;
	va_start(argptr, line);
	CString temp;
	temp.FormatV(line, argptr);
	va_end(argptr);
	CString timestamp;
	if( thePrefs.GetIRCAddTimestamp() )
	{
		//Append time stamp..
		timestamp = CTime::GetCurrentTime().Format(_T("%X: "));
	}
	Channel* update_channel = (Channel*)(m_channelselect.channelPtrList).GetHead();
	if( !update_channel )
	{
		//This should never happen!
		return;
	}
	//We do not support color codes..
	line = StripMessageOfFontCodes( temp );
	line += _T("\r\n");
	//Now that incoming arguments are finished, it's now safe to put back the % chars.
	line.Replace( _T("\004"), _T("%") );
	if (line == _T("\r\n") )
	{
		//This allows for us to add blank lines to the status..
		update_channel->log.AppendText(line);
	}
	else if (line.Mid(0,1) == _T("*"))
	{
		update_channel->log.AppendText(timestamp);
		update_channel->log.AppendKeyWord(line.Left(2),RGB(255,0,0));
		update_channel->log.AppendText(line.Mid(1) );
	}
	else
		update_channel->log.AppendText(timestamp + line);
	if( m_channelselect.m_pCurrentChannel == update_channel )
		return;
	m_channelselect.SetActivity( update_channel->name, true );
}

void CIrcWnd::AddInfoMessage( CString channelName, CString line,...)
{
	if(channelName.IsEmpty())
		return;
	va_list argptr;
	va_start(argptr, line);
	CString temp;
	temp.FormatV(line, argptr);
	va_end(argptr);
	CString timestamp = _T("");
	if( thePrefs.GetIRCAddTimestamp() )
		timestamp = CTime::GetCurrentTime().Format(_T("%X: "));
	Channel* update_channel = m_channelselect.FindChannelByName(channelName);
	if( !update_channel )
	{
		if( channelName.Left(1) == _T("#") )
			update_channel = m_channelselect.NewChannel( channelName, 4);
		else
			update_channel = m_channelselect.NewChannel( channelName, 5);
	}
	line = StripMessageOfFontCodes( temp );
	line += _T("\r\n");
	line.Replace( _T("\004"), _T("%") );
	if (line.Mid(0,1) == _T("*"))
	{
		update_channel->log.AppendText(timestamp);
		update_channel->log.AppendKeyWord(line.Left(2),RGB(255,0,0));
		update_channel->log.AppendText(line.Mid(1) );
	}
	else if (line.Mid(0,1) == _T("-") && line.Find( _T("-"), 1 ) != -1)
	{
		int index = line.Find( _T("-"), 1 );
		update_channel->log.AppendText(timestamp);
		update_channel->log.AppendKeyWord(line.Left(index),RGB(150,0,0));
		update_channel->log.AppendText(line.Mid(index) );
	}
	else
		update_channel->log.AppendText(timestamp + line);
	
	if( m_channelselect.m_pCurrentChannel == update_channel )
		return;
	m_channelselect.SetActivity( update_channel->name, true );
}

void CIrcWnd::AddMessage( CString channelName, CString targetname, CString line,...)
{
	if(channelName.IsEmpty() || targetname.IsEmpty())
		return;
	va_list argptr;
	va_start(argptr, line);
	CString temp;
	temp.FormatV(line, argptr);
	line = temp;
	va_end(argptr);
	CString timestamp = _T("");
	if( thePrefs.GetIRCAddTimestamp() )
		timestamp = CTime::GetCurrentTime().Format(_T("%X: "));
	Channel* update_channel = m_channelselect.FindChannelByName(channelName);
	if( !update_channel )
	{
		if( channelName.Left(1) == _T("#") )
			update_channel = m_channelselect.NewChannel( channelName, 4);
		else
			update_channel = m_channelselect.NewChannel( channelName, 5);
	}
	line = StripMessageOfFontCodes( line );
	line += _T("\r\n");
	line.Replace( _T("\004"), _T("%") );
	COLORREF color;
	if (m_pIrcMain->GetNick() == targetname)
		color = RGB(1,100,1);
	else
		color = RGB(1,20,130);	
	targetname = CString(_T("<"))+ targetname + CString(_T(">"));
	update_channel->log.AppendText(timestamp);
	update_channel->log.AppendKeyWord(targetname, color);
	update_channel->log.AppendText(CString(_T(" "))+line);
	if( m_channelselect.m_pCurrentChannel == update_channel )
		return;
	m_channelselect.SetActivity( update_channel->name, true );	
}

void CIrcWnd::SetConnectStatus( bool flag )
{
	if(flag)
	{
		GetDlgItem(IDC_BN_IRCCONNECT)->SetWindowText(GetResString(IDS_IRC_DISCONNECT));
		AddStatus( GetResString(IDS_CONNECTED));
		m_bConnected = true;
	}
	else
	{
		GetDlgItem(IDC_BN_IRCCONNECT)->SetWindowText(GetResString(IDS_IRC_CONNECT));
		AddStatus( GetResString(IDS_DISCONNECTED));
		m_bConnected = false;
		m_bLoggedIn = false;
		while( m_channelselect.channelPtrList.GetCount() > 2 )
		{
			Channel* todel = (Channel*)(m_channelselect.channelPtrList).GetTail();
			m_channelselect.RemoveChannel( todel->name );
		}
	}
}

void CIrcWnd::NoticeMessage( CString source, CString message )
{
	bool flag = false;
	Channel* curr_channel = m_channelselect.FindChannelByName( source );
	if( curr_channel )
	{
		AddInfoMessage( source, _T("-%s- %s"), source, message);
		flag = true;
	}
	POSITION pos1, pos2;
	for (pos1 = m_channelselect.channelPtrList.GetHeadPosition();( pos2 = pos1 ) != NULL;)
	{
		m_channelselect.channelPtrList.GetNext(pos1);
		curr_channel = (Channel*)(m_channelselect.channelPtrList).GetAt(pos2);
		Nick* curr_nick = m_nicklist.FindNickByName(curr_channel->name, source );
		if( curr_nick)
		{
			AddInfoMessage( curr_channel->name, _T("-%s- %s"), source, message);
			flag = true;			
		}
	}
	if( flag == false )
	{
		if( m_channelselect.m_pCurrentChannel->type == 4 )
			AddInfoMessage( m_channelselect.m_pCurrentChannel->name, _T("-%s- %s"), source, message);
		else
			AddStatus( _T("-%s- %s"), source, message );
	}
}

//We cannot support color within the text since HyperTextCtrl does not detect hyperlinks with color. So I will filter it.
CString CIrcWnd::StripMessageOfFontCodes( CString temp )
{
	temp = StripMessageOfColorCodes( temp );
	temp.Replace(_T("\002"),_T(""));
	temp.Replace(_T("\003"),_T(""));
	temp.Replace(_T("\017"),_T(""));
	temp.Replace(_T("\026"),_T(""));
	temp.Replace(_T("\037"),_T(""));
	return temp;
}

CString CIrcWnd::StripMessageOfColorCodes( CString temp )
{
	if( !temp.IsEmpty() )
	{
		CString temp1, temp2;
		int test = temp.Find( 3 );
		if( test != -1 )
		{
			int testlength = temp.GetLength() - test;
			if( testlength < 2 )
				return temp;
			temp1 = temp.Left( test );
			temp2 = temp.Mid( test + 2);
			if( testlength < 4 )
				return temp1+temp2;
			if( temp2[0] == 44 && temp2.GetLength() > 2)
			{
				temp2 = temp2.Mid(2);
				for( int I = 48; I < 58; I++ )
				{
					if( temp2[0] == I )
						temp2 = temp2.Mid(1);
				}
			}
			else
			{
				for( int I = 48; I < 58; I++ )
				{
					if( temp2[0] == I )
					{
						temp2 = temp2.Mid(1);
						if( temp2[0] == 44 && temp2.GetLength() > 2)
						{
							temp2 = temp2.Mid(2);
							for( int I = 48; I < 58; I++ )
							{
								if( temp2[0] == I )
									temp2 = temp2.Mid(1);
							}
						}
					}
				}
			}
			temp = temp1 + temp2;
			temp = StripMessageOfColorCodes(temp);
		}
	}
	return temp;
}

void CIrcWnd::SetTitle( CString channel, CString title )
{
	Channel* curr_channel = m_channelselect.FindChannelByName(channel);
	if(!curr_channel)
		return;
	curr_channel->title = StripMessageOfFontCodes(title);
	if( curr_channel == m_channelselect.m_pCurrentChannel )
		titleWindow.SetWindowText( curr_channel->title );
}

void CIrcWnd::OnBnClickedChatsend()
{
	CString send;
	GetDlgItem(IDC_INPUTWINDOW)->GetWindowText(send);
	GetDlgItem(IDC_INPUTWINDOW)->SetWindowText(_T(""));
	GetDlgItem(IDC_INPUTWINDOW)->SetFocus();
	m_channelselect.Chatsend(send);
}

void CIrcWnd::SendString( CString send )
{ 
	if( this->m_bConnected )
		m_pIrcMain->SendString( send );
}

BOOL CIrcWnd::OnHelpInfo(HELPINFO* pHelpInfo)
{
	theApp.ShowHelp(eMule_FAQ_IRC_Chat);
	return TRUE;
}

void CIrcWnd::OnChatTextChange()
{
	GetDlgItem(IDC_CHATSEND)->EnableWindow( GetDlgItem(IDC_INPUTWINDOW)->GetWindowTextLength()>0 );
}

void CIrcWnd::ParseChangeMode( CString channel, CString changer, CString commands, CString params )
{
	try
	{
		if( commands.GetLength() == 2 )
		{
			//Single mode change..
			if(m_nicklist.m_sUserModeSettings.Find(commands[1]) != -1 )
			{
				//This is a user mode change!
				m_nicklist.ChangeNickMode( channel, params, commands );
			}
			if(m_channelselect.m_sChannelModeSettingsTypeA.Find(commands[1]) != -1 )
			{
				//We do not use these messages yet.. But we can display them for the user to see
				//These modes always have a param and will add or remove a user from some type of list.
				m_channelselect.ChangeChanMode( channel, params, commands );
			}
			if(m_channelselect.m_sChannelModeSettingsTypeB.Find(commands[1]) != -1 )
			{
				//We do not use these messages yet.. But we can display them for the user to see
				//These modes will always have a param..
				m_channelselect.ChangeChanMode( channel, params, commands );
			}
			if(m_channelselect.m_sChannelModeSettingsTypeC.Find(commands[1]) != -1 )
			{
				//We do not use these messages yet.. But we can display them for the user to see
				//These modes will only have a param if your setting it!
				m_channelselect.ChangeChanMode( channel, params, commands );
			}
			if(m_channelselect.m_sChannelModeSettingsTypeD.Find(commands[1]) != -1 )
			{
				//We do not use these messages yet.. But we can display them for the user to see
				//These modes will never have a param for it!
				m_channelselect.ChangeChanMode( channel, params, commands );
			}
			if( !thePrefs.GetIrcIgnoreMiscMessage() )
				AddInfoMessage( channel, GetResString(IDS_IRC_SETSMODE), changer, commands, params);
			return;
		}
		else if ( commands.GetLength() > 2 )
		{
			//Multiple mode changes..
			CString dir;
			dir = commands[0];
			if( dir == _T("+") || dir == _T("-"))
			{
				//The mode must be either adding (+) or removing (-)
				int currModeIndex = 1;
				int currNameIndex = 0;
				int currNameBackIndex = params.Find( _T(" "), currNameIndex);
				CString currName = _T("");
				while( currModeIndex < commands.GetLength())
				{
					//There is another mode to process..
					if(m_nicklist.m_sUserModeSettings.Find(commands[1]) != -1 )
					{
						//This is a user mode change and must have a param!
                        if( currNameBackIndex > currNameIndex )
						{
							//There's a valid name to this mode change..
							currName = params.Mid(currNameIndex, currNameBackIndex-currNameIndex);
							currNameIndex = currNameBackIndex +1;
						}
						else
						{
							//This should not happen!
							ASSERT(0);
						}
						m_nicklist.ChangeNickMode( channel, currName, dir + commands[currModeIndex]);
						//Move to the next param.
						currNameBackIndex = params.Find(_T(" "), currNameIndex+1);
						if( currNameBackIndex == -1)
							currNameBackIndex = params.GetLength();
					}
					if(m_channelselect.m_sChannelModeSettingsTypeA.Find(commands[currModeIndex]) != -1)
					{
						//We do not use these messages yet.. But we can display them for the user to see
						//These modes always have a param and will add or remove a user from some type of list.
                        if( currNameBackIndex > currNameIndex )
						{
							//There's a valid name to this mode change..
							currName = params.Mid(currNameIndex, currNameBackIndex-currNameIndex);
							currNameIndex = currNameBackIndex +1;
						}
						else
						{
							//This should not happen!
							ASSERT(0);
						}

						m_channelselect.ChangeChanMode( channel, currName, dir + commands[currModeIndex]);

						//Move to the next param.
						currNameBackIndex = params.Find(_T(" "), currNameIndex+1);
						if( currNameBackIndex == -1)
							currNameBackIndex = params.GetLength();
					}
					if(m_channelselect.m_sChannelModeSettingsTypeB.Find(commands[currModeIndex]) != -1)
					{
						//We do not use these messages yet.. But we can display them for the user to see
						//These modes will always have a param..
                        if( currNameBackIndex > currNameIndex )
						{
							//There's a valid name to this mode change..
							currName = params.Mid(currNameIndex, currNameBackIndex-currNameIndex);
							currNameIndex = currNameBackIndex +1;
						}
						else
						{
							//This should not happen!
							ASSERT(0);
						}

						m_channelselect.ChangeChanMode( channel, currName, dir + commands[currModeIndex]);

						//Move to the next param.
						currNameBackIndex = params.Find(_T(" "), currNameIndex+1);
						if( currNameBackIndex == -1)
							currNameBackIndex = params.GetLength();
					}
					if(m_channelselect.m_sChannelModeSettingsTypeC.Find(commands[currModeIndex]) != -1 )
					{
						//We do not use these messages yet.. But we can display them for the user to see
						//These modes will only have a param if your setting it!
						if( dir == _T("+") )
						{
							//We are setting a mode, find param
	                        if( currNameBackIndex > currNameIndex )
							{
								//There's a valid name to this mode change..
								currName = params.Mid(currNameIndex, currNameBackIndex-currNameIndex);
								currNameIndex = currNameBackIndex +1;
							}
							else
							{
								//This should not happen!
								ASSERT(0);
							}
						}
						else
						{
							//We are removing a mode, no params
							currName = _T("");
						}

						m_channelselect.ChangeChanMode( channel, currName, dir + commands[currModeIndex]);

						if( dir == _T("+") )
						{
							//Set this mode, so move to the next param.
							currNameBackIndex = params.Find(_T(" "), currNameIndex+1);
							if( currNameBackIndex == -1)
								currNameBackIndex = params.GetLength();
						}
					}
					if(m_channelselect.m_sChannelModeSettingsTypeD.Find(commands[currModeIndex]) != -1 )
					{
						//We do not use these messages yet.. But we can display them for the user to see
						//These modes will never have a param for it!
						currName = _T("");

						m_channelselect.ChangeChanMode( channel, currName, dir + commands[currModeIndex]);

					}
					currModeIndex++;
				}
				if( !thePrefs.GetIrcIgnoreMiscMessage() )
					AddInfoMessage( channel, GetResString(IDS_IRC_SETSMODE), changer, commands, params);
			}
		}
	}
	catch(...)
	{
		AddInfoMessage( channel, GetResString(IDS_IRC_NOTSUPPORTED));
		ASSERT(0);
	}
}

⌨️ 快捷键说明

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