WOLSession.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. /*
  2. ** Command & Conquer Renegade(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. /******************************************************************************
  19. *
  20. * FILE
  21. * $Archive: /Commando/Code/WWOnline/WOLSession.h $
  22. *
  23. * DESCRIPTION
  24. * WOLSession is the entryway to Westwood Online. An object of this type
  25. * must exist in order to do anything WOL related. There should only be one
  26. * instance of this; retrieve it via GetInstance.
  27. *
  28. * PROGRAMMER
  29. * Steve Clinard & Denzil E. Long, Jr.
  30. * $Author: Denzil_l $
  31. *
  32. * VERSION INFO
  33. * $Revision: 54 $
  34. * $Modtime: 1/25/02 5:02p $
  35. *
  36. ******************************************************************************/
  37. #ifndef __WOLSESSION_H__
  38. #define __WOLSESSION_H__
  39. #include <atlbase.h>
  40. #include "WOLLoginInfo.h"
  41. #include "WOLUser.h"
  42. #include "WOLChannel.h"
  43. #include "WOLPing.h"
  44. #include "WOLAgeCheck.h"
  45. #include "WOLDownload.h"
  46. #include "WOLPageMsg.h"
  47. #include "RefPtr.h"
  48. #include <WWLib\Notify.h>
  49. #include <WWLib\WideString.h>
  50. namespace WOL
  51. {
  52. #include <WOLAPI\wolapi.h>
  53. }
  54. #if defined(_MSC_VER)
  55. #pragma warning(push, 3)
  56. #endif
  57. #include <vector>
  58. #if defined(_MSC_VER)
  59. #pragma warning(pop)
  60. #endif
  61. class WaitCondition;
  62. namespace WWOnline {
  63. // The version of WOLAPI this product was build with.
  64. #define WOLAPI_BUILD_VERSION MAKELONG(19,1)
  65. class ChatObserver;
  66. class NetUtilObserver;
  67. class ServerError;
  68. class ServerData;
  69. class ChannelData;
  70. class LadderServerData;
  71. class GameResultsServerData;
  72. class WDTServerData;
  73. class GameOptionsMessage;
  74. class GameStartEvent;
  75. class SquadEvent;
  76. class ChatMessage;
  77. class ConnectWait;
  78. class DisconnectWait;
  79. class IRCServerData;
  80. typedef std::vector< RefPtr<IRCServerData> > IRCServerList;
  81. class MGLServerData;
  82. typedef std::vector< RefPtr<MGLServerData> > MGLServerList;
  83. class PingServerData;
  84. typedef std::vector< RefPtr<PingServerData> > PingServerList;
  85. typedef std::vector< RefPtr<LadderData> > LadderList;
  86. enum ConnectionStatus {ConnectionDisconnected, ConnectionDisconnecting, ConnectionConnecting, ConnectionConnected};
  87. class MessageOfTheDayType;
  88. typedef TypedEvent<MessageOfTheDayType, WideStringClass> MessageOfTheDayEvent;
  89. // Information request flags
  90. #define REQUEST_LOCALE (1<<0L)
  91. #define REQUEST_SQUADINFO (1<<1L)
  92. #define REQUEST_TEAMINFO (1<<2L)
  93. #define REQUEST_LADDERINFO (1<<3L)
  94. #define REQUEST_ALL (REQUEST_LOCALE|REQUEST_SQUADINFO|REQUEST_TEAMINFO|REQUEST_LADDERINFO)
  95. #define REQUEST_NONE 0
  96. class Session :
  97. public RefCounted,
  98. public Notifier<ServerError>,
  99. public Notifier<ConnectionStatus>,
  100. public Notifier<IRCServerList>,
  101. public Notifier<ChannelListEvent>,
  102. public Notifier<UserList>,
  103. public Notifier<UserEvent>,
  104. public Notifier<BuddyEvent>,
  105. public Notifier<ChannelEvent>,
  106. public Notifier<MessageOfTheDayEvent>,
  107. public Notifier<ChatMessage>,
  108. public Notifier<PageMessage>,
  109. public Notifier<PageSendStatus>,
  110. public Notifier<GameOptionsMessage>,
  111. public Notifier<GameStartEvent>,
  112. public Notifier<RawPing>,
  113. public Notifier<LadderInfoEvent>,
  114. public Notifier<LadderList>,
  115. public Notifier<SquadEvent>,
  116. public Notifier<NewLoginInfoEvent>,
  117. public Notifier<AgeCheckEvent>,
  118. public Notifier<UserIPEvent>
  119. {
  120. public:
  121. // Retrieve WWOnline session instance.
  122. static RefPtr<Session> GetInstance(bool okToCreate = false);
  123. void Reset(void);
  124. // Yeild time for WWOnline processing.
  125. virtual bool Process(void);
  126. // Retrieve pointer to IChat object
  127. const CComPtr<WOL::IChat>& GetChatObject(void) const
  128. {return mChat;}
  129. // Retrieve pointer to INetUtil object
  130. const CComPtr<WOL::INetUtil>& GetNetUtilObject(void) const
  131. {return mNetUtil;}
  132. // Obtain current patch download list
  133. DownloadList& GetPatchDownloadList(void)
  134. {return mPatchFiles;}
  135. // Retrieve connection status
  136. ConnectionStatus GetConnectionStatus(void) const
  137. {return mCurrentConnectionStatus;}
  138. //-------------------------------------------------------------------------
  139. // Server Methods
  140. //-------------------------------------------------------------------------
  141. // Retrieve new server list
  142. RefPtr<WaitCondition> GetNewServerList(void);
  143. // Submit request for new server list
  144. bool RequestServerList(bool just_kidding = false);
  145. // Obtain current server list
  146. const IRCServerList& GetIRCServerList(void)
  147. {return mIRCServers;}
  148. const MGLServerList& GetManglerServerList(void)
  149. {return mMGLServers;}
  150. const PingServerList& GetPingServerList(void)
  151. {return mPingServers;}
  152. // Retrieve current server
  153. const RefPtr<IRCServerData>& GetCurrentServer(void) const
  154. {return mCurrentServer;}
  155. // Retrieve current login
  156. const RefPtr<LoginInfo>& GetCurrentLogin(void) const
  157. {return mCurrentLogin;}
  158. // Login into server
  159. RefPtr<WaitCondition> LoginServer(const RefPtr<IRCServerData>&, const RefPtr<LoginInfo>&);
  160. // Disconnection from current server.
  161. RefPtr<WaitCondition> Logout(void);
  162. // Retrieve message of the day
  163. const WideStringClass& GetMessageOfTheDay(void) const
  164. {return mMessageOfTheDay;}
  165. //-------------------------------------------------------------------------
  166. // Channel Methods
  167. //-------------------------------------------------------------------------
  168. bool EnableProgressiveChannelList(bool enable);
  169. // Submit request for new channel list
  170. bool RequestChannelList(int channelType, bool autoPing);
  171. // Look for a channel with the specified name in the current channel list.
  172. RefPtr<ChannelData> FindChannel(const wchar_t* name);
  173. RefPtr<ChannelData> FindChannel(const char* name);
  174. // Create a new channel
  175. RefPtr<WaitCondition> CreateChannel(const wchar_t* channelName, const wchar_t* password, int type);
  176. RefPtr<WaitCondition> CreateChannel(const RefPtr<ChannelData>&, const wchar_t* password);
  177. // Join a channel
  178. RefPtr<WaitCondition> JoinChannel(const RefPtr<ChannelData>& channel, const wchar_t* password);
  179. RefPtr<WaitCondition> JoinChannel(const wchar_t* name, const wchar_t* password, int type);
  180. bool RequestChannelJoin(const RefPtr<ChannelData>& channel, const wchar_t* password);
  181. // Leave the current channel.
  182. RefPtr<WaitCondition> LeaveChannel(void);
  183. bool RequestLeaveChannel(void);
  184. // Obtain current channel
  185. const RefPtr<ChannelData>& GetCurrentChannel(void) const
  186. {return mCurrentChannel;}
  187. const char* GetChannelTopic(void) const;
  188. // Send the current channels topic to the server.
  189. bool SendChannelTopic(void);
  190. // Send the current channels extra info to the server.
  191. bool SendChannelExtraInfo(void);
  192. // Retrieve current channel status
  193. ChannelStatus GetChannelStatus(void) const
  194. {return mCurrentChannelStatus;}
  195. // Retrieve new chat channel list
  196. RefPtr<WaitCondition> GetNewChatChannelList(void);
  197. // Obtain current channel list.
  198. const ChannelList& GetChatChannelList(void)
  199. {return mChatChannels;}
  200. RefPtr<ChannelData> FindChatChannel(const wchar_t* name);
  201. RefPtr<ChannelData> FindChatChannel(const char* name);
  202. // Retrieve new game channel list
  203. RefPtr<WaitCondition> GetNewGameChannelList(void);
  204. // Submit request for new game channel list.
  205. bool RequestGameChannelList(void);
  206. // Obtain current game channel list
  207. const ChannelList& GetGameChannelList(void)
  208. {return mGameChannels;}
  209. RefPtr<ChannelData> FindGameChannel(const wchar_t* name);
  210. RefPtr<ChannelData> FindGameChannel(const char* name);
  211. //-------------------------------------------------------------------------
  212. // User Methods
  213. //-------------------------------------------------------------------------
  214. // Request a new user list
  215. bool RequestUserList(void);
  216. // Obtian current user list
  217. const UserList& GetUserList(void)
  218. {return mUsers;}
  219. // Find specified user
  220. RefPtr<UserData> FindUser(const wchar_t* userName);
  221. // Obtain current user
  222. RefPtr<UserData> GetCurrentUser(void) const
  223. {return mCurrentUser;}
  224. // Test is specified user is the current one.
  225. bool IsCurrentUser(const RefPtr<UserData>&) const;
  226. bool IsCurrentUser(const wchar_t* username) const;
  227. // Change the locale for the user currently logged in.
  228. bool ChangeCurrentUserLocale(WOL::Locale locale);
  229. // Squelch / unsquelch user messages. Prevents messages from specified user.
  230. bool SquelchUser(const RefPtr<UserData>& user, bool squelched);
  231. // Kick a user from the current channel. Kicking is only allowed for
  232. // channel owners.
  233. bool KickUser(const wchar_t* username);
  234. // Ban / unban a user from the current channel. Banning is only allowed for
  235. // channel owners.
  236. bool BanUser(const wchar_t* username, bool banned);
  237. // Send a page to a user.
  238. bool PageUser(const wchar_t* userName, const wchar_t* message);
  239. // Request a users online location
  240. unsigned long GetAutoRequestFlags(void) const
  241. {return mAutoRequestFlags;}
  242. void SetAutoRequestFlags(unsigned long flags)
  243. {mAutoRequestFlags = flags;}
  244. void RequestUserDetails(const RefPtr<UserData>& user, unsigned long requestFlags);
  245. void RequestLocateUser(const wchar_t* userName);
  246. void RequestLocateUser(const RefPtr<UserData>& user);
  247. // Request users locale
  248. void RequestUserLocale(const wchar_t* userName);
  249. // Request information about a squad by Squad ID
  250. void RequestSquadInfoByID(unsigned long squadID);
  251. // Request information about a squad by member name
  252. void RequestSquadInfoByMemberName(const wchar_t* memberName);
  253. // Request users team information
  254. void RequestTeamInfo(const wchar_t* userName);
  255. // Request users ladder information
  256. void RequestLadderInfo(const wchar_t* name, unsigned long type);
  257. //-------------------------------------------------------------------------
  258. // Buddy Methods
  259. //-------------------------------------------------------------------------
  260. // Obtian current buddy list
  261. const UserList& GetBuddyList(void) const
  262. {return mBuddies;}
  263. // Find specified buddy
  264. RefPtr<UserData> FindBuddy(const wchar_t* buddyName)
  265. {return FindUserInList(buddyName, mBuddies);}
  266. bool RequestBuddyList(void);
  267. bool AddBuddy(const wchar_t* buddyName);
  268. bool RemoveBuddy(const wchar_t* buddyName);
  269. //-------------------------------------------------------------------------
  270. // Chatting Methods
  271. //-------------------------------------------------------------------------
  272. bool AllowFindPage(bool allowFind, bool allowPage);
  273. // Enable / disable filtering of bad language
  274. bool SetBadLanguageFilter(bool enabled);
  275. bool SendPublicMessage(const char* message);
  276. bool SendPublicMessage(const wchar_t* message);
  277. bool SendPublicAction(const char* action);
  278. bool SendPublicAction(const wchar_t* action);
  279. bool SendPrivateMessage(const wchar_t* username, const wchar_t* message);
  280. bool SendPrivateMessage(const UserList& users, const char* message);
  281. bool SendPrivateMessage(const UserList& users, const wchar_t* message);
  282. bool SendPrivateAction(const UserList& users, const char* action);
  283. bool SendPrivateAction(const UserList& users, const wchar_t* action);
  284. bool SendPublicGameOptions(const char* options);
  285. bool SendPrivateGameOptions(const wchar_t* user, const char* options);
  286. bool SendPrivateGameOptions(const UserList& users, const char* options);
  287. //-------------------------------------------------------------------------
  288. // Utility Methods
  289. //-------------------------------------------------------------------------
  290. void GetLocaleStrings(std::vector<WideStringClass>& localeStrings);
  291. void EnablePinging(bool enable);
  292. void RequestPing(const char* address, int timeout = 1000);
  293. unsigned int GetPendingPingCount(void) const
  294. {return mPingsPending;}
  295. bool SendGameResults(unsigned char* packet, unsigned long length);
  296. bool RequestUserIP(char *user_name);
  297. time_t GetServerTime(void)
  298. {return mServerTime;}
  299. //-------------------------------------------------------------------------
  300. // IGR (Internet Gaming Room) support
  301. //-------------------------------------------------------------------------
  302. bool IsStoreLoginAllowed(void);
  303. bool IsAutoLoginAllowed(void);
  304. bool IsRunRegAppAllowed(void);
  305. //-------------------------------------------------------------------------
  306. // Insider status support
  307. //-------------------------------------------------------------------------
  308. void RequestInsiderStatus(void);
  309. void RequestServerTime(void);
  310. bool IsCurrUserInsider(void)
  311. {return mIsInsider;}
  312. //-------------------------------------------------------------------------
  313. // Event notification
  314. //-------------------------------------------------------------------------
  315. DECLARE_NOTIFIER(ServerError)
  316. DECLARE_NOTIFIER(ConnectionStatus)
  317. DECLARE_NOTIFIER(IRCServerList)
  318. DECLARE_NOTIFIER(ChannelListEvent)
  319. DECLARE_NOTIFIER(UserList)
  320. DECLARE_NOTIFIER(UserEvent)
  321. DECLARE_NOTIFIER(BuddyEvent)
  322. DECLARE_NOTIFIER(ChannelEvent)
  323. DECLARE_NOTIFIER(MessageOfTheDayEvent)
  324. DECLARE_NOTIFIER(ChatMessage)
  325. DECLARE_NOTIFIER(PageMessage)
  326. DECLARE_NOTIFIER(PageSendStatus)
  327. DECLARE_NOTIFIER(GameOptionsMessage)
  328. DECLARE_NOTIFIER(GameStartEvent)
  329. DECLARE_NOTIFIER(RawPing)
  330. DECLARE_NOTIFIER(LadderInfoEvent)
  331. DECLARE_NOTIFIER(LadderList)
  332. DECLARE_NOTIFIER(SquadEvent)
  333. DECLARE_NOTIFIER(NewLoginInfoEvent)
  334. DECLARE_NOTIFIER(AgeCheckEvent)
  335. DECLARE_NOTIFIER(UserIPEvent)
  336. protected:
  337. friend ChatObserver;
  338. friend NetUtilObserver;
  339. friend Download;
  340. friend ConnectWait;
  341. friend DisconnectWait;
  342. Session();
  343. virtual ~Session();
  344. // Disallow copy and assignment
  345. Session(const Session&);
  346. const Session& operator=(const Session&);
  347. virtual void ReleaseReference(void);
  348. bool FinalizeCreate(void);
  349. void UpdatePingServerTime(const char* name, int time);
  350. void AutoRequestUserDetails(const RefPtr<UserData>& user);
  351. RefPtr<UserData> GetUserOrBuddy(const wchar_t*);
  352. const CComPtr<WOL::IIGROptions>& GetIGRObject(void);
  353. private:
  354. void ClearServers(void);
  355. void MakeLocateUserRequests(void);
  356. void MakeSquadRequests(void);
  357. void MakeLocaleRequests(void);
  358. void MakeTeamRequests(void);
  359. void MakeLadderRequests(void);
  360. void MakePingRequests(void);
  361. CComPtr<WOL::IChat> mChat;
  362. CComPtr<WOL::IChatEvent> mChatEvents;
  363. unsigned long mChatCookie;
  364. CComPtr<WOL::INetUtil> mNetUtil;
  365. CComPtr<WOL::INetUtilEvent> mNetUtilEvents;
  366. unsigned long mNetUtilCookie;
  367. CComPtr<WOL::IIGROptions> mIGRObject;
  368. // Server data
  369. bool mRequestingServerList;
  370. IRCServerList mIRCServers;
  371. RefPtr<LadderServerData> mLadderServer;
  372. RefPtr<GameResultsServerData> mGameResultsServer;
  373. RefPtr<WDTServerData> mWDTServer;
  374. MGLServerList mMGLServers;
  375. PingServerList mPingServers;
  376. bool mIgnoreServerLists;
  377. // Insider status data
  378. bool mIsInsider;
  379. time_t mServerTime;
  380. // Patch data
  381. DownloadList mPatchFiles;
  382. // Connection state
  383. ConnectionStatus mCurrentConnectionStatus;
  384. RefPtr<IRCServerData> mPendingServer;
  385. RefPtr<IRCServerData> mCurrentServer;
  386. RefPtr<LoginInfo> mPendingLogin;
  387. RefPtr<LoginInfo> mCurrentLogin;
  388. // Channel data
  389. ChannelList mChatChannels;
  390. ChannelList mGameChannels;
  391. int mRequestedChannelType;
  392. ChannelList mIncommingChatChannels;
  393. ChannelList mIncommingGameChannels;
  394. RefPtr<ChannelData> mPendingChannel;
  395. RefPtr<ChannelData> mCurrentChannel;
  396. ChannelStatus mCurrentChannelStatus;
  397. // User data
  398. UserList mUsers;
  399. RefPtr<UserData> mCurrentUser;
  400. UserList mLocatePendingUsers;
  401. RefPtr<UserData> mLocatingUser;
  402. UserList mBuddies;
  403. unsigned long mAutoRequestFlags;
  404. // Squad Request queues
  405. typedef std::vector<WideStringClass> SquadRequestColl;
  406. SquadRequestColl mSquadRequests;
  407. SquadRequestColl mSquadPending;
  408. typedef std::vector<WideStringClass> LocaleRequestColl;
  409. LocaleRequestColl mLocaleRequests;
  410. typedef std::vector<WideStringClass> TeamRequestColl;
  411. TeamRequestColl mTeamRequests;
  412. typedef std::list<WideStringClass> LadderRequestList;
  413. LadderRequestList mLadderRequests;
  414. unsigned long mLadderPending;
  415. // Misc.
  416. WideStringClass mMessageOfTheDay;
  417. std::vector<RawPing> mPingRequests;
  418. unsigned int mPingsPending;
  419. int mPingEnable;
  420. unsigned long mLastUserDataRequestTime;
  421. static RefPtr<Session> _mInstance;
  422. };
  423. class ChatAdvisement :
  424. public RefCounted
  425. {
  426. public:
  427. static RefPtr<ChatAdvisement> Create(const CComPtr<WOL::IChat>&, const CComPtr<WOL::IChatEvent>&);
  428. private:
  429. ChatAdvisement(const CComPtr<WOL::IChat>&, const CComPtr<WOL::IChatEvent>&);
  430. virtual ~ChatAdvisement();
  431. // Prevent copy and assignment
  432. ChatAdvisement(const ChatAdvisement&);
  433. const ChatAdvisement& operator=(const ChatAdvisement&);
  434. CComPtr<WOL::IChat> mChat;
  435. unsigned long mChatCookie;
  436. };
  437. } // using namespace WWOnline
  438. #endif // __WOLSESSION_H__