]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/command/sv_cmd.qc
e1070ad9ad51790792f95479bb376b8abb91d6ca
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / command / sv_cmd.qc
1 #include "sv_cmd.qh"
2
3 #include <common/constants.qh>
4 #include <common/effects/all.qh>
5 #include <common/gamemodes/_mod.qh>
6 #include <common/mapinfo.qh>
7 #include <common/monsters/sv_monsters.qh>
8 #include <common/net_linked.qh>
9 #include <common/notifications/all.qh>
10 #include <common/teams.qh>
11 #include <common/util.qh>
12 #include <server/anticheat.qh>
13 #include <server/bot/api.qh>
14 #include <server/campaign.qh>
15 #include <server/client.qh>
16 #include <server/command/_mod.qh>
17 #include <server/command/banning.qh>
18 #include <server/command/cmd.qh>
19 #include <server/command/common.qh>
20 #include <server/command/getreplies.qh>
21 #include <server/command/radarmap.qh>
22 #include <server/intermission.qh>
23 #include <server/ipban.qh>
24 #include <server/mutators/_mod.qh>
25 #include <server/player.qh>
26 #include <server/teamplay.qh>
27 #include <server/world.qh>
28
29 //  used by GameCommand_make_mapinfo()
30 void make_mapinfo_Think(entity this)
31 {
32         if (_MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 1))
33         {
34                 LOG_INFO("Done rebuiling mapinfos.");
35                 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
36                 delete(this);
37         }
38         else
39         {
40                 setthink(this, make_mapinfo_Think);
41                 this.nextthink = time;
42         }
43 }
44
45 //  used by GameCommand_extendmatchtime() and GameCommand_reducematchtime()
46 void changematchtime(float delta, float mi, float ma)
47 {
48         float cur;
49         float update;
50         float lim;
51
52         if (delta == 0) return;
53         if (autocvar_timelimit < 0) return;
54
55         if (mi <= 10) mi = 10;  // at least ten sec in the future
56         cur = time - game_starttime;
57         if (cur > 0) mi += cur; // from current time!
58
59         lim = autocvar_timelimit * 60;
60
61         if (delta > 0)
62         {
63                 if (lim == 0) return; // cannot increase any further
64                 else if (lim < ma) update = min(ma, lim + delta);
65                 else                  // already above maximum: FAIL
66                         return;
67         }
68         else
69         {
70                 if (lim == 0)      // infinite: try reducing to max, if we are allowed to
71                         update = max(mi, ma);
72                 else if (lim > mi) // above minimum: decrease
73                         update = max(mi, lim + delta);
74                 else               // already below minimum: FAIL
75                         return;
76         }
77
78         cvar_set("timelimit", ftos(update / 60));
79 }
80
81
82 // =======================
83 //  Command Sub-Functions
84 // =======================
85
86 void GameCommand_adminmsg(int request, int argc)
87 {
88         switch (request)
89         {
90                 case CMD_REQUEST_COMMAND:
91                 {
92                         entity client;
93                         float accepted;
94
95                         string targets = strreplace(",", " ", argv(1));
96                         string original_targets = strreplace(" ", ", ", targets);
97                         string admin_message = argv(2);
98                         float infobartime = stof(argv(3));
99
100                         string successful, t;
101                         successful = string_null;
102
103                         if ((targets) && (admin_message))
104                         {
105                                 for ( ; targets; )
106                                 {
107                                         t = car(targets);
108                                         targets = cdr(targets);
109
110                                         // Check to see if the player is a valid target
111                                         client = GetFilteredEntity(t);
112                                         accepted = VerifyClientEntity(client, true, false);
113
114                                         if (accepted <= 0)
115                                         {
116                                                 LOG_INFO("adminmsg: ", GetClientErrorString(accepted, t), (targets ? ", skipping to next player.\n" : "."));
117                                                 continue;
118                                         }
119
120                                         // send the centerprint/console print or infomessage
121                                         if (infobartime)
122                                         {
123                                                 stuffcmd(client, sprintf("\ninfobar %f \"%s\"\n", infobartime, MakeConsoleSafe(admin_message)));
124                                         }
125                                         else
126                                         {
127                                                 centerprint(client, strcat("^3", GetCallerName(NULL), ":\n^7", admin_message));
128                                                 sprint(client, strcat("\{1}\{13}^3", GetCallerName(NULL), "^7: ", admin_message, "\n"));
129                                         }
130
131                                         successful = strcat(successful, (successful ? ", " : ""), playername(client.netname, client.team, false));
132                                         LOG_TRACE("Message sent to ", playername(client.netname, client.team, false));
133                                         continue;
134                                 }
135
136                                 if (successful) bprint("Successfully sent message '", admin_message, "' to ", successful, ".\n");
137                                 else LOG_INFO("No players given (", original_targets, ") could receive the message.");
138
139                                 return;
140                         }
141                 }
142
143                 default:
144                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
145                 case CMD_REQUEST_USAGE:
146                 {
147                         LOG_HELP("Usage:^3 sv_cmd adminmsg <clients> \"<message>\" [<infobartime>]");
148                         LOG_HELP("  <clients> is a list (separated by commas) of player entity ID's or nicknames");
149                         LOG_HELP("  If <infobartime> is provided, the message will be sent to infobar.");
150                         LOG_HELP("  Otherwise, it will just be sent as a centerprint message.");
151                         LOG_HELP("Examples: adminmsg 2,4 \"this infomessage will last for ten seconds\" 10");
152                         LOG_HELP("          adminmsg 2,5 \"this message will be a centerprint\"");
153                         return;
154                 }
155         }
156 }
157
158 void GameCommand_allready(int request)
159 {
160         switch (request)
161         {
162                 case CMD_REQUEST_COMMAND:
163                 {
164                         if(warmup_stage)
165                         {
166                                 warmup_stage = 0;
167                                 ReadyRestart();
168                         }
169                         else
170                                 LOG_INFO("Not in warmup.");
171
172                         return;
173                 }
174
175                 default:
176                 case CMD_REQUEST_USAGE:
177                 {
178                         LOG_HELP("Usage:^3 sv_cmd allready");
179                         LOG_HELP("  No arguments required.");
180                         return;
181                 }
182         }
183 }
184
185 void GameCommand_allspec(int request, int argc)
186 {
187         switch (request)
188         {
189                 case CMD_REQUEST_COMMAND:
190                 {
191                         string reason = argv(1);
192                         int n = 0;
193                         FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
194                                 PutObserverInServer(it, true);
195                                 ++n;
196                         });
197                         if (n)   bprint(strcat("Successfully forced all (", ftos(n), ") players to spectate", (reason ? strcat(" for reason: '", reason, "'") : ""), ".\n"));
198                         else   LOG_INFO("No players found to spectate.");
199                         return;
200                 }
201
202                 default:
203                 case CMD_REQUEST_USAGE:
204                 {
205                         LOG_HELP("Usage:^3 sv_cmd allspec [<reason>]");
206                         LOG_HELP("  Where <reason> is an optional argument for explanation of allspec command.");
207                         LOG_HELP("See also: ^2moveplayer, shuffleteams^7");
208                         return;
209                 }
210         }
211 }
212
213 void GameCommand_anticheat(int request, int argc)
214 {
215         switch (request)
216         {
217                 case CMD_REQUEST_COMMAND:
218                 {
219                         entity client = GetIndexedEntity(argc, 1);
220                         float accepted = VerifyClientEntity(client, false, false);
221
222                         if (accepted > 0)
223                         {
224                                 anticheat_report_to_eventlog(client);
225                                 return;
226                         }
227                         else
228                         {
229                                 LOG_INFO("anticheat: ", GetClientErrorString(accepted, argv(1)), ".");
230                         }
231                 }
232
233                 default:
234                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
235                 case CMD_REQUEST_USAGE:
236                 {
237                         LOG_HELP("Usage:^3 sv_cmd anticheat <client>");
238                         LOG_HELP("  <client> is the entity number or name of the player.");
239                         return;
240                 }
241         }
242 }
243
244 void GameCommand_bbox(int request)
245 {
246         switch (request)
247         {
248                 case CMD_REQUEST_COMMAND:
249                 {
250                         vector size_min = '0 0 0';
251                         vector size_max = '0 0 0';
252                         tracebox('1 0 0' * world.absmin.x,
253                                 '0 1 0' * world.absmin.y + '0 0 1' * world.absmin.z,
254                                 '0 1 0' * world.absmax.y + '0 0 1' * world.absmax.z,
255                                 '1 0 0' * world.absmax.x,
256                                 MOVE_WORLDONLY,
257                                 NULL);
258                         size_min.x = (trace_startsolid) ? world.absmin.x : trace_endpos.x;
259
260                         tracebox('0 1 0' * world.absmin.y,
261                                 '1 0 0' * world.absmin.x + '0 0 1' * world.absmin.z,
262                                 '1 0 0' * world.absmax.x + '0 0 1' * world.absmax.z,
263                                 '0 1 0' * world.absmax.y,
264                                 MOVE_WORLDONLY,
265                                 NULL);
266                         size_min.y = (trace_startsolid) ? world.absmin.y : trace_endpos.y;
267
268                         tracebox('0 0 1' * world.absmin.z,
269                                 '1 0 0' * world.absmin.x + '0 1 0' * world.absmin.y,
270                                 '1 0 0' * world.absmax.x + '0 1 0' * world.absmax.y,
271                                 '0 0 1' * world.absmax.z,
272                                 MOVE_WORLDONLY,
273                                 NULL);
274                         size_min.z = (trace_startsolid) ? world.absmin.z : trace_endpos.z;
275
276                         tracebox('1 0 0' * world.absmax.x,
277                                 '0 1 0' * world.absmin.y + '0 0 1' * world.absmin.z,
278                                 '0 1 0' * world.absmax.y + '0 0 1' * world.absmax.z,
279                                 '1 0 0' * world.absmin.x,
280                                 MOVE_WORLDONLY,
281                                 NULL);
282                         size_max.x = (trace_startsolid) ? world.absmax.x : trace_endpos.x;
283
284                         tracebox('0 1 0' * world.absmax.y,
285                                 '1 0 0' * world.absmin.x + '0 0 1' * world.absmin.z,
286                                 '1 0 0' * world.absmax.x + '0 0 1' * world.absmax.z,
287                                 '0 1 0' * world.absmin.y,
288                                 MOVE_WORLDONLY,
289                                 NULL);
290                         size_max.y = (trace_startsolid) ? world.absmax.y : trace_endpos.y;
291
292                         tracebox('0 0 1' * world.absmax.z,
293                                 '1 0 0' * world.absmin.x + '0 1 0' * world.absmin.y,
294                                 '1 0 0' * world.absmax.x + '0 1 0' * world.absmax.y,
295                                 '0 0 1' * world.absmin.z,
296                                 MOVE_WORLDONLY,
297                                 NULL);
298                         size_max.z = (trace_startsolid) ? world.absmax.z : trace_endpos.z;
299
300                         LOG_INFOF("Original size: %v %v", world.absmin, world.absmax);
301                         LOG_INFOF("Currently set size: %v %v", world.mins, world.maxs);
302                         LOG_INFOF("Solid bounding box size: %v %v", size_min, size_max);
303                         return;
304                 }
305
306                 default:
307                 case CMD_REQUEST_USAGE:
308                 {
309                         LOG_HELP("Usage:^3 sv_cmd bbox");
310                         LOG_HELP("  No arguments required.");
311                         LOG_HELP("See also: ^2gettaginfo, trace^7");
312                         return;
313                 }
314         }
315 }
316
317 void GameCommand_bot_cmd(int request, int argc, string command)
318 {
319         switch (request)
320         {
321                 case CMD_REQUEST_COMMAND:
322                 {
323                         entity bot;
324
325                         if (argv(1) == "reset")
326                         {
327                                 bot_resetqueues();
328                                 return;
329                         }
330                         else if (argv(1) == "setbots")
331                         {
332                                 cvar_settemp("bot_vs_human", "0");
333                                 cvar_settemp("minplayers", "0");
334                                 cvar_settemp("minplayers_per_team", "0");
335                                 cvar_settemp("bot_number", "0");
336                                 bot_fixcount();
337                                 cvar_settemp("bot_number", argv(2));
338                                 if (!bot_fixcount()) LOG_INFO("Sorry, could not set requested bot count");
339                                 return;
340                         }
341                         else if (argv(1) == "load" && argc == 3)
342                         {
343                                 float fh, i;
344                                 string s;
345                                 fh = fopen(argv(2), FILE_READ);
346                                 if (fh < 0)
347                                 {
348                                         LOG_INFO("cannot open the file");
349                                         return;
350                                 }
351
352                                 i = 0;
353                                 while ((s = fgets(fh)))
354                                 {
355                                         argc = tokenize_console(s);
356
357                                         if (argc >= 3 && argv(0) == "sv_cmd" && argv(1) == "bot_cmd")
358                                         {
359                                                 if (argv(2) == "reset")
360                                                 {
361                                                         bot_resetqueues();
362                                                 }
363                                                 else if (argv(2) == "setbots")
364                                                 {
365                                                         cvar_settemp("bot_vs_human", "0");
366                                                         cvar_settemp("minplayers", "0");
367                                                         cvar_settemp("minplayers_per_team", "0");
368                                                         cvar_settemp("bot_number", "0");
369                                                         bot_fixcount();
370                                                         cvar_settemp("bot_number", argv(3));
371                                                         if (!bot_fixcount()) LOG_INFO("Sorry, could not set requested bot count");
372                                                 }
373                                                 else
374                                                 {
375                                                         if(argv(2) == "*" || argv(2) == "all")
376                                                                 FOREACH_CLIENT(IS_BOT_CLIENT(it), {
377                                                                         bot_queuecommand(it, substring(s, argv_start_index(3), -1));
378                                                                 });
379                                                         else
380                                                         {
381                                                                 bot = find_bot_by_number(stof(argv(2)));
382                                                                 if (bot == NULL) bot = find_bot_by_name(argv(2));
383                                                                 if (bot) bot_queuecommand(bot, substring(s, argv_start_index(3), -1));
384                                                         }
385                                                 }
386                                         }
387                                         else
388                                         {
389                                                 localcmd(strcat(s, "\n"));
390                                         }
391
392                                         ++i;
393                                 }
394                                 LOG_INFO(ftos(i), " commands read");
395                                 fclose(fh);
396                                 return;
397                         }
398                         else if (argv(1) == "help")
399                         {
400                                 if (argv(2)) bot_cmdhelp(argv(2));
401                                 else bot_list_commands();
402                                 return;
403                         }
404                         else if (argc >= 3)  // this comes last
405                         {
406                                 if(argv(1) == "*" || argv(1) == "all")
407                                 {
408                                         int bot_num = 0;
409                                         FOREACH_CLIENT(IS_BOT_CLIENT(it), {
410                                                 bot_queuecommand(it, substring(command, argv_start_index(2), -1));
411                                                 bot_num++;
412                                         });
413                                         if(bot_num)
414                                                 LOG_INFO("Command '", substring(command, argv_start_index(2), -1), "' sent to all bots (", ftos(bot_num), ")");
415                                         return;
416                                 }
417                                 else
418                                 {
419                                         bot = find_bot_by_number(stof(argv(1)));
420                                         if (bot == NULL) bot = find_bot_by_name(argv(1));
421                                         if (bot)
422                                         {
423                                                 LOG_INFO("Command '", substring(command, argv_start_index(2), -1), "' sent to bot ", bot.netname);
424                                                 bot_queuecommand(bot, substring(command, argv_start_index(2), -1));
425                                                 return;
426                                         }
427                                         else
428                                         {
429                                                 LOG_INFO("Error: Can't find bot with the name or id '", argv(1), "' - Did you mistype the command?");  // don't return so that usage is shown
430                                         }
431                                 }
432                         }
433                 }
434
435                 default:
436                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
437                 case CMD_REQUEST_USAGE:
438                 {
439                         LOG_HELP("Usage:^3 sv_cmd bot_cmd <client> <command> [<arguments>]");
440                         LOG_HELP("  <client> can be either the name of the bot or a progressive number (not the entity number!)");
441                         LOG_HELP("           can also be '*' or 'all' to allow sending the command to all the bots");
442                         LOG_HELP("  For full list of commands, see bot_cmd help [<command>].");
443                         LOG_HELP("Examples: sv_cmd bot_cmd 1 cc \"say something\"");
444                         LOG_HELP("          sv_cmd bot_cmd 1 presskey jump");
445                         LOG_HELP("          sv_cmd bot_cmd * pause");
446                         return;
447                 }
448         }
449 }
450
451 void GameCommand_cointoss(int request, int argc)
452 {
453         switch (request)
454         {
455                 case CMD_REQUEST_COMMAND:
456                 {
457                         string result1 = (argv(2) ? strcat("^7", argv(1)) : "^1HEADS");
458                         string result2 = (argv(2) ? strcat("^7", argv(2)) : "^4TAILS");
459                         string choice = ((random() > 0.5) ? result1 : result2);
460
461                         Send_Notification(NOTIF_ALL, NULL, MSG_MULTI, MULTI_COINTOSS, choice);
462                         return;
463                 }
464
465                 default:
466                 case CMD_REQUEST_USAGE:
467                 {
468                         LOG_HELP("Usage:^3 sv_cmd cointoss [<result1> <result2>]");
469                         LOG_HELP("  Where <result1> and <result2> are user created options.");
470                         return;
471                 }
472         }
473 }
474
475 void GameCommand_database(int request, int argc)
476 {
477         switch (request)
478         {
479                 case CMD_REQUEST_COMMAND:
480                 {
481                         if (argc == 3)
482                         {
483                                 if (argv(1) == "save")
484                                 {
485                                         db_save(ServerProgsDB, argv(2));
486                                         LOG_INFO("Copied serverprogs database to '", argv(2), "' in the data directory.");
487                                         return;
488                                 }
489                                 else if (argv(1) == "dump")
490                                 {
491                                         db_dump(ServerProgsDB, argv(2));
492                                         LOG_INFO("DB dumped.");  // wtf does this do?
493                                         return;
494                                 }
495                                 else if (argv(1) == "load")
496                                 {
497                                         db_close(ServerProgsDB);
498                                         ServerProgsDB = db_load(argv(2));
499                                         LOG_INFO("Loaded '", argv(2), "' as new serverprogs database.");
500                                         return;
501                                 }
502                         }
503                 }
504
505                 default:
506                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
507                 case CMD_REQUEST_USAGE:
508                 {
509                         LOG_HELP("Usage:^3 sv_cmd database <action> <filename>");
510                         LOG_HELP("  Where <action> is the command to complete,");
511                         LOG_HELP("  and <filename> is what it acts upon.");
512                         LOG_HELP("  Full list of commands here: save, dump, load.");
513                         return;
514                 }
515         }
516 }
517
518 void GameCommand_defer_clear(int request, int argc)
519 {
520         switch (request)
521         {
522                 case CMD_REQUEST_COMMAND:
523                 {
524                         entity client;
525                         float accepted;
526
527                         if (argc >= 2)
528                         {
529                                 client = GetIndexedEntity(argc, 1);
530                                 accepted = VerifyClientEntity(client, true, false);
531
532                                 if (accepted > 0)
533                                 {
534                                         stuffcmd(client, "defer clear\n");
535                                         LOG_INFO("defer clear stuffed to ", playername(client.netname, client.team, false));
536                                 }
537                                 else { LOG_INFO("defer_clear: ", GetClientErrorString(accepted, argv(1)), "."); }
538
539                                 return;
540                         }
541                 }
542
543                 default:
544                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
545                 case CMD_REQUEST_USAGE:
546                 {
547                         LOG_HELP("Usage:^3 sv_cmd defer_clear <client>");
548                         LOG_HELP("  <client> is the entity number or name of the player.");
549                         LOG_HELP("See also: ^2defer_clear_all^7");
550                         return;
551                 }
552         }
553 }
554
555 void GameCommand_defer_clear_all(int request)
556 {
557         switch (request)
558         {
559                 case CMD_REQUEST_COMMAND:
560                 {
561                         int n = 0;
562                         int argc;
563
564                         FOREACH_CLIENT(true, {
565                                 argc = tokenize_console(strcat("defer_clear ", ftos(etof(it))));
566                                 GameCommand_defer_clear(CMD_REQUEST_COMMAND, argc);
567                                 ++n;
568                         });
569                         if (n)   LOG_INFO("Successfully stuffed defer clear to all clients (", ftos(n), ")");  // should a message be added if no players were found?
570                         return;
571                 }
572
573                 default:
574                 case CMD_REQUEST_USAGE:
575                 {
576                         LOG_HELP("Usage:^3 sv_cmd defer_clear_all");
577                         LOG_HELP("  No arguments required.");
578                         LOG_HELP("See also: ^2defer_clear^7");
579                         return;
580                 }
581         }
582 }
583
584 void GameCommand_delrec(int request, int argc)  // perhaps merge later with records and printstats and such?
585 {
586         switch (request)
587         {
588                 case CMD_REQUEST_COMMAND:
589                 {
590                         if (argv(1))
591                         {
592                                 if (argv(2)) race_deleteTime(argv(2), stof(argv(1)));
593                                 else race_deleteTime(GetMapname(), stof(argv(1)));
594                                 return;
595                         }
596                 }
597
598                 default:
599                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
600                 case CMD_REQUEST_USAGE:
601                 {
602                         LOG_HELP("Usage:^3 sv_cmd delrec <ranking> [<map>]");
603                         LOG_HELP("  <ranking> is which ranking level to clear up to, ");
604                         LOG_HELP("  it will clear all records up to nth place.");
605                         LOG_HELP("  if <map> is not provided it will use current map.");
606                         return;
607                 }
608         }
609 }
610
611 void print_Effect_Index(int d, string effect_name)
612
613         // this is inside a function to avoid expanding it on compilation everytime
614         LOG_INFO("effect ", effect_name, " is ", ftos(_particleeffectnum(effect_name)), "\n");
615         db_put(d, effect_name, "1");
616 }
617
618 void GameCommand_effectindexdump(int request)
619 {
620         switch (request)
621         {
622                 case CMD_REQUEST_COMMAND:
623                 {
624                         float fh, d;
625                         string s;
626
627                         d = db_create();
628                         LOG_INFO("begin of effects list");
629
630                         print_Effect_Index(d, "TE_GUNSHOT");
631                         print_Effect_Index(d, "TE_GUNSHOTQUAD");
632                         print_Effect_Index(d, "TE_SPIKE");
633                         print_Effect_Index(d, "TE_SPIKEQUAD");
634                         print_Effect_Index(d, "TE_SUPERSPIKE");
635                         print_Effect_Index(d, "TE_SUPERSPIKEQUAD");
636                         print_Effect_Index(d, "TE_WIZSPIKE");
637                         print_Effect_Index(d, "TE_KNIGHTSPIKE");
638                         print_Effect_Index(d, "TE_EXPLOSION");
639                         print_Effect_Index(d, "TE_EXPLOSIONQUAD");
640                         print_Effect_Index(d, "TE_TAREXPLOSION");
641                         print_Effect_Index(d, "TE_TELEPORT");
642                         print_Effect_Index(d, "TE_LAVASPLASH");
643                         print_Effect_Index(d, "TE_SMALLFLASH");
644                         print_Effect_Index(d, "TE_FLAMEJET");
645                         print_Effect_Index(d, "EF_FLAME");
646                         print_Effect_Index(d, "TE_BLOOD");
647                         print_Effect_Index(d, "TE_SPARK");
648                         print_Effect_Index(d, "TE_PLASMABURN");
649                         print_Effect_Index(d, "TE_TEI_G3");
650                         print_Effect_Index(d, "TE_TEI_SMOKE");
651                         print_Effect_Index(d, "TE_TEI_BIGEXPLOSION");
652                         print_Effect_Index(d, "TE_TEI_PLASMAHIT");
653                         print_Effect_Index(d, "EF_STARDUST");
654                         print_Effect_Index(d, "TR_ROCKET");
655                         print_Effect_Index(d, "TR_GRENADE");
656                         print_Effect_Index(d, "TR_BLOOD");
657                         print_Effect_Index(d, "TR_WIZSPIKE");
658                         print_Effect_Index(d, "TR_SLIGHTBLOOD");
659                         print_Effect_Index(d, "TR_KNIGHTSPIKE");
660                         print_Effect_Index(d, "TR_VORESPIKE");
661                         print_Effect_Index(d, "TR_NEHAHRASMOKE");
662                         print_Effect_Index(d, "TR_NEXUIZPLASMA");
663                         print_Effect_Index(d, "TR_GLOWTRAIL");
664                         print_Effect_Index(d, "TR_SEEKER");
665                         print_Effect_Index(d, "SVC_PARTICLE");
666
667                         fh = fopen("effectinfo.txt", FILE_READ);
668                         while ((s = fgets(fh)))
669                         {
670                                 tokenize_console(s);
671                                 if (argv(0) == "effect")
672                                 {
673                                         if (db_get(d, argv(1)) != "1")
674                                         {
675                                                 int i = _particleeffectnum(argv(1));
676                                                 if (i >= 0) LOG_INFO("effect ", argv(1), " is ", ftos(i));
677                                                 db_put(d, argv(1), "1");
678                                         }
679                                 }
680                         }
681                         LOG_INFO("end of effects list");
682
683                         db_close(d);
684                         return;
685                 }
686
687                 default:
688                 case CMD_REQUEST_USAGE:
689                 {
690                         LOG_HELP("Usage:^3 sv_cmd effectindexdump");
691                         LOG_HELP("  No arguments required.");
692                         return;
693                 }
694         }
695 }
696
697 void GameCommand_extendmatchtime(int request)
698 {
699         switch (request)
700         {
701                 case CMD_REQUEST_COMMAND:
702                 {
703                         changematchtime(autocvar_timelimit_increment * 60, autocvar_timelimit_min * 60, autocvar_timelimit_max * 60);
704                         return;
705                 }
706
707                 default:
708                 case CMD_REQUEST_USAGE:
709                 {
710                         LOG_HELP("Usage:^3 sv_cmd extendmatchtime");
711                         LOG_HELP("  No arguments required.");
712                         LOG_HELP("See also: ^2reducematchtime^7");
713                         return;
714                 }
715         }
716 }
717
718 void GameCommand_gametype(int request, int argc)
719 {
720         switch (request)
721         {
722                 case CMD_REQUEST_COMMAND:
723                 {
724                         if (!world_initialized)
725                         {
726                                 LOG_INFOF("This command works only when the server is running.");
727                                 return;
728                         }
729                         if (argv(1) != "")
730                         {
731                                 string s = argv(1);
732                                 Gametype t = MapInfo_Type_FromString(s, false), tsave = MapInfo_CurrentGametype();
733
734                                 if (t)
735                                 {
736                                         MapInfo_SwitchGameType(t);
737                                         MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
738                                         if (MapInfo_count > 0)
739                                         {
740                                                 // update lsmaps in case the gametype changed, this way people can easily list maps for it
741                                                 if (lsmaps_reply != "")   strunzone(lsmaps_reply);
742                                                 lsmaps_reply = strzone(getlsmaps());
743                                                 bprint("Game type successfully switched to ", s, "\n");
744                                         }
745                                         else
746                                         {
747                                                 bprint("Cannot use this game type: no map for it found\n");
748                                                 MapInfo_SwitchGameType(tsave);
749                                                 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
750                                         }
751                                 }
752                                 else
753                                 {
754                                         bprint("Failed to switch to ", s, ": this game type does not exist!\n");
755                                 }
756
757                                 return;
758                         }
759                 }
760
761                 default:
762                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
763                 case CMD_REQUEST_USAGE:
764                 {
765                         LOG_HELP("Usage:^3 sv_cmd gametype <mode>");
766                         LOG_HELP("  Where <mode> is the gametype mode to switch to.");
767                         LOG_HELP("See also: ^2gotomap^7");
768                         return;
769                 }
770         }
771 }
772
773 void GameCommand_gettaginfo(int request, int argc)
774 {
775         switch (request)
776         {
777                 case CMD_REQUEST_COMMAND:
778                 {
779                         entity tmp_entity;
780                         float i;
781                         vector v;
782
783                         if (argc >= 4)
784                         {
785                                 tmp_entity = spawn();
786                                 if (argv(1) == "w")
787                                 {
788                                         .entity weaponentity = weaponentities[0];
789                                         _setmodel(tmp_entity, (nextent(NULL)).(weaponentity).model);
790                                 }
791                                 else
792                                 {
793                                         precache_model(argv(1));
794                                         _setmodel(tmp_entity, argv(1));
795                                 }
796                                 tmp_entity.frame = stof(argv(2));
797                                 if (substring(argv(3), 0, 1) == "#") i = stof(substring(argv(3), 1, -1));
798                                 else i = gettagindex(tmp_entity, argv(3));
799                                 if (i)
800                                 {
801                                         v = gettaginfo(tmp_entity, i);
802                                         LOG_HELPF("model %s frame %s tag %s index %s parent %s",
803                                                 tmp_entity.model, ftos(tmp_entity.frame), gettaginfo_name, ftos(i), ftos(gettaginfo_parent)
804                                         );
805                                         LOG_HELPF(" vector = %s %s %s", ftos(v.x), ftos(v.y), ftos(v.z));
806                                         LOG_HELPF(" offset = %s %s %s", ftos(gettaginfo_offset.x), ftos(gettaginfo_offset.y), ftos(gettaginfo_offset.z));
807                                         LOG_HELPF(" forward = %s %s %s", ftos(gettaginfo_forward.x), ftos(gettaginfo_forward.y), ftos(gettaginfo_forward.z));
808                                         LOG_HELPF(" right = %s %s %s", ftos(gettaginfo_right.x), ftos(gettaginfo_right.y), ftos(gettaginfo_right.z));
809                                         LOG_HELPF(" up = %s %s %s", ftos(gettaginfo_up.x), ftos(gettaginfo_up.y), ftos(gettaginfo_up.z));
810                                         if (argc >= 6)
811                                         {
812                                                 v.y = -v.y;
813                                                 localcmd(strcat(argv(4), vtos(v), argv(5), "\n"));
814                                         }
815                                 }
816                                 else
817                                 {
818                                         LOG_INFO("bone not found");
819                                 }
820
821                                 delete(tmp_entity);
822                                 return;
823                         }
824                 }
825
826                 default:
827                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
828                 case CMD_REQUEST_USAGE:
829                 {
830                         LOG_HELP("Usage:^3 sv_cmd gettaginfo <model> <frame> <index> [<command1>] [<command2>]");
831                         LOG_HELP("See also: ^2bbox, trace^7");
832                         return;
833                 }
834         }
835 }
836
837 void GameCommand_animbench(int request, int argc)
838 {
839         switch (request)
840         {
841                 case CMD_REQUEST_COMMAND:
842                 {
843                         entity tmp_entity;
844
845                         if (argc >= 4)
846                         {
847                                 tmp_entity = spawn();
848                                 if (argv(1) == "w")
849                                 {
850                                         .entity weaponentity = weaponentities[0];
851                                         _setmodel(tmp_entity, (nextent(NULL)).(weaponentity).model);
852                                 }
853                                 else
854                                 {
855                                         precache_model(argv(1));
856                                         _setmodel(tmp_entity, argv(1));
857                                 }
858                                 float f1 = stof(argv(2));
859                                 float f2 = stof(argv(3));
860                                 float t0;
861                                 float t1 = 0;
862                                 float t2 = 0;
863                                 float n = 0;
864
865                                 while (t1 + t2 < 1)
866                                 {
867                                         tmp_entity.frame = f1;
868                                         t0 = gettime(GETTIME_HIRES);
869                                         getsurfacepoint(tmp_entity, 0, 0);
870                                         t1 += gettime(GETTIME_HIRES) - t0;
871                                         tmp_entity.frame = f2;
872                                         t0 = gettime(GETTIME_HIRES);
873                                         getsurfacepoint(tmp_entity, 0, 0);
874                                         t2 += gettime(GETTIME_HIRES) - t0;
875                                         n += 1;
876                                 }
877                                 LOG_INFO("model ", tmp_entity.model, " frame ", ftos(f1), " animtime ", ftos(n / t1), "/s");
878                                 LOG_INFO("model ", tmp_entity.model, " frame ", ftos(f2), " animtime ", ftos(n / t2), "/s");
879
880                                 delete(tmp_entity);
881                                 return;
882                         }
883                 }
884
885                 default:
886                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
887                 case CMD_REQUEST_USAGE:
888                 {
889                         LOG_HELP("Usage:^3 sv_cmd animbench <model> <frame1> <frame2>");
890                         LOG_HELP("See also: ^2bbox, trace^7");
891                         return;
892                 }
893         }
894 }
895
896 void GameCommand_gotomap(int request, int argc)
897 {
898         switch (request)
899         {
900                 case CMD_REQUEST_COMMAND:
901                 {
902                         if (!world_initialized)
903                         {
904                                 LOG_INFOF("This command works only when the server is running.");
905                                 return;
906                         }
907                         if (argv(1))
908                         {
909                                 LOG_INFO(GotoMap(argv(1)));
910                                 return;
911                         }
912                 }
913
914                 default:
915                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
916                 case CMD_REQUEST_USAGE:
917                 {
918                         LOG_HELP("Usage:^3 sv_cmd gotomap <map>");
919                         LOG_HELP("  Where <map> is the *.bsp file to change to.");
920                         LOG_HELP("See also: ^2gametype^7");
921                         return;
922                 }
923         }
924 }
925
926 void GameCommand_lockteams(int request)
927 {
928         switch (request)
929         {
930                 case CMD_REQUEST_COMMAND:
931                 {
932                         if (teamplay)
933                         {
934                                 lockteams = 1;
935                                 bprint("^1The teams are now locked.\n");
936                         }
937                         else
938                         {
939                                 bprint("lockteams command can only be used in a team-based gamemode.\n");
940                         }
941                         return;
942                 }
943
944                 default:
945                 case CMD_REQUEST_USAGE:
946                 {
947                         LOG_HELP("Usage:^3 sv_cmd lockteams");
948                         LOG_HELP("  No arguments required.");
949                         LOG_HELP("See also: ^2unlockteams^7");
950                         return;
951                 }
952         }
953 }
954
955 void GameCommand_make_mapinfo(int request)
956 {
957         switch (request)
958         {
959                 case CMD_REQUEST_COMMAND:
960                 {
961                         entity tmp_entity;
962
963                         tmp_entity = new(make_mapinfo);
964                         setthink(tmp_entity, make_mapinfo_Think);
965                         tmp_entity.nextthink = time;
966                         MapInfo_Enumerate();
967                         return;
968                 }
969
970                 default:
971                 case CMD_REQUEST_USAGE:
972                 {
973                         LOG_HELP("Usage:^3 sv_cmd make_mapinfo");
974                         LOG_HELP("  No arguments required.");
975                         LOG_HELP("See also: ^2radarmap^7");
976                         return;
977                 }
978         }
979 }
980
981 void GameCommand_moveplayer(int request, int argc)
982 {
983         switch (request)
984         {
985                 case CMD_REQUEST_COMMAND:
986                 {
987                         float accepted;
988                         entity client;
989
990                         string targets = strreplace(",", " ", argv(1));
991                         string original_targets = strreplace(" ", ", ", targets);
992                         string destination = argv(2);
993                         if (destination == "spec")
994                                 destination = "spectator";
995
996                         if ((targets) && (destination))
997                         {
998                                 string successful = string_null;
999                                 string t;
1000                                 for ( ; targets; )
1001                                 {
1002                                         t = car(targets);
1003                                         targets = cdr(targets);
1004
1005                                         // Check to see if the player is a valid target
1006                                         client = GetFilteredEntity(t);
1007                                         accepted = VerifyClientEntity(client, false, false);
1008
1009                                         if (accepted <= 0)
1010                                         {
1011                                                 LOG_INFO("moveplayer: ", GetClientErrorString(accepted, t), ".");
1012                                         }
1013                                         else if (destination == "spectator")
1014                                         {
1015                                                 string pl_name = playername(client.netname, client.team, false);
1016                                                 if (!IS_SPEC(client) && !IS_OBSERVER(client))
1017                                                 {
1018                                                         PutObserverInServer(client, true);
1019
1020                                                         successful = strcat(successful, (successful ? ", " : ""), pl_name);
1021                                                 }
1022                                                 else
1023                                                 {
1024                                                         LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", pl_name, ") is already spectating.");
1025                                                 }
1026                                         }
1027                                         else
1028                                         {
1029                                                 if (!teamplay)
1030                                                 {
1031                                                         LOG_INFO("Can't change teams when currently not playing a team game.");
1032                                                         return;
1033                                                 }
1034
1035                                                 string pl_name = playername(client.netname, client.team, false);
1036                                                 if (IS_SPEC(client) || IS_OBSERVER(client))
1037                                                 {
1038                                                         // well technically we could, but should we allow that? :P
1039                                                         LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", pl_name, ") is not in the game.");
1040                                                         continue;
1041                                                 }
1042
1043                                                 // set up
1044                                                 int save = Player_GetForcedTeamIndex(client);
1045                                                 Player_SetForcedTeamIndex(client, TEAM_FORCE_DEFAULT);
1046
1047                                                 // find the team to move the player to
1048                                                 int team_num = Team_ColorToTeam(destination);
1049                                                 entity balance;
1050                                                 if (team_num == client.team)  // already on the destination team
1051                                                 {
1052                                                         // keep the forcing undone
1053                                                         LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", pl_name, ") is already on the ", Team_ColoredFullName(team_num), ".");
1054                                                         continue;
1055                                                 }
1056                                                 else if (team_num == 0)  // auto team
1057                                                 {
1058                                                         balance = TeamBalance_CheckAllowedTeams(client);
1059                                                         team_num = Team_IndexToTeam(TeamBalance_FindBestTeam(balance, client, false));
1060                                                 }
1061                                                 else
1062                                                 {
1063                                                         balance = TeamBalance_CheckAllowedTeams(client);
1064                                                 }
1065                                                 Player_SetForcedTeamIndex(client, save);
1066
1067                                                 // Check to see if the destination team is even available
1068                                                 int team_id = Team_TeamToIndex(team_num);
1069                                                 if (team_id == -1)
1070                                                 {
1071                                                         LOG_INFO("Sorry, can't move player here if team ", destination, " doesn't exist.");
1072                                                         TeamBalance_Destroy(balance);
1073                                                         return;
1074                                                 }
1075                                                 if (!TeamBalance_IsTeamAllowed(balance, team_id))
1076                                                 {
1077                                                         LOG_INFOF("Sorry, can't move player to %s team if it doesn't exist.", destination);
1078                                                         TeamBalance_Destroy(balance);
1079                                                         return;
1080                                                 }
1081                                                 TeamBalance_Destroy(balance);
1082
1083                                                 // If so, lets continue and finally move the player
1084                                                 Player_SetForcedTeamIndex(client, TEAM_FORCE_DEFAULT);
1085                                                 if (MoveToTeam(client, team_id, 6))
1086                                                 {
1087                                                         successful = strcat(successful, (successful ? ", " : ""), pl_name);
1088                                                         LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", pl_name, ") has been moved to the ", Team_ColoredFullName(team_num), "^7.");
1089                                                 }
1090                                                 else
1091                                                 {
1092                                                         LOG_INFO("Unable to move player ", ftos(GetFilteredNumber(t)), " (", pl_name, ")");
1093                                                 }
1094                                         }
1095                                 } // loop end
1096
1097                                 if (successful) bprint("Successfully moved players ", successful, " to destination ", destination, ".\n");
1098                                 else LOG_INFO("No players given (", original_targets, ") are able to move.");
1099
1100                                 return;  // still correct parameters so return to avoid usage print
1101                         }
1102                 }
1103
1104                 default:
1105                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
1106                 case CMD_REQUEST_USAGE:
1107                 {
1108                         LOG_HELP("Usage:^3 sv_cmd moveplayer <clients> <destination>");
1109                         LOG_HELP("  <clients> is a list (separated by commas) of player entity ID's or nicknames");
1110                         LOG_HELP("  <destination> is what to send the player to, be it team or spectating");
1111                         LOG_HELP("  Full list of destinations here: spec, spectator, red, blue, yellow, pink, auto.");
1112                         LOG_HELP("Examples: sv_cmd moveplayer 1,3,5 red");
1113                         LOG_HELP("          sv_cmd moveplayer 2 spec");
1114                         LOG_HELP("See also: ^2allspec, shuffleteams^7");
1115                         return;
1116                 }
1117         }
1118 }
1119
1120 void GameCommand_nospectators(int request)
1121 {
1122         switch (request)
1123         {
1124                 case CMD_REQUEST_COMMAND:
1125                 {
1126                         blockSpectators = 1;
1127                         // give every spectator <g_maxplayers_spectator_blocktime> seconds time to become a player
1128                         FOREACH_CLIENT(IS_REAL_CLIENT(it) && (IS_SPEC(it) || IS_OBSERVER(it)) && !it.caplayer, {
1129                                 if(!it.caplayer)
1130                                 {
1131                                         CS(it).spectatortime = time;
1132                                         Send_Notification(NOTIF_ONE_ONLY, it, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
1133                                 }
1134                         });
1135                         bprint(strcat("^7All spectators will be automatically kicked when not joining the game after ", ftos(autocvar_g_maxplayers_spectator_blocktime), " seconds!\n"));
1136                         return;
1137                 }
1138
1139                 default:
1140                 case CMD_REQUEST_USAGE:
1141                 {
1142                         LOG_HELP("Usage:^3 sv_cmd nospectators");
1143                         LOG_HELP("  No arguments required.");
1144                         return;
1145                 }
1146         }
1147 }
1148
1149 void GameCommand_printstats(int request)
1150 {
1151         switch (request)
1152         {
1153                 case CMD_REQUEST_COMMAND:
1154                 {
1155                         DumpStats(false);
1156                         LOG_INFO("stats dumped.");
1157                         return;
1158                 }
1159
1160                 default:
1161                 case CMD_REQUEST_USAGE:
1162                 {
1163                         LOG_HELP("Usage:^3 sv_cmd printstats");
1164                         LOG_HELP("  No arguments required.");
1165                         return;
1166                 }
1167         }
1168 }
1169
1170 void GameCommand_radarmap(int request, int argc)
1171 {
1172         switch (request)
1173         {
1174                 case CMD_REQUEST_COMMAND:
1175                 {
1176                         if (RadarMap_Make(argc)) return;
1177                 }
1178
1179                 default:
1180                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
1181                 case CMD_REQUEST_USAGE:
1182                 {
1183                         LOG_HELP("Usage:^3 sv_cmd radarmap [--force] [--loop] [--quit] [--block | --trace | --sample | --lineblock] [--sharpen N] [--res W H] [--qual Q]");
1184                         LOG_HELP("  The quality factor Q is roughly proportional to the time taken.");
1185                         LOG_HELP("  trace supports no quality factor; its result should look like --block with infinite quality factor.");
1186                         LOG_HELP("See also: ^2make_mapinfo^7");
1187                         return;
1188                 }
1189         }
1190 }
1191
1192 void GameCommand_reducematchtime(int request)
1193 {
1194         switch (request)
1195         {
1196                 case CMD_REQUEST_COMMAND:
1197                 {
1198                         changematchtime(autocvar_timelimit_decrement * -60, autocvar_timelimit_min * 60, autocvar_timelimit_max * 60);
1199                         return;
1200                 }
1201
1202                 default:
1203                 case CMD_REQUEST_USAGE:
1204                 {
1205                         LOG_HELP("Usage:^3 sv_cmd reducematchtime");
1206                         LOG_HELP("  No arguments required.");
1207                         LOG_HELP("See also: ^2extendmatchtime^7");
1208                         return;
1209                 }
1210         }
1211 }
1212
1213 void GameCommand_setbots(int request, int argc)
1214 {
1215         switch (request)
1216         {
1217                 case CMD_REQUEST_COMMAND:
1218                 {
1219                         if (argc >= 2)
1220                         {
1221                                 cvar_settemp("minplayers", "0");
1222                                 cvar_settemp("minplayers_per_team", "0");
1223                                 cvar_settemp("bot_number", argv(1));
1224                                 bot_fixcount();
1225                                 return;
1226                         }
1227                 }
1228
1229                 default:
1230                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
1231                 case CMD_REQUEST_USAGE:
1232                 {
1233                         LOG_HELP("Usage:^3 sv_cmd setbots <botnumber>");
1234                         LOG_HELP("  Where <botnumber> is the amount of bots to set bot_number cvar to.");
1235                         LOG_HELP("See also: ^2bot_cmd^7");
1236                         return;
1237                 }
1238         }
1239 }
1240
1241 void shuffleteams()
1242 {
1243         if (!teamplay)
1244         {
1245                 LOG_INFO("Can't shuffle teams when currently not playing a team game.");
1246                 return;
1247         }
1248
1249         FOREACH_CLIENT(IS_PLAYER(it) || it.caplayer, {
1250                 if (Player_HasRealForcedTeam(it)) {
1251                         // we could theoretically assign forced players to their teams
1252                         // and shuffle the rest to fill the empty spots but in practise
1253                         // either all players or none are gonna have forced teams
1254                         LOG_INFO("Can't shuffle teams because at least one player has a forced team.");
1255                         return;
1256                 }
1257         });
1258
1259         int number_of_teams = 0;
1260         entity balance = TeamBalance_CheckAllowedTeams(NULL);
1261         for (int i = 1; i <= NUM_TEAMS; ++i)
1262         {
1263                 if (TeamBalance_IsTeamAllowed(balance, i))
1264                 {
1265                         number_of_teams = max(i, number_of_teams);
1266                 }
1267         }
1268         TeamBalance_Destroy(balance);
1269
1270         int team_index = 0;
1271         FOREACH_CLIENT_RANDOM(IS_PLAYER(it) || it.caplayer, {
1272                 int target_team_index = team_index + 1;
1273                 if (Entity_GetTeamIndex(it) != target_team_index)
1274                 {
1275                         MoveToTeam(it, target_team_index, 6);
1276                 }
1277                 team_index = (team_index + 1) % number_of_teams;
1278         });
1279
1280         bprint("Successfully shuffled the players around randomly.\n");
1281 }
1282
1283 void GameCommand_shuffleteams(int request)
1284 {
1285         switch (request)
1286         {
1287                 case CMD_REQUEST_COMMAND:
1288                 {
1289                         if (shuffleteams_on_reset_map)
1290                         {
1291                                 bprint("Players will be shuffled when this round is over.\n");
1292                                 shuffleteams_on_reset_map = true;
1293                         }
1294                         else
1295                                 shuffleteams();
1296                         return;
1297                 }
1298
1299                 default:
1300                 case CMD_REQUEST_USAGE:
1301                 {
1302                         LOG_HELP("Usage:^3 sv_cmd shuffleteams");
1303                         LOG_HELP("  No arguments required.");
1304                         LOG_HELP("See also: ^2moveplayer, allspec^7");
1305                         return;
1306                 }
1307         }
1308 }
1309
1310 void GameCommand_reset(int request)
1311 {
1312         switch (request)
1313         {
1314                 case CMD_REQUEST_COMMAND:
1315                 {
1316                         warmup_stage = cvar("g_warmup");
1317                         ReadyRestart();
1318                         return;
1319                 }
1320
1321                 default:
1322                 case CMD_REQUEST_USAGE:
1323                 {
1324                         LOG_HELP("Usage:^3 sv_cmd reset");
1325                         LOG_HELP("  No arguments required.");
1326                         return;
1327                 }
1328         }
1329 }
1330
1331 void GameCommand_stuffto(int request, int argc)
1332 {
1333         // This... is a fairly dangerous and powerful command... - It allows any arguments to be sent to a client via rcon.
1334         // Because of this, it is disabled by default and must be enabled by the server owner when doing compilation. That way,
1335         // we can be certain they understand the risks of it... So to enable, compile server with -DSTUFFTO_ENABLED argument.
1336
1337 #ifdef STUFFTO_ENABLED
1338                 switch (request)
1339                 {
1340                         case CMD_REQUEST_COMMAND:
1341                         {
1342                                 if (argv(2))
1343                                 {
1344                                         entity client = GetIndexedEntity(argc, 1);
1345                                         float accepted = VerifyClientEntity(client, true, false);
1346
1347                                         if (accepted > 0)
1348                                         {
1349                                                 stuffcmd(client, strcat("\n", argv(next_token), "\n"));
1350                                                 LOG_INFO("Command: \"", argv(next_token), "\" sent to ", GetCallerName(client), " (", argv(1), ").");
1351                                         }
1352                                         else
1353                                         {
1354                                                 LOG_INFO("stuffto: ", GetClientErrorString(accepted, argv(1)), ".");
1355                                         }
1356
1357                                         return;
1358                                 }
1359                         }
1360
1361                         default:
1362                                 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
1363                         case CMD_REQUEST_USAGE:
1364                         {
1365                                 LOG_HELP("Usage:^3 sv_cmd stuffto <client> \"<command>\"");
1366                                 LOG_HELP("  <client> is the entity number or name of the player,");
1367                                 LOG_HELP("  and <command> is the command to be sent to that player.");
1368                                 return;
1369                         }
1370                 }
1371 #else
1372                 if (request)
1373                 {
1374                         LOG_HELP("stuffto command is not enabled on this server.");
1375                         return;
1376                 }
1377 #endif
1378 }
1379
1380 void GameCommand_trace(int request, int argc)
1381 {
1382         switch (request)
1383         {
1384                 case CMD_REQUEST_COMMAND:
1385                 {
1386                         entity e;
1387                         vector org, delta, start, end, p, q, q0, pos, vv, dv;
1388                         float i, f, safe, unsafe, dq, dqf;
1389
1390                         switch (argv(1))
1391                         {
1392                                 case "debug":
1393                                 {
1394                                         float hitcount = 0;
1395                                         LOG_INFO("TEST CASE. If this returns the runaway loop counter error, possibly everything is oaky.");
1396                                         float worst_endpos_bug = 0;
1397                                         for ( ; ; )
1398                                         {
1399                                                 org = world.mins;
1400                                                 delta = world.maxs - world.mins;
1401
1402                                                 start.x = org.x + random() * delta.x;
1403                                                 start.y = org.y + random() * delta.y;
1404                                                 start.z = org.z + random() * delta.z;
1405
1406                                                 end.x = org.x + random() * delta.x;
1407                                                 end.y = org.y + random() * delta.y;
1408                                                 end.z = org.z + random() * delta.z;
1409
1410                                                 start = stov(vtos(start));
1411                                                 end = stov(vtos(end));
1412
1413                                                 tracebox(start, PL_MIN_CONST, PL_MAX_CONST, end, MOVE_NOMONSTERS, NULL);
1414                                                 if (!trace_startsolid && trace_fraction < 1)
1415                                                 {
1416                                                         p = trace_endpos;
1417                                                         tracebox(p, PL_MIN_CONST, PL_MAX_CONST, p, MOVE_NOMONSTERS, NULL);
1418                                                         if (trace_startsolid)
1419                                                         {
1420                                                                 rint(42);  // do an engine breakpoint on VM_rint so you can get the trace that errnoeously returns startsolid
1421                                                                 tracebox(start, PL_MIN_CONST, PL_MAX_CONST, end, MOVE_NOMONSTERS, NULL);
1422
1423                                                                 // how much do we need to back off?
1424                                                                 safe = 1;
1425                                                                 unsafe = 0;
1426                                                                 for ( ; ; )
1427                                                                 {
1428                                                                         pos = p * (1 - (safe + unsafe) * 0.5) + start * ((safe + unsafe) * 0.5);
1429                                                                         tracebox(pos, PL_MIN_CONST, PL_MAX_CONST, pos, MOVE_NOMONSTERS, NULL);
1430                                                                         if (trace_startsolid)
1431                                                                         {
1432                                                                                 if ((safe + unsafe) * 0.5 == unsafe) break;
1433                                                                                 unsafe = (safe + unsafe) * 0.5;
1434                                                                         }
1435                                                                         else
1436                                                                         {
1437                                                                                 if ((safe + unsafe) * 0.5 == safe) break;
1438                                                                                 safe = (safe + unsafe) * 0.5;
1439                                                                         }
1440                                                                 }
1441
1442                                                                 LOG_INFO("safe distance to back off: ", ftos(safe * vlen(p - start)), "qu");
1443                                                                 LOG_INFO("unsafe distance to back off: ", ftos(unsafe * vlen(p - start)), "qu");
1444
1445                                                                 tracebox(p, PL_MIN_CONST + '0.1 0.1 0.1', PL_MAX_CONST - '0.1 0.1 0.1', p, MOVE_NOMONSTERS, NULL);
1446                                                                 if (trace_startsolid) LOG_INFO("trace_endpos much in solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p));
1447                                                                 else LOG_INFO("trace_endpos just in solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p));
1448                                                                 if (++hitcount >= 10) break;
1449                                                         }
1450                                                         else
1451                                                         {
1452                                                                 q0 = p;
1453                                                                 dq = 0;
1454                                                                 dqf = 1;
1455                                                                 for ( ; ; )
1456                                                                 {
1457                                                                         q = p + normalize(end - p) * (dq + dqf);
1458                                                                         if (q == q0) break;
1459                                                                         tracebox(p, PL_MIN_CONST, PL_MAX_CONST, q, MOVE_NOMONSTERS, NULL);
1460                                                                         if (trace_startsolid) error("THIS ONE cannot happen");
1461                                                                         if (trace_fraction > 0) dq += dqf * trace_fraction;
1462                                                                         dqf *= 0.5;
1463                                                                         q0 = q;
1464                                                                 }
1465                                                                 if (dq > worst_endpos_bug)
1466                                                                 {
1467                                                                         worst_endpos_bug = dq;
1468                                                                         LOG_INFO("trace_endpos still before solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p));
1469                                                                         LOG_INFO("could go ", ftos(dq), " units further to ", vtos(q));
1470                                                                         if (++hitcount >= 10) break;
1471                                                                 }
1472                                                         }
1473                                                 }
1474                                         }
1475                                         return;
1476                                 }
1477
1478                                 case "debug2":
1479                                 {
1480                                         e = nextent(NULL);
1481                                         tracebox(e.origin + '0 0 32', e.mins, e.maxs, e.origin + '0 0 -1024', MOVE_NORMAL, e);
1482                                         vv = trace_endpos;
1483                                         if (trace_fraction == 1)
1484                                         {
1485                                                 LOG_INFO("not above ground, aborting");
1486                                                 return;
1487                                         }
1488                                         f = 0;
1489                                         for (i = 0; i < 100000; ++i)
1490                                         {
1491                                                 dv = randomvec();
1492                                                 if (dv.z > 0) dv = -1 * dv;
1493                                                 tracebox(vv, e.mins, e.maxs, vv + dv, MOVE_NORMAL, e);
1494                                                 if (trace_startsolid) LOG_INFO("bug 1");
1495                                                 if (trace_fraction == 1)
1496                                                 {
1497                                                         if (dv.z < f)
1498                                                         {
1499                                                                 LOG_INFO("bug 2: ", ftos(dv.x), " ", ftos(dv.y), " ", ftos(dv.z));
1500                                                                 LOG_INFO(" (", ftos(asin(dv.z / vlen(dv)) * 180 / M_PI), " degrees)");
1501                                                                 f = dv.z;
1502                                                         }
1503                                                 }
1504                                         }
1505                                         LOG_INFO("highest possible dist: ", ftos(f));
1506                                         return;
1507                                 }
1508
1509                                 case "walk":
1510                                 {
1511                                         if (argc == 4 || argc == 5)
1512                                         {
1513                                                 e = nextent(NULL);
1514                                                 int dphitcontentsmask_save = e.dphitcontentsmask;
1515                                                 e.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
1516                                                 if (tracewalk(e, stov(argv(2)), e.mins, e.maxs, stov(argv(3)), stof(argv(4)), MOVE_NORMAL))
1517                                                         LOG_INFO("can walk");
1518                                                 else
1519                                                         LOG_INFO("cannot walk");
1520                                                 e.dphitcontentsmask = dphitcontentsmask_save;
1521                                                 return;
1522                                         }
1523                                 }
1524
1525                                 case "showline":
1526                                 {
1527                                         if (argc == 4)
1528                                         {
1529                                                 vv = stov(argv(2));
1530                                                 dv = stov(argv(3));
1531                                                 traceline(vv, dv, MOVE_NORMAL, NULL);
1532                                                 __trailparticles(NULL, particleeffectnum(EFFECT_TR_NEXUIZPLASMA), vv, trace_endpos);
1533                                                 __trailparticles(NULL, particleeffectnum(EFFECT_TR_CRYLINKPLASMA), trace_endpos, dv);
1534                                                 return;
1535                                         }
1536                                 }
1537
1538                                 // no default case, just go straight to invalid
1539                         }
1540                 }
1541
1542                 default:
1543                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
1544                 case CMD_REQUEST_USAGE:
1545                 {
1546                         LOG_HELP("Usage:^3 sv_cmd trace <command> [<startpos> <endpos>] [<endpos_height>]");
1547                         LOG_HELP("  Where <startpos> and <endpos> are parameters for the 'walk' and 'showline' commands,");
1548                         LOG_HELP("  <endpos_height> is an optional parameter for the 'walk' command,");
1549                         LOG_HELP("  Full list of commands here: debug, debug2, walk, showline.");
1550                         LOG_HELP("See also: ^2bbox, gettaginfo^7");
1551                         return;
1552                 }
1553         }
1554 }
1555
1556 void GameCommand_unlockteams(int request)
1557 {
1558         switch (request)
1559         {
1560                 case CMD_REQUEST_COMMAND:
1561                 {
1562                         if (teamplay)
1563                         {
1564                                 lockteams = 0;
1565                                 bprint("^1The teams are now unlocked.\n");
1566                         }
1567                         else
1568                         {
1569                                 bprint("unlockteams command can only be used in a team-based gamemode.\n");
1570                         }
1571                         return;
1572                 }
1573
1574                 default:
1575                 case CMD_REQUEST_USAGE:
1576                 {
1577                         LOG_HELP("Usage:^3 sv_cmd unlockteams");
1578                         LOG_HELP("  No arguments required.");
1579                         LOG_HELP("See also: ^2lockteams^7");
1580                         return;
1581                 }
1582         }
1583 }
1584
1585 void GameCommand_warp(int request, int argc)
1586 {
1587         switch (request)
1588         {
1589                 case CMD_REQUEST_COMMAND:
1590                 {
1591                         if (autocvar_g_campaign)
1592                         {
1593                                 if (argc >= 2)
1594                                 {
1595                                         CampaignLevelWarp(stof(argv(1)));
1596                                         LOG_INFO("Successfully warped to campaign level ", argv(1), ".");
1597                                 }
1598                                 else
1599                                 {
1600                                         CampaignLevelWarp(-1);
1601                                         LOG_INFO("Successfully warped to next campaign level.");
1602                                 }
1603                         }
1604                         else
1605                         {
1606                                 LOG_INFO("Not in campaign, can't level warp");
1607                         }
1608                         return;
1609                 }
1610
1611                 default:
1612                 case CMD_REQUEST_USAGE:
1613                 {
1614                         LOG_HELP("Usage:^3 sv_cmd warp [<level>]");
1615                         LOG_HELP("  <level> is the level to change campaign mode to.");
1616                         LOG_HELP("  if <level> is not provided it will change to the next level.");
1617                         return;
1618                 }
1619         }
1620 }
1621
1622 /* use this when creating a new command, making sure to place it in alphabetical order... also,
1623 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
1624 void GameCommand_(int request)
1625 {
1626     switch(request)
1627     {
1628         case CMD_REQUEST_COMMAND:
1629         {
1630
1631             return;
1632         }
1633
1634         default:
1635         case CMD_REQUEST_USAGE:
1636         {
1637             LOG_HELP("Usage:^3 sv_cmd ");
1638             LOG_HELP("  No arguments required.");
1639             return;
1640         }
1641     }
1642 }
1643 */
1644
1645
1646 // ==================================
1647 //  Macro system for server commands
1648 // ==================================
1649
1650 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
1651 SERVER_COMMAND(adminmsg, "Send an admin message to a client directly") { GameCommand_adminmsg(request, arguments); }
1652 SERVER_COMMAND(allready, "Ends warmup and starts the match") { GameCommand_allready(request); }
1653 SERVER_COMMAND(allspec, "Force all players to spectate") { GameCommand_allspec(request, arguments); }
1654 SERVER_COMMAND(anticheat, "Create an anticheat report for a client") { GameCommand_anticheat(request, arguments); }
1655 SERVER_COMMAND(animbench, "Benchmark model animation (LAGS)") { GameCommand_animbench(request, arguments); }
1656 SERVER_COMMAND(bbox, "Print detailed information about world size") { GameCommand_bbox(request); }
1657 SERVER_COMMAND(bot_cmd, "Control and send commands to bots") { GameCommand_bot_cmd(request, arguments, command); }
1658 SERVER_COMMAND(cointoss, "Flip a virtual coin and give random result") { GameCommand_cointoss(request, arguments); }
1659 SERVER_COMMAND(database, "Extra controls of the serverprogs database") { GameCommand_database(request, arguments); }
1660 SERVER_COMMAND(defer_clear, "Clear all queued defer commands for a specific client") { GameCommand_defer_clear(request, arguments); }
1661 SERVER_COMMAND(defer_clear_all, "Clear all queued defer commands for all clients") { GameCommand_defer_clear_all(request); }
1662 SERVER_COMMAND(delrec, "Delete race time record for a map") { GameCommand_delrec(request, arguments); }
1663 SERVER_COMMAND(effectindexdump, "Dump list of effects from code and effectinfo.txt") { GameCommand_effectindexdump(request); }
1664 SERVER_COMMAND(extendmatchtime, "Increase the timelimit value incrementally") { GameCommand_extendmatchtime(request); }
1665 SERVER_COMMAND(gametype, "Simple command to change the active gametype") { GameCommand_gametype(request, arguments); }
1666 SERVER_COMMAND(gettaginfo, "Get specific information about a weapon model") { GameCommand_gettaginfo(request, arguments); }
1667 SERVER_COMMAND(gotomap, "Simple command to switch to another map") { GameCommand_gotomap(request, arguments); }
1668 SERVER_COMMAND(lockteams, "Disable the ability for players to switch or enter teams") { GameCommand_lockteams(request); }
1669 SERVER_COMMAND(make_mapinfo, "Automatically rebuild mapinfo files") { GameCommand_make_mapinfo(request); }
1670 SERVER_COMMAND(moveplayer, "Change the team/status of a player") { GameCommand_moveplayer(request, arguments); }
1671 SERVER_COMMAND(nospectators, "Automatically remove spectators from a match") { GameCommand_nospectators(request); }
1672 SERVER_COMMAND(printstats, "Dump eventlog player stats and other score information") { GameCommand_printstats(request); }
1673 SERVER_COMMAND(radarmap, "Generate a radar image of the map") { GameCommand_radarmap(request, arguments); }
1674 SERVER_COMMAND(reducematchtime, "Decrease the timelimit value incrementally") { GameCommand_reducematchtime(request); }
1675 SERVER_COMMAND(reset, "Soft restart the server and reset the players") { GameCommand_reset(request); }
1676 SERVER_COMMAND(setbots, "Adjust how many bots are in the match") { GameCommand_setbots(request, arguments); }
1677 SERVER_COMMAND(shuffleteams, "Randomly move players to different teams") { GameCommand_shuffleteams(request); }
1678 SERVER_COMMAND(stuffto, "Send a command to be executed on a client") { GameCommand_stuffto(request, arguments); }
1679 SERVER_COMMAND(trace, "Various debugging tools with tracing") { GameCommand_trace(request, arguments); }
1680 SERVER_COMMAND(unlockteams, "Enable the ability for players to switch or enter teams") { GameCommand_unlockteams(request); }
1681 SERVER_COMMAND(warp, "Choose different level in campaign") { GameCommand_warp(request, arguments); }
1682
1683 void GameCommand_macro_help()
1684 {
1685         FOREACH(SERVER_COMMANDS, true, { LOG_HELPF("  ^2%s^7: %s", it.m_name, it.m_description); });
1686 }
1687
1688 float GameCommand_macro_command(int argc, string command)
1689 {
1690         string c = strtolower(argv(0));
1691         FOREACH(SERVER_COMMANDS, it.m_name == c, {
1692                 it.m_invokecmd(it, CMD_REQUEST_COMMAND, NULL, argc, command);
1693                 return true;
1694         });
1695         return false;
1696 }
1697
1698 float GameCommand_macro_usage(int argc)
1699 {
1700         string c = strtolower(argv(1));
1701         FOREACH(SERVER_COMMANDS, it.m_name == c, {
1702                 it.m_invokecmd(it, CMD_REQUEST_USAGE, NULL, argc, "");
1703                 return true;
1704         });
1705         return false;
1706 }
1707
1708 void GameCommand_macro_write_aliases(float fh)
1709 {
1710         FOREACH(SERVER_COMMANDS, true, { CMD_Write_Alias("qc_cmd_sv", it.m_name, it.m_description); });
1711 }
1712
1713
1714 // =========================================
1715 //  Main Function Called By Engine (sv_cmd)
1716 // =========================================
1717 // If this function exists, game code handles gamecommand instead of the engine code.
1718
1719 void GameCommand(string command)
1720 {
1721         int argc = tokenize_console(command);
1722
1723         // Guide for working with argc arguments by example:
1724         // argc:   1    - 2      - 3     - 4
1725         // argv:   0    - 1      - 2     - 3
1726         // cmd     vote - master - login - password
1727
1728         if (strtolower(argv(0)) == "help")
1729         {
1730                 if (argc == 1)
1731                 {
1732                         LOG_HELP("Server console commands:");
1733                         GameCommand_macro_help();
1734
1735                         LOG_HELP("\nBanning commands:");
1736                         BanCommand_macro_help();
1737
1738                         LOG_HELP("\nCommon networked commands:");
1739                         CommonCommand_macro_help(NULL);
1740
1741                         LOG_HELP("\nGeneric commands shared by all programs:");
1742                         GenericCommand_macro_help();
1743
1744                         LOG_HELP("\nUsage:^3 sv_cmd <command>^7, where possible commands are listed above.\n"
1745                                 "For help about a specific command, type sv_cmd help <command>");
1746
1747                         return;
1748                 }
1749                 else if (BanCommand_macro_usage(argc))  // Instead of trying to call a command, we're going to see detailed information about it
1750                 {
1751                         return;
1752                 }
1753                 else if (CommonCommand_macro_usage(argc, NULL))  // same here, but for common commands instead
1754                 {
1755                         return;
1756                 }
1757                 else if (GenericCommand_macro_usage(argc))  // same here, but for generic commands instead
1758                 {
1759                         return;
1760                 }
1761                 else if (GameCommand_macro_usage(argc))  // finally try for normal commands too
1762                 {
1763                         return;
1764                 }
1765         }
1766         else if (MUTATOR_CALLHOOK(SV_ParseServerCommand, strtolower(argv(0)), argc, command))
1767         {
1768                 return;  // handled by a mutator
1769         }
1770         else if (BanCommand(command))
1771         {
1772                 return;  // handled by server/command/ipban.qc
1773         }
1774         else if (CommonCommand_macro_command(argc, NULL, command))
1775         {
1776                 return;  // handled by server/command/common.qc
1777         }
1778         else if (GenericCommand(command))
1779         {
1780                 return;                                        // handled by common/command/generic.qc
1781         }
1782         else if (GameCommand_macro_command(argc, command)) // continue as usual and scan for normal commands
1783         {
1784                 return;                                        // handled by one of the above GameCommand_* functions
1785         }
1786
1787         // nothing above caught the command, must be invalid
1788         LOG_INFO(((command != "") ? strcat("Unknown server command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try sv_cmd help.");
1789 }