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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
|
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
Copyright (C) 2000-2006 Tim Angus
This file is part of Tremulous.
Tremulous is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
Tremulous is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Tremulous; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
#include "server.h"
/*
===============================================================================
OPERATOR CONSOLE ONLY COMMANDS
These commands can only be entered from stdin or by a remote operator datagram
===============================================================================
*/
/*
==================
SV_Map_f
Restart the server on a different map
==================
*/
static void SV_Map_f( void ) {
char *cmd;
char *map;
qboolean killBots, cheat;
char expanded[MAX_QPATH];
char mapname[MAX_QPATH];
int i;
map = Cmd_Argv(1);
if ( !map ) {
return;
}
// make sure the level exists before trying to change, so that
// a typo at the server console won't end the game
Com_sprintf (expanded, sizeof(expanded), "maps/%s.bsp", map);
if ( FS_ReadFile (expanded, NULL) == -1 ) {
Com_Printf ("Can't find map %s\n", expanded);
return;
}
cmd = Cmd_Argv(0);
if ( !Q_stricmp( cmd, "devmap" ) ) {
cheat = qtrue;
killBots = qtrue;
} else {
cheat = qfalse;
killBots = qfalse;
}
// save the map name here cause on a map restart we reload the autogen.cfg
// and thus nuke the arguments of the map command
Q_strncpyz(mapname, map, sizeof(mapname));
// start up the map
SV_SpawnServer( mapname, killBots );
// set the cheat value
// if the level was started with "map <levelname>", then
// cheats will not be allowed. If started with "devmap <levelname>"
// then cheats will be allowed
if ( cheat ) {
Cvar_Set( "sv_cheats", "1" );
} else {
Cvar_Set( "sv_cheats", "0" );
}
// This forces the local master server IP address cache
// to be updated on sending the next heartbeat
for( i = 0; i < MAX_MASTER_SERVERS; i++ )
sv_master[ i ]->modified = qtrue;
}
/*
================
SV_MapRestart_f
Completely restarts a level, but doesn't send a new gamestate to the clients.
This allows fair starts with variable load times.
================
*/
static void SV_MapRestart_f( void ) {
int i;
client_t *client;
char *denied;
int delay;
// make sure we aren't restarting twice in the same frame
if ( com_frameTime == sv.serverId ) {
return;
}
// make sure server is running
if ( !com_sv_running->integer ) {
Com_Printf( "Server is not running.\n" );
return;
}
if ( sv.restartTime ) {
return;
}
if (Cmd_Argc() > 1 ) {
delay = atoi( Cmd_Argv(1) );
}
else {
delay = 5;
}
if( delay && !Cvar_VariableValue("g_doWarmup") ) {
sv.restartTime = sv.time + delay * 1000;
SV_SetConfigstring( CS_WARMUP, va("%i", sv.restartTime) );
return;
}
// check for changes in variables that can't just be restarted
// check for maxclients change
if ( sv_maxclients->modified ) {
char mapname[MAX_QPATH];
Com_Printf( "variable change -- restarting.\n" );
// restart the map the slow way
Q_strncpyz( mapname, Cvar_VariableString( "mapname" ), sizeof( mapname ) );
SV_SpawnServer( mapname, qfalse );
return;
}
// toggle the server bit so clients can detect that a
// map_restart has happened
svs.snapFlagServerBit ^= SNAPFLAG_SERVERCOUNT;
// generate a new serverid
// TTimo - don't update restartedserverId there, otherwise we won't deal correctly with multiple map_restart
sv.serverId = com_frameTime;
Cvar_Set( "sv_serverid", va("%i", sv.serverId ) );
// if a map_restart occurs while a client is changing maps, we need
// to give them the correct time so that when they finish loading
// they don't violate the backwards time check in cl_cgame.c
for (i=0 ; i<sv_maxclients->integer ; i++) {
if (svs.clients[i].state == CS_PRIMED) {
svs.clients[i].oldServerTime = sv.restartTime;
}
}
// reset all the vm data in place without changing memory allocation
// note that we do NOT set sv.state = SS_LOADING, so configstrings that
// had been changed from their default values will generate broadcast updates
sv.state = SS_LOADING;
sv.restarting = qtrue;
SV_RestartGameProgs();
// run a few frames to allow everything to settle
for (i = 0; i < 3; i++)
{
VM_Call (gvm, GAME_RUN_FRAME, sv.time);
sv.time += 100;
svs.time += 100;
}
sv.state = SS_GAME;
sv.restarting = qfalse;
// connect and begin all the clients
for (i=0 ; i<sv_maxclients->integer ; i++) {
client = &svs.clients[i];
// send the new gamestate to all connected clients
if ( client->state < CS_CONNECTED) {
continue;
}
// add the map_restart command
SV_AddServerCommand( client, "map_restart\n" );
// connect the client again, without the firstTime flag
denied = VM_ExplicitArgPtr( gvm, VM_Call( gvm, GAME_CLIENT_CONNECT, i, qfalse ) );
if ( denied ) {
// this generally shouldn't happen, because the client
// was connected before the level change
SV_DropClient( client, denied );
Com_Printf( "SV_MapRestart_f(%d): dropped client %i - denied!\n", delay, i );
continue;
}
client->state = CS_ACTIVE;
SV_ClientEnterWorld( client, &client->lastUsercmd );
}
// run another frame to allow things to look at all the players
VM_Call (gvm, GAME_RUN_FRAME, sv.time);
sv.time += 100;
svs.time += 100;
}
/*
==================
SV_Heartbeat_f
Also called by SV_DropClient, SV_DirectConnect, and SV_SpawnServer
==================
*/
void SV_Heartbeat_f( void ) {
svs.nextHeartbeatTime = -9999999;
}
/*
===========
SV_Serverinfo_f
Examine the serverinfo string
===========
*/
static void SV_Serverinfo_f( void ) {
Com_Printf ("Server info settings:\n");
Info_Print ( Cvar_InfoString( CVAR_SERVERINFO ) );
}
/*
===========
SV_Systeminfo_f
Examine or change the serverinfo string
===========
*/
static void SV_Systeminfo_f( void ) {
Com_Printf ("System info settings:\n");
Info_Print ( Cvar_InfoString( CVAR_SYSTEMINFO ) );
}
/*
=================
SV_KillServer
=================
*/
static void SV_KillServer_f( void ) {
SV_Shutdown( "killserver" );
}
//===========================================================
/*
==================
SV_CompleteMapName
==================
*/
static void SV_CompleteMapName( char *args, int argNum ) {
if( argNum == 2 ) {
Field_CompleteFilename( "maps", "bsp", qtrue );
}
}
/*
==================
SV_AddOperatorCommands
==================
*/
void SV_AddOperatorCommands( void ) {
static qboolean initialized;
if ( initialized ) {
return;
}
initialized = qtrue;
Cmd_AddCommand ("heartbeat", SV_Heartbeat_f);
Cmd_AddCommand ("serverinfo", SV_Serverinfo_f);
Cmd_AddCommand ("systeminfo", SV_Systeminfo_f);
Cmd_AddCommand ("map_restart", SV_MapRestart_f);
Cmd_AddCommand ("sectorlist", SV_SectorList_f);
Cmd_AddCommand ("map", SV_Map_f);
Cmd_SetCommandCompletionFunc( "map", SV_CompleteMapName );
Cmd_AddCommand ("devmap", SV_Map_f);
Cmd_SetCommandCompletionFunc( "devmap", SV_CompleteMapName );
Cmd_AddCommand ("killserver", SV_KillServer_f);
}
/*
==================
SV_RemoveOperatorCommands
==================
*/
void SV_RemoveOperatorCommands( void ) {
#if 0
// removing these won't let the server start again
Cmd_RemoveCommand ("heartbeat");
Cmd_RemoveCommand ("serverinfo");
Cmd_RemoveCommand ("systeminfo");
Cmd_RemoveCommand ("map_restart");
Cmd_RemoveCommand ("sectorlist");
#endif
}
|