]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/command/sv_cmd.qc
Now make everything else compile too
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / command / sv_cmd.qc
1 // =====================================================
2 //  Server side game commands code, reworked by Samual
3 //  Last updated: December 6th, 2011
4 // =====================================================
5
6 // ============================
7 //  Misc. Supporting Functions
8 // ============================
9
10 //  used by GameCommand_make_mapinfo()
11 void make_mapinfo_Think()
12 {
13         if(MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 1))
14         {
15                 print("Done rebuiling mapinfos.\n");
16                 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
17                 remove(self);
18         }
19         else
20         {
21                 self.think = make_mapinfo_Think;
22                 self.nextthink = time;
23         }
24 }
25
26 //  used by GameCommand_extendmatchtime() and GameCommand_reducematchtime()
27 void changematchtime(float delta, float mi, float ma)
28 {
29         float cur;
30         float new;
31         float lim;
32
33         if(delta == 0)
34                 return;
35         if(autocvar_timelimit < 0)
36                 return;
37
38         if(mi <= 10)
39                 mi = 10; // at least ten sec in the future
40         cur = time - game_starttime;
41         if(cur > 0)
42                 mi += cur; // from current time!
43
44         lim = autocvar_timelimit * 60;
45
46         if(delta > 0)
47         {
48                 if(lim == 0)
49                         return; // cannot increase any further
50                 else if(lim < ma)
51                         new = min(ma, lim + delta);
52                 else // already above maximum: FAIL
53                         return;
54         }
55         else
56         {
57                 if(lim == 0) // infinite: try reducing to max, if we are allowed to
58                         new = max(mi, ma);
59                 else if(lim > mi) // above minimum: decrease
60                         new = max(mi, lim + delta);
61                 else // already below minimum: FAIL
62                         return;
63         }
64
65         cvar_set("timelimit", ftos(new / 60));
66 }
67
68 //  used by GameCommand_modelbug() // TODO: is this even needed?
69 float g_clientmodel_genericsendentity (entity to, float sf);
70 void modelbug_make_svqc();
71 void modelbug_make_csqc()
72 {
73         Net_LinkEntity(self, TRUE, 0, g_clientmodel_genericsendentity);
74         self.think = modelbug_make_svqc;
75         self.nextthink = time + 1;
76         setorigin(self, self.origin - '0 0 8');
77 }
78 void modelbug_make_svqc()
79 {
80         self.SendEntity = func_null;
81         self.think = modelbug_make_csqc;
82         self.nextthink = time + 1;
83         setorigin(self, self.origin + '0 0 8');
84 }
85 void modelbug()
86 {
87         entity e;
88         e = spawn();
89         setorigin(e, nextent(world).origin);
90         precache_model("models_portal.md3");
91         setmodel(e, "models/portal.md3");
92         e.think = modelbug_make_svqc;
93         e.nextthink = time + 1;
94 }
95
96
97 // =======================
98 //  Command Sub-Functions
99 // =======================
100
101 void GameCommand_adminmsg(float request, float argc) // todo: re-write this, plus support multiple clients at once like moveplayer
102 {
103         switch(request)
104         {
105                 case GC_REQUEST_COMMAND:
106                 {
107                         entity client;
108                         float entno = stof(argv(1)); 
109                         float n, i;
110                         string s;
111                         
112                         if(argc >= 3 && argc <= 4) {
113                                 if((entno < 0) | (entno > maxclients)) {
114                                         print("Player ", argv(1), " doesn't exist\n");
115                                         return;
116                                 }
117                                 n = 0;
118                                 for(i = (entno ? entno : 1); i <= (entno ? entno : maxclients); ++i)
119                                 {
120                                         client = edict_num(i);
121                                         if(client.flags & FL_CLIENT)
122                                         {
123                                                 if(argc == 4)
124                                                 {
125                                                         // make the string console safe
126                                                         s = argv(2);
127                                                         s = strreplace("\n", "", s);
128                                                         s = strreplace("\\", "\\\\", s);
129                                                         s = strreplace("$", "$$", s);
130                                                         s = strreplace("\"", "\\\"", s);
131                                                         stuffcmd(client, sprintf("\ninfobar %f \"%s\"\n", stof(argv(3)), s));
132                                                 }
133                                                 else
134                                                 {
135                                                         centerprint(client, strcat("^3", admin_name(), ":\n\n^7", argv(2)));
136                                                         sprint(client, strcat("\{1}\{13}^3", admin_name(), "^7: ", argv(2), "\n"));
137                                                 }
138                                                 dprint("Message sent to ", client.netname, "\n");
139                                                 ++n;
140                                         }
141                                 }
142                                 if(!n) { print(strcat("Client (", argv(1) ,") not found.\n")); } 
143                                 return;
144                         }
145                 }
146                 
147                 default:
148                         print("Incorrect parameters for ^2adminmsg^7\n");
149                 case GC_REQUEST_USAGE:
150                 {
151                         print("\nUsage:^3 sv_cmd adminmsg clientnumber \"message\" [infobartime]\n");
152                         print("  If infobartime is provided, the message will be sent to infobar.\n");
153                         print("  Otherwise, it will just be sent as a centerprint message.\n");
154                         print("Examples: adminmsg 4 \"this infomessage will last for ten seconds\" 10\n");
155                         print("          adminmsg 2 \"this message will be a centerprint\"\n");
156                         return;
157                 }
158         }
159 }
160
161 void GameCommand_allready(float request)
162 {
163         switch(request)
164         {
165                 case GC_REQUEST_COMMAND:
166                 {
167                         ReadyRestart();
168                         return;
169                 }
170                         
171                 default:
172                 case GC_REQUEST_USAGE:
173                 {
174                         print("\nUsage:^3 sv_cmd allready\n");
175                         print("  No arguments required.\n");
176                         return;
177                 }
178         }
179 }
180
181 void GameCommand_allspec(float request, float argc)
182 {       
183         switch(request)
184         {
185                 case GC_REQUEST_COMMAND:
186                 {
187                         entity client;
188                         string reason = argv(1);
189                         float i;
190                         
191                         FOR_EACH_REALPLAYER(client)
192                         {
193                                 self = client;
194                                 PutObserverInServer();
195                                 ++i;
196                         }
197                         if(i) { bprint(strcat("Successfully forced all (", ftos(i), ") players to spectate", (reason ? strcat(" for reason: '", reason, "'") : ""), ".\n")); }
198                         else { print("No players found to spectate.\n"); }
199                         return;
200                 }
201                         
202                 default:
203                 case GC_REQUEST_USAGE:
204                 {
205                         print("\nUsage:^3 sv_cmd allspec [reason]\n");
206                         print("  Where 'reason' is an optional argument for explanation of allspec command.\n");
207                         print("See also: ^2moveplayer, shuffleteams^7\n");
208                         return;
209                 }
210         }
211 }
212
213 void GameCommand_anticheat(float request, float argc)
214 {
215         switch(request)
216         {
217                 case GC_REQUEST_COMMAND:
218                 {
219                         entity client;
220                         float entno = stof(argv(1)); 
221                         
222                         if((entno < 1) | (entno > maxclients)) {
223                                 print("Player ", argv(1), " doesn't exist\n");
224                                 return;
225                         }
226                         client = edict_num(entno);
227                         if(clienttype(client) != CLIENTTYPE_REAL || clienttype(client) != CLIENTTYPE_BOT) {
228                                 print("Player ", client.netname, " is not active\n");
229                                 return;
230                         }
231                         self = client;
232                         anticheat_report();
233                         return;
234                 }
235                         
236                 default:
237                         print("Incorrect parameters for ^2anticheat^7\n");
238                 case GC_REQUEST_USAGE:
239                 {
240                         print("\nUsage:^3 sv_cmd anticheat clientnumber\n");
241                         print("  where 'clientnumber' is player entity number.\n");
242                         return;
243                 }
244         }
245 }
246
247 void GameCommand_bbox(float request)
248 {
249         switch(request)
250         {
251                 case GC_REQUEST_COMMAND:
252                 {
253                         print("Original size: ", ftos(world.absmin_x), " ", ftos(world.absmin_y), " ", ftos(world.absmin_z));
254                         print(" ", ftos(world.absmax_x), " ", ftos(world.absmax_y), " ", ftos(world.absmax_z), "\n");
255                         print("Currently set size: ", ftos(world.mins_x), " ", ftos(world.mins_y), " ", ftos(world.mins_z));
256                         print(" ", ftos(world.maxs_x), " ", ftos(world.maxs_y), " ", ftos(world.maxs_z), "\n");
257                         print("Solid bounding box size:");
258
259                         tracebox('1 0 0' * world.absmin_x,
260                                                         '0 1 0' * world.absmin_y + '0 0 1' * world.absmin_z,
261                                                         '0 1 0' * world.absmax_y + '0 0 1' * world.absmax_z,
262                                                         '1 0 0' * world.absmax_x,
263                                         MOVE_WORLDONLY,
264                                         world);
265                         if(trace_startsolid)
266                                 print(" ", ftos(world.absmin_x));
267                         else
268                                 print(" ", ftos(trace_endpos_x));
269
270                         tracebox('0 1 0' * world.absmin_y,
271                                                         '1 0 0' * world.absmin_x + '0 0 1' * world.absmin_z,
272                                                         '1 0 0' * world.absmax_x + '0 0 1' * world.absmax_z,
273                                                         '0 1 0' * world.absmax_y,
274                                         MOVE_WORLDONLY,
275                                         world);
276                         if(trace_startsolid)
277                                 print(" ", ftos(world.absmin_y));
278                         else
279                                 print(" ", ftos(trace_endpos_y));
280
281                         tracebox('0 0 1' * world.absmin_z,
282                                                         '1 0 0' * world.absmin_x + '0 1 0' * world.absmin_y,
283                                                         '1 0 0' * world.absmax_x + '0 1 0' * world.absmax_y,
284                                                         '0 0 1' * world.absmax_z,
285                                         MOVE_WORLDONLY,
286                                         world);
287                         if(trace_startsolid)
288                                 print(" ", ftos(world.absmin_z));
289                         else
290                                 print(" ", ftos(trace_endpos_z));
291
292                         tracebox('1 0 0' * world.absmax_x,
293                                                         '0 1 0' * world.absmin_y + '0 0 1' * world.absmin_z,
294                                                         '0 1 0' * world.absmax_y + '0 0 1' * world.absmax_z,
295                                                         '1 0 0' * world.absmin_x,
296                                         MOVE_WORLDONLY,
297                                         world);
298                         if(trace_startsolid)
299                                 print(" ", ftos(world.absmax_x));
300                         else
301                                 print(" ", ftos(trace_endpos_x));
302
303                         tracebox('0 1 0' * world.absmax_y,
304                                                         '1 0 0' * world.absmin_x + '0 0 1' * world.absmin_z,
305                                                         '1 0 0' * world.absmax_x + '0 0 1' * world.absmax_z,
306                                                         '0 1 0' * world.absmin_y,
307                                         MOVE_WORLDONLY,
308                                         world);
309                         if(trace_startsolid)
310                                 print(" ", ftos(world.absmax_y));
311                         else
312                                 print(" ", ftos(trace_endpos_y));
313
314                         tracebox('0 0 1' * world.absmax_z,
315                                                         '1 0 0' * world.absmin_x + '0 1 0' * world.absmin_y,
316                                                         '1 0 0' * world.absmax_x + '0 1 0' * world.absmax_y,
317                                                         '0 0 1' * world.absmin_z,
318                                         MOVE_WORLDONLY,
319                                         world);
320                         if(trace_startsolid)
321                                 print(" ", ftos(world.absmax_z));
322                         else
323                                 print(" ", ftos(trace_endpos_z));
324                                 
325                         print("\n");
326                         return;
327                 }
328                         
329                 default:
330                 case GC_REQUEST_USAGE:
331                 {
332                         print("\nUsage:^3 sv_cmd bbox\n");
333                         print("  No arguments required.\n");
334                         print("See also: ^2gettaginfo^7\n");
335                         return;
336                 }
337         }
338 }
339
340 void GameCommand_bot_cmd(float request, float argc) // what a mess... old old code.
341 {
342         switch(request)
343         {
344                 case GC_REQUEST_COMMAND:
345                 {
346                         entity bot;
347                         
348                         if(argv(1) == "reset")
349                         {
350                                 bot_resetqueues();
351                                 return;
352                         }
353                         else if(argv(1) == "load" && argc == 3)
354                         {
355                                 float fh, i;
356                                 string s;
357                                 fh = fopen(argv(2), FILE_READ);
358                                 if(fh < 0)
359                                 {
360                                         print("cannot open the file\n");
361                                         return;
362                                 }
363
364                                 i = 0;
365                                 while((s = fgets(fh)))
366                                 {
367                                         argc = tokenize_console(s);
368
369                                         if(argc >= 3 && argv(0) == "sv_cmd" && argv(1) == "bot_cmd")
370                                         {
371                                                 if(argv(2) == "reset")
372                                                 {
373                                                         bot_resetqueues();
374                                                 }
375                                                 else if(argv(2) == "setbots")
376                                                 {
377                                                         cvar_settemp("minplayers", "0");
378                                                         cvar_settemp("bot_number", argv(3));
379                                                         if(!bot_fixcount())
380                                                                 print("Sorry, could not set requested bot count\n");
381                                                 }
382                                                 else
383                                                 {
384                                                         // let's start at token 2 so we can skip sv_cmd bot_cmd
385                                                         bot = find_bot_by_number(stof(argv(2)));
386                                                         if(bot == world)
387                                                                 bot = find_bot_by_name(argv(2));
388                                                         if(bot)
389                                                                 bot_queuecommand(bot, strcat(argv(3), " ", argv(4)));
390                                                 }
391                                         }
392                                         else
393                                                 localcmd(strcat(s, "\n"));
394
395                                         ++i;
396                                 }
397                                 print(ftos(i), " commands read\n");
398                                 fclose(fh);
399                                 return;
400                         }
401                         else if(argv(1) == "help")
402                         {
403                                 if(argv(2))
404                                         bot_cmdhelp(argv(2));
405                                 else
406                                         bot_list_commands();
407                                 return;
408                         }
409                         else if(argc >= 3) // this comes last
410                         {
411                                 bot = find_bot_by_number(stof(argv(1)));
412                                 if(bot == world)
413                                         bot = find_bot_by_name(argv(1));
414                                 if(bot)
415                                 {
416                                         print(strcat("Command '", strcat(argv(2), " ", argv(3)), "' sent to bot ", bot.netname, "\n"));
417                                         bot_queuecommand(bot, strcat(argv(2), " ", argv(3)));
418                                         return;
419                                 }
420                                 else
421                                         print(strcat("Error: Can't find bot with the name or id '", argv(1),"' - Did you mistype the command?\n")); // don't return so that usage is shown
422                         }
423                 }
424                         
425                 default:
426                         print("Incorrect parameters for ^2bot_cmd^7\n");
427                 case GC_REQUEST_USAGE:
428                 {
429                         print("\nUsage:^3 sv_cmd bot_cmd client command [argument]\n");
430                         print("  'client' can be either the name or entity id of the bot\n");
431                         print("  For full list of commands, see bot_cmd help [command].\n");
432                         print("Examples: bot_cmd <id> cc \"say something\"\n");
433                         print("          bot_cmd <id> presskey jump\n");
434                         return;
435                 }
436         }
437 }
438
439 void GameCommand_cointoss(float request, float argc)
440 {
441         switch(request)
442         {
443                 case GC_REQUEST_COMMAND:
444                 {
445                         entity client;
446                         string result1 = (argv(2) ? strcat("^7", argv(1), "^3!\n") : "^1HEADS^3!\n");
447                         string result2 = (argv(2) ? strcat("^7", argv(2), "^3!\n") : "^4TAILS^3!\n");
448                         string choice = ((random() > 0.5) ? result1 : result2);
449                         
450                         FOR_EACH_CLIENT(client)
451                                 centerprint(client, strcat("^3Throwing coin... Result: ", choice));
452                         bprint(strcat("^3Throwing coin... Result: ", choice));
453                         return;
454                 }
455                 
456                 default:
457                 case GC_REQUEST_USAGE:
458                 {
459                         print("\nUsage:^3 sv_cmd cointoss [result1 result2]\n");
460                         print("  Where 'result1' and 'result2' are user created options.\n");
461                         return;
462                 }
463         }
464 }
465
466 void GameCommand_cvar_changes(float request)
467 {
468         switch(request)
469         {
470                 case GC_REQUEST_COMMAND:
471                 {
472                         print(cvar_changes);
473                         return;
474                 }
475                         
476                 default:
477                 case GC_REQUEST_USAGE:
478                 {
479                         print("\nUsage:^3 sv_cmd cvar_changes\n");
480                         print("  No arguments required.\n");
481                         print("See also: ^2cvar_purechanges^7\n");
482                         return;
483                 }
484         }
485 }
486
487 void GameCommand_cvar_purechanges(float request)
488 {
489         switch(request)
490         {
491                 case GC_REQUEST_COMMAND:
492                 {
493                         print(cvar_purechanges);
494                         return;
495                 }
496                         
497                 default:
498                 case GC_REQUEST_USAGE:
499                 {
500                         print("\nUsage:^3 sv_cmd cvar_purechanges\n");
501                         print("  No arguments required.\n");
502                         print("See also: ^2cvar_changes^7\n");
503                         return;
504                 }
505         }
506 }
507
508 void GameCommand_database(float request, float argc)
509 {
510         switch(request)
511         {
512                 case GC_REQUEST_COMMAND:
513                 {
514                         if(argc == 3)
515                         {
516                                 if(argv(1) == "save")
517                                 {
518                                         db_save(ServerProgsDB, argv(2));
519                                         print(strcat("Copied serverprogs database to '", argv(2), "' in the data directory.\n"));
520                                         return;
521                                 }
522                                 else if(argv(1) == "dump")
523                                 {
524                                         db_dump(ServerProgsDB, argv(2));
525                                         print("DB dumped.\n"); // wtf does this do?
526                                         return;
527                                 }
528                                 else if(argv(1) == "load")
529                                 {
530                                         db_close(ServerProgsDB);
531                                         ServerProgsDB = db_load(argv(2));
532                                         print(strcat("Loaded '", argv(2), "' as new serverprogs database.\n"));
533                                         return;
534                                 }
535                         }
536                 }
537                         
538                 default:
539                         print("Incorrect parameters for ^2database^7\n");
540                 case GC_REQUEST_USAGE:
541                 {
542                         print("\nUsage:^3 sv_cmd database action filename\n");
543                         print("  Where 'action' is the command to complete,\n");
544                         print("  and 'filename' is what it acts upon.\n");
545                         print("  Full list of commands here: \"save, dump, load.\"\n");
546                         return;
547                 }
548         }
549 }
550
551 void GameCommand_defer_clear(float request, float argc)
552 {       
553         switch(request)
554         {
555                 case GC_REQUEST_COMMAND:
556                 {
557                         entity client;
558                         float entno = stof(argv(1));
559                         
560                         if(argc == 2)
561                         {
562                                 // player_id is out of range
563                                 if((entno < 1) | (entno > maxclients)) {
564                                         print("Player ", argv(1), " doesn't exist\n");
565                                         return;
566                                 }
567                                 client = edict_num(entno);
568                                 if not(client.flags & FL_CLIENT) {
569                                         print("Player ", argv(1), " doesn't exist\n");
570                                         return;
571                                 }
572                                 if(clienttype(client) == CLIENTTYPE_BOT) {
573                                         print("Player ", argv(1), " (", client.netname, ") is a bot\n");
574                                         return;
575                                 }
576                                 stuffcmd(client, "defer clear\n");
577                                 print("defer clear stuffed to ", argv(1), " (", client.netname, ")\n");
578                                 return;
579                         }
580                 }
581                 
582                 default:
583                         print("Incorrect parameters for ^2defer_clear^7\n");
584                 case GC_REQUEST_USAGE:
585                 {
586                         print("\nUsage:^3 sv_cmd defer_clear clientnumber\n");
587                         print("  where 'clientnumber' is player entity number.\n");
588                         print("See also: ^2defer_clear_all^7\n");
589                         return;
590                 }
591         }
592 }
593
594 void GameCommand_defer_clear_all(float request)
595 {       
596         switch(request)
597         {
598                 case GC_REQUEST_COMMAND:
599                 {
600                         entity client;
601                         float i;
602                         float argc;
603                         
604                         FOR_EACH_CLIENT(client)
605                         {
606                                 argc = tokenize_console(strcat("defer_clear ", ftos(num_for_edict(client))));
607                                 GameCommand_defer_clear(GC_REQUEST_COMMAND, argc);      
608                                 ++i;
609                         }
610                         if(i) { print(strcat("Successfully stuffed defer clear to all clients (", ftos(i), ")\n")); } // should a message be added if no players were found? 
611                         return;
612                 }
613                 
614                 default:
615                 case GC_REQUEST_USAGE:
616                 {
617                         print("\nUsage:^3 sv_cmd defer_clear_all\n");
618                         print("  No arguments required.\n");
619                         print("See also: ^2defer_clear^7\n");
620                         return;
621                 }
622         }
623 }
624
625 void GameCommand_delrec(float request, float argc) // UNTESTED // perhaps merge later with records and printstats and such?
626 {
627         switch(request)
628         {
629                 case GC_REQUEST_COMMAND:
630                 {
631                         if(argv(1))
632                         {
633                                 if(argv(2))
634                                         race_deleteTime(argv(2), stof(argv(1)));
635                                 else
636                                         race_deleteTime(GetMapname(), stof(argv(1)));
637                                 return;
638                         }
639                 }       
640                 
641                 default:
642                         print("Incorrect parameters for ^2delrec^7\n");
643                 case GC_REQUEST_USAGE:
644                 {
645                         print("\nUsage:^3 sv_cmd delrec ranking [map]\n");
646                         print("  'ranking' is which ranking level to clear up to, \n");
647                         print("  it will clear all records up to nth place.\n");
648                         print("  if 'map' is not provided it will use current map.\n");
649                         return;
650                 }
651         }
652 }
653
654 void GameCommand_effectindexdump(float request)
655 {
656         switch(request)
657         {
658                 case GC_REQUEST_COMMAND:
659                 {
660                         float fh, d;
661                         string s;
662                         
663                         d = db_create();
664                         print("begin of effects list\n");
665                         db_put(d, "TE_GUNSHOT", "1"); print("effect TE_GUNSHOT is ", ftos(particleeffectnum("TE_GUNSHOT")), "\n");
666                         db_put(d, "TE_GUNSHOTQUAD", "1"); print("effect TE_GUNSHOTQUAD is ", ftos(particleeffectnum("TE_GUNSHOTQUAD")), "\n");
667                         db_put(d, "TE_SPIKE", "1"); print("effect TE_SPIKE is ", ftos(particleeffectnum("TE_SPIKE")), "\n");
668                         db_put(d, "TE_SPIKEQUAD", "1"); print("effect TE_SPIKEQUAD is ", ftos(particleeffectnum("TE_SPIKEQUAD")), "\n");
669                         db_put(d, "TE_SUPERSPIKE", "1"); print("effect TE_SUPERSPIKE is ", ftos(particleeffectnum("TE_SUPERSPIKE")), "\n");
670                         db_put(d, "TE_SUPERSPIKEQUAD", "1"); print("effect TE_SUPERSPIKEQUAD is ", ftos(particleeffectnum("TE_SUPERSPIKEQUAD")), "\n");
671                         db_put(d, "TE_WIZSPIKE", "1"); print("effect TE_WIZSPIKE is ", ftos(particleeffectnum("TE_WIZSPIKE")), "\n");
672                         db_put(d, "TE_KNIGHTSPIKE", "1"); print("effect TE_KNIGHTSPIKE is ", ftos(particleeffectnum("TE_KNIGHTSPIKE")), "\n");
673                         db_put(d, "TE_EXPLOSION", "1"); print("effect TE_EXPLOSION is ", ftos(particleeffectnum("TE_EXPLOSION")), "\n");
674                         db_put(d, "TE_EXPLOSIONQUAD", "1"); print("effect TE_EXPLOSIONQUAD is ", ftos(particleeffectnum("TE_EXPLOSIONQUAD")), "\n");
675                         db_put(d, "TE_TAREXPLOSION", "1"); print("effect TE_TAREXPLOSION is ", ftos(particleeffectnum("TE_TAREXPLOSION")), "\n");
676                         db_put(d, "TE_TELEPORT", "1"); print("effect TE_TELEPORT is ", ftos(particleeffectnum("TE_TELEPORT")), "\n");
677                         db_put(d, "TE_LAVASPLASH", "1"); print("effect TE_LAVASPLASH is ", ftos(particleeffectnum("TE_LAVASPLASH")), "\n");
678                         db_put(d, "TE_SMALLFLASH", "1"); print("effect TE_SMALLFLASH is ", ftos(particleeffectnum("TE_SMALLFLASH")), "\n");
679                         db_put(d, "TE_FLAMEJET", "1"); print("effect TE_FLAMEJET is ", ftos(particleeffectnum("TE_FLAMEJET")), "\n");
680                         db_put(d, "EF_FLAME", "1"); print("effect EF_FLAME is ", ftos(particleeffectnum("EF_FLAME")), "\n");
681                         db_put(d, "TE_BLOOD", "1"); print("effect TE_BLOOD is ", ftos(particleeffectnum("TE_BLOOD")), "\n");
682                         db_put(d, "TE_SPARK", "1"); print("effect TE_SPARK is ", ftos(particleeffectnum("TE_SPARK")), "\n");
683                         db_put(d, "TE_PLASMABURN", "1"); print("effect TE_PLASMABURN is ", ftos(particleeffectnum("TE_PLASMABURN")), "\n");
684                         db_put(d, "TE_TEI_G3", "1"); print("effect TE_TEI_G3 is ", ftos(particleeffectnum("TE_TEI_G3")), "\n");
685                         db_put(d, "TE_TEI_SMOKE", "1"); print("effect TE_TEI_SMOKE is ", ftos(particleeffectnum("TE_TEI_SMOKE")), "\n");
686                         db_put(d, "TE_TEI_BIGEXPLOSION", "1"); print("effect TE_TEI_BIGEXPLOSION is ", ftos(particleeffectnum("TE_TEI_BIGEXPLOSION")), "\n");
687                         db_put(d, "TE_TEI_PLASMAHIT", "1"); print("effect TE_TEI_PLASMAHIT is ", ftos(particleeffectnum("TE_TEI_PLASMAHIT")), "\n");
688                         db_put(d, "EF_STARDUST", "1"); print("effect EF_STARDUST is ", ftos(particleeffectnum("EF_STARDUST")), "\n");
689                         db_put(d, "TR_ROCKET", "1"); print("effect TR_ROCKET is ", ftos(particleeffectnum("TR_ROCKET")), "\n");
690                         db_put(d, "TR_GRENADE", "1"); print("effect TR_GRENADE is ", ftos(particleeffectnum("TR_GRENADE")), "\n");
691                         db_put(d, "TR_BLOOD", "1"); print("effect TR_BLOOD is ", ftos(particleeffectnum("TR_BLOOD")), "\n");
692                         db_put(d, "TR_WIZSPIKE", "1"); print("effect TR_WIZSPIKE is ", ftos(particleeffectnum("TR_WIZSPIKE")), "\n");
693                         db_put(d, "TR_SLIGHTBLOOD", "1"); print("effect TR_SLIGHTBLOOD is ", ftos(particleeffectnum("TR_SLIGHTBLOOD")), "\n");
694                         db_put(d, "TR_KNIGHTSPIKE", "1"); print("effect TR_KNIGHTSPIKE is ", ftos(particleeffectnum("TR_KNIGHTSPIKE")), "\n");
695                         db_put(d, "TR_VORESPIKE", "1"); print("effect TR_VORESPIKE is ", ftos(particleeffectnum("TR_VORESPIKE")), "\n");
696                         db_put(d, "TR_NEHAHRASMOKE", "1"); print("effect TR_NEHAHRASMOKE is ", ftos(particleeffectnum("TR_NEHAHRASMOKE")), "\n");
697                         db_put(d, "TR_NEXUIZPLASMA", "1"); print("effect TR_NEXUIZPLASMA is ", ftos(particleeffectnum("TR_NEXUIZPLASMA")), "\n");
698                         db_put(d, "TR_GLOWTRAIL", "1"); print("effect TR_GLOWTRAIL is ", ftos(particleeffectnum("TR_GLOWTRAIL")), "\n");
699                         db_put(d, "TR_SEEKER", "1"); print("effect TR_SEEKER is ", ftos(particleeffectnum("TR_SEEKER")), "\n");
700                         db_put(d, "SVC_PARTICLE", "1"); print("effect SVC_PARTICLE is ", ftos(particleeffectnum("SVC_PARTICLE")), "\n");
701
702                         fh = fopen("effectinfo.txt", FILE_READ);
703                         while((s = fgets(fh)))
704                         {
705                                 tokenize_console(s);
706                                 if(argv(0) == "effect")
707                                 {
708                                         if(db_get(d, argv(1)) != "1")
709                                         {
710                                                 if(particleeffectnum(argv(1)) >= 0)
711                                                         print("effect ", argv(1), " is ", ftos(particleeffectnum(argv(1))), "\n");
712                                                 db_put(d, argv(1), "1");
713                                         }
714                                 }
715                         }
716                         print("end of effects list\n");
717
718                         db_close(d);
719                         return;
720                 }
721                         
722                 default:
723                 case GC_REQUEST_USAGE:
724                 {
725                         print("\nUsage:^3 sv_cmd effectindexdump\n");
726                         print("  No arguments required.\n");
727                         return;
728                 }
729         }
730 }
731
732 void GameCommand_extendmatchtime(float request)
733 {
734         switch(request)
735         {
736                 case GC_REQUEST_COMMAND:
737                 {
738                         changematchtime(autocvar_timelimit_increment* 60, autocvar_timelimit_min*60, autocvar_timelimit_max*60);
739                         return;
740                 }
741                         
742                 default:
743                 case GC_REQUEST_USAGE:
744                 {
745                         print("\nUsage:^3 sv_cmd extendmatchtime\n");
746                         print("  No arguments required.\n");
747                         print("See also: ^2reducematchtime^7\n");
748                         return;
749                 }
750         }
751 }
752
753 void GameCommand_find(float request, float argc)
754 {       
755         switch(request)
756         {
757                 case GC_REQUEST_COMMAND:
758                 {
759                         entity client;
760                         
761                         for(client = world; (client = find(client, classname, argv(1))); )
762                                 print(etos(client), "\n");
763                                 
764                         return;
765                 }
766                         
767                 default:
768                         print("Incorrect parameters for ^2find^7\n");
769                 case GC_REQUEST_USAGE:
770                 {
771                         print("\nUsage:^3 sv_cmd find classname\n");
772                         print("  Where 'classname' is the classname to search for.\n");
773                         return;
774                 }
775         }
776 }
777
778 void GameCommand_gametype(float request, float argc)
779 {       
780         switch(request)
781         {
782                 case GC_REQUEST_COMMAND:
783                 {
784                         string s = argv(1);
785                         float t = MapInfo_Type_FromString(s), tsave = MapInfo_CurrentGametype();
786                         
787                         if(t)
788                         {
789                                 MapInfo_SwitchGameType(t);
790                                 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
791                                 if(MapInfo_count > 0)
792                                         bprint("Game type successfully switched to ", s, "\n");
793                                 else
794                                 {
795                                         bprint("Cannot use this game type: no map for it found\n");
796                                         MapInfo_SwitchGameType(tsave);
797                                         MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
798                                 }
799                         }
800                         else
801                                 bprint("Game type switch to ", s, " failed: this type does not exist!\n");
802                         return;
803                 }
804                         
805                 default:
806                         print("Incorrect parameters for ^2gametype^7\n");
807                 case GC_REQUEST_USAGE:
808                 {
809                         print("\nUsage:^3 sv_cmd gametype mode\n");
810                         print("  Where 'mode' is the gametype mode to switch to.\n");
811                         print("See also: ^2gotomap^7\n");
812                         return;
813                 }
814         }
815 }
816
817 void GameCommand_gettaginfo(float request, float argc) // UNTESTED // todo: finish usage description for it (but, must first learn this shit)
818 {       
819         switch(request)
820         {
821                 case GC_REQUEST_COMMAND:
822                 {
823                         entity tmp_entity;
824                         float i;
825                         vector v;
826                         
827                         if(argc >= 4)
828                         {
829                                 tmp_entity = spawn();
830                                 if(argv(1) == "w")
831                                         setmodel(tmp_entity, (nextent(world)).weaponentity.model);
832                                 else
833                                 {
834                                         precache_model(argv(1));
835                                         setmodel(tmp_entity, argv(1));
836                                 }
837                                 tmp_entity.frame = stof(argv(2));
838                                 if(substring(argv(3), 0, 1) == "#")
839                                         i = stof(substring(argv(3), 1, -1));
840                                 else
841                                         i = gettagindex(tmp_entity, argv(3));
842                                 if(i)
843                                 {
844                                         v = gettaginfo(tmp_entity, i);
845                                         print("model ", tmp_entity.model, " frame ", ftos(tmp_entity.frame), " tag ", gettaginfo_name);
846                                         print(" index ", ftos(i), " parent ", ftos(gettaginfo_parent), "\n");
847                                         print(" vector = ", ftos(v_x), " ", ftos(v_y), " ", ftos(v_z), "\n");
848                                         print(" offset = ", ftos(gettaginfo_offset_x), " ", ftos(gettaginfo_offset_y), " ", ftos(gettaginfo_offset_z), "\n");
849                                         print(" forward = ", ftos(gettaginfo_forward_x), " ", ftos(gettaginfo_forward_y), " ", ftos(gettaginfo_forward_z), "\n");
850                                         print(" right = ", ftos(gettaginfo_right_x), " ", ftos(gettaginfo_right_y), " ", ftos(gettaginfo_right_z), "\n");
851                                         print(" up = ", ftos(gettaginfo_up_x), " ", ftos(gettaginfo_up_y), " ", ftos(gettaginfo_up_z), "\n");
852                                         if(argc >= 6)
853                                         {
854                                                 v_y = -v_y;
855                                                 localcmd(strcat(argv(4), vtos(v), argv(5), "\n"));
856                                         }
857                                 }
858                                 else
859                                         print("bone not found\n");
860                                         
861                                 remove(tmp_entity);
862                                 return;
863                         }
864                 }
865                         
866                 default:
867                         print("Incorrect parameters for ^2gettaginfo^7\n");
868                 case GC_REQUEST_USAGE:
869                 {
870                         print("\nUsage:^3 sv_cmd gettaginfo\n");
871                         print("  FIXME: Arguments currently unknown\n");
872                         print("See also: ^2bbox^7\n");
873                         return;
874                 }
875         }
876 }
877
878 void GameCommand_gotomap(float request, float argc)
879 {
880         switch(request)
881         {
882                 case GC_REQUEST_COMMAND:
883                 {
884                         if(argc == 2)
885                         {
886                                 print(GotoMap(argv(1)), "\n");
887                                 return;
888                         }
889                 }
890                         
891                 default:
892                         print("Incorrect parameters for ^2gotomap^7\n");
893                 case GC_REQUEST_USAGE:
894                 {
895                         print("\nUsage:^3 sv_cmd gotomap map\n");
896                         print("  Where 'map' is the *.bsp file to change to.\n");
897                         print("See also: ^2gametype^7\n");
898                         return;
899                 }
900         }
901 }
902
903 void GameCommand_ladder(float request)
904 {
905         switch(request)
906         {
907                 case GC_REQUEST_COMMAND:
908                 {
909                         print(ladder_reply);
910                         return;
911                 }
912                         
913                 default:
914                 case GC_REQUEST_USAGE:
915                 {
916                         print("\nUsage:^3 sv_cmd ladder\n");
917                         print("  No arguments required.\n");
918                         return;
919                 }
920         }
921 }
922
923 void GameCommand_lockteams(float request)
924 {
925         switch(request)
926         {
927                 case GC_REQUEST_COMMAND:
928                 {
929                         if(teamplay)
930                         {
931                                 lockteams = 1;
932                                 bprint("^1The teams are now locked.\n");
933                         }
934                         else
935                         {
936                                 bprint("lockteams command can only be used in a team-based gamemode.\n");
937                         }
938                         return;
939                 }
940                         
941                 default:
942                 case GC_REQUEST_USAGE:
943                 {
944                         print("\nUsage:^3 sv_cmd lockteams\n");
945                         print("  No arguments required.\n");
946                         print("See also: ^2unlockteams^7\n");
947                         return;
948                 }
949         }
950 }
951
952 void GameCommand_make_mapinfo(float request) // UNTESTED
953 {
954         switch(request)
955         {
956                 case GC_REQUEST_COMMAND:
957                 { 
958                         entity tmp_entity;
959                         
960                         tmp_entity = spawn();
961                         tmp_entity.classname = "make_mapinfo";
962                         tmp_entity.think = make_mapinfo_Think;
963                         tmp_entity.nextthink = time; // this sucks... todo: re-write this -- Use initializeentity later
964                         MapInfo_Enumerate();
965                         return;
966                 }
967                         
968                 default:
969                 case GC_REQUEST_USAGE:
970                 {
971                         print("\nUsage:^3 sv_cmd make_mapinfo\n");
972                         print("  No arguments required.\n");
973                         return;
974                 }
975         }
976 }
977
978 void GameCommand_modelbug(float request) // UNTESTED // is this even needed anymore? 
979 {
980         switch(request)
981         {
982                 case GC_REQUEST_COMMAND:
983                 {
984                         modelbug();
985                         return;
986                 }
987                         
988                 default:
989                 case GC_REQUEST_USAGE:
990                 {
991                         print("\nUsage:^3 sv_cmd modelbug\n");
992                         print("  No arguments required.\n");
993                         return;
994                 }
995         }
996 }
997
998 void GameCommand_moveplayer(float request, float argc)
999 {
1000         switch(request)
1001         {
1002                 case GC_REQUEST_COMMAND:
1003                 {
1004                         entity client;
1005         
1006                         string targets = strreplace(",", " ", argv(1));
1007                         string original_targets = strreplace(" ", ", ", targets);
1008                         string destination = argv(2);
1009                         string notify = argv(3);
1010                         
1011                         string successful, t;
1012                         
1013                         // lets see if the target(s) even actually exist.
1014                         if((targets) && (destination))
1015                         { 
1016                                 for(;targets;)
1017                                 {
1018                                         t = car(targets); targets = cdr(targets);
1019
1020                                         // Check to see if the player is a valid target
1021                                         if((GetFilteredNumber(t) < 1) || (GetFilteredNumber(t) > maxclients)) // player_id is out of range
1022                                         {
1023                                                 print("Player ", ftos(GetFilteredNumber(t)), " doesn't exist (out of range)", (targets ? ", skipping to next player.\n" : ".\n"));
1024                                                 continue; 
1025                                         }
1026                                         client = edict_num(GetFilteredNumber(t));
1027                                         if not(client.flags & FL_CLIENT) // player entity is not a client
1028                                         {
1029                                                 print("Player ", ftos(GetFilteredNumber(t)), " doesn't exist (not a client)", (targets ? ", skipping to next player.\n" : ".\n"));
1030                                                 continue;
1031                                         }
1032                                         
1033                                         // Where are we putting this player?
1034                                         if(destination == "spec" || destination == "spectator") 
1035                                         {
1036                                                 if(client.classname != "spectator" && client.classname != "observer")
1037                                                 {
1038                                                         self = client;
1039                                                         PutObserverInServer();
1040                                                         
1041                                                         successful = strcat(successful, (successful ? ", " : ""), client.netname);
1042                                                 }
1043                                                 else
1044                                                 {
1045                                                         print("Player ", ftos(GetFilteredNumber(t)), " (", client.netname, ") is already spectating.\n");
1046                                                 }
1047                                                 continue;
1048                                         }
1049                                         else
1050                                         {
1051                                                 if(client.classname != "spectator" && client.classname != "observer")
1052                                                 {
1053                                                         if(teamplay)
1054                                                         {
1055                                                                 // set up
1056                                                                 float team_color;
1057                                                                 float save = client.team_forced;
1058                                                                 client.team_forced = 0;
1059
1060                                                                 // find the team to move the player to
1061                                                                 team_color = ColourToNumber(destination);
1062                                                                 if(team_color == client.team) // already on the destination team
1063                                                                 {
1064                                                                         // keep the forcing undone
1065                                                                         print("Player ", ftos(GetFilteredNumber(t)), " (", client.netname, ") is already on the ", ColoredTeamName(client.team), (targets ? ", skipping to next player.\n" : ".\n"));
1066                                                                         continue;
1067                                                                 } 
1068                                                                 else if(team_color == 0)  // auto team
1069                                                                 {
1070                                                                         team_color = NumberToTeamNumber(FindSmallestTeam(client, FALSE));
1071                                                                 }
1072                                                                 else
1073                                                                 {
1074                                                                         CheckAllowedTeams(client);
1075                                                                 }
1076                                                                 client.team_forced = save;
1077                                                                 
1078                                                                 // Check to see if the destination team is even available
1079                                                                 switch(team_color) 
1080                                                                 {
1081                                                                         case COLOR_TEAM1: if(c1 == -1) { print("Sorry, can't move player to red team if it doesn't exist.\n"); return; } break;
1082                                                                         case COLOR_TEAM2: if(c2 == -1) { print("Sorry, can't move player to blue team if it doesn't exist.\n"); return; } break;
1083                                                                         case COLOR_TEAM3: if(c3 == -1) { print("Sorry, can't move player to yellow team if it doesn't exist.\n"); return; } break;
1084                                                                         case COLOR_TEAM4: if(c4 == -1) { print("Sorry, can't move player to pink team if it doesn't exist.\n"); return; } break;
1085                                                                         
1086                                                                         default: print("Sorry, can't move player here if team ", destination, " doesn't exist.\n"); return;
1087                                                                 }
1088                                                                 
1089                                                                 // If so, lets continue and finally move the player
1090                                                                 client.team_forced = 0;
1091                                                                 MoveToTeam(client, team_color, 6, stof(notify));
1092                                                                 successful = strcat(successful, (successful ? ", " : ""), client.netname);
1093                                                                 print("Player ", ftos(GetFilteredNumber(t)), " (", client.netname, ") has been moved to the ", ColoredTeamName(team_color), ".\n");
1094                                                                 continue;
1095                                                         }
1096                                                         else
1097                                                         {
1098                                                                 print("Can't change teams when currently not playing a team game.\n");
1099                                                                 return;
1100                                                         }
1101                                                 }
1102                                                 else
1103                                                 {
1104                                                         print("Can't change teams if the player isn't in the game.\n"); // well technically we could, but should we allow that? :P 
1105                                                         return;
1106                                                 }
1107                                         }
1108                                 }
1109                                 
1110                                 if(successful)
1111                                         bprint("Successfully moved players ", successful, " to destination ", destination, ".\n");
1112                                 else
1113                                         print("No players given (", original_targets, ") are able to move.\n");
1114                                         
1115                                 return; // still correct parameters so return to avoid usage print
1116                         }
1117                 }
1118                         
1119                 default:
1120                         print("Incorrect parameters for ^2moveplayer^7\n");
1121                 case GC_REQUEST_USAGE:
1122                 {
1123                         print("\nUsage:^3 sv_cmd moveplayer clientnumbers destination [notify]\n");
1124                         print("  'clientnumbers' is a list (separated by commas) of player entity ID's\n");
1125                         print("  'destination' is what to send the player to, be it team or spectating\n");
1126                         print("  Full list of destinations here: \"spec, spectator, red, blue, yellow, pink, auto.\"\n");
1127                         print("  'notify' is whether or not to send messages notifying of the move. Detail below.\n");
1128                         print("    0 (00) automove centerprint, admin message; 1 (01) automove centerprint, no admin message\n");
1129                         print("    2 (10) no centerprint, admin message; 3 (11) no centerprint, no admin message\n");
1130                         print("Examples: moveplayer 1,3,5 red 3\n");
1131                         print("          moveplayer 2 spec \n");
1132                         print("See also: ^2allspec, shuffleteams^7\n");
1133                         return;
1134                 }
1135         }
1136 }
1137
1138 void GameCommand_nospectators(float request)
1139 {
1140         switch(request)
1141         {
1142                 case GC_REQUEST_COMMAND:
1143                 {
1144                         blockSpectators = 1;
1145                         entity plr;
1146                         FOR_EACH_CLIENT(plr) //give every spectator <g_maxplayers_spectator_blocktime> seconds time to become a player
1147                         {
1148                                 if(plr.classname == "spectator" || plr.classname == "observer")
1149                                 {
1150                                         plr.spectatortime = time;
1151                                         sprint(plr, strcat("^7You have to become a player within the next ", ftos(autocvar_g_maxplayers_spectator_blocktime), " seconds, otherwise you will be kicked, because spectators aren't allowed at this time!\n"));
1152                                 }
1153                         }
1154                         bprint(strcat("^7All spectators will be automatically kicked when not joining the game after ", ftos(autocvar_g_maxplayers_spectator_blocktime), " seconds!\n"));
1155                         return;
1156                 }
1157                         
1158                 default:
1159                 case GC_REQUEST_USAGE:
1160                 {
1161                         print("\nUsage:^3 sv_cmd nospectators\n");
1162                         print("  No arguments required.\n");
1163                         return;
1164                 }
1165         }
1166 }
1167
1168 void GameCommand_onslaught_updatelinks(float request) // UNTESTED // should this be here? Perhaps some mutatorhook call instead....
1169 {
1170         switch(request)
1171         {
1172                 case GC_REQUEST_COMMAND:
1173                 {
1174                         onslaught_updatelinks();
1175                         print("ONS links updated\n");
1176                         return;
1177                 }
1178                         
1179                 default:
1180                 case GC_REQUEST_USAGE:
1181                 {
1182                         print("\nUsage:^3 sv_cmd onslaught_updatelinks\n");
1183                         print("  No arguments required.\n");
1184                         return;
1185                 }
1186         }
1187 }
1188
1189 void GameCommand_playerdemo(float request, float argc) // UNTESTED
1190 {       
1191         switch(request)
1192         {
1193                 case GC_REQUEST_COMMAND:
1194                 {
1195                         entity client;
1196                         float i, n, entno;
1197                         string s;
1198                         
1199                         switch(argv(1))
1200                         {
1201                                 case "read":
1202                                 {
1203                                         // TODO: Create a general command for looking this up, save a lot of space everywhere in this file
1204                                         entno = GetFilteredNumber(argv(2));
1205                                         if((entno < 1) | (entno > maxclients)) {
1206                                                 print("Player ", argv(2), " doesn't exist\n");
1207                                                 return;
1208                                         }
1209                                         client = edict_num(entno);
1210                                         if(clienttype(client) != CLIENTTYPE_BOT) {
1211                                                 print("Player ", client.netname, " is not a bot\n");
1212                                                 return;
1213                                         }
1214                                         self = client;
1215                                         playerdemo_open_read(argv(3));
1216                                         return;
1217                                 }
1218                                 
1219                                 case "write":
1220                                 {
1221                                         entno = GetFilteredNumber(argv(2));
1222                                         if((entno < 1) | (entno > maxclients)) {
1223                                                 print("Player ", argv(2), " doesn't exist\n");
1224                                                 return;
1225                                         }
1226                                         client = edict_num(entno);
1227                                         self = client;
1228                                         playerdemo_open_write(argv(3));
1229                                         return;
1230                                 }
1231                                 
1232                                 case "auto_read_and_write":
1233                                 {
1234                                         s = argv(2);
1235                                         n = GetFilteredNumber(argv(3));
1236                                         cvar_set("bot_number", ftos(n));
1237                                         localcmd("wait; wait; wait\n");
1238                                         for(i = 0; i < n; ++i)
1239                                                 localcmd("sv_cmd playerdemo read ", ftos(i+2), " ", s, ftos(i+1), "\n");
1240                                         localcmd("sv_cmd playerdemo write 1 ", ftos(n+1), "\n");
1241                                         return;
1242                                 }
1243                                 
1244                                 case "auto_read":
1245                                 {
1246                                         s = argv(2);
1247                                         n = GetFilteredNumber(argv(3));
1248                                         cvar_set("bot_number", ftos(n));
1249                                         localcmd("wait; wait; wait\n");
1250                                         for(i = 0; i < n; ++i)
1251                                                 localcmd("sv_cmd playerdemo read ", ftos(i+2), " ", s, ftos(i+1), "\n");
1252                                         return;
1253                                 }
1254                                 
1255                                 return;
1256                         }
1257                 }
1258                         
1259                 default:
1260                         print("Incorrect parameters for ^2radarmap^7\n");
1261                 case GC_REQUEST_USAGE:
1262                 {
1263                         print("\nUsage:^3 sv_cmd \n");
1264                         print("  FIXME: Arguments currently unknown\n");
1265                         return;
1266                 }
1267         }
1268 }
1269
1270 void GameCommand_printstats(float request)
1271 {
1272         switch(request)
1273         {
1274                 case GC_REQUEST_COMMAND:
1275                 {
1276                         DumpStats(FALSE);
1277                         print("stats dumped.\n");
1278                         return;
1279                 }
1280                         
1281                 default:
1282                 case GC_REQUEST_USAGE:
1283                 {
1284                         print("\nUsage:^3 sv_cmd printstats\n");
1285                         print("  No arguments required.\n");
1286                         return;
1287                 }
1288         }
1289 }
1290
1291 void GameCommand_radarmap(float request, float argc)
1292 {
1293         switch(request)
1294         {
1295                 case GC_REQUEST_COMMAND:
1296                 {
1297                         if(RadarMap_Make(argc))
1298                                 return;
1299                 }
1300                         
1301                 default:
1302                         print("Incorrect parameters for ^2radarmap^7\n");
1303                 case GC_REQUEST_USAGE:
1304                 {
1305                         print("\nUsage:^3 sv_cmd radarmap [--force] [--loop] [--quit] [--block | --trace | --sample | --lineblock] [--sharpen N] [--res W H] [--qual Q]\n");
1306                         print("  The quality factor Q is roughly proportional to the time taken.\n");
1307                         print("  trace supports no quality factor; its result should look like --block with infinite quality factor.\n");
1308                         return;
1309                 }
1310         }
1311 }
1312
1313 void GameCommand_rankings(float request) // this is OLD.... jeez.
1314 {
1315         switch(request)
1316         {
1317                 case GC_REQUEST_COMMAND:
1318                 {
1319                         strunzone(rankings_reply);
1320                         rankings_reply = strzone(getrankings());
1321                         print(rankings_reply);
1322                         return;
1323                 }
1324                         
1325                 default:
1326                 case GC_REQUEST_USAGE:
1327                 {
1328                         print("\nUsage:^3 sv_cmd rankings\n");
1329                         print("  No arguments required.\n");
1330                         return;
1331                 }
1332         }
1333 }
1334
1335 void GameCommand_records(float request)
1336 {
1337         switch(request)
1338         {
1339                 case GC_REQUEST_COMMAND:
1340                 {
1341                         float i;
1342                         
1343                         for (i = 0; i < 10; ++i)
1344                                 print(records_reply[i]);
1345                                 
1346                         return;
1347                 }
1348                         
1349                 default:
1350                 case GC_REQUEST_USAGE:
1351                 {
1352                         print("\nUsage:^3 sv_cmd records\n");
1353                         print("  No arguments required.\n");
1354                         return;
1355                 }
1356         }
1357 }
1358
1359 void GameCommand_reducematchtime(float request)
1360 {
1361         switch(request)
1362         {
1363                 case GC_REQUEST_COMMAND:
1364                 {
1365                         changematchtime(autocvar_timelimit_decrement*-60, autocvar_timelimit_min*60, autocvar_timelimit_max*60);
1366                         return;
1367                 }
1368                         
1369                 default:
1370                 case GC_REQUEST_USAGE:
1371                 {
1372                         print("\nUsage:^3 sv_cmd reducematchtime\n");
1373                         print("  No arguments required.\n");
1374                         print("See also: ^2extendmatchtime^7\n");
1375                         return;
1376                 }
1377         }
1378 }
1379
1380 void GameCommand_setbots(float request, float argc)
1381 {
1382         switch(request)
1383         {
1384                 case GC_REQUEST_COMMAND:
1385                 {
1386                         if(argc >= 2)
1387                         {
1388                                 cvar_settemp("minplayers", "0");
1389                                 cvar_settemp("bot_number", argv(1));
1390                                 bot_fixcount();
1391                                 return;
1392                         }
1393                 }
1394                         
1395                 default:
1396                         print("Incorrect parameters for ^2setbots^7\n");
1397                 case GC_REQUEST_USAGE:
1398                 {
1399                         print("\nUsage:^3 sv_cmd setbots botnumber\n");
1400                         print("  Where 'botnumber' is the amount of bots to set bot_number cvar to.\n");
1401                         print("See also: ^2bot_cmd^7\n");
1402                         return;
1403                 }
1404         }
1405 }
1406
1407 void GameCommand_shuffleteams(float request)
1408 {
1409         switch(request)
1410         {
1411                 case GC_REQUEST_COMMAND:
1412                 {
1413                         if(teamplay)
1414                         {
1415                                 entity tmp_player;
1416                                 float i, x, z, t_teams, t_players, team_color;
1417
1418                                 // count the total amount of players and total amount of teams
1419                                 FOR_EACH_PLAYER(tmp_player)
1420                                 {
1421                                         CheckAllowedTeams(tmp_player);
1422                                         
1423                                         if(c1 >= 0) t_teams = max(1, t_teams);
1424                                         if(c2 >= 0) t_teams = max(2, t_teams);
1425                                         if(c3 >= 0) t_teams = max(3, t_teams);
1426                                         if(c4 >= 0) t_teams = max(4, t_teams);
1427                                         
1428                                         ++t_players;
1429                                 }
1430                                 
1431                                 // build a list of the players in a random order
1432                                 FOR_EACH_PLAYER(tmp_player)
1433                                 {
1434                                         for(;;)
1435                                         {
1436                                                 i = bound(1, floor(random() * maxclients) + 1, maxclients);
1437                                                 
1438                                                 if(shuffleteams_players[i])
1439                                                 {
1440                                                         continue; // a player is already assigned to this slot
1441                                                 }
1442                                                 else
1443                                                 {
1444                                                         shuffleteams_players[i] = num_for_edict(tmp_player);
1445                                                         break;
1446                                                 }
1447                                         }
1448                                 }
1449
1450                                 // finally, from the list made earlier, re-join the players in different order. 
1451                                 for(i = 1; i <= t_teams; ++i)
1452                                 {
1453                                         // find out how many players to assign to this team
1454                                         x = (t_players / t_teams);
1455                                         x = ((i == 1) ? ceil(x) : floor(x));
1456                                         
1457                                         team_color = NumberToTeamNumber(i);
1458                                         
1459                                         // sort through the random list of players made earlier 
1460                                         for(z = 1; z <= maxclients; ++z)
1461                                         {                                                       
1462                                                 if not(shuffleteams_teams[i] >= x)
1463                                                 {
1464                                                         if not(shuffleteams_players[z])
1465                                                                 continue; // not a player, move on to next random slot
1466                                                                 
1467                                                         self = edict_num(shuffleteams_players[z]); // TODO: add sanity checks for this entity to make sure it's okay and not some error.
1468                                                                 
1469                                                         if(self.team != team_color) 
1470                                                                 MoveToTeam(self, team_color, 6, 0);
1471
1472                                                         shuffleteams_players[z] = 0;
1473                                                         shuffleteams_teams[i] = shuffleteams_teams[i] + 1;
1474                                                 }
1475                                                 else
1476                                                 {
1477                                                         break; // move on to next team
1478                                                 }
1479                                         }
1480                                 }
1481                                 
1482                                 bprint("Successfully shuffled the players around randomly.\n");
1483                                 
1484                                 // clear the buffers now
1485                                 for (i=0; i<SHUFFLETEAMS_MAX_PLAYERS; ++i)
1486                                         shuffleteams_players[i] = 0;
1487                                 
1488                                 for (i=0; i<SHUFFLETEAMS_MAX_TEAMS; ++i)
1489                                         shuffleteams_teams[i] = 0;
1490                         }
1491                         else
1492                         {
1493                                 print("Can't shuffle teams when currently not playing a team game.\n");
1494                         }
1495                         
1496                         return;
1497                 }
1498                         
1499                 default:
1500                 case GC_REQUEST_USAGE:
1501                 {
1502                         print("\nUsage:^3 sv_cmd shuffleteams\n");
1503                         print("  No arguments required.\n");
1504                         print("See also: ^2moveplayer, allspec^7\n");
1505                         return;
1506                 }
1507         }
1508 }
1509
1510 void GameCommand_stuffto(float request, float argc)
1511 {
1512         // This... is a fairly dangerous and powerful command... - It allows any arguments to be sent to a client via rcon.
1513         // Because of this, it is disabled by default and must be enabled by the server owner when doing compilation. That way,
1514         // we can be certain they understand the risks of it... So to enable, compile server with -DSTUFFTO_ENABLED argument.
1515         
1516         #ifdef STUFFTO_ENABLED
1517         switch(request)
1518         {
1519                 case GC_REQUEST_COMMAND:
1520                 {
1521                         entity client;
1522                         float entno;
1523                         
1524                         if(argc == 3)
1525                         {
1526                                 entno = GetFilteredNumber(argv(1));
1527                                 client = world;
1528                                 if(entno <= maxclients)
1529                                         client = edict_num(entno);
1530                                 if(client.flags & FL_CLIENT)
1531                                 {
1532                                         stuffcmd(client, strcat("\n", argv(2), "\n"));
1533                                         print(strcat("Command: \"", argv(2), "\" sent to ", client.netname, " (", argv(1) ,").\n"));
1534                                 }
1535                                 else
1536                                         print(strcat("Client (", argv(1) ,") not found.\n"));
1537                                 
1538                                 return;
1539                         }
1540                 }
1541                         
1542                 default:
1543                         print("Incorrect parameters for ^2stuffto^7\n");
1544                 case GC_REQUEST_USAGE:
1545                 {
1546                         print("\nUsage:^3 sv_cmd stuffto clientnumber command\n");
1547                         print("  FIXME: Arguments currently unknown\n");
1548                         return;
1549                 }
1550         }
1551         #else
1552         if(request)
1553         {
1554                 print("stuffto command is not enabled on this server.\n");
1555                 return;
1556         }
1557         #endif
1558 }
1559
1560 void GameCommand_teamstatus(float request)
1561 {
1562         switch(request)
1563         {
1564                 case GC_REQUEST_COMMAND:
1565                 {
1566                         Score_NicePrint(world);
1567                         return;
1568                 }
1569                         
1570                 default:
1571                 case GC_REQUEST_USAGE:
1572                 {
1573                         print("\nUsage:^3 sv_cmd teamstatus\n");
1574                         print("  No arguments required.\n");
1575                         return;
1576                 }
1577         }
1578 }
1579
1580 void GameCommand_time(float request)
1581 {
1582         switch(request)
1583         {
1584                 case GC_REQUEST_COMMAND:
1585                 {
1586                         print("time = ", ftos(time), "\n");
1587                         print("frame start = ", ftos(gettime(GETTIME_FRAMESTART)), "\n");
1588                         print("realtime = ", ftos(gettime(GETTIME_REALTIME)), "\n");
1589                         print("hires = ", ftos(gettime(GETTIME_HIRES)), "\n");
1590                         print("uptime = ", ftos(gettime(GETTIME_UPTIME)), "\n");
1591                         print("localtime = ", strftime(TRUE, "%a %b %e %H:%M:%S %Z %Y"), "\n"); // FIXME: Why is strftime broken? is engine problem, I think.
1592                         print("gmtime = ", strftime(FALSE, "%a %b %e %H:%M:%S %Z %Y"), "\n");
1593                         return;
1594                 }
1595                         
1596                 default:
1597                 case GC_REQUEST_USAGE:
1598                 {
1599                         print("\nUsage:^3 sv_cmd time\n");
1600                         print("  No arguments required.\n");
1601                         return;
1602                 }
1603         }
1604 }
1605
1606 void GameCommand_trace(float request, float argc)
1607 {                                               
1608         switch(request)
1609         {
1610                 case GC_REQUEST_COMMAND:
1611                 {
1612                         // TODO: Clean up all of these variables and merge the code below to use only a few
1613                         entity e;
1614                         vector org, delta, start, end, p, q, q0, pos, vv, dv;
1615                         float i, f, safe, unsafe, dq, dqf;
1616         
1617                         switch(argv(1))
1618                         {
1619                                 case "debug":
1620                                 {
1621                                         print("TEST CASE. If this returns the runaway loop counter error, possibly everything is oaky.\n");
1622                                         for(;;)
1623                                         {
1624                                                 org = world.mins;
1625                                                 delta = world.maxs - world.mins;
1626
1627                                                 start_x = org_x + random() * delta_x;
1628                                                 start_y = org_y + random() * delta_y;
1629                                                 start_z = org_z + random() * delta_z;
1630
1631                                                 end_x = org_x + random() * delta_x;
1632                                                 end_y = org_y + random() * delta_y;
1633                                                 end_z = org_z + random() * delta_z;
1634
1635                                                 start = stov(vtos(start));
1636                                                 end = stov(vtos(end));
1637
1638                                                 tracebox(start, PL_MIN, PL_MAX, end, MOVE_NOMONSTERS, world);
1639                                                 if(!trace_startsolid)
1640                                                 {
1641                                                         p = trace_endpos;
1642                                                         tracebox(p, PL_MIN, PL_MAX, p, MOVE_NOMONSTERS, world);
1643                                                         if(trace_startsolid || trace_fraction == 1)
1644                                                         {
1645                                                                 rint(42); // do an engine breakpoint on VM_rint so you can get the trace that errnoeously returns startsolid
1646                                                                 tracebox(start, PL_MIN, PL_MAX, end, MOVE_NOMONSTERS, world);
1647                                                                 tracebox(p, PL_MIN, PL_MAX, q, MOVE_NOMONSTERS, world);
1648
1649                                                                 if(trace_startsolid)
1650                                                                 {
1651                                                                         // how much do we need to back off?
1652                                                                         safe = 1;
1653                                                                         unsafe = 0;
1654                                                                         for(;;)
1655                                                                         {
1656                                                                                 pos = p * (1 - (safe + unsafe) * 0.5) + start * ((safe + unsafe) * 0.5);
1657                                                                                 tracebox(pos, PL_MIN, PL_MAX, pos, MOVE_NOMONSTERS, world);
1658                                                                                 if(trace_startsolid)
1659                                                                                 {
1660                                                                                         if((safe + unsafe) * 0.5 == unsafe)
1661                                                                                                 break;
1662                                                                                         unsafe = (safe + unsafe) * 0.5;
1663                                                                                 }
1664                                                                                 else
1665                                                                                 {
1666                                                                                         if((safe + unsafe) * 0.5 == safe)
1667                                                                                                 break;
1668                                                                                         safe = (safe + unsafe) * 0.5;
1669                                                                                 }
1670                                                                         }
1671
1672                                                                         print("safe distance to back off: ", ftos(safe * vlen(p - start)), "qu\n");
1673                                                                         print("unsafe distance to back off: ", ftos(unsafe * vlen(p - start)), "qu\n");
1674
1675                                                                         tracebox(p, PL_MIN + '0.1 0.1 0.1', PL_MAX - '0.1 0.1 0.1', p, MOVE_NOMONSTERS, world);
1676                                                                         if(trace_startsolid)
1677                                                                                 print("trace_endpos much in solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p), "\n");
1678                                                                         else
1679                                                                                 print("trace_endpos just in solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p), "\n");
1680                                                                         break;
1681                                                                 }
1682
1683                                                                 q0 = p;
1684                                                                 dq = 0;
1685                                                                 dqf = 1;
1686                                                                 for(;;)
1687                                                                 {
1688                                                                         q = p + normalize(end - p) * (dq + dqf);
1689                                                                         if(q == q0)
1690                                                                                 break;
1691                                                                         tracebox(p, PL_MIN, PL_MAX, q, MOVE_NOMONSTERS, world);
1692                                                                         if(trace_startsolid)
1693                                                                                 error("THIS ONE cannot happen");
1694                                                                         if(trace_fraction > 0)
1695                                                                                 dq += dqf * trace_fraction;
1696                                                                         dqf *= 0.5;
1697                                                                         q0 = q;
1698                                                                 }
1699                                                                 if(dq > 0)
1700                                                                 {
1701                                                                         print("trace_endpos still before solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p), "\n");
1702                                                                         print("could go ", ftos(dq), " units further to ", vtos(q), "\n");
1703                                                                         break;
1704                                                                 }
1705                                                         }
1706                                                 }
1707                                         }
1708                                         return;
1709                                 }
1710                                         
1711                                 case "debug2":
1712                                 {
1713                                         e = nextent(world);
1714                                         tracebox(e.origin + '0 0 32', e.mins, e.maxs, e.origin + '0 0 -1024', MOVE_NORMAL, e);
1715                                         vv = trace_endpos;
1716                                         if(trace_fraction == 1)
1717                                         {
1718                                                 print("not above ground, aborting\n");
1719                                                 return;
1720                                         }
1721                                         f = 0;
1722                                         for(i = 0; i < 100000; ++i)
1723                                         {
1724                                                 dv = randomvec();
1725                                                 if(dv_z > 0)
1726                                                         dv = -1 * dv;
1727                                                 tracebox(vv, e.mins, e.maxs, vv + dv, MOVE_NORMAL, e);
1728                                                 if(trace_startsolid)
1729                                                         print("bug 1\n");
1730                                                 if(trace_fraction == 1)
1731                                                 if(dv_z < f)
1732                                                 {
1733                                                         print("bug 2: ", ftos(dv_x), " ", ftos(dv_y), " ", ftos(dv_z));
1734                                                         print(" (", ftos(asin(dv_z / vlen(dv)) * 180 / M_PI), " degrees)\n");
1735                                                         f = dv_z;
1736                                                 }
1737                                         }
1738                                         print("highest possible dist: ", ftos(f), "\n");
1739                                         return;
1740                                 }
1741                                 
1742                                 case "walk":
1743                                 {
1744                                         if(argc == 3)
1745                                         {
1746                                                 e = nextent(world);
1747                                                 if(tracewalk(e, stov(argv(1)), e.mins, e.maxs, stov(argv(2)), MOVE_NORMAL))
1748                                                         print("can walk\n");
1749                                                 else
1750                                                         print("cannot walk\n");
1751                                                 return;
1752                                         }
1753                                 }
1754                                 
1755                                 case "showline":
1756                                 {
1757                                         if(argc == 3)
1758                                         {
1759                                                 vv = stov(argv(1));
1760                                                 dv = stov(argv(2));
1761                                                 traceline(vv, dv, MOVE_NORMAL, world);
1762                                                 trailparticles(world, particleeffectnum("TR_NEXUIZPLASMA"), vv, trace_endpos);
1763                                                 trailparticles(world, particleeffectnum("TR_CRYLINKPLASMA"), trace_endpos, dv);
1764                                                 return;
1765                                         }
1766                                 }
1767                                 
1768                                 // no default case, just go straight to invalid
1769                         }
1770                 }
1771                         
1772                 default:
1773                         print("Incorrect parameters for ^2trace^7\n");
1774                 case GC_REQUEST_USAGE:
1775                 {
1776                         print("\nUsage:^3 sv_cmd trace command [arguments]\n");
1777                         print("  FIXME: Arguments currently unknown\n");
1778                         return;
1779                 }
1780         }
1781 }
1782
1783 void GameCommand_unlockteams(float request)
1784 {
1785         switch(request)
1786         {
1787                 case GC_REQUEST_COMMAND:
1788                 {
1789                         if(teamplay)
1790                         {
1791                                 lockteams = 0;
1792                                 bprint("^1The teams are now unlocked.\n");
1793                         }
1794                         else
1795                         {
1796                                 bprint("unlockteams command can only be used in a team-based gamemode.\n");
1797                         }
1798                         return;
1799                 }
1800                         
1801                 default:
1802                 case GC_REQUEST_USAGE:
1803                 {
1804                         print("\nUsage:^3 sv_cmd unlockteams\n");
1805                         print("  No arguments required.\n");
1806                         print("See also: ^2lockteams^7\n");
1807                         return;
1808                 }
1809         }
1810 }
1811
1812 void GameCommand_warp(float request, float argc)
1813 {
1814         switch (request)
1815         {
1816                 case GC_REQUEST_COMMAND:
1817                 {
1818                         if(autocvar_g_campaign)
1819                         {
1820                                 if(argc >= 2)
1821                                 {
1822                                         CampaignLevelWarp(stof(argv(1)));
1823                                         print("Successfully warped to campaign level ", stof(argv(1)), ".\n");
1824                                 }       
1825                                 else
1826                                 {
1827                                         CampaignLevelWarp(-1);
1828                                         print("Successfully warped to next campaign level.\n");
1829                                 }
1830                         }
1831                         else
1832                                 print("Not in campaign, can't level warp\n");
1833                         return;
1834                 }
1835                 
1836                 default:
1837                 case GC_REQUEST_USAGE:
1838                 {
1839                         print("\nUsage:^3 sv_cmd level\n");
1840                         print("  'level' is the level to change campaign mode to.\n");
1841                         return;
1842                 }
1843         }
1844 }
1845
1846 /* use this when creating a new command, making sure to place it in alphabetical order.
1847 void GameCommand_(float request)
1848 {
1849         switch(request)
1850         {
1851                 case GC_REQUEST_COMMAND:
1852                 {
1853                         
1854                         return;
1855                 }
1856                         
1857                 default:
1858                 case GC_REQUEST_USAGE:
1859                 {
1860                         print("\nUsage:^3 sv_cmd \n");
1861                         print("  No arguments required.\n");
1862                         return;
1863                 }
1864         }
1865 }
1866 */
1867
1868
1869 // ==================================
1870 //  Macro system for server commands
1871 // ==================================
1872
1873 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
1874 #define SERVER_COMMANDS(request,arguments,command) \
1875         SERVER_COMMAND("adminmsg", GameCommand_adminmsg(request, arguments), "Send an admin message to a client directly") \
1876         SERVER_COMMAND("allready", GameCommand_allready(request), "Restart the server and reset the players") \
1877         SERVER_COMMAND("allspec", GameCommand_allspec(request, arguments), "Force all players to spectate") \
1878         SERVER_COMMAND("anticheat", GameCommand_anticheat(request, arguments), "Create an anticheat report for a client") \
1879         SERVER_COMMAND("bbox", GameCommand_bbox(request), "Print detailed information about world size") \
1880         SERVER_COMMAND("bot_cmd", GameCommand_bot_cmd(request, arguments), "Control and send commands to bots") \
1881         SERVER_COMMAND("cointoss", GameCommand_cointoss(request, arguments), "Flip a virtual coin and give random result") \
1882         SERVER_COMMAND("cvar_changes", GameCommand_cvar_changes(request), "Prints a list of all changed server cvars") \
1883         SERVER_COMMAND("cvar_purechanges", GameCommand_cvar_purechanges(request), "Prints a list of all changed gameplay cvars") \
1884         SERVER_COMMAND("database", GameCommand_database(request, arguments), "Extra controls of the serverprogs database") \
1885         SERVER_COMMAND("defer_clear", GameCommand_defer_clear(request, arguments), "Clear all queued defer commands for a specific client") \
1886         SERVER_COMMAND("defer_clear_all", GameCommand_defer_clear_all(request), "Clear all queued defer commands for all clients") \
1887         SERVER_COMMAND("delrec", GameCommand_delrec(request, arguments), "Delete race time record for a map") \
1888         SERVER_COMMAND("effectindexdump", GameCommand_effectindexdump(request), "Dump list of effects from code and effectinfo.txt") \
1889         SERVER_COMMAND("extendmatchtime", GameCommand_extendmatchtime(request), "Increase the timelimit value incrementally") \
1890         SERVER_COMMAND("find", GameCommand_find(request, arguments), "Search through entities for matching classname") \
1891         SERVER_COMMAND("gametype", GameCommand_gametype(request, arguments), "Simple command to change the active gametype") \
1892         SERVER_COMMAND("gettaginfo", GameCommand_gettaginfo(request, arguments), "Get specific information about a weapon model") \
1893         SERVER_COMMAND("gotomap", GameCommand_gotomap(request, arguments), "Simple command to switch to another map") \
1894         SERVER_COMMAND("ladder", GameCommand_ladder(request), "Get information about top players if supported") \
1895         SERVER_COMMAND("lockteams", GameCommand_lockteams(request), "Disable the ability for players to switch or enter teams") \
1896         SERVER_COMMAND("make_mapinfo", GameCommand_make_mapinfo(request), "Automatically rebuild mapinfo files") \
1897         SERVER_COMMAND("modelbug", GameCommand_modelbug(request), "TODO foobar") \
1898         SERVER_COMMAND("moveplayer", GameCommand_moveplayer(request, arguments), "Change the team/status of a player") \
1899         SERVER_COMMAND("nospectators", GameCommand_nospectators(request), "Automatically remove spectators from a match") \
1900         SERVER_COMMAND("onslaught_updatelinks", GameCommand_onslaught_updatelinks(request), "Refresh link status for onslaught") \
1901         SERVER_COMMAND("playerdemo", GameCommand_playerdemo(request, arguments), "Control the ability to save demos of players") \
1902         SERVER_COMMAND("printstats", GameCommand_printstats(request), "TODO foobar") \
1903         SERVER_COMMAND("radarmap", GameCommand_radarmap(request, arguments), "Generate a radar image of the map") \
1904         SERVER_COMMAND("rankings", GameCommand_rankings(request), "Print information about rankings") \
1905         SERVER_COMMAND("records", GameCommand_records(request), "List top 10 records for the current map") \
1906         SERVER_COMMAND("reducematchtime", GameCommand_reducematchtime(request), "Decrease the timelimit value incrementally") \
1907         SERVER_COMMAND("setbots", GameCommand_setbots(request, arguments), "Adjust how many bots are in the match") \
1908         SERVER_COMMAND("shuffleteams", GameCommand_shuffleteams(request), "Randomly move players to different teams") \
1909         SERVER_COMMAND("stuffto", GameCommand_stuffto(request, arguments), "Send a command to be executed on a client") \
1910         SERVER_COMMAND("teamstatus", GameCommand_teamstatus(request), "Show information about player and team scores") \
1911         SERVER_COMMAND("time", GameCommand_time(request), "Print different formats/readouts of time") \
1912         SERVER_COMMAND("trace", GameCommand_trace(request, arguments), "Various debugging tools with tracing") \
1913         SERVER_COMMAND("unlockteams", GameCommand_unlockteams(request), "Enable the ability for players to switch or enter teams") \
1914         SERVER_COMMAND("warp", GameCommand_warp(request, arguments), "Choose different level in campaign") \
1915         SERVER_COMMAND("vote", VoteCommand(request, world, arguments, command), "Server side control of voting") /* handled in server/vote.qc */ \
1916         /* nothing */
1917
1918 void GameCommand_macro_help()
1919 {
1920         #define SERVER_COMMAND(name,function,description) \
1921                 { print("  ^2", name, "^7: ", description, "\n"); }
1922                 
1923         SERVER_COMMANDS(0, 0, "")
1924         #undef SERVER_COMMAND
1925         
1926         return;
1927 }
1928
1929 float GameCommand_macro_command(float argc, string command)
1930 {
1931         #define SERVER_COMMAND(name,function,description) \
1932                 { if(name == strtolower(argv(0))) { function; return TRUE; } }
1933                 
1934         SERVER_COMMANDS(GC_REQUEST_COMMAND, argc, command)
1935         #undef SERVER_COMMAND
1936         
1937         return FALSE;
1938 }
1939
1940 float GameCommand_macro_usage(float argc)
1941 {
1942         #define SERVER_COMMAND(name,function,description) \
1943                 { if(name == strtolower(argv(1))) { function; return TRUE; } }
1944                 
1945         SERVER_COMMANDS(GC_REQUEST_USAGE, argc, "")
1946         #undef SERVER_COMMAND
1947         
1948         return FALSE;
1949 }
1950         
1951
1952 // =========================================
1953 //  Main Function Called By Engine (sv_cmd)
1954 // =========================================
1955 // If this function exists, game code handles gamecommand instead of the engine code.
1956
1957 void GameCommand(string command)
1958 {
1959         float argc = tokenize_console(command);
1960
1961         if(strtolower(argv(0)) == "help") 
1962         {
1963                 if(argc == 1) 
1964                 {
1965                         print("\nUsage:^3 sv_cmd COMMAND...^7, where possible commands are:\n");
1966                         GameCommand_macro_help();
1967                         
1968                         GameCommand_Ban("help");
1969                         GameCommand_Generic("help");
1970                         print("For help about specific commands, type sv_cmd help COMMAND\n");
1971                         return;
1972                 } 
1973                 else if(GameCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
1974                 {
1975                         return;
1976                 }
1977         } 
1978         else if(GameCommand_Ban(command)) 
1979         {
1980                 return; // handled by server/ipban.qc
1981         }
1982         else if(GameCommand_Generic(command)) 
1983         {
1984                 return; // handled by common/gamecommand.qc
1985         }
1986         else if(GameCommand_macro_command(argc, command)) // continue as usual and scan for normal commands
1987         {
1988                 return; // handled by one of the above GameCommand_* functions
1989         }
1990         
1991         // nothing above caught the command, must be invalid
1992         print("Unknown server command", ((command != "") ? strcat(" \"", command, "\"") : ""), ". For a list of supported commands, try sv_cmd help.\n");
1993         
1994         return;
1995 }