WOLServer.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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.h $
  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: 11 $
  36. * $Modtime: 1/11/02 5:40p $
  37. *
  38. ******************************************************************************/
  39. #ifndef __WOLSERVER_H__
  40. #define __WOLSERVER_H__
  41. #include "RefCounted.h"
  42. #include "RefPtr.h"
  43. #include "WOLString.h"
  44. #include <WWLib\WWString.h>
  45. namespace WOL
  46. {
  47. #include <WOLAPI\wolapi.h>
  48. }
  49. namespace WWOnline {
  50. class ServerData :
  51. public RefCounted
  52. {
  53. public:
  54. inline WOL::Server& GetData(void)
  55. {return mData;}
  56. inline const int GetTimeZone(void) const
  57. {return mData.timezone;}
  58. inline const float GetLongitude(void) const
  59. {return mData.longitude;}
  60. inline const float GetLattitude(void) const
  61. {return mData.lattitude;}
  62. protected:
  63. ServerData(const WOL::Server&);
  64. virtual ~ServerData();
  65. WOL::Server mData;
  66. };
  67. // base class for chat and game servers
  68. class IRCServerData :
  69. public ServerData
  70. {
  71. public:
  72. static RefPtr<IRCServerData> Create(const WOL::Server&);
  73. inline const char* GetName(void) const
  74. {return mServerName;}
  75. inline bool IsGameServer(void) const
  76. {return mIsGameServer;}
  77. inline bool HasLanguageCode(void) const
  78. {return mHasLanguageCode;}
  79. inline bool MatchesLanguageCode(void) const
  80. {return mMatchesLanguageCode;}
  81. protected:
  82. IRCServerData(const WOL::Server&);
  83. virtual ~IRCServerData()
  84. {}
  85. private:
  86. StringClass mServerName;
  87. bool mIsGameServer;
  88. bool mMatchesLanguageCode;
  89. bool mHasLanguageCode;
  90. };
  91. // base class for non-chat/non-game servers
  92. class HostPortServerData :
  93. public ServerData
  94. {
  95. public:
  96. inline const char* GetName(void) const
  97. {return (const char*)mData.name;}
  98. inline const char* GetHostAddress(void) const
  99. {return mHostAddress;}
  100. inline unsigned int GetPort(void) const
  101. {return mHostPort;}
  102. protected:
  103. HostPortServerData(const WOL::Server&);
  104. virtual ~HostPortServerData()
  105. {}
  106. private:
  107. StringClass mHostAddress;
  108. unsigned int mHostPort;
  109. };
  110. class LadderServerData :
  111. public HostPortServerData
  112. {
  113. public:
  114. static RefPtr<LadderServerData> Create(const WOL::Server&);
  115. private:
  116. LadderServerData(const WOL::Server&);
  117. virtual ~LadderServerData()
  118. {}
  119. LadderServerData(const LadderServerData&);
  120. const LadderServerData& operator=(const LadderServerData&);
  121. };
  122. class GameResultsServerData :
  123. public HostPortServerData
  124. {
  125. public:
  126. static RefPtr<GameResultsServerData> Create(const WOL::Server&);
  127. private:
  128. GameResultsServerData(const WOL::Server&);
  129. virtual ~GameResultsServerData()
  130. {}
  131. GameResultsServerData(const GameResultsServerData&);
  132. const GameResultsServerData& operator=(const GameResultsServerData&);
  133. };
  134. class WDTServerData :
  135. public HostPortServerData
  136. {
  137. public:
  138. static RefPtr<WDTServerData> Create(const WOL::Server&);
  139. private:
  140. WDTServerData(const WOL::Server&);
  141. virtual ~WDTServerData()
  142. {}
  143. WDTServerData(const WDTServerData&);
  144. const WDTServerData& operator=(const WDTServerData&);
  145. };
  146. class MGLServerData :
  147. public HostPortServerData
  148. {
  149. public:
  150. static RefPtr<MGLServerData> Create(const WOL::Server&);
  151. private:
  152. MGLServerData(const WOL::Server&);
  153. virtual ~MGLServerData()
  154. {}
  155. MGLServerData(const MGLServerData&);
  156. const MGLServerData& operator=(const MGLServerData&);
  157. };
  158. class PingServerData :
  159. public HostPortServerData
  160. {
  161. public:
  162. static RefPtr<PingServerData> Create(const WOL::Server&);
  163. void SetPingTime(int time);
  164. inline int GetPingTime(void) const
  165. {return mPingTime;}
  166. protected:
  167. PingServerData(const WOL::Server&);
  168. virtual ~PingServerData()
  169. {}
  170. // Prevent copy and assignment
  171. PingServerData(const PingServerData&);
  172. const PingServerData& operator=(const PingServerData&);
  173. private:
  174. int mPingTime;
  175. };
  176. class ServerError
  177. {
  178. public:
  179. ServerError(int code, const char* description, unsigned long data = 0) :
  180. mCode(code),
  181. mDescription(description),
  182. mData(data)
  183. {}
  184. inline int GetErrorCode(void)
  185. {return mCode;}
  186. inline const wchar_t* GetDescription(void) const
  187. {return WOLSTRING(mDescription);}
  188. inline unsigned int GetData(void) const
  189. {return mData;}
  190. private:
  191. ServerError(const ServerError&);
  192. const ServerError& operator=(const ServerError&);
  193. int mCode;
  194. StringClass mDescription;
  195. unsigned long mData;
  196. };
  197. } // namespace WWOnline
  198. #endif // __WOLSERVER_H__