Team Fortress 2 Source Code as on 22/4/2020
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.

187 lines
5.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #ifdef _WIN32
  7. #include <windows.h>
  8. #include <direct.h>
  9. // includes for the VGUI version
  10. #include <vgui_controls/Panel.h>
  11. #include <vgui_controls/Controls.h>
  12. #include <vgui/ISystem.h>
  13. #include <vgui/IVGui.h>
  14. #include <vgui/IPanel.h>
  15. #include "filesystem.h"
  16. #include <vgui/ILocalize.h>
  17. #include <vgui/IScheme.h>
  18. #include <vgui/ISurface.h>
  19. #include <IVGuiModule.h>
  20. #include "vgui/MainPanel.h"
  21. #include "IAdminServer.h"
  22. // memdbgon must be the last include file in a .cpp file!!!
  23. #include "tier0/memdbgon.h"
  24. static CMainPanel *g_pMainPanel = NULL; // the main panel to show
  25. static CSysModule *g_hAdminServerModule;
  26. IAdminServer *g_pAdminServer = NULL;
  27. static IVGuiModule *g_pAdminVGuiModule = NULL;
  28. void* DedicatedFactory(const char *pName, int *pReturnCode);
  29. //-----------------------------------------------------------------------------
  30. // Purpose: Starts up the VGUI system and loads the base panel
  31. //-----------------------------------------------------------------------------
  32. int StartVGUI( CreateInterfaceFn dedicatedFactory )
  33. {
  34. // the "base dir" so we can scan mod name
  35. g_pFullFileSystem->AddSearchPath(".", "MAIN");
  36. // the main platform dir
  37. g_pFullFileSystem->AddSearchPath( "platform", "PLATFORM", PATH_ADD_TO_HEAD);
  38. vgui::ivgui()->SetSleep(false);
  39. // find our configuration directory
  40. char szConfigDir[512];
  41. const char *steamPath = getenv("SteamInstallPath");
  42. if (steamPath)
  43. {
  44. // put the config dir directly under steam
  45. Q_snprintf(szConfigDir, sizeof(szConfigDir), "%s/config", steamPath);
  46. }
  47. else
  48. {
  49. // we're not running steam, so just put the config dir under the platform
  50. Q_strncpy( szConfigDir, "platform/config", sizeof(szConfigDir));
  51. }
  52. g_pFullFileSystem->CreateDirHierarchy("config", "PLATFORM");
  53. g_pFullFileSystem->AddSearchPath(szConfigDir, "CONFIG", PATH_ADD_TO_HEAD);
  54. // initialize the user configuration file
  55. vgui::system()->SetUserConfigFile("DedicatedServerDialogConfig.vdf", "CONFIG");
  56. // Init the surface
  57. g_pMainPanel = new CMainPanel( );
  58. g_pMainPanel->SetVisible(true);
  59. vgui::surface()->SetEmbeddedPanel(g_pMainPanel->GetVPanel());
  60. // load the scheme
  61. vgui::scheme()->LoadSchemeFromFile("Resource/SourceScheme.res", NULL);
  62. // localization
  63. g_pVGuiLocalize->AddFile( "Resource/platform_%language%.txt" );
  64. g_pVGuiLocalize->AddFile( "Resource/vgui_%language%.txt" );
  65. g_pVGuiLocalize->AddFile( "Admin/server_%language%.txt" );
  66. // Start vgui
  67. vgui::ivgui()->Start();
  68. // load the module
  69. g_pFullFileSystem->GetLocalCopy("bin/AdminServer.dll");
  70. g_hAdminServerModule = g_pFullFileSystem->LoadModule("AdminServer");
  71. Assert(g_hAdminServerModule != NULL);
  72. CreateInterfaceFn adminFactory = NULL;
  73. if (!g_hAdminServerModule)
  74. {
  75. vgui::ivgui()->DPrintf2("Admin Error: module version (Admin/AdminServer.dll, %s) invalid, not loading\n", IMANAGESERVER_INTERFACE_VERSION );
  76. }
  77. else
  78. {
  79. // make sure we get the right version
  80. adminFactory = Sys_GetFactory(g_hAdminServerModule);
  81. g_pAdminServer = (IAdminServer *)adminFactory(ADMINSERVER_INTERFACE_VERSION, NULL);
  82. g_pAdminVGuiModule = (IVGuiModule *)adminFactory("VGuiModuleAdminServer001", NULL);
  83. Assert(g_pAdminServer != NULL);
  84. Assert(g_pAdminVGuiModule != NULL);
  85. if (!g_pAdminServer || !g_pAdminVGuiModule)
  86. {
  87. vgui::ivgui()->DPrintf2("Admin Error: module version (Admin/AdminServer.dll, %s) invalid, not loading\n", IMANAGESERVER_INTERFACE_VERSION );
  88. }
  89. }
  90. // finish initializing admin module
  91. g_pAdminVGuiModule->Initialize( &dedicatedFactory, 1 );
  92. g_pAdminVGuiModule->PostInitialize(&adminFactory, 1);
  93. g_pAdminVGuiModule->SetParent( g_pMainPanel->GetVPanel() );
  94. // finish setting up main panel
  95. g_pMainPanel->Initialize( );
  96. g_pMainPanel->Open();
  97. return 0;
  98. }
  99. //-----------------------------------------------------------------------------
  100. // Purpose: Shuts down the VGUI system
  101. //-----------------------------------------------------------------------------
  102. void StopVGUI()
  103. {
  104. SetEvent(g_pMainPanel->GetShutdownHandle());
  105. delete g_pMainPanel;
  106. g_pMainPanel = NULL;
  107. if (g_hAdminServerModule)
  108. {
  109. g_pAdminVGuiModule->Shutdown( );
  110. Sys_UnloadModule(g_hAdminServerModule);
  111. }
  112. }
  113. //-----------------------------------------------------------------------------
  114. // Purpose: Run a single VGUI frame
  115. //-----------------------------------------------------------------------------
  116. void RunVGUIFrame()
  117. {
  118. vgui::ivgui()->RunFrame();
  119. }
  120. bool VGUIIsStopping()
  121. {
  122. return g_pMainPanel->Stopping();
  123. }
  124. bool VGUIIsRunning()
  125. {
  126. return vgui::ivgui()->IsRunning();
  127. }
  128. bool VGUIIsInConfig()
  129. {
  130. return g_pMainPanel->IsInConfig();
  131. }
  132. void VGUIFinishedConfig()
  133. {
  134. Assert( g_pMainPanel );
  135. if(g_pMainPanel) // engine is loaded, pass the message on
  136. {
  137. SetEvent(g_pMainPanel->GetShutdownHandle());
  138. }
  139. }
  140. void VGUIPrintf( const char *msg )
  141. {
  142. if ( !g_pMainPanel || VGUIIsInConfig() || VGUIIsStopping() )
  143. {
  144. OutputDebugStringA( msg );
  145. }
  146. else if ( g_pMainPanel )
  147. {
  148. g_pMainPanel->AddConsoleText( msg );
  149. }
  150. }
  151. #endif // _WIN32