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 "Server.h" // Interface declarations.
28 #include <tags/ServerTags.h>
30 #include "NetworkFunctions.h" // Needed for StringIPtoUint32
31 #include "OtherStructs.h" // Needed for ServerMet_Struct
34 CServer::CServer(ServerMet_Struct
* in_data
)
42 CServer::CServer(uint16 in_port
, const wxString i_addr
)
46 ip
= StringIPtoUint32(i_addr
);
50 // GonoszTopi - Init() would clear dynip !
51 // Check that the ip isn't in fact 0.0.0.0
52 if (!ip
&& !StringIPtoUint32( i_addr
, ip
) ) {
53 // If ip == 0, the address is a hostname
59 CServer::CServer(CEC_Server_Tag
*tag
)
61 ip
= tag
->GetIPv4Data().IP();
63 port
= tag
->GetIPv4Data().m_port
;
67 listname
= tag
->ServerName();
68 description
= tag
->ServerDesc();
69 maxusers
= tag
->GetMaxUsers();
71 files
= tag
->GetFiles();
72 users
= tag
->GetUsers();
74 preferences
= tag
->GetPrio(); // SRV_PR_NORMAL = 0, so it's ok
75 staticservermember
= tag
->GetStatic();
77 ping
= tag
->GetPing();
78 failedcount
= tag
->GetFailed();
83 CServer::CServer(CServer
* pOld
)
85 wxASSERT(pOld
!= NULL
);
87 TagPtrList::iterator it
= pOld
->m_taglist
.begin();
88 for ( ; it
!= pOld
->m_taglist
.end(); ++it
) {
89 m_taglist
.push_back((*it
)->CloneTag());
93 realport
= pOld
->realport
;
94 staticservermember
=pOld
->IsStaticMember();
95 tagcount
= pOld
->tagcount
;
96 ipfull
= pOld
->ipfull
;
99 preferences
= pOld
->preferences
;
101 failedcount
= pOld
->failedcount
;
102 lastpinged
= pOld
->lastpinged
;
103 lastpingedtime
= pOld
->lastpingedtime
;
104 m_dwRealLastPingedTime
= pOld
->m_dwRealLastPingedTime
;
105 description
= pOld
->description
;
106 listname
= pOld
->listname
;
108 maxusers
= pOld
->maxusers
;
109 m_strVersion
= pOld
->m_strVersion
;
110 m_uTCPFlags
= pOld
->m_uTCPFlags
;
111 m_uUDPFlags
= pOld
->m_uUDPFlags
;
112 challenge
= pOld
->challenge
;
113 softfiles
= pOld
->softfiles
;
114 hardfiles
= pOld
->hardfiles
;
115 m_uDescReqChallenge
= pOld
->m_uDescReqChallenge
;
116 m_uLowIDUsers
= pOld
->m_uLowIDUsers
;
117 lastdescpingedcout
= pOld
->lastdescpingedcout
;
118 m_auxPorts
= pOld
->m_auxPorts
;
119 m_dwServerKeyUDP
= pOld
->m_dwServerKeyUDP
;
120 m_bCryptPingReplyPending
= pOld
->m_bCryptPingReplyPending
;
121 m_dwIPServerKeyUDP
= pOld
->m_dwIPServerKeyUDP
;
122 m_nObfuscationPortTCP
= pOld
->m_nObfuscationPortTCP
;
123 m_nObfuscationPortUDP
= pOld
->m_nObfuscationPortUDP
;
128 deleteTagPtrListEntries(&m_taglist
);
132 void CServer::Init() {
134 ipfull
= Uint32toStringIP(ip
);
148 m_dwRealLastPingedTime
= 0;
149 staticservermember
=false;
156 m_strVersion
= _("Unknown");
158 m_uDescReqChallenge
= 0;
159 lastdescpingedcout
= 0;
162 m_dnsfailure
= false;
164 m_dwServerKeyUDP
= 0;
165 m_bCryptPingReplyPending
= false;
166 m_dwIPServerKeyUDP
= 0;
167 m_nObfuscationPortTCP
= 0;
168 m_nObfuscationPortUDP
= 0;
173 bool CServer::AddTagFromFile(CFileDataIO
* servermet
)
175 if (servermet
== NULL
) {
179 CTag
tag(*servermet
, true);
181 switch(tag
.GetNameID()){
183 if (listname
.IsEmpty()) {
184 listname
= tag
.GetStr();
189 if (description
.IsEmpty()) {
190 description
= tag
.GetStr();
195 preferences
= tag
.GetInt();
203 if (dynip
.IsEmpty()) {
204 dynip
= tag
.GetStr();
209 failedcount
= tag
.GetInt();
213 lastpinged
= tag
.GetInt();
217 maxusers
= tag
.GetInt();
221 softfiles
= tag
.GetInt();
225 hardfiles
= tag
.GetInt();
230 // m_strVersion defaults to _("Unknown"), so check for that as well
231 if ((m_strVersion
.IsEmpty()) || (m_strVersion
== _("Unknown"))) {
232 m_strVersion
= tag
.GetStr();
234 } else if (tag
.IsInt()) {
235 m_strVersion
= CFormat(wxT("%u.%u")) % (tag
.GetInt() >> 16) % (tag
.GetInt() & 0xFFFF);
242 m_uUDPFlags
= tag
.GetInt();
245 case ST_AUXPORTSLIST
:
246 m_auxPorts
= tag
.GetStr();
248 // Some server.mets contain empty ST_AUXPORTSLIST tags
249 if (!m_auxPorts
.IsEmpty()) {
251 port
= StrToULong(m_auxPorts
.BeforeFirst(','));
256 m_uLowIDUsers
= tag
.GetInt();
260 m_dwServerKeyUDP
= tag
.GetInt();
264 m_dwIPServerKeyUDP
= tag
.GetInt();
267 case ST_TCPPORTOBFUSCATION
:
268 m_nObfuscationPortTCP
= (uint16
)tag
.GetInt();
271 case ST_UDPPORTOBFUSCATION
:
272 m_nObfuscationPortUDP
= (uint16
)tag
.GetInt();
276 if (!tag
.GetName().IsEmpty()) {
277 if (tag
.GetName() == wxT("files")) {
278 files
= tag
.GetInt();
279 } else if (tag
.GetName() == wxT("users")) {
280 users
= tag
.GetInt();
291 void CServer::SetListName(const wxString
& newname
)
296 void CServer::SetDescription(const wxString
& newname
)
298 description
= newname
;
301 void CServer::SetID(uint32 newip
)
305 ipfull
= Uint32toStringIP(ip
);
308 void CServer::SetDynIP(const wxString
& newdynip
)
314 void CServer::SetLastDescPingedCount(bool bReset
)
317 lastdescpingedcout
= 0;
319 lastdescpingedcout
++;
323 uint32
CServer::GetServerKeyUDP(bool bForce
) const
325 if ((m_dwIPServerKeyUDP
!= 0 && m_dwIPServerKeyUDP
== theApp
->GetPublicIP()) || bForce
) {
326 return m_dwServerKeyUDP
;
332 void CServer::SetServerKeyUDP(uint32 dwServerKeyUDP
)
334 wxASSERT( theApp
->GetPublicIP() != 0 || dwServerKeyUDP
== 0 );
335 m_dwServerKeyUDP
= dwServerKeyUDP
;
336 m_dwIPServerKeyUDP
= theApp
->GetPublicIP();
338 // File_checked_for_headers