]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/gamecommand.qc
git-svn-id: svn://svn.icculus.org/nexuiz/trunk@3661 f962a42d-fe04-0410-a3ab-8c8b0445ebaa
[divverent/nexuiz.git] / data / qcsrc / server / gamecommand.qc
1 string GotoMap(string m);
2
3 void make_mapinfo_Think()
4 {
5         if(MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 1))
6         {
7                 print("Done rebuiling mapinfos.\n");
8                 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
9                 remove(self);
10         }
11         else
12         {
13                 self.think = make_mapinfo_Think;
14                 self.nextthink = time;
15         }
16 }
17
18 void GameCommand(string command)
19 {
20         float argc;
21         argc = tokenize(command);
22
23         if(argv(0) == "help" || argc == 0)
24         {
25                 print("Usage: sv_cmd COMMAND..., where possible commands are:\n");
26                 print("  adminmsg clientnumber \"message\"\n");
27                 print("  teamstatus\n");
28                 print("  printstats\n");
29                 print("  make_mapinfo\n");
30                 print("  gametype dm|ctf|...\n");
31                 print("  savedb filename\n");
32                 print("  dumpdb filename\n");
33                 print("  loaddb filename\n");
34                 print("  vstop\n");
35                 GameCommand_Ban("help");
36                 GameCommand_Generic("help");
37                 return;
38         }
39
40         if(GameCommand_Ban(command))
41                 return;
42
43         if(GameCommand_Generic(command))
44                 return;
45
46         if(argv(0) == "teamstatus")
47         {
48                 PrintScoreboard(world);
49                 return;
50         }
51
52         if(argv(0) == "printstats")
53         {
54                 DumpStats(FALSE);
55                 return;
56         }
57
58         if(argv(0) == "make_mapinfo")
59         {
60                 entity e;
61                 e = spawn();
62                 e.classname = "make_mapinfo";
63                 e.think = make_mapinfo_Think;
64                 e.nextthink = time;
65                 MapInfo_Enumerate();
66                 return;
67         }
68
69         if(argv(0) == "warp") if(argc == 2) if(cvar("g_campaign"))
70         {
71                 CampaignLevelWarp(stof(argv(1)));
72                 return;
73         }
74
75         if(argv(0) == "gotomap") if(argc == 2)
76         {
77                 print(GotoMap(argv(1)), "\n");
78                 return;
79         }
80
81 #ifdef MAPINFO
82         if(argv(0) == "gametype") if(argc == 2)
83         {
84                 float t, tsave;
85                 string s;
86                 s = argv(1);
87                 t = MapInfo_Type_FromString(s);
88                 tsave = MapInfo_CurrentGametype();
89                 if(t)
90                 {
91                         MapInfo_SwitchGameType(t);
92                         MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
93                         if(MapInfo_count > 0)
94                         {
95                                 bprint("Game type successfully switched to ", s, "\n");
96                         }
97                         else
98                         {
99                                 bprint("Cannot use this game type: no map for it found\n");
100                                 MapInfo_SwitchGameType(tsave);
101                                 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
102                         }
103                 }
104                 else
105                         bprint("Game type switch to ", s, " failed: this type does not exist!\n");
106                 return;
107         }
108 #endif
109
110         if(argv(0) == "adminmsg") if(argc == 3)
111         {
112                 entity client;
113                 float entno;
114                 entno = stof(argv(1));
115                 client = world;
116                 if(entno <= maxclients)
117                         client = edict_num(entno);
118                 if(client.flags & FL_CLIENT)
119                 {
120                         centerprint_atprio(client, CENTERPRIO_ADMIN, strcat("^3SERVER ADMIN:\n\n^7", argv(2)));
121                         sprint(client, strcat("\{1}\{13}^3SERVER ADMIN^7: ", argv(2), "\n"));
122                         print("Message sent to ", client.netname, "\n");
123                 }
124                 else
125                         print("Client not found\n");
126                 return;
127         }
128
129         if(argv(0) == "savedb") if(argc == 2)
130         {
131                 db_save(ServerProgsDB, argv(1));
132                 print("DB saved.\n");
133                 return;
134         }
135
136         if(argv(0) == "dumpdb") if(argc == 2)
137         {
138                 db_dump(ServerProgsDB, argv(1));
139                 print("DB dumped.\n");
140                 return;
141         }
142
143         if(argv(0) == "loaddb") if(argc == 2)
144         {
145                 db_close(ServerProgsDB);
146                 ServerProgsDB = db_load(argv(1));
147                 print("DB loaded.\n");
148                 return;
149         }
150         if (argv(0) == "nospectators")
151         {
152                 blockSpectators = 1;
153                 local entity plr;
154                 FOR_EACH_CLIENT(plr) //give every spectator <g_maxplayers_spectator_blocktime> seconds time to become a player
155                 {
156                         if(plr.classname == "spectator" || plr.classname == "observer")
157                         {
158                                 plr.spectatortime = time;
159                                 sprint(plr, strcat("^7You have to become a player within the next ", ftos(cvar("g_maxplayers_spectator_blocktime")), " seconds, otherwise you will be kicked, because spectators aren't allowed at this time!\n"));
160                         }
161                 }
162                 bprint(strcat("^7All spectators will be automatically kicked when not joining the game after ", ftos(cvar("g_maxplayers_spectator_blocktime")), " seconds!\n"));
163                 return;
164         }
165         if (argv(0) == "lockteams")
166         {
167                 if(teamplay)
168                 {
169                         lockteams = 1;
170                         bprint("^1The teams are now locked.\n");
171                 }
172                 else
173                         bprint("That command can only be used in a team-based gamemode.\n");
174                 return;
175         }
176         if (argv(0) == "unlockteams")
177         {
178                 if(teamplay)
179                 {
180                         lockteams = 0;
181                         bprint("^1The teams are now unlocked.\n");
182                 }
183                 else
184                         bprint("That command can only be used in a team-based gamemode.\n");
185                 return;
186         }
187         if(argv(0) == "vstop")
188         {
189                 local entity temp;
190                 temp = spawn();
191                 if(cvar_string("sv_adminnick") == "")
192                         temp.netname = cvar_string("hostname");
193                 else
194                         temp.netname = cvar_string("sv_adminnick");
195                 VoteStop(temp);
196                 remove(temp);
197                 return;
198         }
199
200         print("Invalid command. For a list of supported commands, try sv_cmd help.\n");
201 }
202