WOLAPIOB.H 15 KB

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