gamespycschallengeresponseevent.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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/gamespycschallengeresponseevent.cpp $*
  25. * *
  26. * $Author:: Bhayes $*
  27. * *
  28. * $Modtime:: 3/22/02 12:32p $*
  29. * *
  30. * $Revision:: 5 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "gamespycschallengeresponseevent.h"
  36. #include "networkobjectfactory.h"
  37. #include "cnetwork.h"
  38. #include "apppackettypes.h"
  39. #include "networkobjectmgr.h"
  40. #include "playermanager.h"
  41. #include "CDKeyAuth.h"
  42. DECLARE_NETWORKOBJECT_FACTORY(cGameSpyCsChallengeResponseEvent, NETCLASSID_GAMESPYCSCHALLENGERESPONSEEVENT);
  43. //-----------------------------------------------------------------------------
  44. cGameSpyCsChallengeResponseEvent::cGameSpyCsChallengeResponseEvent
  45. (
  46. void
  47. )
  48. {
  49. ClientId = -1;
  50. ChallengeResponseString.Format("");
  51. Set_App_Packet_Type(APPPACKETTYPE_GAMESPYCSCHALLENGERESPONSEEVENT);
  52. }
  53. //-----------------------------------------------------------------------------
  54. void
  55. cGameSpyCsChallengeResponseEvent::Init
  56. (
  57. StringClass & challenge_string
  58. )
  59. {
  60. WWDEBUG_SAY(("cGameSpyCsChallengeResponseEvent::Init\n"));
  61. WWASSERT(cNetwork::I_Am_Client());
  62. ClientId = cNetwork::Get_My_Id();
  63. //TODO_AUTH - construct ChallengeResponseString here from challenge_string,
  64. // CD-KEY, random value.
  65. CCDKeyAuth::AuthSerial(challenge_string.Peek_Buffer(), ChallengeResponseString);
  66. // Get Serial Number
  67. Set_Network_ID(NetworkObjectMgrClass::Get_New_Client_ID());
  68. if (cNetwork::I_Am_Server()) {
  69. Act();
  70. } else {
  71. Set_Object_Dirty_Bit(0, BIT_CREATION, true);
  72. }
  73. }
  74. //-----------------------------------------------------------------------------
  75. void
  76. cGameSpyCsChallengeResponseEvent::Act
  77. (
  78. void
  79. )
  80. {
  81. WWDEBUG_SAY(("cGameSpyCsChallengeResponseEvent::Act\n"));
  82. WWASSERT(cNetwork::I_Am_Server());
  83. cPlayer * p_player = cPlayerManager::Find_Player(ClientId);
  84. if (p_player != NULL)
  85. {
  86. WWDEBUG_SAY((" Validating client %d against validation server.\n", ClientId));
  87. CCDKeyAuth::AuthenticateUser(ClientId, p_player->Get_Ip_Address(),
  88. p_player->Get_GameSpy_Challenge_String().Peek_Buffer(),
  89. ChallengeResponseString.Peek_Buffer());
  90. if (ChallengeResponseString.Get_Length() > 31) {
  91. StringClass tmpstr = ChallengeResponseString;
  92. if (tmpstr.Get_Length() > 32) tmpstr.Erase(32, tmpstr.Get_Length()-32);
  93. p_player->Set_GameSpy_Hash_Id(tmpstr);
  94. }
  95. p_player->Set_GameSpy_Auth_State(GAMESPY_AUTH_STATE_VALIDATING);
  96. }
  97. Set_Delete_Pending();
  98. }
  99. //-----------------------------------------------------------------------------
  100. void
  101. cGameSpyCsChallengeResponseEvent::Export_Creation
  102. (
  103. BitStreamClass & packet
  104. )
  105. {
  106. WWDEBUG_SAY(("cGameSpyCsChallengeResponseEvent::Export_Creation\n"));
  107. WWASSERT(cNetwork::I_Am_Only_Client());
  108. cNetEvent::Export_Creation(packet);
  109. packet.Add(ClientId);
  110. WWASSERT(ChallengeResponseString.Get_Length() <= MAX_CHALLENGE_RESPONSE_STRING_LENGTH);
  111. packet.Add_Terminated_String(ChallengeResponseString.Peek_Buffer());
  112. Set_Delete_Pending();
  113. }
  114. //-----------------------------------------------------------------------------
  115. void
  116. cGameSpyCsChallengeResponseEvent::Import_Creation
  117. (
  118. BitStreamClass & packet
  119. )
  120. {
  121. WWDEBUG_SAY(("cGameSpyCsChallengeResponseEvent::Import_Creation\n"));
  122. WWASSERT(cNetwork::I_Am_Server());
  123. cNetEvent::Import_Creation(packet);
  124. packet.Get(ClientId);
  125. packet.Get_Terminated_String(
  126. ChallengeResponseString.Get_Buffer(MAX_CHALLENGE_RESPONSE_STRING_LENGTH), MAX_CHALLENGE_RESPONSE_STRING_LENGTH);
  127. Act();
  128. }