WOLBuddyMgr.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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/Commando/WOLBuddyMgr.h $
  22. *
  23. * DESCRIPTION
  24. *
  25. * PROGRAMMER
  26. * Denzil E. Long, Jr.
  27. * $Author: Denzil_l $
  28. *
  29. * VERSION INFO
  30. * $Revision: 14 $
  31. * $Modtime: 1/31/02 2:52p $
  32. *
  33. ******************************************************************************/
  34. #ifndef __WOLBUDDYMGR_H__
  35. #define __WOLBUDDYMGR_H__
  36. #include <WWOnline\RefPtr.h>
  37. #include <WWOnline\WOLSession.h>
  38. #include <WWOnline\WOLPageMsg.h>
  39. #include <WWLib\RefCount.h>
  40. #include <WWLib\Notify.h>
  41. #include <WWLib\Signaler.h>
  42. #include <WWLib\WideString.h>
  43. #if defined(_MSC_VER)
  44. #pragma warning(push, 3)
  45. #endif
  46. #include <vector>
  47. #if defined(_MSC_VER)
  48. #pragma warning(pop)
  49. #endif
  50. class DlgPasswordPrompt;
  51. class WOLBuddyMgr;
  52. typedef enum
  53. {
  54. BUDDYLIST_CHANGED = 1,
  55. IGNORELIST_CHANGED,
  56. BUDDYINFO_CHANGED
  57. } WOLBuddyMgrAction;
  58. typedef TypedActionPtr<WOLBuddyMgrAction, WOLBuddyMgr> WOLBuddyMgrEvent;
  59. typedef enum
  60. {
  61. PAGE_ERROR = 0,
  62. PAGE_NOT_THERE = 1,
  63. PAGE_TURNED_OFF,
  64. PAGE_SENT,
  65. PAGE_RECEIVED,
  66. INVITATION_RECEIVED,
  67. INVITATION_DECLINED
  68. } WOLPagedAction;
  69. typedef TypedActionPtr<WOLPagedAction, WWOnline::PageMessage> WOLPagedEvent;
  70. class WOLBuddyMgr :
  71. public RefCountClass,
  72. public Notifier<WOLBuddyMgrEvent>,
  73. public Notifier<WOLPagedEvent>,
  74. protected Observer<WWOnline::BuddyEvent>,
  75. protected Observer<WWOnline::UserEvent>,
  76. protected Observer<WWOnline::PageMessage>,
  77. protected Observer<WWOnline::PageSendStatus>,
  78. protected Signaler<DlgPasswordPrompt>
  79. {
  80. public:
  81. typedef std::vector< WideStringClass > IgnoreList;
  82. typedef WWOnline::PageMessageList PageList;
  83. typedef enum
  84. {
  85. DECLINE_MIN = 0,
  86. DECLINE_BYUSER = 1,
  87. DECLINE_NOTBUDDY,
  88. DECLINE_NOTAPPLICABLE,
  89. DECLINE_BUSY,
  90. DECLINE_MAX
  91. } DECLINE_REASON;
  92. static WOLBuddyMgr* GetInstance(bool createOK);
  93. // Get a description of a users location.
  94. static void GetLocationDescription(const RefPtr<WWOnline::UserData>& user, WideStringClass& description);
  95. // Request the buddy list anew.
  96. void RefreshBuddyList(void);
  97. // Get list of buddies
  98. const WWOnline::UserList& GetBuddyList(void) const
  99. {return mWOLSession->GetBuddyList();}
  100. // Get a user from our buddy list
  101. const RefPtr<WWOnline::UserData> FindBuddy(const WCHAR* name) const;
  102. // Add a user to our buddy list
  103. void AddBuddy(const WCHAR* name);
  104. // Remove a user from our buddy list
  105. void RemoveBuddy(const WCHAR* name);
  106. // Check if a user is in our buddy list
  107. bool IsBuddy(const WCHAR* name) const;
  108. // Request update to the location of our buddies.
  109. void RefreshBuddyInfo(void);
  110. // Add a user to the ignore list
  111. void AddIgnore(const WCHAR* name);
  112. // Remove a user from the ignore list.
  113. void RemoveIgnore(const WCHAR* name);
  114. // Check if a user is in the ignore list.
  115. bool IsIgnored(const WCHAR* name) const;
  116. // Get a list of usernames we are ignoring
  117. const IgnoreList& GetIngoreList(void) const
  118. {return mIgnoreList;}
  119. const PageList& GetPageList(void) const
  120. {return mPageList;}
  121. // Enable the display of a dialog when paged.
  122. // This function sets an internal counter that determines whether a dialog
  123. // should be displayed when a page message is received.
  124. void ShowPagedDialog(void);
  125. // Disable the display of a dialog when paged.
  126. // This function sets an internal counter that determines whether a dialog
  127. // should be displayed when a page message is received.
  128. void HidePagedDialog(void);
  129. // Clear all the queued pages.
  130. void ClearPageList(void);
  131. // Get the name of the last user who we received a page from.
  132. const WCHAR* GetLastPagersName(void) const
  133. {return mLastPagersName;}
  134. // Send a page message to user
  135. void PageUser(const WCHAR* name, const WCHAR* message);
  136. // Join a user at his location
  137. void JoinUser(const RefPtr<WWOnline::UserData>& user);
  138. // Check if we are in a position to invite users.
  139. bool CanInviteUsers(void) const;
  140. // Invite a user to our location
  141. void InviteUser(const WCHAR* username, const WCHAR* message);
  142. // Decline an invitation to join a user.
  143. void DeclineInvitation(const WCHAR* username, DECLINE_REASON reason = DECLINE_BYUSER);
  144. protected:
  145. WOLBuddyMgr();
  146. ~WOLBuddyMgr();
  147. bool FinalizeCreate(void);
  148. void LoadIgnoreList(void);
  149. void SaveIgnoreList(void);
  150. bool IsCommand(const WCHAR* message);
  151. void ProcessPendingJoin(void);
  152. void GotoPendingJoinLocation(const wchar_t* password);
  153. void ReceiveSignal(DlgPasswordPrompt&);
  154. bool IsInvitation(const WCHAR* message);
  155. void InvitationReceived(WWOnline::PageMessage& page);
  156. void DisplayInvitation(const RefPtr<WWOnline::UserData>& user, const WCHAR* message);
  157. bool IsInvitationDeclined(const WCHAR* message);
  158. void InvitationDeclined(const WCHAR* username, DECLINE_REASON reaon);
  159. void HandleNotification(WWOnline::BuddyEvent&);
  160. void HandleNotification(WWOnline::UserEvent&);
  161. void HandleNotification(WWOnline::PageMessage&);
  162. void HandleNotification(WWOnline::PageSendStatus&);
  163. DECLARE_NOTIFIER(WOLBuddyMgrEvent)
  164. DECLARE_NOTIFIER(WOLPagedEvent)
  165. private:
  166. static WOLBuddyMgr* _mInstance;
  167. RefPtr<WWOnline::Session> mWOLSession;
  168. IgnoreList mIgnoreList;
  169. PageList mPageList;
  170. PageList mInvitations;
  171. WideStringClass mLastPagersName;
  172. unsigned long mHidePagedDialog;
  173. RefPtr<WWOnline::UserData> mPendingJoin;
  174. };
  175. #endif __WOLBUDDYMGR_H__