2 // This file is part of the aMule Project.
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2008 Merkur ( devs@emule-project.net / http://www.emule-project.net )
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "ServerSocket.h" // Interface declarations
28 #include <protocol/Protocols.h>
29 #include <common/EventIDs.h>
30 #include <tags/ServerTags.h>
32 #include <wx/tokenzr.h>
34 #include "Packet.h" // Needed for CPacket
35 #include "updownclient.h" // Needed for CUpDownClient
36 #include "ClientList.h" // Needed for CClientList
37 #include "MemFile.h" // Needed for CMemFile
38 #include "PartFile.h" // Needed for CPartFile
39 #include "SearchList.h" // Needed for CSearchList
40 #include "Preferences.h" // Needed for CPreferences
41 #include "DownloadQueue.h" // Needed for CDownloadQueue
42 #include "ServerList.h" // Needed for CServerList
43 #include "Server.h" // Needed for CServer
44 #include "amule.h" // Needed for theApp
45 #include "Statistics.h" // Needed for theStats
46 #include "AsyncDNS.h" // Needed for CAsyncDNS
48 #include <common/Format.h>
50 #include "GuiEvents.h" // Needed for Notify_*
54 //------------------------------------------------------------------------------
55 // CServerSocketHandler
56 //------------------------------------------------------------------------------
58 //------------------------------------------------------------------------------
59 // CServerSocketHandler
60 //------------------------------------------------------------------------------
63 class CServerSocketHandler
: public wxEvtHandler
66 CServerSocketHandler() {};
70 void ServerSocketHandler(wxSocketEvent
& event
);
75 BEGIN_EVENT_TABLE(CServerSocketHandler
, wxEvtHandler
)
76 EVT_SOCKET(ID_SERVERSOCKET_EVENT
, CServerSocketHandler::ServerSocketHandler
)
79 void CServerSocketHandler::ServerSocketHandler(wxSocketEvent
& event
)
81 CServerSocket
*socket
= dynamic_cast<CServerSocket
*>(event
.GetSocket());
87 if (socket
->OnDestroy()) {
91 switch(event
.GetSocketEvent()) {
92 case wxSOCKET_CONNECTION
:
93 socket
->OnConnect(wxSOCKET_NOERROR
);
96 socket
->OnError(socket
->LastError());
99 socket
->OnReceive(wxSOCKET_NOERROR
);
101 case wxSOCKET_OUTPUT
:
102 socket
->OnSend(wxSOCKET_NOERROR
);
113 // There can be only one. :)
115 static CServerSocketHandler g_serverSocketHandler
;
118 //------------------------------------------------------------------------------
120 //------------------------------------------------------------------------------
122 CServerSocket::CServerSocket(CServerConnect
* in_serverconnect
, const CProxyData
*ProxyData
)
126 serverconnect
= in_serverconnect
;
130 m_bIsDeleting
= false;
132 SetEventHandler(g_serverSocketHandler
, ID_SERVERSOCKET_EVENT
);
135 wxSOCKET_CONNECTION_FLAG
|
136 wxSOCKET_INPUT_FLAG
|
137 wxSOCKET_OUTPUT_FLAG
|
141 m_dwLastTransmission
= 0;
146 CServerSocket::~CServerSocket()
148 // remove event handler...
159 void CServerSocket::OnConnect(wxSocketError nErrorCode
)
161 switch (nErrorCode
) {
162 case wxSOCKET_NOERROR
:
163 if (cur_server
->HasDynIP()) {
164 amuleIPV4Address tmpaddr
;
166 uint32 server_ip
= StringIPtoUint32(tmpaddr
.IPAddress());
167 cur_server
->SetID(server_ip
);
168 // GetServerByAddress may return NULL, so we must test!
169 // This was the reason why amule would crash when trying to
170 // connect in wxWidgets 2.5.2
171 CServer
*pServer
= theApp
->serverlist
->GetServerByAddress(
172 cur_server
->GetAddress(), cur_server
->GetPort());
174 pServer
->SetID(server_ip
);
176 AddDebugLogLineM(false, logServer
, wxT("theApp->serverlist->GetServerByAddress() returned NULL"));
180 SetConnectionState(CS_WAITFORLOGIN
);
183 case wxSOCKET_INVADDR
:
184 case wxSOCKET_NOHOST
:
185 case wxSOCKET_INVPORT
:
186 case wxSOCKET_TIMEDOUT
:
187 m_bIsDeleting
= true;
188 SetConnectionState(CS_SERVERDEAD
);
189 serverconnect
->DestroySocket(this);
193 case wxSOCKET_MEMERR
:
196 m_bIsDeleting
= true;
197 SetConnectionState(CS_FATALERROR
);
198 serverconnect
->DestroySocket(this);
205 void CServerSocket::OnReceive(wxSocketError nErrorCode
)
207 if (connectionstate
!= CS_CONNECTED
&& !serverconnect
->IsConnecting()) {
208 serverconnect
->DestroySocket(this);
211 CEMSocket::OnReceive((int)nErrorCode
);
212 m_dwLastTransmission
= GetTickCount();
215 bool CServerSocket::ProcessPacket(const byte
* packet
, uint32 size
, int8 opcode
)
218 AddDebugLogLineM( false, logServer
, wxT("Processing Server Packet: ") );
221 case OP_SERVERMESSAGE
: {
222 /* Kry import of lugdunum 16.40 new features */
223 AddDebugLogLineM( false, logServer
, wxT("Server: OP_SERVERMESSAGE") );
225 theStats::AddDownOverheadServer(size
);
226 char* buffer
= new char[size
-1];
227 memcpy(buffer
,&packet
[2],size
-2);
230 wxString
strMessages(char2unicode(buffer
));
234 // 16.40 servers do not send separate OP_SERVERMESSAGE packets for each line;
235 // instead of this they are sending all text lines with one OP_SERVERMESSAGE packet.
237 wxStringTokenizer
token(strMessages
,wxT("\r\n"),wxTOKEN_DEFAULT
);
239 while (token
.HasMoreTokens()) {
240 wxString message
= token
.GetNextToken();
242 bool bOutputMessage
= true;
243 if (message
.StartsWith(wxT("server version"))) {
244 wxString strVer
= message
.Mid(15,64); // truncate string to avoid misuse by servers in showing ads
246 CServer
* eserver
= theApp
->serverlist
->GetServerByAddress(cur_server
->GetAddress(),cur_server
->GetPort());
248 eserver
->SetVersion(strVer
);
249 Notify_ServerRefresh(eserver
);
251 } else if (message
.StartsWith(wxT("ERROR"))) {
252 CServer
* pServer
= theApp
->serverlist
->GetServerByAddress(cur_server
->GetAddress(),cur_server
->GetPort());
255 servername
= pServer
->GetListName();
257 servername
= _("Server");
259 AddLogLineM(false, CFormat( _("ERROR: %s (%s) - %s") )
261 % Uint32_16toStringIP_Port(cur_server
->GetIP(), cur_server
->GetPort())
262 % message
.Mid(5,message
.Len()).Trim(wxT(" :")));
263 bOutputMessage
= false;
265 } else if (message
.StartsWith(wxT("WARNING"))) {
267 CServer
* pServer
= theApp
->serverlist
->GetServerByAddress(cur_server
->GetAddress(),cur_server
->GetPort());
270 servername
= pServer
->GetListName();
272 servername
= _("Server");
274 AddLogLineM(false, CFormat( _("WARNING: %s (%s) - %s") )
276 % Uint32_16toStringIP_Port(cur_server
->GetIP(), cur_server
->GetPort())
277 % message
.Mid(5,message
.Len()).Trim(wxT(" :")));
279 bOutputMessage
= false;
282 if (message
.Find(wxT("[emDynIP: ")) != (-1) && message
.Find(wxT("]")) != (-1) && message
.Find(wxT("[emDynIP: ")) < message
.Find(wxT("]"))){
283 wxString dynip
= message
.Mid(message
.Find(wxT("[emDynIP: "))+10,message
.Find(wxT("]")) - (message
.Find(wxT("[emDynIP: "))+10));
284 dynip
.Trim(wxT(" "));
285 if ( dynip
.Length() && dynip
.Length() < 51){
286 CServer
* eserver
= theApp
->serverlist
->GetServerByAddress(cur_server
->GetAddress(),cur_server
->GetPort());
288 eserver
->SetDynIP(dynip
);
289 cur_server
->SetDynIP(dynip
);
290 Notify_ServerRefresh(eserver
);
295 if (bOutputMessage
) {
296 theApp
->AddServerMessageLine(message
);
302 AddDebugLogLineM(false,logServer
,wxT("Server: OP_IDCHANGE"));
304 theStats::AddDownOverheadServer(size
);
306 if (size
< 4 /* uint32 (ID)*/) {
307 throw wxString(wxT("Corrupt or invalid loginanswer from server received"));
310 CMemFile
data(packet
, size
);
312 uint32 new_id
= data
.ReadUInt32();
314 // save TCP flags in 'cur_server'
315 wxASSERT(cur_server
);
317 CServer
* pServer
= NULL
;
319 uint32 rport
= cur_server
->GetConnPort();
320 pServer
= theApp
->serverlist
->GetServerByAddress(cur_server
->GetAddress(), rport
);
321 if (size
>= 4+4 /* uint32 (ID) + uint32 (TCP flags)*/) {
322 cur_server
->SetTCPFlags(data
.ReadUInt32());
323 if (size
>= 4+4+4 /* uint32 (ID) + uint32 (TCP flags) + uint32 (aux port) */) {
324 // aux port login : we should use the 'standard' port of this server to advertize to other clients
325 ConnPort
= data
.ReadUInt32();
326 cur_server
->SetPort(ConnPort
);
327 if (cur_server
->GetAuxPortsList().IsEmpty()) {
328 cur_server
->SetAuxPortsList(wxString::Format(wxT("%u"), rport
));
330 // cur_server->SetAuxPortsList(wxString::Format(wxT("%u"), rport) + wxT(",") + cur_server->GetAuxPortsList());
334 cur_server
->SetTCPFlags(0);
336 // copy TCP flags into the server in the server list
338 pServer
->SetTCPFlags(cur_server
->GetTCPFlags());
340 pServer
->SetPort(ConnPort
);
341 if (pServer
->GetAuxPortsList().IsEmpty()) {
342 pServer
->SetAuxPortsList(wxString::Format(wxT("%u"), pServer
->GetConnPort()));
344 // pServer->SetAuxPortsList(wxString::Format(wxT("%u"), pServer->GetConnPort()) + wxT(",") + pServer->GetAuxPortsList());
346 Notify_ServerRefresh(pServer
);
347 Notify_ServerUpdateED2KInfo();
352 uint32 dwServerReportedIP
= 0;
353 uint32 dwObfuscationTCPPort
= 0;
354 if (size
>= 4 + 4 + 4 + 4 + 4 /* All of the above + reported ip + obfuscation port */) {
355 dwServerReportedIP
= data
.ReadUInt32();
356 if (::IsLowID(dwServerReportedIP
)){
358 dwServerReportedIP
= 0;
360 wxASSERT( dwServerReportedIP
== new_id
|| ::IsLowID(new_id
) );
361 dwObfuscationTCPPort
= data
.ReadUInt32();
362 if (cur_server
!= NULL
&& dwObfuscationTCPPort
!= 0) {
363 cur_server
->SetObfuscationPortTCP((uint16
)dwObfuscationTCPPort
);
366 if (pServer
!= NULL
&& dwObfuscationTCPPort
!= 0) {
367 pServer
->SetObfuscationPortTCP((uint16
)dwObfuscationTCPPort
);
372 uint8 state
= thePrefs::GetSmartIdState();
376 thePrefs::SetSmartIdState(0);
378 thePrefs::SetSmartIdState(state
);
383 if(thePrefs::GetSmartIdCheck()) {
384 if (!IsLowID(new_id
)) {
385 thePrefs::SetSmartIdState(1);
387 uint8 state
= thePrefs::GetSmartIdState();
391 thePrefs::SetSmartIdState(0);
393 thePrefs::SetSmartIdState(state
);
400 // we need to know our client when sending our shared files (done indirectly on SetConnectionState)
402 serverconnect
->SetClientID(new_id
);
404 if (::IsLowID(new_id
) && dwServerReportedIP
!= 0) {
405 theApp
->SetPublicIP(dwServerReportedIP
);
408 if (connectionstate
!= CS_CONNECTED
) {
409 AddDebugLogLineM(false,logServer
,wxT("Connected"));
411 SetConnectionState(CS_CONNECTED
);
412 theApp
->OnlineSig(); // Added By Bouc7
415 theApp
->ShowConnectionState();
417 AddLogLineM(false, wxString::Format(_("New clientid is %u"),new_id
));
418 if (::IsLowID(new_id
)) {
419 AddLogLineM(true, _("WARNING: You have received Low-ID!"));
420 AddLogLineM(false, _("\tMost likely this is because you're behind a firewall or router."));
421 AddLogLineM(false, _("\tFor more information, please refer to http://wiki.amule.org"));
424 theApp
->downloadqueue
->ResetLocalServerRequests();
427 case OP_SEARCHRESULT
: {
428 AddDebugLogLineM(false,logServer
,wxT("Server: OP_SEARCHRESULT"));
430 theStats::AddDownOverheadServer(size
);
431 CServer
* cur_srv
= (serverconnect
) ?
432 serverconnect
->GetCurrentServer() : NULL
;
433 theApp
->searchlist
->ProcessSearchAnswer(
436 true /*(cur_srv && cur_srv->GetUnicodeSupport())*/,
437 cur_srv
? cur_srv
->GetIP() : 0,
438 cur_srv
? cur_srv
->GetPort() : 0);
439 theApp
->searchlist
->LocalSearchEnd();
442 case OP_FOUNDSOURCES_OBFU
:
443 case OP_FOUNDSOURCES
: {
444 AddDebugLogLineM(false,logServer
,wxString::Format(wxT("ServerMsg - OP_FoundSources; sources = %u"), (uint32
)(byte
)packet
[16]));
445 theStats::AddDownOverheadServer(size
);
446 CMemFile
sources(packet
,size
);
447 CMD4Hash fileid
= sources
.ReadHash();
448 if (CPartFile
* file
= theApp
->downloadqueue
->GetFileByID(fileid
)) {
449 file
->AddSources(sources
, cur_server
->GetIP(), cur_server
->GetPort(), SF_LOCAL_SERVER
, (opcode
== OP_FOUNDSOURCES_OBFU
));
451 AddDebugLogLineM(false, logServer
, wxT("Sources received for unknown file: ") + fileid
.Encode());
455 case OP_SERVERSTATUS
: {
456 AddDebugLogLineM(false,logServer
,wxT("Server: OP_SERVERSTATUS"));
457 // FIXME some statuspackets have a different size -> why? structur?
459 throw wxString(wxT("Invalid server status packet"));
462 CServer
* update
= theApp
->serverlist
->GetServerByAddress(cur_server
->GetAddress(), cur_server
->GetPort());
464 CMemFile
data(packet
, size
);
465 update
->SetUserCount(data
.ReadUInt32());
466 update
->SetFileCount(data
.ReadUInt32());
467 Notify_ServerRefresh( update
);
468 theApp
->ShowUserCount();
473 case OP_SERVERIDENT
: {
474 AddDebugLogLineM(false,logServer
,wxT("Server: OP_SERVERIDENT"));
476 theStats::AddDownOverheadServer(size
);
478 AddLogLineM(false, _("Unknown server info received! - too short"));
479 // throw wxString(wxT("Unknown server info received!"));
482 CServer
* update
= theApp
->serverlist
->GetServerByAddress(cur_server
->GetAddress(),cur_server
->GetPort());
484 CMemFile
data(packet
,size
);
485 CMD4Hash hash
= data
.ReadHash();
486 if (RawPeekUInt32(hash
.GetHash()) == 0x2A2A2A2A){ // No endian problem here
487 const wxString
& rstrVersion
= update
->GetVersion();
488 if (!rstrVersion
.IsEmpty()) {
489 update
->SetVersion(wxT("eFarm ") + rstrVersion
);
491 update
->SetVersion(wxT("eFarm"));
495 /*uint32 nServerIP = */data
.ReadUInt32();
496 /*uint16 nServerPort = */data
.ReadUInt16();
498 uint32 nTags
= data
.ReadUInt32();
499 for (uint32 i
= 0; i
< nTags
; i
++){
500 CTag
tag(data
, update
->GetUnicodeSupport());
501 if (tag
.GetNameID() == ST_SERVERNAME
){
502 update
->SetListName(tag
.GetStr());
503 } else if (tag
.GetNameID() == ST_DESCRIPTION
){
504 update
->SetDescription(tag
.GetStr());
505 } // No more known tags from server
508 theApp
->ShowConnectionState();
509 Notify_ServerRefresh(update
);
513 // tecxx 1609 2002 - add server's serverlist to own serverlist
514 case OP_SERVERLIST
: {
515 AddDebugLogLineM(false,logServer
,wxT("Server: OP_SERVERLIST"));
517 CMemFile
* servers
= new CMemFile(packet
,size
);
518 uint8 count
= servers
->ReadUInt8();
519 if (((int32
)(count
*6 + 1) > size
)) {
524 uint32 ip
= servers
->ReadUInt32();
525 uint16 port
= servers
->ReadUInt16();
526 CServer
* srv
= new CServer(
528 Uint32toStringIP(ip
)); // Ip
529 srv
->SetListName(srv
->GetFullIP());
530 if (!theApp
->AddServer(srv
)) {
539 AddLogLineM(false, wxString::Format(wxPLURAL("Received %d new server", "Received %d new servers", addcount
), addcount
));
541 theApp
->serverlist
->SaveServerMet();
542 AddLogLineM(false, _("Saving of server-list completed."));
545 case OP_CALLBACKREQUESTED
: {
546 AddDebugLogLineM(false,logServer
,wxT("Server: OP_CALLBACKREQUESTED"));
548 theStats::AddDownOverheadServer(size
);
550 CMemFile
data(packet
,size
);
551 uint32 dwIP
= data
.ReadUInt32();
552 uint16 nPort
= data
.ReadUInt16();
554 uint8 byCryptOptions
= 0;
555 CMD4Hash achUserHash
;
557 byCryptOptions
= data
.ReadUInt8();;
558 achUserHash
= data
.ReadHash();
561 CUpDownClient
* client
= theApp
->clientlist
->FindClientByIP(dwIP
,nPort
);
562 if (size
>= 23 && client
->HasValidHash()){
563 if (client
->GetUserHash() != achUserHash
){
564 AddDebugLogLineM(false, logServer
, wxT("Reported Userhash from OP_CALLBACKREQUESTED differs with our stored hash"));
565 // disable crypt support since we dont know which hash is true
566 client
->SetCryptLayerRequest(false);
567 client
->SetCryptLayerSupport(false);
568 client
->SetCryptLayerRequires(false);
570 client
->SetConnectOptions(byCryptOptions
, true, false);
572 } else if (size
>= 23) {
573 client
->SetUserHash(achUserHash
);
574 client
->SetConnectOptions(byCryptOptions
, true, false);
578 client
->TryToConnect();
580 client
= new CUpDownClient(nPort
,dwIP
,0,0,0, true, true);
581 theApp
->clientlist
->AddClient(client
);
582 client
->TryToConnect();
587 case OP_CALLBACK_FAIL
: {
588 AddDebugLogLineM(false,logServer
,wxT("Server: OP_CALLBACK_FAIL"));
592 AddDebugLogLineM(false,logServer
,wxT("Server: OP_REJECT"));
593 AddLogLineM(false, _("Server rejected last command"));
597 AddDebugLogLineM( false, logPacketErrors
,
598 wxString::Format( wxT("Unknown server packet with OPcode %x"), opcode
)
602 } catch (const CInvalidPacket
& e
) {
603 AddLogLineM(false,CFormat( _("Bogus packet received from server: %s") ) % e
.what());
604 } catch (const CEOFException
& e
) {
605 AddLogLineM(false,CFormat( _("Bogus packet received from server: %s") ) % e
.what());
606 } catch (const wxString
& error
) {
607 AddLogLineM(false,CFormat( _("Unhandled error while processing packet from server: %s") ) % error
);
610 // Don't disconnect because of wrong sources.
611 if (opcode
==OP_SEARCHRESULT
|| opcode
==OP_FOUNDSOURCES
) {
615 SetConnectionState(CS_DISCONNECTED
);
619 void CServerSocket::ConnectToServer(CServer
* server
, bool bNoCrypt
)
621 AddDebugLogLineM(false,logServer
,wxT("Trying to connect"));
629 cur_server
= new CServer(server
);
631 m_bNoCrypt
= bNoCrypt
;
633 SetConnectionState(CS_CONNECTING
);
635 info
= cur_server
->GetListName();
637 // This must be used if we want to reverse-check the addr of the server
638 if (cur_server
->HasDynIP() || !cur_server
->GetIP()) {
640 // Send it to solving thread.
641 CAsyncDNS
* dns
= new CAsyncDNS(server
->GetAddress(), DNS_SERVER_CONNECT
, theApp
, this);
643 if ( dns
->Create() == wxTHREAD_NO_ERROR
) {
644 if ( dns
->Run() != wxTHREAD_NO_ERROR
) {
646 AddLogLineM(false, CFormat( _("Cannot create DNS solving thread for connecting to %s") ) % cur_server
->GetAddress());
650 AddLogLineM(false, CFormat( _("Cannot create DNS solving thread for connecting to %s") ) % cur_server
->GetAddress());
653 // Nothing to solve, we already have the IP
654 OnHostnameResolved(cur_server
->GetIP());
659 void CServerSocket::OnError(wxSocketError nErrorCode
)
661 AddDebugLogLineM(false, logServer
, wxT("Error in serversocket: ") + cur_server
->GetListName() + wxT("(") + cur_server
->GetFullIP() + wxString::Format(wxT(":%i): %u"),cur_server
->GetPort(), (int)nErrorCode
));
662 SetConnectionState(CS_DISCONNECTED
);
666 bool CServerSocket::PacketReceived(CPacket
* packet
)
668 AddDebugLogLineM(false, logServer
, wxString::Format(wxT("Server: Packet Received: Prot %x, Opcode %x, Length %u"), packet
->GetProtocol(), packet
->GetOpCode(), packet
->GetPacketSize()));
670 if (packet
->GetProtocol() == OP_PACKEDPROT
) {
671 if (!packet
->UnPackPacket(250000)){
672 AddDebugLogLineM(false, logZLib
, wxString::Format(wxT("Failed to decompress server TCP packet: protocol=0x%02x opcode=0x%02x size=%u"), packet
? packet
->GetProtocol() : 0, packet
? packet
->GetOpCode() : 0, packet
? packet
->GetPacketSize() : 0));
673 theStats::AddDownOverheadServer(packet
->GetPacketSize());
677 packet
->SetProtocol(OP_EDONKEYPROT
);
680 if (packet
->GetProtocol() == OP_EDONKEYPROT
) {
681 ProcessPacket(packet
->GetDataBuffer(), packet
->GetPacketSize(), packet
->GetOpCode());
683 AddDebugLogLineM(false, logServer
, wxString::Format(wxT("Received server TCP packet with unknown protocol: protocol=0x%02x opcode=0x%02x size=%u"), packet
? packet
->GetProtocol() : 0, packet
? packet
->GetOpCode() : 0, packet
? packet
->GetPacketSize() : 0));
684 theStats::AddDownOverheadServer(packet
->GetPacketSize());
691 void CServerSocket::OnClose(wxSocketError
WXUNUSED(nErrorCode
))
693 CEMSocket::OnClose(0);
695 switch (connectionstate
) {
696 case CS_WAITFORLOGIN
: SetConnectionState(CS_SERVERFULL
); break;
697 case CS_CONNECTED
: SetConnectionState(CS_DISCONNECTED
); break;
698 default: SetConnectionState(CS_NOTCONNECTED
);
701 serverconnect
->DestroySocket(this);
704 void CServerSocket::SetConnectionState(sint8 newstate
)
706 connectionstate
= newstate
;
707 if (newstate
< CS_CONNECTING
) {
708 serverconnect
->ConnectionFailed(this);
709 } else if (newstate
== CS_CONNECTED
|| newstate
== CS_WAITFORLOGIN
) {
711 serverconnect
->ConnectionEstablished(this);
717 void CServerSocket::SendPacket(CPacket
* packet
, bool delpacket
, bool controlpacket
, uint32 actualPayloadSize
)
719 m_dwLastTransmission
= GetTickCount();
720 CEMSocket::SendPacket(packet
, delpacket
, controlpacket
, actualPayloadSize
);
724 void CServerSocket::OnHostnameResolved(uint32 ip
) {
728 if (theApp
->ipfilter
->IsFiltered(ip
, true)) {
729 AddLogLineM(true, CFormat( _("Server IP %s (%s) is filtered. Not connecting.") )
730 % Uint32toStringIP(ip
) % cur_server
->GetAddress() );
731 OnConnect(wxSOCKET_INVADDR
);
733 amuleIPV4Address addr
;
736 wxString useObfuscation
;
737 if ( !m_bNoCrypt
&& thePrefs::IsServerCryptLayerTCPRequested() && cur_server
->GetObfuscationPortTCP() != 0 && cur_server
->SupportsObfuscationTCP()){
738 nPort
= cur_server
->GetObfuscationPortTCP();
739 useObfuscation
= _("using protocol obfuscation.");
740 SetConnectionEncryption(true, NULL
, true);
742 nPort
= cur_server
->GetConnPort();
743 SetConnectionEncryption(false, NULL
, true);
748 AddLogLineM(false, CFormat( _("Connecting to %s (%s - %s:%i) %s") )
749 % cur_server
->GetListName()
750 % cur_server
->GetAddress()
751 % cur_server
->GetFullIP()
756 AddDebugLogLineM(false, logServer
, wxT("Server ") + cur_server
->GetAddress() + wxT("(") + Uint32toStringIP(ip
) + wxT(")") + wxString::Format(wxT(" Port %i"), cur_server
->GetConnPort()));
757 Connect(addr
, false);
760 AddLogLineM(true, CFormat( _("Could not solve dns for server %s: Unable to connect!") )
761 % cur_server
->GetAddress() );
762 OnConnect(wxSOCKET_NOHOST
);
766 uint32
CServerSocket::GetServerIP() const
768 return cur_server
? cur_server
->GetIP() : 0;
770 // File_checked_for_headers