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