PeerThread.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. /*
  2. ** Command & Conquer Generals(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. UnsignedShort ladPort;
  107. UnsignedInt ladPassCRC;
  108. Bool restrictGameList;
  109. } stagingRoomCreation;
  110. struct
  111. {
  112. Int wins[MAX_SLOTS];
  113. Int losses[MAX_SLOTS];
  114. Int profileID[MAX_SLOTS];
  115. Int faction[MAX_SLOTS];
  116. Int color[MAX_SLOTS];
  117. Int numPlayers;
  118. Int maxPlayers;
  119. Int numObservers;
  120. } gameOptions;
  121. struct
  122. {
  123. Bool isStagingRoom;
  124. } UTM;
  125. struct
  126. {
  127. Int minPointPercentage, maxPointPercentage, points;
  128. Int widenTime;
  129. Int ladderID;
  130. UnsignedInt ladderPassCRC;
  131. Int maxPing;
  132. Int maxDiscons, discons;
  133. char pings[17]; // 8 servers (0-ff), 1 NULL
  134. Int numPlayers;
  135. Int botID;
  136. Int roomID;
  137. Int side;
  138. Int color;
  139. Int NAT;
  140. UnsignedInt exeCRC;
  141. UnsignedInt iniCRC;
  142. } QM;
  143. struct
  144. {
  145. Int locale;
  146. Int wins;
  147. Int losses;
  148. Int rankPoints;
  149. Int side;
  150. Bool preorder;
  151. } statsToPush;
  152. };
  153. };
  154. //-------------------------------------------------------------------------
  155. enum DisconnectReason
  156. {
  157. DISCONNECT_NICKTAKEN = 1,
  158. DISCONNECT_BADNICK,
  159. DISCONNECT_LOSTCON,
  160. DISCONNECT_COULDNOTCONNECT,
  161. DISCONNECT_GP_LOGIN_TIMEOUT,
  162. DISCONNECT_GP_LOGIN_BAD_NICK,
  163. DISCONNECT_GP_LOGIN_BAD_EMAIL,
  164. DISCONNECT_GP_LOGIN_BAD_PASSWORD,
  165. DISCONNECT_GP_LOGIN_BAD_PROFILE,
  166. DISCONNECT_GP_LOGIN_PROFILE_DELETED,
  167. DISCONNECT_GP_LOGIN_CONNECTION_FAILED,
  168. DISCONNECT_GP_LOGIN_SERVER_AUTH_FAILED,
  169. DISCONNECT_SERIAL_INVALID,
  170. DISCONNECT_SERIAL_NOT_PRESENT,
  171. DISCONNECT_SERIAL_BANNED,
  172. DISCONNECT_GP_NEWUSER_BAD_NICK,
  173. DISCONNECT_GP_NEWUSER_BAD_PASSWORD,
  174. DISCONNECT_GP_NEWPROFILE_BAD_NICK,
  175. DISCONNECT_GP_NEWPROFILE_BAD_OLD_NICK,
  176. DISCONNECT_MAX,
  177. };
  178. enum QMStatus
  179. {
  180. QM_IDLE,
  181. QM_JOININGQMCHANNEL,
  182. QM_LOOKINGFORBOT,
  183. QM_SENTINFO,
  184. QM_WORKING,
  185. QM_POOLSIZE,
  186. QM_WIDENINGSEARCH,
  187. QM_MATCHED,
  188. QM_INCHANNEL,
  189. QM_NEGOTIATINGFIREWALLS,
  190. QM_STARTINGGAME,
  191. QM_COULDNOTFINDBOT,
  192. QM_COULDNOTFINDCHANNEL,
  193. QM_COULDNOTNEGOTIATEFIREWALLS,
  194. QM_STOPPED,
  195. };
  196. // this class encapsulates an action the peer thread wants from the UI
  197. class PeerResponse
  198. {
  199. public:
  200. enum
  201. {
  202. PEERRESPONSE_LOGIN,
  203. PEERRESPONSE_DISCONNECT,
  204. PEERRESPONSE_MESSAGE,
  205. PEERRESPONSE_GROUPROOM,
  206. PEERRESPONSE_STAGINGROOM,
  207. PEERRESPONSE_STAGINGROOMLISTCOMPLETE,
  208. PEERRESPONSE_STAGINGROOMPLAYERINFO,
  209. PEERRESPONSE_JOINGROUPROOM,
  210. PEERRESPONSE_CREATESTAGINGROOM,
  211. PEERRESPONSE_JOINSTAGINGROOM,
  212. PEERRESPONSE_PLAYERJOIN,
  213. PEERRESPONSE_PLAYERLEFT,
  214. PEERRESPONSE_PLAYERCHANGEDNICK,
  215. PEERRESPONSE_PLAYERINFO,
  216. PEERRESPONSE_PLAYERCHANGEDFLAGS,
  217. PEERRESPONSE_ROOMUTM,
  218. PEERRESPONSE_PLAYERUTM,
  219. PEERRESPONSE_QUICKMATCHSTATUS,
  220. PEERRESPONSE_GAMESTART,
  221. PEERRESPONSE_FAILEDTOHOST,
  222. PEERRESPONSE_MAX
  223. } peerResponseType;
  224. std::string groupRoomName; // can't be in union
  225. std::string nick; // can't be in a union
  226. std::string oldNick; // can't be in a union
  227. std::wstring text; // can't be in a union
  228. std::string locale; // can't be in a union
  229. std::string stagingServerGameOptions; // full string from UTMs
  230. // game opts sent with PEERRESPONSE_STAGINGROOM
  231. std::wstring stagingServerName;
  232. std::string stagingServerPingString;
  233. std::string stagingServerLadderIP;
  234. std::string stagingRoomMapName;
  235. // game opts sent with PEERRESPONSE_STAGINGROOMPLAYERINFO
  236. std::string stagingRoomPlayerNames[MAX_SLOTS];
  237. std::string command;
  238. std::string commandOptions;
  239. union
  240. {
  241. struct
  242. {
  243. DisconnectReason reason;
  244. } discon;
  245. struct
  246. {
  247. Int id;
  248. Int numWaiting;
  249. Int maxWaiting;
  250. Int numGames;
  251. Int numPlaying;
  252. } groupRoom;
  253. struct
  254. {
  255. Int id;
  256. Bool ok;
  257. } joinGroupRoom;
  258. struct
  259. {
  260. Int result;
  261. } createStagingRoom;
  262. struct
  263. {
  264. Int id;
  265. Bool ok;
  266. Bool isHostPresent;
  267. Int result; // for failures
  268. } joinStagingRoom;
  269. struct
  270. {
  271. Bool isPrivate;
  272. Bool isAction;
  273. Int profileID;
  274. } message;
  275. struct
  276. {
  277. Int profileID;
  278. Int wins;
  279. Int losses;
  280. RoomType roomType;
  281. Int flags;
  282. UnsignedInt IP;
  283. Int rankPoints;
  284. Int side;
  285. Int preorder;
  286. UnsignedInt internalIP; // for us, on connection
  287. UnsignedInt externalIP; // for us, on connection
  288. } player;
  289. struct
  290. {
  291. Int id;
  292. Int action;
  293. Bool isStaging;
  294. Bool requiresPassword;
  295. Bool allowObservers;
  296. UnsignedInt version;
  297. UnsignedInt exeCRC;
  298. UnsignedInt iniCRC;
  299. UnsignedShort ladderPort;
  300. Int wins[MAX_SLOTS];
  301. Int losses[MAX_SLOTS];
  302. Int profileID[MAX_SLOTS];
  303. Int faction[MAX_SLOTS];
  304. Int color[MAX_SLOTS];
  305. Int numPlayers;
  306. Int numObservers;
  307. Int maxPlayers;
  308. Int percentComplete;
  309. } stagingRoom;
  310. struct
  311. {
  312. QMStatus status;
  313. Int poolSize;
  314. Int mapIdx; // when matched
  315. Int seed; // when matched
  316. UnsignedInt IP[MAX_SLOTS]; // when matched
  317. Int side[MAX_SLOTS]; // when matched
  318. Int color[MAX_SLOTS]; // when matched
  319. Int nat[MAX_SLOTS];
  320. } qmStatus;
  321. };
  322. };
  323. //-------------------------------------------------------------------------
  324. // this is the actual message queue used to pass messages between threads
  325. class GameSpyPeerMessageQueueInterface
  326. {
  327. public:
  328. virtual ~GameSpyPeerMessageQueueInterface() {}
  329. virtual void startThread( void ) = 0;
  330. virtual void endThread( void ) = 0;
  331. virtual Bool isThreadRunning( void ) = 0;
  332. virtual Bool isConnected( void ) = 0;
  333. virtual Bool isConnecting( void ) = 0;
  334. virtual void addRequest( const PeerRequest& req ) = 0;
  335. virtual Bool getRequest( PeerRequest& req ) = 0;
  336. virtual void addResponse( const PeerResponse& resp ) = 0;
  337. virtual Bool getResponse( PeerResponse& resp ) = 0;
  338. virtual SerialAuthResult getSerialAuthResult( void ) = 0;
  339. static GameSpyPeerMessageQueueInterface* createNewMessageQueue( void );
  340. };
  341. extern GameSpyPeerMessageQueueInterface *TheGameSpyPeerMessageQueue;
  342. #endif // __PEERTHREAD_H__