📄 ircmain.cpp
字号:
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "StdAfx.h"
#include "ircmain.h"
#include "emule.h"
#include "ED2KLink.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
CIrcMain::CIrcMain(void)
{
m_pwndIRC = 0; // i_a
preParseBuffer = "";
srand( (unsigned)time( NULL ) );
}
CIrcMain::~CIrcMain(void)
{
}
void CIrcMain::PreParseMessage( CString buffer ){
CString rawMessage;
preParseBuffer += buffer;
int test = preParseBuffer.Find('\n');
while( test != -1 ){
rawMessage = preParseBuffer.Left(test);
rawMessage.Replace( "\n", "" );
rawMessage.Replace( "\r", "" );
ParseMessage( rawMessage );
preParseBuffer = preParseBuffer.Mid(test+1);
test = preParseBuffer.Find("\n");
}
}
extern void URLDecode(CString& result, const char* buff);
void CIrcMain::ProcessLink( CString ed2kLink ) {
try {
CString link;
URLDecode(link,(const char*)ed2kLink.GetBuffer());
CED2KLink* pLink = CED2KLink::CreateLinkFromUrl(link);
_ASSERT( pLink !=0 );
switch (pLink->GetKind()) {
case CED2KLink::kFile:
{
CED2KFileLink* pFileLink = pLink->GetFileLink();
_ASSERT(pFileLink !=0);
theApp.downloadqueue->AddFileLinkToDownload(pFileLink);
}
break;
case CED2KLink::kServerList:
{
CED2KServerListLink* pListLink = pLink->GetServerListLink();
_ASSERT( pListLink !=0 );
CString strAddress = pListLink->GetAddress();
if(strAddress.GetLength() != 0)
theApp.emuledlg->serverwnd.UpdateServerMetFromURL(strAddress);
}
break;
case CED2KLink::kServer:
{
CString defName;
CED2KServerLink* pSrvLink = pLink->GetServerLink();
_ASSERT( pSrvLink !=0 );
in_addr host;
host.S_un.S_addr = pSrvLink->GetIP();
CServer* pSrv = new CServer(pSrvLink->GetPort(),inet_ntoa(host));
_ASSERT( pSrv !=0 );
pSrvLink->GetDefaultName(defName);
pSrv->SetListName(defName.GetBuffer());
// Barry - Default all new irc servers to high priority
if( theApp.glob_prefs->GetManualHighPrio() )
pSrv->SetPreference(SRV_PR_HIGH);
if (!theApp.emuledlg->serverwnd.serverlistctrl.AddServer(pSrv,true))
delete pSrv;
else theApp.emuledlg->AddLogLine(true,GetResString(IDS_SERVERADDED)+CString(pSrv->GetListName()));
}
break;
default:
break;
}
delete pLink;
} catch(...) {
OUTPUT_DEBUG_TRACE();
theApp.emuledlg->AddLogLine(true, GetResString(IDS_LINKNOTADDED));
}
}
void CIrcMain::ParseMessage( CString rawMessage ){
if( rawMessage.Left(6) == "PING :" ){
ircsocket->SendString( "PONG " + rawMessage.Right(rawMessage.GetLength()-6) );
m_pwndIRC->AddStatus( "PING?/PONG" );
return;
}
rawMessage.Replace( "%", "\004" );
CString source = "";
int sourceIndex = -1;
CString sourceIp = "";
int sourceIpIndex = -1;
CString command = "";
int commandIndex = -1;
CString target = "";
int targetIndex = -1;
CString target2 = "";
int target2Index = -1;
CString message = "";
int messageIndex = -1;
sourceIndex = rawMessage.Find( '!' );
commandIndex = rawMessage.Find( ' ' );
targetIndex = rawMessage.Find( ' ', commandIndex + 1);
command = rawMessage.Mid( commandIndex + 1, targetIndex - commandIndex - 1);
if( sourceIndex < commandIndex && sourceIndex > 0){
source = rawMessage.Mid( 1, sourceIndex - 1);
sourceIp = rawMessage.Mid( sourceIndex + 1, commandIndex - sourceIndex - 1);
messageIndex = rawMessage.Find( ' ', targetIndex + 1);
if( messageIndex > sourceIndex ){
target = rawMessage.Mid( targetIndex + 1, messageIndex - targetIndex - 1);
message = rawMessage.Mid( messageIndex );
if( target.Left(1) == ":" )
target = target.Mid(1);
if( message.Left(1) == ":" )
message = message.Mid(1);
if( target.Left(2) == " :" )
target = target.Mid(2);
if( message.Left(2) == " :" )
message = message.Mid(2);
}
else{
target = rawMessage.Mid( targetIndex + 1, rawMessage.GetLength() - targetIndex - 1);
if( target.Left(1) == ":" )
target = target.Mid(1);
if( message.Left(1) == ":" )
message = message.Mid(1);
if( target.Left(2) == " :" )
target = target.Mid(2);
if( message.Left(2) == " :" )
message = message.Mid(2);
}
}
else{
source = rawMessage.Mid( 1, commandIndex - 1);
message = rawMessage.Mid( targetIndex + 1);
}
if( command == "PRIVMSG" ){
if ( target.Left(1) == "#" ){
if( message.Left(1) == "\001" ){
message = message.Mid( 1, message.GetLength() - 2);
if( message.Left(6) == "ACTION" ){
m_pwndIRC->AddInfoMessage( target, "* %s%s", source, message.Mid(6) );
return;
}
if( message.Left(7) == "VERSION"){
version = "eMule" + (CString)CURRENT_VERSION_LONG + (CString)Irc_Version;
CString build;
build.Format( "NOTICE %s :\001VERSION %s\001", source, version );
ircsocket->SendString( build );
return;
}
}
else{
m_pwndIRC->AddMessage( target, source, message);
return;
}
}
else{
if( message.Left(1) == "\001" ){
message = message.Mid(1, message.GetLength() -2);
if( message.Left(6) == "ACTION"){
m_pwndIRC->AddInfoMessage( source, "* %s%s", source, message.Mid(6) );
return;
}
if( message.Left(7) == "VERSION"){
version = "eMule" + (CString)CURRENT_VERSION_LONG + (CString)Irc_Version;
CString build;
build.Format( "NOTICE %s :\001VERSION %s\001", source, version );
ircsocket->SendString( build );
}
if( message.Left(9) == "REQSFRIEND" ){
message = message.Mid(9);
int index1 = message.Find( "|" );
if( index1 == -1 || index1 == message.GetLength() )
return;
int index2 = message.Find( "|", index1+1 );
if( index2 == -1 || index1 > index2 )
return;
CString sverify = message.Mid(index1+1, index2-index1-1);
CString build;
if( theApp.serverconnect->IsConnected() ){
CString clientId;
clientId.Format( "%i", theApp.serverconnect->GetClientID());
CString clientPort;
clientPort.Format( "%i", theApp.glob_prefs->GetPort());
CString sip;
sip.Format( "%i", theApp.serverconnect->GetCurrentServer()->GetIP());
CString sport;
sport.Format( "%i", theApp.serverconnect->GetCurrentServer()->GetPort());
CString send = "eMule" + (CString)CURRENT_VERSION_LONG + (CString)Irc_Version + "|" + sverify + "|" + clientId + ":" + clientPort + "|" + sip + ":" + sport + "|";
build.Format( "PRIVMSG %s :\001RSPFRIEND %s\001", source, send );
}
else{
build.Format( "PRIVMSG %s :\001REPFRIEND %s\001", source, version );
}
ircsocket->SendString( build );
build.Format( "%s %s", source, GetResString(IDS_IRC_ADDASFRIEND));
if( !theApp.glob_prefs->GetIrcIgnoreEmuleProtoInfoMessage() )
m_pwndIRC->NoticeMessage( "*EmuleProto*", build );
return;
}
if( message.Left(8) == "SENDLINK" ){
//Needs more coding (Mainly security) before releasing.
/* message = message.Mid(8);
int index1, index2;
index1 = message.Find( "|" );
if( index1 == -1 || index1 == message.GetLength() )
return;
index2 = message.Find( "|", index1+1 );
if( index2 == -1 || index1 > index2 )
return;
CString sverify = message.Mid(index1+1, index2-index1-1);
if( verify != atoi(sverify))
return;
if ( !theApp.glob_prefs->GetIrcAcceptLinks() )
return;
CString RecieveString, build;
if( message.Find( '|' ) != -1 ){
RecieveString = message.Mid( message.Find('|')+1 );
if( !RecieveString.IsEmpty() ){
build.Format( GetResString(IDS_IRC_RECIEVEDLINK), source, RecieveString );
if( !theApp.glob_prefs->GetIrcIgnoreInfoMessage() )
m_pwndIRC->NoticeMessage( "*EmuleProto*", build );
ProcessLink( RecieveString );
}
}
*/ return;
}
if( message.Left(9) == "REPFRIEND" ){
message = message.Mid(9);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -