PeerDefs.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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: PeerDefs.h //////////////////////////////////////////////////////
  24. // Generals GameSpy Peer (chat) definitions
  25. // Author: Matthew D. Campbell, June 2002
  26. #pragma once
  27. #ifndef __PEERDEFS_H__
  28. #define __PEERDEFS_H__
  29. #include "GameSpy/Peer/Peer.h"
  30. #include "GameSpy/GP/GP.h"
  31. #include "GameClient/Color.h"
  32. #include "Common/STLTypedefs.h"
  33. #include "GameNetwork/GameSpy/StagingRoomGameInfo.h"
  34. class GameWindow;
  35. class PSPlayerStats;
  36. typedef std::set<AsciiString> IgnoreList;
  37. typedef std::map<Int, AsciiString> SavedIgnoreMap;
  38. enum RCItemType
  39. {
  40. ITEM_BUDDY,
  41. ITEM_REQUEST,
  42. ITEM_NONBUDDY,
  43. ITEM_NONE,
  44. };
  45. class GameSpyRCMenuData
  46. {
  47. public:
  48. AsciiString m_nick;
  49. GPProfile m_id;
  50. RCItemType m_itemType;
  51. };
  52. class BuddyInfo
  53. {
  54. public:
  55. GPProfile m_id;
  56. AsciiString m_name;
  57. AsciiString m_email;
  58. AsciiString m_countryCode;
  59. GPEnum m_status;
  60. UnicodeString m_statusString;
  61. UnicodeString m_locationString;
  62. };
  63. typedef std::map<GPProfile, BuddyInfo> BuddyInfoMap;
  64. class BuddyMessage
  65. {
  66. public:
  67. UnsignedInt m_timestamp;
  68. GPProfile m_senderID;
  69. AsciiString m_senderNick;
  70. GPProfile m_recipientID;
  71. AsciiString m_recipientNick;
  72. UnicodeString m_message;
  73. };
  74. typedef std::list<BuddyMessage> BuddyMessageList;
  75. class GameSpyGroupRoom
  76. {
  77. public:
  78. GameSpyGroupRoom() { m_name = AsciiString::TheEmptyString; m_translatedName = UnicodeString::TheEmptyString; m_groupID = m_numWaiting = m_maxWaiting = m_numGames = m_numPlaying = 0; }
  79. AsciiString m_name;
  80. UnicodeString m_translatedName;
  81. Int m_groupID;
  82. Int m_numWaiting;
  83. Int m_maxWaiting;
  84. Int m_numGames;
  85. Int m_numPlaying;
  86. };
  87. typedef std::map<Int, GameSpyGroupRoom> GroupRoomMap;
  88. class Transport;
  89. class NAT;
  90. typedef std::map<Int, GameSpyStagingRoom *> StagingRoomMap;
  91. class PlayerInfo
  92. {
  93. public:
  94. PlayerInfo() { m_name = m_locale = AsciiString::TheEmptyString; m_wins = m_losses = m_rankPoints = m_side = m_preorder = m_profileID = m_flags = 0; }
  95. AsciiString m_name;
  96. AsciiString m_locale;
  97. Int m_wins;
  98. Int m_losses;
  99. Int m_profileID;
  100. Int m_flags;
  101. Int m_rankPoints;
  102. Int m_side;
  103. Int m_preorder;
  104. Bool isIgnored( void );
  105. };
  106. struct AsciiComparator
  107. {
  108. bool operator()(AsciiString s1, AsciiString s2) const;
  109. };
  110. typedef std::map<AsciiString, PlayerInfo, AsciiComparator> PlayerInfoMap;
  111. enum GameSpyColors {
  112. GSCOLOR_DEFAULT = 0,
  113. GSCOLOR_CURRENTROOM,
  114. GSCOLOR_ROOM,
  115. GSCOLOR_GAME,
  116. GSCOLOR_GAME_FULL,
  117. GSCOLOR_GAME_CRCMISMATCH,
  118. GSCOLOR_PLAYER_NORMAL,
  119. GSCOLOR_PLAYER_OWNER,
  120. GSCOLOR_PLAYER_BUDDY,
  121. GSCOLOR_PLAYER_SELF,
  122. GSCOLOR_PLAYER_IGNORED,
  123. GSCOLOR_CHAT_NORMAL,
  124. GSCOLOR_CHAT_EMOTE,
  125. GSCOLOR_CHAT_OWNER,
  126. GSCOLOR_CHAT_OWNER_EMOTE,
  127. GSCOLOR_CHAT_PRIVATE,
  128. GSCOLOR_CHAT_PRIVATE_EMOTE,
  129. GSCOLOR_CHAT_PRIVATE_OWNER,
  130. GSCOLOR_CHAT_PRIVATE_OWNER_EMOTE,
  131. GSCOLOR_CHAT_BUDDY,
  132. GSCOLOR_CHAT_SELF,
  133. GSCOLOR_ACCEPT_TRUE,
  134. GSCOLOR_ACCEPT_FALSE,
  135. GSCOLOR_MAP_SELECTED,
  136. GSCOLOR_MAP_UNSELECTED,
  137. GSCOLOR_MOTD,
  138. GSCOLOR_MOTD_HEADING,
  139. GSCOLOR_MAX
  140. };
  141. extern Color GameSpyColor[GSCOLOR_MAX];
  142. enum GameSpyBuddyStatus {
  143. BUDDY_OFFLINE,
  144. BUDDY_ONLINE,
  145. BUDDY_LOBBY,
  146. BUDDY_STAGING,
  147. BUDDY_LOADING,
  148. BUDDY_PLAYING,
  149. BUDDY_MATCHING,
  150. BUDDY_MAX
  151. };
  152. // ---------------------------------------------------
  153. // this class holds info used in the main thread
  154. class GameSpyInfoInterface
  155. {
  156. public:
  157. virtual ~GameSpyInfoInterface() {};
  158. virtual void reset( void ) {};
  159. virtual void clearGroupRoomList( void ) = 0;
  160. virtual GroupRoomMap* getGroupRoomList( void ) = 0;
  161. virtual void addGroupRoom( GameSpyGroupRoom room ) = 0;
  162. virtual Bool gotGroupRoomList( void ) = 0;
  163. virtual void joinGroupRoom( Int groupID ) = 0;
  164. virtual void leaveGroupRoom( void ) = 0;
  165. virtual void joinBestGroupRoom( void ) = 0;
  166. virtual void setCurrentGroupRoom( Int groupID ) = 0;
  167. virtual Int getCurrentGroupRoom( void ) = 0;
  168. virtual void updatePlayerInfo( PlayerInfo pi, AsciiString oldNick = AsciiString::TheEmptyString ) = 0;
  169. virtual void playerLeftGroupRoom( AsciiString nick ) = 0;
  170. virtual PlayerInfoMap* getPlayerInfoMap( void ) = 0;
  171. virtual BuddyInfoMap* getBuddyMap( void ) = 0;
  172. virtual BuddyInfoMap* getBuddyRequestMap( void ) = 0;
  173. virtual BuddyMessageList* getBuddyMessages( void ) = 0;
  174. virtual Bool isBuddy( Int id ) = 0;
  175. virtual void setLocalName( AsciiString name ) = 0;
  176. virtual AsciiString getLocalName( void ) = 0;
  177. virtual void setLocalProfileID( Int profileID ) = 0;
  178. virtual Int getLocalProfileID( void ) = 0;
  179. virtual AsciiString getLocalEmail( void ) = 0;
  180. virtual void setLocalEmail( AsciiString email ) = 0;
  181. virtual AsciiString getLocalPassword( void ) = 0;
  182. virtual void setLocalPassword( AsciiString passwd ) = 0;
  183. virtual void setLocalBaseName( AsciiString name ) = 0;
  184. virtual AsciiString getLocalBaseName( void ) = 0;
  185. virtual void setCachedLocalPlayerStats( PSPlayerStats stats ) = 0;
  186. virtual PSPlayerStats getCachedLocalPlayerStats( void ) = 0;
  187. virtual void clearStagingRoomList( void ) = 0;
  188. virtual StagingRoomMap* getStagingRoomList( void ) = 0;
  189. virtual GameSpyStagingRoom* findStagingRoomByID( Int id ) = 0;
  190. virtual void addStagingRoom( GameSpyStagingRoom room ) = 0;
  191. virtual void updateStagingRoom( GameSpyStagingRoom room ) = 0;
  192. virtual void removeStagingRoom( GameSpyStagingRoom room ) = 0;
  193. virtual Bool hasStagingRoomListChanged( void ) = 0;
  194. virtual void leaveStagingRoom( void ) = 0;
  195. virtual void markAsStagingRoomHost( void ) = 0;
  196. virtual void markAsStagingRoomJoiner( Int game ) = 0;
  197. virtual void sawFullGameList( void ) = 0;
  198. virtual Bool amIHost( void ) = 0;
  199. virtual GameSpyStagingRoom* getCurrentStagingRoom( void ) = 0;
  200. virtual void setGameOptions( void ) = 0;
  201. virtual Int getCurrentStagingRoomID( void ) = 0;
  202. virtual void setDisallowAsianText( Bool val ) = 0;
  203. virtual void setDisallowNonAsianText( Bool val ) = 0;
  204. virtual Bool getDisallowAsianText( void ) = 0;
  205. virtual Bool getDisallowNonAsianText(void ) = 0;
  206. // chat
  207. virtual void registerTextWindow( GameWindow *win ) = 0;
  208. virtual void unregisterTextWindow( GameWindow *win ) = 0;
  209. virtual Int addText( UnicodeString message, Color c, GameWindow *win ) = 0;
  210. virtual void addChat( PlayerInfo p, UnicodeString msg, Bool isPublic, Bool isAction, GameWindow *win ) = 0;
  211. virtual void addChat( AsciiString nick, Int profileID, UnicodeString msg, Bool isPublic, Bool isAction, GameWindow *win ) = 0;
  212. virtual Bool sendChat( UnicodeString message, Bool isAction, GameWindow *playerListbox ) = 0;
  213. virtual void setMOTD( const AsciiString& motd ) = 0;
  214. virtual const AsciiString& getMOTD( void ) = 0;
  215. virtual void setConfig( const AsciiString& config ) = 0;
  216. virtual const AsciiString& getConfig( void ) = 0;
  217. virtual void setPingString( const AsciiString& ping ) = 0;
  218. virtual const AsciiString& getPingString( void ) = 0;
  219. virtual Int getPingValue( const AsciiString& otherPing ) = 0;
  220. static GameSpyInfoInterface* createNewGameSpyInfoInterface( void );
  221. virtual void addToSavedIgnoreList( Int profileID, AsciiString nick ) = 0;
  222. virtual void removeFromSavedIgnoreList( Int profileID ) = 0;
  223. virtual Bool isSavedIgnored( Int profileID ) = 0;
  224. virtual SavedIgnoreMap returnSavedIgnoreList( void ) = 0;
  225. virtual void loadSavedIgnoreList( void ) = 0;
  226. virtual IgnoreList returnIgnoreList( void ) = 0;
  227. virtual void addToIgnoreList( AsciiString nick ) = 0;
  228. virtual void removeFromIgnoreList( AsciiString nick ) = 0;
  229. virtual Bool isIgnored( AsciiString nick ) = 0;
  230. virtual void setLocalIPs(UnsignedInt internalIP, UnsignedInt externalIP) = 0;
  231. virtual UnsignedInt getInternalIP(void) = 0;
  232. virtual UnsignedInt getExternalIP(void) = 0;
  233. virtual Bool isDisconnectedAfterGameStart(Int *reason) const = 0;
  234. virtual void markAsDisconnectedAfterGameStart(Int reason) = 0;
  235. virtual Bool didPlayerPreorder( Int profileID ) const = 0;
  236. virtual void markPlayerAsPreorder( Int profileID ) = 0;
  237. virtual void setMaxMessagesPerUpdate( Int num ) = 0;
  238. virtual Int getMaxMessagesPerUpdate( void ) = 0;
  239. virtual Int getAdditionalDisconnects( void ) = 0;
  240. virtual void clearAdditionalDisconnects( void ) = 0;
  241. virtual void readAdditionalDisconnects( void ) = 0;
  242. virtual void updateAdditionalGameSpyDisconnections(Int count) = 0;
  243. };
  244. extern GameSpyInfoInterface *TheGameSpyInfo;
  245. void WOLDisplayGameOptions( void );
  246. void WOLDisplaySlotList( void );
  247. Bool GetLocalChatConnectionAddress(AsciiString serverName, UnsignedShort serverPort, UnsignedInt& localIP);
  248. void SetLobbyAttemptHostJoin(Bool start);
  249. void SendStatsToOtherPlayers(const GameInfo *game);
  250. class PSPlayerStats;
  251. void GetAdditionalDisconnectsFromUserFile(PSPlayerStats *stats);
  252. extern Int GetAdditionalDisconnectsFromUserFile(Int playerID);
  253. //-------------------------------------------------------------------------
  254. // These functions set up the globals and threads neccessary for our GameSpy impl.
  255. void SetUpGameSpy( const char *motdBuffer, const char *configBuffer );
  256. void TearDownGameSpy( void );
  257. #endif // __PEERDEFS_H__