2 // This file is part of the aMule Project.
4 // Copyright (c) 2005-2008 aMule Team ( admin@amule.org / http://www.amule.org )
6 // Any parts of this program derived from the xMule, lMule or eMule project,
7 // or contributed by third-party developers are copyrighted by their
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #define AMULE_REMOTE_GUI_CPP
29 #include <memory> // Needed for auto_ptr
34 #include <wx/cmdline.h> // Needed for wxCmdLineParser
35 #include <wx/config.h> // Do_not_auto_remove (win32)
36 #include <wx/fileconf.h> // Needed for wxFileConfig
39 #include <common/Format.h>
40 #include <common/StringFunctions.h>
41 #include <common/MD5Sum.h>
44 #include <include/common/EventIDs.h>
47 #include "amule.h" // Interface declarations.
48 #include "amuleDlg.h" // Needed for CamuleDlg
49 #include "ClientCredits.h"
50 #include "ClientListCtrl.h"
51 #include "DataToText.h" // Needed for GetSoftName()
52 #include "DownloadListCtrl.h" // Needed for CDownloadListCtrl
53 #include "GuiEvents.h"
54 #ifdef ENABLE_IP2COUNTRY
55 #include "IP2Country.h" // Needed for IP2Country
57 #include "InternalEvents.h" // Needed for wxEVT_CORE_FINISHED_HTTP_DOWNLOAD
59 #include "muuli_wdr.h" // Needed for IDs
60 #include "PartFile.h" // Needed for CPartFile
61 #include "SearchDlg.h" // Needed for CSearchDlg
62 #include "Server.h" // Needed for GetListName
63 #include "ServerWnd.h" // Needed for CServerWnd
64 #include "SharedFilesCtrl.h" // Needed for CSharedFilesCtrl
65 #include "SharedFilesWnd.h" // Needed for CSharedFilesWnd
66 #include "TransferWnd.h" // Needed for CTransferWnd
67 #include "updownclient.h"
68 #include "ServerListCtrl.h" // Needed for CServerListCtrl
69 #include "MagnetURI.h" // Needed for CMagnetURI
72 CEConnectDlg::CEConnectDlg()
74 wxDialog(theApp
->amuledlg
, -1, _("Connect to remote amule"), wxDefaultPosition
)
76 CoreConnect(this, true);
78 wxString pref_host
, pref_port
;
79 wxConfig::Get()->Read(wxT("/EC/Host"), &pref_host
, wxT("localhost"));
80 wxConfig::Get()->Read(wxT("/EC/Port"), &pref_port
, wxT("4712"));
81 wxConfig::Get()->Read(wxT("/EC/Password"), &pwd_hash
);
83 CastChild(ID_REMOTE_HOST
, wxTextCtrl
)->SetValue(pref_host
);
84 CastChild(ID_REMOTE_PORT
, wxTextCtrl
)->SetValue(pref_port
);
85 CastChild(ID_EC_PASSWD
, wxTextCtrl
)->SetValue(pwd_hash
);
91 wxString
CEConnectDlg::PassHash()
97 BEGIN_EVENT_TABLE(CEConnectDlg
, wxDialog
)
98 EVT_BUTTON(wxID_OK
, CEConnectDlg::OnOK
)
102 void CEConnectDlg::OnOK(wxCommandEvent
& evt
)
104 wxString s_port
= CastChild(ID_REMOTE_PORT
, wxTextCtrl
)->GetValue();
105 port
= StrToLong(s_port
);
107 host
= CastChild(ID_REMOTE_HOST
, wxTextCtrl
)->GetValue();
108 passwd
= CastChild(ID_EC_PASSWD
, wxTextCtrl
)->GetValue();
110 if (passwd
!= pwd_hash
) {
111 pwd_hash
= MD5Sum(passwd
).GetHash();
113 m_save_user_pass
= CastChild(ID_EC_SAVE
, wxCheckBox
)->IsChecked();
118 DEFINE_LOCAL_EVENT_TYPE(wxEVT_EC_INIT_DONE
)
121 BEGIN_EVENT_TABLE(CamuleRemoteGuiApp
, wxApp
)
123 EVT_TIMER(ID_CORE_TIMER_EVENT
, CamuleRemoteGuiApp::OnPollTimer
)
125 EVT_CUSTOM(wxEVT_EC_CONNECTION
, -1, CamuleRemoteGuiApp::OnECConnection
)
126 EVT_CUSTOM(wxEVT_EC_INIT_DONE
, -1, CamuleRemoteGuiApp::OnECInitDone
)
128 EVT_MULE_NOTIFY(CamuleRemoteGuiApp::OnNotifyEvent
)
130 #ifdef ENABLE_IP2COUNTRY
131 // HTTPDownload finished
132 EVT_MULE_INTERNAL(wxEVT_CORE_FINISHED_HTTP_DOWNLOAD
, -1, CamuleRemoteGuiApp::OnFinishedHTTPDownload
)
137 IMPLEMENT_APP(CamuleRemoteGuiApp
)
140 int CamuleRemoteGuiApp::OnExit()
144 return wxApp::OnExit();
148 void CamuleRemoteGuiApp::OnPollTimer(wxTimerEvent
&)
150 static int request_step
= 0;
152 if (m_connect
->RequestFifoFull()) {
156 switch (request_step
) {
158 serverconnect
->ReQuery();
159 serverlist
->UpdateUserFileStatus(serverconnect
->GetCurrentServer());
163 CECPacket
stats_req(EC_OP_STAT_REQ
);
164 m_connect
->SendRequest(&m_stats_updater
, &stats_req
);
165 amuledlg
->ShowTransferRate();
170 if (amuledlg
->m_sharedfileswnd
->IsShown()) {
171 sharedfiles
->DoRequery(EC_OP_GET_SHARED_FILES
, EC_TAG_KNOWNFILE
);
172 } else if (amuledlg
->m_serverwnd
->IsShown()) {
173 //serverlist->FullReload(EC_OP_GET_SERVER_LIST);
174 } else if (amuledlg
->m_transferwnd
->IsShown()) {
175 static bool firstcall
= true;
176 downloadqueue
->DoRequery(
177 theApp
->m_FileDetailDialogActive
|| firstcall
?
178 EC_OP_GET_DLOAD_QUEUE_DETAIL
: EC_OP_GET_DLOAD_QUEUE
,
181 switch(amuledlg
->m_transferwnd
->clientlistctrl
->GetListView()) {
183 uploadqueue
->ReQueryUp();
186 uploadqueue
->ReQueryWait();
193 amuledlg
->m_transferwnd
->ShowQueueCount(theStats::GetWaitingUserCount());
194 } else if (amuledlg
->m_searchwnd
->IsShown()) {
195 if (searchlist
->m_curr_search
!= -1) {
196 searchlist
->DoRequery(EC_OP_SEARCH_RESULTS
, EC_TAG_SEARCHFILE
);
203 AddLogLineCS(wxT("WTF?")); // should not happen. :-)
209 void CamuleRemoteGuiApp::OnFinishedHTTPDownload(CMuleInternalEvent
& event
)
211 #ifdef ENABLE_IP2COUNTRY
212 if (event
.GetInt() == HTTP_GeoIP
) {
213 amuledlg
->IP2CountryDownloadFinished(event
.GetExtraLong());
214 // If we updated, the dialog is already up. Redraw it to show the flags.
221 void CamuleRemoteGuiApp::ShutDown(wxCloseEvent
&WXUNUSED(evt
))
223 // Stop the Core Timer
227 // Destroy the EC socket
228 m_connect
->Destroy();
233 amuledlg
->DlgShutDown();
240 bool CamuleRemoteGuiApp::OnInit()
244 if ( !wxApp::OnInit() ) {
249 theApp
= &wxGetApp();
251 // Handle uncaught exceptions
252 InstallMuleExceptionHandler();
254 // Create the polling timer
255 poll_timer
= new wxTimer(this,ID_CORE_TIMER_EVENT
);
257 AddLogLineCS(_("Fatal Error: Failed to create Poll Timer"));
261 m_connect
= new CRemoteConnect(this);
262 SetAppName(wxT("aMule"));
265 // This creates the CFG file we shall use
266 ConfigDir
= GetConfigDir();
267 if (!wxDirExists(ConfigDir
)) {
271 wxConfig::Set(new wxFileConfig(wxEmptyString
, wxEmptyString
,
272 ConfigDir
+ wxT("remote.conf")));
274 glob_prefs
= new CPreferencesRem(m_connect
);
276 InitCustomLanguages();
277 InitLocale(m_locale
, StrLang2wx(thePrefs::GetLanguageID()));
279 bool result
= ShowConnectionDialog();
281 AddLogLineNS(_("Going to event loop..."));
287 bool CamuleRemoteGuiApp::CryptoAvailable() const
289 return clientcredits
&& clientcredits
->CryptoAvailable();
293 bool CamuleRemoteGuiApp::ShowConnectionDialog() {
295 dialog
= new CEConnectDlg
;
297 if (dialog
->ShowModal() != wxID_OK
) {
302 AddLogLineNS(_("Connecting..."));
303 if (!m_connect
->ConnectToCore(dialog
->Host(), dialog
->Port(),
304 dialog
->Login(), dialog
->PassHash(),
305 wxT("amule-remote"), wxT("0x0001"))) {
306 wxMessageBox(_("Connection failed "),_("ERROR"),wxOK
);
315 void CamuleRemoteGuiApp::OnECConnection(wxEvent
& event
) {
316 wxECSocketEvent
& evt
= *((wxECSocketEvent
*)&event
);
317 AddLogLineNS(_("Remote GUI EC event handler"));
318 AddLogLineM(true,evt
.GetServerReply());
319 if (evt
.GetResult() == true) {
320 // Connected - go to next init step
321 glob_prefs
->LoadRemote();
323 AddLogLineNS(_("Going down"));
329 void CamuleRemoteGuiApp::OnECInitDone(wxEvent
& )
335 void CamuleRemoteGuiApp::OnNotifyEvent(CMuleGUIEvent
& evt
)
341 void CamuleRemoteGuiApp::Startup() {
343 if (dialog
->SaveUserPass()) {
344 wxConfig::Get()->Write(wxT("/EC/Host"), dialog
->Host());
345 wxConfig::Get()->Write(wxT("/EC/Port"), dialog
->Port());
346 wxConfig::Get()->Write(wxT("/EC/Password"), dialog
->PassHash());
353 serverconnect
= new CServerConnectRem(m_connect
);
354 m_statistics
= new CStatistics(*m_connect
);
356 clientlist
= new CClientListRem(m_connect
);
357 searchlist
= new CSearchListRem(m_connect
);
358 serverlist
= new CServerListRem(m_connect
);
360 sharedfiles
= new CSharedFilesRem(m_connect
);
361 knownfiles
= new CKnownFilesRem(sharedfiles
);
363 clientcredits
= new CClientCreditsRem();
365 // bugfix - do this before creating the uploadqueue
366 downloadqueue
= new CDownQueueRem(m_connect
);
367 uploadqueue
= new CUpQueueRem(m_connect
);
368 ipfilter
= new CIPFilterRem(m_connect
);
370 // Parse cmdline arguments.
371 wxCmdLineParser
cmdline(wxApp::argc
, wxApp::argv
);
372 cmdline
.AddSwitch(wxT("v"), wxT("version"),
373 wxT("Displays the current version number."));
374 cmdline
.AddSwitch(wxT("h"), wxT("help"),
375 wxT("Displays this information."));
376 cmdline
.AddOption(wxT("geometry"), wxEmptyString
, wxT("Sets the geometry of the app.\n\t\t\t<str> uses the same format as standard X11 apps:\n\t\t\t[=][<width>{xX}<height>][{+-}<xoffset>{+-}<yoffset>]"));
379 bool geometry_enabled
= false;
380 wxString geom_string
;
381 if (cmdline
.Found(wxT("geometry"), &geom_string
)) {
382 geometry_enabled
= true;
385 // Create main dialog
386 InitGui(0, geom_string
);
388 // Forward wxLog events to CLogger
389 wxLog::SetActiveTarget(new CLoggerTarget
);
390 serverlist
->FullReload(EC_OP_GET_SERVER_LIST
);
391 sharedfiles
->DoRequery(EC_OP_GET_SHARED_FILES
, EC_TAG_KNOWNFILE
);
393 // Start the Poll Timer
394 poll_timer
->Start(1000);
395 amuledlg
->StartGuiTimer();
397 // Now activate GeoIP, so that the download dialog doesn't get destroyed immediately
398 #ifdef ENABLE_IP2COUNTRY
399 if (thePrefs::IsGeoIPEnabled()) {
400 amuledlg
->m_IP2Country
->Enable();
406 void CamuleRemoteGuiApp::ShowAlert(wxString msg
, wxString title
, int flags
)
408 CamuleGuiBase::ShowAlert(msg
, title
, flags
);
412 void CamuleRemoteGuiApp::AddRemoteLogLine(const wxString
& line
)
414 amuledlg
->AddLogLine(line
);
417 int CamuleRemoteGuiApp::InitGui(bool geometry_enabled
, wxString
&geom_string
)
419 CamuleGuiBase::InitGui(geometry_enabled
, geom_string
);
420 SetTopWindow(amuledlg
);
421 AddLogLineN(_("Ready")); // The first log line after the window is up triggers output of all the ones before
426 bool CamuleRemoteGuiApp::CopyTextToClipboard(wxString strText
)
428 return CamuleGuiBase::CopyTextToClipboard(strText
);
432 uint32
CamuleRemoteGuiApp::GetPublicIP()
438 wxString
CamuleRemoteGuiApp::GetLog(bool)
440 return wxEmptyString
;
444 wxString
CamuleRemoteGuiApp::GetServerLog(bool)
446 return wxEmptyString
;
450 wxString
CamuleRemoteGuiApp::CreateMagnetLink(const CAbstractFile
* f
)
452 // TODO: Remove duplicate code (also in amule.cpp) ...
455 uri
.AddField(wxT("dn"), f
->GetFileName().Cleanup(false).GetPrintable());
456 uri
.AddField(wxT("xt"), wxString(wxT("urn:ed2k:")) + f
->GetFileHash().Encode().Lower());
457 uri
.AddField(wxT("xt"), wxString(wxT("urn:ed2khash:")) + f
->GetFileHash().Encode().Lower());
458 uri
.AddField(wxT("xl"), wxString::Format(wxT("%") wxLongLongFmtSpec
wxT("u"), f
->GetFileSize()));
460 return uri
.GetLink();
463 wxString
CamuleRemoteGuiApp::CreateED2kLink(const CAbstractFile
* f
, bool add_source
, bool use_hostname
, bool addcryptoptions
)
465 // TODO: Avoid duplicate code (also in amule.cpp) ...
466 wxASSERT(!(!add_source
&& (use_hostname
|| addcryptoptions
)));
467 // Construct URL like this: ed2k://|file|<filename>|<size>|<hash>|/
468 wxString strURL
= CFormat(wxT("ed2k://|file|%s|%i|%s|/"))
469 % f
->GetFileName().Cleanup(false)
470 % f
->GetFileSize() % f
->GetFileHash().Encode();
472 if (add_source
&& IsConnected() && !IsFirewalled()) {
473 // Create the first part of the URL
474 strURL
<< wxT("|sources,");
477 strURL
<< thePrefs::GetYourHostname();
479 uint32 clientID
= GetID();
480 strURL
<< (uint8
) clientID
<< wxT(".") <<
481 (uint8
)(clientID
>> 8) << wxT(".") <<
482 (uint8
)(clientID
>> 16) << wxT(".") <<
483 (uint8
)(clientID
>> 24);
486 strURL
<< wxT(":") <<
489 if (addcryptoptions
) {
490 const uint8 uSupportsCryptLayer
= thePrefs::IsClientCryptLayerSupported() ? 1 : 0;
491 const uint8 uRequestsCryptLayer
= thePrefs::IsClientCryptLayerRequested() ? 1 : 0;
492 const uint8 uRequiresCryptLayer
= thePrefs::IsClientCryptLayerRequired() ? 1 : 0;
493 const uint8 byCryptOptions
= (uRequiresCryptLayer
<< 2) | (uRequestsCryptLayer
<< 1) | (uSupportsCryptLayer
<< 0) | (uSupportsCryptLayer
? 0x80 : 0x00);
495 strURL
<< wxT(":") << byCryptOptions
;
497 if (byCryptOptions
& 0x80) {
498 strURL
<< wxT(":") << thePrefs::GetUserHash().Encode();
503 } else if (add_source
) {
504 AddLogLineM(true, _("WARNING: You can't add yourself as a source for an eD2k link while having a lowid."));
507 // Result is "ed2k://|file|<filename>|<size>|<hash>|/|sources,[(<ip>|<hostname>):<port>[:cryptoptions[:hash]]]|/"
512 wxString
CamuleRemoteGuiApp::CreateED2kAICHLink(const CKnownFile
* f
)
514 // TODO: Avoid duplicate code (also in amule.cpp) ...
515 // Create the first part of the URL
516 wxString strURL
= CreateED2kLink(f
);
517 // Append the AICH info
518 if (f
->HasProperAICHHashSet()) {
519 strURL
.RemoveLast(); // remove trailing '/'
520 strURL
<< wxT("h=") << f
->GetAICHMasterHash() << wxT("|/");
523 // Result is "ed2k://|file|<filename>|<size>|<hash>|h=<AICH master hash>|/"
528 bool CamuleRemoteGuiApp::AddServer(CServer
*, bool)
530 // #warning TODO: Add remote command
535 bool CamuleRemoteGuiApp::IsFirewalled() const
537 if (IsConnectedED2K() && !serverconnect
->IsLowID()) {
541 return IsFirewalledKad();
545 bool CamuleRemoteGuiApp::IsConnectedED2K() const {
546 return serverconnect
&& serverconnect
->IsConnected();
550 void CamuleRemoteGuiApp::StartKad() {
551 m_connect
->StartKad();
555 void CamuleRemoteGuiApp::StopKad() {
556 m_connect
->StopKad();
560 void CamuleRemoteGuiApp::BootstrapKad(uint32 ip
, uint16 port
)
562 CECPacket
req(EC_OP_KAD_BOOTSTRAP_FROM_IP
);
563 req
.AddTag(CECTag(EC_TAG_BOOTSTRAP_IP
, ip
));
564 req
.AddTag(CECTag(EC_TAG_BOOTSTRAP_PORT
, port
));
566 m_connect
->SendPacket(&req
);
570 void CamuleRemoteGuiApp::UpdateNotesDat(const wxString
& url
)
572 CECPacket
req(EC_OP_KAD_UPDATE_FROM_URL
);
573 req
.AddTag(CECTag(EC_TAG_KADEMLIA_UPDATE_URL
, url
));
575 m_connect
->SendPacket(&req
);
579 void CamuleRemoteGuiApp::DisconnectED2K() {
580 if (IsConnectedED2K()) {
581 m_connect
->DisconnectED2K();
586 uint32
CamuleRemoteGuiApp::GetED2KID() const
588 return serverconnect
? serverconnect
->GetClientID() : 0;
592 uint32
CamuleRemoteGuiApp::GetID() const
598 void CamuleRemoteGuiApp::ShowUserCount() {
600 CFormat(_("Users: E: %s K: %s | Files E: %s K: %s")) % CastItoIShort(theStats::GetED2KUsers()) %
601 CastItoIShort(theStats::GetKadUsers()) % CastItoIShort(theStats::GetED2KFiles()) % CastItoIShort(theStats::GetKadFiles());
603 Notify_ShowUserCount(buffer
);
608 * Preferences: holds both local and remote settings.
610 * First, everything is loaded from local config file. Later, settings
611 * that are relevant on remote side only are loaded thru EC
613 CPreferencesRem::CPreferencesRem(CRemoteConnect
*conn
)
617 CPreferences::BuildItemList(theApp
->ConfigDir
);
618 CPreferences::LoadAllItems(wxConfigBase::Get());
621 // Settings queried from remote side
623 m_exchange_send_selected_prefs
=
625 EC_PREFS_CONNECTIONS
|
626 EC_PREFS_MESSAGEFILTER
|
632 EC_PREFS_CORETWEAKS
|
633 EC_PREFS_REMOTECONTROLS
|
635 m_exchange_recv_selected_prefs
=
636 m_exchange_send_selected_prefs
|
641 void CPreferencesRem::HandlePacket(const CECPacket
*packet
)
643 ((CEC_Prefs_Packet
*)packet
)->Apply();
645 if ( packet
->GetTagByName(EC_TAG_PREFS_CATEGORIES
) != 0 ) {
646 for (size_t i
= 0; i
< packet
->GetTagByName(EC_TAG_PREFS_CATEGORIES
)->GetTagCount(); i
++) {
647 const CECTag
*cat_tag
= packet
->GetTagByName(EC_TAG_PREFS_CATEGORIES
)->GetTagByIndex(i
);
648 Category_Struct
*cat
= new Category_Struct
;
649 cat
->title
= cat_tag
->GetTagByName(EC_TAG_CATEGORY_TITLE
)->GetStringData();
650 cat
->path
= CPath(cat_tag
->GetTagByName(EC_TAG_CATEGORY_PATH
)->GetStringData());
651 cat
->comment
= cat_tag
->GetTagByName(EC_TAG_CATEGORY_COMMENT
)->GetStringData();
652 cat
->color
= cat_tag
->GetTagByName(EC_TAG_CATEGORY_COLOR
)->GetInt();
653 cat
->prio
= cat_tag
->GetTagByName(EC_TAG_CATEGORY_PRIO
)->GetInt();
654 theApp
->glob_prefs
->AddCat(cat
);
657 Category_Struct
*cat
= new Category_Struct
;
658 cat
->title
= _("All");
660 cat
->prio
= PR_NORMAL
;
661 theApp
->glob_prefs
->AddCat(cat
);
663 wxECInitDoneEvent event
;
664 theApp
->AddPendingEvent(event
);
669 bool CPreferencesRem::LoadRemote()
672 // override local settings with remote
673 CECPacket
req(EC_OP_GET_PREFERENCES
, EC_DETAIL_UPDATE
);
675 // bring categories too
676 req
.AddTag(CECTag(EC_TAG_SELECT_PREFS
, m_exchange_recv_selected_prefs
));
678 m_conn
->SendRequest(this, &req
);
684 void CPreferencesRem::SendToRemote()
686 CEC_Prefs_Packet
pref_packet(m_exchange_send_selected_prefs
, EC_DETAIL_UPDATE
, EC_DETAIL_FULL
);
687 m_conn
->SendPacket(&pref_packet
);
691 Category_Struct
*CPreferencesRem::CreateCategory(
692 const wxString
& name
,
694 const wxString
& comment
,
698 CECPacket
req(EC_OP_CREATE_CATEGORY
);
699 CEC_Category_Tag
tag(0xffffffff, name
, path
.GetRaw(), comment
, color
, prio
);
701 m_conn
->SendPacket(&req
);
703 Category_Struct
*category
= new Category_Struct();
704 category
->path
= path
;
705 category
->title
= name
;
706 category
->comment
= comment
;
707 category
->color
= color
;
708 category
->prio
= prio
;
716 void CPreferencesRem::UpdateCategory(
718 const wxString
& name
,
720 const wxString
& comment
,
724 CECPacket
req(EC_OP_UPDATE_CATEGORY
);
725 CEC_Category_Tag
tag(cat
, name
, path
.GetRaw(), comment
, color
, prio
);
727 m_conn
->SendPacket(&req
);
729 Category_Struct
*category
= m_CatList
[cat
];
730 category
->path
= path
;
731 category
->title
= name
;
732 category
->comment
= comment
;
733 category
->color
= color
;
734 category
->prio
= prio
;
738 void CPreferencesRem::RemoveCat(uint8 cat
)
740 CECPacket
req(EC_OP_DELETE_CATEGORY
);
741 CEC_Category_Tag
tag(cat
, EC_DETAIL_CMD
);
743 m_conn
->SendPacket(&req
);
744 CPreferences::RemoveCat(cat
);
749 // Container implementation
751 CServerConnectRem::CServerConnectRem(CRemoteConnect
*conn
)
758 void CServerConnectRem::ConnectToAnyServer()
760 CECPacket
req(EC_OP_SERVER_CONNECT
);
761 m_Conn
->SendPacket(&req
);
765 void CServerConnectRem::StopConnectionTry()
767 // lfroen: isn't Disconnect the same ?
771 void CServerConnectRem::Disconnect()
773 CECPacket
req(EC_OP_SERVER_DISCONNECT
);
774 m_Conn
->SendPacket(&req
);
778 void CServerConnectRem::ConnectToServer(CServer
*server
)
780 m_Conn
->ConnectED2K(server
->GetIP(), server
->GetPort());
784 bool CServerConnectRem::ReQuery()
786 CECPacket
stat_req(EC_OP_GET_CONNSTATE
);
787 m_Conn
->SendRequest(this, &stat_req
);
793 void CServerConnectRem::HandlePacket(const CECPacket
*packet
)
795 CEC_ConnState_Tag
*tag
=
796 (CEC_ConnState_Tag
*)packet
->GetTagByName(EC_TAG_CONNSTATE
);
801 theApp
->m_ConnState
= 0;
803 m_ID
= tag
->GetEd2kId();
804 theApp
->m_clientID
= tag
->GetClientId();
806 if (tag
->IsConnectedED2K()) {
807 CECTag
*srvtag
= tag
->GetTagByName(EC_TAG_SERVER
);
811 server
= theApp
->serverlist
->GetByID(srvtag
->GetIPv4Data().IP());
812 if (m_CurrServer
&& (server
!= m_CurrServer
)) {
813 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->
814 HighlightServer(m_CurrServer
, false);
816 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->
817 HighlightServer(server
, true);
818 m_CurrServer
= server
;
819 theApp
->m_ConnState
|= CONNECTED_ED2K
;
821 if ( m_CurrServer
) {
822 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->
823 HighlightServer(m_CurrServer
, false);
828 if (tag
->IsConnectedKademlia()) {
829 if (tag
->IsKadFirewalled()) {
830 theApp
->m_ConnState
|= CONNECTED_KAD_FIREWALLED
;
832 theApp
->m_ConnState
|= CONNECTED_KAD_OK
;
835 if (tag
->IsKadRunning()) {
836 theApp
->m_ConnState
|= CONNECTED_KAD_NOT
;
840 theApp
->amuledlg
->ShowConnectionState();
845 * Server list: host list of ed2k servers.
847 CServerListRem::CServerListRem(CRemoteConnect
*conn
)
849 CRemoteContainer
<CServer
, uint32
, CEC_Server_Tag
>(conn
)
854 void CServerListRem::HandlePacket(const CECPacket
*packet
)
856 CRemoteContainer
<CServer
, uint32
, CEC_Server_Tag
>::HandlePacket(packet
);
861 void CServerListRem::UpdateServerMetFromURL(wxString url
)
863 CECPacket
req(EC_OP_SERVER_UPDATE_FROM_URL
);
864 req
.AddTag(CECTag(EC_TAG_SERVERS_UPDATE_URL
, url
));
866 m_conn
->SendPacket(&req
);
870 void CServerListRem::SaveServerMet()
872 // lfroen: stub, nothing to do
876 void CServerListRem::FilterServers()
883 void CServerListRem::RemoveServer(CServer
* server
)
885 m_conn
->RemoveServer(server
->GetIP(),server
->GetPort());
889 void CServerListRem::UpdateUserFileStatus(CServer
*server
)
892 m_TotalUser
= server
->GetUsers();
893 m_TotalFile
= server
->GetFiles();
896 CFormat(_("Total Users: %s | Total Files: %s")) % CastItoIShort(m_TotalUser
) % CastItoIShort(m_TotalFile
);
898 Notify_ShowUserCount(buffer
);
903 CServer
*CServerListRem::GetServerByAddress(const wxString
& WXUNUSED(address
), uint16
WXUNUSED(port
)) const
905 // It's ok to return 0 for context where this code is used in remote gui
909 CServer
*CServerListRem::GetServerByIPTCP(uint32
WXUNUSED(nIP
), uint16
WXUNUSED(nPort
)) const
911 // It's ok to return 0 for context where this code is used in remote gui
915 CServer
*CServerListRem::CreateItem(CEC_Server_Tag
*tag
)
917 return new CServer(tag
);
921 void CServerListRem::DeleteItem(CServer
*in_srv
)
923 auto_ptr
<CServer
> srv(in_srv
);
924 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->RemoveServer(srv
.get());
928 uint32
CServerListRem::GetItemID(CServer
*server
)
930 return server
->GetIP();
934 void CServerListRem::ProcessItemUpdate(CEC_Server_Tag
*, CServer
*)
936 // server list is always realoaded from scratch
941 void CServerListRem::ReloadControl()
943 for(uint32 i
= 0;i
< GetCount(); i
++) {
944 CServer
*srv
= GetByIndex(i
);
945 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->RefreshServer(srv
);
950 CIPFilterRem::CIPFilterRem(CRemoteConnect
* conn
)
956 void CIPFilterRem::Reload()
958 CECPacket
req(EC_OP_IPFILTER_RELOAD
);
959 m_conn
->SendPacket(&req
);
963 void CIPFilterRem::Update(wxString
WXUNUSED(url
))
965 // FIXME: add command
973 CSharedFilesRem::CSharedFilesRem(CRemoteConnect
*conn
) : CRemoteContainer
<CKnownFile
, CMD4Hash
, CEC_SharedFile_Tag
>(conn
, true)
975 m_rename_file
= NULL
;
979 void CSharedFilesRem::Reload(bool, bool)
981 CECPacket
req(EC_OP_SHAREDFILES_RELOAD
);
983 m_conn
->SendPacket(&req
);
987 void CSharedFilesRem::AddFilesFromDirectory(const CPath
& path
)
989 CECPacket
req(EC_OP_SHAREDFILES_ADD_DIRECTORY
);
991 req
.AddTag(CECTag(EC_TAG_PREFS_DIRECTORIES
, path
.GetRaw()));
993 m_conn
->SendPacket(&req
);
997 bool CSharedFilesRem::RenameFile(CKnownFile
* file
, const CPath
& newName
)
999 // We use the printable name, as the filename originated from user input,
1000 // and the filesystem name might not be valid on the remote host.
1001 const wxString strNewName
= newName
.GetPrintable();
1003 CECPacket
request(EC_OP_RENAME_FILE
);
1004 request
.AddTag(CECTag(EC_TAG_KNOWNFILE
, file
->GetFileHash()));
1005 request
.AddTag(CECTag(EC_TAG_PARTFILE_NAME
, strNewName
));
1007 m_conn
->SendRequest(this, &request
);
1008 m_rename_file
= file
;
1009 m_new_name
= strNewName
;
1015 void CSharedFilesRem::HandlePacket(const CECPacket
*packet
)
1017 if (m_rename_file
&& (packet
->GetOpCode() == EC_OP_NOOP
)) {
1018 m_rename_file
->SetFileName(CPath(m_new_name
));
1019 m_rename_file
= NULL
;
1020 } else if (packet
->GetOpCode() != EC_OP_FAILED
) {
1021 CRemoteContainer
<CKnownFile
, CMD4Hash
, CEC_SharedFile_Tag
>::HandlePacket(packet
);
1026 CKnownFile
*CSharedFilesRem::CreateItem(CEC_SharedFile_Tag
*tag
)
1028 CKnownFile
*file
= new CKnownFile(tag
);
1030 m_enc_map
[file
->GetFileHash()] = RLE_Data(file
->GetPartCount(), true);
1032 ProcessItemUpdate(tag
, file
);
1034 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->ShowFile(file
);
1040 void CSharedFilesRem::DeleteItem(CKnownFile
*in_file
)
1042 auto_ptr
<CKnownFile
> file(in_file
);
1044 m_enc_map
.erase(file
->GetFileHash());
1046 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->RemoveFile(file
.get());
1050 CMD4Hash
CSharedFilesRem::GetItemID(CKnownFile
*file
)
1052 return file
->GetFileHash();
1056 void CSharedFilesRem::ProcessItemUpdate(CEC_SharedFile_Tag
*tag
, CKnownFile
*file
)
1058 CECTag
*parttag
= tag
->GetTagByName(EC_TAG_PARTFILE_PART_STATUS
);
1059 const unsigned char *data
=
1060 m_enc_map
[file
->GetFileHash()].Decode(
1061 (unsigned char *)parttag
->GetTagData(),
1062 parttag
->GetTagDataLen());
1063 for(int i
= 0; i
< file
->GetPartCount(); ++i
) {
1064 file
->m_AvailPartFrequency
[i
] = data
[i
];
1067 tag
->SetRequests(file
->statistic
.requested
);
1068 tag
->SetAllRequests(file
->statistic
.alltimerequested
);
1069 tag
->SetAccepts(file
->statistic
.accepted
);
1070 tag
->SetAllAccepts(file
->statistic
.alltimeaccepted
);
1071 tag
->SetXferred(file
->statistic
.transferred
);
1072 tag
->SetAllXferred(file
->statistic
.alltimetransferred
);
1073 tag
->SetPrio(file
->m_iUpPriority
);
1075 file
->statistic
.requested
= tag
->GetRequests();
1076 file
->statistic
.alltimerequested
= tag
->GetAllRequests();
1077 file
->statistic
.accepted
= tag
->GetAccepts();
1078 file
->statistic
.alltimeaccepted
= tag
->GetAllAccepts();
1079 file
->statistic
.transferred
= tag
->GetXferred();
1080 file
->statistic
.alltimetransferred
= tag
->GetAllXferred();
1081 file
->m_iUpPriority
= tag
->Prio();
1083 if (file
->m_iUpPriority
>= 10) {
1084 file
->m_iUpPriority
-= 10;
1085 file
->m_bAutoUpPriority
= true;
1087 file
->m_bAutoUpPriority
= false;
1090 theApp
->knownfiles
->requested
+= file
->statistic
.requested
;
1091 theApp
->knownfiles
->transferred
+= file
->statistic
.transferred
;
1092 theApp
->knownfiles
->accepted
+= file
->statistic
.transferred
;
1094 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->UpdateItem(file
);
1097 bool CSharedFilesRem::Phase1Done(const CECPacket
*)
1099 theApp
->knownfiles
->requested
= 0;
1100 theApp
->knownfiles
->transferred
= 0;
1101 theApp
->knownfiles
->accepted
= 0;
1106 void CSharedFilesRem::SetFilePrio(CKnownFile
*file
, uint8 prio
)
1108 CECPacket
req(EC_OP_SHARED_SET_PRIO
);
1110 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1111 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_PRIO
, prio
));
1113 req
.AddTag(hashtag
);
1115 m_conn
->SendPacket(&req
);
1119 * List of uploading and waiting clients.
1121 CUpDownClientListRem::CUpDownClientListRem(CRemoteConnect
*conn
, int viewtype
)
1123 CRemoteContainer
<CUpDownClient
, uint32
, CEC_UpDownClient_Tag
>(conn
)
1125 m_viewtype
= viewtype
;
1129 CUpDownClient::CUpDownClient(CEC_UpDownClient_Tag
*tag
)
1131 m_bRemoteQueueFull
= false;
1132 m_nUserIDHybrid
= tag
->ID();
1133 m_Username
= tag
->ClientName();
1134 m_score
= tag
->Score();
1135 m_clientSoft
= tag
->ClientSoftware();
1136 m_clientVersionString
= GetSoftName(m_clientSoft
);
1137 m_clientSoftString
= m_clientVersionString
;
1139 // The functions to retrieve m_clientVerString information are
1140 // currently in BaseClient.cpp, which is not linked in remote-gui app.
1141 // So, in the meantime, we use a tag sent from core.
1142 m_clientVerString
= tag
->SoftVerStr();
1143 m_strModVersion
= wxEmptyString
;
1144 wxString clientModString
;
1145 if (!clientModString
.IsEmpty()) {
1146 m_clientVerString
+= wxT(" - ") + clientModString
;
1148 m_fullClientVerString
= m_clientSoftString
+ wxT(" ") + m_clientVerString
;
1151 m_UserHash
= tag
->UserID();
1154 m_nConnectIP
= m_dwUserIP
= tag
->UserIP();
1155 m_nUserPort
= tag
->UserPort();
1156 m_FullUserIP
= m_nConnectIP
;
1159 m_dwServerIP
= tag
->ServerIP();
1160 m_nServerPort
= tag
->ServerPort();
1161 m_ServerName
= tag
->ServerName();
1163 m_waitingPosition
= tag
->WaitingPosition();
1166 if (tag
->HaveFile()) {
1167 CMD4Hash filehash
= tag
->FileID();
1168 m_uploadingfile
= theApp
->sharedfiles
->GetByID(filehash
);
1169 if (!m_uploadingfile
) {
1170 m_uploadingfile
= theApp
->downloadqueue
->GetByID(filehash
);
1173 m_uploadingfile
= NULL
;
1176 m_nCurSessionUp
= 0;
1178 credits
= new CClientCredits(new CreditStruct());
1181 uint16
CUpQueueRem::GetWaitingPosition(const CUpDownClient
*client
) const
1183 return client
->GetWaitingPosition();
1186 /* Warning: do common base */
1189 bool CUpDownClient::IsIdentified() const
1191 return (credits
&& credits
->GetCurrentIdentState(GetIP()) == IS_IDENTIFIED
);
1195 bool CUpDownClient::IsBadGuy() const
1197 return (credits
&& credits
->GetCurrentIdentState(GetIP()) == IS_IDBADGUY
);
1201 bool CUpDownClient::SUIFailed() const
1203 return (credits
&& credits
->GetCurrentIdentState(GetIP()) == IS_IDFAILED
);
1207 bool CUpDownClient::SUINeeded() const
1209 return (credits
&& credits
->GetCurrentIdentState(GetIP()) == IS_IDNEEDED
);
1213 bool CUpDownClient::SUINotSupported() const
1215 return (credits
&& credits
->GetCurrentIdentState(GetIP()) == IS_NOTAVAILABLE
);
1219 uint64
CUpDownClient::GetDownloadedTotal() const
1221 return credits
? credits
->GetDownloadedTotal() : 0;
1225 uint64
CUpDownClient::GetUploadedTotal() const
1227 return credits
? credits
->GetUploadedTotal() : 0;
1231 double CUpDownClient::GetScoreRatio() const
1233 return credits
? credits
->GetScoreRatio(GetIP(), theApp
->CryptoAvailable()) : 0;
1239 CUpDownClient::~CUpDownClient()
1247 CUpDownClient
*CUpDownClientListRem::CreateItem(CEC_UpDownClient_Tag
*tag
)
1249 CUpDownClient
*client
= new CUpDownClient(tag
);
1250 ProcessItemUpdate(tag
, client
);
1252 theApp
->amuledlg
->m_transferwnd
->clientlistctrl
->InsertClient(client
, (ViewType
)m_viewtype
);
1258 void CUpDownClientListRem::DeleteItem(CUpDownClient
*client
)
1260 theApp
->amuledlg
->m_transferwnd
->clientlistctrl
->
1261 RemoveClient(client
, (ViewType
)m_viewtype
);
1266 uint32
CUpDownClientListRem::GetItemID(CUpDownClient
*client
)
1268 return client
->GetUserIDHybrid();
1272 void CUpDownClientListRem::ProcessItemUpdate(
1273 CEC_UpDownClient_Tag
*tag
,
1274 CUpDownClient
*client
)
1276 uint16 state
= tag
->ClientState();
1278 client
->m_nDownloadState
= state
& 0xff;
1279 client
->m_nUploadState
= (state
>> 8) & 0xff;
1281 client
->m_nUpDatarate
= tag
->SpeedUp();
1282 if ( client
->m_nDownloadState
== DS_DOWNLOADING
) {
1283 client
->kBpsDown
= tag
->SpeedDown() / 1024.0;
1285 client
->kBpsDown
= 0;
1288 client
->m_WaitTime
= tag
->WaitTime();
1289 client
->m_UpStartTimeDelay
= tag
->XferTime();
1290 client
->m_dwLastUpRequest
= tag
->LastReqTime();
1291 client
->m_WaitStartTime
= tag
->QueueTime();
1293 CreditStruct
*credit_struct
=
1294 (CreditStruct
*)client
->credits
->GetDataStruct();
1295 credit_struct
->uploaded
= tag
->XferUp();
1296 client
->m_nTransferredUp
= tag
->XferUpSession();
1298 credit_struct
->downloaded
= tag
->XferDown();
1302 CUpQueueRem::CUpQueueRem(CRemoteConnect
*conn
)
1304 m_up_list(conn
, vtUploading
), m_wait_list(conn
, vtQueued
)
1310 * Download queue container: hold PartFiles with progress status
1315 CDownQueueRem::CDownQueueRem(CRemoteConnect
*conn
)
1317 CRemoteContainer
<CPartFile
, CMD4Hash
, CEC_PartFile_Tag
>(conn
, true)
1322 bool CDownQueueRem::AddLink(const wxString
&link
, int)
1324 CECPacket
req(EC_OP_ADD_LINK
);
1325 req
.AddTag(CECTag(EC_TAG_STRING
, link
));
1327 m_conn
->SendPacket(&req
);
1332 void CDownQueueRem::StopUDPRequests()
1334 // have no idea what is it about
1338 void CDownQueueRem::ResetCatParts(int)
1340 // called when category being deleted. Command will be performed on remote side
1344 bool CDownQueueRem::IsPartFile(const CKnownFile
*) const
1346 // hope i understand it right
1351 void CDownQueueRem::OnConnectionState(bool)
1356 CPartFile
*CDownQueueRem::CreateItem(CEC_PartFile_Tag
*tag
)
1358 CPartFile
*file
= new CPartFile(tag
);
1359 m_enc_map
[file
->GetFileHash()] = PartFileEncoderData(file
->GetPartCount(), 10);
1360 ProcessItemUpdate(tag
, file
);
1362 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->AddFile(file
);
1367 void CDownQueueRem::DeleteItem(CPartFile
*in_file
)
1369 auto_ptr
<CPartFile
> file(in_file
);
1371 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->RemoveFile(file
.get());
1373 m_enc_map
.erase(file
->GetFileHash());
1377 CMD4Hash
CDownQueueRem::GetItemID(CPartFile
*file
)
1379 return file
->GetFileHash();
1383 void CDownQueueRem::ProcessItemUpdate(CEC_PartFile_Tag
*tag
, CPartFile
*file
)
1389 uint32 tmpval
= (uint32
)(file
->kBpsDown
* 1024);
1390 tag
->SetSpeed(tmpval
);
1391 file
->kBpsDown
= tmpval
/ 1024.0;
1393 tag
->SetSizeXfer(file
->transferred
);
1394 tag
->SetSizeDone(file
->completedsize
);
1395 tag
->SetSourceXferCount(file
->transferingsrc
);
1396 tag
->SetSourceNotCurrCount(file
->m_notCurrentSources
);
1397 tag
->SetSourceCount(file
->m_source_count
);
1398 tag
->SetSourceCountA4AF(file
->m_a4af_source_count
);
1399 tag
->SetFileStatus(file
->status
);
1401 tag
->SetLastSeenComplete(file
->lastseencomplete
);
1403 tag
->SetFileCat(file
->m_category
);
1405 tag
->SetPrio(file
->m_iDownPriority
);
1407 file
->kBpsDown
= tag
->Speed() / 1024.0;
1409 if ( file
->kBpsDown
> 0 ) {
1410 file
->transferred
= tag
->SizeXfer();
1411 file
->SetCompletedSize(tag
->SizeDone());
1414 file
->transferingsrc
= tag
->SourceXferCount();
1415 file
->m_notCurrentSources
= tag
->SourceNotCurrCount();
1416 file
->m_source_count
= tag
->SourceCount();
1417 file
->m_a4af_source_count
= tag
->SourceCountA4AF();
1418 file
->status
= tag
->FileStatus();
1420 file
->lastseencomplete
= tag
->LastSeenComplete();
1422 file
->m_category
= tag
->FileCat();
1424 file
->m_iDownPriority
= tag
->Prio();
1425 if ( file
->m_iDownPriority
>= 10 ) {
1426 file
->m_iDownPriority
-= 10;
1427 file
->m_bAutoDownPriority
= true;
1429 file
->m_bAutoDownPriority
= false;
1432 file
->percentcompleted
= (100.0*file
->GetCompletedSize()) / file
->GetFileSize();
1433 if ( file
->m_iDownPriority
>= 10 ) {
1434 file
->m_iDownPriority
-= 10;
1435 file
->m_bAutoUpPriority
= true;
1437 file
->m_bAutoUpPriority
= false;
1441 // Copy part/gap status
1443 CECTag
*gaptag
= tag
->GetTagByName(EC_TAG_PARTFILE_GAP_STATUS
);
1444 CECTag
*parttag
= tag
->GetTagByName(EC_TAG_PARTFILE_PART_STATUS
);
1445 CECTag
*reqtag
= tag
->GetTagByName(EC_TAG_PARTFILE_REQ_STATUS
);
1446 if (gaptag
&& parttag
&& reqtag
) {
1447 wxASSERT(m_enc_map
.count(file
->GetFileHash()));
1449 PartFileEncoderData
&encoder
= m_enc_map
[file
->GetFileHash()];
1451 (unsigned char *)gaptag
->GetTagData(), gaptag
->GetTagDataLen(),
1452 (unsigned char *)parttag
->GetTagData(), parttag
->GetTagDataLen());
1454 const uint64
*reqparts
= (const uint64
*)reqtag
->GetTagData();
1455 unsigned reqcount
= reqtag
->GetTagDataLen() / (2 * sizeof(uint64
));
1457 unsigned gap_size
= encoder
.m_gap_status
.Size() / (2 * sizeof(uint64
));
1459 file
->m_gaplist
.Init(file
->GetFileSize(), false);
1462 const uint64
*gap_info
= (const uint64
*)encoder
.m_gap_status
.Buffer();
1463 for (unsigned j
= 0; j
< gap_size
;j
++) {
1464 file
->m_gaplist
.AddGap(ENDIAN_NTOHLL(gap_info
[2*j
]), ENDIAN_NTOHLL(gap_info
[2*j
+1]));
1467 // adjust size of requested block list
1468 while ( file
->m_requestedblocks_list
.size() > reqcount
) {
1469 delete file
->m_requestedblocks_list
.front();
1470 file
->m_requestedblocks_list
.pop_front();
1472 while ( file
->m_requestedblocks_list
.size() != reqcount
) {
1473 file
->m_requestedblocks_list
.push_front(new Requested_Block_Struct
);
1476 std::list
<Requested_Block_Struct
*>::iterator it2
= file
->m_requestedblocks_list
.begin();
1477 for (unsigned i
= 0; i
< reqcount
; ++i
) {
1478 Requested_Block_Struct
* block
= *it2
++;
1479 block
->StartOffset
= ENDIAN_NTOHLL(reqparts
[2*i
]);
1480 block
->EndOffset
= ENDIAN_NTOHLL(reqparts
[2*i
+1]);
1482 // copy parts frequency
1483 const unsigned char *part_info
= encoder
.m_part_status
.Buffer();
1484 for(int i
= 0; i
< file
->GetPartCount(); ++i
) {
1485 file
->m_SrcpartFrequency
[i
] = part_info
[i
];
1488 AddLogLineNS(CFormat(wxT("ERROR: %X %X %X")) % (size_t)gaptag
% (size_t)parttag
% (size_t)reqtag
);
1492 CECTag
*srcnametag
= tag
->GetTagByName(EC_TAG_PARTFILE_SOURCE_NAMES
);
1494 file
->ClearSourcenameItemList();
1495 int max
= srcnametag
->GetTagCount();
1496 for (int i
= 0; i
< max
- 1; ) {
1497 wxString name
= srcnametag
->GetTagByIndex(i
++)->GetStringData();
1498 long count
= srcnametag
->GetTagByIndex(i
++)->GetInt();
1499 file
->AddSourcenameItemList(name
, count
);
1504 CECTag
*commenttag
= tag
->GetTagByName(EC_TAG_PARTFILE_COMMENTS
);
1506 file
->ClearFileRatingList();
1507 int max
= commenttag
->GetTagCount();
1508 for (int i
= 0; i
< max
- 3; ) {
1509 wxString u
= commenttag
->GetTagByIndex(i
++)->GetStringData();
1510 wxString f
= commenttag
->GetTagByIndex(i
++)->GetStringData();
1511 int r
= commenttag
->GetTagByIndex(i
++)->GetInt();
1512 wxString c
= commenttag
->GetTagByIndex(i
++)->GetStringData();
1513 file
->AddFileRatingList(u
, f
, r
, c
);
1515 file
->UpdateFileRatingCommentAvail();
1518 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->UpdateItem(file
);
1522 bool CDownQueueRem::Phase1Done(const CECPacket
*)
1528 void CDownQueueRem::SendFileCommand(CPartFile
*file
, ec_tagname_t cmd
)
1531 req
.AddTag(CECTag(EC_TAG_PARTFILE
, file
->GetFileHash()));
1533 m_conn
->SendPacket(&req
);
1537 void CDownQueueRem::Prio(CPartFile
*file
, uint8 prio
)
1539 CECPacket
req(EC_OP_PARTFILE_PRIO_SET
);
1541 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1542 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_PRIO
, prio
));
1543 req
.AddTag(hashtag
);
1545 m_conn
->SendPacket(&req
);
1549 void CDownQueueRem::AutoPrio(CPartFile
*file
, bool flag
)
1551 CECPacket
req(EC_OP_PARTFILE_PRIO_SET
);
1553 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1555 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_PRIO
,
1556 (uint8
)(flag
? PR_AUTO
: file
->GetDownPriority())));
1557 req
.AddTag(hashtag
);
1559 m_conn
->SendPacket(&req
);
1563 void CDownQueueRem::Category(CPartFile
*file
, uint8 cat
)
1565 CECPacket
req(EC_OP_PARTFILE_SET_CAT
);
1566 file
->m_category
= cat
;
1568 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1569 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_CAT
, cat
));
1570 req
.AddTag(hashtag
);
1572 m_conn
->SendPacket(&req
);
1576 void CDownQueueRem::AddSearchToDownload(CSearchFile
* file
, uint8 category
)
1578 CECPacket
req(EC_OP_DOWNLOAD_SEARCH_RESULT
);
1579 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1580 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_CAT
, category
));
1581 req
.AddTag(hashtag
);
1583 m_conn
->SendPacket(&req
);
1587 CClientListRem::CClientListRem(CRemoteConnect
*conn
)
1593 void CClientListRem::FilterQueues()
1600 CSearchListRem::CSearchListRem(CRemoteConnect
*conn
) : CRemoteContainer
<CSearchFile
, CMD4Hash
, CEC_SearchFile_Tag
>(conn
)
1606 wxString
CSearchListRem::StartNewSearch(
1607 uint32
* nSearchID
, SearchType search_type
,
1608 const CSearchList::CSearchParams
& params
)
1610 CECPacket
search_req(EC_OP_SEARCH_START
);
1611 EC_SEARCH_TYPE ec_search_type
= EC_SEARCH_LOCAL
;
1612 switch(search_type
) {
1613 case LocalSearch
: ec_search_type
= EC_SEARCH_LOCAL
; break;
1614 case GlobalSearch
: ec_search_type
= EC_SEARCH_GLOBAL
; break;
1615 case KadSearch
: ec_search_type
= EC_SEARCH_KAD
; break;
1618 CEC_Search_Tag(params
.searchString
, ec_search_type
,
1619 params
.typeText
, params
.extension
, params
.availability
,
1620 params
.minSize
, params
.maxSize
));
1622 m_conn
->SendPacket(&search_req
);
1623 m_curr_search
= *(nSearchID
); // No kad remote search yet.
1627 return wxEmptyString
; // EC reply will have the error mesg is needed.
1631 void CSearchListRem::StopGlobalSearch()
1633 if (m_curr_search
!= -1) {
1634 CECPacket
search_req(EC_OP_SEARCH_STOP
);
1635 m_conn
->SendPacket(&search_req
);
1640 void CSearchListRem::HandlePacket(const CECPacket
*packet
)
1642 if ( packet
->GetOpCode() == EC_OP_SEARCH_PROGRESS
) {
1643 CoreNotify_Search_Update_Progress(packet
->GetTagByIndex(0)->GetInt());
1645 CRemoteContainer
<CSearchFile
, CMD4Hash
, CEC_SearchFile_Tag
>::HandlePacket(packet
);
1650 CSearchFile::CSearchFile(CEC_SearchFile_Tag
*tag
)
1653 m_showChildren(false),
1655 m_completeSourceCount(0),
1660 SetFileName(CPath(tag
->FileName()));
1661 m_abyFileHash
= tag
->ID();
1662 SetFileSize(tag
->SizeFull());
1664 m_searchID
= theApp
->searchlist
->m_curr_search
;
1669 // dtor is virtual - must be implemented
1670 CSearchFile::~CSearchFile()
1675 CSearchFile
*CSearchListRem::CreateItem(CEC_SearchFile_Tag
*tag
)
1677 CSearchFile
*file
= new CSearchFile(tag
);
1678 ProcessItemUpdate(tag
, file
);
1680 theApp
->amuledlg
->m_searchwnd
->AddResult(file
);
1686 void CSearchListRem::DeleteItem(CSearchFile
*file
)
1692 CMD4Hash
CSearchListRem::GetItemID(CSearchFile
*file
)
1694 return file
->GetFileHash();
1698 void CSearchListRem::ProcessItemUpdate(CEC_SearchFile_Tag
*tag
, CSearchFile
*file
)
1700 file
->m_sourceCount
= tag
->SourceCount();
1701 file
->m_completeSourceCount
= tag
->CompleteSourceCount();
1705 bool CSearchListRem::Phase1Done(const CECPacket
*WXUNUSED(reply
))
1707 CECPacket
progress_req(EC_OP_SEARCH_PROGRESS
);
1708 m_conn
->SendRequest(this, &progress_req
);
1714 void CSearchListRem::RemoveResults(long nSearchID
)
1716 ResultMap::iterator it
= m_results
.find(nSearchID
);
1717 if (it
!= m_results
.end()) {
1718 CSearchResultList
& list
= it
->second
;
1719 for (unsigned int i
= 0; i
< list
.size(); ++i
) {
1722 m_results
.erase(it
);
1727 const CSearchResultList
& CSearchListRem::GetSearchResults(long nSearchID
)
1729 ResultMap::const_iterator it
= m_results
.find(nSearchID
);
1730 if (it
!= m_results
.end()) {
1734 // TODO: Should we assert in this case?
1735 static CSearchResultList list
;
1740 void CStatsUpdaterRem::HandlePacket(const CECPacket
*packet
)
1742 theStats::UpdateStats(packet
);
1743 theApp
->ShowUserCount(); // maybe there should be a check if a usercount changed ?
1747 bool CUpDownClient::IsBanned() const
1755 // Those functions have different implementation in remote gui
1757 void CUpDownClient::Ban()
1764 void CUpDownClient::UnBan()
1771 void CUpDownClient::RequestSharedFileList()
1778 void CKnownFile::SetFileComment(const wxString
&)
1785 void CKnownFile::SetFileRating(unsigned char)
1792 // I don't think it will be implemented - too match data transfer. But who knows ?
1793 wxString
CUpDownClient::ShowDownloadingParts() const
1795 return wxEmptyString
;
1799 bool CUpDownClient::SwapToAnotherFile(
1800 bool WXUNUSED(bIgnoreNoNeeded
),
1801 bool WXUNUSED(ignoreSuspensions
),
1802 bool WXUNUSED(bRemoveCompletely
),
1803 CPartFile
* WXUNUSED(toFile
))
1812 // Those functions are virtual. So even they don't get called they must
1813 // be defined so linker will be happy
1815 CPacket
* CKnownFile::CreateSrcInfoPacket(const CUpDownClient
*, uint8
/*byRequestedVersion*/, uint16
/*nRequestedOptions*/)
1822 bool CKnownFile::LoadFromFile(const class CFileDataIO
*)
1829 void CKnownFile::UpdatePartsInfo()
1835 CPacket
* CPartFile::CreateSrcInfoPacket(CUpDownClient
const *, uint8
/*byRequestedVersion*/, uint16
/*nRequestedOptions*/)
1842 void CPartFile::UpdatePartsInfo()
1848 void CPartFile::UpdateFileRatingCommentAvail()
1850 bool prevComment
= m_hasComment
;
1851 int prevRating
= m_iUserRating
;
1853 m_hasComment
= false;
1855 int ratingCount
= 0;
1857 FileRatingList::iterator it
= m_FileRatingList
.begin();
1858 for (; it
!= m_FileRatingList
.end(); ++it
) {
1859 SFileRating
& cur_rat
= *it
;
1861 if (!cur_rat
.Comment
.IsEmpty()) {
1862 m_hasComment
= true;
1865 uint8 rating
= cur_rat
.Rating
;
1867 wxASSERT(rating
<= 5);
1870 m_iUserRating
+= rating
;
1875 m_iUserRating
/= ratingCount
;
1876 wxASSERT(m_iUserRating
> 0 && m_iUserRating
<= 5);
1879 if ((prevComment
!= m_hasComment
) || (prevRating
!= m_iUserRating
)) {
1880 UpdateDisplayedInfo();
1884 bool CPartFile::SavePartFile(bool)
1892 // since gui is not linked with amule.cpp - define events here
1894 DEFINE_LOCAL_EVENT_TYPE(wxEVT_CORE_FINISHED_HTTP_DOWNLOAD
)
1895 DEFINE_LOCAL_EVENT_TYPE(wxEVT_CORE_SOURCE_DNS_DONE
)
1896 DEFINE_LOCAL_EVENT_TYPE(wxEVT_CORE_UDP_DNS_DONE
)
1897 DEFINE_LOCAL_EVENT_TYPE(wxEVT_CORE_SERVER_DNS_DONE
)
1898 // File_checked_for_headers