WOLUser.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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/WOLUser.h $
  22. *
  23. * DESCRIPTION
  24. *
  25. * PROGRAMMER
  26. * $Author: Steve_t $
  27. *
  28. * VERSION INFO
  29. * $Revision: 19 $
  30. * $Modtime: 10/10/02 10:17a $
  31. *
  32. ******************************************************************************/
  33. #ifndef __WOLUSER_H__
  34. #define __WOLUSER_H__
  35. // Disable warning about exception handling not being enabled.
  36. #pragma warning(disable : 4530)
  37. #include <atlbase.h>
  38. #include "RefCounted.h"
  39. #include "RefPtr.h"
  40. #include <WWLib\Notify.h>
  41. #include <WWLib\WideString.h>
  42. #include "WOLChannel.h"
  43. #include "WOLSquad.h"
  44. #include "WOLLadder.h"
  45. namespace WOL
  46. {
  47. #include <wolapi\wolapi.h>
  48. #include <wolapi\chatdefs.h>
  49. }
  50. #if defined(_MSC_VER)
  51. #pragma warning(push, 3)
  52. #endif
  53. #include <vector>
  54. #if defined(_MSC_VER)
  55. #pragma warning(pop)
  56. #endif
  57. namespace WWOnline {
  58. typedef enum
  59. {
  60. USERLOCATION_UNKNOWN = 0,
  61. USERLOCATION_OFFLINE,
  62. USERLOCATION_HIDING,
  63. USERLOCATION_NO_CHANNEL,
  64. USERLOCATION_IN_CHANNEL
  65. } UserLocation;
  66. class UserData :
  67. public RefCounted
  68. {
  69. public:
  70. // Create new User
  71. static RefPtr<UserData> Create(const WOL::User&);
  72. static RefPtr<UserData> Create(const wchar_t*);
  73. // Get WOL::User data
  74. WOL::User& GetData(void)
  75. {return mData;}
  76. void UpdateData(const WOL::User&);
  77. // Get user's name
  78. const WideStringClass& GetName(void) const
  79. {return mUserName;}
  80. // Check if this user is the one logged in.
  81. bool IsMe(void) const
  82. {return ((mData.flags & CHAT_USER_MYSELF) == CHAT_USER_MYSELF);}
  83. // Check if this user is the channel owner.
  84. bool IsChannelOwner(void) const
  85. {return ((mData.flags & CHAT_USER_CHANNELOWNER) == CHAT_USER_CHANNELOWNER);}
  86. // Check if this user has the floor to speak
  87. bool HasVoice(void) const
  88. {return ((mData.flags & CHAT_USER_VOICE) == CHAT_USER_VOICE);}
  89. // Check if this user is squelched
  90. bool IsSquelched(void) const
  91. {return ((mData.flags & CHAT_USER_SQUELCHED) == CHAT_USER_SQUELCHED);}
  92. // Squelch this user
  93. void Squelch(bool onoff);
  94. // Get the users location (IE: Offline, Hiding, In channel, etc...)
  95. UserLocation GetLocation(void) const
  96. {return mLocation;}
  97. // Set the users location
  98. void SetLocation(UserLocation location);
  99. // Get the channel the user is in (If available)
  100. const RefPtr<ChannelData> GetChannel(void)
  101. {return mChannel;}
  102. // Set the channel the user is in
  103. void SetChannel(const RefPtr<ChannelData>& channel);
  104. // Get user's clan ID
  105. unsigned long GetSquadID(void) const
  106. {return mData.squadID;}
  107. // Get access user's Clan data (This is shared with all other users in the same clan)
  108. RefPtr<SquadData> GetSquad(void) const
  109. {return mSquad;}
  110. // Set user's clan data
  111. void SetSquad(const RefPtr<SquadData>&);
  112. // Get user's team
  113. int GetTeam(void) const
  114. {return mData.team;}
  115. // Set user's team
  116. void SetTeam(int);
  117. // Get user's locale (IE: US, Germany, Korea, etc...)
  118. WOL::Locale GetLocale(void) const
  119. {return mData.locale;}
  120. // Set user's locale
  121. void SetLocale(WOL::Locale);
  122. // Set user's ladder
  123. void SetLadder(const RefPtr<LadderData>&);
  124. // Get user's ladder
  125. RefPtr<LadderData> GetLadder(void) const
  126. {return mUserLadder;}
  127. // Get the ladder ranking data for the users clan
  128. RefPtr<LadderData> GetClanLadder(void) const;
  129. void SetTeamLadder(const RefPtr<LadderData>&);
  130. RefPtr<LadderData> GetTeamLadder(void) const
  131. {return mTeamLadder;}
  132. void SetLadderFromType(const RefPtr<LadderData>& ladder, LadderType ladderType);
  133. RefPtr<LadderData> GetLadderFromType(LadderType ladderType);
  134. unsigned long mKickTimer;
  135. private:
  136. UserData(const WOL::User&);
  137. virtual ~UserData();
  138. // Prevent copy and assignment
  139. UserData(const UserData&);
  140. const UserData& operator=(const UserData&);
  141. WOL::User mData;
  142. WideStringClass mUserName;
  143. UserLocation mLocation;
  144. int mUserTeam;
  145. RefPtr<ChannelData> mChannel;
  146. RefPtr<SquadData> mSquad;
  147. RefPtr<LadderData> mUserLadder;
  148. RefPtr<LadderData> mTeamLadder;
  149. };
  150. typedef std::vector< RefPtr<UserData> > UserList;
  151. class UserEvent :
  152. public TypedEvent< UserEvent, const RefPtr<UserData> >
  153. {
  154. public:
  155. enum Event {Error = 0, NewData, Join, Leave, Located, Kicked, Banned, Locale, SquadInfo, LadderInfo};
  156. Event GetEvent(void) const
  157. {return mEvent;}
  158. UserEvent(Event event, const RefPtr<UserData>& user) :
  159. TypedEvent< UserEvent, const RefPtr<UserData> >(user),
  160. mEvent(event)
  161. {}
  162. ~UserEvent()
  163. {}
  164. private:
  165. Event mEvent;
  166. };
  167. class BuddyEvent :
  168. public TypedEvent< BuddyEvent, const UserList >
  169. {
  170. public:
  171. enum Event {Added = 0, Deleted, NewList};
  172. Event GetEvent(void) const
  173. {return mEvent;}
  174. BuddyEvent(Event event, const UserList& list) :
  175. TypedEvent<BuddyEvent, const UserList>(list),
  176. mEvent(event)
  177. {}
  178. ~BuddyEvent()
  179. {}
  180. private:
  181. Event mEvent;
  182. };
  183. class NativeWOLUserList
  184. {
  185. public:
  186. NativeWOLUserList(const UserList& users);
  187. ~NativeWOLUserList();
  188. operator const WOL::User*(void)
  189. {return mNativeList;}
  190. operator WOL::User*(void)
  191. {return mNativeList;}
  192. protected:
  193. NativeWOLUserList(const NativeWOLUserList&);
  194. const NativeWOLUserList& operator=(const NativeWOLUserList&);
  195. WOL::User* mNativeList;
  196. };
  197. class UserIPEvent :
  198. public TypedEvent< UserIPEvent, const WOL::User >
  199. {
  200. public:
  201. enum Event {Error = 0, GotIP};
  202. Event GetEvent(void) const
  203. {return mEvent;}
  204. UserIPEvent(Event event, const WOL::User &user) :
  205. TypedEvent<UserIPEvent, const WOL::User>(user),
  206. mEvent(event)
  207. {}
  208. ~UserIPEvent()
  209. {}
  210. private:
  211. Event mEvent;
  212. };
  213. RefPtr<UserData> FindUserInList(const wchar_t* name, const UserList& list);
  214. RefPtr<UserData> RemoveUserInList(const wchar_t* name, UserList& list);
  215. } // namespace WWOnline
  216. #endif // __WOLUSER_H__