summaryrefslogtreecommitdiff
path: root/gameui/RunGameEngine.cpp
blob: b0ecd0fb693fa65a3936959aef36773968765431 (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
198
199
200
201
202
203
204
205
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//===========================================================================//


#include "IRunGameEngine.h"
#include "EngineInterface.h"
#include "tier1/strtools.h"
#include "IGameUIFuncs.h"
#include "tier1/convar.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"


//-----------------------------------------------------------------------------
// Purpose: Interface to running the engine from the UI dlls
//-----------------------------------------------------------------------------
class CRunGameEngine : public IRunGameEngine
{
public:
	// Returns true if the engine is running, false otherwise.
	virtual bool IsRunning()
	{
		return true;
	}

	// Adds text to the engine command buffer. Only works if IsRunning()
	// returns true on success, false on failure
	virtual bool AddTextCommand(const char *text)
	{
		engine->ClientCmd_Unrestricted((char *)text);
		return true;
	}

	// runs the engine with the specified command line parameters.  Only works if !IsRunning()
	// returns true on success, false on failure
	virtual bool RunEngine(const char *gameName, const char *commandLineParams)
	{
		return false;
	}

	virtual bool RunEngine2(const char *gameDir, const char *commandLineParams, bool isSourceGame)
	{
		return false;
	}

	virtual ERunResult RunEngine( int iAppID, const char *gameDir, const char *commandLineParams )
	{
		return k_ERunResultOkay;
	}
	
	// returns true if the player is currently connected to a game server
	virtual bool IsInGame()
	{
		return engine->GetLevelName() && strlen(engine->GetLevelName()) > 0;
	}

	// gets information about the server the engine is currently connected to
	// returns true on success, false on failure
	virtual bool GetGameInfo(char *infoBuffer, int bufferSize)
	{
		//!! need to implement
		return false;
	}

	virtual void SetTrackerUserID(int trackerID, const char *trackerName)
	{
		gameuifuncs->SetFriendsID(trackerID, trackerName);

		// update the player's name if necessary
		ConVarRef name( "name" );
		if ( name.IsValid() && trackerName && *trackerName && !Q_strcmp( name.GetString(), "unnamed" ) )
		{
			name.SetValue(trackerName);
		}
	}

	// iterates users
	// returns the number of user
	virtual int GetPlayerCount()
	{
		return engine->GetMaxClients();
	}

	// returns a playerID for a player
	// playerIndex is in the range [0, GetPlayerCount)
	virtual unsigned int GetPlayerFriendsID(int playerIndex)
	{
		player_info_t pi;

		if  ( engine->GetPlayerInfo(playerIndex, &pi ) )
			return pi.friendsID;

		return 0;
	}

	// gets the in-game name of another user, returns NULL if that user doesn't exists
	virtual const char *GetPlayerName(int trackerID, char *name, int namelen)
	{
		// find the player by their friendsID
		player_info_t pi;
		for (int i = 0; i < engine->GetMaxClients(); i++)
		{
			if  (engine->GetPlayerInfo(i, &pi ))
			{
				if (pi.friendsID == (uint)trackerID)
				{
					Q_strncpy( name, pi.name, namelen );
					return name;
				}
			}
		}

		return NULL;
	}

	virtual const char *GetPlayerFriendsName(int trackerID, char *name, int namelen)
	{
		// find the player by their friendsID
		player_info_t pi;
		for (int i = 0; i < engine->GetMaxClients(); i++)
		{
			if  (engine->GetPlayerInfo(i, &pi ))
			{
				if (pi.friendsID == (uint)trackerID)
				{
					Q_strncpy( name, pi.friendsName, namelen );
					return name;
				}
			}
		}

		return NULL;
	}

	// return the build number of the engine
	virtual unsigned int GetEngineBuildNumber()
	{
		return engine->GetEngineBuildNumber();
	}

	// return the product version of the mod being played (comes from steam.inf)
	virtual const char *GetProductVersionString()
	{
		return engine->GetProductVersionString();
	}
};

EXPOSE_SINGLE_INTERFACE(CRunGameEngine, IRunGameEngine, RUNGAMEENGINE_INTERFACE_VERSION);

//namespace
//{
////-----------------------------------------------------------------------------
//// Purpose: Interface to running the game engine
////-----------------------------------------------------------------------------
//abstract_class IRunGameEngine_Old : public IBaseInterface
//{
//public:
//	// Returns true if the engine is running, false otherwise.
//	virtual bool IsRunning() = 0;
//
//	// Adds text to the engine command buffer. Only works if IsRunning()
//	// returns true on success, false on failure
//	virtual bool AddTextCommand(const char *text) = 0;
//
//	// runs the engine with the specified command line parameters.  Only works if !IsRunning()
//	// returns true on success, false on failure
//	virtual bool RunEngine(const char *gameDir, const char *commandLineParams) = 0;
//
//	// returns true if the player is currently connected to a game server
//	virtual bool IsInGame() = 0;
//
//	// gets information about the server the engine is currently ctrue on success, false on failure
//	virtual bool GetGameInfo(char *infoBuffer, int bufferSize) = 0;
//
//	// tells the engine our userID
//	virtual void SetTrackerUserID(int trackerID, const char *trackerName) = 0;
//
//	// this next section could probably moved to another interface
//	// iterates users
//	// returns the number of user
//	virtual int GetPlayerCount() = 0;
//
//	// returns a playerID for a player
//	// playerIndex is in the range [0, GetPlayerCount)
//	virtual unsigned int GetPlayerFriendsID(int playerIndex) = 0;
//
//	// gets the in-game name of another user, returns NULL if that user doesn't exists
//	virtual const char *GetPlayerName(int friendsID) = 0;
//
//	// gets the friends name of a player
//	virtual const char *GetPlayerFriendsName(int friendsID) = 0;
//};
//
//#define RUNGAMEENGINE_INTERFACE_VERSION_OLD "RunGameEngine004"
//
//#ifndef _XBOX
//EXPOSE_SINGLE_INTERFACE(CRunGameEngine, IRunGameEngine_Old, RUNGAMEENGINE_INTERFACE_VERSION_OLD);
//#endif
//}