RAWOLAPI.H 11 KB

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