Here is an (alpha) implementation of those new messages for eMule. I've tested the code with eDonkey Hybrid v0.44, Overnet v0.42 and Overnet v0.44 and it seems to work well. Although it's not a very important feature to support the "shared files" messages, someone may have a use for it
Because the changes are a little wide-spread I've decided to post the code in "diff" format -- hope you like it. (No, you wont't like it, but maybe some of you can use it.) Apply the "diff" with 'patch -l < eMule0.26b2.diff'
The code is straight forward, nothing special to note. Just one thing: In ReGetClientSoftware I try to detect Overnet clients only with internal versions 44 and 441 -- this has no future but currently I don't know how to make this more properly.
TODO:
- Properly determination of eDonkeyHybrid and Overnet clients.
- Generally I don't like the idea of letting other clients see my *real* directory names. There should be some kind of "virtualization".
Real directory......Public directory (sent to clients)
------------------------------------------------------
C:\Data\Stuff.......Dir1
D:\Data\MoreStuff...Dir2
- I don't like the 'm_iFileListRequested' counter. I just used it to get the thing working. But there should be some other mechanism to properly determine if there's a directory- or filelist request pending.
- I would also suggest to be a little more paranoid and canonicalize the received directories. Although it should currently be no problem to receive directories with "." and ".." and "..\..\" and so on, it may become a potential security problem in future versions of eMule.
diff -u -p -r -x *.vcproj -x *.sln -x *.ncb -x *.suo eMule0.26b/src/opcodes.h eMule0.26b2/src/opcodes.h --- eMule0.26b/src/opcodes.h Sat Feb 15 10:16:44 2003 +++ eMule0.26b2/src/opcodes.h Sat Feb 15 10:17:20 2003 @@ -147,6 +147,11 @@ #define OP_FILEREQANSWER 0x59 // <HASH 16><len 4><NAME len> #define OP_CHANGE_SLOT 0x5B // <HASH 16> #define OP_QUEUERANK 0x5C // <wert 4> (slot index of the request) +#define OP_ASKSHAREDDIRS 0x5D // (null) +#define OP_ASKSHAREDFILESDIR 0x5E // <len 2><Directory len> +#define OP_ASKSHAREDDIRSANS 0x5F // <count 4>(<len 2><Directory len>)[count] +#define OP_ASKSHAREDFILESDIRANS 0x60 // <len 2><Directory len><count 4>(<HASH 16><ID 4><PORT 2><1 Tag_set>)[count] +#define OP_ASKSHAREDDENIEDANS 0x61 // (null) // extened prot client <-> extened prot client diff -u -p -r -x *.vcproj -x *.sln -x *.ncb -x *.suo eMule0.26b/src/updownclient.h eMule0.26b2/src/updownclient.h --- eMule0.26b/src/updownclient.h Sat Feb 15 10:16:44 2003 +++ eMule0.26b2/src/updownclient.h Sat Feb 15 10:17:20 2003 @@ -221,6 +221,8 @@ public: // Barry - Sets string to show parts downloading, eg NNNYNNNNYYNYN void ShowDownloadingParts(CString *partsYN); void UpdateDisplayedInfo(boolean force=false); + int GetFileListRequested() { return m_iFileListRequested; } + void SetFileListRequested(int iFileListRequested) { m_iFileListRequested = iFileListRequested; } private: // base void Init(); @@ -252,7 +254,7 @@ private: uint8 m_clientSoft; uint32 m_dwLastSourceRequest; uint32 m_dwLastSourceAnswer; - bool m_bFileListRequested; + int m_iFileListRequested; bool m_bFriendSlot; bool m_bCommentDirty; uint32 m_byCompatableClient; diff -u -p -r -x *.vcproj -x *.sln -x *.ncb -x *.suo eMule0.26b/src/BaseClient.cpp eMule0.26b2/src/BaseClient.cpp --- eMule0.26b/src/BaseClient.cpp Sat Feb 15 10:16:44 2003 +++ eMule0.26b2/src/BaseClient.cpp Sat Feb 15 10:17:20 2003 @@ -73,7 +73,7 @@ void CUpDownClient::Init(){ m_nUserID = 0; m_nServerPort = 0; m_bBanned = false; - m_bFileListRequested = false; + m_iFileListRequested = 0; m_dwLastUpRequest = 0; m_bEmuleProtocol = false; usedcompressiondown = false; @@ -491,9 +491,9 @@ void CUpDownClient::Disconnected(){ socket->Safe_Delete(); } socket = 0; - if (m_bFileListRequested){ + if (m_iFileListRequested){ theApp.emuledlg->AddDebugLogLine(false,GetResString(IDS_SHAREDFILES_FAILED),GetUserName()); - m_bFileListRequested = false; + m_iFileListRequested = 0; } if (m_Friend) theApp.friendlist->RefreshFriend(m_Friend); @@ -604,8 +604,8 @@ void CUpDownClient::ConnectionEstablishe socket->SendPacket(packet,true); } } - if (m_bFileListRequested){ - Packet* packet = new Packet(OP_ASKSHAREDFILES,0); + if (m_iFileListRequested == 1){ + Packet* packet = new Packet((GetClientSoft()==SO_EDONKEYHYBRID) ? OP_ASKSHAREDDIRS : OP_ASKSHAREDFILES,0); theApp.uploadqueue->AddUpDataOverheadOther(packet->size); socket->SendPacket(packet,true,true); } @@ -625,7 +625,7 @@ void CUpDownClient::ReGetClientSoft(){ } } if (m_achUserHash[5] == 'M' && m_achUserHash[14] == 'L') {m_clientSoft= SO_MLDONKEY;return;} - if( this->GetVersion() > 1040 ) + if( this->GetVersion() > 1040 || this->GetVersion() == 44 || this->GetVersion() == 441 ) m_clientSoft=SO_EDONKEYHYBRID; else m_clientSoft=SO_EDONKEY; @@ -639,13 +639,13 @@ void CUpDownClient::SetUserName(char* ps void CUpDownClient::RequestSharedFileList(){ theApp.emuledlg->AddDebugLogLine(true,GetResString(IDS_SHAREDFILES_REQUEST),GetUserName()); - m_bFileListRequested = true; + m_iFileListRequested = 1; TryToConnect(true); } void CUpDownClient::ProcessSharedFileList(char* pachPacket, uint32 nSize){ - if (m_bFileListRequested){ - m_bFileListRequested = false; + if (m_iFileListRequested > 0){ + m_iFileListRequested--; theApp.searchlist->ProcessSearchanswer(pachPacket,nSize,this); } } diff -u -p -r -x *.vcproj -x *.sln -x *.ncb -x *.suo eMule0.26b/src/ListenSocket.cpp eMule0.26b2/src/ListenSocket.cpp --- eMule0.26b/src/ListenSocket.cpp Sat Feb 15 10:16:44 2003 +++ eMule0.26b2/src/ListenSocket.cpp Sat Feb 15 10:17:20 2003 @@ -432,6 +432,140 @@ bool CClientReqSocket::ProcessPacket(cha client->ProcessSharedFileList(packet,size); break; } + case OP_ASKSHAREDDIRS:{ + theApp.downloadqueue->AddDownDataOverheadOther(size); + ASSERT( size == 0 ); + if (theApp.glob_prefs->CanSeeShares()==0 || (theApp.glob_prefs->CanSeeShares()==1 && client->IsFriend())){ + theApp.emuledlg->AddLogLine(true,"User %s (%u) requested your shareddirectories-list -> %s",client->GetUserName(),client->GetUserID(),GetResString(IDS_ACCEPTED) ); + + CSafeMemFile tempfile(80); + uint32 uDirs = theApp.glob_prefs->shareddir_list.GetCount(); + tempfile.Write(&uDirs, 4); + + POSITION pos = theApp.glob_prefs->shareddir_list.GetHeadPosition(); + while (pos){ + CString strDir = theApp.glob_prefs->shareddir_list.GetNext(pos); + PathRemoveBackslash(strDir.GetBuffer()); + strDir.ReleaseBuffer(); + uint16 cnt = strDir.GetLength(); + tempfile.Write(&cnt, 2); + tempfile.Write((LPCTSTR)strDir, cnt); + } + + Packet* replypacket = new Packet(&tempfile); + replypacket->opcode = OP_ASKSHAREDDIRSANS; + theApp.uploadqueue->AddUpDataOverheadOther(replypacket->size); + SendPacket(replypacket, true, true); + } + else{ + theApp.emuledlg->AddLogLine(true,"User %s (%u) requested your shareddirectories-list -> %s",client->GetUserName(),client->GetUserID(),GetResString(IDS_DENIED) ); + Packet* replypacket = new Packet(OP_ASKSHAREDDENIEDANS, 0); + theApp.uploadqueue->AddUpDataOverheadOther(replypacket->size); + SendPacket(replypacket, true, true); + } + break; + } + case OP_ASKSHAREDFILESDIR:{ + theApp.downloadqueue->AddDownDataOverheadOther(size); + CSafeMemFile data((uchar*)packet, size, 0); + uint16 cnt; + data.Read(&cnt, 2); + CString strReqDir; + data.Read(strReqDir.GetBuffer(cnt), cnt); + strReqDir.ReleaseBuffer(cnt); + PathRemoveBackslash(strReqDir.GetBuffer()); + strReqDir.ReleaseBuffer(); + + if (theApp.glob_prefs->CanSeeShares()==0 || (theApp.glob_prefs->CanSeeShares()==1 && client->IsFriend())){ + theApp.emuledlg->AddLogLine(true,"User %s (%u) requested your sharedfiles-list for directory %s -> %s",client->GetUserName(),client->GetUserID(),strReqDir,GetResString(IDS_ACCEPTED) ); + ASSERT( data.GetPosition() == data.GetLength() ); + + CTypedPtrList<CPtrList, CKnownFile*> list; + for (POSITION pos = theApp.sharedfiles->m_Files_map.GetStartPosition();pos != 0;){ + CCKey bufKey; + CKnownFile* cur_file; + theApp.sharedfiles->m_Files_map.GetNextAssoc(pos, bufKey, cur_file); + CString strSharedFile(cur_file->GetPath()); + PathRemoveFileSpec(strSharedFile.GetBuffer()); + strSharedFile.ReleaseBuffer(); + if (strReqDir.CompareNoCase(strSharedFile) == 0) + list.AddTail(cur_file); + } + + if (list.GetCount()){ + CSafeMemFile tempfile(80); + uint16 cnt = strReqDir.GetLength(); + tempfile.Write(&cnt, 2); + tempfile.Write((LPCTSTR)strReqDir, cnt); + uint32 uFiles = list.GetCount(); + tempfile.Write(&uFiles, 4); + while (list.GetCount()){ + theApp.sharedfiles->CreateOfferedFilePacket(list.GetHead(), &tempfile); + list.RemoveHead(); + } + + Packet* replypacket = new Packet(&tempfile); + replypacket->opcode = OP_ASKSHAREDFILESDIRANS; + theApp.uploadqueue->AddUpDataOverheadOther(replypacket->size); + SendPacket(replypacket, true, true); + } + } + else{ + theApp.emuledlg->AddLogLine(true,"User %s (%u) requested your sharedfiles-list for directory %s -> %s",client->GetUserName(),client->GetUserID(),strReqDir,GetResString(IDS_DENIED) ); + Packet* replypacket = new Packet(OP_ASKSHAREDDENIEDANS, 0); + theApp.uploadqueue->AddUpDataOverheadOther(replypacket->size); + SendPacket(replypacket, true, true); + } + break; + } + case OP_ASKSHAREDDIRSANS:{ + theApp.downloadqueue->AddDownDataOverheadOther(size); + if (client->GetFileListRequested() == 1){ + CSafeMemFile data((uchar*)packet, size, 0); + uint32 uDirs; + data.Read(&uDirs, 4); + for (UINT i = 0; i < uDirs; i++){ + uint16 cnt; + data.Read(&cnt, 2); + CString strDir; + data.Read(strDir.GetBuffer(cnt), cnt); + strDir.ReleaseBuffer(cnt); + theApp.emuledlg->AddLogLine(true,"User %s (%u) shares directory %s",client->GetUserName(),client->GetUserID(),strDir); + + CSafeMemFile tempfile(80); + cnt = strDir.GetLength(); + tempfile.Write(&cnt, 2); + tempfile.Write((LPCTSTR)strDir, cnt); + Packet* replypacket = new Packet(&tempfile); + replypacket->opcode = OP_ASKSHAREDFILESDIR; + theApp.uploadqueue->AddUpDataOverheadOther(replypacket->size); + SendPacket(replypacket, true, true); + } + ASSERT( data.GetPosition() == data.GetLength() ); + client->SetFileListRequested(uDirs); + } + break; + } + case OP_ASKSHAREDFILESDIRANS:{ + theApp.downloadqueue->AddDownDataOverheadOther(size); + if (client->GetFileListRequested() > 0){ + CSafeMemFile data((uchar*)packet, size, 0); + uint16 cnt; + data.Read(&cnt, 2); + CString strDir; + data.Read(strDir.GetBuffer(cnt), cnt); + strDir.ReleaseBuffer(cnt); + theApp.emuledlg->AddLogLine(true,"User %s (%u) sent sharedfiles-list for directory %s",client->GetUserName(),client->GetUserID(),strDir); + client->ProcessSharedFileList(packet + data.GetPosition(), size - data.GetPosition()); + } + break; + } + case OP_ASKSHAREDDENIEDANS:{ + theApp.downloadqueue->AddDownDataOverheadOther(size); + ASSERT( size == 0 ); + theApp.emuledlg->AddLogLine(true,"User %s (%u) denied access to shareddirectories/files-list",client->GetUserName(),client->GetUserID()); + break; + } default: theApp.downloadqueue->AddDownDataOverheadOther(size); theApp.emuledlg->AddDebugLogLine(false,"unknown opcode: %i %h",opcode,opcode); diff -u -p -r -x *.vcproj -x *.sln -x *.ncb -x *.suo eMule0.26b/src/SearchDlg.cpp eMule0.26b2/src/SearchDlg.cpp --- eMule0.26b/src/SearchDlg.cpp Sat Feb 15 10:16:44 2003 +++ eMule0.26b2/src/SearchDlg.cpp Sat Feb 15 10:17:20 2003 @@ -492,6 +492,13 @@ void CSearchDlg::StartNewSearch(){ } void CSearchDlg::CreateNewTab(CString searchString,uint32 nSearchID){ + int iTabItems = searchselect.GetItemCount(); + for (int i = 0; i < iTabItems; i++){ + TCITEM tci; + tci.mask = TCIF_PARAM; + if (searchselect.GetItem(i, &tci) && tci.lParam == nSearchID) + return; + } // add new tab TCITEM newitem; if (searchString.GetLength() == 0)