gamespyadmin.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. // Filename: gamespyadmin.cpp
  20. // Author: Tom Spencer-Smith
  21. // Date: Jan 2002
  22. // Description:
  23. //
  24. #include "gamespyadmin.h"
  25. #include "wwdebug.h"
  26. #include "widestring.h"
  27. #include "gameinitmgr.h"
  28. #include "gamedata.h"
  29. #include "cnetwork.h"
  30. #include "dlgmpconnect.h"
  31. #include "gamespy_qnr.h"
  32. #include <Gamespy\ghttp.h>
  33. #include "useroptions.h"
  34. #include "renegadedialogmgr.h"
  35. #include "dialogtests.h"
  36. #include "translatedb.h"
  37. #include "string_ids.h"
  38. #include "bandwidthcheck.h"
  39. #include "gamespyauthmgr.h"
  40. #include "specialbuilds.h"
  41. //
  42. // Class statics
  43. //
  44. bool cGameSpyAdmin::DetectingBandwidth = false;
  45. bool cGameSpyAdmin::IsUnderGamespyMenuing = false;
  46. bool cGameSpyAdmin::IsLaunchFromGamespyRequested = false;
  47. bool cGameSpyAdmin::IsLaunchedFromGamespy = false;
  48. bool cGameSpyAdmin::IsServerGamespyListed = false;
  49. ULONG cGameSpyAdmin::GameHostIp = 0;
  50. USHORT cGameSpyAdmin::GameHostPort = 0;
  51. WideStringClass cGameSpyAdmin::PasswordAttempt;
  52. // It's 2:00am....see DoDialog below..
  53. cGameSpyAdmin theGameSpy;
  54. //----------------------------------------------------------------------------------
  55. void
  56. cGameSpyAdmin::Think
  57. (
  58. void
  59. )
  60. {
  61. WWASSERT(Is_Gamespy_Game());
  62. if (IsLaunchFromGamespyRequested && SplashIntroMenuDialogClass::Is_Complete ())
  63. {
  64. if (!DetectingBandwidth) {
  65. RefPtr<SerialWait> serverWait = SerialWait::Create();
  66. WWASSERT(serverWait.IsValid());
  67. DetectingBandwidth = true;
  68. RefPtr<WaitCondition> bandwidth_wait = BandwidthCheckerClass::Detect();
  69. if (cUserOptions::DoneClientBandwidthTest.Is_True()) {
  70. //DlgWOLWait::DoDialog(TRANSLATE (IDS_MENU_DETECTING_BANDWIDTH), L"Skip", bandwidth_wait, &theGameSpy);
  71. DlgWOLWait::DoDialog(TRANSLATE (IDS_MENU_DETECTING_BANDWIDTH), TRANSLATE (IDS_MP_SKIP), bandwidth_wait, &theGameSpy);
  72. } else {
  73. DlgWOLWait::DoDialog(TRANSLATE (IDS_MENU_DETECTING_BANDWIDTH), bandwidth_wait, &theGameSpy);
  74. }
  75. }
  76. }
  77. ghttpThink();
  78. #ifndef MULTIPLAYERDEMO
  79. if (cNetwork::I_Am_Server())
  80. {
  81. cGameSpyAuthMgr::Think();
  82. }
  83. #endif // MULTIPLAYERDEMO
  84. }
  85. //----------------------------------------------------------------------------------
  86. void cGameSpyAdmin::HandleNotification(DlgWOLWaitEvent& event) {
  87. switch (event.Result()) {
  88. case WaitCondition::ConditionMet:
  89. {
  90. if (DetectingBandwidth) {
  91. DetectingBandwidth = false;
  92. cUserOptions::Set_Bandwidth_Type(BANDWIDTH_AUTO);
  93. cUserOptions::DoneClientBandwidthTest.Set(true);
  94. Join_Server();
  95. }
  96. }
  97. break;
  98. case WaitCondition::Waiting:
  99. {
  100. // Do nothing
  101. }
  102. break;
  103. case WaitCondition::UserCancel:
  104. {
  105. if (DetectingBandwidth) {
  106. if (cUserOptions::DoneClientBandwidthTest.Is_True()) {
  107. // Skip Bandwidth test...
  108. DetectingBandwidth = false;
  109. BandwidthCheckerClass::Force_Upstream_Bandwidth(cUserOptions::BandwidthBps.Get());
  110. cUserOptions::Set_Bandwidth_Type(BANDWIDTH_AUTO);
  111. Join_Server();
  112. } else { // This must be an Abort...
  113. DetectingBandwidth = false;
  114. #pragma message ("Is Stop_Main_Loop() safe here?")
  115. extern void Stop_Main_Loop (int);
  116. Stop_Main_Loop(EXIT_SUCCESS);
  117. }
  118. }
  119. }
  120. break;
  121. case WaitCondition::TimeOut:
  122. case WaitCondition::Error:
  123. {
  124. DetectingBandwidth = false;
  125. #pragma message ("Is Stop_Main_Loop() safe here?")
  126. extern void Stop_Main_Loop (int);
  127. Stop_Main_Loop(EXIT_SUCCESS);
  128. }
  129. break;
  130. default:
  131. DIE;
  132. break;
  133. }
  134. }
  135. //----------------------------------------------------------------------------------
  136. void
  137. cGameSpyAdmin::Join_Server(void) {
  138. Connect_To_Game_Server();
  139. IsLaunchFromGamespyRequested = false;
  140. IsLaunchedFromGamespy = true;
  141. }
  142. //----------------------------------------------------------------------------------
  143. void
  144. cGameSpyAdmin::Reset
  145. (
  146. void
  147. )
  148. {
  149. IsUnderGamespyMenuing = false;
  150. IsLaunchFromGamespyRequested = false;
  151. IsLaunchedFromGamespy = false;
  152. IsServerGamespyListed = false;
  153. GameHostIp = 0;
  154. GameHostPort = 0;
  155. GameSpyQnR.Shutdown();
  156. }
  157. //----------------------------------------------------------------------------------
  158. void
  159. cGameSpyAdmin::Connect_To_Game_Server
  160. (
  161. void
  162. )
  163. {
  164. WWASSERT(GameHostIp > 0);
  165. WWASSERT(GameHostPort > 0);
  166. GameInitMgrClass::Initialize_LAN();
  167. WWASSERT(PTheGameData == NULL);
  168. PTheGameData = cGameData::Create_Game_Of_Type(cGameData::GAME_TYPE_CNC);
  169. WWASSERT(PTheGameData != NULL);
  170. PTheGameData->Set_Ip_Address(GameHostIp);
  171. PTheGameData->Set_Port(GameHostPort);
  172. cNetwork::Init_Client();
  173. //
  174. // Display the "connecting" dialog
  175. //
  176. DlgMPConnect::DoDialog(-1, 0);
  177. }
  178. //----------------------------------------------------------------------------------
  179. void
  180. cGameSpyAdmin::Set_Game_Host_Ip
  181. (
  182. ULONG ip
  183. )
  184. {
  185. WWASSERT(ip > 0);
  186. GameHostIp = ip;
  187. }
  188. //----------------------------------------------------------------------------------
  189. void
  190. cGameSpyAdmin::Set_Game_Host_Port
  191. (
  192. USHORT port
  193. )
  194. {
  195. WWASSERT(port > 0);
  196. GameHostPort = port;
  197. }
  198. //----------------------------------------------------------------------------------
  199. bool
  200. cGameSpyAdmin::Is_Gamespy_Game
  201. (
  202. void
  203. )
  204. {
  205. return
  206. IsUnderGamespyMenuing ||
  207. IsLaunchFromGamespyRequested ||
  208. IsLaunchedFromGamespy ||
  209. IsServerGamespyListed;
  210. }
  211. //----------------------------------------------------------------------------------
  212. bool
  213. cGameSpyAdmin::Is_Nickname_Collision
  214. (
  215. WideStringClass & nickname
  216. )
  217. {
  218. WWASSERT(!nickname.Is_Empty());
  219. WWASSERT(cNetwork::I_Am_Server());
  220. bool collides = (cPlayerManager::Find_Player(nickname) != NULL);
  221. if (cNetwork::I_Am_Only_Server())
  222. {
  223. collides |= !nickname.Compare_No_Case(cNetInterface::Get_Nickname());
  224. }
  225. return collides;
  226. }