WOLServer.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /******************************************************************************
  19. *
  20. * FILE
  21. * $Archive: /Commando/Code/WWOnline/WOLServer.cpp $
  22. *
  23. * DESCRIPTION
  24. * These classes encapsulate a Westwood Online Server.
  25. *
  26. * This is a base class. Derived classes include (but not necessarily limited to)
  27. * ChatServer, GameResultsServer, LadderServer, and WDTServer.
  28. *
  29. * Server primarily repackages the WOL Server struct
  30. *
  31. * PROGRAMMER
  32. * $Author: Denzil_l $
  33. *
  34. * VERSION INFO
  35. * $Revision: 14 $
  36. * $Modtime: 1/12/02 9:42p $
  37. *
  38. ******************************************************************************/
  39. #include <stdlib.h>
  40. #include "WOLServer.h"
  41. #include "WOLProduct.h"
  42. #include <commando\_globals.h>
  43. #include <string.h>
  44. #include <WWDebug\WWDebug.h>
  45. #include <WWLib\Registry.h>
  46. namespace WWOnline {
  47. /******************************************************************************
  48. *
  49. * NAME
  50. * ServerData::ServerData
  51. *
  52. * DESCRIPTION
  53. * Constructor
  54. *
  55. * INPUTS
  56. * Server - WOLAPI Server structure representing server.
  57. *
  58. * RESULT
  59. * NONE
  60. *
  61. ******************************************************************************/
  62. ServerData::ServerData(const WOL::Server& server)
  63. {
  64. memcpy(&mData, &server, sizeof(mData));
  65. mData.next = NULL;
  66. }
  67. /******************************************************************************
  68. *
  69. * NAME
  70. * ServerData::~ServerData
  71. *
  72. * DESCRIPTION
  73. * Destructor
  74. *
  75. * INPUTS
  76. * NONE
  77. *
  78. * RESULT
  79. * NONE
  80. *
  81. ******************************************************************************/
  82. ServerData::~ServerData()
  83. {
  84. WWDEBUG_SAY(("WOL: Destructing ServerData %s:%s\n", mData.connlabel, mData.name));
  85. }
  86. /******************************************************************************
  87. *
  88. * NAME
  89. * IRCServerData::Create
  90. *
  91. * DESCRIPTION
  92. * Create a IRC server instance.
  93. *
  94. * INPUTS
  95. * Server - WOLAPI server structure
  96. *
  97. * RESULT
  98. * Instance of IRC server class.
  99. *
  100. ******************************************************************************/
  101. RefPtr<IRCServerData> IRCServerData::Create(const WOL::Server& server)
  102. {
  103. WWASSERT((strcmp((char*)server.connlabel, "IRC") == 0) || (strcmp((char*)server.connlabel, "IGS") == 0));
  104. return new IRCServerData(server);
  105. }
  106. /******************************************************************************
  107. *
  108. * NAME
  109. * IRCServerData::IRCServerData
  110. *
  111. * DESCRIPTION
  112. * Constructor
  113. *
  114. * INPUTS
  115. * Server - WOLAPI server structure
  116. *
  117. * RESULT
  118. * NONE
  119. *
  120. ******************************************************************************/
  121. IRCServerData::IRCServerData(const WOL::Server& server) :
  122. ServerData(server),
  123. mMatchesLanguageCode(false),
  124. mHasLanguageCode(false)
  125. {
  126. mIsGameServer = (strcmp((char*)server.connlabel, "IGS") == 0);
  127. RefPtr<Product> product = Product::Current();
  128. WWASSERT(product.IsValid() && "WWOnline product not initialized.");
  129. char* namePart = strchr((char*)server.name, ':');
  130. if (namePart)
  131. {
  132. namePart++;
  133. }
  134. char name[sizeof(server.name) + 1];
  135. strcpy(name, (char*)server.name);
  136. char* langPart = strtok(name, ":");
  137. if (namePart && langPart)
  138. {
  139. char* token = strtok(langPart, ",");
  140. if (token)
  141. {
  142. long productLangCode = product->GetLanguageCode();
  143. do
  144. {
  145. long langCode = atol(token);
  146. if (langCode == productLangCode)
  147. {
  148. mMatchesLanguageCode = true;
  149. }
  150. token = strtok(NULL, ",");
  151. } while (token);
  152. }
  153. }
  154. if (namePart)
  155. {
  156. mServerName = namePart;
  157. mHasLanguageCode = true;
  158. }
  159. else
  160. {
  161. mServerName = (char*)server.name;
  162. }
  163. }
  164. /******************************************************************************
  165. *
  166. * NAME
  167. * HostPortServerData::HostPortServerData
  168. *
  169. * DESCRIPTION
  170. *
  171. * INPUTS
  172. *
  173. * RESULT
  174. * NONE
  175. *
  176. ******************************************************************************/
  177. HostPortServerData::HostPortServerData(const WOL::Server& server) :
  178. ServerData(server)
  179. {
  180. char data[sizeof(server.conndata) + 1];
  181. strcpy(data, (char*)server.conndata);
  182. char* token = strtok(data, ";");
  183. WWASSERT(token);
  184. if (token)
  185. {
  186. token = strtok(NULL, ";");
  187. }
  188. WWASSERT(token);
  189. if (token)
  190. {
  191. mHostAddress = token;
  192. token = strtok(NULL, ";");
  193. }
  194. WWASSERT(token);
  195. if (token)
  196. {
  197. mHostPort = atol(token);
  198. }
  199. }
  200. /******************************************************************************
  201. *
  202. * NAME
  203. * LadderServerData::Create
  204. *
  205. * DESCRIPTION
  206. *
  207. * INPUTS
  208. *
  209. * RESULT
  210. *
  211. ******************************************************************************/
  212. RefPtr<LadderServerData> LadderServerData::Create(const WOL::Server& server)
  213. {
  214. WWASSERT(strcmp((char*)server.connlabel, "LAD") == 0);
  215. return new LadderServerData(server);
  216. }
  217. /******************************************************************************
  218. *
  219. * NAME
  220. * LadderServerData::LadderServerData
  221. *
  222. * DESCRIPTION
  223. *
  224. * INPUTS
  225. *
  226. * RESULT
  227. * NONE
  228. *
  229. ******************************************************************************/
  230. LadderServerData::LadderServerData(const WOL::Server& server) :
  231. HostPortServerData(server)
  232. {
  233. }
  234. /******************************************************************************
  235. *
  236. * NAME
  237. * GameResultsServerData::Create
  238. *
  239. * DESCRIPTION
  240. *
  241. * INPUTS
  242. *
  243. * RESULT
  244. *
  245. ******************************************************************************/
  246. RefPtr<GameResultsServerData> GameResultsServerData::Create(const WOL::Server& server)
  247. {
  248. WWASSERT(strcmp((char*)server.connlabel, "GAM") == 0);
  249. return new GameResultsServerData(server);
  250. }
  251. /******************************************************************************
  252. *
  253. * NAME
  254. * GameResultsServerData::GameResultsServerData
  255. *
  256. * DESCRIPTION
  257. *
  258. * INPUTS
  259. *
  260. * RESULT
  261. * NONE
  262. *
  263. ******************************************************************************/
  264. GameResultsServerData::GameResultsServerData(const WOL::Server& server) :
  265. HostPortServerData(server)
  266. {
  267. }
  268. /******************************************************************************
  269. *
  270. * NAME
  271. * WDTServerData::Create
  272. *
  273. * DESCRIPTION
  274. *
  275. * INPUTS
  276. *
  277. * RESULT
  278. *
  279. ******************************************************************************/
  280. RefPtr<WDTServerData> WDTServerData::Create(const WOL::Server& server)
  281. {
  282. WWASSERT(strcmp((char*)server.connlabel, "WDT") == 0);
  283. return new WDTServerData(server);
  284. }
  285. /******************************************************************************
  286. *
  287. * NAME
  288. * WDTServerData::WDTServerData
  289. *
  290. * DESCRIPTION
  291. *
  292. * INPUTS
  293. *
  294. * RESULT
  295. * NONE
  296. *
  297. ******************************************************************************/
  298. WDTServerData::WDTServerData(const WOL::Server& server) :
  299. HostPortServerData(server)
  300. {
  301. }
  302. /******************************************************************************
  303. *
  304. * NAME
  305. * MGLServerData::Create
  306. *
  307. * DESCRIPTION
  308. *
  309. * INPUTS
  310. *
  311. * RESULT
  312. *
  313. ******************************************************************************/
  314. RefPtr<MGLServerData> MGLServerData::Create(const WOL::Server& server)
  315. {
  316. WWASSERT(strcmp((char*)server.connlabel, "MGL") == 0);
  317. return new MGLServerData(server);
  318. }
  319. /******************************************************************************
  320. *
  321. * NAME
  322. * MGLServerData::MGLServerData
  323. *
  324. * DESCRIPTION
  325. *
  326. * INPUTS
  327. *
  328. * RESULT
  329. * NONE
  330. *
  331. ******************************************************************************/
  332. MGLServerData::MGLServerData(const WOL::Server& server) :
  333. HostPortServerData(server)
  334. {
  335. WWDEBUG_SAY(("WOL: ManglerServer %s:%d\n", GetHostAddress(), GetPort()));
  336. }
  337. RefPtr<PingServerData> PingServerData::Create(const WOL::Server& server)
  338. {
  339. WWASSERT(strcmp((char*)server.connlabel, "PNG") == 0);
  340. return new PingServerData(server);
  341. }
  342. PingServerData::PingServerData(const WOL::Server& server) :
  343. HostPortServerData(server),
  344. mPingTime(-1)
  345. {
  346. WWDEBUG_SAY(("WOL: PingServer %s:%d\n", GetHostAddress(), GetPort()));
  347. }
  348. void PingServerData::SetPingTime(int time)
  349. {
  350. mPingTime = time;
  351. // Save the ping time in the registry.
  352. RegistryClass reg(APPLICATION_SUB_KEY_NAME_SERVER_LIST);
  353. reg.Set_Int(GetHostAddress(), time);
  354. }
  355. }