Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
4.4 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "CreateMultiplayerGameDialog.h"
  8. #include "CreateMultiplayerGameServerPage.h"
  9. #include "CreateMultiplayerGameGameplayPage.h"
  10. #include "CreateMultiplayerGameBotPage.h"
  11. #include "EngineInterface.h"
  12. #include "ModInfo.h"
  13. #include "GameUI_Interface.h"
  14. #include <stdio.h>
  15. using namespace vgui;
  16. #include <vgui/ILocalize.h>
  17. #include "FileSystem.h"
  18. #include <KeyValues.h>
  19. // memdbgon must be the last include file in a .cpp file!!!
  20. #include <tier0/memdbgon.h>
  21. //-----------------------------------------------------------------------------
  22. // Purpose: Constructor
  23. //-----------------------------------------------------------------------------
  24. CCreateMultiplayerGameDialog::CCreateMultiplayerGameDialog(vgui::Panel *parent) : PropertyDialog(parent, "CreateMultiplayerGameDialog")
  25. {
  26. m_bBotsEnabled = false;
  27. SetDeleteSelfOnClose(true);
  28. SetSize(348, 460);
  29. SetTitle("#GameUI_CreateServer", true);
  30. SetOKButtonText("#GameUI_Start");
  31. if (!stricmp( ModInfo().GetGameName(), "Counter-Strike Source" ))
  32. {
  33. m_bBotsEnabled = true;
  34. }
  35. m_pServerPage = new CCreateMultiplayerGameServerPage(this, "ServerPage");
  36. m_pGameplayPage = new CCreateMultiplayerGameGameplayPage(this, "GameplayPage");
  37. m_pBotPage = NULL;
  38. AddPage(m_pServerPage, "#GameUI_Server");
  39. AddPage(m_pGameplayPage, "#GameUI_Game");
  40. // create KeyValues object to load/save config options
  41. m_pSavedData = new KeyValues( "ServerConfig" );
  42. // load the config data
  43. if (m_pSavedData)
  44. {
  45. m_pSavedData->LoadFromFile( g_pFullFileSystem, "ServerConfig.vdf", "GAME" ); // this is game-specific data, so it should live in GAME, not CONFIG
  46. const char *startMap = m_pSavedData->GetString("map", "");
  47. if (startMap[0])
  48. {
  49. m_pServerPage->SetMap(startMap);
  50. }
  51. }
  52. if ( m_bBotsEnabled )
  53. {
  54. // add a page of advanced bot controls
  55. // NOTE: These controls will use the bot keys to initialize their values
  56. m_pBotPage = new CCreateMultiplayerGameBotPage( this, "BotPage", m_pSavedData );
  57. AddPage( m_pBotPage, "#GameUI_CPUPlayerOptions" );
  58. m_pServerPage->EnableBots( m_pSavedData );
  59. }
  60. }
  61. //-----------------------------------------------------------------------------
  62. // Purpose: Destructor
  63. //-----------------------------------------------------------------------------
  64. CCreateMultiplayerGameDialog::~CCreateMultiplayerGameDialog()
  65. {
  66. if (m_pSavedData)
  67. {
  68. m_pSavedData->deleteThis();
  69. m_pSavedData = NULL;
  70. }
  71. }
  72. //-----------------------------------------------------------------------------
  73. // Purpose: runs the server when the OK button is pressed
  74. //-----------------------------------------------------------------------------
  75. bool CCreateMultiplayerGameDialog::OnOK(bool applyOnly)
  76. {
  77. // reset server enforced cvars
  78. g_pCVar->RevertFlaggedConVars( FCVAR_REPLICATED );
  79. // Cheats were disabled; revert all cheat cvars to their default values.
  80. // This must be done heading into multiplayer games because people can play
  81. // demos etc and set cheat cvars with sv_cheats 0.
  82. g_pCVar->RevertFlaggedConVars( FCVAR_CHEAT );
  83. DevMsg( "FCVAR_CHEAT cvars reverted to defaults.\n" );
  84. BaseClass::OnOK(applyOnly);
  85. // get these values from m_pServerPage and store them temporarily
  86. char szMapName[64], szHostName[64], szPassword[64];
  87. Q_strncpy(szMapName, m_pServerPage->GetMapName(), sizeof( szMapName ));
  88. Q_strncpy(szHostName, m_pGameplayPage->GetHostName(), sizeof( szHostName ));
  89. Q_strncpy(szPassword, m_pGameplayPage->GetPassword(), sizeof( szPassword ));
  90. // save the config data
  91. if (m_pSavedData)
  92. {
  93. if (m_pServerPage->IsRandomMapSelected())
  94. {
  95. // it's set to random map, just save an
  96. m_pSavedData->SetString("map", "");
  97. }
  98. else
  99. {
  100. m_pSavedData->SetString("map", szMapName);
  101. }
  102. // save config to a file
  103. m_pSavedData->SaveToFile( g_pFullFileSystem, "ServerConfig.vdf", "GAME" );
  104. }
  105. char szMapCommand[1024];
  106. // create the command to execute
  107. Q_snprintf(szMapCommand, sizeof( szMapCommand ), "disconnect\nwait\nwait\nsv_lan 1\nsetmaster enable\nmaxplayers %i\nsv_password \"%s\"\nhostname \"%s\"\nprogress_enable\nmap %s\n",
  108. m_pGameplayPage->GetMaxPlayers(),
  109. szPassword,
  110. szHostName,
  111. szMapName
  112. );
  113. // exec
  114. engine->ClientCmd_Unrestricted(szMapCommand);
  115. return true;
  116. }