RAWOLAPI.H 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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. #ifndef WIN32
  16. #error WOLAPI_INTEGRATION can't be specified for non WIN32 version!
  17. #endif
  18. // rawolapi.h - WOLAPI sinks declarations.
  19. // ajw 07/10/98
  20. // Based somewhat on Neal's Borlandized version, "chatapi.h".
  21. #ifndef RAWOLAPI_H
  22. #define RAWOLAPI_H
  23. #include "function.h"
  24. //#include "cominit.h"
  25. #include <stdio.h>
  26. // From OBJBASE.H
  27. #define interface struct
  28. // From RPCNDR.H
  29. #define DECLSPEC_UUID(x)
  30. #include <commctrl.h>
  31. //namespace WOL // namespace is workaround due to the use of "Server" as a global in Red Alert.
  32. // ajw - Can't use namespaces in Watcom 10.5 it seems...
  33. //{
  34. #include "wolapi\wolapi.h"
  35. #define IID_DEFINED
  36. //#include "wlib/wdebug.h"
  37. #include "wolapi\chatdefs.h"
  38. #include "wolapi\downloaddefs.h"
  39. #include "wolapi\ftpdefs.h"
  40. //};
  41. //using namespace WOL;
  42. #include <winerror.h>
  43. //#include <ocidl.h>
  44. #include <olectl.h>
  45. //***********************************************************************************************
  46. // For debugging chat defined hresults...
  47. void ChatDefAsText( char* szDesc, HRESULT hRes );
  48. void DebugChatDef( HRESULT hRes );
  49. int iChannelLobbyNumber( const unsigned char* szChannelName );
  50. #define REASONABLELOBBYINTERPRETEDNAMELEN 50
  51. void InterpretLobbyNumber( char* szLobbyNameToSet, int iLobby );
  52. class WolapiObject;
  53. #define MAXCHATSENDLENGTH 71 // Mainly aesthetic, and because of the length of edit line.
  54. enum CHANNELFILTER
  55. {
  56. CHANNELFILTER_NO,
  57. CHANNELFILTER_OFFICIAL,
  58. CHANNELFILTER_UNOFFICIAL,
  59. CHANNELFILTER_LOBBIES,
  60. CHANNELFILTER_LOCALLOBBYGAMES,
  61. };
  62. #define WOLCOLORREMAP_ACTION PCOLOR_GREY
  63. #define WOLCOLORREMAP_SELFSPEAKING PCOLOR_RED
  64. #define WOLCOLORREMAP_LOCALMACHINEMESS PCOLOR_REALLY_BLUE // Color of system messages that originate locally.
  65. #define WOLCOLORREMAP_PAGE PCOLOR_GOLD
  66. #define WOLCOLORREMAP_KICKORBAN PCOLOR_GREEN //LTBLUE
  67. #define WOLCOLORREMAP_PUBLICMESSAGE PCOLOR_NONE
  68. #define WOLCOLORREMAP_PRIVATEMESSAGE PCOLOR_ORANGE
  69. #define WOLSOUND_ERROR VOC_SYS_ERROR
  70. #define WOLSOUND_LOGIN VOC_RADAR_ON
  71. #define WOLSOUND_LOGOUT VOC_RADAR_OFF
  72. #define WOLSOUND_ENTERCHAN VOC_PLAYER_JOINED
  73. #define WOLSOUND_EXITCHAN VOC_PLAYER_LEFT
  74. #define WOLSOUND_ONPAGE VOC_INCOMING_MESSAGE
  75. #define WOLSOUND_KICKORBAN VOC_TANYA_KISS
  76. #define WOLSOUND_ENTERGAME VOC_INVULNERABLE
  77. #define WOLSOUND_EXITGAME VOC_DOOR
  78. enum DISCONNECT_PING_STATUS
  79. {
  80. PING_UNSTARTED,
  81. PING_WAITING,
  82. PING_GOOD,
  83. PING_BAD,
  84. };
  85. #define DISCONNECT_PING_COUNT 5
  86. //***********************************************************************************************
  87. class RAChatEventSink : /////public CComObjectRoot, /////public IConnectionPoint,
  88. public IChatEvent
  89. {
  90. public:
  91. RAChatEventSink( WolapiObject* pOwner );
  92. virtual ~RAChatEventSink();
  93. // BEGIN_COM_MAP(RAChatEventSink)
  94. // COM_INTERFACE_ENTRY(IChatEvent)
  95. // END_COM_MAP()
  96. // IUnknown
  97. STDMETHOD(QueryInterface)(const IID& iid, void **ppv);
  98. STDMETHOD_(ULONG,AddRef)();
  99. STDMETHOD_(ULONG,Release)();
  100. // IChatEvent
  101. STDMETHOD(OnServerList)(HRESULT res, Server* servers);
  102. STDMETHOD(OnLogout)(HRESULT r, User *user);
  103. STDMETHOD(OnBusy)(HRESULT r);
  104. STDMETHOD(OnIdle)(HRESULT r);
  105. STDMETHOD(OnPageSend)(HRESULT r);
  106. STDMETHOD(OnPaged)(HRESULT r, User *, LPCSTR);
  107. STDMETHOD(OnFind)(HRESULT r, Channel *);
  108. STDMETHOD(OnConnection)(HRESULT r,LPCSTR motd);
  109. STDMETHOD(OnChannelCreate)(HRESULT r, Channel *channel);
  110. STDMETHOD(OnChannelModify)(HRESULT r, Channel *channel);
  111. STDMETHOD(OnChannelJoin)(HRESULT r, Channel *channel, User *user);
  112. STDMETHOD(OnChannelLeave)(HRESULT r, Channel *channel, User *user);
  113. STDMETHOD(OnChannelTopic)(HRESULT r, Channel *channel, LPCSTR topic);
  114. STDMETHOD(OnGroupList)(HRESULT r, Group *);
  115. STDMETHOD(OnPublicMessage)(HRESULT r, Channel *channel, User *user, LPCSTR text);
  116. STDMETHOD(OnPrivateMessage)(HRESULT r, User *user,LPCSTR text);
  117. STDMETHOD(OnSystemMessage)(HRESULT r, LPCSTR);
  118. STDMETHOD(OnNetStatus)(HRESULT r);
  119. STDMETHOD(OnChannelList)(HRESULT r, Channel* channels);
  120. STDMETHOD(OnUserList)(HRESULT r, Channel* channel, User* users);
  121. STDMETHOD(OnUpdateList)(HRESULT res, Update *);
  122. STDMETHOD(OnServerError)(HRESULT res);
  123. STDMETHOD(OnMessageOfTheDay)(HRESULT res, LPCSTR);
  124. STDMETHOD(OnPrivateAction)(HRESULT r, User *, LPCSTR);
  125. STDMETHOD(OnPublicAction)(HRESULT r, Channel *, User *, LPCSTR);
  126. STDMETHOD(OnPrivateGameOptions)(HRESULT r, User *, LPCSTR);
  127. STDMETHOD(OnPublicGameOptions)(HRESULT r, Channel *, User *, LPCSTR);
  128. STDMETHOD(OnGameStart)(HRESULT r, Channel *, User *, int);
  129. STDMETHOD(OnUserKick)(HRESULT r, Channel *, User *, User *);
  130. STDMETHOD(OnUserIP)(HRESULT r, User *);
  131. STDMETHOD(OnServerError)(HRESULT res, LPCSTR ircmsg);
  132. STDMETHOD(OnServerBannedYou)(HRESULT r, time_t bannedTill);
  133. STDMETHOD(OnUserFlags)(HRESULT r, LPCSTR name, unsigned int flags, unsigned int mask);
  134. STDMETHOD(OnChannelBan)(HRESULT r, LPCSTR name, int banned);
  135. unsigned long GetPlayerGameIP( const char* szPlayerName ) const;
  136. void DeleteUserList(); // Deletes from heap all users pointed to through pUserList.
  137. void DeleteUserIPList();
  138. unsigned long GetUserIP( const char* szName ) const;
  139. void ActionEggSound( const char* szMessage );
  140. public:
  141. // These vars are rather hackish. Basically, they are set before a callback is expected to be fired, and
  142. // then checked immediately afterwards. The rest of the time, their values are meaningless.
  143. // The idea is to force wolapi act in a modal way. In many places I "block" until a callback response to a
  144. // wolapi request has been received.
  145. bool bRequestServerListWait;
  146. bool bRequestConnectionWait;
  147. bool bRequestLogoutWait;
  148. // bool bRequestChannelListWait;
  149. bool bRequestChannelJoinWait;
  150. bool bRequestChannelLeaveWait;
  151. bool bRequestUserListWait;
  152. bool bRequestChannelCreateWait;
  153. bool bRequestFindWait;
  154. bool bRequestPageWait;
  155. bool bRequestChannelListForLobbiesWait;
  156. bool bIgnoreChannelLists; // Used to temporarily turn off response to channel lists, when we are in the midst
  157. // of some processing that depends on pChannelList remaining constant.
  158. bool bRequestGameStartWait;
  159. Server* pServer; // Server to connect to, acquired from OnServerList.
  160. bool bConnected; // True when user is logged in to chat server.
  161. bool bJoined; // True when user has joined a channel.
  162. Channel* pChannelList; // First element of channel list, or null.
  163. CHANNELFILTER ChannelFilter; // Affects what channels are included in channel list when built.
  164. User* pUserList; // First element of user list, or null.
  165. User* pUserTail; // Last element of user list, or null.
  166. char* szMotd; // Message of the day.
  167. HRESULT hresRequestConnectionError; // Used to pass error hresult.
  168. HRESULT hresRequestFindResult; // Used to pass hresult.
  169. Channel OnFindChannel;
  170. HRESULT hresRequestPageResult; // Used to pass hresult.
  171. HRESULT hresRequestJoinResult; // Used to pass hresult.
  172. bool bGotKickedTrigger; // Special flag meaning do some more processing after callback has exited.
  173. User* pGameUserList; // First element of start game user list, or null.
  174. int iGameID; // WW Online game id received from OnGameStart.
  175. // Is also a flag indicating "OnGameStart() called, TriggerGameStart() not yet called".
  176. User* pUserIPList; // List that holds user IP's, used for pinging in game channel.
  177. User* pUserIPListTail;
  178. protected:
  179. WolapiObject* pOwner; // Link back to the object that contains me.
  180. void DeleteChannelList(); // Deletes from heap all channels pointed to through pChannelList.
  181. bool DownloadUpdates( Update* pUpdateList, int iUpdates );
  182. bool bSpecialMessage( const char* szMessage );
  183. void InsertUserSorted( User* pUserNew );
  184. private:
  185. long m_cRef; // Reference Count
  186. };
  187. //***********************************************************************************************
  188. class RADownloadEventSink :
  189. /////////// public CComObjectRoot,
  190. public IDownloadEvent
  191. {
  192. public:
  193. RADownloadEventSink();
  194. virtual ~RADownloadEventSink() {};
  195. // BEGIN_COM_MAP(RADownloadEventSink)
  196. // COM_INTERFACE_ENTRY(IDownloadEvent)
  197. // END_COM_MAP()
  198. // IUnknown
  199. STDMETHOD(QueryInterface)(const IID& iid, void **ppv);
  200. STDMETHOD_(ULONG,AddRef)();
  201. STDMETHOD_(ULONG,Release)();
  202. // IDownloadEvent
  203. STDMETHOD(OnEnd)(void);
  204. STDMETHOD(OnError)(int error);
  205. STDMETHOD(OnProgressUpdate)(int bytesread, int totalsize, int timetaken, int timeleft);
  206. STDMETHOD(OnStatusUpdate)(int status);
  207. STDMETHOD(OnQueryResume)(void);
  208. public:
  209. bool bFlagEnd;
  210. bool bFlagError;
  211. bool bFlagProgressUpdate;
  212. bool bFlagStatusUpdate;
  213. bool bFlagQueryResume;
  214. int iBytesRead;
  215. int iTotalSize;
  216. int iTimeTaken;
  217. int iTimeLeft;
  218. int iStatus;
  219. bool bResumed;
  220. private:
  221. long m_cRef; // Ref count
  222. };
  223. //***********************************************************************************************
  224. class RANetUtilEventSink :
  225. // public CComObjectRoot,
  226. public INetUtilEvent
  227. {
  228. public:
  229. RANetUtilEventSink( WolapiObject* pOwner );
  230. virtual ~RANetUtilEventSink();
  231. //BEGIN_COM_MAP(CNetUtilEventSink)
  232. // COM_INTERFACE_ENTRY(INetUtilEvent)
  233. //END_COM_MAP()
  234. // IUnknown
  235. STDMETHOD(QueryInterface)(const IID& iid, void **ppv);
  236. STDMETHOD_(ULONG,AddRef)();
  237. STDMETHOD_(ULONG,Release)();
  238. // INetUtilEvent
  239. STDMETHOD(OnGameresSent)(HRESULT res);
  240. STDMETHOD(OnLadderList)(HRESULT res, Ladder *list, int totalCount, long timeStamp, int keyRung);
  241. STDMETHOD(OnPing)(HRESULT res, int time, unsigned long ip, int handle);
  242. void DeleteLadderList(); // Deletes from heap all users pointed to through pUserList.
  243. unsigned int GetUserRank( const char* szName, bool bRankRA );
  244. Ladder* pLadderList; // First element of Ladder list, or null.
  245. Ladder* pLadderTail; // Last element of Ladder list, or null.
  246. Ladder* pLadderListAM; // First element of Aftermath Ladder list, or null.
  247. Ladder* pLadderTailAM; // Last element of Aftermath Ladder list, or null.
  248. protected:
  249. WolapiObject* pOwner; // Link back to the object that contains me.
  250. private:
  251. long m_cRef; // Reference Count
  252. };
  253. //***********************************************************************************************
  254. // SKU, reported to WOLAPI for the purpose of finding patches.
  255. #ifdef ENGLISH
  256. #define GAME_SKU 0x1500
  257. #else
  258. #ifdef GERMAN
  259. #define GAME_SKU 0x1502
  260. #else
  261. #define GAME_SKU 0x1503
  262. #endif
  263. #endif
  264. #define GAME_VERSION 0x00030003
  265. #define GAME_TYPE 21
  266. #define LOB_PREFIX "Lob_21_"
  267. // Sent to gameres server in order to receive Red Alert or Aftermath ladder rankings. (Sent in RequestLadderList.)
  268. #define LADDER_CODE_RA 1005
  269. #define LADDER_CODE_AM 500
  270. #endif
  271. #endif