PeerThread.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: PeerThread.h //////////////////////////////////////////////////////
  24. // Generals GameSpy Peer-to-peer chat thread class interface
  25. // Author: Matthew D. Campbell, June 2002
  26. #pragma once
  27. #ifndef __PEERTHREAD_H__
  28. #define __PEERTHREAD_H__
  29. #include "GameSpy/Peer/Peer.h"
  30. #include "GameNetwork/NetworkDefs.h"
  31. enum SerialAuthResult
  32. {
  33. SERIAL_NONEXISTENT,
  34. SERIAL_AUTHFAILED,
  35. SERIAL_BANNED,
  36. SERIAL_OK
  37. };
  38. // this class encapsulates a request for the peer thread
  39. class PeerRequest
  40. {
  41. public:
  42. enum
  43. {
  44. PEERREQUEST_LOGIN, // attempt to login
  45. PEERREQUEST_LOGOUT, // log out if connected
  46. PEERREQUEST_MESSAGEPLAYER,
  47. PEERREQUEST_MESSAGEROOM,
  48. PEERREQUEST_JOINGROUPROOM,
  49. PEERREQUEST_LEAVEGROUPROOM,
  50. PEERREQUEST_STARTGAMELIST,
  51. PEERREQUEST_STOPGAMELIST,
  52. PEERREQUEST_CREATESTAGINGROOM,
  53. PEERREQUEST_SETGAMEOPTIONS,
  54. PEERREQUEST_JOINSTAGINGROOM,
  55. PEERREQUEST_LEAVESTAGINGROOM,
  56. PEERREQUEST_UTMPLAYER,
  57. PEERREQUEST_UTMROOM,
  58. PEERREQUEST_STARTGAME,
  59. PEERREQUEST_STARTQUICKMATCH,
  60. PEERREQUEST_WIDENQUICKMATCHSEARCH,
  61. PEERREQUEST_STOPQUICKMATCH,
  62. PEERREQUEST_PUSHSTATS,
  63. PEERREQUEST_GETEXTENDEDSTAGINGROOMINFO,
  64. PEERREQUEST_MAX
  65. } peerRequestType;
  66. std::string nick; // only used by login, but must be outside the union b/c of copy constructor
  67. std::wstring text; // can't be in a union
  68. std::string password;
  69. std::string email;
  70. std::string id;
  71. // gameopts
  72. std::string options; // full string for UTMs
  73. std::string ladderIP;
  74. std::string hostPingStr;
  75. std::string gameOptsMapName;
  76. std::string gameOptsPlayerNames[MAX_SLOTS];
  77. std::vector<bool> qmMaps;
  78. union
  79. {
  80. struct
  81. {
  82. Int profileID;
  83. } login;
  84. struct
  85. {
  86. Int id;
  87. } groupRoom;
  88. struct
  89. {
  90. Bool restrictGameList;
  91. } gameList;
  92. struct
  93. {
  94. Bool isAction;
  95. } message;
  96. struct
  97. {
  98. Int id;
  99. } stagingRoom;
  100. struct
  101. {
  102. UnsignedInt exeCRC;
  103. UnsignedInt iniCRC;
  104. UnsignedInt gameVersion;
  105. Bool allowObservers;
  106. Bool useStats;
  107. UnsignedShort ladPort;
  108. UnsignedInt ladPassCRC;
  109. Bool restrictGameList;
  110. } stagingRoomCreation;
  111. struct
  112. {
  113. Int wins[MAX_SLOTS];
  114. Int losses[MAX_SLOTS];
  115. Int profileID[MAX_SLOTS];
  116. Int faction[MAX_SLOTS];
  117. Int color[MAX_SLOTS];
  118. Int numPlayers;
  119. Int maxPlayers;
  120. Int numObservers;
  121. } gameOptions;
  122. struct
  123. {
  124. Bool isStagingRoom;
  125. } UTM;
  126. struct
  127. {
  128. Int minPointPercentage, maxPointPercentage, points;
  129. Int widenTime;
  130. Int ladderID;
  131. UnsignedInt ladderPassCRC;
  132. Int maxPing;
  133. Int maxDiscons, discons;
  134. char pings[17]; // 8 servers (0-ff), 1 NULL
  135. Int numPlayers;
  136. Int botID;
  137. Int roomID;
  138. Int side;
  139. Int color;
  140. Int NAT;
  141. UnsignedInt exeCRC;
  142. UnsignedInt iniCRC;
  143. } QM;
  144. struct
  145. {
  146. Int locale;
  147. Int wins;
  148. Int losses;
  149. Int rankPoints;
  150. Int side;
  151. Bool preorder;
  152. } statsToPush;
  153. };
  154. };
  155. //-------------------------------------------------------------------------
  156. enum DisconnectReason
  157. {
  158. DISCONNECT_NICKTAKEN = 1,
  159. DISCONNECT_BADNICK,
  160. DISCONNECT_LOSTCON,
  161. DISCONNECT_COULDNOTCONNECT,
  162. DISCONNECT_GP_LOGIN_TIMEOUT,
  163. DISCONNECT_GP_LOGIN_BAD_NICK,
  164. DISCONNECT_GP_LOGIN_BAD_EMAIL,
  165. DISCONNECT_GP_LOGIN_BAD_PASSWORD,
  166. DISCONNECT_GP_LOGIN_BAD_PROFILE,
  167. DISCONNECT_GP_LOGIN_PROFILE_DELETED,
  168. DISCONNECT_GP_LOGIN_CONNECTION_FAILED,
  169. DISCONNECT_GP_LOGIN_SERVER_AUTH_FAILED,
  170. DISCONNECT_SERIAL_INVALID,
  171. DISCONNECT_SERIAL_NOT_PRESENT,
  172. DISCONNECT_SERIAL_BANNED,
  173. DISCONNECT_GP_NEWUSER_BAD_NICK,
  174. DISCONNECT_GP_NEWUSER_BAD_PASSWORD,
  175. DISCONNECT_GP_NEWPROFILE_BAD_NICK,
  176. DISCONNECT_GP_NEWPROFILE_BAD_OLD_NICK,
  177. DISCONNECT_MAX,
  178. };
  179. enum QMStatus
  180. {
  181. QM_IDLE,
  182. QM_JOININGQMCHANNEL,
  183. QM_LOOKINGFORBOT,
  184. QM_SENTINFO,
  185. QM_WORKING,
  186. QM_POOLSIZE,
  187. QM_WIDENINGSEARCH,
  188. QM_MATCHED,
  189. QM_INCHANNEL,
  190. QM_NEGOTIATINGFIREWALLS,
  191. QM_STARTINGGAME,
  192. QM_COULDNOTFINDBOT,
  193. QM_COULDNOTFINDCHANNEL,
  194. QM_COULDNOTNEGOTIATEFIREWALLS,
  195. QM_STOPPED,
  196. };
  197. // this class encapsulates an action the peer thread wants from the UI
  198. class PeerResponse
  199. {
  200. public:
  201. enum
  202. {
  203. PEERRESPONSE_LOGIN,
  204. PEERRESPONSE_DISCONNECT,
  205. PEERRESPONSE_MESSAGE,
  206. PEERRESPONSE_GROUPROOM,
  207. PEERRESPONSE_STAGINGROOM,
  208. PEERRESPONSE_STAGINGROOMLISTCOMPLETE,
  209. PEERRESPONSE_STAGINGROOMPLAYERINFO,
  210. PEERRESPONSE_JOINGROUPROOM,
  211. PEERRESPONSE_CREATESTAGINGROOM,
  212. PEERRESPONSE_JOINSTAGINGROOM,
  213. PEERRESPONSE_PLAYERJOIN,
  214. PEERRESPONSE_PLAYERLEFT,
  215. PEERRESPONSE_PLAYERCHANGEDNICK,
  216. PEERRESPONSE_PLAYERINFO,
  217. PEERRESPONSE_PLAYERCHANGEDFLAGS,
  218. PEERRESPONSE_ROOMUTM,
  219. PEERRESPONSE_PLAYERUTM,
  220. PEERRESPONSE_QUICKMATCHSTATUS,
  221. PEERRESPONSE_GAMESTART,
  222. PEERRESPONSE_FAILEDTOHOST,
  223. PEERRESPONSE_MAX
  224. } peerResponseType;
  225. std::string groupRoomName; // can't be in union
  226. std::string nick; // can't be in a union
  227. std::string oldNick; // can't be in a union
  228. std::wstring text; // can't be in a union
  229. std::string locale; // can't be in a union
  230. std::string stagingServerGameOptions; // full string from UTMs
  231. // game opts sent with PEERRESPONSE_STAGINGROOM
  232. std::wstring stagingServerName;
  233. std::string stagingServerPingString;
  234. std::string stagingServerLadderIP;
  235. std::string stagingRoomMapName;
  236. // game opts sent with PEERRESPONSE_STAGINGROOMPLAYERINFO
  237. std::string stagingRoomPlayerNames[MAX_SLOTS];
  238. std::string command;
  239. std::string commandOptions;
  240. union
  241. {
  242. struct
  243. {
  244. DisconnectReason reason;
  245. } discon;
  246. struct
  247. {
  248. Int id;
  249. Int numWaiting;
  250. Int maxWaiting;
  251. Int numGames;
  252. Int numPlaying;
  253. } groupRoom;
  254. struct
  255. {
  256. Int id;
  257. Bool ok;
  258. } joinGroupRoom;
  259. struct
  260. {
  261. Int result;
  262. } createStagingRoom;
  263. struct
  264. {
  265. Int id;
  266. Bool ok;
  267. Bool isHostPresent;
  268. Int result; // for failures
  269. } joinStagingRoom;
  270. struct
  271. {
  272. Bool isPrivate;
  273. Bool isAction;
  274. Int profileID;
  275. } message;
  276. struct
  277. {
  278. Int profileID;
  279. Int wins;
  280. Int losses;
  281. RoomType roomType;
  282. Int flags;
  283. UnsignedInt IP;
  284. Int rankPoints;
  285. Int side;
  286. Int preorder;
  287. UnsignedInt internalIP; // for us, on connection
  288. UnsignedInt externalIP; // for us, on connection
  289. } player;
  290. struct
  291. {
  292. Int id;
  293. Int action;
  294. Bool isStaging;
  295. Bool requiresPassword;
  296. Bool allowObservers;
  297. Bool useStats;
  298. UnsignedInt version;
  299. UnsignedInt exeCRC;
  300. UnsignedInt iniCRC;
  301. UnsignedShort ladderPort;
  302. Int wins[MAX_SLOTS];
  303. Int losses[MAX_SLOTS];
  304. Int profileID[MAX_SLOTS];
  305. Int faction[MAX_SLOTS];
  306. Int color[MAX_SLOTS];
  307. Int numPlayers;
  308. Int numObservers;
  309. Int maxPlayers;
  310. Int percentComplete;
  311. } stagingRoom;
  312. struct
  313. {
  314. QMStatus status;
  315. Int poolSize;
  316. Int mapIdx; // when matched
  317. Int seed; // when matched
  318. UnsignedInt IP[MAX_SLOTS]; // when matched
  319. Int side[MAX_SLOTS]; // when matched
  320. Int color[MAX_SLOTS]; // when matched
  321. Int nat[MAX_SLOTS];
  322. } qmStatus;
  323. };
  324. };
  325. //-------------------------------------------------------------------------
  326. // this is the actual message queue used to pass messages between threads
  327. class GameSpyPeerMessageQueueInterface
  328. {
  329. public:
  330. virtual ~GameSpyPeerMessageQueueInterface() {}
  331. virtual void startThread( void ) = 0;
  332. virtual void endThread( void ) = 0;
  333. virtual Bool isThreadRunning( void ) = 0;
  334. virtual Bool isConnected( void ) = 0;
  335. virtual Bool isConnecting( void ) = 0;
  336. virtual void addRequest( const PeerRequest& req ) = 0;
  337. virtual Bool getRequest( PeerRequest& req ) = 0;
  338. virtual void addResponse( const PeerResponse& resp ) = 0;
  339. virtual Bool getResponse( PeerResponse& resp ) = 0;
  340. virtual SerialAuthResult getSerialAuthResult( void ) = 0;
  341. static GameSpyPeerMessageQueueInterface* createNewMessageQueue( void );
  342. };
  343. extern GameSpyPeerMessageQueueInterface *TheGameSpyPeerMessageQueue;
  344. #endif // __PEERTHREAD_H__