/
sv_ccmds.c
744 lines (630 loc) · 15.5 KB
/
sv_ccmds.c
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
/*
* Wolfenstein: Enemy Territory GPL Source Code
* Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
*
* ET: Legacy
* Copyright (C) 2012 Jan Simek <mail@etlegacy.com>
*
* This file is part of ET: Legacy - http://www.etlegacy.com
*
* ET: Legacy 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 3 of the License, or
* (at your option) any later version.
*
* ET: Legacy 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 ET: Legacy. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, Wolfenstein: Enemy Territory GPL Source Code is also
* subject to certain additional terms. You should have received a copy
* of these additional terms immediately following the terms and conditions
* of the GNU General Public License which accompanied the source code.
* If not, please request a copy in writing from id Software at the address below.
*
* id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
*
* @file sv_ccmds.c
* @brief OPERATOR CONSOLE ONLY COMMANDS
*
* These commands can only be entered from stdin or by a remote operator datagram
*/
#include "server.h"
/*
==================
SV_GetPlayerByName
Returns the player with name from Cmd_Argv(1)
==================
*/
static client_t *SV_GetPlayerByName(void)
{
client_t *cl;
int i;
char *s;
char cleanName[64];
// make sure server is running
if (!com_sv_running->integer)
{
return NULL;
}
if (Cmd_Argc() < 2)
{
Com_Printf("No player specified.\n");
return NULL;
}
s = Cmd_Argv(1);
// check for a name match
for (i = 0, cl = svs.clients ; i < sv_maxclients->integer ; i++, cl++)
{
if (cl->state <= CS_ZOMBIE)
{
continue;
}
if (!Q_stricmp(cl->name, s))
{
return cl;
}
Q_strncpyz(cleanName, cl->name, sizeof(cleanName));
Q_CleanStr(cleanName);
if (!Q_stricmp(cleanName, s))
{
return cl;
}
}
Com_Printf("Player %s is not on the server\n", s);
return NULL;
}
//=========================================================
/*
==================
SV_Map_f
Restart the server on a different map
==================
*/
static void SV_Map_f(void)
{
char *cmd;
char *map;
char mapname[MAX_QPATH];
qboolean killBots, cheat;
char expanded[MAX_QPATH];
map = Cmd_Argv(1);
if (!map)
{
return;
}
if (!com_gameInfo.spEnabled)
{
if (!Q_stricmp(Cmd_Argv(0), "spdevmap") || !Q_stricmp(Cmd_Argv(0), "spmap"))
{
Com_Printf("Single Player is not enabled.\n");
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;
}
Cvar_Set("gamestate", va("%i", GS_INITIALIZE)); // NERVE - SMF - reset gamestate on map/devmap
Cvar_Set("g_currentRound", "0"); // NERVE - SMF - reset the current round
Cvar_Set("g_nextTimeLimit", "0"); // NERVE - SMF - reset the next time limit
// START Mad Doctor I changes, 8/14/2002. Need a way to force load a single player map as single player
if (!Q_stricmp(Cmd_Argv(0), "spdevmap") || !Q_stricmp(Cmd_Argv(0), "spmap"))
{
// This is explicitly asking for a single player load of this map
Cvar_Set("g_gametype", va("%i", com_gameInfo.defaultSPGameType));
// force latched values to get set
Cvar_Get("g_gametype", va("%i", com_gameInfo.defaultSPGameType), CVAR_SERVERINFO | CVAR_USERINFO | CVAR_LATCH);
}
cmd = Cmd_Argv(0);
if (!Q_stricmp(cmd, "devmap"))
{
cheat = qtrue;
killBots = qtrue;
}
else
if (!Q_stricmp(Cmd_Argv(0), "spdevmap"))
{
cheat = qtrue;
killBots = qtrue;
}
else
{
cheat = qfalse;
killBots = qfalse;
}
// save the map name here cause on a map restart we reload the q3config.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");
}
}
/*
================
SV_CheckTransitionGameState
================
*/
static qboolean SV_CheckTransitionGameState(gamestate_t new_gs, gamestate_t old_gs)
{
if (old_gs == new_gs && new_gs != GS_PLAYING)
{
return qfalse;
}
if (old_gs == GS_WAITING_FOR_PLAYERS && new_gs != GS_WARMUP)
{
return qfalse;
}
if (old_gs == GS_INTERMISSION && new_gs != GS_WARMUP)
{
return qfalse;
}
if (old_gs == GS_RESET && (new_gs != GS_WAITING_FOR_PLAYERS && new_gs != GS_WARMUP))
{
return qfalse;
}
return qtrue;
}
/*
================
SV_TransitionGameState
================
*/
static qboolean SV_TransitionGameState(gamestate_t new_gs, gamestate_t old_gs, int delay)
{
// we always do a warmup before starting match
if (old_gs == GS_INTERMISSION && new_gs == GS_PLAYING)
{
new_gs = GS_WARMUP;
}
// check if its a valid state transition
if (!SV_CheckTransitionGameState(new_gs, old_gs))
{
return qfalse;
}
if (new_gs == GS_RESET)
{
new_gs = GS_WARMUP;
}
Cvar_Set("gamestate", va("%i", new_gs));
return qtrue;
}
void MSG_PrioritiseEntitystateFields(void);
void MSG_PrioritisePlayerStateFields(void);
static void SV_FieldInfo_f(void)
{
MSG_PrioritiseEntitystateFields();
MSG_PrioritisePlayerStateFields();
}
/*
================
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;
qboolean isBot;
int delay = 0;
gamestate_t new_gs, old_gs; // NERVE - SMF
// 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 (Cmd_Argc() > 1)
{
delay = atoi(Cmd_Argv(1));
}
if (delay)
{
sv.restartTime = svs.time + delay * 1000;
SV_SetConfigstring(CS_WARMUP, va("%i", sv.restartTime));
return;
}
// NERVE - SMF - read in gamestate or just default to GS_PLAYING
old_gs = atoi(Cvar_VariableString("gamestate"));
if (Cmd_Argc() > 2)
{
new_gs = atoi(Cmd_Argv(2));
}
else
{
new_gs = GS_PLAYING;
}
if (!SV_TransitionGameState(new_gs, old_gs, delay))
{
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("sv_maxclients 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));
// 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;
Cvar_Set("sv_serverRestarting", "1");
SV_RestartGameProgs();
// run a few frames to allow everything to settle
for (i = 0; i < GAME_INIT_FRAMES; i++)
{
VM_Call(gvm, GAME_RUN_FRAME, svs.time);
svs.time += FRAMETIME;
}
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;
}
if (client->netchan.remoteAddress.type == NA_BOT)
{
isBot = qtrue;
}
else
{
isBot = qfalse;
}
// 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, isBot));
if (denied)
{
// this generally shouldn't happen, because the client
// was connected before the level change
SV_DropClient(client, denied);
if (!isBot)
{
Com_Printf("SV_MapRestart_f(%d): dropped client %i - denied!\n", delay, i); // bk010125
}
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, svs.time);
svs.time += FRAMETIME;
Cvar_Set("sv_serverRestarting", "0");
}
//===============================================================
/*
==================
SV_TempBanNetAddress
==================
*/
void SV_TempBanNetAddress(netadr_t address, int length)
{
int i;
int oldesttime = 0;
int oldest = -1;
for (i = 0; i < MAX_TEMPBAN_ADDRESSES; i++)
{
if (!svs.tempBanAddresses[i].endtime || svs.tempBanAddresses[i].endtime < svs.time)
{
// found a free slot
svs.tempBanAddresses[i].adr = address;
svs.tempBanAddresses[i].endtime = svs.time + (length * 1000);
return;
}
else
{
if (oldest == -1 || oldesttime > svs.tempBanAddresses[i].endtime)
{
oldesttime = svs.tempBanAddresses[i].endtime;
oldest = i;
}
}
}
svs.tempBanAddresses[oldest].adr = address;
svs.tempBanAddresses[oldest].endtime = svs.time + length;
}
qboolean SV_TempBanIsBanned(netadr_t address)
{
int i;
for (i = 0; i < MAX_TEMPBAN_ADDRESSES; i++)
{
if (svs.tempBanAddresses[i].endtime && svs.tempBanAddresses[i].endtime > svs.time)
{
if (NET_CompareAdr(address, svs.tempBanAddresses[i].adr))
{
return qtrue;
}
}
}
return qfalse;
}
/*
================
SV_Status_f
================
*/
static void SV_Status_f(void)
{
int i, j, l;
client_t *cl;
playerState_t *ps;
const char *s;
int ping;
// make sure server is running
if (!com_sv_running->integer)
{
Com_Printf("Server is not running.\n");
return;
}
Com_Printf("map: %s\n", sv_mapname->string);
Com_Printf("num score ping name lastmsg address qport rate\n");
Com_Printf("--- ----- ---- --------------- ------- --------------------- ----- -----\n");
// FIXME: extend player name lenght (>16 chars) ? - they are printed!
// FIXME: do a Com_Printf per line! ... create the row at first
for (i = 0, cl = svs.clients ; i < sv_maxclients->integer ; i++, cl++)
{
if (!cl->state)
{
continue;
}
Com_Printf("%3i ", i);
ps = SV_GameClientNum(i);
Com_Printf("%5i ", ps->persistant[PERS_SCORE]);
if (cl->state == CS_CONNECTED)
{
Com_Printf("CNCT ");
}
else if (cl->state == CS_ZOMBIE)
{
Com_Printf("ZMBI ");
}
else
{
ping = cl->ping < 9999 ? cl->ping : 9999;
Com_Printf("%4i ", ping);
}
Com_Printf("%s", rc(cl->name));
l = 16 - strlen(cl->name);
for (j = 0 ; j < l ; j++)
{
Com_Printf(" ");
}
Com_Printf("%7i ", svs.time - cl->lastPacketTime);
s = NET_AdrToString(cl->netchan.remoteAddress);
Com_Printf("%s", s);
l = 22 - strlen(s);
for (j = 0 ; j < l ; j++)
{
Com_Printf(" ");
}
Com_Printf("%5i", cl->netchan.qport);
Com_Printf(" %5i\n", cl->rate);
}
Com_Printf("\n");
}
/*
==================
SV_ConSay_f
==================
*/
static void SV_ConSay_f(void)
{
char *p;
char text[1024];
// make sure server is running
if (!com_sv_running->integer)
{
Com_Printf("Server is not running.\n");
return;
}
if (Cmd_Argc() < 2)
{
return;
}
strcpy(text, "console: ");
p = Cmd_Args();
if (*p == '"')
{
p++;
p[strlen(p) - 1] = 0;
}
strcat(text, p);
SV_SendServerCommand(NULL, "chat \"%s\"", text);
}
/*
==================
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 | CVAR_SERVERINFO_NOUPDATE));
}
/*
===========
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_SERVERINFO | CVAR_SERVERINFO_NOUPDATE));
}
/*
===========
SV_DumpUser_f
Examine all a users info strings FIXME: move to game
===========
*/
static void SV_DumpUser_f(void)
{
client_t *cl;
// make sure server is running
if (!com_sv_running->integer)
{
Com_Printf("Server is not running.\n");
return;
}
if (Cmd_Argc() != 2)
{
Com_Printf("Usage: dumpuser <userid>\n");
return;
}
cl = SV_GetPlayerByName();
if (!cl)
{
Com_Printf("No player found.\n");
return;
}
Com_Printf("userinfo\n--------\n");
Info_Print(cl->userinfo);
}
/*
=================
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, qfalse);
}
}
/*
=================
SV_GameCompleteStatus_f
=================
*/
void SV_GameCompleteStatus_f(void)
{
SV_MasterGameCompleteStatus();
}
//===========================================================
/*
==================
SV_AddOperatorCommands
==================
*/
void SV_AddOperatorCommands(void)
{
static qboolean initialized;
if (initialized)
{
return;
}
initialized = qtrue;
Cmd_AddCommand("heartbeat", SV_Heartbeat_f);
Cmd_AddCommand("status", SV_Status_f);
Cmd_AddCommand("serverinfo", SV_Serverinfo_f);
Cmd_AddCommand("systeminfo", SV_Systeminfo_f);
Cmd_AddCommand("dumpuser", SV_DumpUser_f);
Cmd_AddCommand("map_restart", SV_MapRestart_f);
Cmd_AddCommand("fieldinfo", SV_FieldInfo_f);
Cmd_AddCommand("sectorlist", SV_SectorList_f);
Cmd_AddCommand("map", SV_Map_f);
Cmd_SetCommandCompletionFunc("map", SV_CompleteMapName);
Cmd_AddCommand("gameCompleteStatus", SV_GameCompleteStatus_f); // NERVE - SMF
Cmd_AddCommand("devmap", SV_Map_f);
Cmd_SetCommandCompletionFunc("devmap", SV_CompleteMapName);
Cmd_AddCommand("spmap", SV_Map_f);
Cmd_SetCommandCompletionFunc("spmap", SV_CompleteMapName);
Cmd_AddCommand("spdevmap", SV_Map_f);
Cmd_SetCommandCompletionFunc("spdevmap", SV_CompleteMapName);
Cmd_AddCommand("killserver", SV_KillServer_f);
if (com_dedicated->integer)
{
Cmd_AddCommand("say", SV_ConSay_f);
}
}
/*
==================
SV_RemoveOperatorCommands
==================
*/
void SV_RemoveOperatorCommands(void)
{
#if 0
// removing these won't let the server start again
Cmd_RemoveCommand("heartbeat");
Cmd_RemoveCommand("kick");
Cmd_RemoveCommand("banUser");
Cmd_RemoveCommand("banClient");
Cmd_RemoveCommand("status");
Cmd_RemoveCommand("serverinfo");
Cmd_RemoveCommand("systeminfo");
Cmd_RemoveCommand("dumpuser");
Cmd_RemoveCommand("map_restart");
Cmd_RemoveCommand("sectorlist");
Cmd_RemoveCommand("say");
#endif
}