WOLChannel.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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/WOLChannel.h $
  22. *
  23. * DESCRIPTION
  24. * Westwood Online channel representation.
  25. *
  26. * PROGRAMMER
  27. * Denzil E. Long, Jr.
  28. * $Author: Denzil_l $
  29. *
  30. * VERSION INFO
  31. * $Revision: 17 $
  32. * $Modtime: 11/08/01 5:05p $
  33. *
  34. ******************************************************************************/
  35. #ifndef __WOLCHANNEL_H__
  36. #define __WOLCHANNEL_H__
  37. #include "RefCounted.h"
  38. #include "RefPtr.h"
  39. #include <WWLib\Notify.h>
  40. #include <WWLib\WideString.h>
  41. namespace WOL
  42. {
  43. #include <WOLAPI\wolapi.h>
  44. }
  45. #if defined(_MSC_VER)
  46. #pragma warning(push, 3)
  47. #endif
  48. #include <list>
  49. #if defined(_MSC_VER)
  50. #pragma warning(pop)
  51. #endif
  52. namespace WWOnline {
  53. class ChannelData :
  54. public RefCounted
  55. {
  56. public:
  57. static RefPtr<ChannelData> Create(const WOL::Channel&);
  58. static RefPtr<ChannelData> Create(const wchar_t* name, const wchar_t* password, int type);
  59. const WideStringClass& GetName(void)
  60. const {return mChannelName;}
  61. int GetType(void) const
  62. {return mData.type;}
  63. void SetLatency(int latency);
  64. int GetLatency(void) const
  65. {return mData.latency;}
  66. bool IsHidden(void) const
  67. {return (mData.hidden != 0);}
  68. void SetTopic(const char* topic);
  69. const char* GetTopic(void) const
  70. {return (const char*)mData.topic;}
  71. void SetExtraInfo(const char* exInfo);
  72. const char* GetExtraInfo(void) const
  73. {return (const char*)mData.exInfo;}
  74. // Check if this channel requires a password to join.
  75. bool IsPassworded(void) const;
  76. // Set the channels minimum and maximum users allowed.
  77. void SetMinMaxUsers(unsigned int minUsers, unsigned int maxUsers);
  78. // Get the minimum number of users for game.
  79. inline unsigned int GetMinUsers(void) const
  80. {return mData.minUsers;}
  81. // Get the maximum number of users for game.
  82. inline unsigned int GetMaxUsers(void) const
  83. {return mData.maxUsers;}
  84. inline unsigned int GetCurrentUsers(void) const
  85. {return mData.currentUsers;}
  86. // Set official status
  87. void SetOfficial(bool official);
  88. // Test if this channel is an official Westwood channel
  89. inline bool IsOfficial(void) const
  90. {return (mData.official != 0);}
  91. // Set the tournament type this channel is hosting (0 = none)
  92. void SetTournament(unsigned int tournamentType);
  93. // Get the tournament type for this channel
  94. inline unsigned int GetTournament(void) const
  95. {return mData.tournament;}
  96. inline unsigned int GetFlags(void) const
  97. {return mData.flags;}
  98. WOL::Channel& GetData(void)
  99. {return mData;}
  100. void UpdateData(const WOL::Channel&);
  101. protected:
  102. ChannelData(const WOL::Channel&);
  103. ChannelData(const wchar_t* name, const wchar_t* password, int type);
  104. virtual ~ChannelData();
  105. ChannelData(const ChannelData&);
  106. const ChannelData& operator=(const ChannelData&);
  107. WOL::Channel mData;
  108. WideStringClass mChannelName;
  109. };
  110. typedef enum
  111. {
  112. ChannelError = -1,
  113. ChannelLeft = 0,
  114. ChannelJoined,
  115. ChannelCreated,
  116. ChannelNotFound,
  117. ChannelExists,
  118. ChannelBadPassword,
  119. ChannelFull,
  120. ChannelBanned,
  121. ChannelKicked,
  122. ChannelNewData,
  123. ChannelLeaving
  124. } ChannelStatus;
  125. ChannelStatus GetChannelStatusFromHResult(HRESULT result);
  126. const wchar_t* GetChannelStatusDescription(ChannelStatus status);
  127. class ChannelEvent :
  128. public TypedEvent< ChannelEvent, const RefPtr<ChannelData> >
  129. {
  130. public:
  131. ChannelStatus GetStatus(void) const
  132. {return mStatus;}
  133. ChannelEvent(ChannelStatus status, const RefPtr<ChannelData>& channel) :
  134. TypedEvent< ChannelEvent, const RefPtr<ChannelData> >(channel),
  135. mStatus(status)
  136. {}
  137. ~ChannelEvent()
  138. {}
  139. protected:
  140. ChannelStatus mStatus;
  141. };
  142. typedef std::list< RefPtr<ChannelData> > ChannelList;
  143. class ChannelListEvent :
  144. public TypedEvent<ChannelListEvent, ChannelList>
  145. {
  146. public:
  147. typedef enum {Error = -1, NewList, Update, Remove} Event;
  148. Event GetEvent(void) const
  149. {return mEvent;}
  150. int GetChannelType(void)
  151. {return mType;}
  152. ChannelListEvent(Event event, ChannelList& list, int type) :
  153. TypedEvent<ChannelListEvent, ChannelList>(list),
  154. mEvent(event),
  155. mType(type)
  156. {}
  157. ~ChannelListEvent()
  158. {}
  159. protected:
  160. Event mEvent;
  161. int mType;
  162. };
  163. ChannelList::iterator FindChannelNode(ChannelList& list, const char* name);
  164. RefPtr<ChannelData> FindChannelInList(ChannelList& list, const wchar_t* name);
  165. RefPtr<ChannelData> FindChannelInList(ChannelList& list, const char* name);
  166. } // namespace WWOnline
  167. #endif // __WOLCHANNEL_H__