]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/gamecommand.qc
- Moved all the voting stuff into a file of its own and made it accessible from the...
[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                 GameCommand_Vote("help", world);
35                 GameCommand_Ban("help");
36                 GameCommand_Generic("help");
37                 return;
38         }
39
40         if(GameCommand_Vote(command, world))
41                 return;
42
43         if(GameCommand_Ban(command))
44                 return;
45
46         if(GameCommand_Generic(command))
47                 return;
48
49         if(argv(0) == "teamstatus")
50         {
51                 PrintScoreboard(world);
52                 return;
53         }
54
55         if(argv(0) == "printstats")
56         {
57                 DumpStats(FALSE);
58                 return;
59         }
60
61         if(argv(0) == "make_mapinfo")
62         {
63                 entity e;
64                 e = spawn();
65                 e.classname = "make_mapinfo";
66                 e.think = make_mapinfo_Think;
67                 e.nextthink = time;
68                 MapInfo_Enumerate();
69                 return;
70         }
71
72         if(argv(0) == "warp") if(argc == 2) if(cvar("g_campaign"))
73         {
74                 CampaignLevelWarp(stof(argv(1)));
75                 return;
76         }
77
78         if(argv(0) == "gotomap") if(argc == 2)
79         {
80                 print(GotoMap(argv(1)), "\n");
81                 return;
82         }
83
84 #ifdef MAPINFO
85         if(argv(0) == "gametype") if(argc == 2)
86         {
87                 float t, tsave;
88                 string s;
89                 s = argv(1);
90                 t = MapInfo_Type_FromString(s);
91                 tsave = MapInfo_CurrentGametype();
92                 if(t)
93                 {
94                         MapInfo_SwitchGameType(t);
95                         MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
96                         if(MapInfo_count > 0)
97                         {
98                                 bprint("Game type successfully switched to ", s, "\n");
99                         }
100                         else
101                         {
102                                 bprint("Cannot use this game type: no map for it found\n");
103                                 MapInfo_SwitchGameType(tsave);
104                                 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
105                         }
106                 }
107                 else
108                         bprint("Game type switch to ", s, " failed: this type does not exist!\n");
109                 return;
110         }
111 #endif
112
113         if(argv(0) == "adminmsg") if(argc == 3)
114         {
115                 entity client;
116                 float entno;
117                 entno = stof(argv(1));
118                 client = world;
119                 if(entno <= maxclients)
120                         client = edict_num(entno);
121                 if(client.flags & FL_CLIENT)
122                 {
123                         centerprint_atprio(client, CENTERPRIO_ADMIN, strcat("^3SERVER ADMIN:\n\n^7", argv(2)));
124                         sprint(client, strcat("\{1}\{13}^3SERVER ADMIN^7: ", argv(2), "\n"));
125                         print("Message sent to ", client.netname, "\n");
126                 }
127                 else
128                         print("Client not found\n");
129                 return;
130         }
131
132         if(argv(0) == "savedb") if(argc == 2)
133         {
134                 db_save(ServerProgsDB, argv(1));
135                 print("DB saved.\n");
136                 return;
137         }
138
139         if(argv(0) == "dumpdb") if(argc == 2)
140         {
141                 db_dump(ServerProgsDB, argv(1));
142                 print("DB dumped.\n");
143                 return;
144         }
145
146         if(argv(0) == "loaddb") if(argc == 2)
147         {
148                 db_close(ServerProgsDB);
149                 ServerProgsDB = db_load(argv(1));
150                 print("DB loaded.\n");
151                 return;
152         }
153         if (argv(0) == "nospectators")
154         {
155                 blockSpectators = 1;
156                 local entity plr;
157                 FOR_EACH_CLIENT(plr) //give every spectator <g_maxplayers_spectator_blocktime> seconds time to become a player
158                 {
159                         if(plr.classname == "spectator" || plr.classname == "observer")
160                         {
161                                 plr.spectatortime = time;
162                                 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"));
163                         }
164                 }
165                 bprint(strcat("^7All spectators will be automatically kicked when not joining the game after ", ftos(cvar("g_maxplayers_spectator_blocktime")), " seconds!\n"));
166                 return;
167         }
168         if (argv(0) == "lockteams")
169         {
170                 if(teamplay)
171                 {
172                         lockteams = 1;
173                         bprint("^1The teams are now locked.\n");
174                 }
175                 else
176                         bprint("That command can only be used in a team-based gamemode.\n");
177                 return;
178         }
179         if (argv(0) == "unlockteams")
180         {
181                 if(teamplay)
182                 {
183                         lockteams = 0;
184                         bprint("^1The teams are now unlocked.\n");
185                 }
186                 else
187                         bprint("That command can only be used in a team-based gamemode.\n");
188                 return;
189         }
190
191         print("Invalid command. For a list of supported commands, try sv_cmd help.\n");
192 }
193