2 // This file is part of the aMule Project.
4 // Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2011 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_*
52 # include <boost/system/error_code.hpp>
58 //------------------------------------------------------------------------------
59 // CServerSocketHandler
60 //------------------------------------------------------------------------------
62 class CServerSocketHandler
: public wxEvtHandler
65 CServerSocketHandler() {};
69 void ServerSocketHandler(wxSocketEvent
& event
);
74 BEGIN_EVENT_TABLE(CServerSocketHandler
, wxEvtHandler
)
75 EVT_SOCKET(ID_SERVERSOCKET_EVENT
, CServerSocketHandler::ServerSocketHandler
)
78 void CServerSocketHandler::ServerSocketHandler(wxSocketEvent
& event
)
80 CServerSocket
*socket
= dynamic_cast<CServerSocket
*>(event
.GetSocket());
86 if (socket
->IsDestroying()) {
90 switch(event
.GetSocketEvent()) {
91 case wxSOCKET_CONNECTION
:
92 socket
->OnConnect(wxSOCKET_NOERROR
);
95 socket
->OnError(socket
->LastError());
98 socket
->OnReceive(wxSOCKET_NOERROR
);
100 case wxSOCKET_OUTPUT
:
101 socket
->OnSend(wxSOCKET_NOERROR
);
112 // There can be only one. :)
114 static CServerSocketHandler g_serverSocketHandler
;
116 #endif /* !ASIO_SOCKETS */
119 //------------------------------------------------------------------------------
121 //------------------------------------------------------------------------------
123 CServerSocket::CServerSocket(CServerConnect
* in_serverconnect
, const CProxyData
*ProxyData
)
127 serverconnect
= in_serverconnect
;
131 m_bIsDeleting
= false;
134 SetEventHandler(g_serverSocketHandler
, ID_SERVERSOCKET_EVENT
);
137 wxSOCKET_CONNECTION_FLAG
|
138 wxSOCKET_INPUT_FLAG
|
139 wxSOCKET_OUTPUT_FLAG
|
144 m_dwLastTransmission
= 0;
149 CServerSocket::~CServerSocket()
152 // remove event handler...
164 void CServerSocket::OnConnect(int nErrorCode
)
166 switch (nErrorCode
) {
168 case boost::system::errc::success
:
170 case wxSOCKET_NOERROR
:
172 if (cur_server
->HasDynIP()) {
173 uint32 server_ip
= GetPeerInt();
174 cur_server
->SetID(server_ip
);
175 // GetServerByAddress may return NULL, so we must test!
176 // This was the reason why amule would crash when trying to
177 // connect in wxWidgets 2.5.2
178 CServer
*pServer
= theApp
->serverlist
->GetServerByAddress(
179 cur_server
->GetAddress(), cur_server
->GetPort());
181 pServer
->SetID(server_ip
);
183 AddDebugLogLineN(logServer
, wxT("theApp->serverlist->GetServerByAddress() returned NULL"));
187 SetConnectionState(CS_WAITFORLOGIN
);
191 case boost::system::errc::address_in_use
:
192 case boost::system::errc::address_not_available
:
193 case boost::system::errc::bad_address
:
194 case boost::system::errc::connection_refused
:
195 case boost::system::errc::host_unreachable
:
196 case boost::system::errc::invalid_argument
:
197 case boost::system::errc::timed_out
:
199 case wxSOCKET_INVADDR
:
200 case wxSOCKET_NOHOST
:
201 case wxSOCKET_INVPORT
:
202 case wxSOCKET_TIMEDOUT
:
204 m_bIsDeleting
= true;
205 SetConnectionState(CS_SERVERDEAD
);
206 serverconnect
->DestroySocket(this);
210 m_bIsDeleting
= true;
211 SetConnectionState(CS_FATALERROR
);
212 serverconnect
->DestroySocket(this);
219 void CServerSocket::OnReceive(int nErrorCode
)
221 if (connectionstate
!= CS_CONNECTED
&& !serverconnect
->IsConnecting()) {
222 serverconnect
->DestroySocket(this);
225 CEMSocket::OnReceive(nErrorCode
);
226 m_dwLastTransmission
= GetTickCount();
229 bool CServerSocket::ProcessPacket(const uint8_t* packet
, uint32 size
, int8 opcode
)
232 AddDebugLogLineN( logServer
, wxT("Processing Server Packet: ") );
235 case OP_SERVERMESSAGE
: {
236 /* Kry import of lugdunum 16.40 new features */
237 AddDebugLogLineN( logServer
, wxT("Server: OP_SERVERMESSAGE") );
239 theStats::AddDownOverheadServer(size
);
240 char* buffer
= new char[size
-1];
241 memcpy(buffer
,&packet
[2],size
-2);
244 wxString
strMessages(char2unicode(buffer
));
248 // 16.40 servers do not send separate OP_SERVERMESSAGE packets for each line;
249 // instead of this they are sending all text lines with one OP_SERVERMESSAGE packet.
251 wxStringTokenizer
token(strMessages
,wxT("\r\n"),wxTOKEN_DEFAULT
);
253 while (token
.HasMoreTokens()) {
254 wxString message
= token
.GetNextToken();
256 bool bOutputMessage
= true;
257 if (message
.StartsWith(wxT("server version"))) {
258 wxString strVer
= message
.Mid(15,64); // truncate string to avoid misuse by servers in showing ads
260 CServer
* eserver
= theApp
->serverlist
->GetServerByAddress(cur_server
->GetAddress(),cur_server
->GetPort());
262 eserver
->SetVersion(strVer
);
263 Notify_ServerRefresh(eserver
);
265 } else if (message
.StartsWith(wxT("ERROR"))) {
266 CServer
* pServer
= theApp
->serverlist
->GetServerByAddress(cur_server
->GetAddress(),cur_server
->GetPort());
269 servername
= pServer
->GetListName();
271 servername
= _("Server");
273 AddLogLineN(CFormat( _("ERROR: %s (%s) - %s") )
275 % Uint32_16toStringIP_Port(cur_server
->GetIP(), cur_server
->GetPort())
276 % message
.Mid(5,message
.Len()).Trim(wxT(" :")));
277 bOutputMessage
= false;
279 } else if (message
.StartsWith(wxT("WARNING"))) {
281 CServer
* pServer
= theApp
->serverlist
->GetServerByAddress(cur_server
->GetAddress(),cur_server
->GetPort());
284 servername
= pServer
->GetListName();
286 servername
= _("Server");
288 AddLogLineN(CFormat( _("WARNING: %s (%s) - %s") )
290 % Uint32_16toStringIP_Port(cur_server
->GetIP(), cur_server
->GetPort())
291 % message
.Mid(5,message
.Len()).Trim(wxT(" :")));
293 bOutputMessage
= false;
296 if (message
.Find(wxT("[emDynIP: ")) != (-1) && message
.Find(wxT("]")) != (-1) && message
.Find(wxT("[emDynIP: ")) < message
.Find(wxT("]"))){
297 wxString dynip
= message
.Mid(message
.Find(wxT("[emDynIP: "))+10,message
.Find(wxT("]")) - (message
.Find(wxT("[emDynIP: "))+10));
298 dynip
.Trim(wxT(" "));
299 if ( dynip
.Length() && dynip
.Length() < 51){
300 CServer
* eserver
= theApp
->serverlist
->GetServerByAddress(cur_server
->GetAddress(),cur_server
->GetPort());
302 eserver
->SetDynIP(dynip
);
303 cur_server
->SetDynIP(dynip
);
304 Notify_ServerRefresh(eserver
);
309 if (bOutputMessage
) {
310 theApp
->AddServerMessageLine(message
);
316 AddDebugLogLineN(logServer
, wxT("Server: OP_IDCHANGE"));
318 theStats::AddDownOverheadServer(size
);
320 if (size
< 4 /* uint32 (ID)*/) {
321 throw wxString(wxT("Corrupt or invalid loginanswer from server received"));
324 CMemFile
data(packet
, size
);
326 uint32 new_id
= data
.ReadUInt32();
328 // save TCP flags in 'cur_server'
329 wxASSERT(cur_server
);
330 CServer
* pServer
= NULL
;
333 uint32 rport
= cur_server
->GetConnPort();
334 pServer
= theApp
->serverlist
->GetServerByAddress(cur_server
->GetAddress(), rport
);
335 if (size
>= 4+4 /* uint32 (ID) + uint32 (TCP flags)*/) {
336 cur_server
->SetTCPFlags(data
.ReadUInt32());
337 if (size
>= 4+4+4 /* uint32 (ID) + uint32 (TCP flags) + uint32 (aux port) */) {
338 // aux port login : we should use the 'standard' port of this server to advertize to other clients
339 ConnPort
= data
.ReadUInt32();
340 cur_server
->SetPort(ConnPort
);
341 if (cur_server
->GetAuxPortsList().IsEmpty()) {
342 cur_server
->SetAuxPortsList(CFormat(wxT("%u")) % rport
);
346 cur_server
->SetTCPFlags(0);
348 // copy TCP flags into the server in the server list
350 pServer
->SetTCPFlags(cur_server
->GetTCPFlags());
352 pServer
->SetPort(ConnPort
);
353 if (pServer
->GetAuxPortsList().IsEmpty()) {
354 pServer
->SetAuxPortsList(CFormat(wxT("%u")) % pServer
->GetConnPort());
356 Notify_ServerRefresh(pServer
);
357 Notify_ServerUpdateED2KInfo();
362 uint32 dwServerReportedIP
= 0;
363 if (size
>= 4 + 4 + 4 + 4 + 4 /* All of the above + reported ip + obfuscation port */) {
364 dwServerReportedIP
= data
.ReadUInt32();
365 if (::IsLowID(dwServerReportedIP
)){
367 dwServerReportedIP
= 0;
369 wxASSERT( dwServerReportedIP
== new_id
|| ::IsLowID(new_id
) );
370 uint32 dwObfuscationTCPPort
= data
.ReadUInt32();
371 if (dwObfuscationTCPPort
!= 0) {
372 if (cur_server
!= NULL
) {
373 cur_server
->SetObfuscationPortTCP(dwObfuscationTCPPort
);
375 if (pServer
!= NULL
) {
376 pServer
->SetObfuscationPortTCP(dwObfuscationTCPPort
);
382 uint8 state
= thePrefs::GetSmartIdState();
386 thePrefs::SetSmartIdState(0);
388 thePrefs::SetSmartIdState(state
);
393 if(thePrefs::GetSmartIdCheck()) {
394 if (!IsLowID(new_id
)) {
395 thePrefs::SetSmartIdState(1);
397 uint8 state
= thePrefs::GetSmartIdState();
401 thePrefs::SetSmartIdState(0);
403 thePrefs::SetSmartIdState(state
);
410 // we need to know our client when sending our shared files (done indirectly on SetConnectionState)
412 serverconnect
->SetClientID(new_id
);
414 if (::IsLowID(new_id
) && dwServerReportedIP
!= 0) {
415 theApp
->SetPublicIP(dwServerReportedIP
);
418 if (connectionstate
!= CS_CONNECTED
) {
419 AddDebugLogLineN(logServer
, wxT("Connected"));
421 SetConnectionState(CS_CONNECTED
);
422 theApp
->OnlineSig(); // Added By Bouc7
425 theApp
->ShowConnectionState();
427 AddLogLineN(CFormat(_("New clientid is %u")) % new_id
);
428 if (::IsLowID(new_id
)) {
429 AddLogLineC(_("WARNING: You have received Low-ID!"));
430 AddLogLineN(_("\tMost likely this is because you're behind a firewall or router."));
431 AddLogLineN(_("\tFor more information, please refer to http://wiki.amule.org"));
434 theApp
->downloadqueue
->ResetLocalServerRequests();
437 case OP_SEARCHRESULT
: {
438 AddDebugLogLineN(logServer
, wxT("Server: OP_SEARCHRESULT"));
440 theStats::AddDownOverheadServer(size
);
441 CServer
* cur_srv
= (serverconnect
) ?
442 serverconnect
->GetCurrentServer() : NULL
;
443 theApp
->searchlist
->ProcessSearchAnswer(
446 true /*(cur_srv && cur_srv->GetUnicodeSupport())*/,
447 cur_srv
? cur_srv
->GetIP() : 0,
448 cur_srv
? cur_srv
->GetPort() : 0);
449 theApp
->searchlist
->LocalSearchEnd();
452 case OP_FOUNDSOURCES_OBFU
:
453 case OP_FOUNDSOURCES
: {
454 AddDebugLogLineN(logServer
, CFormat(wxT("ServerMsg - OP_FoundSources; sources = %u")) % packet
[16]);
455 theStats::AddDownOverheadServer(size
);
456 CMemFile
sources(packet
,size
);
457 CMD4Hash fileid
= sources
.ReadHash();
458 if (CPartFile
* file
= theApp
->downloadqueue
->GetFileByID(fileid
)) {
459 file
->AddSources(sources
, cur_server
->GetIP(), cur_server
->GetPort(), SF_LOCAL_SERVER
, (opcode
== OP_FOUNDSOURCES_OBFU
));
461 AddDebugLogLineN(logServer
, wxT("Sources received for unknown file: ") + fileid
.Encode());
465 case OP_SERVERSTATUS
: {
466 AddDebugLogLineN(logServer
, wxT("Server: OP_SERVERSTATUS"));
467 // FIXME some statuspackets have a different size -> why? structur?
469 throw wxString(wxT("Invalid server status packet"));
471 CServer
* update
= theApp
->serverlist
->GetServerByAddress(cur_server
->GetAddress(), cur_server
->GetPort());
473 CMemFile
data(packet
, size
);
474 update
->SetUserCount(data
.ReadUInt32());
475 update
->SetFileCount(data
.ReadUInt32());
476 Notify_ServerRefresh( update
);
477 theApp
->ShowUserCount();
482 case OP_SERVERIDENT
: {
483 AddDebugLogLineN(logServer
, wxT("Server: OP_SERVERIDENT"));
485 theStats::AddDownOverheadServer(size
);
487 AddLogLineN(_("Unknown server info received! - too short"));
488 // throw wxString(wxT("Unknown server info received!"));
491 CServer
* update
= theApp
->serverlist
->GetServerByAddress(cur_server
->GetAddress(),cur_server
->GetPort());
493 CMemFile
data(packet
,size
);
494 CMD4Hash hash
= data
.ReadHash();
495 if (RawPeekUInt32(hash
.GetHash()) == 0x2A2A2A2A){ // No endian problem here
496 const wxString
& rstrVersion
= update
->GetVersion();
497 if (!rstrVersion
.IsEmpty()) {
498 update
->SetVersion(wxT("eFarm ") + rstrVersion
);
500 update
->SetVersion(wxT("eFarm"));
504 /*uint32 nServerIP = */data
.ReadUInt32();
505 /*uint16 nServerPort = */data
.ReadUInt16();
507 uint32 nTags
= data
.ReadUInt32();
508 for (uint32 i
= 0; i
< nTags
; i
++){
509 CTag
tag(data
, update
->GetUnicodeSupport());
510 if (tag
.GetNameID() == ST_SERVERNAME
){
511 update
->SetListName(tag
.GetStr());
512 } else if (tag
.GetNameID() == ST_DESCRIPTION
){
513 update
->SetDescription(tag
.GetStr());
514 } // No more known tags from server
517 theApp
->ShowConnectionState();
518 Notify_ServerRefresh(update
);
522 // tecxx 1609 2002 - add server's serverlist to own serverlist
523 case OP_SERVERLIST
: {
524 AddDebugLogLineN(logServer
, wxT("Server: OP_SERVERLIST"));
526 CMemFile
* servers
= new CMemFile(packet
,size
);
527 uint8 count
= servers
->ReadUInt8();
528 if (((int32
)(count
*6 + 1) > size
)) {
533 uint32 ip
= servers
->ReadUInt32();
534 uint16 port
= servers
->ReadUInt16();
535 CServer
* srv
= new CServer(
537 Uint32toStringIP(ip
)); // Ip
538 srv
->SetListName(srv
->GetFullIP());
539 if (!theApp
->AddServer(srv
)) {
548 AddLogLineN(CFormat(wxPLURAL("Received %d new server", "Received %d new servers", addcount
)) % addcount
);
550 theApp
->serverlist
->SaveServerMet();
551 AddLogLineN(_("Saving of server-list completed."));
554 case OP_CALLBACKREQUESTED
: {
555 AddDebugLogLineN(logServer
, wxT("Server: OP_CALLBACKREQUESTED"));
557 theStats::AddDownOverheadServer(size
);
559 CMemFile
data(packet
,size
);
560 uint32 dwIP
= data
.ReadUInt32();
561 uint16 nPort
= data
.ReadUInt16();
563 uint8 byCryptOptions
= 0;
564 CMD4Hash achUserHash
;
566 byCryptOptions
= data
.ReadUInt8();;
567 achUserHash
= data
.ReadHash();
570 CUpDownClient
* client
= theApp
->clientlist
->FindClientByIP(dwIP
,nPort
);
573 client
= new CUpDownClient(nPort
,dwIP
,0,0,0, true, true);
574 theApp
->clientlist
->AddClient(client
);
576 if (size
>= 23 && client
->HasValidHash()){
577 if (client
->GetUserHash() != achUserHash
){
578 AddDebugLogLineN(logServer
, wxT("Reported Userhash from OP_CALLBACKREQUESTED differs with our stored hash"));
579 // disable crypt support since we dont know which hash is true
580 client
->SetCryptLayerRequest(false);
581 client
->SetCryptLayerSupport(false);
582 client
->SetCryptLayerRequires(false);
584 client
->SetConnectOptions(byCryptOptions
, true, false);
586 } else if (size
>= 23) {
587 client
->SetUserHash(achUserHash
);
588 client
->SetConnectOptions(byCryptOptions
, true, false);
591 client
->TryToConnect();
595 case OP_CALLBACK_FAIL
: {
596 AddDebugLogLineN(logServer
, wxT("Server: OP_CALLBACK_FAIL"));
600 AddDebugLogLineN(logServer
, wxT("Server: OP_REJECT"));
601 AddLogLineN(_("Server rejected last command"));
605 AddDebugLogLineN(logPacketErrors
, CFormat(wxT("Unknown server packet with OPcode %x")) % opcode
);
608 } catch (const CInvalidPacket
& e
) {
609 AddLogLineN(CFormat( _("Bogus packet received from server: %s") ) % e
.what());
610 } catch (const CEOFException
& e
) {
611 AddLogLineN(CFormat( _("Bogus packet received from server: %s") ) % e
.what());
612 } catch (const wxString
& error
) {
613 AddLogLineN(CFormat( _("Unhandled error while processing packet from server: %s") ) % error
);
616 // Don't disconnect because of wrong sources.
617 if (opcode
==OP_SEARCHRESULT
|| opcode
==OP_FOUNDSOURCES
) {
621 SetConnectionState(CS_DISCONNECTED
);
625 void CServerSocket::ConnectToServer(CServer
* server
, bool bNoCrypt
)
627 AddDebugLogLineN(logServer
, wxT("Trying to connect"));
635 cur_server
= new CServer(server
);
637 m_bNoCrypt
= bNoCrypt
;
639 SetConnectionState(CS_CONNECTING
);
641 info
= cur_server
->GetListName();
643 // This must be used if we want to reverse-check the addr of the server
644 if (cur_server
->HasDynIP() || !cur_server
->GetIP()) {
646 // Send it to solving thread.
647 CAsyncDNS
* dns
= new CAsyncDNS(server
->GetAddress(), DNS_SERVER_CONNECT
, theApp
, this);
649 if ( dns
->Create() == wxTHREAD_NO_ERROR
) {
650 if ( dns
->Run() != wxTHREAD_NO_ERROR
) {
652 AddLogLineN(CFormat( _("Cannot create DNS solving thread for connecting to %s") ) % cur_server
->GetAddress());
656 AddLogLineN(CFormat( _("Cannot create DNS solving thread for connecting to %s") ) % cur_server
->GetAddress());
659 // Nothing to solve, we already have the IP
660 OnHostnameResolved(cur_server
->GetIP());
665 void CServerSocket::OnError(int DEBUG_ONLY(nErrorCode
))
667 AddDebugLogLineN(logServer
, CFormat(wxT("Error in serversocket: %s(%s:%i): %u"))
668 % cur_server
->GetListName() % cur_server
->GetFullIP() % cur_server
->GetPort() % nErrorCode
);
669 SetConnectionState(CS_DISCONNECTED
);
673 bool CServerSocket::PacketReceived(CPacket
* packet
)
675 AddDebugLogLineN(logServer
, CFormat(wxT("Server: Packet Received: Prot %x, Opcode %x, Length %u")) % packet
->GetProtocol() % packet
->GetOpCode() % packet
->GetPacketSize());
677 if (packet
->GetProtocol() == OP_PACKEDPROT
) {
678 if (!packet
->UnPackPacket(250000)){
679 AddDebugLogLineN(logZLib
, CFormat(wxT("Failed to decompress server TCP packet: protocol=0x%02x opcode=0x%02x size=%u"))
680 % packet
->GetProtocol() % packet
->GetOpCode() % packet
->GetPacketSize());
681 theStats::AddDownOverheadServer(packet
->GetPacketSize());
685 packet
->SetProtocol(OP_EDONKEYPROT
);
688 if (packet
->GetProtocol() == OP_EDONKEYPROT
) {
689 ProcessPacket(packet
->GetDataBuffer(), packet
->GetPacketSize(), packet
->GetOpCode());
691 AddDebugLogLineN(logServer
, CFormat(wxT("Received server TCP packet with unknown protocol: protocol=0x%02x opcode=0x%02x size=%u"))
692 % packet
->GetProtocol() % packet
->GetOpCode() % packet
->GetPacketSize());
693 theStats::AddDownOverheadServer(packet
->GetPacketSize());
700 void CServerSocket::OnClose(int WXUNUSED(nErrorCode
))
702 CEMSocket::OnClose(0);
704 switch (connectionstate
) {
705 case CS_WAITFORLOGIN
: SetConnectionState(CS_SERVERFULL
); break;
706 case CS_CONNECTED
: SetConnectionState(CS_DISCONNECTED
); break;
707 default: SetConnectionState(CS_NOTCONNECTED
);
710 serverconnect
->DestroySocket(this);
713 void CServerSocket::SetConnectionState(sint8 newstate
)
715 connectionstate
= newstate
;
716 if (newstate
< CS_CONNECTING
) {
717 serverconnect
->ConnectionFailed(this);
718 } else if (newstate
== CS_CONNECTED
|| newstate
== CS_WAITFORLOGIN
) {
720 serverconnect
->ConnectionEstablished(this);
726 void CServerSocket::SendPacket(CPacket
* packet
, bool delpacket
, bool controlpacket
, uint32 actualPayloadSize
)
728 m_dwLastTransmission
= GetTickCount();
729 CEMSocket::SendPacket(packet
, delpacket
, controlpacket
, actualPayloadSize
);
733 void CServerSocket::OnHostnameResolved(uint32 ip
) {
737 if (theApp
->ipfilter
->IsFiltered(ip
, true)) {
738 AddLogLineC(CFormat( _("Server IP %s (%s) is filtered. Not connecting.") )
739 % Uint32toStringIP(ip
) % cur_server
->GetAddress() );
741 OnConnect(boost::system::errc::invalid_argument
);
743 OnConnect(wxSOCKET_INVADDR
);
746 amuleIPV4Address addr
;
749 wxString useObfuscation
;
750 if ( !m_bNoCrypt
&& thePrefs::IsServerCryptLayerTCPRequested() && cur_server
->GetObfuscationPortTCP() != 0 && cur_server
->SupportsObfuscationTCP()){
751 nPort
= cur_server
->GetObfuscationPortTCP();
752 useObfuscation
= _("using protocol obfuscation.");
753 SetConnectionEncryption(true, NULL
, true);
755 nPort
= cur_server
->GetConnPort();
756 SetConnectionEncryption(false, NULL
, true);
761 AddLogLineN(CFormat( _("Connecting to %s (%s - %s:%i) %s") )
762 % cur_server
->GetListName()
763 % cur_server
->GetAddress()
764 % cur_server
->GetFullIP()
769 AddDebugLogLineN(logServer
, CFormat(wxT("Server %s(%s) Port %i"))
770 % cur_server
->GetAddress() % Uint32toStringIP(ip
) % cur_server
->GetConnPort());
771 Connect(addr
, false);
774 AddLogLineC(CFormat( _("Could not solve dns for server %s: Unable to connect!") )
775 % cur_server
->GetAddress() );
777 OnConnect(boost::system::errc::host_unreachable
);
779 OnConnect(wxSOCKET_NOHOST
);
784 uint32
CServerSocket::GetServerIP() const
786 return cur_server
? cur_server
->GetIP() : 0;
788 // File_checked_for_headers