PersistentStorageThread.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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: PersistentStorageThread.h //////////////////////////////////////////////////////
  24. // Generals GameSpy Persistent Storage thread class interface
  25. // Author: Matthew D. Campbell, July 2002
  26. #pragma once
  27. #ifndef __PERSISTENTSTORAGETHREAD_H__
  28. #define __PERSISTENTSTORAGETHREAD_H__
  29. #include "GameSpy/gstats/gpersist.h"
  30. #define MAX_BUDDY_CHAT_LEN 128
  31. typedef std::map<Int, UnsignedInt> PerGeneralMap;
  32. // this structure holds all info on a player that is stored online
  33. class PSPlayerStats
  34. {
  35. public:
  36. PSPlayerStats( void );
  37. PSPlayerStats( const PSPlayerStats& other );
  38. void reset(void);
  39. Int id;
  40. PerGeneralMap wins;
  41. PerGeneralMap losses;
  42. PerGeneralMap games; //first: playerTemplate #, second: #games played (see also gamesAsRandom)
  43. PerGeneralMap duration;
  44. PerGeneralMap unitsKilled;
  45. PerGeneralMap unitsLost;
  46. PerGeneralMap unitsBuilt;
  47. PerGeneralMap buildingsKilled;
  48. PerGeneralMap buildingsLost;
  49. PerGeneralMap buildingsBuilt;
  50. PerGeneralMap earnings;
  51. PerGeneralMap techCaptured;
  52. PerGeneralMap discons;
  53. PerGeneralMap desyncs;
  54. PerGeneralMap surrenders;
  55. PerGeneralMap gamesOf2p;
  56. PerGeneralMap gamesOf3p;
  57. PerGeneralMap gamesOf4p;
  58. PerGeneralMap gamesOf5p;
  59. PerGeneralMap gamesOf6p;
  60. PerGeneralMap gamesOf7p;
  61. PerGeneralMap gamesOf8p;
  62. PerGeneralMap customGames;
  63. PerGeneralMap QMGames;
  64. Int locale;
  65. Int gamesAsRandom;
  66. std::string options;
  67. std::string systemSpec;
  68. Real lastFPS;
  69. Int lastGeneral;
  70. Int gamesInRowWithLastGeneral;
  71. Int challengeMedals;
  72. Int battleHonors;
  73. Int QMwinsInARow;
  74. Int maxQMwinsInARow;
  75. Int winsInARow;
  76. Int maxWinsInARow;
  77. Int lossesInARow;
  78. Int maxLossesInARow;
  79. Int disconsInARow;
  80. Int maxDisconsInARow;
  81. Int desyncsInARow;
  82. Int maxDesyncsInARow;
  83. Int builtParticleCannon;
  84. Int builtNuke;
  85. Int builtSCUD;
  86. Int lastLadderPort;
  87. std::string lastLadderHost;
  88. void incorporate( const PSPlayerStats& other );
  89. };
  90. // this class encapsulates a request for the thread
  91. class PSRequest
  92. {
  93. public:
  94. PSRequest();
  95. enum
  96. {
  97. PSREQUEST_READPLAYERSTATS, // read stats for a player
  98. PSREQUEST_UPDATEPLAYERSTATS, // update stats on the server
  99. PSREQUEST_UPDATEPLAYERLOCALE, // update locale on the server
  100. PSREQUEST_READCDKEYSTATS, // read stats for a cdkey
  101. PSREQUEST_SENDGAMERESTOGAMESPY, // report game results to GameSpy
  102. PSREQUEST_MAX
  103. } requestType;
  104. // player stats for the *PLAYERSTATS
  105. PSPlayerStats player;
  106. // cdkey for READCDKEYSTATS;
  107. std::string cdkey;
  108. // our info for UPDATEPLAYERSTATS
  109. std::string nick;
  110. std::string password;
  111. std::string email;
  112. Bool addDiscon;
  113. Bool addDesync;
  114. Int lastHouse;
  115. // for GameRes
  116. std::string results;
  117. };
  118. //-------------------------------------------------------------------------
  119. // this class encapsulates a response from the thread
  120. class PSResponse
  121. {
  122. public:
  123. enum
  124. {
  125. PSRESPONSE_PLAYERSTATS,
  126. PSRESPONSE_COULDNOTCONNECT,
  127. PSRESPONSE_PREORDER,
  128. PSRESPONSE_MAX
  129. } responseType;
  130. // player stats for the *PLAYERSTATS
  131. PSPlayerStats player;
  132. // preorder flag
  133. Bool preorder;
  134. };
  135. //-------------------------------------------------------------------------
  136. // this is the actual message queue used to pass messages between threads
  137. class GameSpyPSMessageQueueInterface
  138. {
  139. public:
  140. virtual ~GameSpyPSMessageQueueInterface() {}
  141. virtual void startThread( void ) = 0;
  142. virtual void endThread( void ) = 0;
  143. virtual Bool isThreadRunning( void ) = 0;
  144. virtual void addRequest( const PSRequest& req ) = 0;
  145. virtual Bool getRequest( PSRequest& req ) = 0;
  146. virtual void addResponse( const PSResponse& resp ) = 0;
  147. virtual Bool getResponse( PSResponse& resp ) = 0;
  148. // called from the main thread
  149. virtual void trackPlayerStats( PSPlayerStats stats ) = 0;
  150. virtual PSPlayerStats findPlayerStatsByID( Int id ) = 0;
  151. static GameSpyPSMessageQueueInterface* createNewMessageQueue( void );
  152. static std::string formatPlayerKVPairs( PSPlayerStats stats );
  153. static PSPlayerStats parsePlayerKVPairs( std::string kvPairs );
  154. };
  155. extern GameSpyPSMessageQueueInterface *TheGameSpyPSMessageQueue;
  156. #endif // __PERSISTENTSTORAGETHREAD_H__