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 AddDebugLogLineN(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 AddDebugLogLineN( logServer
, wxT("Processing Server Packet: ") );
221 case OP_SERVERMESSAGE
: {
222 /* Kry import of lugdunum 16.40 new features */
223 AddDebugLogLineN( 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 AddLogLineN(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 AddLogLineN(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 AddDebugLogLineN(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(CFormat(wxT("%u")) % rport
);
332 cur_server
->SetTCPFlags(0);
334 // copy TCP flags into the server in the server list
336 pServer
->SetTCPFlags(cur_server
->GetTCPFlags());
338 pServer
->SetPort(ConnPort
);
339 if (pServer
->GetAuxPortsList().IsEmpty()) {
340 pServer
->SetAuxPortsList(CFormat(wxT("%u")) % pServer
->GetConnPort());
342 Notify_ServerRefresh(pServer
);
343 Notify_ServerUpdateED2KInfo();
348 uint32 dwServerReportedIP
= 0;
349 uint32 dwObfuscationTCPPort
= 0;
350 if (size
>= 4 + 4 + 4 + 4 + 4 /* All of the above + reported ip + obfuscation port */) {
351 dwServerReportedIP
= data
.ReadUInt32();
352 if (::IsLowID(dwServerReportedIP
)){
354 dwServerReportedIP
= 0;
356 wxASSERT( dwServerReportedIP
== new_id
|| ::IsLowID(new_id
) );
357 dwObfuscationTCPPort
= data
.ReadUInt32();
358 if (cur_server
!= NULL
&& dwObfuscationTCPPort
!= 0) {
359 cur_server
->SetObfuscationPortTCP((uint16
)dwObfuscationTCPPort
);
362 if (pServer
!= NULL
&& dwObfuscationTCPPort
!= 0) {
363 pServer
->SetObfuscationPortTCP((uint16
)dwObfuscationTCPPort
);
368 uint8 state
= thePrefs::GetSmartIdState();
372 thePrefs::SetSmartIdState(0);
374 thePrefs::SetSmartIdState(state
);
379 if(thePrefs::GetSmartIdCheck()) {
380 if (!IsLowID(new_id
)) {
381 thePrefs::SetSmartIdState(1);
383 uint8 state
= thePrefs::GetSmartIdState();
387 thePrefs::SetSmartIdState(0);
389 thePrefs::SetSmartIdState(state
);
396 // we need to know our client when sending our shared files (done indirectly on SetConnectionState)
398 serverconnect
->SetClientID(new_id
);
400 if (::IsLowID(new_id
) && dwServerReportedIP
!= 0) {
401 theApp
->SetPublicIP(dwServerReportedIP
);
404 if (connectionstate
!= CS_CONNECTED
) {
405 AddDebugLogLineN(logServer
, wxT("Connected"));
407 SetConnectionState(CS_CONNECTED
);
408 theApp
->OnlineSig(); // Added By Bouc7
411 theApp
->ShowConnectionState();
413 AddLogLineN(CFormat(_("New clientid is %u")) % new_id
);
414 if (::IsLowID(new_id
)) {
415 AddLogLineC(_("WARNING: You have received Low-ID!"));
416 AddLogLineN(_("\tMost likely this is because you're behind a firewall or router."));
417 AddLogLineN(_("\tFor more information, please refer to http://wiki.amule.org"));
420 theApp
->downloadqueue
->ResetLocalServerRequests();
423 case OP_SEARCHRESULT
: {
424 AddDebugLogLineN(logServer
, wxT("Server: OP_SEARCHRESULT"));
426 theStats::AddDownOverheadServer(size
);
427 CServer
* cur_srv
= (serverconnect
) ?
428 serverconnect
->GetCurrentServer() : NULL
;
429 theApp
->searchlist
->ProcessSearchAnswer(
432 true /*(cur_srv && cur_srv->GetUnicodeSupport())*/,
433 cur_srv
? cur_srv
->GetIP() : 0,
434 cur_srv
? cur_srv
->GetPort() : 0);
435 theApp
->searchlist
->LocalSearchEnd();
438 case OP_FOUNDSOURCES_OBFU
:
439 case OP_FOUNDSOURCES
: {
440 AddDebugLogLineN(logServer
, CFormat(wxT("ServerMsg - OP_FoundSources; sources = %u")) % packet
[16]);
441 theStats::AddDownOverheadServer(size
);
442 CMemFile
sources(packet
,size
);
443 CMD4Hash fileid
= sources
.ReadHash();
444 if (CPartFile
* file
= theApp
->downloadqueue
->GetFileByID(fileid
)) {
445 file
->AddSources(sources
, cur_server
->GetIP(), cur_server
->GetPort(), SF_LOCAL_SERVER
, (opcode
== OP_FOUNDSOURCES_OBFU
));
447 AddDebugLogLineN(logServer
, wxT("Sources received for unknown file: ") + fileid
.Encode());
451 case OP_SERVERSTATUS
: {
452 AddDebugLogLineN(logServer
, wxT("Server: OP_SERVERSTATUS"));
453 // FIXME some statuspackets have a different size -> why? structur?
455 throw wxString(wxT("Invalid server status packet"));
458 CServer
* update
= theApp
->serverlist
->GetServerByAddress(cur_server
->GetAddress(), cur_server
->GetPort());
460 CMemFile
data(packet
, size
);
461 update
->SetUserCount(data
.ReadUInt32());
462 update
->SetFileCount(data
.ReadUInt32());
463 Notify_ServerRefresh( update
);
464 theApp
->ShowUserCount();
469 case OP_SERVERIDENT
: {
470 AddDebugLogLineN(logServer
, wxT("Server: OP_SERVERIDENT"));
472 theStats::AddDownOverheadServer(size
);
474 AddLogLineN(_("Unknown server info received! - too short"));
475 // throw wxString(wxT("Unknown server info received!"));
478 CServer
* update
= theApp
->serverlist
->GetServerByAddress(cur_server
->GetAddress(),cur_server
->GetPort());
480 CMemFile
data(packet
,size
);
481 CMD4Hash hash
= data
.ReadHash();
482 if (RawPeekUInt32(hash
.GetHash()) == 0x2A2A2A2A){ // No endian problem here
483 const wxString
& rstrVersion
= update
->GetVersion();
484 if (!rstrVersion
.IsEmpty()) {
485 update
->SetVersion(wxT("eFarm ") + rstrVersion
);
487 update
->SetVersion(wxT("eFarm"));
491 /*uint32 nServerIP = */data
.ReadUInt32();
492 /*uint16 nServerPort = */data
.ReadUInt16();
494 uint32 nTags
= data
.ReadUInt32();
495 for (uint32 i
= 0; i
< nTags
; i
++){
496 CTag
tag(data
, update
->GetUnicodeSupport());
497 if (tag
.GetNameID() == ST_SERVERNAME
){
498 update
->SetListName(tag
.GetStr());
499 } else if (tag
.GetNameID() == ST_DESCRIPTION
){
500 update
->SetDescription(tag
.GetStr());
501 } // No more known tags from server
504 theApp
->ShowConnectionState();
505 Notify_ServerRefresh(update
);
509 // tecxx 1609 2002 - add server's serverlist to own serverlist
510 case OP_SERVERLIST
: {
511 AddDebugLogLineN(logServer
, wxT("Server: OP_SERVERLIST"));
513 CMemFile
* servers
= new CMemFile(packet
,size
);
514 uint8 count
= servers
->ReadUInt8();
515 if (((int32
)(count
*6 + 1) > size
)) {
520 uint32 ip
= servers
->ReadUInt32();
521 uint16 port
= servers
->ReadUInt16();
522 CServer
* srv
= new CServer(
524 Uint32toStringIP(ip
)); // Ip
525 srv
->SetListName(srv
->GetFullIP());
526 if (!theApp
->AddServer(srv
)) {
535 AddLogLineN(CFormat(wxPLURAL("Received %d new server", "Received %d new servers", addcount
)) % addcount
);
537 theApp
->serverlist
->SaveServerMet();
538 AddLogLineN(_("Saving of server-list completed."));
541 case OP_CALLBACKREQUESTED
: {
542 AddDebugLogLineN(logServer
, wxT("Server: OP_CALLBACKREQUESTED"));
544 theStats::AddDownOverheadServer(size
);
546 CMemFile
data(packet
,size
);
547 uint32 dwIP
= data
.ReadUInt32();
548 uint16 nPort
= data
.ReadUInt16();
550 uint8 byCryptOptions
= 0;
551 CMD4Hash achUserHash
;
553 byCryptOptions
= data
.ReadUInt8();;
554 achUserHash
= data
.ReadHash();
557 CUpDownClient
* client
= theApp
->clientlist
->FindClientByIP(dwIP
,nPort
);
560 client
= new CUpDownClient(nPort
,dwIP
,0,0,0, true, true);
561 theApp
->clientlist
->AddClient(client
);
563 if (size
>= 23 && client
->HasValidHash()){
564 if (client
->GetUserHash() != achUserHash
){
565 AddDebugLogLineN(logServer
, wxT("Reported Userhash from OP_CALLBACKREQUESTED differs with our stored hash"));
566 // disable crypt support since we dont know which hash is true
567 client
->SetCryptLayerRequest(false);
568 client
->SetCryptLayerSupport(false);
569 client
->SetCryptLayerRequires(false);
571 client
->SetConnectOptions(byCryptOptions
, true, false);
573 } else if (size
>= 23) {
574 client
->SetUserHash(achUserHash
);
575 client
->SetConnectOptions(byCryptOptions
, true, false);
578 client
->TryToConnect();
582 case OP_CALLBACK_FAIL
: {
583 AddDebugLogLineN(logServer
, wxT("Server: OP_CALLBACK_FAIL"));
587 AddDebugLogLineN(logServer
, wxT("Server: OP_REJECT"));
588 AddLogLineN(_("Server rejected last command"));
592 AddDebugLogLineN(logPacketErrors
, CFormat(wxT("Unknown server packet with OPcode %x")) % opcode
);
595 } catch (const CInvalidPacket
& e
) {
596 AddLogLineN(CFormat( _("Bogus packet received from server: %s") ) % e
.what());
597 } catch (const CEOFException
& e
) {
598 AddLogLineN(CFormat( _("Bogus packet received from server: %s") ) % e
.what());
599 } catch (const wxString
& error
) {
600 AddLogLineN(CFormat( _("Unhandled error while processing packet from server: %s") ) % error
);
603 // Don't disconnect because of wrong sources.
604 if (opcode
==OP_SEARCHRESULT
|| opcode
==OP_FOUNDSOURCES
) {
608 SetConnectionState(CS_DISCONNECTED
);
612 void CServerSocket::ConnectToServer(CServer
* server
, bool bNoCrypt
)
614 AddDebugLogLineN(logServer
, wxT("Trying to connect"));
622 cur_server
= new CServer(server
);
624 m_bNoCrypt
= bNoCrypt
;
626 SetConnectionState(CS_CONNECTING
);
628 info
= cur_server
->GetListName();
630 // This must be used if we want to reverse-check the addr of the server
631 if (cur_server
->HasDynIP() || !cur_server
->GetIP()) {
633 // Send it to solving thread.
634 CAsyncDNS
* dns
= new CAsyncDNS(server
->GetAddress(), DNS_SERVER_CONNECT
, theApp
, this);
636 if ( dns
->Create() == wxTHREAD_NO_ERROR
) {
637 if ( dns
->Run() != wxTHREAD_NO_ERROR
) {
639 AddLogLineN(CFormat( _("Cannot create DNS solving thread for connecting to %s") ) % cur_server
->GetAddress());
643 AddLogLineN(CFormat( _("Cannot create DNS solving thread for connecting to %s") ) % cur_server
->GetAddress());
646 // Nothing to solve, we already have the IP
647 OnHostnameResolved(cur_server
->GetIP());
652 void CServerSocket::OnError(wxSocketError nErrorCode
)
654 AddDebugLogLineN(logServer
, CFormat(wxT("Error in serversocket: %s(%s:%i): %u"))
655 % cur_server
->GetListName() % cur_server
->GetFullIP() % cur_server
->GetPort() % (int)nErrorCode
);
656 SetConnectionState(CS_DISCONNECTED
);
660 bool CServerSocket::PacketReceived(CPacket
* packet
)
662 AddDebugLogLineN(logServer
, CFormat(wxT("Server: Packet Received: Prot %x, Opcode %x, Length %u")) % packet
->GetProtocol() % packet
->GetOpCode() % packet
->GetPacketSize());
664 if (packet
->GetProtocol() == OP_PACKEDPROT
) {
665 if (!packet
->UnPackPacket(250000)){
666 AddDebugLogLineN(logZLib
, CFormat(wxT("Failed to decompress server TCP packet: protocol=0x%02x opcode=0x%02x size=%u"))
667 % packet
->GetProtocol() % packet
->GetOpCode() % packet
->GetPacketSize());
668 theStats::AddDownOverheadServer(packet
->GetPacketSize());
672 packet
->SetProtocol(OP_EDONKEYPROT
);
675 if (packet
->GetProtocol() == OP_EDONKEYPROT
) {
676 ProcessPacket(packet
->GetDataBuffer(), packet
->GetPacketSize(), packet
->GetOpCode());
678 AddDebugLogLineN(logServer
, CFormat(wxT("Received server TCP packet with unknown protocol: protocol=0x%02x opcode=0x%02x size=%u"))
679 % packet
->GetProtocol() % packet
->GetOpCode() % packet
->GetPacketSize());
680 theStats::AddDownOverheadServer(packet
->GetPacketSize());
687 void CServerSocket::OnClose(wxSocketError
WXUNUSED(nErrorCode
))
689 CEMSocket::OnClose(0);
691 switch (connectionstate
) {
692 case CS_WAITFORLOGIN
: SetConnectionState(CS_SERVERFULL
); break;
693 case CS_CONNECTED
: SetConnectionState(CS_DISCONNECTED
); break;
694 default: SetConnectionState(CS_NOTCONNECTED
);
697 serverconnect
->DestroySocket(this);
700 void CServerSocket::SetConnectionState(sint8 newstate
)
702 connectionstate
= newstate
;
703 if (newstate
< CS_CONNECTING
) {
704 serverconnect
->ConnectionFailed(this);
705 } else if (newstate
== CS_CONNECTED
|| newstate
== CS_WAITFORLOGIN
) {
707 serverconnect
->ConnectionEstablished(this);
713 void CServerSocket::SendPacket(CPacket
* packet
, bool delpacket
, bool controlpacket
, uint32 actualPayloadSize
)
715 m_dwLastTransmission
= GetTickCount();
716 CEMSocket::SendPacket(packet
, delpacket
, controlpacket
, actualPayloadSize
);
720 void CServerSocket::OnHostnameResolved(uint32 ip
) {
724 if (theApp
->ipfilter
->IsFiltered(ip
, true)) {
725 AddLogLineC(CFormat( _("Server IP %s (%s) is filtered. Not connecting.") )
726 % Uint32toStringIP(ip
) % cur_server
->GetAddress() );
727 OnConnect(wxSOCKET_INVADDR
);
729 amuleIPV4Address addr
;
732 wxString useObfuscation
;
733 if ( !m_bNoCrypt
&& thePrefs::IsServerCryptLayerTCPRequested() && cur_server
->GetObfuscationPortTCP() != 0 && cur_server
->SupportsObfuscationTCP()){
734 nPort
= cur_server
->GetObfuscationPortTCP();
735 useObfuscation
= _("using protocol obfuscation.");
736 SetConnectionEncryption(true, NULL
, true);
738 nPort
= cur_server
->GetConnPort();
739 SetConnectionEncryption(false, NULL
, true);
744 AddLogLineN(CFormat( _("Connecting to %s (%s - %s:%i) %s") )
745 % cur_server
->GetListName()
746 % cur_server
->GetAddress()
747 % cur_server
->GetFullIP()
752 AddDebugLogLineN(logServer
, CFormat(wxT("Server %s(%s) Port %i"))
753 % cur_server
->GetAddress() % Uint32toStringIP(ip
) % cur_server
->GetConnPort());
754 Connect(addr
, false);
757 AddLogLineC(CFormat( _("Could not solve dns for server %s: Unable to connect!") )
758 % cur_server
->GetAddress() );
759 OnConnect(wxSOCKET_NOHOST
);
763 uint32
CServerSocket::GetServerIP() const
765 return cur_server
? cur_server
->GetIP() : 0;
767 // File_checked_for_headers