WOLGame.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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/WOLGame.cpp $
  22. *
  23. * DESCRIPTION
  24. *
  25. * PROGRAMMER
  26. * $Author: Steve_t $
  27. *
  28. * VERSION INFO
  29. * $Revision: 10 $
  30. * $Modtime: 8/21/02 12:30p $
  31. *
  32. ******************************************************************************/
  33. #include "always.h"
  34. #include "WOLGame.h"
  35. #include "WOLSession.h"
  36. #include "WOLChannel.h"
  37. #include "WOLString.h"
  38. #include "WOLErrorUtil.h"
  39. namespace WWOnline {
  40. /******************************************************************************
  41. *
  42. * NAME
  43. * GameStartEvent::GameStartEvent
  44. *
  45. * DESCRIPTION
  46. * Constructor
  47. *
  48. * INPUTS
  49. * Channel - Channel game is in.
  50. * UserList - List of users in game.
  51. * GameID - Game ID for this game.
  52. *
  53. * RESULT
  54. * NONE
  55. *
  56. ******************************************************************************/
  57. GameStartEvent::GameStartEvent(const RefPtr<ChannelData>& channel, const UserList& users, unsigned long gameID) :
  58. mResult(S_OK),
  59. mChannel(channel),
  60. mGameID(gameID)
  61. {
  62. for (unsigned int index = 0; index < users.size(); index++)
  63. {
  64. mPlayers.push_back(users[index]);
  65. }
  66. }
  67. /******************************************************************************
  68. *
  69. * NAME
  70. * GameStartEvent::GetErrorDescription
  71. *
  72. * DESCRIPTION
  73. * Get text description of error condition.
  74. *
  75. * INPUTS
  76. * NONE
  77. *
  78. * RESULT
  79. * ErrorText - Error text description.
  80. *
  81. ******************************************************************************/
  82. const char* GameStartEvent::GetErrorDescription(void) const
  83. {
  84. return GetChatErrorString(mResult);
  85. }
  86. /******************************************************************************
  87. *
  88. * NAME
  89. * GameStartWait::Create
  90. *
  91. * DESCRIPTION
  92. * Create a game start wait condition.
  93. *
  94. * INPUTS
  95. * Players - Players in game.
  96. *
  97. * RESULT
  98. * Wait - Wait condition to process for game start.
  99. *
  100. ******************************************************************************/
  101. RefPtr<GameStartWait> GameStartWait::Create(const UserList& players, void(*timeout_callback)(void))
  102. {
  103. return new GameStartWait(players, timeout_callback);
  104. }
  105. /******************************************************************************
  106. *
  107. * NAME
  108. * GameStartWait::GameStartWait
  109. *
  110. * DESCRIPTION
  111. * Constructor
  112. *
  113. * INPUTS
  114. * Players -
  115. *
  116. * RESULT
  117. * NONE
  118. *
  119. ******************************************************************************/
  120. GameStartWait::GameStartWait(const UserList& players, void(*timeout_callback)(void)) :
  121. SingleWait(WOLSTRING("WOL_GAMEIDFETCH")),
  122. mPlayers(players)
  123. {
  124. mTimeoutCallback = timeout_callback;
  125. WWDEBUG_SAY(("WOL: GameStartWait Create\n"));
  126. }
  127. /******************************************************************************
  128. *
  129. * NAME
  130. * GameStartWait::~GameStartWait
  131. *
  132. * DESCRIPTION
  133. * Destructor
  134. *
  135. * INPUTS
  136. * NONE
  137. *
  138. * RESULT
  139. * NONE
  140. *
  141. ******************************************************************************/
  142. GameStartWait::~GameStartWait()
  143. {
  144. WWDEBUG_SAY(("WOL: GameStartWait End %S\n", mEndText));
  145. }
  146. /******************************************************************************
  147. *
  148. * NAME
  149. * GameStartWait::WaitBeginning
  150. *
  151. * DESCRIPTION
  152. * Begin game start wait condition.
  153. *
  154. * INPUTS
  155. * NONE
  156. *
  157. * RESULT
  158. * NONE
  159. *
  160. ******************************************************************************/
  161. void GameStartWait::WaitBeginning(void)
  162. {
  163. WWDEBUG_SAY(("WOL: GameStartWait Begin\n"));
  164. RefPtr<Session> session = Session::GetInstance(false);
  165. if (!session.IsValid())
  166. {
  167. WWDEBUG_SAY(("WOLERROR: WOLSession not initialized\n"));
  168. EndWait(Error, WOLSTRING("WOL_NOTINITIALIZED"));
  169. }
  170. Observer<GameStartEvent>::NotifyMe(*session);
  171. HRESULT hr = session->GetChatObject()->RequestGameStart(mPlayers);
  172. if (FAILED(hr))
  173. {
  174. WWDEBUG_SAY(("WOLERROR: GameStartWait %s\n", GetChatErrorString(hr)));
  175. EndWait(Error, WOLSTRING("WOL_GAMEIDERROR"));
  176. }
  177. }
  178. /******************************************************************************
  179. *
  180. * NAME
  181. * GameStartWait::HandleNotification(GameStartEvent)
  182. *
  183. * DESCRIPTION
  184. * Handle game start.
  185. *
  186. * INPUTS
  187. * Event - Game start event.
  188. *
  189. * RESULT
  190. * NONE
  191. *
  192. ******************************************************************************/
  193. void GameStartWait::HandleNotification(GameStartEvent& start)
  194. {
  195. if (mEndResult == Waiting)
  196. {
  197. if (start.IsSuccess())
  198. {
  199. EndWait(ConditionMet, WOLSTRING("WOL_GAMEIDRECEIVED"));
  200. }
  201. else
  202. {
  203. const char* text = start.GetErrorDescription();
  204. WWDEBUG_SAY(("WOLERROR: GameStartWait %s\n", text));
  205. EndWait(Error, WOLSTRING(text));
  206. }
  207. }
  208. }
  209. //
  210. // Override base class to check for timeout
  211. //
  212. void GameStartWait::EndWait(WaitResult result, const wchar_t* endText)
  213. {
  214. WWDEBUG_SAY(("GameStartWait::EndWait\n"));
  215. if (result == TimeOut && mTimeoutCallback) {
  216. mTimeoutCallback();
  217. }
  218. SingleWait::EndWait(result, endText);
  219. }
  220. } // namespace WWOnline