Fix compilation with wxWidgets 2.8.12
[amule.git] / src / ServerConnect.h
blobadb23810ee88d0e985f06bb7157b2cfc41417c3a
1 //
2 // This file is part of the aMule Project.
3 //
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 )
6 //
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
9 // respective authors.
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
27 // Client to Server communication
30 #ifndef SERVERCONNECT_H
31 #define SERVERCONNECT_H
34 #include "amuleIPV4Address.h" // Needed for amuleIPV4Address
35 #include "Timer.h" // Needed for CTimer
37 #include <map> // Needed for std::map
39 class CServerList;
40 class CServerSocket;
41 class CServer;
42 class CPacket;
43 class CServerUDPSocket;
45 #define CS_FATALERROR -5
46 #define CS_DISCONNECTED -4
47 #define CS_SERVERDEAD -3
48 #define CS_ERROR -2
49 #define CS_SERVERFULL -1
50 #define CS_NOTCONNECTED 0
51 #define CS_CONNECTING 1
52 #define CS_CONNECTED 2
53 #define CS_WAITFORLOGIN 3
54 #define CS_RETRYCONNECTTIME 30 // seconds
56 typedef std::map<uint32, CServerSocket*> ServerSocketMap;
58 class CServerConnect {
59 public:
60 CServerConnect(CServerList* in_serverlist, amuleIPV4Address &address);
61 ~CServerConnect();
63 void ConnectionFailed(CServerSocket* sender);
64 void ConnectionEstablished(CServerSocket* sender);
66 void ConnectToAnyServer(bool prioSort = true, bool bNoCrypt = false);
67 void ConnectToServer(CServer* toconnect, bool multiconnect = false, bool bNoCrypt = false);
68 void StopConnectionTry();
69 void CheckForTimeout();
71 // safe socket closure and destruction
72 void DestroySocket(CServerSocket* pSck);
73 bool SendPacket(CPacket* packet,bool delpacket = true, CServerSocket* to = 0);
75 // Creteil Begin
76 bool IsUDPSocketAvailable() const { return serverudpsocket != NULL; }
77 // Creteil End
79 bool SendUDPPacket(CPacket* packet,CServer* host, bool delpacket, bool rawpacket = false, uint16 port_offset = 4);
80 bool Disconnect();
81 bool IsConnecting() { return connecting; }
82 bool IsConnected() { return connected; }
83 uint32 GetClientID() { return clientid; }
84 CServer*GetCurrentServer();
85 uint32 clientid;
86 bool IsLowID() { return ::IsLowID(clientid); }
87 void SetClientID(uint32 newid);
88 bool IsLocalServer(uint32 dwIP, uint16 nPort);
89 void TryAnotherConnectionrequest();
90 bool IsSingleConnect() { return singleconnecting; }
91 void KeepConnectionAlive();
93 bool AwaitingTestFromIP(uint32 ip);
94 bool IsConnectedObfuscated() const;
96 /**
97 * Called when a socket has been DNS resolved.
99 * @param socket The socket object requesting DNS resolution.
100 * @param ip The found IP, or zero on error.
102 * Note that 'socket' may or may not refer to an valid object,
103 * and should be checked before being used.
105 void OnServerHostnameResolved(void* socket, uint32 ip);
106 private:
107 bool connecting;
108 bool singleconnecting;
109 bool connected;
110 int8 max_simcons;
111 bool m_bTryObfuscated;
112 bool m_recurseTryAnotherConnectionrequest;
113 CServerSocket* connectedsocket;
114 CServerList* used_list;
115 CServerUDPSocket* serverudpsocket;
117 // list of currently opened sockets
118 typedef std::list<CServerSocket*> SocketsList;
119 SocketsList m_lstOpenSockets;
120 CTimer m_idRetryTimer;
122 ServerSocketMap connectionattemps;
125 #endif // SERVERCONNECT_H
126 // File_checked_for_headers