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