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

📄 ircmain.cpp

📁 eMule0.44b的原代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
						//TODO - Respond to a user ping.
						return;
					}
					if( message.Left(9) == _T("RQSFRIEND") )
					{
						//eMule user requested to add you as friend.
						if( !thePrefs.GetIrcAllowEmuleProtoAddFriend() )
							return;
						if( message.GetLength() < 10 )
							throw CString( _T("SMIRC Error: Received Invalid friend request") );
						message = message.Mid(9);
						int index1 = message.Find( _T("|") );
						if( index1 == -1 || index1 == message.GetLength() )
							throw CString( _T("SMIRC Error: Received Invalid friend request") );
						int index2 = message.Find( _T("|"), index1+1 );
						if( index2 == -1 || index1 > index2 )
							throw CString( _T("SMIRC Error: Received Invalid friend request") );
						//Adds a little protection
						CString sverify = message.Mid(index1+1, index2-index1-1);
						CString sip;
						CString sport;
						if(theApp.serverconnect->IsConnected())
						{
							//Tell them what server we are on for possibel lowID support later.
							sip.Format( _T("%i"), theApp.serverconnect->GetCurrentServer()->GetIP());
							sport.Format( _T("%i"), theApp.serverconnect->GetCurrentServer()->GetPort());
						}
						else
						{
							//Not on a server.
							sip = _T("0.0.0.0");
							sport = _T("0");
						}
						//Create our response.
						CString build;
						build.Format( _T("PRIVMSG %s :\001REPFRIEND eMule%s%s|%s|%u:%u|%s:%s|%s|\001"), source, theApp.m_strCurVersionLong, Irc_Version, sverify, theApp.IsFirewalled() ? 0 : theApp.GetID(), thePrefs.GetPort(), sip, sport, md4str(thePrefs.GetUserHash()));
						ircsocket->SendString( build );
						build.Format( _T("%s %s"), source, GetResString(IDS_IRC_ADDASFRIEND));
						if( !thePrefs.GetIrcIgnoreEmuleProtoAddFriend() )
							m_pwndIRC->NoticeMessage( _T("*EmuleProto*"), build );
						return;
					}
					if( message.Left(9) == _T("REPFRIEND") )
					{
						if( message.GetLength() < 10 )
							throw CString( _T("SMIRC Error: Received Invalid friend reply") );
						message = message.Mid(9);
						int index1 = message.Find( _T("|") );
						if( index1 == -1 || index1 == message.GetLength() )
							throw CString( _T("SMIRC Error: Received Invalid friend reply") );
						int index2 = message.Find( _T("|"), index1+1 );
						if( index2 == -1 || index1 > index2 )
							throw CString( _T("SMIRC Error: Received Invalid friend reply") );
						CString sverify = message.Mid(index1+1, index2-index1-1);
						//Make sure we requested this!
						if( verify != _tstoi(sverify))
							return;
						//Pick a new random verify.
						SetVerify();
						index1 = message.Find( _T(":"), index2+1);
						if( index1 == -1 || index2 > index1 )
							throw CString( _T("SMIRC Error: Received Invalid friend reply") );
						uint32 newClientID = _tstoi(message.Mid( index2 + 1, index1 - index2 -1));
						index2 = message.Find( _T('|'), index1+1);
						if( index2 == -1 || index1 >= index2 )
							throw CString( _T("SMIRC Error: Received Invalid friend reply") );
						uint16 newClientPort = _tstoi(message.Mid( index1 + 1, index2 - index1 -1));
						index1 = message.Find( _T(':'), index2+1);
						if( index1 == -1 || index2 >= index1 )
							throw CString( _T("SMIRC Error: Received Invalid friend reply") );
						//This is if we decide to support lowID clients.
						//uint32 newClientServerIP = _tstoi(message.Mid( index2 + 1, index1 - index2 -1));
						index2 = message.Find( _T('|'), index1+1);
						if( index2 == -1 || index1 >= index2 )
							throw CString( _T("SMIRC Error: Received Invalid friend reply") );
						//This is if we decide to support lowID clients.
						//uint16 newClientServerPort = _tstoi(message.Mid( index1 + 1, index2 - index1 -1));
						index1 = message.Find( _T('|'), index2+1);
						if( index1 == -1 || index2 >= index1 )
							throw CString( _T("SMIRC Error: Received Invalid friend reply") );
						CString hash(message.Mid( index2 + 1, index1 - index2 -1));
						uchar userid[16];
						if (!strmd4(hash,userid))
							throw CString( _T("SMIRC Error: Received Invalid friend reply") );
						theApp.friendlist->AddFriend( userid, 0, newClientID, newClientPort, 0, source, 1);
						return;
					}
					if( message.Left(8) == _T("SENDLINK") )
					{
						//Received a ED2K link from someone.
						if ( !thePrefs.GetIrcAcceptLinks() )
						{
							if( !thePrefs.GetIrcIgnoreEmuleProtoSendLink() )
							{
								m_pwndIRC->NoticeMessage( _T("*EmuleProto*"), source + _T(" attempted to send you a file. If you wanted to accept the files from this person, enable Receive files in the IRC Preferences."));
							}
							return;
						}
						if( message.GetLength() < 9 )
							throw CString( _T("SMIRC Error: Received Invalid ED2K link") );
						message = message.Mid(8);
						int index1, index2;
						index1 = message.Find( _T("|") );
						if( index1 == -1 || index1 == message.GetLength() )
							throw CString( _T("SMIRC Error: Received Invalid ED2K link") );
						index2 = message.Find( _T("|"), index1+1 );
						if( index2 == -1 || index1 > index2 )
							throw CString( _T("SMIRC Error: Received Invalid ED2K link") );
						CString hash = message.Mid(index1+1, index2-index1-1);
						uchar userid[16];
						if (!strmd4(hash,userid))
							throw CString( _T("SMIRC Error: Received Invalid ED2K link") );
						if(!theApp.friendlist->SearchFriend(userid, 0, 0))
						{
							//This wasn't a friend..
							if( thePrefs.GetIrcAcceptLinksFriends() )
							{
								//We don't accept from non-friends.
								if( !thePrefs.GetIrcIgnoreEmuleProtoSendLink() )
								{
									m_pwndIRC->NoticeMessage( _T("*EmuleProto*"), source + _T(" attempted to send you a file but wasn't a friend. If you wanted to accept files from this person, add person as a friend or disable from friends only in the IRC preferences."));
								}
								return;
							}
						}
						message = message.Mid( index2+1 );
						if( !message.IsEmpty() )
						{
							CString build;
							build.Format( GetResString(IDS_IRC_RECIEVEDLINK), source, message );
							if( !thePrefs.GetIrcIgnoreEmuleProtoSendLink() )
								m_pwndIRC->NoticeMessage( _T("*EmuleProto*"), build );
							ProcessLink( message );
						}
						return;
					}
					return;
				}
				else
				{
					m_pwndIRC->AddMessage( source, source, message);
					return;
				}
			}
		}
		if( command == _T("JOIN") )
		{
			//Channel join
			if( source == nick )
			{
				//This was you.. So for it to add a new channel..
				m_pwndIRC->AddInfoMessage( target, GetResString(IDS_IRC_HASJOINED), source, target );
				return;
			}
			if( !thePrefs.GetIrcIgnoreJoinMessage() )
				m_pwndIRC->AddInfoMessage( target, GetResString(IDS_IRC_HASJOINED), source, target );
			//Add new nick to your channel.
			m_pwndIRC->m_nicklist.NewNick( target, source );
			return;
	
		}
		if( command == _T("PART") )
		{
			//Part message
			if ( source == nick )
			{
				//This was you, so remove channel.
				m_pwndIRC->m_channelselect.RemoveChannel( target );
				return;
			}
			if( !thePrefs.GetIrcIgnorePartMessage() )
				m_pwndIRC->AddInfoMessage( target, GetResString(IDS_IRC_HASPARTED), source, target, message );
			//Remove nick from your channel.
			m_pwndIRC->m_nicklist.RemoveNick( target, source );
			return;
		}
	
		if( command == _T("TOPIC") )
		{
			//Topic was set, update it.
			m_pwndIRC->SetTitle( target, message );
			return;
		}
	
		if( command == _T("QUIT") )
		{
			//This user left the network.. Remove from all Channels..
			m_pwndIRC->m_nicklist.DeleteNickInAll( source, message );
			return;
		}
	
		if( command == _T("NICK") )
		{
			//Someone changed a nick..
			if( source == nick )
			{
				//It was you.. Update!
				nick = target;
				thePrefs.SetIRCNick( nick.GetBuffer() );
			}
			//UPdate new nick in all channles..
			m_pwndIRC->m_nicklist.ChangeAllNick( source, target );
			return;
		}
	
		if( command == _T("KICK") )
		{
			//Someone was kicked from a channel..
			target2Index = message.Find(_T(':'));
			if( target2Index > 0 ){
				target2 = message.Mid( 1, target2Index - 2);
				message = message.Mid( target2Index + 1 );
			}
			if( target2 == nick )
			{
				//It was you!
				m_pwndIRC->m_channelselect.RemoveChannel( target );
				m_pwndIRC->AddStatus(  GetResString(IDS_IRC_WASKICKEDBY), target2, source, message );
				return;
			}
			if( !thePrefs.GetIrcIgnoreMiscMessage() )
				m_pwndIRC->AddInfoMessage( target, GetResString(IDS_IRC_WASKICKEDBY), target2, source, message );
			//Remove nick from your channel.
			m_pwndIRC->m_nicklist.RemoveNick( target, target2 );
			return;
		}
		if( command == _T("MODE") )
		{
			if( target != _T("") )
			{
				//A mode was set..
				commandIndex = message.Find( _T(' '), 1 );
				if( commandIndex < 2 )
					throw CString( _T("SMIRC Error: Received Invalid Mode change.") );
				command = message.Mid( 1, commandIndex - 1 );
				command.Replace( _T("\004"), _T("%") );
				target2 = message.Mid( commandIndex + 1 );
				m_pwndIRC->ParseChangeMode( target, source, command, target2 );
				return;
			}
			else
			{
				//The server just set a server user mode that relates to no channels!
				//Atm, we do not handle these modes.
			}
		}
		if( command == _T("NOTICE"))
		{
			//Receive notive..
			m_pwndIRC->NoticeMessage( source, message );
			return;
		}

		//TODO: Double and trible check this.. I don't know of any 3 letter commands
		//So I'm currently assuming it's a numberical command..
		if( command.GetLength() == 3 )
		{
			messageIndex = message.Find(_T(" "));
			if( messageIndex == -1 )
				throw CString(_T("SMIRC Error: received [") + command + _T("] command with invalid messageIndex"));
			message = message.Mid( messageIndex + 1);
			//The first line of each command appears to start with a ":"
			if( message.Left(1) == _T(":") )
			{
				m_pwndIRC->AddStatus( _T("") );
				message = message.Mid(1);
			}
			uint16 intCommand = _tstoi(command);
			switch(intCommand)
			{
				//- The server sends Replies 001 to 004 to a user upon
				//successful registration.				
				//001    RPL_WELCOME
				//"Welcome to the Internet Relay Network
				//<nick>!<user>@<host>"
				//002    RPL_YOURHOST
				//"Your host is <servername>, running version <ver>"
				//003    RPL_CREATED
				//"This server was created <date>"
				//004    RPL_MYINFO
				//"<servername> <version> <available user modes>
				//<available channel modes>"
				case 1:
				{
					m_pwndIRC->SetLoggedIn( true );
					if( thePrefs.GetIRCListOnConnect() )
						ircsocket->SendString(_T("list"));
					ParsePerform();
					m_pwndIRC->AddStatus( message );
					return;
				}
				case 2:
				case 3:
				case 4:
				{
					m_pwndIRC->AddStatus( message );
					return;
				}

				//- Sent by the server to a user to suggest an alternative
				//server.  This is often used when the connection is
				//refused because the server is already full.
                //005    RPL_BOUNCE
				//"Try server <server name>, port <port number>"

				//005 is actually confusing.. Different sites say different things?
				//It appears this is also RPL_ISUPPORT which tells you what modes are
				//availabile to this server..
				case 5:
				{
					//This get our viable user modes
					int prefixStart = message.Find(_T("PREFIX=(")) ;
					if( prefixStart != -1 )
					{
						int prefixEnd = message.Find(_T(")"), prefixStart );
						if( prefixEnd != -1 )
						{
							//Set our channel modes actions
							m_pwndIRC->m_nicklist.m_sUserModeSettings = message.Mid( prefixStart+8, prefixEnd-prefixStart-8 );
							m_pwndIRC->m_nicklist.m_sUserModeSettings.Replace( _T("\004"), _T("%") );
							//Set our channel modes symbols
							m_pwndIRC->m_nicklist.m_sUserModeSymbols = message.Mid( prefixEnd+1, prefixEnd-prefixStart-8);
							m_pwndIRC->m_nicklist.m_sUserModeSymbols.Replace( _T("\004"), _T("%") );

						}
					}
					int chanmodesStart = message.Find(_T("CHANMODES=")) ;
					int chanmodesEnd = -1;
					if( chanmodesStart != -1 )
					{
						chanmodesEnd = message.Find(_T(","), chanmodesStart );
						if( chanmodesEnd != -1 )
						{
							chanmodesStart += 10;
							//Mode that adds or removes a nick or address to a list. Always has a parameter.
							//Modes of type A return the list when there is no parameter present.
							m_pwndIRC->m_channelselect.m_sChannelModeSettingsTypeA = message.Mid( chanmodesStart, chanmodesEnd-chanmodesStart );
							m_pwndIRC->m_channelselect.m_sChannelModeSettingsTypeA.Replace( _T("\004"), _T("%") );
						}
					}
					chanmodesStart = chanmodesEnd+1;
					if( chanmodesStart != -1 )
					{
						chanmodesEnd = message.Find(_T(","), chanmodesStart );
						if( chanmodesEnd != -1 )
						{
							//Mode that changes a setting and always has a parameter.
							m_pwndIRC->m_channelselect.m_sChannelModeSettingsTypeB = message.Mid( chanmodesStart, chanmodesEnd-chanmodesStart );
							m_pwndIRC->m_channelselect.m_sChannelModeSettingsTypeB.Replace( _T("\004"), _T("%") );
						}
					}
					chanmodesStart = chanmodesEnd+1;
					if( chanmodesStart != -1 )
					{
						chanmodesEnd = message.Find(_T(","), chanmodesStart );
						if( chanmodesEnd != -1 )
						{
							//Mode that changes a setting and only has a parameter when set.
							m_pwndIRC->m_channelselect.m_sChannelModeSettingsTypeC = message.Mid( chanmodesStart, chanmodesEnd-chanmodesStart );
							m_pwndIRC->m_channelselect.m_sChannelModeSettingsTypeC.Replace( _T("\004"), _T("%") );
						}
					}
					chanmodesStart = chanmodesEnd+1;
					if( chanmodesStart != -1 )
					{
						chanmodesEnd = message.Find(_T(" "), chanmodesStart );
						if( chanmodesEnd != -1 )
						{
							//Mode that changes a setting and never has a parameter.
							m_pwndIRC->m_channelselect.m_sChannelModeSettingsTypeD = message.Mid( chanmodesStart, chanmodesEnd-chanmodesStart );
							m_pwndIRC->m_channelselect.m_sChannelModeSettingsTypeD.Replace( _T("\004"), _T("%") );
						}
					}
					m_pwndIRC->AddStatus( message );
					return;
				}

                //- Reply format used by USERHOST to list replies to
                //the query list.  The reply string is composed as
				//follows:
				//
				//reply = nickname [ "*" ] "=" ( "+" / "-" ) hostname
				//
				//The '*' indicates whether the client has registered
				//as an Operator.  The '-' or '+' characters represent
				//whether the client has set an AWAY message or not
                //respectively.
				//302    RPL_USERHOST
				//":*1<reply> *( " " <reply> )"
				case 302:
				{
					m_pwndIRC->AddStatus( message );
					return;
				}

				//- Reply format used by ISON to list replies to the
				//query list.
					
				//303    RPL_ISON
				//":*1<nick> *( " " <nick> )"
				case 303:
				{
					m_pwndIRC->AddStatus( message );
					return;
				}

⌨️ 快捷键说明

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