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
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
|
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program 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.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// Created on 18.01.2004 by RST.
// $Id: SV_CCMDS.java,v 1.12 2004-09-22 19:22:12 salomo Exp $
package jake2.server;
import jake2.Defines;
import jake2.Globals;
import jake2.game.Cmd;
import jake2.game.EndianHandler;
import jake2.game.GameSVCmds;
import jake2.game.GameSave;
import jake2.game.Info;
import jake2.game.cvar_t;
import jake2.qcommon.CM;
import jake2.qcommon.Com;
import jake2.qcommon.Cvar;
import jake2.qcommon.FS;
import jake2.qcommon.MSG;
import jake2.qcommon.Netchan;
import jake2.qcommon.SZ;
import jake2.qcommon.netadr_t;
import jake2.qcommon.sizebuf_t;
import jake2.qcommon.xcommand_t;
import jake2.sys.NET;
import jake2.sys.Sys;
import jake2.util.Lib;
import jake2.util.QuakeFile;
import jake2.util.Vargs;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Calendar;
public class SV_CCMDS {
/*
===============================================================================
OPERATOR CONSOLE ONLY COMMANDS
These commands can only be entered from stdin or by a remote operator datagram
===============================================================================
*/
/*
====================
SV_SetMaster_f
Specify a list of master servers
====================
*/
public static void SV_SetMaster_f() {
int i, slot;
// only dedicated servers send heartbeats
if (Globals.dedicated.value == 0) {
Com.Printf("Only dedicated servers use masters.\n");
return;
}
// make sure the server is listed public
Cvar.Set("public", "1");
for (i = 1; i < Defines.MAX_MASTERS; i++)
SV_MAIN.master_adr[i] = new netadr_t();
slot = 1; // slot 0 will always contain the id master
for (i = 1; i < Cmd.Argc(); i++) {
if (slot == Defines.MAX_MASTERS)
break;
if (!NET.StringToAdr(Cmd.Argv(i), SV_MAIN.master_adr[i])) {
Com.Printf("Bad address: " + Cmd.Argv(i) + "\n");
continue;
}
if (SV_MAIN.master_adr[slot].port == 0)
SV_MAIN.master_adr[slot].port = Defines.PORT_MASTER;
Com.Printf("Master server at " + NET.AdrToString(SV_MAIN.master_adr[slot]) + "\n");
Com.Printf("Sending a ping.\n");
Netchan.OutOfBandPrint(Defines.NS_SERVER, SV_MAIN.master_adr[slot], "ping");
slot++;
}
SV_INIT.svs.last_heartbeat = -9999999;
}
/*
==================
SV_SetPlayer
Sets sv_client and sv_player to the player with idnum Cmd.Argv(1)
==================
*/
public static boolean SV_SetPlayer() {
client_t cl;
int i;
int idnum;
String s;
if (Cmd.Argc() < 2)
return false;
s = Cmd.Argv(1);
// numeric values are just slot numbers
if (s.charAt(0) >= '0' && s.charAt(0) <= '9') {
idnum = Lib.atoi(Cmd.Argv(1));
if (idnum < 0 || idnum >= SV_MAIN.maxclients.value) {
Com.Printf("Bad client slot: " + idnum + "\n");
return false;
}
SV_MAIN.sv_client = SV_INIT.svs.clients[idnum];
SV_USER.sv_player = SV_MAIN.sv_client.edict;
if (0 == SV_MAIN.sv_client.state) {
Com.Printf("Client " + idnum + " is not active\n");
return false;
}
return true;
}
// check for a name match
for (i = 0; i < SV_MAIN.maxclients.value; i++) {
cl = SV_INIT.svs.clients[i];
if (0 == cl.state)
continue;
if (0 == Lib.strcmp(cl.name, s)) {
SV_MAIN.sv_client = cl;
SV_USER.sv_player = SV_MAIN.sv_client.edict;
return true;
}
}
Com.Printf("Userid " + s + " is not on the server\n");
return false;
}
/*
===============================================================================
SAVEGAME FILES
===============================================================================
*/
public static void remove(String name) {
try {
new File(name).delete();
}
catch (Exception e) {
}
}
/*
=====================
SV_WipeSavegame
Delete save/<XXX>/
=====================
*/
public static void SV_WipeSavegame(String savename) {
String name, s;
Com.DPrintf("SV_WipeSaveGame(" + savename + ")\n");
name = FS.Gamedir() + "/save/" + savename + "/server.ssv";
remove(name);
name = FS.Gamedir() + "/save/" + savename + "/game.ssv";
remove(name);
name = FS.Gamedir() + "/save/" + savename + "/*.sav";
File f = Sys.FindFirst(name, 0, 0);
while (f != null) {
f.delete();
f = Sys.FindNext();
}
Sys.FindClose();
name = FS.Gamedir() + "/save/" + savename + "/*.sv2";
f = Sys.FindFirst(name, 0, 0);
while (f != null) {
f.delete();
f = Sys.FindNext();
}
Sys.FindClose();
}
/*
================
CopyFile
================
*/
public static void CopyFile(String src, String dst) {
RandomAccessFile f1, f2;
int l = -1;
byte buffer[] = new byte[65536];
//Com.DPrintf("CopyFile (" + src + ", " + dst + ")\n");
try {
f1 = new RandomAccessFile(src, "r");
}
catch (Exception e) {
return;
}
try {
f2 = new RandomAccessFile(dst, "rw");
}
catch (Exception e) {
try {
f1.close();
}
catch (IOException e1) {
e1.printStackTrace();
}
return;
}
while (true) {
try {
l = f1.read(buffer, 0, 65536);
}
catch (IOException e1) {
e1.printStackTrace();
}
if (l == -1)
break;
try {
f2.write(buffer, 0, l);
}
catch (IOException e2) {
e2.printStackTrace();
}
}
try {
f1.close();
}
catch (IOException e1) {
e1.printStackTrace();
}
try {
f2.close();
}
catch (IOException e2) {
e2.printStackTrace();
}
}
/*
================
SV_CopySaveGame
================
*/
public static void SV_CopySaveGame(String src, String dst) {
//char name[MAX_OSPATH], name2[MAX_OSPATH];
int l, len;
File found;
String name, name2;
Com.DPrintf("SV_CopySaveGame(" + src + "," + dst + ")\n");
SV_WipeSavegame(dst);
// copy the savegame over
name = FS.Gamedir() + "/save/" + src + "/server.ssv";
name2 = FS.Gamedir() + "/save/" + dst + "/server.ssv";
FS.CreatePath(name2);
CopyFile(name, name2);
name = FS.Gamedir() + "/save/" + src + "/game.ssv";
name2 = FS.Gamedir() + "/save/" + dst + "/game.ssv";
CopyFile(name, name2);
String name1 = FS.Gamedir() + "/save/" + src + "/";
len = name1.length();
name = FS.Gamedir() + "/save/" + src + "/*.sav";
found = Sys.FindFirst(name, 0, 0);
while (found != null) {
name = name1 + found.getName();
name2 = FS.Gamedir() + "/save/" + dst + "/" + found.getName();
CopyFile(name, name2);
// change sav to sv2
name = name.substring(0, name.length() - 3) + "sv2";
name2 = name2.substring(0, name2.length() - 3) + "sv2";
CopyFile(name, name2);
found = Sys.FindNext();
}
Sys.FindClose();
}
/*
==============
SV_WriteLevelFile
==============
*/
public static void SV_WriteLevelFile() {
String name;
QuakeFile f;
Com.DPrintf("SV_WriteLevelFile()\n");
name = FS.Gamedir() + "/save/current/" + SV_INIT.sv.name + ".sv2";
try {
f = new QuakeFile(name, "rw");
for (int i = 0; i < Defines.MAX_CONFIGSTRINGS; i++)
f.writeString(SV_INIT.sv.configstrings[i]);
CM.CM_WritePortalState(f);
f.close();
}
catch (Exception e) {
Com.Printf("Failed to open " + name + "\n");
e.printStackTrace();
}
name = FS.Gamedir() + "/save/current/" + SV_INIT.sv.name + ".sav";
GameSave.WriteLevel(name);
}
/*
==============
SV_ReadLevelFile
==============
*/
public static void SV_ReadLevelFile() {
//char name[MAX_OSPATH];
String name;
QuakeFile f;
Com.DPrintf("SV_ReadLevelFile()\n");
name = FS.Gamedir() + "/save/current/" + SV_INIT.sv.name + ".sv2";
try {
f = new QuakeFile(name, "r");
for (int n = 0; n < Defines.MAX_CONFIGSTRINGS; n++)
SV_INIT.sv.configstrings[n] = f.readString();
CM.CM_ReadPortalState(f);
f.close();
}
catch (IOException e1) {
Com.Printf("Failed to open " + name + "\n");
e1.printStackTrace();
}
name = FS.Gamedir() + "/save/current/" + SV_INIT.sv.name + ".sav";
GameSave.ReadLevel(name);
}
/*
==============
SV_WriteServerFile
==============
*/
public static void SV_WriteServerFile(boolean autosave) {
QuakeFile f;
cvar_t var;
String filename, name, string, comment;
Com.DPrintf("SV_WriteServerFile(" + (autosave ? "true" : "false") + ")\n");
filename = FS.Gamedir() + "/save/current/server.ssv";
try {
f = new QuakeFile(filename, "rw");
if (!autosave) {
Calendar c = Calendar.getInstance();
comment =
Com.sprintf(
"%2i:%2i %2i/%2i ",
new Vargs().add(c.get(Calendar.HOUR_OF_DAY)).add(c.get(Calendar.MINUTE)).add(
c.get(Calendar.MONTH) + 1).add(
c.get(Calendar.DAY_OF_MONTH)));
comment += SV_INIT.sv.configstrings[Defines.CS_NAME];
}
else {
// autosaved
comment = "ENTERING " + SV_INIT.sv.configstrings[Defines.CS_NAME];
}
f.writeString(comment);
f.writeString(SV_INIT.svs.mapcmd);
// write the mapcmd
// write all CVAR_LATCH cvars
// these will be things like coop, skill, deathmatch, etc
for (var = Globals.cvar_vars; var != null; var = var.next) {
if (0 == (var.flags & Defines.CVAR_LATCH))
continue;
if (var.name.length() >= Defines.MAX_OSPATH - 1 || var.string.length() >= 128 - 1) {
Com.Printf("Cvar too long: " + var.name + " = " + var.string + "\n");
continue;
}
name = var.name;
string = var.string;
try {
f.writeString(name);
f.writeString(string);
}
catch (IOException e2) {
}
}
// rst: for termination.
f.writeString(null);
f.close();
}
catch (Exception e) {
Com.Printf("Couldn't write " + filename + "\n");
}
// write game state
filename = FS.Gamedir() + "/save/current/game.ssv";
GameSave.WriteGame(filename, autosave);
}
/*
==============
SV_ReadServerFile
==============
*/
public static void SV_ReadServerFile() {
String filename, name = "", string, comment, mapcmd;
try {
QuakeFile f;
mapcmd = "";
Com.DPrintf("SV_ReadServerFile()\n");
filename = FS.Gamedir() + "/save/current/server.ssv";
f = new QuakeFile(filename, "r");
// read the comment field
comment = f.readString();
// read the mapcmd
mapcmd = f.readString();
// read all CVAR_LATCH cvars
// these will be things like coop, skill, deathmatch, etc
while (true) {
name = f.readString();
if (name == null)
break;
string = f.readString();
Com.DPrintf("Set " + name + " = " + string + "\n");
Cvar.ForceSet(name, string);
}
f.close();
// start a new game fresh with new cvars
SV_INIT.SV_InitGame();
SV_INIT.svs.mapcmd = mapcmd;
// read game state
filename = FS.Gamedir() + "/save/current/game.ssv";
GameSave.ReadGame(filename);
}
catch (Exception e) {
Com.Printf("Couldn't read file " + name + "\n");
e.printStackTrace();
}
}
//=========================================================
/*
==================
SV_DemoMap_f
Puts the server in demo mode on a specific map/cinematic
==================
*/
public static void SV_DemoMap_f() {
SV_INIT.SV_Map(true, Cmd.Argv(1), false);
}
/*
==================
SV_GameMap_f
Saves the state of the map just being exited and goes to a new map.
If the initial character of the map string is '*', the next map is
in a new unit, so the current savegame directory is cleared of
map files.
Example:
*inter.cin+jail
Clears the archived maps, plays the inter.cin cinematic, then
goes to map jail.bsp.
==================
*/
public static void SV_GameMap_f() {
String map;
int i;
client_t cl;
boolean savedInuse[];
if (Cmd.Argc() != 2) {
Com.Printf("USAGE: gamemap <map>\n");
return;
}
Com.DPrintf("SV_GameMap(" + Cmd.Argv(1) + ")\n");
FS.CreatePath(FS.Gamedir() + "/save/current/");
// check for clearing the current savegame
map = Cmd.Argv(1);
if (map.charAt(0) == '*') {
// wipe all the *.sav files
SV_WipeSavegame("current");
}
else { // save the map just exited
if (SV_INIT.sv.state == Defines.ss_game) {
// clear all the client inuse flags before saving so that
// when the level is re-entered, the clients will spawn
// at spawn points instead of occupying body shells
savedInuse = new boolean[(int) SV_MAIN.maxclients.value];
for (i = 0; i < SV_MAIN.maxclients.value; i++) {
cl = SV_INIT.svs.clients[i];
savedInuse[i] = cl.edict.inuse;
cl.edict.inuse = false;
}
SV_WriteLevelFile();
// we must restore these for clients to transfer over correctly
for (i = 0; i < SV_MAIN.maxclients.value; i++) {
cl = SV_INIT.svs.clients[i];
cl.edict.inuse = savedInuse[i];
}
savedInuse = null;
}
}
// start up the next map
SV_INIT.SV_Map(false, Cmd.Argv(1), false);
// archive server state
SV_INIT.svs.mapcmd = Cmd.Argv(1);
// copy off the level to the autosave slot
if (0 == Globals.dedicated.value) {
SV_WriteServerFile(true);
SV_CopySaveGame("current", "save0");
}
}
/*
==================
SV_Map_f
Goes directly to a given map without any savegame archiving.
For development work
==================
*/
public static void SV_Map_f() {
String map;
//char expanded[MAX_QPATH];
String expanded;
// if not a pcx, demo, or cinematic, check to make sure the level exists
map = Cmd.Argv(1);
if (map.indexOf(".") < 0) {
expanded = "maps/" + map + ".bsp";
if (FS.LoadFile(expanded) == null) {
Com.Printf("Can't find " + expanded + "\n");
return;
}
}
SV_INIT.sv.state = Defines.ss_dead; // don't save current level when changing
SV_WipeSavegame("current");
SV_GameMap_f();
}
/*
=====================================================================
SAVEGAMES
=====================================================================
*/
/*
==============
SV_Loadgame_f
==============
*/
public static void SV_Loadgame_f() {
String name;
RandomAccessFile f;
String dir;
if (Cmd.Argc() != 2) {
Com.Printf("USAGE: loadgame <directory>\n");
return;
}
Com.Printf("Loading game...\n");
dir = Cmd.Argv(1);
if (Lib.strstr(dir, "..") || Lib.strstr(dir, "/") || Lib.strstr(dir, "\\")) {
Com.Printf("Bad savedir.\n");
}
// make sure the server.ssv file exists
name = FS.Gamedir() + "/save/" + Cmd.Argv(1) + "/server.ssv";
try {
f = new RandomAccessFile(name, "r");
}
catch (FileNotFoundException e) {
Com.Printf("No such savegame: " + name + "\n");
return;
}
try {
f.close();
}
catch (IOException e1) {
e1.printStackTrace();
}
SV_CopySaveGame(Cmd.Argv(1), "current");
SV_ReadServerFile();
// go to the map
SV_INIT.sv.state = Defines.ss_dead; // don't save current level when changing
SV_INIT.SV_Map(false, SV_INIT.svs.mapcmd, true);
}
/*
==============
SV_Savegame_f
==============
*/
public static void SV_Savegame_f() {
String dir;
if (SV_INIT.sv.state != Defines.ss_game) {
Com.Printf("You must be in a game to save.\n");
return;
}
if (Cmd.Argc() != 2) {
Com.Printf("USAGE: savegame <directory>\n");
return;
}
if (Cvar.VariableValue("deathmatch") != 0) {
Com.Printf("Can't savegame in a deathmatch\n");
return;
}
if (0 == Lib.strcmp(Cmd.Argv(1), "current")) {
Com.Printf("Can't save to 'current'\n");
return;
}
if (SV_MAIN.maxclients.value == 1 && SV_INIT.svs.clients[0].edict.client.ps.stats[Defines.STAT_HEALTH] <= 0) {
Com.Printf("\nCan't savegame while dead!\n");
return;
}
dir = Cmd.Argv(1);
if (Lib.strstr(dir, "..") || Lib.strstr(dir, "/") || Lib.strstr(dir, "\\")) {
Com.Printf("Bad savedir.\n");
}
Com.Printf("Saving game...\n");
// archive current level, including all client edicts.
// when the level is reloaded, they will be shells awaiting
// a connecting client
SV_WriteLevelFile();
// save server state
try {
SV_WriteServerFile(false);
}
catch (Exception e) {
Com.Printf("IOError in SV_WriteServerFile: " + e);
}
// copy it off
SV_CopySaveGame("current", dir);
Com.Printf("Done.\n");
}
//===============================================================
/*
==================
SV_Kick_f
Kick a user off of the server
==================
*/
public static void SV_Kick_f() {
if (!SV_INIT.svs.initialized) {
Com.Printf("No server running.\n");
return;
}
if (Cmd.Argc() != 2) {
Com.Printf("Usage: kick <userid>\n");
return;
}
if (!SV_SetPlayer())
return;
SV_SEND.SV_BroadcastPrintf(Defines.PRINT_HIGH, SV_MAIN.sv_client.name + " was kicked\n");
// print directly, because the dropped client won't get the
// SV_BroadcastPrintf message
SV_SEND.SV_ClientPrintf(SV_MAIN.sv_client, Defines.PRINT_HIGH, "You were kicked from the game\n");
SV_MAIN.SV_DropClient(SV_MAIN.sv_client);
SV_MAIN.sv_client.lastmessage = SV_INIT.svs.realtime; // min case there is a funny zombie
}
/*
================
SV_Status_f
================
*/
public static void SV_Status_f() {
int i, j, l;
client_t cl;
String s;
int ping;
if (SV_INIT.svs.clients == null) {
Com.Printf("No server running.\n");
return;
}
Com.Printf("map : " + SV_INIT.sv.name + "\n");
Com.Printf("num score ping name lastmsg address qport \n");
Com.Printf("--- ----- ---- --------------- ------- --------------------- ------\n");
for (i = 0; i < SV_MAIN.maxclients.value; i++) {
cl = SV_INIT.svs.clients[i];
if (0 == cl.state)
continue;
Com.Printf("%3i ", new Vargs().add(i));
Com.Printf("%5i ", new Vargs().add(cl.edict.client.ps.stats[Defines.STAT_FRAGS]));
if (cl.state == Defines.cs_connected)
Com.Printf("CNCT ");
else if (cl.state == Defines.cs_zombie)
Com.Printf("ZMBI ");
else {
ping = cl.ping < 9999 ? cl.ping : 9999;
Com.Printf("%4i ", new Vargs().add(ping));
}
Com.Printf("%s", new Vargs().add(cl.name));
l = 16 - cl.name.length();
for (j = 0; j < l; j++)
Com.Printf(" ");
Com.Printf("%7i ", new Vargs().add(SV_INIT.svs.realtime - cl.lastmessage));
s = NET.AdrToString(cl.netchan.remote_address);
Com.Printf(s);
l = 22 - s.length();
for (j = 0; j < l; j++)
Com.Printf(" ");
Com.Printf("%5i", new Vargs().add(cl.netchan.qport));
Com.Printf("\n");
}
Com.Printf("\n");
}
/*
==================
SV_ConSay_f
==================
*/
public static void SV_ConSay_f() {
client_t client;
int j;
String p;
String text; // char[1024];
if (Cmd.Argc() < 2)
return;
text = "console: ";
p = Cmd.Args();
if (p.charAt(0) == '"') {
p = p.substring(1, p.length() - 1);
}
text += p;
for (j = 0; j < SV_MAIN.maxclients.value; j++) {
client = SV_INIT.svs.clients[j];
if (client.state != Defines.cs_spawned)
continue;
SV_SEND.SV_ClientPrintf(client, Defines.PRINT_CHAT, text + "\n");
}
}
/*
==================
SV_Heartbeat_f
==================
*/
public static void SV_Heartbeat_f() {
SV_INIT.svs.last_heartbeat = -9999999;
}
/*
===========
SV_Serverinfo_f
Examine or change the serverinfo string
===========
*/
public static void SV_Serverinfo_f() {
Com.Printf("Server info settings:\n");
Info.Print(Cvar.Serverinfo());
}
/*
===========
SV_DumpUser_f
Examine all a users info strings
===========
*/
public static void SV_DumpUser_f() {
if (Cmd.Argc() != 2) {
Com.Printf("Usage: info <userid>\n");
return;
}
if (!SV_SetPlayer())
return;
Com.Printf("userinfo\n");
Com.Printf("--------\n");
Info.Print(SV_MAIN.sv_client.userinfo);
}
/*
==============
SV_ServerRecord_f
Begins server demo recording. Every entity and every message will be
recorded, but no playerinfo will be stored. Primarily for demo merging.
==============
*/
public static void SV_ServerRecord_f() {
//char name[MAX_OSPATH];
String name;
byte buf_data[] = new byte[32768];
sizebuf_t buf = new sizebuf_t();
int len;
int i;
if (Cmd.Argc() != 2) {
Com.Printf("serverrecord <demoname>\n");
return;
}
if (SV_INIT.svs.demofile != null) {
Com.Printf("Already recording.\n");
return;
}
if (SV_INIT.sv.state != Defines.ss_game) {
Com.Printf("You must be in a level to record.\n");
return;
}
//
// open the demo file
//
name = FS.Gamedir() + "/demos/" + Cmd.Argv(1) + ".dm2";
Com.Printf("recording to " + name + ".\n");
FS.CreatePath(name);
try {
SV_INIT.svs.demofile = new RandomAccessFile(name, "rw");
}
catch (Exception e) {
Com.Printf("ERROR: couldn't open.\n");
return;
}
// setup a buffer to catch all multicasts
SZ.Init(SV_INIT.svs.demo_multicast, SV_INIT.svs.demo_multicast_buf, SV_INIT.svs.demo_multicast_buf.length);
//
// write a single giant fake message with all the startup info
//
SZ.Init(buf, buf_data, buf_data.length);
//
// serverdata needs to go over for all types of servers
// to make sure the protocol is right, and to set the gamedir
//
// send the serverdata
MSG.WriteByte(buf, Defines.svc_serverdata);
MSG.WriteLong(buf, Defines.PROTOCOL_VERSION);
MSG.WriteLong(buf, SV_INIT.svs.spawncount);
// 2 means server demo
MSG.WriteByte(buf, 2); // demos are always attract loops
MSG.WriteString(buf, Cvar.VariableString("gamedir"));
MSG.WriteShort(buf, -1);
// send full levelname
MSG.WriteString(buf, SV_INIT.sv.configstrings[Defines.CS_NAME]);
for (i = 0; i < Defines.MAX_CONFIGSTRINGS; i++)
if (SV_INIT.sv.configstrings[i].length() == 0) {
MSG.WriteByte(buf, Defines.svc_configstring);
MSG.WriteShort(buf, i);
MSG.WriteString(buf, SV_INIT.sv.configstrings[i]);
}
// write it to the demo file
Com.DPrintf("signon message length: " + buf.cursize + "\n");
len = EndianHandler.swapInt(buf.cursize);
//fwrite(len, 4, 1, svs.demofile);
//fwrite(buf.data, buf.cursize, 1, svs.demofile);
try {
SV_INIT.svs.demofile.writeInt(len);
SV_INIT.svs.demofile.write(buf.data, 0, buf.cursize);
}
catch (IOException e1) {
// TODO: do quake2 error handling!
e1.printStackTrace();
}
// the rest of the demo file will be individual frames
}
/*
==============
SV_ServerStop_f
Ends server demo recording
==============
*/
public static void SV_ServerStop_f() {
if (SV_INIT.svs.demofile == null) {
Com.Printf("Not doing a serverrecord.\n");
return;
}
try {
SV_INIT.svs.demofile.close();
}
catch (IOException e) {
e.printStackTrace();
}
SV_INIT.svs.demofile = null;
Com.Printf("Recording completed.\n");
}
/*
===============
SV_KillServer_f
Kick everyone off, possibly in preparation for a new game
===============
*/
public static void SV_KillServer_f() {
if (!SV_INIT.svs.initialized)
return;
SV_MAIN.SV_Shutdown("Server was killed.\n", false);
NET.Config(false); // close network sockets
}
/*
===============
SV_ServerCommand_f
Let the game dll handle a command
===============
*/
public static void SV_ServerCommand_f() {
GameSVCmds.ServerCommand();
}
//===========================================================
/*
==================
SV_InitOperatorCommands
==================
*/
public static void SV_InitOperatorCommands() {
Cmd.AddCommand("heartbeat", new xcommand_t() {
public void execute() {
SV_Heartbeat_f();
}
});
Cmd.AddCommand("kick", new xcommand_t() {
public void execute() {
SV_Kick_f();
}
});
Cmd.AddCommand("status", new xcommand_t() {
public void execute() {
SV_Status_f();
}
});
Cmd.AddCommand("serverinfo", new xcommand_t() {
public void execute() {
SV_Serverinfo_f();
}
});
Cmd.AddCommand("dumpuser", new xcommand_t() {
public void execute() {
SV_DumpUser_f();
}
});
Cmd.AddCommand("map", new xcommand_t() {
public void execute() {
SV_Map_f();
}
});
Cmd.AddCommand("demomap", new xcommand_t() {
public void execute() {
SV_DemoMap_f();
}
});
Cmd.AddCommand("gamemap", new xcommand_t() {
public void execute() {
SV_GameMap_f();
}
});
Cmd.AddCommand("setmaster", new xcommand_t() {
public void execute() {
SV_SetMaster_f();
}
});
if (Globals.dedicated.value != 0)
Cmd.AddCommand("say", new xcommand_t() {
public void execute() {
SV_ConSay_f();
}
});
Cmd.AddCommand("serverrecord", new xcommand_t() {
public void execute() {
SV_ServerRecord_f();
}
});
Cmd.AddCommand("serverstop", new xcommand_t() {
public void execute() {
SV_ServerStop_f();
}
});
Cmd.AddCommand("save", new xcommand_t() {
public void execute() {
SV_Savegame_f();
}
});
Cmd.AddCommand("load", new xcommand_t() {
public void execute() {
SV_Loadgame_f();
}
});
Cmd.AddCommand("killserver", new xcommand_t() {
public void execute() {
SV_KillServer_f();
}
});
Cmd.AddCommand("sv", new xcommand_t() {
public void execute() {
SV_ServerCommand_f();
}
});
}
}
|