Upstream tarball 9882
[amule.git] / src / Server.h
bloba2702502623436b93c600424367bbd47db932b52
1 //
2 // This file is part of the aMule Project.
3 //
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 )
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.
20 //
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 #ifndef SERVER_H
27 #define SERVER_H
29 #include "Tag.h"
30 #include "OtherStructs.h"
32 #include <protocol/ed2k/Client2Server/TCP.h>
33 #include <protocol/ed2k/Client2Server/UDP.h>
35 #ifdef CLIENT_GUI
36 #include <ec/cpp/ECSpecialTags.h>
37 #endif
39 class CFileDataIO;
41 // Server priority
42 #define SRV_PR_LOW 2
43 #define SRV_PR_NORMAL 0
44 #define SRV_PR_HIGH 1
45 // Server priority max and min values
46 #define SRV_PR_MAX 2
47 #define SRV_PR_MID 1
48 #define SRV_PR_MIN 0
50 class CServer
52 public:
53 CServer(ServerMet_Struct* in_data);
54 CServer(uint16 in_port, const wxString i_addr);
55 CServer(CServer* pOld);
57 #ifdef CLIENT_GUI
58 CServer(CEC_Server_Tag *);
59 #endif
61 ~CServer();
62 void AddTag(CTag* in_tag) {m_taglist.push_back(in_tag);}
63 const wxString &GetListName() const {return listname;}
64 const wxString &GetFullIP() const {return ipfull;}
66 const wxString &GetAddress() const {
67 if (!dynip.IsEmpty()) {
68 return dynip;
69 } else {
70 return ipfull;
74 // the official port
75 uint16 GetPort() const {return realport ? realport : port;}
76 // the connection port
77 uint16 GetConnPort() const {return port;}
78 void SetPort(uint32 val) {realport = val;}
79 bool AddTagFromFile(CFileDataIO* servermet);
80 void SetListName(const wxString& newname);
81 void SetDescription(const wxString& newdescription);
82 uint32 GetIP() const {return ip;}
83 uint32 GetFiles() const {return files;}
84 uint32 GetUsers() const {return users;}
85 const wxString &GetDescription() const {return description;}
86 uint32 GetPing() const {return ping;}
87 uint32 GetPreferences() const {return preferences;}
88 uint32 GetMaxUsers() const {return maxusers;}
89 void SetMaxUsers(uint32 in_maxusers) {maxusers = in_maxusers;}
90 void SetUserCount(uint32 in_users) {users = in_users;}
91 void SetFileCount(uint32 in_files) {files = in_files;}
92 void ResetFailedCount() {failedcount = 0;}
93 void AddFailedCount() {failedcount++;}
94 uint32 GetFailedCount() const {return failedcount;}
95 void SetID(uint32 newip);
96 const wxString &GetDynIP() const {return dynip;}
97 bool HasDynIP() const {return !dynip.IsEmpty() ;}
98 void SetDynIP(const wxString& newdynip);
100 uint32 GetLastPingedTime() const {return lastpingedtime;}
101 void SetLastPingedTime(uint32 in_lastpingedtime) {lastpingedtime = in_lastpingedtime;}
103 uint32 GetRealLastPingedTime() const {return m_dwRealLastPingedTime;} // last pinged time without any random modificator
104 void SetRealLastPingedTime(uint32 in_lastpingedtime) {m_dwRealLastPingedTime = in_lastpingedtime;}
106 uint32 GetLastPinged() const {return lastpinged;}
107 void SetLastPinged(uint32 in_lastpinged) {lastpinged = in_lastpinged;}
109 void SetPing(uint32 in_ping) {ping = in_ping;}
110 void SetPreference(uint32 in_preferences) {preferences = in_preferences;}
111 void SetIsStaticMember(bool in) {staticservermember=in;}
112 bool IsStaticMember() const {return staticservermember;}
113 uint32 GetChallenge() const {return challenge;}
114 void SetChallenge(uint32 in_challenge) {challenge = in_challenge;}
115 uint32 GetSoftFiles() const {return softfiles;}
116 void SetSoftFiles(uint32 in_softfiles) {softfiles = in_softfiles;}
117 uint32 GetHardFiles() const {return hardfiles;}
118 void SetHardFiles(uint32 in_hardfiles) {hardfiles = in_hardfiles;}
119 const wxString &GetVersion() const {return m_strVersion;}
120 void SetVersion(const wxString &pszVersion) {m_strVersion = pszVersion;}
121 void SetTCPFlags(uint32 uFlags) {m_uTCPFlags = uFlags;}
122 uint32 GetTCPFlags() const {return m_uTCPFlags;}
123 void SetUDPFlags(uint32 uFlags) {m_uUDPFlags = uFlags;}
124 uint32 GetUDPFlags() const {return m_uUDPFlags;}
125 uint32 GetLowIDUsers() const {return m_uLowIDUsers;}
126 void SetLowIDUsers(uint32 uLowIDUsers) {m_uLowIDUsers = uLowIDUsers;}
127 uint32 GetDescReqChallenge() const {return m_uDescReqChallenge;}
128 void SetDescReqChallenge(uint32 uDescReqChallenge) {m_uDescReqChallenge = uDescReqChallenge;}
129 uint8 GetLastDescPingedCount() const {return lastdescpingedcout;}
130 void SetLastDescPingedCount(bool reset);
132 uint16 GetObfuscationPortTCP() const {return m_nObfuscationPortTCP;}
133 void SetObfuscationPortTCP(uint16 nPort) {m_nObfuscationPortTCP = nPort;}
135 uint16 GetObfuscationPortUDP() const {return m_nObfuscationPortUDP;}
136 void SetObfuscationPortUDP(uint16 nPort) {m_nObfuscationPortUDP = nPort;}
138 uint32 GetServerKeyUDP(bool bForce = false) const;
139 void SetServerKeyUDP(uint32 dwServerKeyUDP);
141 bool GetCryptPingReplyPending() const {return m_bCryptPingReplyPending;}
142 void SetCryptPingReplyPending(bool bVal) {m_bCryptPingReplyPending = bVal;}
144 uint32 GetServerKeyUDPIP() const {return m_dwIPServerKeyUDP;}
146 bool GetUnicodeSupport() const {return (GetTCPFlags() & SRV_TCPFLG_UNICODE) != 0;}
147 bool GetRelatedSearchSupport() const {return (GetTCPFlags() & SRV_TCPFLG_RELATEDSEARCH) != 0;}
148 bool SupportsLargeFilesTCP() const {return (GetTCPFlags() & SRV_TCPFLG_LARGEFILES) != 0;}
149 bool SupportsLargeFilesUDP() const {return (GetUDPFlags() & SRV_UDPFLG_LARGEFILES) != 0;}
150 bool SupportsObfuscationUDP() const {return (GetUDPFlags() & SRV_UDPFLG_UDPOBFUSCATION) != 0;}
151 bool SupportsObfuscationTCP() const {return (GetObfuscationPortTCP() != 0) && (((GetUDPFlags() & SRV_UDPFLG_TCPOBFUSCATION) != 0) || ((GetTCPFlags() & SRV_TCPFLG_TCPOBFUSCATION) != 0));}
152 bool SupportsGetSourcesObfuscation() const {return (GetTCPFlags() & SRV_TCPFLG_TCPOBFUSCATION) != 0;} // mapped to TCPFLAG_TCPOBFU
154 const wxString& GetAuxPortsList() const {return m_auxPorts;}
155 void SetAuxPortsList(const wxString& val) {m_auxPorts = val;}
157 uint64 GetLastDNSSolve() const { return m_lastdnssolve; }
158 void SetLastDNSSolve(uint64 value) { m_lastdnssolve = value; }
160 bool GetDNSError() const { return m_dnsfailure; }
161 void SetDNSError(bool value) { m_dnsfailure = value; }
163 private:
164 uint32 challenge;
165 uint32 lastpinged; //This is to get the ping delay.
166 uint32 lastpingedtime; //This is to decided when we retry the ping.
167 uint32 files;
168 uint32 users;
169 uint32 maxusers;
170 uint32 softfiles;
171 uint32 hardfiles;
172 uint32 preferences;
173 uint32 ping;
174 wxString description;
175 wxString listname;
176 wxString dynip;
177 uint32 tagcount;
178 wxString ipfull;
179 uint32 ip;
180 uint16 port;
181 uint16 realport;
182 uint32 failedcount;
183 uint32 m_uDescReqChallenge;
184 uint8 lastdescpingedcout;
185 TagPtrList m_taglist;
186 bool staticservermember;
187 wxString m_strVersion;
188 uint32 m_uTCPFlags;
189 uint32 m_uUDPFlags;
190 uint32 m_uLowIDUsers;
191 wxString m_auxPorts;
193 uint64 m_lastdnssolve;
194 bool m_dnsfailure;
196 bool m_bCryptPingReplyPending;
197 uint32 m_dwServerKeyUDP;
198 uint32 m_dwIPServerKeyUDP;
199 uint16 m_nObfuscationPortTCP;
200 uint16 m_nObfuscationPortUDP;
202 uint32 m_dwRealLastPingedTime;
204 void Init();
207 #endif // SERVER_H
208 // File_checked_for_headers