gamespyauthmgr.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Commando/gamespyauthmgr.cpp $*
  25. * *
  26. * $Author:: Tom_s $*
  27. * *
  28. * $Modtime:: 2/22/02 5:41p $*
  29. * *
  30. * $Revision:: 3 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "gamespyauthmgr.h"
  36. #include "gamespyscchallengeevent.h"
  37. #include "playermanager.h"
  38. #include "cnetwork.h"
  39. #include "gamespyadmin.h"
  40. #include "cdkeyauth.h"
  41. #include "sctextobj.h"
  42. #include "translatedb.h"
  43. #include "string_ids.h"
  44. //
  45. // Class statics
  46. //
  47. //-----------------------------------------------------------------------------
  48. void
  49. cGameSpyAuthMgr::Think
  50. (
  51. void
  52. )
  53. {
  54. WWASSERT(cNetwork::I_Am_Server());
  55. WWASSERT(cGameSpyAdmin::Is_Gamespy_Game());
  56. //
  57. // Process all the players
  58. //
  59. WWASSERT(cPlayerManager::Get_Player_Object_List() != NULL);
  60. for (
  61. SLNode<cPlayer> * player_node = cPlayerManager::Get_Player_Object_List()->Head();
  62. player_node != NULL;
  63. player_node = player_node->Next())
  64. {
  65. cPlayer * p_player = player_node->Data();
  66. WWASSERT(p_player != NULL);
  67. if (!p_player->Is_Alive_And_Kicking())
  68. {
  69. continue;
  70. }
  71. switch (p_player->Get_GameSpy_Auth_State())
  72. {
  73. case GAMESPY_AUTH_STATE_INITIAL:
  74. {
  75. if (cNetwork::I_Am_Client() && p_player->Get_Id() == cNetwork::Get_My_Id())
  76. {
  77. //
  78. // Do not bother authenticating the server's local client.
  79. //
  80. p_player->Set_GameSpy_Auth_State(GAMESPY_AUTH_STATE_ACCEPTED);
  81. }
  82. else
  83. {
  84. //
  85. // Challenge this player
  86. //
  87. StringClass challenge_string;
  88. challenge_string.Format("%s", CCDKeyAuth::GenChallenge(8));
  89. p_player->Set_GameSpy_Auth_State(GAMESPY_AUTH_STATE_CHALLENGED);
  90. p_player->Set_GameSpy_Challenge_String(challenge_string);
  91. cGameSpyScChallengeEvent * p_event = new cGameSpyScChallengeEvent;
  92. p_event->Init(p_player->Get_Id(), challenge_string);
  93. }
  94. break;
  95. }
  96. case GAMESPY_AUTH_STATE_CHALLENGED:
  97. {
  98. DWORD time_now_ms = TIMEGETTIME();
  99. if (time_now_ms - p_player->Get_GameSpy_Auth_State_Entry_Time_Ms() >
  100. CHALLENGE_RESPONSE_TIMEOUT_MS)
  101. {
  102. //
  103. // We challenged this guy and he hasn't responded in the required
  104. // time. We are going to have to boot him out.
  105. //
  106. int player_id = p_player->Get_Id();
  107. WWDEBUG_SAY(("cGameSpyAuthMgr::Think: player %d timed out on challenge response.\n",
  108. player_id));
  109. //p_player->Set_GameSpy_Auth_State(GAMESPY_AUTH_STATE_REJECTING);
  110. //Evict_Player(player_id);
  111. cGameSpyAuthMgr::Initiate_Auth_Rejection(player_id);
  112. }
  113. break;
  114. }
  115. case GAMESPY_AUTH_STATE_VALIDATING:
  116. {
  117. //
  118. // At this stage I am not implementing any timeout for GameSpy to
  119. // authenticate this user.
  120. //
  121. break;
  122. }
  123. case GAMESPY_AUTH_STATE_ACCEPTED:
  124. {
  125. //
  126. // The only peaceful, harmonious state.
  127. //
  128. break;
  129. }
  130. case GAMESPY_AUTH_STATE_REJECTING:
  131. {
  132. DWORD time_now_ms = TIMEGETTIME();
  133. if (time_now_ms - p_player->Get_GameSpy_Auth_State_Entry_Time_Ms() >
  134. REJECTION_DELAY_MS)
  135. {
  136. p_player->Set_GameSpy_Auth_State(GAMESPY_AUTH_STATE_REJECTED);
  137. Evict_Player(p_player->Get_Id());
  138. }
  139. break;
  140. }
  141. case GAMESPY_AUTH_STATE_REJECTED:
  142. {
  143. //
  144. // Do nothing
  145. //
  146. break;
  147. }
  148. default:
  149. DIE;
  150. }
  151. }
  152. }
  153. //-----------------------------------------------------------------------------
  154. void
  155. cGameSpyAuthMgr::Initiate_Auth_Rejection
  156. (
  157. int player_id
  158. )
  159. {
  160. WWDEBUG_SAY(("cGameSpyAuthMgr::Initiate_Auth_Rejection(%d)\n", player_id));
  161. WWASSERT(cNetwork::I_Am_Server());
  162. WWASSERT(cGameSpyAdmin::Is_Gamespy_Game());
  163. cPlayer * p_player = cPlayerManager::Find_Player(player_id);
  164. if (p_player != NULL)
  165. {
  166. cScTextObj * p_message = new cScTextObj;
  167. //p_message->Init(L"CD Authentication failed. Please quit.", TEXT_MESSAGE_PRIVATE, true, HOST_TEXT_SENDER, player_id);
  168. p_message->Init(TRANSLATE(IDS_MP_CD_AUTH_FAILED), TEXT_MESSAGE_PRIVATE, true, HOST_TEXT_SENDER, player_id);
  169. p_player->Set_GameSpy_Auth_State(GAMESPY_AUTH_STATE_REJECTING);
  170. }
  171. }
  172. //-----------------------------------------------------------------------------
  173. void
  174. cGameSpyAuthMgr::Evict_Player
  175. (
  176. int player_id
  177. )
  178. {
  179. WWDEBUG_SAY(("cGameSpyAuthMgr::Evict_Player(%d)\n", player_id));
  180. WWASSERT(cNetwork::I_Am_Server());
  181. WWASSERT(cGameSpyAdmin::Is_Gamespy_Game());
  182. //
  183. // The behaviour presently is fairly brutal - no feedback to evicted player.
  184. // This is fine if he is a cracker, but other cases exist. TODO_AUTH.
  185. //
  186. cNetwork::Server_Kill_Connection(player_id);
  187. cNetwork::Cleanup_After_Client(player_id);
  188. }
  189. //-----------------------------------------------------------------------------
  190. LPCSTR
  191. cGameSpyAuthMgr::Describe_Auth_State
  192. (
  193. GAMESPY_AUTH_STATE_ENUM state
  194. )
  195. {
  196. switch (state)
  197. {
  198. case GAMESPY_AUTH_STATE_INITIAL: return "INITIAL";
  199. case GAMESPY_AUTH_STATE_CHALLENGED: return "CHALLENGED";
  200. case GAMESPY_AUTH_STATE_VALIDATING: return "VALIDATING";
  201. case GAMESPY_AUTH_STATE_ACCEPTED: return "ACCEPTED";
  202. case GAMESPY_AUTH_STATE_REJECTING: return "REJECTING";
  203. case GAMESPY_AUTH_STATE_REJECTED: return "REJECTED";
  204. default: DIE; return "bollocks"; // avoid compiler warning;
  205. }
  206. }