📄 baseclient.cpp
字号:
break;
case ET_UDPPORT:
m_nUDPPort = temptag->tag->intvalue;
break;
case ET_UDPVER:
m_byUDPVer = temptag->tag->intvalue;
break;
case ET_SOURCEEXCHANGE:
m_bySourceExchangeVer = temptag->tag->intvalue;
break;
case ET_COMMENTS:
m_byAcceptCommentVer = temptag->tag->intvalue;
break;
case ET_EXTENDEDREQUEST:
m_byExtendedRequestsVer = temptag->tag->intvalue;
break;
case ET_COMPATIBLECLIENT:
m_byCompatibleClient = temptag->tag->intvalue;
break;
}
delete temptag;
}
if( m_byDataCompVer == 0 ){
m_bySourceExchangeVer = 0;
m_byExtendedRequestsVer = 0;
m_byAcceptCommentVer = 0;
m_nUDPPort = 0;
}
delete data;
ReGetClientSoft();
}
void CUpDownClient::SendHelloAnswer(){
CMemFile* data = new CMemFile();
SendHelloTypePacket(data);
Packet* packet = new Packet(data);
delete data;
packet->opcode = OP_HELLOANSWER;
if (socket){
theApp.uploadqueue->AddUpDataOverheadOther(packet->size);
socket->SendPacket(packet,true);
}
}
void CUpDownClient::SendHelloTypePacket(CMemFile* data){
data->Write(theApp.glob_prefs->GetUserHash(),16);
uint32 clientid = theApp.serverconnect->GetClientID();
data->Write(&clientid,4);
uint16 nPort = theApp.glob_prefs->GetPort();
data->Write(&nPort,2);
uint32 tagcount = 2;
data->Write(&tagcount,4);
CTag* tag = new CTag(CT_NAME,theApp.glob_prefs->GetUserNick());
tag->WriteTagToFile(data);
delete tag;
tag = new CTag(CT_VERSION,EDONKEYVERSION);
tag->WriteTagToFile(data);
delete tag;
// tag = new CTag(CT_PORT,theApp.glob_prefs->GetPort());
// tag->WriteTagToFile(data);
// delete tag;
uint32 dwIP;
if (theApp.serverconnect->IsConnected()){
dwIP = theApp.serverconnect->GetCurrentServer()->GetIP();
nPort = theApp.serverconnect->GetCurrentServer()->GetPort();
}
else{
nPort = 0;
dwIP = 0;
}
data->Write(&dwIP,4);
data->Write(&nPort,2);
}
void CUpDownClient::ProcessMuleCommentPacket(char* pachPacket, uint32 nSize){
if( reqfile ){
if( reqfile->IsPartFile()){
int length;
if (nSize>(sizeof(m_iRate)+sizeof(length)-1)){
CSafeMemFile data((BYTE*)pachPacket,nSize);
data.Read(&m_iRate,sizeof(m_iRate));
data.Read(&length,sizeof(length));
reqfile->SetHasRating(true);
theApp.emuledlg->AddDebugLogLine(false,GetResString(IDS_RATINGRECV),m_pszClientFilename,m_iRate);
if ( length > data.GetLength() - data.GetPosition() ){
length = data.GetLength() - data.GetPosition();
}
if (length>50) length=50;
if (length>0){
char* desc=new char[length+1];
memset(desc,0,length+1);
data.Read(desc,length);
theApp.emuledlg->AddDebugLogLine(false,GetResString(IDS_DESCRIPTIONRECV), m_pszClientFilename, desc);
m_strComment.Format("%s",desc);
reqfile->SetHasComment(true);
// test if comment is filtered
if (theApp.glob_prefs->GetCommentFilter().GetLength()>0) {
CString resToken;
CString strlink=theApp.glob_prefs->GetCommentFilter();
strlink.MakeLower();
int curPos=0;
resToken= strlink.Tokenize("|",curPos);
while (resToken != "") {
if (m_strComment.MakeLower().Find(resToken)>-1) {
m_strComment="";
m_iRate=0;
reqfile->SetHasRating(false);
reqfile->SetHasComment(false);
break;
}
resToken= strlink.Tokenize("|",curPos);
}
}
delete desc;
}
}
if (reqfile->HasRating() || reqfile->HasComment()) theApp.emuledlg->transferwnd.downloadlistctrl.UpdateItem(reqfile);
}
}
}
void CUpDownClient::Disconnected(){
ASSERT(theApp.clientlist->Debug_IsValidClient(this));
if (GetUploadState() == US_UPLOADING)
theApp.uploadqueue->RemoveFromUploadQueue(this);
if (GetDownloadState() == DS_DOWNLOADING){
SetDownloadState(DS_ONQUEUE);
}
if ((GetDownloadState() == DS_REQHASHSET) && (reqfile))
reqfile->hashsetneeded= true;
ASSERT(theApp.clientlist->Debug_IsValidClient(this));
//check if this client is needed in any way, if not delete it
bool bDelete = true;
switch(m_byUploadState){
case US_ONUPLOADQUEUE:
bDelete = false;
// default:
// this->SetUploadFileID(NULL);
};
switch(m_nDownloadState){
case DS_ONQUEUE:
case DS_TOOMANYCONNS:
case DS_NONEEDEDPARTS:
case DS_LOWTOLOWIP:
bDelete = false;
};
switch(m_byUploadState){
case US_CONNECTING:
case US_WAITCALLBACK:
case US_ERROR:
bDelete = true;
};
switch(m_nDownloadState){
case DS_CONNECTING:
{
m_cFailed++;
if (m_cFailed <= 2){
TryToConnect();
return;
}
}
case DS_WAITCALLBACK:
case DS_ERROR:
bDelete = true;
};
if (GetChatState()){
bDelete = false;
theApp.emuledlg->chatwnd.chatselector.ConnectingResult(this,false);
}
if (socket){
ASSERT (theApp.listensocket->IsValidSocket(socket));
socket->Safe_Delete();
}
socket = 0;
if (m_iFileListRequested){
theApp.emuledlg->AddDebugLogLine(false,GetResString(IDS_SHAREDFILES_FAILED),GetUserName());
m_iFileListRequested = 0;
}
if (m_Friend)
theApp.friendlist->RefreshFriend(m_Friend);
theApp.emuledlg->transferwnd.clientlistctrl.RefreshClient(this);
if (bDelete){
delete this;
}
}
void CUpDownClient::TryToConnect(bool bIgnoreMaxCon){
if (theApp.listensocket->TooManySockets() && !bIgnoreMaxCon && !(socket && socket->IsConnected())){
Disconnected();
return;
}
if ((theApp.serverconnect->GetClientID() < 16777216) && HasLowID()){
if (GetDownloadState() == DS_CONNECTING)
SetDownloadState(DS_LOWTOLOWIP);
else if (GetDownloadState() == DS_REQHASHSET){
SetDownloadState(DS_ONQUEUE);
reqfile->hashsetneeded = true;
}
if (GetUploadState() == US_CONNECTING){
Disconnected();
}
}
if (!socket){
socket = new CClientReqSocket(theApp.glob_prefs,this);
if (!socket->Create()){
socket->Safe_Delete();
return;
}
}
else if (!socket->IsConnected()){
socket->Safe_Delete();
socket = new CClientReqSocket(theApp.glob_prefs,this);
if (!socket->Create()){
socket->Safe_Delete();
return;
}
}
else{
ConnectionEstablished();
return;
}
// MOD Note: Do not change this part - Merkur
if (HasLowID()){
if (GetDownloadState() == DS_CONNECTING)
SetDownloadState(DS_WAITCALLBACK);
if (GetUploadState() == US_CONNECTING){
Disconnected();
return;
}
if (theApp.serverconnect->IsLocalServer(m_dwServerIP,m_nServerPort)){
Packet* packet = new Packet(OP_CALLBACKREQUEST,4);
memcpy(packet->pBuffer,&m_nUserID,4);
theApp.uploadqueue->AddUpDataOverheadServer(packet->size);
theApp.serverconnect->SendPacket(packet);
}
else{
if (GetUploadState() == US_NONE && (!GetRemoteQueueRank() || m_bReaskPending) ){
theApp.downloadqueue->RemoveSource(this);
Disconnected();
return;
}
else{
if (GetDownloadState() == DS_WAITCALLBACK){
m_bReaskPending = true;
SetDownloadState(DS_ONQUEUE);
}
}
}
}
// MOD Note - end
else{
socket->Connect(GetFullIP(),GetUserPort());
SendHelloPacket();
}
}
void CUpDownClient::ConnectionEstablished(){
m_cFailed = 0;
// ok we have a connection, lets see if we want anything from this client
if (GetChatState() == MS_CONNECTING)
theApp.emuledlg->chatwnd.chatselector.ConnectingResult(this,true);
switch(GetDownloadState()){
case DS_CONNECTING:
case DS_WAITCALLBACK:
m_bReaskPending = false;
SetDownloadState(DS_CONNECTED);
SendFileRequest();
}
if (m_bReaskPending){
m_bReaskPending = false;
if (GetDownloadState() != DS_NONE && GetDownloadState() != DS_DOWNLOADING){
SetDownloadState(DS_CONNECTED);
SendFileRequest();
}
}
switch(GetUploadState()){
case US_CONNECTING:
case US_WAITCALLBACK:
if (theApp.uploadqueue->IsDownloading(this)){
SetUploadState(US_UPLOADING);
Packet* packet = new Packet(OP_ACCEPTUPLOADREQ,0);
theApp.uploadqueue->AddUpDataOverheadFileRequest(packet->size);
socket->SendPacket(packet,true);
}
}
if (m_iFileListRequested == 1){
Packet* packet = new Packet((GetClientSoft()==SO_EDONKEYHYBRID) ? OP_ASKSHAREDDIRS : OP_ASKSHAREDFILES,0);
theApp.uploadqueue->AddUpDataOverheadOther(packet->size);
socket->SendPacket(packet,true,true);
}
}
void CUpDownClient::ReGetClientSoft(){
if (!m_pszUsername) {m_clientSoft=SO_UNKNOWN;return;}
if (m_achUserHash[5] == 13 && m_achUserHash[14] == 110) {m_clientSoft= SO_OLDEMULE;return;}
if (m_achUserHash[5] == 14 && m_achUserHash[14] == 111){
if( m_byEmuleVersion!=0x99 ){
CString temp;
temp.Format( "%02X", m_byEmuleVersion );
m_nClientVersion = atoi(temp.GetBuffer())*10;
}
switch(m_byCompatibleClient){
case SO_CDONKEY:
m_clientSoft = SO_CDONKEY;
break;
case SO_LMULE:
m_clientSoft = SO_LMULE;
break;
default:
m_clientSoft = SO_EMULE;
}
return;
}
if (m_achUserHash[5] == 'M' && m_achUserHash[14] == 'L') {m_clientSoft= SO_MLDONKEY;return;}
if( m_bIsHybrid )
m_clientSoft=SO_EDONKEYHYBRID;
else
m_clientSoft=SO_EDONKEY;
}
void CUpDownClient::SetUserName(char* pszNewName){
if (m_pszUsername)
delete[] m_pszUsername;
if( pszNewName )
m_pszUsername = nstrdup(pszNewName);
else
m_pszUsername = NULL;
}
void CUpDownClient::RequestSharedFileList(){
theApp.emuledlg->AddDebugLogLine(true,GetResString(IDS_SHAREDFILES_REQUEST),GetUserName());
m_iFileListRequested = 1;
TryToConnect(true);
}
void CUpDownClient::ProcessSharedFileList(char* pachPacket, uint32 nSize){
if (m_iFileListRequested > 0){
m_iFileListRequested--;
theApp.searchlist->ProcessSearchanswer(pachPacket,nSize,this);
}
}
// Webserber [kuchin]
CString CUpDownClient::GetUploadFileInfo()
{
if(this == NULL) return "";
CString sRet;
// build info text and display it
sRet.Format(GetResString(IDS_USERINFO), GetUserName(), GetUserID());
if (reqfile)
{
sRet += GetResString(IDS_SF_REQUESTED) + CString(reqfile->GetFileName()) + "\n";
CString stat;
stat.Format(GetResString(IDS_FILESTATS_SESSION)+GetResString(IDS_FILESTATS_TOTAL),
reqfile->statistic.GetAccepts(), reqfile->statistic.GetRequests(), reqfile->statistic.GetTransferred(),
reqfile->statistic.GetAllTimeAccepts(), reqfile->statistic.GetAllTimeRequests(), reqfile->statistic.GetAllTimeTransferred());
sRet += stat;
}
else
{
sRet += GetResString(IDS_REQ_UNKNOWNFILE);
}
return sRet;
return "";
}
void CUpDownClient::SetUserHash(uchar* m_achTempUserHash){
if( m_achTempUserHash == NULL ){
for( int i = 0; i <16; i++)
m_achUserHash[i] = 0;
return;
}
memcpy(m_achUserHash,m_achTempUserHash,16);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -