aboutsummaryrefslogtreecommitdiff
path: root/src/parsec_server/include/e_gameserver.h
blob: 217e1a531015e897ad7ca5453339ebe8b928e86b (plain)
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
/*
* PARSEC HEADER: e_gameserver.h
*/

#ifndef _E_GAMESERVER_H_
#define _E_GAMESERVER_H_

// constants ------------------------------------------------------------------
//
#define MAX_MASTERSERVER_NAME					MAX_HOSTNAME_LEN
#define MAX_NUM_CLIENTS							TheServer->GetMaxNumClients()

#include <string.h>

// class holding the server configuration -------------------------------------
//
class ServerConfig
{
private:
	int					m_SimFrequency;						// frequency to run the sim
protected:

	// data that can be modified via commandline/cfg file
	//char				m_szSelectedInterfaceIP[ MAX_STRLEN_IPADDR ];	// string containing the selected interface IP ( NULL if default )
	word				m_nInterface;						// zero based interface index
	int					m_MaintainFrequency;				// frequency to run maintainance
	int					m_nPacketAverageSecs;				// time to sample the average packetsize for optimal client update rate

	int					m_nMaxNumClients;					// current max. # of players
	char				m_szServername[ MAX_SERVER_NAME + 1 ];// the servername

	refframe_t			m_ClientUpdateHeartbeat;

	int					m_ServerIsMaster;

/*	char	location[ MAX_CFG_LINE + 1 ]		= "not specified";
	char	admin_name[ MAX_CFG_LINE + 1 ]		= "not specified";
	char	admin_email[ MAX_CFG_LINE + 1 ]		= "not specified";
	char	server_info[ MAX_CFG_LINE + 1 ]		= "";
	char	server_url[ MAX_CFG_LINE + 1 ]		= "";
	char	messageline1[ MAX_CFG_LINE + 1 ]	= "";
	char	messageline2[ MAX_CFG_LINE + 1 ]	= "";
	char	messageline3[ MAX_CFG_LINE + 1 ]	= "";
	char	messageline4[ MAX_CFG_LINE + 1 ]	= "";
	
	int		time_limit = 0;
	int		time_startrefframes = 0;
	int		time_counter = GAME_NOTSTARTEDYET;
	int		counter_active = FALSE;
	int		wait_startrefframes = 0;
	
	int		kill_limit = 0;
	
	char	*banlist[ MAX_BANNED_CLIENTS ];
	int		num_banned = 0;
*/	

public:
	// standard ctor
	ServerConfig();

	// return the refframes to wait between client update heartbeats
	refframe_t GetClientUpdateHeartbeat() { return m_ClientUpdateHeartbeat; }

	// functions to set/get whether this server instance is a master server.
	void SetServerIsMaster(bool isMaster);
	bool GetServerIsMaster();

	// set the servername
	void SetServername( const char* pName )
	{ 
		strncpy( m_szServername, pName, MAX_SERVER_NAME );
		m_szServername[ MAX_SERVER_NAME ] = 0;
	}

	// get the server name 
	const char* GetServerName()	{ return m_szServername; }

	// set the # of max players
	bool_t SetMaxNumClients( int nMaxNumClients );

	// return the max # of players
	int GetMaxNumClients();

	// set the simulation frequency
	bool_t SetSimFrequency( int nSimFrequency );

	// return the simulation frequency
	int	GetSimFrequency();
};

// class for holding a server link --------------------------------------------
//
class E_ServerLinkInfo
{
public:
	int			m_serverid;
	Vector3		m_pos;
	Vector3		m_dir;

	E_ServerLinkInfo()
	{
		Reset();
	}

	void Reset()
	{
		m_serverid = 0;
		memset( &m_pos, 0, sizeof( Vector3 ) );
		memset( &m_dir, 0, sizeof( Vector3 ) );
	}
};



// main gameserver class ------------------------------------------------------
//
class E_GameServer : public ServerConfig
{
protected: 	// data

	// internal data
	refframe_t			m_Maintain_FrameTime;
	refframe_t			m_SimTick_FrameTime;				// duration in refframes of one simulation tick
	int					m_Select_Timeout;					// timout for select (microseconds)
	int					m_ServerIdleTime_msec;				// idle time ( select timeout ) of server

	int					m_nServerFrame;						// the current server frame

	refframe_t			m_MaintainFrameBase;
	refframe_t			m_MasterServerFrameBase;
	refframe_t			m_PacketFrameBase;
	refframe_t			m_CurPacketRefFrames;

	refframe_t			m_CurServerRefFrame;
	refframe_t			m_LastServerRefFrame;

	refframe_t			m_MasterServer_FrameTime;			// frametime for master server maintenance
	char				m_MasterServer_Hostname[ MAX_MASTERSERVER_NAME + 1];
	int					m_MasterServer_Challenge;
	bool_t				m_bMasterServer_NodeValid;
	node_t				m_MasterServer_Node;

	E_ServerLinkInfo	m_ServerLinks[ MAX_NUM_LINKS ];
	int					m_nNumServerLinks;

	bool_t				m_bQuit;
protected: 	// methods

	// init pre/post running of console script
	int			_InitPostConsoleScript();
	int			_InitPreConsoleScript();

	// ------------------------------------------------------------------------
	// main methods called in the server frame
	// ------------------------------------------------------------------------
	void		_MaintainSimulation();						// maintain the simulation
	int			_MaintainHousekeeping();					// maintain clients ( client timeouts etc. )
	int			_MaintainMasterServer();					// maintain communication to master server

	E_GameServer();										// standard ctor
	~E_GameServer();										// standard dtor

public: 	// methods

	// SINGLETON pattern
	static E_GameServer* GetGameServer()
	{
		static E_GameServer _TheGameServer;
		return &_TheGameServer;
	}

	int			Init();										// init the server components
	int			Kill();										// kill the server components
	
	int			ParseCommandLine( int argc, char** argv );	// parse the command line

	int			PrintCopyRight();							// print copyright
	int			PrintUsage();								// print program usage
	
	int			MainLoop();									// server mainloop
	refframe_t	ServerFrame();								// server Frame

	// set the new masterserver info
	void		SetMasterServerInfo( char* pName, refframe_t _MasterServer_FrameTime );

	// check whether the supplied node matches the stored masterserver node
	int			IsMasterServerNode( node_t* node );

	// set a new masterserver challenge
	void		SetMasterServerChallenge( int nMASVChallenge );

	// add a serverlink
	int			AddServerLink( int serverid, Vector3* pos_spec, Vector3* dir_spec );

	// accessor methods
	refframe_t	GetSimTickFrameTime()		{ return m_SimTick_FrameTime; }
	int			GetPacketAverageSecs()		{ return m_nPacketAverageSecs; }
	refframe_t  GetMasterServerFrameTime()  { return m_MasterServer_FrameTime; }

	void		SetQuitFlag()				{ m_bQuit = TRUE; }
};

#endif // _E_GAMESERVER_H_