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.

197 lines
6.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "AdminServer.h"
  8. #include "IRunGameEngine.h"
  9. #include "IGameServerData.h"
  10. #include "GamePanelInfo.h"
  11. #include "ivprofexport.h"
  12. #include <vgui/ISystem.h>
  13. #include <vgui/IPanel.h>
  14. #include <vgui/IVGui.h>
  15. #include <vgui/ILocalize.h>
  16. #include <KeyValues.h>
  17. #include "filesystem.h"
  18. // expose the server browser interfaces
  19. CAdminServer g_AdminServerSingleton;
  20. EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CAdminServer, IAdminServer, ADMINSERVER_INTERFACE_VERSION, g_AdminServerSingleton);
  21. EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CAdminServer, IVGuiModule, "VGuiModuleAdminServer001", g_AdminServerSingleton);
  22. IGameServerData *g_pGameServerData = NULL;
  23. IVProfExport *g_pVProfExport = NULL;
  24. //-----------------------------------------------------------------------------
  25. // Purpose: Constructor
  26. //-----------------------------------------------------------------------------
  27. CAdminServer::CAdminServer()
  28. {
  29. // fill in the 0-based element of the manage servers list
  30. OpenedManageDialog_t empty = { 0, NULL };
  31. m_OpenedManageDialog.AddToTail(empty);
  32. m_hParent=0;
  33. }
  34. //-----------------------------------------------------------------------------
  35. // Purpose: Destructor
  36. //-----------------------------------------------------------------------------
  37. CAdminServer::~CAdminServer()
  38. {
  39. }
  40. //-----------------------------------------------------------------------------
  41. // Purpose: links to vgui and engine interfaces
  42. //-----------------------------------------------------------------------------
  43. bool CAdminServer::Initialize(CreateInterfaceFn *factorylist, int factoryCount)
  44. {
  45. ConnectTier1Libraries( factorylist, factoryCount );
  46. ConVar_Register();
  47. ConnectTier2Libraries( factorylist, factoryCount );
  48. ConnectTier3Libraries( factorylist, factoryCount );
  49. // find our interfaces
  50. for (int i = 0; i < factoryCount; i++)
  51. {
  52. // if we're running locally we can get this direct interface to the game engine
  53. if (!g_pGameServerData)
  54. {
  55. g_pGameServerData = (IGameServerData *)(factorylist[i])(GAMESERVERDATA_INTERFACE_VERSION, NULL);
  56. }
  57. if ( !g_pVProfExport )
  58. {
  59. g_pVProfExport = (IVProfExport*)(factorylist[i])( VPROF_EXPORT_INTERFACE_VERSION, NULL );
  60. }
  61. }
  62. RemoteServer().Initialize(); // now we have the game date interface, initialize the engine connection
  63. if ( vgui::VGui_InitInterfacesList("AdminServer", factorylist, factoryCount) )
  64. {
  65. // load localization file
  66. g_pVGuiLocalize->AddFile( "admin/admin_%language%.txt");
  67. return true;
  68. }
  69. return false;
  70. }
  71. //-----------------------------------------------------------------------------
  72. // Purpose: links to other modules interfaces (tracker)
  73. //-----------------------------------------------------------------------------
  74. bool CAdminServer::PostInitialize(CreateInterfaceFn *modules, int factoryCount)
  75. {
  76. return true;
  77. }
  78. //-----------------------------------------------------------------------------
  79. // Purpose:
  80. //-----------------------------------------------------------------------------
  81. bool CAdminServer::IsValid()
  82. {
  83. return true;
  84. }
  85. //-----------------------------------------------------------------------------
  86. // Purpose:
  87. //-----------------------------------------------------------------------------
  88. bool CAdminServer::Activate()
  89. {
  90. return true;
  91. }
  92. //-----------------------------------------------------------------------------
  93. // Purpose: returns direct handle to main server browser dialog
  94. //-----------------------------------------------------------------------------
  95. vgui::VPANEL CAdminServer::GetPanel()
  96. {
  97. return NULL;
  98. }
  99. //-----------------------------------------------------------------------------
  100. // Purpose: Closes down the server browser for good
  101. //-----------------------------------------------------------------------------
  102. void CAdminServer::Shutdown()
  103. {
  104. DisconnectTier3Libraries();
  105. DisconnectTier2Libraries();
  106. ConVar_Unregister();
  107. DisconnectTier1Libraries();
  108. }
  109. void CAdminServer::SetParent(vgui::VPANEL parent)
  110. {
  111. /* if (m_hServerPage.Get())
  112. {
  113. m_hServerPage->SetParent(parent);
  114. }
  115. */
  116. m_hParent = parent;
  117. }
  118. //-----------------------------------------------------------------------------
  119. // Purpose: Called when the user enters the game
  120. //-----------------------------------------------------------------------------
  121. void CAdminServer::Deactivate()
  122. {
  123. }
  124. //-----------------------------------------------------------------------------
  125. // Purpose: Called when the user returns from the game to the outside UI
  126. //-----------------------------------------------------------------------------
  127. void CAdminServer::Reactivate()
  128. {
  129. }
  130. //-----------------------------------------------------------------------------
  131. // Purpose: opens a manage server dialog for a local server
  132. //-----------------------------------------------------------------------------
  133. ManageServerUIHandle_t CAdminServer::OpenManageServerDialog(const char *serverName, const char *gameDir)
  134. {
  135. CGamePanelInfo *tmp = new CGamePanelInfo(NULL, serverName, gameDir);
  136. tmp->SetParent(m_hParent);
  137. // add a new item into the list
  138. int i = m_OpenedManageDialog.AddToTail();
  139. m_OpenedManageDialog[i].handle = vgui::ivgui()->PanelToHandle(tmp->GetVPanel());
  140. m_OpenedManageDialog[i].manageInterface = tmp;
  141. return (ManageServerUIHandle_t)i;
  142. }
  143. //-----------------------------------------------------------------------------
  144. // Purpose: opens a manage server dialog to a remote server
  145. //-----------------------------------------------------------------------------
  146. ManageServerUIHandle_t CAdminServer::OpenManageServerDialog(unsigned int gameIP, unsigned int gamePort, const char *password)
  147. {
  148. Assert(false);
  149. return (ManageServerUIHandle_t)0;
  150. }
  151. //-----------------------------------------------------------------------------
  152. // Purpose: forces the game info dialog closed
  153. //-----------------------------------------------------------------------------
  154. void CAdminServer::CloseManageServerDialog(ManageServerUIHandle_t gameDialog)
  155. {
  156. Assert(false);
  157. }
  158. //-----------------------------------------------------------------------------
  159. // Purpose: Gets a handle to the management interface
  160. //-----------------------------------------------------------------------------
  161. IManageServer *CAdminServer::GetManageServerInterface(ManageServerUIHandle_t handle)
  162. {
  163. // make sure it's safe
  164. if ((int)handle < 1 || (int)handle > m_OpenedManageDialog.Count())
  165. return NULL;
  166. vgui::VPANEL panel = vgui::ivgui()->HandleToPanel(m_OpenedManageDialog[handle].handle);
  167. if (!panel)
  168. return NULL;
  169. return m_OpenedManageDialog[handle].manageInterface;
  170. }