WOLAPIOB.H 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. /*
  2. ** Command & Conquer Red Alert(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. #ifdef WOLAPI_INTEGRATION
  19. // WolapiOb.h
  20. // ajw 07/10/98
  21. // Class WolapiObject is mainly a container so I can avoid globals and keep things clean.
  22. // All WOLAPI interfacing will be done through this object. It's lifetime will begin when
  23. // API functions are first needed and end when we are finished with the API - this will
  24. // presumably parallel the duration of the user's connection to WOL.
  25. #ifndef WOLAPI_H
  26. #define WOLAPI_H
  27. #include "RAWolapi.h"
  28. #include "dibapi.h"
  29. #include "IconList.h"
  30. //***********************************************************************************************
  31. class IconListClass;
  32. class WOL_GameSetupDialog;
  33. class ToolTipClass;
  34. #define PUMPSLEEPDURATION 300 // Milliseconds between PumpMessages() calls.
  35. #define EMERGENCY_TIMEOUT 40000 // Longest we wait for a wolapi response before terminating everything.
  36. // Milliseconds between automatic behaviors.
  37. #define WOLAPIPUMPWAIT 300
  38. #define CHANNELUPDATEWAIT 45000
  39. #define WOL_NAME_LEN_MAX 10 // Includes null-terminator.
  40. #define WOL_PASSWORD_LEN 9 // Includes null-terminator.
  41. #define WOL_CHANNAME_LEN_MAX 17 // Includes null-terminator.
  42. #define WOL_CHANKEY_LEN_MAX 9 // Includes null-terminator.
  43. #define CHAT_USER_SQUELCHED 0x0004 // Will theoretically be added to the api and implemented.
  44. #define LOBBYPASSWORD "not_a_valid_password" // Password removed per Security review - LFeenanEA, 26th February 2025
  45. #define USERCANCELLED 1
  46. #define PATCHDOWNLOADED 2
  47. #define PATCHAVOIDED 3
  48. // Special hidden descriptors added to channel list items.
  49. // These serve double-duty as tooltip help text.
  50. #define CHANNELTYPE_TOP TXT_WOL_CHANNELTYPE_TOP
  51. #define CHANNELTYPE_OFFICIALCHAT TXT_WOL_CHANNELTYPE_OFFICIALCHAT
  52. #define CHANNELTYPE_USERCHAT TXT_WOL_CHANNELTYPE_USERCHAT
  53. #define CHANNELTYPE_GAMES TXT_WOL_CHANNELTYPE_GAMES
  54. #define CHANNELTYPE_GAMESOFTYPE "GamesOfType" // Not seen.
  55. #define CHANNELTYPE_CHATCHANNEL "ChatChannel" // Not seen.
  56. #define CHANNELTYPE_GAMECHANNEL "GameChannel" // Not seen.
  57. #define CHANNELTYPE_LOADING TXT_WOL_CHANNELTYPE_LOADING
  58. #define CHANNELTYPE_LOBBIES TXT_WOL_CHANNELTYPE_LOBBIES
  59. #define CHANNELTYPE_LOBBYCHANNEL "LobbyChannel" // Not seen.
  60. enum WOL_LEVEL
  61. {
  62. WOL_LEVEL_TOP, // Viewing top level menu choices.
  63. WOL_LEVEL_OFFICIALCHAT, // Viewing official chat channels.
  64. WOL_LEVEL_USERCHAT, // Viewing user chat channels.
  65. WOL_LEVEL_INCHATCHANNEL, // In a chat channel.
  66. WOL_LEVEL_GAMES, // Viewing types (skus) of games.
  67. WOL_LEVEL_GAMESOFTYPE, // Viewing game channels of a type.
  68. WOL_LEVEL_INGAMECHANNEL, // In a game channel.
  69. WOL_LEVEL_LOBBIES, // Viewing the game lobbies.
  70. WOL_LEVEL_INLOBBY, // In a "lobby" chat channel.
  71. WOL_LEVEL_INVALID
  72. };
  73. struct WOL_GAMETYPEINFO
  74. {
  75. int iGameType;
  76. char szName[128];
  77. char szURL[256];
  78. HDIB hDIB; // DIB handle.
  79. const char* pDIB; // What you get when you GlobalLock hDIB.
  80. };
  81. // Header values for game options messages. Note that 0 is not used!
  82. enum WOL_GAMEOPT
  83. {
  84. WOL_GAMEOPT_REQCOLOR = 1, // REQuest = guest asks game host for a color
  85. WOL_GAMEOPT_INFCOLOR, // INForm = game host tells guests color of a single player (not "accept-canceling")
  86. WOL_GAMEOPT_INFPARAMS, // host tells guests all common game params
  87. WOL_GAMEOPT_REQHOUSE, // guest tells host he's changed house (REQ because it's guest->host)
  88. WOL_GAMEOPT_INFHOUSE, // host tells guests about new house of a single player
  89. WOL_GAMEOPT_REQACCEPT, // guest tells host he accepts current params
  90. WOL_GAMEOPT_INFACCEPT, // host tells guests that a player accepted
  91. WOL_GAMEOPT_INFSTART, // host tell guests to go into wait for start mode
  92. WOL_GAMEOPT_REQSTART, // guest acknowledges WOL_GAMEOPT_INFSTART
  93. WOL_GAMEOPT_REQSTART_BUTNEEDSCENARIO, // guests acks WOL_GAMEOPT_INFSTART and asks for scenario download
  94. WOL_GAMEOPT_INFCANCELSTART, // host tells guests to cancel game start, as a change arrived or player joined/left
  95. WOL_GAMEOPT_INFGO, // host tells everyone to start
  96. WOL_GAMEOPT_INFNEWGUESTPLAYERINFO, // host tells new guest a lot of stuff about everyone that's in the game
  97. };
  98. enum DIBICON
  99. {
  100. DIBICON_OWNER,
  101. DIBICON_SQUELCH,
  102. DIBICON_LATENCY,
  103. DIBICON_ACCEPT,
  104. DIBICON_NOTACCEPT,
  105. DIBICON_USER,
  106. DIBICON_PRIVATE,
  107. DIBICON_TOURNAMENT,
  108. DIBICON_VOICE,
  109. };
  110. #define NUMDIBICONS 9
  111. struct DIBICONINFO
  112. {
  113. char szFile[50];
  114. HDIB hDIB;
  115. const char* pDIB;
  116. };
  117. // See SaveChat()...
  118. #define SAVECHATWIDTH 150 // Wider than text that will fit in the chat list window.
  119. struct CHATSAVE // What we save about each individual list item.
  120. {
  121. char szText[ SAVECHATWIDTH + 1 ];
  122. IconList_ItemExtras ItemExtras; // Only color is used.
  123. CHATSAVE* next;
  124. };
  125. struct CREATEGAMEINFO
  126. {
  127. enum GAMEKIND // Gets or'ed with lobby number in channel 'reserved' field.
  128. {
  129. RAGAME = 0x01000000,
  130. CSGAME = 0x02000000,
  131. AMGAME = 0x04000000,
  132. };
  133. bool bCreateGame; // True if user confirms game creation.
  134. int iPlayerMax; // NOT number of players, but maximum number allowed into game channel.
  135. int iPlayerCount; // Number of initial human players in game. Set at game launch, used for stats.
  136. bool bTournament;
  137. bool bPrivate;
  138. GAMEKIND GameKind;
  139. char szPassword[ WOL_CHANKEY_LEN_MAX ]; // If not blank, key for private game.
  140. };
  141. //***********************************************************************************************
  142. HPALETTE GetCurrentScreenPalette();
  143. void RemapDIBToPalette( HPALETTE hPal, const char* pDIB ); // Note: pDIB is treated as non-const.
  144. //char* LoadFileIntoMemory( const char* szFileName, int& iLength );
  145. //***********************************************************************************************
  146. class WolapiObject
  147. {
  148. public:
  149. WolapiObject();
  150. virtual ~WolapiObject();
  151. IChat* pChat;
  152. IDownload* pDownload;
  153. INetUtil* pNetUtil;
  154. DWORD dwChatAdvise; // Value that identifies the "connection" from chat to chatsink.
  155. DWORD dwDownloadAdvise;
  156. DWORD dwNetUtilAdvise;
  157. RAChatEventSink* pChatSink;
  158. RADownloadEventSink* pDownloadSink;
  159. RANetUtilEventSink* pNetUtilSink;
  160. bool bChatShownBefore;
  161. char szLadderServerHost[ 150 ];
  162. int iLadderServerPort;
  163. char szGameResServerHost1[ 150 ];
  164. int iGameResServerPort1;
  165. char szGameResServerHost2[ 150 ];
  166. int iGameResServerPort2;
  167. bool bFindEnabled; // I have to maintain these, though wolapi should do it for me...
  168. bool bPageEnabled; // Note they are initialized true, as is currently the case in wol.
  169. bool bLangFilter; //
  170. bool bAllGamesShown;
  171. bool bEggSounds; // Easter egg related. True = user actions trigger sounds.
  172. bool bEgg8Player; // True = 8 player games can be created. This is hidden so that we don't really have to support the feature...
  173. WOL_LEVEL CurrentLevel;
  174. WOL_LEVEL LastUpdateChannelCallLevel;
  175. char szMyName[WOL_NAME_LEN_MAX]; // Local user's name, valid while connected.
  176. char szMyRecord[ WOL_NAME_LEN_MAX + 80 ];
  177. char szMyRecordAM[ WOL_NAME_LEN_MAX + 80 ];
  178. bool bMyRecordUpdated; // True when szMyRecord has changed and not yet recognized by chat dialog.
  179. char szChannelListTitle[ 100 ];
  180. bool bChannelListTitleUpdated;
  181. char szChannelNameCurrent[WOL_CHANNAME_LEN_MAX];
  182. bool bChannelOwner;
  183. char szChannelReturnOnGameEnterFail[WOL_CHANNAME_LEN_MAX];
  184. int iLobbyReturnAfterGame; // When in game channel, part of the value of the channel's 'reserved' field.
  185. bool bReturningAfterGame;
  186. int iLobbyLast; // Number of last lobby we personally were in.
  187. // CREATEGAMEINFO::GAMEKIND GameKindCurrent; // Kind of game (Red Alert, CS, AM) we are in game setup for.
  188. CREATEGAMEINFO GameInfoCurrent; // Kind of game (Red Alert, CS, AM, tournament, private) we are in game setup for.
  189. bool bEnableNewAftermathUnits; // Used to pass game parameter back to init only.
  190. DWORD dwTimeNextWolapiPump;
  191. DWORD dwTimeNextChannelUpdate;
  192. DIBICONINFO DibIconInfos[ NUMDIBICONS ];
  193. HRESULT hresPatchResults; // Used when a patch has been downloaded or cancelled.
  194. WOL_GameSetupDialog* pGSupDlg; // When in a game channel, setting up a game; ptr to the dialog.
  195. bool bInGame; // True while playing a game.
  196. bool bConnectionDown; // Flag used while in a game, set to true if connection goes down.
  197. bool bGameServer; // Flag used while in a game, true if game server (host).
  198. unsigned long TournamentOpponentIP; // Valid while playing a tournament game. IP address of opponent.
  199. bool bPump_In_Call_Back; // Used to enable PumpMessages during Call_Back(), for when we're in a modal dialog.
  200. bool bSelfDestruct; // If set true, causes logout and deletion of wolapi object.
  201. char szWebBrowser[ _MAX_PATH + 1 ];
  202. // For "disconnect pinging".
  203. bool bDoingDisconnectPinging;
  204. bool bDisconnectPingingCompleted;
  205. int iDisconnectPingCurrent;
  206. DISCONNECT_PING_STATUS DisconnectPingResult_Server[ DISCONNECT_PING_COUNT ];
  207. DISCONNECT_PING_STATUS DisconnectPingResult_Opponent[ DISCONNECT_PING_COUNT ];
  208. // Used for in-game paging and responding.
  209. char szExternalPager[ WOL_NAME_LEN_MAX ]; // Last person to page me from outside the game, or blank for none.
  210. bool bFreezeExternalPager;
  211. bool bShowRankRA; // true = view RA rankings, false = view AM rankings
  212. bool bShowRankUpdated; // set true when bShowRankRA value changes
  213. // Standard wol buttons.
  214. char* pShpDiscon;
  215. char* pShpLeave;
  216. char* pShpRefresh;
  217. char* pShpSquelch;
  218. char* pShpBan;
  219. char* pShpKick;
  220. char* pShpFindpage;
  221. char* pShpOptions;
  222. char* pShpLadder;
  223. char* pShpHelp;
  224. ShapeButtonClass* pShpBtnDiscon;
  225. ShapeButtonClass* pShpBtnLeave;
  226. ShapeButtonClass* pShpBtnRefresh;
  227. ShapeButtonClass* pShpBtnSquelch;
  228. ShapeButtonClass* pShpBtnBan;
  229. ShapeButtonClass* pShpBtnKick;
  230. ShapeButtonClass* pShpBtnFindpage;
  231. ShapeButtonClass* pShpBtnOptions;
  232. ShapeButtonClass* pShpBtnLadder;
  233. ShapeButtonClass* pShpBtnHelp;
  234. ToolTipClass* pTTipDiscon;
  235. ToolTipClass* pTTipLeave;
  236. ToolTipClass* pTTipRefresh;
  237. ToolTipClass* pTTipSquelch;
  238. ToolTipClass* pTTipBan;
  239. ToolTipClass* pTTipKick;
  240. ToolTipClass* pTTipFindpage;
  241. ToolTipClass* pTTipOptions;
  242. ToolTipClass* pTTipLadder;
  243. ToolTipClass* pTTipHelp;
  244. WOL_GAMETYPEINFO OldRAGameTypeInfos[ 3 ]; // Used for storing old red alert icons only.
  245. public:
  246. bool bLoggedIn();
  247. void LinkToChatDlg( IconListClass* pILChat, IconListClass* pILChannels, IconListClass* pILUsers, StaticButtonClass* pStaticUsers );
  248. void ClearListPtrs();
  249. void LinkToGameDlg( IconListClass* pILDisc, IconListClass* pILPlayers );
  250. void PrepareButtonsAndIcons();
  251. bool bSetupCOMStuff();
  252. void UnsetupCOMStuff();
  253. void PrintMessage( const char* szText, PlayerColorType iColorRemap = PCOLOR_NONE );
  254. void PrintMessage( const char* szText, RemapControlType* pColorRemap );
  255. HRESULT GetChatServer();
  256. HRESULT AttemptLogin( const char* szName, const char* szPass, bool bPassIsMangled );
  257. void Logout();
  258. bool UpdateChannels( int iChannelType, CHANNELFILTER ChannelFilter, bool bAutoping );
  259. void OnChannelList();
  260. void ListChannels();
  261. HRESULT ChannelJoin( const char* szChannelName, const char* szKey );
  262. HRESULT ChannelJoin( Channel* pChannelToJoin );
  263. bool ChannelLeave();
  264. // bool UserList();
  265. bool ListChannelUsers();
  266. bool bItemMarkedAccepted( int iIndex );
  267. bool MarkItemAccepted( int iIndex, bool bAccept );
  268. bool bItemMarkedReadyToGo( int iIndex );
  269. void MarkItemReadyToGo( int iIndex, const char* szReadyState );
  270. bool bItemMarkedNeedScenario( int iIndex );
  271. void PullPlayerName_Into_From( char* szDest, const char* szSource );
  272. HousesType PullPlayerHouse_From( const char* szSource );
  273. void WritePlayerListItem( char* szDest, const char* szName, HousesType House );
  274. void RequestPlayerPings();
  275. void SendMessage( const char* szMessage, IconListClass& ILUsers, bool bAction );
  276. bool ChannelCreate( const char* szChannelName, const char* szKey, bool bGame = false, int iMaxPlayers = 0,
  277. bool bTournament = false, int iLobby = 0, CREATEGAMEINFO::GAMEKIND GameKind = CREATEGAMEINFO::RAGAME );
  278. void DoFindPage();
  279. HRESULT Locate( const char* szUser );
  280. HRESULT Page( const char* szUser, const char* szSend, bool bWaitForResult );
  281. void DoKick( IconListClass* pILUsersOrPlayers, bool bAndBan );
  282. bool Kick( User* pUserToKick );
  283. bool Ban( User* pUserToKick );
  284. void DoSquelch( IconListClass* pILUsersOrPlayers );
  285. bool Squelch( User* pUserToSquelch );
  286. void DoOptions();
  287. bool DoLadder();
  288. bool DoHelp();
  289. bool DoWebRegistration();
  290. bool DoGameAdvertising( const Channel* pChannel );
  291. bool SpawnBrowser( const char* szURL );
  292. void ChannelListTitle( const char* szTitle );
  293. bool EnterLevel_Top();
  294. bool EnterLevel_OfficialChat();
  295. bool EnterLevel_UserChat();
  296. bool EnterLevel_Games();
  297. bool EnterLevel_GamesOfType( WOL_GAMETYPEINFO* pGameTypeInfo );
  298. bool EnterLevel_Lobbies();
  299. bool OnEnteringChatChannel( const char* szChannelName, bool bICreatedChannel, int iLobby );
  300. void OnExitingChatChannel();
  301. bool ExitChatChannelForGameChannel();
  302. bool OnEnteringGameChannel( const char* szChannelName, bool bICreatedChannel, const CREATEGAMEINFO& CreateGameInfo );
  303. bool OnEnteringGameSetup();
  304. void OnFailedToEnterGameChannel();
  305. void OnExitingGameChannel();
  306. void RejoinLobbyAfterGame();
  307. bool RequestLadders( const char* szName );
  308. bool RequestIPs( const char* szName );
  309. void SaveChat();
  310. void RestoreChat();
  311. void AddHostLeftMessageToSavedChat( const char* szName );
  312. void AddMessageToSavedChat( const char* szMessage );
  313. void DeleteSavedChat();
  314. void GenericErrorMessage();
  315. bool GetNameOfBeginningLobby( char* szNameToSet );
  316. bool GetLobbyChannels();
  317. const char* pGameHostName();
  318. User* pGameHost();
  319. bool SendGameOpt( const char* szSend, User* pUserPriv );
  320. bool RequestGameStart();
  321. bool SendGo( const char* szSend );
  322. void Init_DisconnectPinging();
  323. bool Pump_DisconnectPinging();
  324. void DisconnectPingResultsString( char* szStringToSet );
  325. void SetOptionDefaults();
  326. void SetOptions( bool bEnableFind, bool bEnablePage, bool bLangFilterOn, bool bShowAllGames );
  327. protected:
  328. void GetGameTypeInfo( int iGameType, WOL_GAMETYPEINFO& GameTypeInfo, HPALETTE hPal );
  329. void* IconForGameType( int iGameType );
  330. const char* NameOfGameType( int iGameType ) const;
  331. const char* URLForGameType( int iGameType ) const;
  332. protected:
  333. // Used by the general chat dialog.
  334. IconListClass* pILChat; // Main messages list.
  335. IconListClass* pILChannels; // Channels list.
  336. IconListClass* pILUsers; // Users list.
  337. // IconListClass* pILDisc; // Main messages list. (pILChat is used.)
  338. IconListClass* pILPlayers; // Players list.
  339. StaticButtonClass* pStaticUsers; // Title for a users list. Used by main chat dialog only, not by game setup.
  340. WOL_GAMETYPEINFO* GameTypeInfos;
  341. unsigned int nGameTypeInfos;
  342. float fLatencyToIconWidth;
  343. CHATSAVE* pChatSaveList;
  344. CHATSAVE* pChatSaveLast;
  345. };
  346. #endif
  347. #endif