summaryrefslogtreecommitdiff
path: root/tracker/AdminServer/AdminServer.cpp
blob: 5352efbaeb9bdf8426381870b7cd9eb3c626d415 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================

#include "AdminServer.h"
#include "IRunGameEngine.h"
#include "IGameServerData.h"
#include "GamePanelInfo.h"
#include "ivprofexport.h"

#include <vgui/ISystem.h>
#include <vgui/IPanel.h>
#include <vgui/IVGui.h>
#include <vgui/ILocalize.h>
#include <KeyValues.h>
#include "filesystem.h"

// expose the server browser interfaces
CAdminServer g_AdminServerSingleton;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CAdminServer, IAdminServer, ADMINSERVER_INTERFACE_VERSION, g_AdminServerSingleton);
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CAdminServer, IVGuiModule, "VGuiModuleAdminServer001", g_AdminServerSingleton);

IGameServerData *g_pGameServerData = NULL;
IVProfExport *g_pVProfExport = NULL;

//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CAdminServer::CAdminServer()
{
	// fill in the 0-based element of the manage servers list
	OpenedManageDialog_t empty = { 0, NULL };
	m_OpenedManageDialog.AddToTail(empty);
	m_hParent=0;
}

//-----------------------------------------------------------------------------
// Purpose: Destructor
//-----------------------------------------------------------------------------
CAdminServer::~CAdminServer()
{
}

//-----------------------------------------------------------------------------
// Purpose: links to vgui and engine interfaces
//-----------------------------------------------------------------------------
bool CAdminServer::Initialize(CreateInterfaceFn *factorylist, int factoryCount)
{
	ConnectTier1Libraries( factorylist, factoryCount );
	ConVar_Register();
	ConnectTier2Libraries( factorylist, factoryCount );
	ConnectTier3Libraries( factorylist, factoryCount );

	// find our interfaces
	for (int i = 0; i < factoryCount; i++)
	{
		// if we're running locally we can get this direct interface to the game engine
		if (!g_pGameServerData)
		{
			g_pGameServerData = (IGameServerData *)(factorylist[i])(GAMESERVERDATA_INTERFACE_VERSION, NULL);
		}
		if ( !g_pVProfExport )
		{
			g_pVProfExport = (IVProfExport*)(factorylist[i])( VPROF_EXPORT_INTERFACE_VERSION, NULL );
		}
	}

	RemoteServer().Initialize(); // now we have the game date interface, initialize the engine connection

	if ( vgui::VGui_InitInterfacesList("AdminServer", factorylist, factoryCount) )
	{
		// load localization file
		g_pVGuiLocalize->AddFile( "admin/admin_%language%.txt");
		return true;
	}

	return false;
}

//-----------------------------------------------------------------------------
// Purpose: links to other modules interfaces (tracker)
//-----------------------------------------------------------------------------
bool CAdminServer::PostInitialize(CreateInterfaceFn *modules, int factoryCount)
{
	return true;
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CAdminServer::IsValid()
{
	return true;
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CAdminServer::Activate()
{
	return true;
}

//-----------------------------------------------------------------------------
// Purpose: returns direct handle to main server browser dialog
//-----------------------------------------------------------------------------
vgui::VPANEL CAdminServer::GetPanel()
{
	return NULL;
}

//-----------------------------------------------------------------------------
// Purpose: Closes down the server browser for good
//-----------------------------------------------------------------------------
void CAdminServer::Shutdown()
{
	DisconnectTier3Libraries();
	DisconnectTier2Libraries();
	ConVar_Unregister();
	DisconnectTier1Libraries();
}

void CAdminServer::SetParent(vgui::VPANEL parent)
{
/*	if (m_hServerPage.Get())
	{
		m_hServerPage->SetParent(parent);
	}
	*/
	m_hParent = parent;
}

//-----------------------------------------------------------------------------
// Purpose: Called when the user enters the game
//-----------------------------------------------------------------------------
void CAdminServer::Deactivate()
{
}

//-----------------------------------------------------------------------------
// Purpose: Called when the user returns from the game to the outside UI
//-----------------------------------------------------------------------------
void CAdminServer::Reactivate()
{
}

//-----------------------------------------------------------------------------
// Purpose: opens a manage server dialog for a local server
//-----------------------------------------------------------------------------
ManageServerUIHandle_t CAdminServer::OpenManageServerDialog(const char *serverName, const char *gameDir)
{
	CGamePanelInfo *tmp = new CGamePanelInfo(NULL, serverName, gameDir);
	tmp->SetParent(m_hParent);

	// add a new item into the list
	int i = m_OpenedManageDialog.AddToTail();
	m_OpenedManageDialog[i].handle = vgui::ivgui()->PanelToHandle(tmp->GetVPanel());
	m_OpenedManageDialog[i].manageInterface = tmp;

	return (ManageServerUIHandle_t)i;
}

//-----------------------------------------------------------------------------
// Purpose: opens a manage server dialog to a remote server
//-----------------------------------------------------------------------------
ManageServerUIHandle_t CAdminServer::OpenManageServerDialog(unsigned int gameIP, unsigned int gamePort, const char *password)
{
	Assert(false);
	return (ManageServerUIHandle_t)0;
}

//-----------------------------------------------------------------------------
// Purpose: forces the game info dialog closed
//-----------------------------------------------------------------------------
void CAdminServer::CloseManageServerDialog(ManageServerUIHandle_t gameDialog)
{
	Assert(false);
}

//-----------------------------------------------------------------------------
// Purpose: Gets a handle to the management interface
//-----------------------------------------------------------------------------
IManageServer *CAdminServer::GetManageServerInterface(ManageServerUIHandle_t handle)
{
	// make sure it's safe
	if ((int)handle < 1 || (int)handle > m_OpenedManageDialog.Count())
		return NULL;

	vgui::VPANEL panel = vgui::ivgui()->HandleToPanel(m_OpenedManageDialog[handle].handle);
	if (!panel)
		return NULL;
	
	return m_OpenedManageDialog[handle].manageInterface;
}