bool CKnownFileList::LoadKnownFiles() { CString fullpath = thePrefs.GetMuleDirectory(EMULE_CONFIGDIR); fullpath.Append(KNOWN_MET_FILENAME); CSafeBufferedFile file; CFileException fexp; if (!file.Open(fullpath,CFile::modeRead|CFile::osSequentialScan|CFile::typeBinary|CFile::shareDenyWrite, &fexp)){ if (fexp.m_cause != CFileException::fileNotFound){ CString strError(_T("Failed to load ") KNOWN_MET_FILENAME _T(" file")); TCHAR szError[MAX_CFEXP_ERRORMSG]; if (fexp.GetErrorMessage(szError, ARRSIZE(szError))){ strError += _T(" - "); strError += szError; } LogError(LOG_STATUSBAR, _T("%s"), strError); } return false; } setvbuf(file.m_pStream, NULL, _IOFBF, 16384); CKnownFile* pRecord = NULL; try { uint8 header = file.ReadUInt8(); if (header != MET_HEADER && header != MET_HEADER_I64TAGS){ file.Close(); LogError(LOG_STATUSBAR, GetResString(IDS_ERR_SERVERMET_BAD)); return false; } AddDebugLogLine(false, _T("Known.met file version is %u (%s support 64bit tags)"), header, (header == MET_HEADER) ? _T("doesn't") : _T("does")); UINT RecordsNumber = file.ReadUInt32(); for (UINT i = 0; i < RecordsNumber; i++) { pRecord = new CKnownFile(); if (!pRecord->LoadFromFile(&file)){ TRACE(_T("*** Failed to load entry %u (name=%s hash=%s size=%I64u parthashs=%u expected parthashs=%u) from known.met\n"), i, pRecord->GetFileName(), md4str(pRecord->GetFileHash()), pRecord->GetFileSize(), pRecord->GetHashCount(), pRecord->GetED2KPartHashCount()); delete pRecord; pRecord = NULL; continue; } SafeAddKFile(pRecord); pRecord = NULL; } file.Close(); } catch(CFileException* error){ if (error->m_cause == CFileException::endOfFile) LogError(LOG_STATUSBAR, GetResString(IDS_ERR_SERVERMET_BAD)); else{ TCHAR buffer[MAX_CFEXP_ERRORMSG]; error->GetErrorMessage(buffer, ARRSIZE(buffer)); LogError(LOG_STATUSBAR, GetResString(IDS_ERR_SERVERMET_UNKNOWN),buffer); } error->Delete(); delete pRecord; return false; } return true; }
void CAbstractFile::LoadComment() { CIni ini(thePrefs.GetFileCommentsFilePath(), md4str(GetFileHash())); m_strComment = ini.GetStringUTF8(_T("Comment")).Left(MAXFILECOMMENTLEN); m_uRating = ini.GetInt(_T("Rate"), 0); m_bCommentLoaded = true; }
CString GetValue(const CTag* pTag) { CString strValue; if (pTag->IsStr()) strValue = pTag->GetStr(); else if (pTag->IsInt()) { if (pTag->GetNameID() == FT_MEDIA_LENGTH || pTag->GetNameID() == FT_LASTSEENCOMPLETE) SecToTimeLength(pTag->GetInt(), strValue); else if (pTag->GetNameID() == FT_FILERATING) strValue = GetRateString(pTag->GetInt()); else if (pTag->GetNameID() == 0x10 || pTag->GetNameID() >= 0xFA) strValue.Format(_T("%u"), pTag->GetInt()); else strValue = GetFormatedUInt(pTag->GetInt()); } else if (pTag->IsFloat()) strValue.Format(_T("%f"), pTag->GetFloat()); else if (pTag->IsHash()) strValue = md4str(pTag->GetHash()); else if (pTag->IsInt64(false)) strValue = GetFormatedUInt64(pTag->GetInt64()); else strValue.Format(_T("<Unknown value of type 0x%02X>"), pTag->GetType()); return strValue; }
//You can add a friend without a IP to allow the IRC to trade links with lowID users. bool CFriendList::AddFriend(const uchar* abyUserhash, uint32 dwLastSeen, uint32 dwLastUsedIP, uint16 nLastUsedPort, uint32 dwLastChatted, LPCTSTR pszName, uint32 dwHasHash){ // client must have an IP (HighID) or a hash // TODO: check if this can be switched to a hybridID so clients with *.*.*.0 can be added.. if (IsLowID(dwLastUsedIP) && dwHasHash==0) return false; if (SearchFriend(abyUserhash, dwLastUsedIP, nLastUsedPort) != NULL) return false; CFriend* Record = new CFriend( abyUserhash, dwLastSeen, dwLastUsedIP, nLastUsedPort, dwLastChatted, pszName, dwHasHash ); m_listFriends.AddTail(Record); ShowFriends(); SaveList(); // Mighty Knife: log friend activities if (thePrefs.GetLogFriendlistActivities ()) { #ifdef MIGHTY_TWEAKS AddLogLine(false, GetResString(IDS_NEWFRIEND)+_T(" '%s', ip %i.%i.%i.%i:%i, ")+GetResString(IDS_CD_UHASH)+_T(" %s"), Record->m_strName, (uint8)Record->m_dwLastUsedIP, (uint8)(Record->m_dwLastUsedIP>>8), (uint8)(Record->m_dwLastUsedIP>>16),(uint8)(Record->m_dwLastUsedIP>>24), Record->m_nLastUsedPort, md4str(Record->m_abyUserhash)); #else AddLogLine(false, GetResString(IDS_NEWFRIEND)+_T(" '%s', ")+GetResString(IDS_CD_UHASH)+_T(" %s"), Record->m_strName, md4str(Record->m_abyUserhash)); #endif }
void CFriend::KadSearchNodeIDByIPResult(Kademlia::EKadClientSearchRes eStatus, const uchar* pachNodeID){ if (!theApp.friendlist->IsValid(this)) { ASSERT( false ); return; } if (eStatus == Kademlia::KCSR_SUCCEEDED){ ASSERT( pachNodeID != NULL ); DebugLog(_T("Successfully fetched KadID (%s) for friend %s"), md4str(pachNodeID), m_strName.IsEmpty() ? _T("(Unknown)") : m_strName); md4cpy(m_abyKadID, pachNodeID); } else DebugLog(_T("Failed to fetch KadID for friend %s (%s)"), m_strName.IsEmpty() ? _T("(Unknown)") : m_strName, ipstr(m_dwLastUsedIP)); }
CStringA CUrlSrcGetFromSvrSocket::GetUrlPath() { if (::IsBadReadPtr(m_pMgr, sizeof(CUrlSrcFromSvrMgr))) return ""; CStringA strUrlPath; CStringA strHash; CStringA strSize; CStringA strFileName; CStringA strEncodedFileName; if( NULL==m_pMgr->m_pAssocPartFile ) return ""; try { // Hash strHash = md4str(m_pMgr->m_pAssocPartFile->GetFileHash()); strHash.MakeLower(); //必须都为小写。 // Size char szSize[1024]; _i64toa(m_pMgr->m_pAssocPartFile->GetFileSize(), szSize,10); strSize = szSize; //strHash = "48F8220C4FF02D4E5AD11DD5E1E305CB"; //strHash.MakeLower(); //strSize = "125753277"; //lptszFileName = _T("PopKart_Setup_P092.exe"); // FileName strEncodedFileName = EncodeUrlUtf8(m_pMgr->m_pAssocPartFile->GetFileName()); // construct UrlPath //strUrlPath.Format("http://client.stat.verycd.com/dl/%s%s/%s/start", strHash, strSize, strEncodedFileName); if (m_bStart) strUrlPath.Format("/dl/%s%s/%s/start", strHash, strSize, strEncodedFileName); else strUrlPath.Format("/dl/%s%s/%s/finished", strHash, strSize, strEncodedFileName); return strUrlPath; } catch ( ... ) { return ""; } }
void CFriend::KadSearchIPByNodeIDResult(Kademlia::EKadClientSearchRes eStatus, uint32_t dwIP, uint16_t nPort){ if (!theApp.friendlist->IsValid(this)) { ASSERT( false ); return; } if (m_FriendConnectState == FCS_KADSEARCHING ){ if (eStatus == Kademlia::KCSR_SUCCEEDED && GetLinkedClient(true) != NULL){ DebugLog(_T("Successfully fetched IP (%s) by KadID (%s) for friend %s"), ipstr(dwIP), md4str(m_abyKadID), m_strName.IsEmpty() ? _T("(Unknown)") : m_strName); if (GetLinkedClient()->GetIP() != dwIP || GetLinkedClient()->GetUserPort() != nPort){ // retry to connect with our new found IP for (POSITION pos = m_liConnectionReport.GetHeadPosition(); pos != 0; m_liConnectionReport.GetNext(pos)){ m_liConnectionReport.GetAt(pos)->ReportConnectionProgress(GetLinkedClient(), _T(" ...") + GetResString(IDS_FOUND) + _T("\n"), true); m_liConnectionReport.GetAt(pos)->ReportConnectionProgress(m_LinkedClient, _T("*** ") + GetResString(IDS_CONNECTING), false); } m_FriendConnectState = FCS_CONNECTING; m_LinkedClient->SetChatState(MS_CONNECTING); if (m_LinkedClient->socket != NULL && m_LinkedClient->socket->IsConnected()) { // we shouldnt get he since we checked for FCS_KADSEARCHING ASSERT( false ); UpdateFriendConnectionState(FCR_ESTABLISHED); } m_dwLastUsedIP = dwIP; m_nLastUsedPort = nPort; m_LinkedClient->SetIP(dwIP); m_LinkedClient->SetUserPort(nPort); m_LinkedClient->TryToConnect(true); return; } else DebugLog(_T("KadSearchIPByNodeIDResult: Result IP is the same as known (not working) IP (%s)"), ipstr(dwIP)); } DebugLog(_T("Failed to fetch IP by KadID (%s) for friend %s"), md4str(m_abyKadID), m_strName.IsEmpty() ? _T("(Unknown)") : m_strName); // here ends our journey to connect to our friend unsuccessfully m_FriendConnectState = FCS_NONE; for (POSITION pos = m_liConnectionReport.GetHeadPosition(); pos != 0;) m_liConnectionReport.GetNext(pos)->ConnectingResult(GetLinkedClient(), false); m_liConnectionReport.RemoveAll(); } else ASSERT( false ); }
BOOL CAddFriend::OnInitDialog() { CDialog::OnInitDialog(); InitWindowStyles(this); Localize(); if (m_pShowFriend) { SetIcon(m_icnWnd = theApp.LoadIcon(_T("ClientDetails")), FALSE); SendDlgItemMessage(IDC_IP, EM_SETREADONLY, TRUE); SendDlgItemMessage(IDC_PORT, EM_SETREADONLY, TRUE); SendDlgItemMessage(IDC_USERNAME, EM_SETREADONLY, TRUE); SetDlgItemInt(IDC_IP, m_pShowFriend->m_dwLastUsedIP, FALSE); SetDlgItemInt(IDC_PORT, m_pShowFriend->m_nLastUsedPort, FALSE); SetDlgItemText(IDC_USERNAME, m_pShowFriend->m_strName); if (m_pShowFriend->m_dwHasHash) SetDlgItemText(IDC_USERHASH, md4str(m_pShowFriend->m_abyUserhash)); else SetDlgItemText(IDC_USERHASH, _T("")); if (m_pShowFriend->m_dwLastSeen){ CTime t((time_t)m_pShowFriend->m_dwLastSeen); SetDlgItemText(IDC_EDIT2, t.Format(thePrefs.GetDateTimeFormat())); } /*if (m_pShowFriend->m_dwLastChatted){ CTime t((time_t)m_pShowFriend->m_dwLastChatted); SetDlgItemText(IDC_LAST_CHATTED, t.Format(thePrefs.GetDateTimeFormat())); }*/ GetDlgItem(IDC_ADD)->ShowWindow(SW_HIDE); } else { SetIcon(m_icnWnd = theApp.LoadIcon(_T("AddFriend")), FALSE); ((CEdit*)GetDlgItem(IDC_USERNAME))->SetLimitText(thePrefs.GetMaxUserNickLength()); SetDlgItemText(IDC_USERHASH, _T("")); } return TRUE; }
void CSearchList::GetWebList(CQArray<SearchFileStruct, SearchFileStruct> *SearchFileArray, int iSortBy) const { for (POSITION pos = list.GetHeadPosition(); pos != NULL; ) { const CSearchFile* pFile = list.GetNext(pos); if (pFile == NULL || pFile->GetListParent() != NULL || pFile->GetFileSize() == 0 || pFile->GetFileName().IsEmpty()) continue; SearchFileStruct structFile; structFile.m_strFileName = pFile->GetFileName(); structFile.m_strFileType = pFile->GetFileTypeDisplayStr(); structFile.m_strFileHash = md4str(pFile->GetFileHash()); structFile.m_uSourceCount = pFile->GetSourceCount(); structFile.m_dwCompleteSourceCount = pFile->GetCompleteSourceCount(); structFile.m_uFileSize = pFile->GetFileSize(); switch (iSortBy) { case 0: structFile.m_strIndex = structFile.m_strFileName; break; case 1: structFile.m_strIndex.Format(_T("%10u"), structFile.m_uFileSize); break; case 2: structFile.m_strIndex = structFile.m_strFileHash; break; case 3: structFile.m_strIndex.Format(_T("%09u"), structFile.m_uSourceCount); break; case 4: structFile.m_strIndex = structFile.m_strFileType; break; default: structFile.m_strIndex.Empty(); } SearchFileArray->Add(structFile); } }
bool CServerSocket::ProcessPacket(char* packet, uint32 size, uint8 opcode) { try { switch(opcode) { case OP_SERVERMESSAGE: { if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("ServerMsg - OP_ServerMessage\n")); CServer* pServer = cur_server ? theApp.serverlist->GetServerByAddress(cur_server->GetAddress(),cur_server->GetPort()) : NULL; CSafeMemFile data((const BYTE*)packet, size); CString strMessages(data.ReadString(pServer ? pServer->GetUnicodeSupport() : false)); if (thePrefs.GetDebugServerTCPLevel() > 0) { UINT uAddData = data.GetLength() - data.GetPosition(); if (uAddData > 0) { Debug(_T("*** NOTE: OP_ServerMessage: ***AddData: %u bytes\n"), uAddData); DebugHexDump((uint8*)packet + data.GetPosition(), uAddData); } } // 16.40 servers do not send separate OP_SERVERMESSAGE packets for each line; // instead of this they are sending all text lines with one OP_SERVERMESSAGE packet. int iPos = 0; CString message = strMessages.Tokenize(_T("\r\n"), iPos); while (!message.IsEmpty()) { bool bOutputMessage = true; if (_tcsnicmp(message, _T("server version"), 14) == 0) { CString strVer = message.Mid(14); strVer.Trim(); strVer = strVer.Left(64); // truncate string to avoid misuse by servers in showing ads if (pServer) { pServer->SetVersion(strVer); theApp.emuledlg->serverwnd->serverlistctrl.RefreshServer(pServer); theApp.emuledlg->serverwnd->UpdateMyInfo(); } if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("%s\n"), message); } else if (_tcsncmp(message, _T("ERROR"), 5) == 0) { LogError(LOG_STATUSBAR, _T("%s %s (%s:%u) - %s"), GetResString(IDS_ERROR), pServer ? pServer->GetListName() : GetResString(IDS_PW_SERVER), cur_server ? cur_server->GetAddress() : _T(""), cur_server ? cur_server->GetPort() : 0, message.Mid(5).Trim(_T(" :"))); bOutputMessage = false; } else if (_tcsncmp(message, _T("WARNING"), 7) == 0) { LogWarning(LOG_STATUSBAR, _T("%s %s (%s:%u) - %s"), GetResString(IDS_WARNING), pServer ? pServer->GetListName() : GetResString(IDS_PW_SERVER), cur_server ? cur_server->GetAddress() : _T(""), cur_server ? cur_server->GetPort() : 0, message.Mid(7).Trim(_T(" :"))); bOutputMessage = false; } if (message.Find(_T("[emDynIP: ")) != -1 && message.Find(_T("]")) != -1 && message.Find(_T("[emDynIP: ")) < message.Find(_T("]"))) { CString dynip = message.Mid(message.Find(_T("[emDynIP: ")) + 10, message.Find(_T("]")) - (message.Find(_T("[emDynIP: ")) + 10)); dynip.Trim(_T(" ")); if (dynip.GetLength() && dynip.GetLength() < 51) { if (pServer) { pServer->SetDynIP(dynip); if (cur_server) cur_server->SetDynIP(dynip); theApp.emuledlg->serverwnd->serverlistctrl.RefreshServer(pServer); theApp.emuledlg->serverwnd->UpdateMyInfo(); } } } if (bOutputMessage) theApp.emuledlg->AddServerMessageLine(message); message = strMessages.Tokenize(_T("\r\n"), iPos); } break; } case OP_IDCHANGE: { if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("ServerMsg - OP_IDChange\n")); if (size < sizeof(LoginAnswer_Struct)) { throw GetResString(IDS_ERR_BADSERVERREPLY); } LoginAnswer_Struct* la = (LoginAnswer_Struct*)packet; // save TCP flags in 'cur_server' ASSERT( cur_server ); if (cur_server) { if (size >= sizeof(LoginAnswer_Struct)+4) { DWORD dwFlags = *((uint32*)(packet + sizeof(LoginAnswer_Struct))); if (thePrefs.GetDebugServerTCPLevel() > 0) { CString strInfo; strInfo.AppendFormat(_T(" TCP Flags=0x%08x"), dwFlags); const DWORD dwKnownBits = SRV_TCPFLG_COMPRESSION | SRV_TCPFLG_NEWTAGS | SRV_TCPFLG_UNICODE; if (dwFlags & ~dwKnownBits) strInfo.AppendFormat(_T(" ***UnkBits=0x%08x"), dwFlags & ~dwKnownBits); if (dwFlags & SRV_TCPFLG_COMPRESSION) strInfo.AppendFormat(_T(" Compression=1")); if (dwFlags & SRV_TCPFLG_NEWTAGS) strInfo.AppendFormat(_T(" NewTags=1")); if (dwFlags & SRV_TCPFLG_UNICODE) strInfo.AppendFormat(_T(" Unicode=1")); Debug(_T("%s\n"), strInfo); } cur_server->SetTCPFlags(dwFlags); } else cur_server->SetTCPFlags(0); // copy TCP flags into the server in the server list CServer* pServer = theApp.serverlist->GetServerByAddress(cur_server->GetAddress(), cur_server->GetPort()); if (pServer) pServer->SetTCPFlags(cur_server->GetTCPFlags()); } if (la->clientid == 0) { uint8 state = thePrefs.GetSmartIdState(); if ( state > 0 ) { state++; if( state > 3 ) thePrefs.SetSmartIdState(0); else thePrefs.SetSmartIdState(state); } break; } if( thePrefs.GetSmartIdCheck() ) { if (!IsLowID(la->clientid)) thePrefs.SetSmartIdState(1); else { uint8 state = thePrefs.GetSmartIdState(); if ( state > 0 ) { state++; if( state > 3 ) thePrefs.SetSmartIdState(0); else thePrefs.SetSmartIdState(state); break; } } } //==>Lowid retry by SlugFiller [cyrex2001] #ifdef LOWID if (thePrefs.GetLowIdRetried()) { if (la->clientid < 16777216 ) { SetConnectionState(CS_ERROR); AddLogLine(true,GetResString(IDS_LOWIDRETRYING),thePrefs.GetLowIdRetried()); thePrefs.SetLowIdRetried(); break; } } #endif //Lowid retry //<==Lowid retry [cyrex2001] // we need to know our client's HighID when sending our shared files (done indirectly on SetConnectionState) serverconnect->clientid = la->clientid; if (connectionstate != CS_CONNECTED) { SetConnectionState(CS_CONNECTED); theApp.OnlineSig(); // Added By Bouc7 } serverconnect->SetClientID(la->clientid); AddLogLine(false, GetResString(IDS_NEWCLIENTID), la->clientid); //==>Reask sourcen after ip change [cyrex2001] #ifdef RSAIC_MAELLA theApp.CheckIDChange(); #endif //Reask sourcen after ip change //<==Reask sourcen after ip change [cyrex2001] theApp.downloadqueue->ResetLocalServerRequests(); break; } case OP_SEARCHRESULT: { if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("ServerMsg - OP_SearchResult\n")); CServer* cur_srv = (serverconnect) ? serverconnect->GetCurrentServer() : NULL; CServer* pServer = cur_srv ? theApp.serverlist->GetServerByAddress(cur_srv->GetAddress(), cur_srv->GetPort()) : NULL; bool bMoreResultsAvailable; uint16 uSearchResults = theApp.searchlist->ProcessSearchanswer(packet, size, true/*pServer ? pServer->GetUnicodeSupport() : false*/, cur_srv ? cur_srv->GetIP() : 0, cur_srv ? cur_srv->GetPort() : 0, &bMoreResultsAvailable); theApp.emuledlg->searchwnd->LocalSearchEnd(uSearchResults, bMoreResultsAvailable); break; } case OP_FOUNDSOURCES: { if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("ServerMsg - OP_FoundSources; Sources=%u %s\n"), (UINT)(uchar)packet[16], DbgGetFileInfo((uchar*)packet)); ASSERT( cur_server ); if (cur_server) { CSafeMemFile sources((BYTE*)packet,size); uchar fileid[16]; sources.ReadHash16(fileid); if (CPartFile* file = theApp.downloadqueue->GetFileByID(fileid)) file->AddSources(&sources,cur_server->GetIP(), cur_server->GetPort()); } break; } case OP_SERVERSTATUS: { if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("ServerMsg - OP_ServerStatus\n")); // FIXME some statuspackets have a different size -> why? structur? if (size < 8) break;//throw "Invalid status packet"; uint32 cur_user = PeekUInt32(packet); uint32 cur_files = PeekUInt32(packet+4); CServer* update = cur_server ? theApp.serverlist->GetServerByAddress(cur_server->GetAddress(), cur_server->GetPort()) : NULL; if (update) { update->SetUserCount(cur_user); update->SetFileCount(cur_files); theApp.emuledlg->ShowUserCount(); theApp.emuledlg->serverwnd->serverlistctrl.RefreshServer( update ); theApp.emuledlg->serverwnd->UpdateMyInfo(); } if (thePrefs.GetDebugServerTCPLevel() > 0) { if (size > 8) { Debug(_T("*** NOTE: OP_ServerStatus: ***AddData: %u bytes\n"), size - 8); DebugHexDump((uint8*)packet + 8, size - 8); } } break; } case OP_SERVERIDENT: { // OP_SERVERIDENT - this is sent by the server only if we send a OP_GETSERVERLIST if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("ServerMsg - OP_ServerIdent\n")); if (size<16+4+2+4) { if (thePrefs.GetVerbose()) DebugLogError(_T("%s"), GetResString(IDS_ERR_KNOWNSERVERINFOREC)); break;// throw "Invalid server info received"; } CServer* pServer = cur_server ? theApp.serverlist->GetServerByAddress(cur_server->GetAddress(),cur_server->GetPort()) : NULL; CString strInfo; CSafeMemFile data((BYTE*)packet, size); uint8 aucHash[16]; data.ReadHash16(aucHash); if (thePrefs.GetDebugServerTCPLevel() > 0) strInfo.AppendFormat(_T("Hash=%s (%s)"), md4str(aucHash), DbgGetHashTypeString(aucHash)); uint32 nServerIP = data.ReadUInt32(); uint16 nServerPort = data.ReadUInt16(); if (thePrefs.GetDebugServerTCPLevel() > 0) strInfo.AppendFormat(_T(" IP=%s:%u"), ipstr(nServerIP), nServerPort); UINT nTags = data.ReadUInt32(); if (thePrefs.GetDebugServerTCPLevel() > 0) strInfo.AppendFormat(_T(" Tags=%u"), nTags); CString strName; CString strDescription; for (UINT i = 0; i < nTags; i++) { CTag tag(&data, pServer ? pServer->GetUnicodeSupport() : false); if (tag.GetNameID() == ST_SERVERNAME) { if (tag.IsStr()) { strName = tag.GetStr(); if (thePrefs.GetDebugServerTCPLevel() > 0) strInfo.AppendFormat(_T(" Name=%s"), strName); } } else if (tag.GetNameID() == ST_DESCRIPTION) { if (tag.IsStr()) { strDescription = tag.GetStr(); if (thePrefs.GetDebugServerTCPLevel() > 0) strInfo.AppendFormat(_T(" Desc=%s"), strDescription); } } else if (thePrefs.GetDebugServerTCPLevel() > 0) strInfo.AppendFormat(_T(" ***UnkTag: 0x%02x=%u"), tag.GetNameID(), tag.GetInt()); } if (thePrefs.GetDebugServerTCPLevel() > 0) { strInfo += _T('\n'); Debug(_T("%s"), strInfo); UINT uAddData = data.GetLength() - data.GetPosition(); if (uAddData > 0) { Debug(_T("*** NOTE: OP_ServerIdent: ***AddData: %u bytes\n"), uAddData); DebugHexDump((uint8*)packet + data.GetPosition(), uAddData); } } if (pServer) { pServer->SetListName(strName); pServer->SetDescription(strDescription); if (((uint32*)aucHash)[0] == 0x2A2A2A2A) { const CString& rstrVersion = pServer->GetVersion(); if (!rstrVersion.IsEmpty()) pServer->SetVersion(_T("eFarm ") + rstrVersion); else pServer->SetVersion(_T("eFarm")); } theApp.emuledlg->ShowConnectionState(); theApp.emuledlg->serverwnd->serverlistctrl.RefreshServer(pServer); theApp.emuledlg->serverwnd->UpdateMyInfo(); } break; } // tecxx 1609 2002 - add server's serverlist to own serverlist case OP_SERVERLIST: { if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("ServerMsg - OP_ServerList\n")); try { CSafeMemFile servers((BYTE*)packet,size); UINT count = servers.ReadUInt8(); // check if packet is valid if (1 + count*(4+2) > size) count = 0; int addcount = 0; while(count) { uint32 ip = servers.ReadUInt32(); uint16 port = servers.ReadUInt16(); CServer* srv = new CServer(port, ipstr(ip)); srv->SetListName(srv->GetFullIP()); if (!theApp.emuledlg->serverwnd->serverlistctrl.AddServer(srv, true)) delete srv; else addcount++; count--; } if (addcount) AddLogLine(false, GetResString(IDS_NEWSERVERS), addcount); if (thePrefs.GetDebugServerTCPLevel() > 0) { UINT uAddData = servers.GetLength() - servers.GetPosition(); if (uAddData > 0) { Debug(_T("*** NOTE: OP_ServerList: ***AddData: %u bytes\n"), uAddData); DebugHexDump((uint8*)packet + servers.GetPosition(), uAddData); } } } catch(CFileException* error) { if (thePrefs.GetVerbose()) DebugLogError(_T("%s"), GetResString(IDS_ERR_BADSERVERLISTRECEIVED)); error->Delete(); } break; } case OP_CALLBACKREQUESTED: { if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("ServerMsg - OP_CallbackRequested\n")); if (size == 6) { uint32 dwIP = PeekUInt32(packet); if (theApp.ipfilter->IsFiltered(dwIP)) { theStats.filteredclients++; if (thePrefs.GetLogFilteredIPs()) AddDebugLogLine(false, _T("Ignored callback request (IP=%s) - IP filter (%s)"), ipstr(dwIP), theApp.ipfilter->GetLastHit()); break; } if (theApp.clientlist->IsBannedClient(dwIP)) { if (thePrefs.GetLogBannedClients()) { CUpDownClient* pClient = theApp.clientlist->FindClientByIP(dwIP); AddDebugLogLine(false, _T("Ignored callback request from banned client %s; %s"), ipstr(dwIP), pClient->DbgGetClientInfo()); } break; } uint16 nPort = PeekUInt16(packet+4); CUpDownClient* client = theApp.clientlist->FindClientByIP(dwIP,nPort); if (client) client->TryToConnect(); else { client = new CUpDownClient(0,nPort,dwIP,0,0,true); theApp.clientlist->AddClient(client); client->TryToConnect(); } } break; } case OP_CALLBACK_FAIL: { if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("ServerMsg - OP_Callback_Fail %s\n"), DbgGetHexDump((uint8*)packet, size)); break; } case OP_REJECT: { if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("ServerMsg - OP_Reject %s\n"), DbgGetHexDump((uint8*)packet, size)); // this could happen if we send a command with the wrong protocol (e.g. sending a compressed packet to // a server which does not support that protocol). if (thePrefs.GetVerbose()) DebugLogError(_T("Server rejected last command")); break; } default: if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("***NOTE: ServerMsg - Unknown message; opcode=0x%02x %s\n"), opcode, DbgGetHexDump((uint8*)packet, size)); ; } return true; } catch(CFileException* error) { if (thePrefs.GetVerbose()) { TCHAR szError[MAX_CFEXP_ERRORMSG]; error->m_strFileName = _T("server packet"); error->GetErrorMessage(szError, ARRSIZE(szError)); DebugLogError(GetResString(IDS_ERR_PACKAGEHANDLING), szError); } error->Delete(); ASSERT(0); if (opcode==OP_SEARCHRESULT || opcode==OP_FOUNDSOURCES) return true; } catch(CMemoryException* error) { if (thePrefs.GetVerbose()) DebugLogError(GetResString(IDS_ERR_PACKAGEHANDLING), _T("CMemoryException")); error->Delete(); ASSERT(0); if (opcode==OP_SEARCHRESULT || opcode==OP_FOUNDSOURCES) return true; } catch(CString error) { if (thePrefs.GetVerbose()) DebugLogError(GetResString(IDS_ERR_PACKAGEHANDLING), error); ASSERT(0); } catch(...) { if (thePrefs.GetVerbose()) DebugLogError(GetResString(IDS_ERR_PACKAGEHANDLING), _T("Unknown exception")); ASSERT(0); } SetConnectionState(CS_DISCONNECTED); return false; }
void CFileDetailDialogInfo::RefreshData() { CString str; if (m_paFiles->GetSize() == 1) { CPartFile* file = STATIC_DOWNCAST(CPartFile, (*m_paFiles)[0]); // if file is completed, we output the 'file path' and not the 'part.met file path' if (file->GetStatus(true) == PS_COMPLETE) GetDlgItem(IDC_FD_X2)->SetWindowText(GetResString(IDS_DL_FILENAME)); SetDlgItemText(IDC_FNAME, file->GetFileName()); SetDlgItemText(IDC_METFILE, file->GetFullName()); SetDlgItemText(IDC_FHASH, md4str(file->GetFileHash())); if (file->GetTransferringSrcCount() > 0) str.Format(GetResString(IDS_PARTINFOS2), file->GetTransferringSrcCount()); else str = file->getPartfileStatus(); SetDlgItemText(IDC_PFSTATUS, str); str.Format(_T("%u; %s: %u (%.1f%%)"), file->GetPartCount(), GetResString(IDS_AVAILABLE) , file->GetAvailablePartCount(), (float)((file->GetAvailablePartCount()*100)/file->GetPartCount())); SetDlgItemText(IDC_PARTCOUNT, str); // date created if (file->GetCrFileDate() != 0) { str.Format(_T("%s ") + GetResString(IDS_TIMEBEFORE), file->GetCrCFileDate().Format(thePrefs.GetDateTimeFormat()), CastSecondsToLngHM(time(NULL) - file->GetCrFileDate())); } else str = GetResString(IDS_UNKNOWN); SetDlgItemText(IDC_FILECREATED, str); // active download time time_t nDlActiveTime = file->GetDlActiveTime(); //vs2005 if (nDlActiveTime) str = CastSecondsToLngHM(nDlActiveTime); else str = GetResString(IDS_UNKNOWN); SetDlgItemText(IDC_DL_ACTIVE_TIME, str); // last seen complete struct tm tmTemp; struct tm* ptimLastSeenComplete = file->lastseencomplete.GetLocalTm(&tmTemp); if (file->lastseencomplete == NULL || ptimLastSeenComplete == NULL) str.Format(GetResString(IDS_NEVER)); else { str.Format(_T("%s ") + GetResString(IDS_TIMEBEFORE), file->lastseencomplete.Format(thePrefs.GetDateTimeFormat()), CastSecondsToLngHM(time(NULL) - safe_mktime(ptimLastSeenComplete))); } SetDlgItemText(IDC_LASTSEENCOMPL, str); // last receive if (file->GetFileDate() != 0 && file->GetRealFileSize() > (uint64)0) { // 'Last Modified' sometimes is up to 2 seconds greater than the current time ??? // If it's related to the FAT32 seconds time resolution the max. failure should still be only 1 sec. // Happens at least on FAT32 with very high download speed. uint32 tLastModified = file->GetFileDate(); time_t tNow = time(NULL); //vs2005 uint32 tAgo; if (tNow >= tLastModified) tAgo = tNow - tLastModified; else{ TRACE("tNow = %s\n", CTime(tNow).Format("%X")); TRACE("tLMd = %s, +%u\n", CTime(tLastModified).Format("%X"), tLastModified - tNow); TRACE("\n"); tAgo = 0; } str.Format(_T("%s ") + GetResString(IDS_TIMEBEFORE), file->GetCFileDate().Format(thePrefs.GetDateTimeFormat()), CastSecondsToLngHM(tAgo)); } else str = GetResString(IDS_NEVER); SetDlgItemText(IDC_LASTRECEIVED, str); // AICH Hash switch (file->GetAICHRecoveryHashSet()->GetStatus()) { case AICH_TRUSTED: case AICH_VERIFIED: case AICH_HASHSETCOMPLETE: if (file->GetAICHRecoveryHashSet()->HasValidMasterHash()) { SetDlgItemText(IDC_FD_AICHHASH, file->GetAICHRecoveryHashSet()->GetMasterHash().GetString()); break; } default: SetDlgItemText(IDC_FD_AICHHASH, GetResString(IDS_UNKNOWN)); } // file type CString ext; bool showwarning = false; int pos = file->GetFileName().ReverseFind(_T('.')); if (file->GetFileName().ReverseFind(_T('\\')) < pos) { ext = file->GetFileName().Mid(pos + 1); ext.MakeUpper(); } EFileType bycontent = GetFileTypeEx((CKnownFile *)file, false, true); if (bycontent != FILETYPE_UNKNOWN) { str = GetFileTypeName(bycontent) + _T(" ("); str.Append(GetResString(IDS_VERIFIED) + _T(')')); int extLevel = IsExtensionTypeOf(bycontent, ext); if (extLevel == -1) { showwarning = true; str.Append(_T(" - ")); str.Append(GetResString(IDS_INVALIDFILEEXT) + _T(": ")); str.Append(ext); } else if (extLevel == 0) { str.Append(_T(" - ")); str.Append(GetResString(IDS_UNKNOWNFILEEXT) + _T(": ")); str.Append(ext); } } else { // not verified if (pos != -1) { str =file->GetFileName().Mid(pos + 1); str.MakeUpper(); str.Append(_T(" (") ); str.Append( GetResString(IDS_UNVERIFIED) + _T(')')); } else str = GetResString(IDS_UNKNOWN); } m_bShowFileTypeWarning = showwarning; SetDlgItemText(IDC_FD_X11,str); } else { SetDlgItemText(IDC_FNAME, sm_pszNotAvail); SetDlgItemText(IDC_METFILE, sm_pszNotAvail); SetDlgItemText(IDC_FHASH, sm_pszNotAvail); SetDlgItemText(IDC_PFSTATUS, sm_pszNotAvail); SetDlgItemText(IDC_PARTCOUNT, sm_pszNotAvail); SetDlgItemText(IDC_FD_X11, sm_pszNotAvail); SetDlgItemText(IDC_FILECREATED, sm_pszNotAvail); SetDlgItemText(IDC_DL_ACTIVE_TIME, sm_pszNotAvail); SetDlgItemText(IDC_LASTSEENCOMPL, sm_pszNotAvail); SetDlgItemText(IDC_LASTRECEIVED, sm_pszNotAvail); SetDlgItemText(IDC_FD_AICHHASH, sm_pszNotAvail); } uint64 uFileSize = 0; uint64 uRealFileSize = 0; uint64 uTransferred = 0; uint64 uCorrupted = 0; uint32 uRecoveredParts = 0; uint64 uCompression = 0; uint64 uCompleted = 0; int iMD4HashsetAvailable = 0; int iAICHHashsetAvailable = 0; uint32 uDataRate = 0; UINT uSources = 0; UINT uValidSources = 0; UINT uNNPSources = 0; UINT uA4AFSources = 0; for (int i = 0; i < m_paFiles->GetSize(); i++) { CPartFile* file = STATIC_DOWNCAST(CPartFile, (*m_paFiles)[i]); uFileSize += (uint64)file->GetFileSize(); uRealFileSize += (uint64)file->GetRealFileSize(); uTransferred += (uint64)file->GetTransferred(); uCorrupted += file->GetCorruptionLoss(); uRecoveredParts += file->GetRecoveredPartsByICH(); uCompression += file->GetCompressionGain(); uDataRate += file->GetDatarate(); uCompleted += (uint64)file->GetCompletedSize(); iMD4HashsetAvailable += (file->GetFileIdentifier().HasExpectedMD4HashCount()) ? 1 : 0; iAICHHashsetAvailable += (file->GetFileIdentifier().HasExpectedAICHHashCount()) ? 1 : 0; if (file->IsPartFile()) { uSources += file->GetSourceCount(); uValidSources += file->GetValidSourcesCount(); uNNPSources += file->GetSrcStatisticsValue(DS_NONEEDEDPARTS); uA4AFSources += file->GetSrcA4AFCount(); } } str.Format(_T("%s (%s %s); %s %s"), CastItoXBytes(uFileSize, false, false), GetFormatedUInt64(uFileSize), GetResString(IDS_BYTES), GetResString(IDS_ONDISK), CastItoXBytes(uRealFileSize, false, false)); SetDlgItemText(IDC_FSIZE, str); if (m_paFiles->GetSize() == 1) { if (iAICHHashsetAvailable == 0 && iMD4HashsetAvailable == 0) SetDlgItemText(IDC_HASHSET, GetResString(IDS_NO)); else if (iAICHHashsetAvailable == 1 && iMD4HashsetAvailable == 1) SetDlgItemText(IDC_HASHSET, GetResString(IDS_YES) + _T(" (eD2K + AICH)")); else if (iAICHHashsetAvailable == 1) SetDlgItemText(IDC_HASHSET, GetResString(IDS_YES) + _T(" (AICH)")); else if (iMD4HashsetAvailable == 1) SetDlgItemText(IDC_HASHSET, GetResString(IDS_YES) + _T(" (eD2K)")); } else { if (iAICHHashsetAvailable == 0 && iMD4HashsetAvailable == 0) SetDlgItemText(IDC_HASHSET, GetResString(IDS_NO)); else if (iMD4HashsetAvailable == m_paFiles->GetSize() && iAICHHashsetAvailable == m_paFiles->GetSize()) SetDlgItemText(IDC_HASHSET, GetResString(IDS_YES) + + _T(" (eD2K + AICH)")); else SetDlgItemText(IDC_HASHSET, _T("")); } str.Format(GetResString(IDS_SOURCESINFO), uSources, uValidSources, uNNPSources, uA4AFSources); SetDlgItemText(IDC_SOURCECOUNT, str); SetDlgItemText(IDC_DATARATE, CastItoXBytes(uDataRate, false, true)); SetDlgItemText(IDC_TRANSFERRED, CastItoXBytes(uTransferred, false, false)); str.Format(_T("%s (%.1f%%)"), CastItoXBytes(uCompleted, false, false), uFileSize!=0 ? (uCompleted * 100.0 / uFileSize) : 0.0); SetDlgItemText(IDC_COMPLSIZE, str); str.Format(_T("%s (%.1f%%)"), CastItoXBytes(uCorrupted, false, false), uTransferred!=0 ? (uCorrupted * 100.0 / uTransferred) : 0.0); SetDlgItemText(IDC_CORRUPTED, str); str.Format(_T("%s (%.1f%%)"), CastItoXBytes(uFileSize - uCompleted, false, false), uFileSize!=0 ? ((uFileSize - uCompleted) * 100.0 / uFileSize) : 0.0); SetDlgItemText(IDC_REMAINING, str); str.Format(_T("%u %s"), uRecoveredParts, GetResString(IDS_FD_PARTS)); SetDlgItemText(IDC_RECOVERED, str); str.Format(_T("%s (%.1f%%)"), CastItoXBytes(uCompression, false, false), uTransferred!=0 ? (uCompression * 100.0 / uTransferred) : 0.0); SetDlgItemText(IDC_COMPRESSION, str); }
void CChatWnd::ShowFriendMsgDetails(CFriend* pFriend) { if (pFriend) { CString buffer; // Name if (pFriend->GetLinkedClient()) GetDlgItem(IDC_FRIENDS_NAME_EDIT)->SetWindowText(pFriend->GetLinkedClient()->GetUserName()); else if (pFriend->m_strName != _T("")) GetDlgItem(IDC_FRIENDS_NAME_EDIT)->SetWindowText(pFriend->m_strName); else GetDlgItem(IDC_FRIENDS_NAME_EDIT)->SetWindowText(_T("?")); // Hash if (pFriend->GetLinkedClient()) GetDlgItem(IDC_FRIENDS_USERHASH_EDIT)->SetWindowText(md4str(pFriend->GetLinkedClient()->GetUserHash())); else if (pFriend->m_dwHasHash) GetDlgItem(IDC_FRIENDS_USERHASH_EDIT)->SetWindowText(md4str(pFriend->m_abyUserhash)); else GetDlgItem(IDC_FRIENDS_USERHASH_EDIT)->SetWindowText(_T("?")); // Client if (pFriend->GetLinkedClient()) GetDlgItem(IDC_FRIENDS_CLIENTE_EDIT)->SetWindowText(pFriend->GetLinkedClient()->GetClientSoftVer()); else GetDlgItem(IDC_FRIENDS_CLIENTE_EDIT)->SetWindowText(_T("?")); // Identification if (pFriend->GetLinkedClient() && pFriend->GetLinkedClient()->Credits()) { if (CGlobalVariable::clientcredits->CryptoAvailable()) { switch (pFriend->GetLinkedClient()->Credits()->GetCurrentIdentState(pFriend->GetLinkedClient()->GetIP())) { case IS_NOTAVAILABLE: GetDlgItem(IDC_FRIENDS_IDENTIFICACION_EDIT)->SetWindowText(GetResString(IDS_IDENTNOSUPPORT)); break; case IS_IDFAILED: case IS_IDNEEDED: case IS_IDBADGUY: GetDlgItem(IDC_FRIENDS_IDENTIFICACION_EDIT)->SetWindowText(GetResString(IDS_IDENTFAILED)); break; case IS_IDENTIFIED: GetDlgItem(IDC_FRIENDS_IDENTIFICACION_EDIT)->SetWindowText(GetResString(IDS_IDENTOK)); break; } } else GetDlgItem(IDC_FRIENDS_IDENTIFICACION_EDIT)->SetWindowText(GetResString(IDS_IDENTNOSUPPORT)); } else GetDlgItem(IDC_FRIENDS_IDENTIFICACION_EDIT)->SetWindowText(_T("?")); // Upload and downloaded if (pFriend->GetLinkedClient() && pFriend->GetLinkedClient()->Credits()) GetDlgItem(IDC_FRIENDS_DESCARGADO_EDIT)->SetWindowText(CastItoXBytes(pFriend->GetLinkedClient()->Credits()->GetDownloadedTotal(), false, false)); else GetDlgItem(IDC_FRIENDS_DESCARGADO_EDIT)->SetWindowText(_T("?")); if (pFriend->GetLinkedClient() && pFriend->GetLinkedClient()->Credits()) GetDlgItem(IDC_FRIENDS_SUBIDO_EDIT)->SetWindowText(CastItoXBytes(pFriend->GetLinkedClient()->Credits()->GetUploadedTotal(), false, false)); else GetDlgItem(IDC_FRIENDS_SUBIDO_EDIT)->SetWindowText(_T("?")); } else { GetDlgItem(IDC_FRIENDS_NAME_EDIT)->SetWindowText(_T("-")); GetDlgItem(IDC_FRIENDS_USERHASH_EDIT)->SetWindowText(_T("-")); GetDlgItem(IDC_FRIENDS_CLIENTE_EDIT)->SetWindowText(_T("-")); GetDlgItem(IDC_FRIENDS_IDENTIFICACION_EDIT)->SetWindowText(_T("-")); GetDlgItem(IDC_FRIENDS_DESCARGADO_EDIT)->SetWindowText(_T("-")); GetDlgItem(IDC_FRIENDS_SUBIDO_EDIT)->SetWindowText(_T("-")); } }
void CDetailInfo::UpdateInfo(CPartFile* pFile, DWORD dwMask) { try { m_ListDetail.DeleteAllItems(); if (NULL == pFile || 0 == dwMask) return; m_pCurFile = pFile; m_dwCurMask = dwMask; int iItem; CString str; CPartFile *lpPartFile = pFile;//DYNAMIC_DOWNCAST(CPartFile, pFile); iItem = 0; if (IM_FILENAME & dwMask) { str = pFile->GetFileName(); m_ListDetail.InsertItem(iItem, GetResString(IDS_DL_FILENAME)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } if (IM_FILESIZE & dwMask) { str = CastItoXBytes(pFile->GetFileSize(), false, false); m_ListDetail.InsertItem(iItem, GetResString(IDS_DL_SIZE)); if(!str.IsEmpty()) m_ListDetail.SetItemText(iItem, 1, str); else m_ListDetail.SetItemText(iItem, 1, GetResString(IDS_UNKNOWN)); iItem++; } if (IM_FILETYPE & dwMask) { str = pFile->GetFileTypeDisplayStr(); m_ListDetail.InsertItem(iItem, GetResString(IDS_TYPE)); if(!str.IsEmpty()) m_ListDetail.SetItemText(iItem, 1, str); else m_ListDetail.SetItemText(iItem, 1, GetResString(IDS_UNKNOWN)); iItem++; } if (IM_LINK & dwMask) { str = GetLink(pFile); bool bRefer = false; if(str.Left(7).CompareNoCase(_T("http://")) == 0) { if(str.Find(_T('<'))>0) { bRefer = true; str = str.Left(str.Find(_T('<'))); } if(str.Find(_T('#'))>0) str = str.Left(str.Find(_T('#'))); } if(!str.IsEmpty()) { m_ListDetail.InsertItem(iItem, GetResString(IDS_DOWNLOAD_LINK)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } if(bRefer) { CString refer = GetLink(pFile); refer = refer.Right(refer.GetLength() - 1 - refer.Find(_T('='))); if(refer.Find(_T('>')) > 0) refer.Remove(_T('>')); m_ListDetail.InsertItem(iItem,GetResString(IDS_REFER_LINK)); m_ListDetail.SetItemText(iItem,1,refer); iItem++; } } if (IM_SOURCEURL & dwMask) { str = pFile->GetPartFileURL(); bool bRefer = false; if(str.Find(_T('<'))>0) { bRefer = true; str = str.Left(str.Find(_T('<'))); } if(str.Find(_T('#'))>0) str = str.Left(str.Find(_T('#'))); if(!str.IsEmpty()) { m_ListDetail.InsertItem(iItem, GetResString(IDS_URL_LINK)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } if(bRefer) { CString strRefer = pFile->GetPartFileURL(); strRefer = strRefer.Right(strRefer.GetLength() -1 - strRefer.Find(_T('=') )); if(strRefer.Find(_T('>'))>0) strRefer.Remove(_T('>')); m_ListDetail.InsertItem(iItem,GetResString(IDS_REFER_LINK)); m_ListDetail.SetItemText(iItem,1,strRefer); iItem++; } } if (IM_PRIORITY & dwMask) { if(dwMask == CDetailInfo::IM_COMBINE_DOWNLOAD) str = PriorityToString(pFile->GetDownPriority(), pFile->IsAutoDownPriority()); if(dwMask == CDetailInfo::IM_COMBINE_SHARE) str = PriorityToString(pFile->GetUpPriority(),pFile->IsAutoUpPriority()); m_ListDetail.InsertItem(iItem, GetResString(IDS_PRIORITY)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } if (IM_FILEHASH & dwMask) { if (pFile->HasNullHash()) { str = _T("-"); } else { str = md4str(pFile->GetFileHash()); } m_ListDetail.InsertItem(iItem, GetResString(IDS_FILEID)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } if (IM_REQUEST & dwMask) { str.Format(_T("%u (%u)"), pFile->statistic.GetRequests(), pFile->statistic.GetAllTimeRequests()); m_ListDetail.InsertItem(iItem, GetResString(IDS_SF_REQUESTS)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } if (IM_TRANSFERED & dwMask) { str.Format(_T("%s (%s)"), CastItoXBytes(pFile->statistic.GetTransferred(), false, false), CastItoXBytes(pFile->statistic.GetAllTimeTransferred(), false, false)); m_ListDetail.InsertItem(iItem, GetResString(IDS_SF_TRANSFERRED)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } if (IM_FILEPATH & dwMask) { str = pFile->GetPath(); PathRemoveBackslash(str.GetBuffer()); str.ReleaseBuffer(); m_ListDetail.InsertItem(iItem, GetResString(IDS_FOLDER)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } if (IM_ACCEPT & dwMask) { str.Format(_T("%u (%u)"), pFile->statistic.GetAccepts(), pFile->statistic.GetAllTimeAccepts()); m_ListDetail.InsertItem(iItem, GetResString(IDS_SF_ACCEPTS)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } if (IM_SOURCE & dwMask) { str.Format(_T("%u - %u"), pFile->m_nCompleteSourcesCountLo, pFile->m_nCompleteSourcesCountHi); m_ListDetail.InsertItem(iItem, GetResString(IDS_COMPLSOURCES)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } if (IM_REMAIN & dwMask) { if (NULL != lpPartFile) { str.Empty(); if (lpPartFile->GetStatus() != PS_COMPLETING && lpPartFile->GetStatus() != PS_COMPLETE ) { // time time_t restTime; if (!thePrefs.UseSimpleTimeRemainingComputation()) restTime = lpPartFile->getTimeRemaining(); else restTime = lpPartFile->getTimeRemainingSimple(); str.Format(_T("%s (%s)"), CastSecondsToHM(restTime), CastItoXBytes((lpPartFile->GetFileSize() - lpPartFile->GetCompletedSize()), false, false)); } else { str.Format(_T("%s (%s)"), _T("0"), CastItoXBytes((lpPartFile->GetFileSize() - lpPartFile->GetCompletedSize()), false, false)); } m_ListDetail.InsertItem(iItem, GetResString(IDS_DL_REMAINS)); if(!str.IsEmpty()) m_ListDetail.SetItemText(iItem, 1, str); else m_ListDetail.SetItemText(iItem,1,GetResString(IDS_UNKNOWN)); iItem++; } } if (IM_LASTCOMPLETE & dwMask) { if (NULL != lpPartFile) { // CString tempbuffer; // if (lpPartFile->m_nCompleteSourcesCountLo == 0) // { // tempbuffer.Format(_T("< %u"), lpPartFile->m_nCompleteSourcesCountHi); // } // else if (lpPartFile->m_nCompleteSourcesCountLo == lpPartFile->m_nCompleteSourcesCountHi) // { // tempbuffer.Format(_T("%u"), lpPartFile->m_nCompleteSourcesCountLo); // } // else // { // tempbuffer.Format(_T("%u - %u"), lpPartFile->m_nCompleteSourcesCountLo, lpPartFile->m_nCompleteSourcesCountHi); // } if (lpPartFile->lastseencomplete==NULL) str.Format(_T("%s" /*(%s)*/),GetResString(IDS_NEVER)/*,tempbuffer*/); else str.Format(_T("%s" /*(%s)*/),lpPartFile->lastseencomplete.Format( thePrefs.GetDateTimeFormat())/*,tempbuffer*/); m_ListDetail.InsertItem(iItem, GetResString(IDS_LASTSEENCOMPL)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } } if (IM_LASTRECV & dwMask) { if (NULL != lpPartFile) { if(lpPartFile->GetFileDate()!=NULL && lpPartFile->GetRealFileSize()/*GetCompletedSize() */> (uint64)0) str = lpPartFile->GetCFileDate().Format( thePrefs.GetDateTimeFormat()); else str.Format(_T("%s"),GetResString(IDS_NEVER)); m_ListDetail.InsertItem(iItem, GetResString(IDS_FD_LASTCHANGE)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } } if (IM_CATEGORY & dwMask) { if (NULL != lpPartFile) { str = (lpPartFile->GetCategory()!=0) ? thePrefs.GetCategory(lpPartFile->GetCategory())->strTitle:_T(""); m_ListDetail.InsertItem(iItem, GetResString(IDS_CAT)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } } } catch(...) { } }
void CreateNetworkInfo(CRichEditCtrlX& rCtrl, CHARFORMAT& rcfDef, CHARFORMAT& rcfBold, bool bFullInfo) { CString buffer; if (bFullInfo) { /////////////////////////////////////////////////////////////////////////// // Ports Info /////////////////////////////////////////////////////////////////////////// rCtrl.SetSelectionCharFormat(rcfBold); rCtrl << GetResString(IDS_CLIENT) << _T("\r\n"); rCtrl.SetSelectionCharFormat(rcfDef); rCtrl << GetResString(IDS_PW_NICK) << _T(":\t") << thePrefs.GetUserNick() << _T("\r\n"); rCtrl << GetResString(IDS_CD_UHASH) << _T("\t") << md4str((uchar*)thePrefs.GetUserHash()) << _T("\r\n"); rCtrl << _T("TCP-") << GetResString(IDS_PORT) << _T(":\t") << thePrefs.GetPort() << _T("\r\n"); rCtrl << _T("UDP-") << GetResString(IDS_PORT) << _T(":\t") << thePrefs.GetUDPPort() << _T("\r\n"); rCtrl << _T("\r\n"); } /////////////////////////////////////////////////////////////////////////// // ED2K /////////////////////////////////////////////////////////////////////////// rCtrl.SetSelectionCharFormat(rcfBold); rCtrl << _T("eD2K ") << GetResString(IDS_NETWORK) << _T("\r\n"); rCtrl.SetSelectionCharFormat(rcfDef); rCtrl << GetResString(IDS_STATUS) << _T(":\t"); if (theApp.serverconnect->IsConnected()) rCtrl << GetResString(IDS_CONNECTED); else if(theApp.serverconnect->IsConnecting()) rCtrl << GetResString(IDS_CONNECTING); else rCtrl << GetResString(IDS_DISCONNECTED); rCtrl << _T("\r\n"); //I only show this in full display as the normal display is not //updated at regular intervals. if (bFullInfo && theApp.serverconnect->IsConnected()) { uint32_t uTotalUser = 0; uint32_t uTotalFile = 0; theApp.serverlist->GetUserFileStatus(uTotalUser, uTotalFile); rCtrl << GetResString(IDS_UUSERS) << _T(":\t") << GetFormatedUInt(uTotalUser) << _T("\r\n"); rCtrl << GetResString(IDS_PW_FILES) << _T(":\t") << GetFormatedUInt(uTotalFile) << _T("\r\n"); } if (theApp.serverconnect->IsConnected()){ rCtrl << GetResString(IDS_IP) << _T(":") << GetResString(IDS_PORT) << _T(":") ; if (theApp.serverconnect->IsLowID() && theApp.GetPublicIP(true) == 0) buffer = GetResString(IDS_UNKNOWN); else buffer.Format(_T("%s:%u"), ipstr(theApp.GetPublicIP(true)), thePrefs.GetPort()); rCtrl << _T("\t") << buffer << _T("\r\n"); rCtrl << GetResString(IDS_ID) << _T(":\t"); if (theApp.serverconnect->IsConnected()){ buffer.Format(_T("%u"),theApp.serverconnect->GetClientID()); rCtrl << buffer; } rCtrl << _T("\r\n"); rCtrl << _T("\t"); if (theApp.serverconnect->IsLowID()) rCtrl << GetResString(IDS_IDLOW); else rCtrl << GetResString(IDS_IDHIGH); rCtrl << _T("\r\n"); CServer* cur_server = theApp.serverconnect->GetCurrentServer(); CServer* srv = cur_server ? theApp.serverlist->GetServerByAddress(cur_server->GetAddress(), cur_server->GetPort()) : NULL; if (srv){ rCtrl << _T("\r\n"); rCtrl.SetSelectionCharFormat(rcfBold); rCtrl << _T("eD2K ") << GetResString(IDS_SERVER) << _T("\r\n"); rCtrl.SetSelectionCharFormat(rcfDef); rCtrl << GetResString(IDS_SW_NAME) << _T(":\t") << srv->GetListName() << _T("\r\n"); rCtrl << GetResString(IDS_DESCRIPTION) << _T(":\t") << srv->GetDescription() << _T("\r\n"); rCtrl << GetResString(IDS_IP) << _T(":") << GetResString(IDS_PORT) << _T(":\t") << srv->GetAddress() << _T(":") << srv->GetPort() << _T("\r\n"); rCtrl << GetResString(IDS_VERSION) << _T(":\t") << srv->GetVersion() << _T("\r\n"); rCtrl << GetResString(IDS_UUSERS) << _T(":\t") << GetFormatedUInt(srv->GetUsers()) << _T("\r\n"); rCtrl << GetResString(IDS_PW_FILES) << _T(":\t") << GetFormatedUInt(srv->GetFiles()) << _T("\r\n"); rCtrl << GetResString(IDS_FSTAT_CONNECTION) << _T(":\t"); if (theApp.serverconnect->IsConnectedObfuscated()) rCtrl << GetResString(IDS_OBFUSCATED); else rCtrl << GetResString(IDS_PRIONORMAL); rCtrl << _T("\r\n"); if (bFullInfo) { rCtrl << GetResString(IDS_IDLOW) << _T(":\t") << GetFormatedUInt(srv->GetLowIDUsers()) << _T("\r\n"); rCtrl << GetResString(IDS_PING) << _T(":\t") << srv->GetPing() << _T(" ms\r\n"); rCtrl << _T("\r\n"); rCtrl.SetSelectionCharFormat(rcfBold); rCtrl << _T("eD2K ") << GetResString(IDS_SERVER) << _T(" ") << GetResString(IDS_FEATURES) << _T("\r\n"); rCtrl.SetSelectionCharFormat(rcfDef); rCtrl << GetResString(IDS_SERVER_LIMITS) << _T(": ") << GetFormatedUInt(srv->GetSoftFiles()) << _T("/") << GetFormatedUInt(srv->GetHardFiles()) << _T("\r\n"); if (thePrefs.IsExtControlsEnabled()) { rCtrl << GetResString(IDS_SRV_TCPCOMPR) << _T(": "); if (srv->GetTCPFlags() & SRV_TCPFLG_COMPRESSION) rCtrl << GetResString(IDS_YES); else rCtrl << GetResString(IDS_NO); rCtrl << _T("\r\n"); rCtrl << GetResString(IDS_SHORTTAGS) << _T(": "); if ((srv->GetTCPFlags() & SRV_TCPFLG_NEWTAGS) || (srv->GetUDPFlags() & SRV_UDPFLG_NEWTAGS)) rCtrl << GetResString(IDS_YES); else rCtrl << GetResString(IDS_NO); rCtrl << _T("\r\n"); rCtrl << _T("Unicode") << _T(": "); if ((srv->GetTCPFlags() & SRV_TCPFLG_UNICODE) || (srv->GetUDPFlags() & SRV_UDPFLG_UNICODE)) rCtrl << GetResString(IDS_YES); else rCtrl << GetResString(IDS_NO); rCtrl << _T("\r\n"); rCtrl << GetResString(IDS_SERVERFEATURE_INTTYPETAGS) << _T(": "); if (srv->GetTCPFlags() & SRV_TCPFLG_TYPETAGINTEGER) rCtrl << GetResString(IDS_YES); else rCtrl << GetResString(IDS_NO); rCtrl << _T("\r\n"); rCtrl << GetResString(IDS_SRV_UDPSR) << _T(": "); if (srv->GetUDPFlags() & SRV_UDPFLG_EXT_GETSOURCES) rCtrl << GetResString(IDS_YES); else rCtrl << GetResString(IDS_NO); rCtrl << _T("\r\n"); rCtrl << GetResString(IDS_SRV_UDPSR) << _T(" #2: "); if (srv->GetUDPFlags() & SRV_UDPFLG_EXT_GETSOURCES2) rCtrl << GetResString(IDS_YES); else rCtrl << GetResString(IDS_NO); rCtrl << _T("\r\n"); rCtrl << GetResString(IDS_SRV_UDPFR) << _T(": "); if (srv->GetUDPFlags() & SRV_UDPFLG_EXT_GETFILES) rCtrl << GetResString(IDS_YES); else rCtrl << GetResString(IDS_NO); rCtrl << _T("\r\n"); rCtrl << GetResString(IDS_SRV_LARGEFILES) << _T(": "); if (srv->SupportsLargeFilesTCP() || srv->SupportsLargeFilesUDP()) rCtrl << GetResString(IDS_YES); else rCtrl << GetResString(IDS_NO); rCtrl << _T("\r\n"); rCtrl << GetResString(IDS_PROTOCOLOBFUSCATION) << _T(" (UDP)") << _T(": "); if (srv->SupportsObfuscationUDP()) rCtrl << GetResString(IDS_YES); else rCtrl << GetResString(IDS_NO); rCtrl << _T("\r\n"); rCtrl << GetResString(IDS_PROTOCOLOBFUSCATION) << _T(" (TCP)") << _T(": "); if (srv->SupportsObfuscationTCP()) rCtrl << GetResString(IDS_YES); else rCtrl << GetResString(IDS_NO); rCtrl << _T("\r\n"); } } } } rCtrl << _T("\r\n"); /////////////////////////////////////////////////////////////////////////// // Kademlia /////////////////////////////////////////////////////////////////////////// /* ismod: no KAD rCtrl.SetSelectionCharFormat(rcfBold); rCtrl << GetResString(IDS_KADEMLIA) << _T(" ") << GetResString(IDS_NETWORK) << _T("\r\n"); rCtrl.SetSelectionCharFormat(rcfDef); rCtrl << GetResString(IDS_STATUS) << _T(":\t"); if(Kademlia::CKademlia::IsConnected()){ if(Kademlia::CKademlia::IsFirewalled()) rCtrl << GetResString(IDS_FIREWALLED); else rCtrl << GetResString(IDS_KADOPEN); if (Kademlia::CKademlia::IsRunningInLANMode()) rCtrl << _T(" (") << GetResString(IDS_LANMODE) << _T(")"); rCtrl << _T("\r\n"); rCtrl << _T("UDP ") + GetResString(IDS_STATUS) << _T(":\t"); if(Kademlia::CUDPFirewallTester::IsFirewalledUDP(true)) rCtrl << GetResString(IDS_FIREWALLED); else if (Kademlia::CUDPFirewallTester::IsVerified()) rCtrl << GetResString(IDS_KADOPEN); else{ CString strTmp = GetResString(IDS_UNVERIFIED); strTmp.MakeLower(); rCtrl << GetResString(IDS_KADOPEN) + _T(" (") + strTmp + _T(")"); } rCtrl << _T("\r\n"); CString IP; IP = ipstr(ntohl(Kademlia::CKademlia::GetPrefs()->GetIPAddress())); buffer.Format(_T("%s:%i"), IP, thePrefs.GetUDPPort()); rCtrl << GetResString(IDS_IP) << _T(":") << GetResString(IDS_PORT) << _T(":\t") << buffer << _T("\r\n"); buffer.Format(_T("%u"),Kademlia::CKademlia::GetPrefs()->GetIPAddress()); rCtrl << GetResString(IDS_ID) << _T(":\t") << buffer << _T("\r\n"); if (Kademlia::CKademlia::GetPrefs()->GetUseExternKadPort() && Kademlia::CKademlia::GetPrefs()->GetExternalKadPort() != 0 && Kademlia::CKademlia::GetPrefs()->GetInternKadPort() != Kademlia::CKademlia::GetPrefs()->GetExternalKadPort()) { buffer.Format(_T("%u"), Kademlia::CKademlia::GetPrefs()->GetExternalKadPort()); rCtrl << GetResString(IDS_EXTERNUDPPORT) << _T(":\t") << buffer << _T("\r\n"); } if (Kademlia::CUDPFirewallTester::IsFirewalledUDP(true)) { rCtrl << GetResString(IDS_BUDDY) << _T(":\t"); switch ( theApp.clientlist->GetBuddyStatus() ) { case Disconnected: rCtrl << GetResString(IDS_BUDDYNONE); break; case Connecting: rCtrl << GetResString(IDS_CONNECTING); break; case Connected: rCtrl << GetResString(IDS_CONNECTED); break; } rCtrl << _T("\r\n"); } if (bFullInfo) { CString sKadID; Kademlia::CKademlia::GetPrefs()->GetKadID(&sKadID); rCtrl << GetResString(IDS_CD_UHASH) << _T("\t") << sKadID << _T("\r\n"); rCtrl << GetResString(IDS_UUSERS) << _T(":\t") << GetFormatedUInt(Kademlia::CKademlia::GetKademliaUsers()) << _T(" (Experimental: ") << GetFormatedUInt(Kademlia::CKademlia::GetKademliaUsers(true)) << _T(")\r\n"); //rCtrl << GetResString(IDS_UUSERS) << _T(":\t") << GetFormatedUInt(Kademlia::CKademlia::GetKademliaUsers()) << _T("\r\n"); rCtrl << GetResString(IDS_PW_FILES) << _T(":\t") << GetFormatedUInt(Kademlia::CKademlia::GetKademliaFiles()) << _T("\r\n"); rCtrl << GetResString(IDS_INDEXED) << _T(":\r\n"); buffer.Format(GetResString(IDS_KADINFO_SRC) , Kademlia::CKademlia::GetIndexed()->m_uTotalIndexSource); rCtrl << buffer; buffer.Format(GetResString(IDS_KADINFO_KEYW), Kademlia::CKademlia::GetIndexed()->m_uTotalIndexKeyword); rCtrl << buffer; buffer.Format(_T("\t%s: %u\r\n"), GetResString(IDS_NOTES), Kademlia::CKademlia::GetIndexed()->m_uTotalIndexNotes); rCtrl << buffer; buffer.Format(_T("\t%s: %u\r\n"), GetResString(IDS_THELOAD), Kademlia::CKademlia::GetIndexed()->m_uTotalIndexLoad); rCtrl << buffer; } } else if (Kademlia::CKademlia::IsRunning()) rCtrl << GetResString(IDS_CONNECTING) << _T("\r\n"); else rCtrl << GetResString(IDS_DISCONNECTED) << _T("\r\n"); rCtrl << _T("\r\n"); */ /////////////////////////////////////////////////////////////////////////// // Web Interface /////////////////////////////////////////////////////////////////////////// rCtrl.SetSelectionCharFormat(rcfBold); rCtrl << GetResString(IDS_WEBSRV) << _T("\r\n"); rCtrl.SetSelectionCharFormat(rcfDef); rCtrl << GetResString(IDS_STATUS) << _T(":\t"); rCtrl << (thePrefs.GetWSIsEnabled() ? GetResString(IDS_ENABLED) : GetResString(IDS_DISABLED)) << _T("\r\n"); if (thePrefs.GetWSIsEnabled()){ CString count; count.Format(_T("%i %s"), theApp.webserver->GetSessionCount(), GetResString(IDS_ACTSESSIONS)); rCtrl << _T("\t") << count << _T("\r\n"); CString strHostname; if (!thePrefs.GetYourHostname().IsEmpty() && thePrefs.GetYourHostname().Find(_T('.')) != -1) strHostname = thePrefs.GetYourHostname(); else strHostname = ipstr(theApp.serverconnect->GetLocalIP()); rCtrl << _T("URL:\t") << _T("http://") << strHostname << _T(":") << thePrefs.GetWSPort() << _T("/\r\n"); } }
bool CUpDownClient::ProcessPeerCacheAnswer(const uchar* packet, UINT size) { const bool bDebug = (thePrefs.GetDebugClientTCPLevel() > 0); ASSERT( GetDownloadState() == DS_DOWNLOADING ); ASSERT( m_ePeerCacheDownState == PCDS_WAIT_CLIENT_REPLY ); if (bDebug) DebugRecv("OP_PeerCacheAnswer", this); if (socket == NULL || reqfile == NULL){ ASSERT(0); return false; } CSafeMemFile dataRecv(packet, size); uint8 uPCVersion = dataRecv.ReadUInt8(); if (uPCVersion != PCPCK_VERSION){ if (bDebug) Debug(_T(" ***Invalid packet version: 0x%02x\n"), uPCVersion); ASSERT(0); return false; } uint8 uPCOpcode = dataRecv.ReadUInt8(); if (uPCOpcode == PCOP_NONE){ if (thePrefs.GetVerbose()) AddDebugLogLine(false, _T("Client does not support PeerCache; %s"), DbgGetClientInfo()); return false; } if (uPCOpcode != PCOP_RES){ if (bDebug) Debug(_T(" ***Invalid packet opcode: 0x%02x\n"), uPCOpcode); ASSERT(0); return false; } uint32 uPushId = 0; uint32 uRemoteIP = 0; uchar aucFileHash[16]; md4clr(aucFileHash); CString strInfo; UINT uTags = dataRecv.ReadUInt8(); while (uTags--) { CTag tag(&dataRecv, GetUnicodeSupport()!=utf8strNone); if (tag.GetNameID() == PCTAG_PUSHID && tag.IsInt()) { uPushId = tag.GetInt(); if (bDebug) strInfo.AppendFormat(_T(" PushId=%u"), uPushId); } else if (tag.GetNameID() == PCTAG_PUBLICIP && tag.IsInt()) { uRemoteIP = tag.GetInt(); if (bDebug) strInfo.AppendFormat(_T(" RemoteIP=%s"), ipstr(uRemoteIP)); } else if (tag.GetNameID() == PCTAG_FILEID && tag.IsHash() && tag.GetHash() != NULL) { md4cpy(aucFileHash, tag.GetHash()); if (bDebug) strInfo.AppendFormat(_T(" FileId=%s"), md4str(aucFileHash)); } else { if (bDebug) strInfo.AppendFormat(_T(" ***UnkTag: %s"), tag.GetFullInfo()); ASSERT(0); } } if (bDebug) { if (dataRecv.GetPosition() < dataRecv.GetLength()) strInfo.AppendFormat(_T(" ***AddData: %u bytes"), (UINT)(dataRecv.GetLength() - dataRecv.GetPosition())); Debug(_T("%s\n"), strInfo); } if (uPushId == 0 || uRemoteIP == 0 || isnulmd4(aucFileHash)){ if (thePrefs.GetVerbose()) AddDebugLogLine(false, _T("Invalid PeerCacheAnswer; %s"), DbgGetClientInfo()); return false; } if (md4cmp(aucFileHash, reqfile->GetFileHash()) != 0){ if (thePrefs.GetVerbose()) AddDebugLogLine(false, _T("PeerCacheAnswer reqfile does not match ed2k reqfile; %s"), DbgGetClientInfo()); return false; } m_uPeerCacheDownloadPushId = uPushId; m_uPeerCacheRemoteIP = uRemoteIP; if (!SendHttpBlockRequests()) return false; theApp.m_pPeerCache->DownloadAttemptStarted(); ASSERT( m_ePeerCacheDownState == PCDS_WAIT_CACHE_REPLY ); return true; }
bool CUpDownClient::ProcessPeerCacheQuery(const uchar* packet, UINT size) { const bool bDebug = (thePrefs.GetDebugClientTCPLevel() > 0); if (bDebug) DebugRecv("OP_PeerCacheQuery", this); if (socket == NULL){ ASSERT(0); return false; } CSafeMemFile dataRecv(packet, size); uint8 uPCVersion = dataRecv.ReadUInt8(); if (uPCVersion != PCPCK_VERSION){ if (bDebug) Debug(_T(" ***Invalid packet version: 0x%02x\n"), uPCVersion); ASSERT(0); return false; } uint8 uPCOpcode = dataRecv.ReadUInt8(); if (uPCOpcode != PCOP_REQ){ if (bDebug) Debug(_T(" ***Invalid packet opcode: 0x%02x\n"), uPCOpcode); ASSERT(0); return false; } uint32 uCacheIP = 0; uint16 uCachePort = 0; uint32 uPushId = 0; uchar aucFileHash[16]; uint32 uRemoteIP = 0; md4clr(aucFileHash); CString strInfo; UINT uTags = dataRecv.ReadUInt8(); while (uTags--) { CTag tag(&dataRecv, GetUnicodeSupport()!=utf8strNone); if (tag.GetNameID() == PCTAG_CACHEIP && tag.IsInt()) { uCacheIP = tag.GetInt(); if (bDebug) strInfo.AppendFormat(_T(" CacheIP=%s"), ipstr(uCacheIP)); } else if (tag.GetNameID() == PCTAG_CACHEPORT && tag.IsInt()) { uCachePort = (uint16)tag.GetInt(); if (bDebug) strInfo.AppendFormat(_T(" CachePort=%u"), uCachePort); } else if (tag.GetNameID() == PCTAG_PUSHID && tag.IsInt()) { uPushId = tag.GetInt(); if (bDebug) strInfo.AppendFormat(_T(" PushId=%u"), uPushId); } else if (tag.GetNameID() == PCTAG_FILEID && tag.IsHash() && tag.GetHash() != NULL) { md4cpy(aucFileHash, tag.GetHash()); if (bDebug) strInfo.AppendFormat(_T(" FileId=%s"), md4str(aucFileHash)); } else if (tag.GetNameID() == PCTAG_PUBLICIP && tag.IsInt()) { uRemoteIP = tag.GetInt(); if (bDebug) strInfo.AppendFormat(_T(" PublicIP=%s"), ipstr(uRemoteIP)); } else { if (bDebug) strInfo.AppendFormat(_T(" ***UnkTag: %s"), tag.GetFullInfo()); ASSERT(0); } } if (bDebug) { if (dataRecv.GetPosition() < dataRecv.GetLength()) strInfo.AppendFormat(_T(" ***AddData: %u bytes"), (UINT)(dataRecv.GetLength() - dataRecv.GetPosition())); Debug(_T("%s\n"), strInfo); } if (uCacheIP == 0 || uCachePort == 0 || uPushId == 0 || isnulmd4(aucFileHash)){ if (thePrefs.GetVerbose()) AddDebugLogLine(false, _T("Invalid PeerCacheQuery; %s"), DbgGetClientInfo()); return false; } CKnownFile* pUploadFile = theApp.sharedfiles->GetFileByID(aucFileHash); if (pUploadFile == NULL){ if (thePrefs.GetVerbose()) AddDebugLogLine(false, _T("PeerCacheQuery reqfile does not match ed2k reqfile; %s"), DbgGetClientInfo()); return false; } if (m_pPCUpSocket != NULL) { SetPeerCacheUpState(PCUS_NONE); m_pPCUpSocket->Safe_Delete(); ASSERT( m_pPCUpSocket == NULL ); } m_pPCUpSocket = new CPeerCacheUpSocket(this); m_pPCUpSocket->SetTimeOut(GetPeerCacheSocketUploadTimeout()); m_pPCUpSocket->Create(); SOCKADDR_IN sockAddr = {0}; sockAddr.sin_family = AF_INET; sockAddr.sin_port = htons(uCachePort); sockAddr.sin_addr.S_un.S_addr = uCacheIP; //Try to always tell the socket to WaitForOnConnect before you call Connect. m_pPCUpSocket->WaitForOnConnect(); m_pPCUpSocket->Connect((SOCKADDR*)&sockAddr, sizeof sockAddr); CStringA strPCRequest; strPCRequest.AppendFormat("GIVE %u\r\n", uPushId); if (thePrefs.GetDebugClientTCPLevel() > 0){ DebugSend("PeerCache-GIVE", this, pUploadFile->GetFileHash()); Debug(_T(" %hs\n"), strPCRequest); } CRawPacket* pHttpPacket = new CRawPacket(strPCRequest); theStats.AddUpDataOverheadFileRequest(pHttpPacket->size); m_pPCUpSocket->SendPacket(pHttpPacket); m_pPCUpSocket->SetHttpState(HttpStateRecvExpected); m_bPeerCacheUpHit = false; SetPeerCacheUpState(PCUS_WAIT_CACHE_REPLY); //theApp.uploadBandwidthThrottler->AddToStandardList(0, m_pPCUpSocket); CSafeMemFile dataSend(128); dataSend.WriteUInt8(PCPCK_VERSION); dataSend.WriteUInt8(PCOP_RES); dataSend.WriteUInt8(3); CTag tagPushId(PCTAG_PUSHID, uPushId); tagPushId.WriteNewEd2kTag(&dataSend); CTag tagPublicIP(PCTAG_PUBLICIP, theApp.GetPublicIP()); tagPublicIP.WriteNewEd2kTag(&dataSend); CTag tagFileId(PCTAG_FILEID, (BYTE*)aucFileHash); tagFileId.WriteNewEd2kTag(&dataSend); if (thePrefs.GetDebugClientTCPLevel() > 0){ DebugSend("OP__PeerCacheAnswer", this, aucFileHash); Debug(_T(" PushId=%u PublicIP=%s FileId=%s\n"), tagPushId.GetInt(), ipstr(tagPublicIP.GetInt()), md4str(tagFileId.GetHash())); } Packet* pEd2kPacket = new Packet(&dataSend, OP_EMULEPROT, OP_PEERCACHE_ANSWER); theStats.AddUpDataOverheadFileRequest(pEd2kPacket->size); socket->SendPacket(pEd2kPacket); return true; }
bool CUpDownClient::SendPeerCacheFileRequest() { if (GetDownloadState() == DS_ONQUEUE){ ASSERT( m_ePeerCacheDownState == PCDS_NONE ); ASSERT( m_pPCDownSocket == NULL ); } else if (GetDownloadState() == DS_DOWNLOADING){ ASSERT( m_ePeerCacheDownState == PCDS_NONE ); ASSERT( m_pPCDownSocket == NULL ); } else{ ASSERT(0); } if (!SupportPeerCache() || socket == NULL){ ASSERT(0); return false; } m_uPeerCacheDownloadPushId = GetRandomUInt32(); CSafeMemFile data(128); data.WriteUInt8(PCPCK_VERSION); data.WriteUInt8(PCOP_REQ); data.WriteUInt8(5); CTag tagCacheIP(PCTAG_CACHEIP, theApp.m_pPeerCache->GetCacheIP()); tagCacheIP.WriteNewEd2kTag(&data); CTag tagPushId(PCTAG_PUSHID, m_uPeerCacheDownloadPushId); tagPushId.WriteNewEd2kTag(&data); CTag tagFileId(PCTAG_FILEID, (uchar*)reqfile->GetFileHash()); tagFileId.WriteNewEd2kTag(&data); CTag tagPublicIP(PCTAG_PUBLICIP, theApp.GetPublicIP()); tagPublicIP.WriteNewEd2kTag(&data); CTag tagCachePort(PCTAG_CACHEPORT, theApp.m_pPeerCache->GetCachePort()); tagCachePort.WriteNewEd2kTag(&data); if (thePrefs.GetDebugClientTCPLevel() > 0){ DebugSend("OP__PeerCacheQuery", this, reqfile->GetFileHash()); Debug(_T(" CacheIP=%s PushId=%u PublicIP=%s FileId=%s\n"), ipstr(tagCacheIP.GetInt()), tagPushId.GetInt(), ipstr(tagPublicIP.GetInt()), md4str(tagFileId.GetHash())); } Packet* pEd2kPacket = new Packet(&data, OP_EMULEPROT, OP_PEERCACHE_QUERY); theStats.AddUpDataOverheadFileRequest(pEd2kPacket->size); socket->SendPacket(pEd2kPacket); SetDownloadState(DS_DOWNLOADING); m_dwLastBlockReceived = ::GetTickCount(); SetPeerCacheDownState(PCDS_WAIT_CLIENT_REPLY); return true; }
BOOL CClientDetailPage::OnSetActive() { if (!CResizablePage::OnSetActive()) return FALSE; if (m_bDataChanged) { //Xman Code Fix //don't know how this happend, but happend with a friend: if(m_paClients==NULL) return FALSE; //Xman end CUpDownClient* client = STATIC_DOWNCAST(CUpDownClient, (*m_paClients)[0]); CString buffer; if (client->GetUserName()) GetDlgItem(IDC_DNAME)->SetWindowText(client->GetUserName()); else GetDlgItem(IDC_DNAME)->SetWindowText(_T("?")); //EastShare Start - added by AndCycle, IP to Country GetDlgItem(IDC_DLOC)->SetWindowText(client->GetCountryName(true)); //EastShare End - added by AndCycle, IP to Country if (client->HasValidHash()) GetDlgItem(IDC_DHASH)->SetWindowText(md4str(client->GetUserHash())); else GetDlgItem(IDC_DHASH)->SetWindowText(_T("?")); //Xman ModId /* GetDlgItem(IDC_DSOFT)->SetWindowText(client->GetClientSoftVer()); */ GetDlgItem(IDC_DSOFT)->SetWindowText(client->DbgGetFullClientSoftVer()); //Xman end if (client->SupportsCryptLayer() && thePrefs.IsClientCryptLayerSupported() && (client->RequestsCryptLayer() || thePrefs.IsClientCryptLayerRequested()) && (client->IsObfuscatedConnectionEstablished() || !(client->socket != NULL && client->socket->IsConnected()))) { buffer = GetResString(IDS_ENABLED); } else if (client->SupportsCryptLayer()) buffer = GetResString(IDS_SUPPORTED); else buffer = GetResString(IDS_IDENTNOSUPPORT); #if defined(_DEBUG) if (client->IsObfuscatedConnectionEstablished()) buffer += _T("(In Use)"); #endif GetDlgItem(IDC_OBFUSCATION_STAT)->SetWindowText(buffer); buffer.Format(_T("%s"),(client->HasLowID() ? GetResString(IDS_IDLOW):GetResString(IDS_IDHIGH))); GetDlgItem(IDC_DID)->SetWindowText(buffer); if (client->GetServerIP()){ GetDlgItem(IDC_DSIP)->SetWindowText(ipstr(client->GetServerIP())); CServer* cserver = theApp.serverlist->GetServerByIPTCP(client->GetServerIP(), client->GetServerPort()); if (cserver) GetDlgItem(IDC_DSNAME)->SetWindowText(cserver->GetListName()); else GetDlgItem(IDC_DSNAME)->SetWindowText(_T("?")); } else{ GetDlgItem(IDC_DSIP)->SetWindowText(_T("?")); GetDlgItem(IDC_DSNAME)->SetWindowText(_T("?")); } //Xman Queuerank at clientdetail if(client->GetUploadState()==US_ONUPLOADQUEUE) buffer.Format(_T("%u"),theApp.uploadqueue->GetWaitingPosition(client)); else buffer.Format(_T("-")); GetDlgItem(IDC_DOWNQUEUERANK)->SetWindowText(buffer); if(client->GetDownloadState()==DS_ONQUEUE) { if(client->IsRemoteQueueFull()) buffer = GetResString(IDS_QUEUEFULL); else buffer.Format(_T("%u"), client->GetRemoteQueueRank()); } else buffer.Format(_T("-")); GetDlgItem(IDC_UPLOADQUEURANK)->SetWindowText(buffer); //Xman end //Xman Anti-Leecher if(client->IsLeecher()>0 && client->GetBanMessageString().IsEmpty()==false) GetDlgItem(IDC_LEECHERINFO)->SetWindowText(client->GetBanMessageString()); else GetDlgItem(IDC_LEECHERINFO)->SetWindowText(_T(" ")); //Xman end // ==> requpfile optimization [SiRoB] - Stulle /* CKnownFile* file = theApp.sharedfiles->GetFileByID(client->GetUploadFileID()); */ CKnownFile* file = client->CheckAndGetReqUpFile(); // <== requpfile optimization [SiRoB] - Stulle if (file) GetDlgItem(IDC_DDOWNLOADING)->SetWindowText(file->GetFileName()); else GetDlgItem(IDC_DDOWNLOADING)->SetWindowText(_T("-")); if (client->GetRequestFile()) GetDlgItem(IDC_UPLOADING)->SetWindowText( client->GetRequestFile()->GetFileName() ); else GetDlgItem(IDC_UPLOADING)->SetWindowText(_T("-")); GetDlgItem(IDC_DDUP)->SetWindowText(CastItoXBytes(client->GetTransferredDown(), false, false)); GetDlgItem(IDC_DDOWN)->SetWindowText(CastItoXBytes(client->GetTransferredUp(), false, false)); buffer.Format(_T("%s"), CastItoXBytes(client->GetDownloadDatarate(), false, true)); GetDlgItem(IDC_DAVUR)->SetWindowText(buffer); //Xman // Maella -Accurate measure of bandwidth /* buffer.Format(_T("%s"),CastItoXBytes(client->GetDatarate(), false, true)); */ buffer.Format(_T("%s"),CastItoXBytes(client->GetUploadDatarate(), false, true)); //Xman end GetDlgItem(IDC_DAVDR)->SetWindowText(buffer); if (client->Credits()){ GetDlgItem(IDC_DUPTOTAL)->SetWindowText(CastItoXBytes(client->Credits()->GetDownloadedTotal(), false, false)); GetDlgItem(IDC_DDOWNTOTAL)->SetWindowText(CastItoXBytes(client->Credits()->GetUploadedTotal(), false, false)); // Xman Creditsystem /* buffer.Format(_T("%.1f"),(float)client->Credits()->GetScoreRatio(client->GetIP())); */ // ==> CreditSystems [EastShare/ MorphXT] - Stulle if (thePrefs.GetCreditSystem() == 7) // is Xman CS¿ buffer.Format(_T("%.1f %+.1f [%.1f]"),(float)client->Credits()->GetScoreRatio(client)- (float)client->Credits()->GetBonusFaktor(client),(float)client->Credits()->GetBonusFaktor(client),(float)client->Credits()->GetMyScoreRatio(client->GetIP())); // See own credits VQB else buffer.Format(_T("%.1f [%.1f]"),(float)client->Credits()->GetScoreRatio(client),(float)client->Credits()->GetMyScoreRatio(client->GetIP())); // See own credits VQB // <== CreditSystems [EastShare/ MorphXT] - Stulle //Xman Creditsystem end GetDlgItem(IDC_DRATIO)->SetWindowText(buffer); if (theApp.clientcredits->CryptoAvailable()){ switch(client->Credits()->GetCurrentIdentState(client->GetIP())){ case IS_NOTAVAILABLE: GetDlgItem(IDC_CDIDENT)->SetWindowText(GetResString(IDS_IDENTNOSUPPORT)); break; case IS_IDFAILED: case IS_IDNEEDED: case IS_IDBADGUY: GetDlgItem(IDC_CDIDENT)->SetWindowText(GetResString(IDS_IDENTFAILED)); break; case IS_IDENTIFIED: GetDlgItem(IDC_CDIDENT)->SetWindowText(GetResString(IDS_IDENTOK)); break; } } else GetDlgItem(IDC_CDIDENT)->SetWindowText(GetResString(IDS_IDENTNOSUPPORT)); } else{ GetDlgItem(IDC_DDOWNTOTAL)->SetWindowText(_T("?")); GetDlgItem(IDC_DUPTOTAL)->SetWindowText(_T("?")); GetDlgItem(IDC_DRATIO)->SetWindowText(_T("?")); GetDlgItem(IDC_CDIDENT)->SetWindowText(_T("?")); } if (client->GetUserName() && client->Credits()!=NULL){ buffer.Format(_T("%.1f"),(float)client->GetScore(false,client->IsDownloading(),true)); GetDlgItem(IDC_DRATING)->SetWindowText(buffer); } else GetDlgItem(IDC_DRATING)->SetWindowText(_T("?")); if (client->GetUploadState() != US_NONE && client->Credits()!=NULL){ if (!client->GetFriendSlot()){ buffer.Format(_T("%u"),client->GetScore(false,client->IsDownloading(),false)); GetDlgItem(IDC_DSCORE)->SetWindowText(buffer); } else GetDlgItem(IDC_DSCORE)->SetWindowText(GetResString(IDS_FRIENDDETAIL)); } else GetDlgItem(IDC_DSCORE)->SetWindowText(_T("-")); if (client->GetKadPort() ) buffer.Format( _T("%s"), GetResString(IDS_CONNECTED)); else buffer.Format( _T("%s"), GetResString(IDS_DISCONNECTED)); GetDlgItem(IDC_CLIENTDETAIL_KADCON)->SetWindowText(buffer); m_bDataChanged = false; } return TRUE; }
bool CServerSocket::ProcessPacket(const BYTE* packet, uint32 size, uint8 opcode) { try { switch (opcode) { case OP_SERVERMESSAGE:{ if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("ServerMsg - OP_ServerMessage\n")); CServer* pServer = cur_server ? theApp.serverlist->GetServerByAddress(cur_server->GetAddress(), cur_server->GetPort()) : NULL; CSafeMemFile data(packet, size); CString strMessages(data.ReadString(pServer ? pServer->GetUnicodeSupport() : false)); if (thePrefs.GetDebugServerTCPLevel() > 0){ UINT uAddData = (UINT)(data.GetLength() - data.GetPosition()); if (uAddData > 0){ Debug(_T("*** NOTE: OP_ServerMessage: ***AddData: %u bytes\n"), uAddData); DebugHexDump(packet + data.GetPosition(), uAddData); } } // 16.40 servers do not send separate OP_SERVERMESSAGE packets for each line; // instead of this they are sending all text lines with one OP_SERVERMESSAGE packet. int iPos = 0; CString message = strMessages.Tokenize(_T("\r\n"), iPos); while (!message.IsEmpty()) { bool bOutputMessage = true; if (_tcsnicmp(message, _T("server version"), 14) == 0){ CString strVer = message.Mid(14); strVer.Trim(); strVer = strVer.Left(64); // truncate string to avoid misuse by servers in showing ads if (pServer){ UINT nVerMaj, nVerMin; if (_stscanf(strVer, _T("%u.%u"), &nVerMaj, &nVerMin) == 2) strVer.Format(_T("%u.%02u"), nVerMaj, nVerMin); pServer->SetVersion(strVer); theApp.emuledlg->serverwnd->serverlistctrl.RefreshServer(pServer); theApp.emuledlg->serverwnd->UpdateMyInfo(); } if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("%s\n"), message); } else if (_tcsncmp(message, _T("ERROR"), 5) == 0){ LogError(LOG_STATUSBAR, _T("%s %s (%s:%u) - %s"), GetResString(IDS_ERROR), pServer ? pServer->GetListName() : GetResString(IDS_PW_SERVER), cur_server ? cur_server->GetAddress() : _T(""), cur_server ? cur_server->GetPort() : 0, message.Mid(5).Trim(_T(" :"))); bOutputMessage = false; } else if (_tcsncmp(message, _T("WARNING"), 7) == 0){ LogWarning(LOG_STATUSBAR, _T("%s %s (%s:%u) - %s"), GetResString(IDS_WARNING), pServer ? pServer->GetListName() : GetResString(IDS_PW_SERVER), cur_server ? cur_server->GetAddress() : _T(""), cur_server ? cur_server->GetPort() : 0, message.Mid(7).Trim(_T(" :"))); bOutputMessage = false; } if (message.Find(_T("[emDynIP: ")) != -1 && message.Find(_T("]")) != -1 && message.Find(_T("[emDynIP: ")) < message.Find(_T("]"))){ CString dynip = message.Mid(message.Find(_T("[emDynIP: ")) + 10, message.Find(_T("]")) - (message.Find(_T("[emDynIP: ")) + 10)); dynip.Trim(); if (dynip.GetLength() && dynip.GetLength() < 51){ // Verify that we really received a DN. if (pServer && inet_addr(CStringA(dynip)) == INADDR_NONE){ // Update the dynIP of this server, but do not reset it's IP // which we just determined during connecting. CString strOldDynIP = pServer->GetDynIP(); pServer->SetDynIP(dynip); // If a dynIP-server changed its address or, if this is the // first time we get the dynIP-address for a server which we // already have as non-dynIP in our list, we need to remove // an already available server with the same 'dynIP:port'. if (strOldDynIP.CompareNoCase(pServer->GetDynIP()) != 0) theApp.serverlist->RemoveDuplicatesByAddress(pServer); if (cur_server) cur_server->SetDynIP(dynip); theApp.emuledlg->serverwnd->serverlistctrl.RefreshServer(pServer); theApp.emuledlg->serverwnd->UpdateMyInfo(); } } } if (bOutputMessage) { if (m_bStartNewMessageLog) { m_bStartNewMessageLog = false; theApp.emuledlg->AddServerMessageLine(LOG_INFO, _T("")); if (cur_server) { CString strMsg; if (IsObfusicating()) strMsg.Format(_T("%s: ") + GetResString(IDS_CONNECTEDTOOBFUSCATED) + _T(" (%s:%u)"), CTime::GetCurrentTime().Format(thePrefs.GetDateTimeFormat4Log()), cur_server->GetListName(), cur_server->GetAddress(), cur_server->GetObfuscationPortTCP()); else strMsg.Format(_T("%s: ") + GetResString(IDS_CONNECTEDTO) + _T(" (%s:%u)"), CTime::GetCurrentTime().Format(thePrefs.GetDateTimeFormat4Log()), cur_server->GetListName(), cur_server->GetAddress(), cur_server->GetPort()); theApp.emuledlg->AddServerMessageLine(LOG_SUCCESS, strMsg); } } theApp.emuledlg->AddServerMessageLine(LOG_INFO, message); } message = strMessages.Tokenize(_T("\r\n"), iPos); } break; } case OP_IDCHANGE:{ if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("ServerMsg - OP_IDChange\n")); if (size < sizeof(LoginAnswer_Struct)){ throw GetResString(IDS_ERR_BADSERVERREPLY); } LoginAnswer_Struct* la = (LoginAnswer_Struct*)packet; // save TCP flags in 'cur_server' CServer* pServer = NULL; ASSERT( cur_server ); if (cur_server){ if (size >= sizeof(LoginAnswer_Struct)+4){ DWORD dwFlags = *((uint32*)(packet + sizeof(LoginAnswer_Struct))); if (thePrefs.GetDebugServerTCPLevel() > 0){ CString strInfo; strInfo.AppendFormat(_T(" TCP Flags=0x%08x"), dwFlags); const DWORD dwKnownBits = SRV_TCPFLG_COMPRESSION | SRV_TCPFLG_NEWTAGS | SRV_TCPFLG_UNICODE | SRV_TCPFLG_RELATEDSEARCH | SRV_TCPFLG_TYPETAGINTEGER | SRV_TCPFLG_LARGEFILES | SRV_TCPFLG_TCPOBFUSCATION; if (dwFlags & ~dwKnownBits) strInfo.AppendFormat(_T(" ***UnkBits=0x%08x"), dwFlags & ~dwKnownBits); if (dwFlags & SRV_TCPFLG_COMPRESSION) strInfo.AppendFormat(_T(" Compression=1")); if (dwFlags & SRV_TCPFLG_NEWTAGS) strInfo.AppendFormat(_T(" NewTags=1")); if (dwFlags & SRV_TCPFLG_UNICODE) strInfo.AppendFormat(_T(" Unicode=1")); if (dwFlags & SRV_TCPFLG_RELATEDSEARCH) strInfo.AppendFormat(_T(" RelatedSearch=1")); if (dwFlags & SRV_TCPFLG_TYPETAGINTEGER) strInfo.AppendFormat(_T(" IntTypeTags=1")); if (dwFlags & SRV_TCPFLG_LARGEFILES) strInfo.AppendFormat(_T(" LargeFiles=1")); if (dwFlags & SRV_TCPFLG_TCPOBFUSCATION) strInfo.AppendFormat(_T(" TCP_Obfscation=1")); Debug(_T("%s\n"), strInfo); } cur_server->SetTCPFlags(dwFlags); } else cur_server->SetTCPFlags(0); // copy TCP flags into the server in the server list pServer = theApp.serverlist->GetServerByAddress(cur_server->GetAddress(), cur_server->GetPort()); if (pServer) pServer->SetTCPFlags(cur_server->GetTCPFlags()); } uint32 dwServerReportedIP = 0; uint32 dwObfuscationTCPPort = 0; if (size >= 20){ dwServerReportedIP = *((uint32*)(packet + 12)); if (::IsLowID(dwServerReportedIP)){ ASSERT( false ); dwServerReportedIP = 0; } ASSERT( dwServerReportedIP == la->clientid || ::IsLowID(la->clientid) ); dwObfuscationTCPPort = *((uint32*)(packet + 16)); if (cur_server != NULL && dwObfuscationTCPPort != 0) cur_server->SetObfuscationPortTCP((uint16)dwObfuscationTCPPort); if (pServer != NULL && dwObfuscationTCPPort != 0) pServer->SetObfuscationPortTCP((uint16)dwObfuscationTCPPort); } //Xman // Maella -Activate Smart Low ID check- /* if (la->clientid == 0) { uint8 state = thePrefs.GetSmartIdState(); if ( state > 0 ) { if (state == 1) theApp.emuledlg->RefreshUPnP(false); // refresh the UPnP mappings once state++; if( state > 2 ) thePrefs.SetSmartIdState(0); else thePrefs.SetSmartIdState(state); } break; } if( thePrefs.GetSmartIdCheck() ){ if (!IsLowID(la->clientid)) thePrefs.SetSmartIdState(1); else{ uint8 state = thePrefs.GetSmartIdState(); if ( state > 0 ) { if (state == 1) theApp.emuledlg->RefreshUPnP(false); // refresh the UPnP mappings once state++; if( state > 2 ) thePrefs.SetSmartIdState(0); else thePrefs.SetSmartIdState(state); if (!m_bManualSingleConnect) break; // if this is a connect to any/multiple server connection try, disconnect and try another one } } } */ if(la->clientid == 0){ // Reset attempts counter thePrefs.SetSmartIdState(0); } else if(la->clientid >= 16777216){ // High ID => reset attempts counter thePrefs.SetSmartIdState(0); } else if(thePrefs.GetSmartIdCheck() == true){ // Low ID => Check and increment attempts counter uint8 attempts = thePrefs.GetSmartIdState(); if(attempts < 3){ //zz_fly :: not needed, rebind upnp on ipchange :: start //Official UPNP /* if (!thePrefs.m_bUseACATUPnPCurrent && (attempts == 1)) theApp.emuledlg->RefreshUPnP(false); // refresh the UPnP mappings once */ //zz_fly :: end SetConnectionState(CS_ERROR); thePrefs.SetSmartIdState(++attempts); AddLogLine(true, _T("LowID -- Trying Again (attempts %i)"), attempts); break; // Retries } else if (!m_bManualSingleConnect) break; // if this is a connect to any/multiple server connection try, disconnect and try another one } //Xman end // we need to know our client's HighID when sending our shared files (done indirectly on SetConnectionState) serverconnect->clientid = la->clientid; if (connectionstate != CS_CONNECTED) { SetConnectionState(CS_CONNECTED); theApp.OnlineSig(); // Added By Bouc7 } serverconnect->SetClientID(la->clientid); if (::IsLowID(la->clientid) && dwServerReportedIP != 0) theApp.SetPublicIP(dwServerReportedIP); AddLogLine(false, GetResString(IDS_NEWCLIENTID), la->clientid); //Xman -Reask sources after IP change- v4 if(serverconnect->GetClientID() != 0 && theApp.last_valid_ip != 0 && serverconnect->GetClientID() != theApp.last_valid_ip && serverconnect->GetClientID() != theApp.last_valid_serverid) { //remark: this code doesn't trigger when changing low->hidh-ID and we already had //a session with this HighID-IP. This is because we don't know when this last lowID-session was. //but there is no need to trigger when changing low to high-id but keeping the IP, we can'tt loose the waiting-position! { // Public IP has been changed, it's necessary to inform all sources about it // All sources would be informed during their next session refresh (with TCP) // about the new IP. // ==> Quick start [TPT] - Max if(thePrefs.GetQuickStart() && thePrefs.GetQuickStartAfterIPChange()) { theApp.downloadqueue->quickflag = 0; theApp.downloadqueue->quickflags = 0; } // <== Quick start [TPT] - Max if(GetTickCount() - theApp.last_ip_change > FILEREASKTIME + 60000){ theApp.clientlist->TrigReaskForDownload(true); theApp.last_ip_change=::GetTickCount(); theApp.m_bneedpublicIP=false; AddLogLine(false, _T("Change from %u (%s ID) to %u (%s ID) detected%s"), theApp.last_valid_serverid, (theApp.last_valid_serverid < 16777216) ? _T("low") : _T("high"), serverconnect->GetClientID(), (serverconnect->GetClientID() < 16777216) ? _T("low") : _T("high"), _T(", all sources will be reasked immediately")); } else { theApp.clientlist->TrigReaskForDownload(false); theApp.last_ip_change=::GetTickCount(); theApp.m_bneedpublicIP=false; AddLogLine(false, _T("Change from %u (%s ID) to %u (%s ID) detected%s"), theApp.last_valid_serverid, (theApp.last_valid_serverid < 16777216) ? _T("low") : _T("high"), serverconnect->GetClientID(), (serverconnect->GetClientID() < 16777216) ? _T("low") : _T("high"), _T(", all sources will be reasked within the next 10 minutes")); } // ==> UPnP support [MoNKi] - leuk_he /* // official UPNP theApp.emuledlg->RefreshUPnP(false); // refresh the UPnP mappings once // official UPNP */ theApp.RebindUPnP(); // <== UPnP support [MoNKi] - leuk_he } } if(serverconnect->GetClientID() != 0 && theApp.last_ip_change==0) theApp.last_ip_change=::GetTickCount(); if(serverconnect->GetClientID() != 0 && serverconnect->GetClientID() != theApp.last_valid_serverid){ // Keep track of a change of the global IP theApp.last_valid_serverid = serverconnect->GetClientID(); } theApp.last_valid_ip=theApp.GetPublicIP(true); //can also be 0 theApp.last_traffic_reception=::GetTickCount(); theApp.internetmaybedown=false; //we have to reopen here if we are using server only // Xman end theApp.downloadqueue->ResetLocalServerRequests(); break; } case OP_SEARCHRESULT:{ if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("ServerMsg - OP_SearchResult\n")); CServer* cur_srv = (serverconnect) ? serverconnect->GetCurrentServer() : NULL; CServer* pServer = cur_srv ? theApp.serverlist->GetServerByAddress(cur_srv->GetAddress(), cur_srv->GetPort()) : NULL; (void)pServer; bool bMoreResultsAvailable; UINT uSearchResults = theApp.searchlist->ProcessSearchAnswer(packet, size, true/*pServer ? pServer->GetUnicodeSupport() : false*/, cur_srv ? cur_srv->GetIP() : 0, cur_srv ? cur_srv->GetPort() : (uint16)0, &bMoreResultsAvailable); theApp.emuledlg->searchwnd->LocalEd2kSearchEnd(uSearchResults, bMoreResultsAvailable); break; } case OP_FOUNDSOURCES_OBFU: case OP_FOUNDSOURCES:{ if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("ServerMsg - OP_FoundSources%s; Sources=%u %s\n"), (opcode == OP_FOUNDSOURCES_OBFU) ? _T("_OBFU") : _T(""), (UINT)packet[16], DbgGetFileInfo(packet)); ASSERT( cur_server ); if (cur_server) { CSafeMemFile sources(packet, size); uchar fileid[16]; sources.ReadHash16(fileid); if (CPartFile* file = theApp.downloadqueue->GetFileByID(fileid)) file->AddSources(&sources,cur_server->GetIP(), cur_server->GetPort(), (opcode == OP_FOUNDSOURCES_OBFU)); } break; } case OP_SERVERSTATUS:{ if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("ServerMsg - OP_ServerStatus\n")); // FIXME some statuspackets have a different size -> why? structur? if (size < 8) break;//throw "Invalid status packet"; uint32 cur_user = PeekUInt32(packet); uint32 cur_files = PeekUInt32(packet+4); CServer* pServer = cur_server ? theApp.serverlist->GetServerByAddress(cur_server->GetAddress(), cur_server->GetPort()) : NULL; if (pServer){ pServer->SetUserCount(cur_user); pServer->SetFileCount(cur_files); theApp.emuledlg->ShowUserCount(); theApp.emuledlg->serverwnd->serverlistctrl.RefreshServer(pServer); theApp.emuledlg->serverwnd->UpdateMyInfo(); } if (thePrefs.GetDebugServerTCPLevel() > 0){ if (size > 8){ Debug(_T("*** NOTE: OP_ServerStatus: ***AddData: %u bytes\n"), size - 8); DebugHexDump(packet + 8, size - 8); } } break; } case OP_SERVERIDENT:{ // OP_SERVERIDENT - this is sent by the server only if we send a OP_GETSERVERLIST if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("ServerMsg - OP_ServerIdent\n")); if (size<16+4+2+4){ if (thePrefs.GetVerbose()) DebugLogError(_T("%s"), GetResString(IDS_ERR_KNOWNSERVERINFOREC)); break;// throw "Invalid server info received"; } CServer* pServer = cur_server ? theApp.serverlist->GetServerByAddress(cur_server->GetAddress(),cur_server->GetPort()) : NULL; CString strInfo; CSafeMemFile data(packet, size); uint8 aucHash[16]; data.ReadHash16(aucHash); if (thePrefs.GetDebugServerTCPLevel() > 0) strInfo.AppendFormat(_T("Hash=%s (%s)"), md4str(aucHash), DbgGetHashTypeString(aucHash)); uint32 nServerIP = data.ReadUInt32(); uint16 nServerPort = data.ReadUInt16(); if (thePrefs.GetDebugServerTCPLevel() > 0) strInfo.AppendFormat(_T(" IP=%s:%u"), ipstr(nServerIP), nServerPort); UINT nTags = data.ReadUInt32(); if (thePrefs.GetDebugServerTCPLevel() > 0) strInfo.AppendFormat(_T(" Tags=%u"), nTags); CString strName; CString strDescription; for (UINT i = 0; i < nTags; i++){ CTag tag(&data, pServer ? pServer->GetUnicodeSupport() : false); if (tag.GetNameID() == ST_SERVERNAME){ if (tag.IsStr()){ strName = tag.GetStr(); if (thePrefs.GetDebugServerTCPLevel() > 0) strInfo.AppendFormat(_T(" Name=%s"), strName); } } else if (tag.GetNameID() == ST_DESCRIPTION){ if (tag.IsStr()){ strDescription = tag.GetStr(); if (thePrefs.GetDebugServerTCPLevel() > 0) strInfo.AppendFormat(_T(" Desc=%s"), strDescription); } } else if (thePrefs.GetDebugServerTCPLevel() > 0) strInfo.AppendFormat(_T(" ***UnkTag: 0x%02x=%u"), tag.GetNameID(), tag.GetInt()); } if (thePrefs.GetDebugServerTCPLevel() > 0){ strInfo += _T('\n'); Debug(_T("%s"), strInfo); UINT uAddData = (UINT)(data.GetLength() - data.GetPosition()); if (uAddData > 0){ Debug(_T("*** NOTE: OP_ServerIdent: ***AddData: %u bytes\n"), uAddData); DebugHexDump(packet + data.GetPosition(), uAddData); } } if (pServer){ pServer->SetListName(strName); pServer->SetDescription(strDescription); if (((uint32*)aucHash)[0] == 0x2A2A2A2A){ const CString& rstrVersion = pServer->GetVersion(); if (!rstrVersion.IsEmpty()) pServer->SetVersion(_T("eFarm ") + rstrVersion); else pServer->SetVersion(_T("eFarm")); } theApp.emuledlg->ShowConnectionState(); theApp.emuledlg->serverwnd->serverlistctrl.RefreshServer(pServer); } break; } // tecxx 1609 2002 - add server's serverlist to own serverlist case OP_SERVERLIST:{ if (!thePrefs.GetAddServersFromServer()) break; if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("ServerMsg - OP_ServerList\n")); try{ CSafeMemFile servers(packet, size); UINT count = servers.ReadUInt8(); // check if packet is valid if (1 + count*(4+2) > size) count = 0; int addcount = 0; while(count) { uint32 ip = servers.ReadUInt32(); uint16 port = servers.ReadUInt16(); CServer* srv = new CServer(port, ipstr(ip)); srv->SetListName(srv->GetFullIP()); srv->SetPreference(SRV_PR_LOW); if (!theApp.emuledlg->serverwnd->serverlistctrl.AddServer(srv, true)) delete srv; else addcount++; count--; } if (addcount) AddLogLine(false, GetResString(IDS_NEWSERVERS), addcount); if (thePrefs.GetDebugServerTCPLevel() > 0){ UINT uAddData = (UINT)(servers.GetLength() - servers.GetPosition()); if (uAddData > 0){ Debug(_T("*** NOTE: OP_ServerList: ***AddData: %u bytes\n"), uAddData); DebugHexDump(packet + servers.GetPosition(), uAddData); } } } catch(CFileException* error){ if (thePrefs.GetVerbose()) DebugLogError(_T("%s"), GetResString(IDS_ERR_BADSERVERLISTRECEIVED)); error->Delete(); } break; } case OP_CALLBACKREQUESTED:{ if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("ServerMsg - OP_CallbackRequested: %s\n"), (size >= 23) ? _T("With Cryptflag and Userhash") : _T("Without Cryptflag and Userhash")); if (size >= 6) { uint32 dwIP = PeekUInt32(packet); if (theApp.ipfilter->IsFiltered(dwIP)){ theStats.filteredclients++; if (thePrefs.GetLogFilteredIPs()) AddDebugLogLine(false, _T("Ignored callback request (IP=%s) - IP filter (%s)"), ipstr(dwIP), theApp.ipfilter->GetLastHit()); break; } if (theApp.clientlist->IsBannedClient(dwIP)){ if (thePrefs.GetLogBannedClients()){ CUpDownClient* pClient = theApp.clientlist->FindClientByIP(dwIP); //Xman Code Fix /* AddDebugLogLine(false, _T("Ignored callback request from banned client %s; %s"), ipstr(dwIP), pClient->DbgGetClientInfo()); */ AddDebugLogLine(false, _T("Ignored callback request from banned client %s; %s"), ipstr(dwIP), pClient ? pClient->DbgGetClientInfo() : _T("unknown")); //Xman end } break; } uint16 nPort = PeekUInt16(packet+4); uint8 byCryptOptions = 0; uchar achUserHash[16]; if (size >= 23){ byCryptOptions = packet[6]; md4cpy(achUserHash, packet + 7); } CUpDownClient* client = theApp.clientlist->FindClientByIP(dwIP,nPort); if (client == NULL) { client = new CUpDownClient(0,nPort,dwIP,0,0,true); //Xman Code Improvement don't search new generated clients in lists /* theApp.clientlist->AddClient(client); */ theApp.clientlist->AddClient(client, true); //Xman end } if (size >= 23 && client->HasValidHash()){ if (md4cmp(client->GetUserHash(), achUserHash) != 0){ DebugLogError(_T("Reported Userhash from OP_CALLBACKREQUESTED differs with our stored hash")); // disable crypt support since we dont know which hash is true client->SetCryptLayerRequest(false); client->SetCryptLayerSupport(false); client->SetCryptLayerRequires(false); } else{ client->SetConnectOptions(byCryptOptions, true, false); client->SetDirectUDPCallbackSupport(false); } } else if (size >= 23){ client->SetUserHash(achUserHash); client->SetCryptLayerSupport((byCryptOptions & 0x01) != 0); client->SetCryptLayerRequest((byCryptOptions & 0x02) != 0); client->SetCryptLayerRequires((byCryptOptions & 0x04) != 0); client->SetDirectUDPCallbackSupport(false); } client->TryToConnect(); } break; } case OP_CALLBACK_FAIL:{ if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("ServerMsg - OP_Callback_Fail %s\n"), DbgGetHexDump(packet, size)); break; } case OP_REJECT:{ if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("ServerMsg - OP_Reject %s\n"), DbgGetHexDump(packet, size)); // this could happen if we send a command with the wrong protocol (e.g. sending a compressed packet to // a server which does not support that protocol). if (thePrefs.GetVerbose()) DebugLogError(_T("Server rejected last command")); break; } default: if (thePrefs.GetDebugServerTCPLevel() > 0) Debug(_T("***NOTE: ServerMsg - Unknown message; opcode=0x%02x %s\n"), opcode, DbgGetHexDump(packet, size)); ; } return true; } catch(CFileException* error) { if (thePrefs.GetVerbose()) { TCHAR szError[MAX_CFEXP_ERRORMSG]; error->m_strFileName = _T("server packet"); error->GetErrorMessage(szError, ARRSIZE(szError)); ProcessPacketError(size, opcode, szError); } ASSERT(0); error->Delete(); if (opcode==OP_SEARCHRESULT || opcode==OP_FOUNDSOURCES) return true; } catch(CMemoryException* error) { ProcessPacketError(size, opcode, _T("CMemoryException")); ASSERT(0); error->Delete(); if (opcode==OP_SEARCHRESULT || opcode==OP_FOUNDSOURCES) return true; } catch(CString error) { ProcessPacketError(size, opcode, error); ASSERT(0); } #ifndef _DEBUG catch(...) { ProcessPacketError(size, opcode, _T("Unknown exception")); ASSERT(0); } #endif SetConnectionState(CS_DISCONNECTED); return false; }
BOOL CCollectionViewDialog::OnInitDialog(void) { CDialog::OnInitDialog(); InitWindowStyles(this); if (!m_pCollection) { ASSERT(0); return TRUE; } m_CollectionViewList.Init(_T("CollectionView")); SetIcon(m_icoWnd = theApp.LoadIcon(_T("Collection_View")), FALSE); m_AddNewCatagory.SetCheck(false); SetWindowText(GetResString(IDS_VIEWCOLLECTION) + _T(": ") + m_pCollection->m_sCollectionName); m_CollectionViewListIcon.SetIcon(m_icoColl = theApp.LoadIcon(_T("AABCollectionFileType"))); m_CollectionDownload.SetWindowText(GetResString(IDS_DOWNLOAD)); m_CollectionExit.SetWindowText(GetResString(IDS_CW_CLOSE)); SetDlgItemText(IDC_COLLECTIONVIEWAUTHORLABEL, GetResString(IDS_AUTHOR) + _T(":")); SetDlgItemText(IDC_COLLECTIONVIEWAUTHORKEYLABEL, GetResString(IDS_AUTHORKEY) + _T(":")); SetDlgItemText(IDC_COLLECTIONVIEWCATEGORYCHECK, GetResString(IDS_COLL_ADDINCAT)); SetDlgItemText(IDC_VCOLL_DETAILS, GetResString(IDS_DETAILS)); SetDlgItemText(IDC_VCOLL_OPTIONS, GetResString(IDS_OPTIONS)); m_CollectionViewAuthor.SetWindowText(m_pCollection->m_sCollectionAuthorName); m_CollectionViewAuthorKey.SetWindowText(m_pCollection->GetAuthorKeyHashString()); AddAnchor(IDC_COLLECTIONVEWLIST, TOP_LEFT, BOTTOM_RIGHT); AddAnchor(IDC_VCOLL_DETAILS, BOTTOM_LEFT, BOTTOM_RIGHT); AddAnchor(IDC_VCOLL_OPTIONS, BOTTOM_LEFT, BOTTOM_RIGHT); AddAnchor(IDC_COLLECTIONVIEWAUTHORLABEL, BOTTOM_LEFT); AddAnchor(IDC_COLLECTIONVIEWAUTHORKEYLABEL, BOTTOM_LEFT); AddAnchor(IDC_COLLECTIONVIEWCATEGORYCHECK, BOTTOM_LEFT); AddAnchor(IDC_COLLECTIONVIEWAUTHOR, BOTTOM_LEFT, BOTTOM_RIGHT); AddAnchor(IDC_COLLECTIONVIEWAUTHORKEY, BOTTOM_LEFT, BOTTOM_RIGHT); AddAnchor(IDC_VCOLL_CLOSE, BOTTOM_RIGHT); AddAnchor(IDC_VIEWCOLLECTIONDL, BOTTOM_RIGHT); EnableSaveRestore(PREF_INI_SECTION); POSITION pos = m_pCollection->m_CollectionFilesMap.GetStartPosition(); while (pos != NULL) { CCollectionFile* pCollectionFile; CSKey key; m_pCollection->m_CollectionFilesMap.GetNextAssoc(pos, key, pCollectionFile); int iImage = theApp.GetFileTypeSystemImageIdx(pCollectionFile->GetFileName()); int iItem = m_CollectionViewList.InsertItem(LVIF_TEXT | LVIF_PARAM | (iImage > 0 ? LVIF_IMAGE : 0), m_CollectionViewList.GetItemCount(), NULL, 0, 0, iImage, (LPARAM)pCollectionFile); if (iItem != -1) { m_CollectionViewList.SetItemText(iItem, colName, pCollectionFile->GetFileName()); m_CollectionViewList.SetItemText(iItem, colSize, CastItoXBytes(pCollectionFile->GetFileSize())); m_CollectionViewList.SetItemText(iItem, colHash, md4str(pCollectionFile->GetFileHash())); } } int iItem = m_CollectionViewList.GetItemCount(); while (iItem) m_CollectionViewList.SetItemState(--iItem, LVIS_SELECTED, LVIS_SELECTED); CString strTitle; strTitle.Format(GetResString(IDS_COLLECTIONLIST) + _T(" (%u)"), m_CollectionViewList.GetItemCount()); m_CollectionViewListLabel.SetWindowText(strTitle); return TRUE; }
bool CKnownFileList::SafeAddKFile(CKnownFile* toadd) { bool bRemovedDuplicateSharedFile = false; CCKey key(toadd->GetFileHash()); CKnownFile* pFileInMap; if (m_Files_map.Lookup(key, pFileInMap)) { TRACE(_T("%hs: Already in known list: %s %I64u \"%s\"\n"), __FUNCTION__, md4str(pFileInMap->GetFileHash()), pFileInMap->GetFileSize(), pFileInMap->GetFileName()); TRACE(_T("%hs: Old entry replaced with: %s %I64u \"%s\"\n"), __FUNCTION__, md4str(toadd->GetFileHash()), toadd->GetFileSize(), toadd->GetFileName()); // if we hash files which are already in known file list and add them later (when the hashing thread is finished), // we can not delete any already available entry from known files list. that entry can already be used by the // shared file list -> crash. m_Files_map.RemoveKey(CCKey(pFileInMap->GetFileHash())); m_mapKnownFilesByAICH.RemoveKey(pFileInMap->GetAICHHashset()->GetMasterHash()); //This can happen in a couple situations.. //File was renamed outside of eMule.. //A user decided to redownload a file he has downloaded and unshared.. //RemovingKeyWords I believe is not thread safe if I'm looking at this right. //Not sure of a good solution yet.. if (theApp.sharedfiles) { #if 0 // This may crash the client because of dangling ptr in shared files ctrl. // This may happen if a file is re-shared which is also currently downloaded. // After the file was downloaded (again) there is a dangl. ptr in shared files // ctrl. // Actually that's also wrong in some cases: Keywords are not always removed // because the wrong ptr is used to search for in keyword publish list. theApp.sharedfiles->RemoveKeywords(pFileInMap); #else // This solves the problem with dangl. ptr in shared files ctrl, // but creates a new bug. It may lead to unshared files! Even // worse it may lead to files which are 'shared' in GUI but // which are though not shared 'logically'. // // To reduce the harm, remove the file from shared files list, // only if really needed. Right now this 'harm' applies for files // which are re-shared and then completed (again) because they were // also in download queue (they were added there when the already // available file was not in shared file list). if (theApp.sharedfiles->IsFilePtrInList(pFileInMap)) bRemovedDuplicateSharedFile = theApp.sharedfiles->RemoveFile(pFileInMap); #endif ASSERT( !theApp.sharedfiles->IsFilePtrInList(pFileInMap) ); } //Double check to make sure this is the same file as it's possible that a two files have the same hash. //Maybe in the furture we can change the client to not just use Hash as a key throughout the entire client.. ASSERT( toadd->GetFileSize() == pFileInMap->GetFileSize() ); ASSERT( toadd != pFileInMap ); if (toadd->GetFileSize() == pFileInMap->GetFileSize()) toadd->statistic.MergeFileStats(&pFileInMap->statistic); ASSERT( theApp.sharedfiles==NULL || !theApp.sharedfiles->IsFilePtrInList(pFileInMap) ); ASSERT( theApp.downloadqueue==NULL || !theApp.downloadqueue->IsPartFile(pFileInMap) ); // Quick fix: If we downloaded already downloaded files again and if those files all had the same file names // and were renamed during file completion, we have a pending ptr in transfer window. if (theApp.emuledlg && theApp.emuledlg->transferwnd && theApp.emuledlg->transferwnd->downloadlistctrl.m_hWnd) theApp.emuledlg->transferwnd->downloadlistctrl.RemoveFile((CPartFile*)pFileInMap); delete pFileInMap; } m_Files_map.SetAt(key, toadd); if (bRemovedDuplicateSharedFile) { theApp.sharedfiles->SafeAddKFile(toadd); } if (toadd->GetAICHHashset()->HasValidMasterHash()) m_mapKnownFilesByAICH.SetAt(toadd->GetAICHHashset()->GetMasterHash(), toadd); return true; }
void CMetaDataDlg::InitTags() { CWaitCursor curWait; m_tags.DeleteAllItems(); m_tags.SetRedraw(FALSE); int iMetaTags = 0; if (m_file != NULL) { LVITEM lvi; lvi.mask = LVIF_TEXT; lvi.iItem = INT_MAX; lvi.iSubItem = META_DATA_COL_NAME; CString strBuff = GetResString(IDS_FD_HASH); StripTrailingCollon(strBuff); lvi.pszText = const_cast<LPTSTR>((LPCTSTR)strBuff); int iItem = m_tags.InsertItem(&lvi); if (iItem >= 0) { lvi.mask = LVIF_TEXT; lvi.iItem = iItem; strBuff.Empty(); // intentionally left blank as it's not a real meta tag lvi.pszText = const_cast<LPTSTR>((LPCTSTR)strBuff); lvi.iSubItem = META_DATA_COL_TYPE; m_tags.SetItem(&lvi); strBuff = md4str(m_file->GetFileHash()); lvi.pszText = const_cast<LPTSTR>((LPCTSTR)strBuff); lvi.iSubItem = META_DATA_COL_VALUE; m_tags.SetItem(&lvi); } const CArray<CTag*,CTag*>& aTags = m_file->GetTags(); int iTags = aTags.GetCount(); for (int i = 0; i < iTags; i++) { const CTag* pTag = aTags.GetAt(i); LVITEM lvi; lvi.mask = LVIF_TEXT; lvi.iItem = INT_MAX; lvi.iSubItem = META_DATA_COL_NAME; strBuff = GetName(pTag); lvi.pszText = const_cast<LPTSTR>((LPCTSTR)strBuff); int iItem = m_tags.InsertItem(&lvi); if (iItem >= 0) { lvi.mask = LVIF_TEXT; lvi.iItem = iItem; strBuff = GetType(pTag->GetType()); lvi.pszText = const_cast<LPTSTR>((LPCTSTR)strBuff); lvi.iSubItem = META_DATA_COL_TYPE; m_tags.SetItem(&lvi); strBuff = GetValue(pTag); lvi.pszText = const_cast<LPTSTR>((LPCTSTR)strBuff); lvi.iSubItem = META_DATA_COL_VALUE; m_tags.SetItem(&lvi); iMetaTags++; } } } else if (m_taglist != NULL) { const Kademlia::CTag* pTag; Kademlia::TagList::const_iterator it; for (it = m_taglist->begin(); it != m_taglist->end(); it++) { pTag = *it; CString strBuff; LVITEM lvi; lvi.mask = LVIF_TEXT; lvi.iItem = INT_MAX; lvi.iSubItem = META_DATA_COL_NAME; strBuff = GetName(pTag); lvi.pszText = const_cast<LPTSTR>((LPCTSTR)strBuff); int iItem = m_tags.InsertItem(&lvi); if (iItem >= 0) { lvi.mask = LVIF_TEXT; lvi.iItem = iItem; strBuff = GetType(pTag->m_type); lvi.pszText = const_cast<LPTSTR>((LPCTSTR)strBuff); lvi.iSubItem = META_DATA_COL_TYPE; m_tags.SetItem(&lvi); strBuff = GetValue(pTag); lvi.pszText = const_cast<LPTSTR>((LPCTSTR)strBuff); lvi.iSubItem = META_DATA_COL_VALUE; m_tags.SetItem(&lvi); iMetaTags++; } } } CString strTmp; strTmp.Format(_T("%s %u"), GetResString(IDS_METATAGS), iMetaTags); SetDlgItemText(IDC_TOTAL_TAGS, strTmp); m_tags.SetRedraw(); }
BOOL CIrcNickListCtrl::OnCommand(WPARAM wParam, LPARAM) { int iNickItem = GetNextItem(-1, LVIS_SELECTED | LVIS_FOCUSED); int iChanItem = m_pParent->m_tabctrlChannelSelect.GetCurSel(); Nick* pNick = (Nick*)GetItemData(iNickItem); TCITEM item; item.mask = TCIF_PARAM; m_pParent->m_tabctrlChannelSelect.GetItem(iChanItem,&item); Channel* pChannel = (Channel*)item.lParam; switch( wParam ) { case Irc_Priv: { //Right clicked and choose start private chan. if(pNick) { //Send a message with the nick as the channel name, this will create a new window with the default message. m_pParent->AddInfoMessage( pNick->m_sNick, GetResString(IDS_IRC_PRIVATECHANSTART)); } return true; } case Irc_Kick: { //Kick someone from a channel if( pNick && pChannel ) { //We have a nick and chan, send the command. CString sSend; sSend.Format(_T("KICK %s %s"), pChannel->m_sName, pNick->m_sNick ); m_pParent->m_pIrcMain->SendString(sSend); } return true; } case Irc_Ban: { //Kick someone from a channel if( pNick && pChannel ) { //We have a nick and chan, send the command. CString sSend; sSend.Format(_T("cs ban %s %s"), pChannel->m_sName, pNick->m_sNick ); m_pParent->m_pIrcMain->SendString(sSend); } return true; } case Irc_Slap: { //Do a silly slap on someone if( pNick && pChannel ) { //We have a nick and chan, send the command. CString sSend; sSend.Format( GetResString(IDS_IRC_SLAPMSGSEND), pChannel->m_sName, pNick->m_sNick ); m_pParent->AddInfoMessage( pChannel->m_sName, GetResString(IDS_IRC_SLAPMSG), m_pParent->m_pIrcMain->GetNick(), pNick->m_sNick); m_pParent->m_pIrcMain->SendString(sSend); } return true; } case Irc_AddFriend: { //Attempt to add this person as a friend. if( pNick && pChannel ) { //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 sSend; sSend.Format(_T("PRIVMSG %s :\001RQSFRIEND|%i|\001"), pNick->m_sNick, m_pParent->m_pIrcMain->SetVerify() ); m_pParent->m_pIrcMain->SendString(sSend); } 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; } if( pNick && pChannel ) { //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 sSend; sSend.Format(_T("PRIVMSG %s :\001SENDLINK|%s|%s\001"), pNick->m_sNick, md4str(thePrefs.GetUserHash()), m_pParent->GetSendFileString() ); m_pParent->m_pIrcMain->SendString(sSend); } return true; } } if( wParam >= Irc_OpCommands && wParam < Irc_OpCommands+25) { int iIndex = wParam - Irc_OpCommands; CString sMode = m_sUserModeSettings.Mid(iIndex,1); if( pNick && pChannel ) { //We have a nick and chan, send the command. CString sSend; sSend.Format(_T("MODE %s +%s %s"), pChannel->m_sName, sMode, pNick->m_sNick ); m_pParent->m_pIrcMain->SendString(sSend); } return true; } if( wParam >= Irc_OpCommands+25 && wParam < Irc_OpCommands+50) { int iIndex = wParam - Irc_OpCommands-25; CString sMode = m_sUserModeSettings.Mid(iIndex,1); if( pNick && pChannel ) { //We have a nick and chan, send the command. CString sSend; sSend.Format(_T("MODE %s -%s %s"), pChannel->m_sName, sMode, pNick->m_sNick ); m_pParent->m_pIrcMain->SendString(sSend); } return true; } return true; }
void CClientListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { if( !theApp.emuledlg->IsRunning() ) return; if (!lpDrawItemStruct->itemData) return; CDC* odc = CDC::FromHandle(lpDrawItemStruct->hDC); BOOL bCtrlFocused = ((GetFocus() == this ) || (GetStyle() & LVS_SHOWSELALWAYS)); if (lpDrawItemStruct->itemState & ODS_SELECTED) { if(bCtrlFocused) odc->SetBkColor(m_crHighlight); else odc->SetBkColor(m_crNoHighlight); } else odc->SetBkColor(GetBkColor()); const CUpDownClient* client = (CUpDownClient*)lpDrawItemStruct->itemData; CMemDC dc(odc, &lpDrawItemStruct->rcItem); CFont* pOldFont = dc.SelectObject(GetFont()); CRect cur_rec(lpDrawItemStruct->rcItem); COLORREF crOldTextColor = dc.SetTextColor((lpDrawItemStruct->itemState & ODS_SELECTED) ? m_crHighlightText : m_crWindowText); int iOldBkMode; if (m_crWindowTextBk == CLR_NONE){ DefWindowProc(WM_ERASEBKGND, (WPARAM)(HDC)dc, 0); iOldBkMode = dc.SetBkMode(TRANSPARENT); } else iOldBkMode = OPAQUE; CHeaderCtrl *pHeaderCtrl = GetHeaderCtrl(); int iCount = pHeaderCtrl->GetItemCount(); cur_rec.right = cur_rec.left - 8; cur_rec.left += 4; CString Sbuffer; for(int iCurrent = 0; iCurrent < iCount; iCurrent++){ int iColumn = pHeaderCtrl->OrderToIndex(iCurrent); if( !IsColumnHidden(iColumn) ){ cur_rec.right += GetColumnWidth(iColumn); switch(iColumn){ case 0:{ uint8 image; if (client->IsFriend()) image = 2; else if (client->GetClientSoft() == SO_EDONKEYHYBRID) image = 4; else if (client->GetClientSoft() == SO_MLDONKEY) image = 3; else if (client->GetClientSoft() == SO_SHAREAZA) image = 5; else if (client->GetClientSoft() == SO_URL) image = 6; else if (client->GetClientSoft() == SO_AMULE) image = 7; else if (client->GetClientSoft() == SO_LPHANT) image = 8; else if (client->ExtProtocolAvailable()) //==>Modversion [shadow2004] #ifdef MODVERSION image = (client->IsNextEMF())?10:1; #else //Modversion image = 1; #endif //Modversion //<==Modversion [shadow2004] else image = 0; POINT point = {cur_rec.left, cur_rec.top+1}; imagelist.Draw(dc,image, point, ILD_NORMAL | ((client->Credits() && client->Credits()->GetCurrentIdentState(client->GetIP()) == IS_IDENTIFIED) ? INDEXTOOVERLAYMASK(1) : 0)); if (client->GetUserName()==NULL) Sbuffer.Format(_T("(%s)"), GetResString(IDS_UNKNOWN)); else Sbuffer = client->GetUserName(); cur_rec.left +=20; dc.DrawText(Sbuffer,Sbuffer.GetLength(),&cur_rec,DLC_DT_TEXT); cur_rec.left -=20; break; } case 1:{ Sbuffer = client->GetUploadStateDisplayString(); break; } case 2:{ if(client->credits) Sbuffer = CastItoXBytes(client->credits->GetUploadedTotal(), false, false); else Sbuffer.Empty(); break; } case 3:{ Sbuffer = client->GetDownloadStateDisplayString(); break; } case 4:{ if(client->credits) Sbuffer = CastItoXBytes(client->credits->GetDownloadedTotal(), false, false); else Sbuffer.Empty(); break; } case 5:{ Sbuffer = client->GetClientSoftVer(); if (Sbuffer.IsEmpty()) Sbuffer = GetResString(IDS_UNKNOWN); break; } case 6:{ if(client->socket){ if(client->socket->IsConnected()){ Sbuffer = GetResString(IDS_YES); break; } } Sbuffer = GetResString(IDS_NO); break; } case 7: Sbuffer = md4str(client->GetUserHash()); break; } if( iColumn != 0) dc.DrawText(Sbuffer,Sbuffer.GetLength(),&cur_rec,DLC_DT_TEXT); cur_rec.left += GetColumnWidth(iColumn); }
void CClientListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { if (!theApp.emuledlg->IsRunning()) return; if (!lpDrawItemStruct->itemData) return; CDC* odc = CDC::FromHandle(lpDrawItemStruct->hDC); BOOL bCtrlFocused = ((GetFocus() == this) || (GetStyle() & LVS_SHOWSELALWAYS)); if (lpDrawItemStruct->itemState & ODS_SELECTED) { if (bCtrlFocused) odc->SetBkColor(m_crHighlight); else odc->SetBkColor(m_crNoHighlight); } else odc->SetBkColor(GetBkColor()); const CUpDownClient* client = (CUpDownClient*)lpDrawItemStruct->itemData; CMemDC dc(odc, &lpDrawItemStruct->rcItem); CFont* pOldFont = dc.SelectObject(GetFont()); CRect cur_rec(lpDrawItemStruct->rcItem); COLORREF crOldTextColor = dc.SetTextColor((lpDrawItemStruct->itemState & ODS_SELECTED) ? m_crHighlightText : m_crWindowText); int iOldBkMode; if (m_crWindowTextBk == CLR_NONE){ DefWindowProc(WM_ERASEBKGND, (WPARAM)(HDC)dc, 0); iOldBkMode = dc.SetBkMode(TRANSPARENT); } else iOldBkMode = OPAQUE; CHeaderCtrl *pHeaderCtrl = GetHeaderCtrl(); int iCount = pHeaderCtrl->GetItemCount(); cur_rec.right = cur_rec.left - 8; cur_rec.left += 4; CString Sbuffer; for(int iCurrent = 0; iCurrent < iCount; iCurrent++){ int iColumn = pHeaderCtrl->OrderToIndex(iCurrent); if( !IsColumnHidden(iColumn) ){ cur_rec.right += GetColumnWidth(iColumn); switch(iColumn){ case 0:{ uint8 image; if (client->IsFriend()) image = 2; else if (client->GetClientSoft() == SO_EDONKEYHYBRID) image = 4; else if (client->GetClientSoft() == SO_MLDONKEY) image = 3; else if (client->GetClientSoft() == SO_SHAREAZA) image = 5; else if (client->GetClientSoft() == SO_URL) image = 6; else if (client->GetClientSoft() == SO_AMULE) image = 7; else if (client->GetClientSoft() == SO_LPHANT) image = 8; else if (client->ExtProtocolAvailable()) image = 1; else image = 0; uint32 nOverlayImage = 0; if ((client->Credits() && client->Credits()->GetCurrentIdentState(client->GetIP()) == IS_IDENTIFIED)) nOverlayImage |= 1; if (client->IsObfuscatedConnectionEstablished()) nOverlayImage |= 2; POINT point = {cur_rec.left, cur_rec.top+1}; imagelist.Draw(dc,image, point, ILD_NORMAL | ((client->Credits() && client->Credits()->GetCurrentIdentState(client->GetIP()) == IS_IDENTIFIED) ? INDEXTOOVERLAYMASK(1) : 0)); if (client->GetUserName()==NULL) Sbuffer.Format(_T("(%s)"), GetResString(IDS_UNKNOWN)); else Sbuffer = client->GetUserName(); //EastShare Start - added by AndCycle, IP to Country CString tempStr; tempStr.Format(_T("%s%s"), client->GetCountryName(), Sbuffer); Sbuffer = tempStr; if(CGlobalVariable::ip2country->ShowCountryFlag()){ cur_rec.left+=20; POINT point2= {cur_rec.left,cur_rec.top+1}; CGlobalVariable::ip2country->GetFlagImageList()->DrawIndirect(dc, client->GetCountryFlagIndex(), point2, CSize(18,16), CPoint(0,0), ILD_NORMAL); } //EastShare End - added by AndCycle, IP to Country cur_rec.left +=20; dc.DrawText(Sbuffer,Sbuffer.GetLength(),&cur_rec,DLC_DT_TEXT); cur_rec.left -=20; //EastShare Start - added by AndCycle, IP to Country if(CGlobalVariable::ip2country->ShowCountryFlag()){ cur_rec.left-=20; } //EastShare End - added by AndCycle, IP to Country break; } case 1:{ Sbuffer = client->GetUploadStateDisplayString(); break; } case 2:{ if(client->credits) Sbuffer = CastItoXBytes(client->credits->GetUploadedTotal(), false, false); else Sbuffer.Empty(); break; } case 3:{ Sbuffer = client->GetDownloadStateDisplayString(); break; } case 4:{ if(client->credits) Sbuffer = CastItoXBytes(client->credits->GetDownloadedTotal(), false, false); else Sbuffer.Empty(); break; } case 5:{ Sbuffer = client->GetClientSoftVer(); if (Sbuffer.IsEmpty()) Sbuffer = GetResString(IDS_UNKNOWN); break; } case 6:{ if(client->socket){ if(client->socket->IsConnected()){ Sbuffer = GetResString(IDS_YES); break; } } Sbuffer = GetResString(IDS_NO); break; } case 7: Sbuffer = md4str(client->GetUserHash()); break; } if( iColumn != 0) dc.DrawText(Sbuffer,Sbuffer.GetLength(),&cur_rec,DLC_DT_TEXT); cur_rec.left += GetColumnWidth(iColumn); } } // draw rectangle around selected item(s) if (lpDrawItemStruct->itemState & ODS_SELECTED) { RECT outline_rec = lpDrawItemStruct->rcItem; outline_rec.top--; outline_rec.bottom++; dc.FrameRect(&outline_rec, &CBrush(GetBkColor())); outline_rec.top++; outline_rec.bottom--; outline_rec.left++; outline_rec.right--; if(bCtrlFocused) dc.FrameRect(&outline_rec, &CBrush(m_crFocusLine)); else dc.FrameRect(&outline_rec, &CBrush(m_crNoFocusLine)); } if (m_crWindowTextBk == CLR_NONE) dc.SetBkMode(iOldBkMode); dc.SelectObject(pOldFont); dc.SetTextColor(crOldTextColor); }