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/scores_rules.qh>
27 #include <server/teamplay.qh>
28 #include <server/world.qh>
30 // used by GameCommand_make_mapinfo()
31 void make_mapinfo_Think(entity this)
33 if (_MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 1))
35 LOG_INFO("Done rebuiling mapinfos.");
36 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
41 setthink(this, make_mapinfo_Think);
42 this.nextthink = time;
46 // used by GameCommand_extendmatchtime() and GameCommand_reducematchtime()
47 void changematchtime(float delta, float mi, float ma)
53 if (delta == 0) return;
54 if (autocvar_timelimit < 0) return;
56 if (mi <= 10) mi = 10; // at least ten sec in the future
57 cur = time - game_starttime;
58 if (cur > 0) mi += cur; // from current time!
60 lim = autocvar_timelimit * 60;
64 if (lim == 0) return; // cannot increase any further
65 else if (lim < ma) update = min(ma, lim + delta);
66 else // already above maximum: FAIL
71 if (lim == 0) // infinite: try reducing to max, if we are allowed to
73 else if (lim > mi) // above minimum: decrease
74 update = max(mi, lim + delta);
75 else // already below minimum: FAIL
79 cvar_set("timelimit", ftos(update / 60));
83 // =======================
84 // Command Sub-Functions
85 // =======================
87 void GameCommand_adminmsg(int request, int argc)
91 case CMD_REQUEST_COMMAND:
96 string targets = strreplace(",", " ", argv(1));
97 string original_targets = strreplace(" ", ", ", targets);
98 string admin_message = argv(2);
99 float infobartime = stof(argv(3));
101 string successful, t;
102 successful = string_null;
104 if ((targets) && (admin_message))
109 targets = cdr(targets);
111 // Check to see if the player is a valid target
112 client = GetFilteredEntity(t);
113 accepted = VerifyClientEntity(client, true, false);
117 LOG_INFO("adminmsg: ", GetClientErrorString(accepted, t), (targets ? ", skipping to next player.\n" : "."));
121 // send the centerprint/console print or infomessage
124 stuffcmd(client, sprintf("\ninfobar %f \"%s\"\n", infobartime, MakeConsoleSafe(admin_message)));
128 centerprint(client, strcat("^3", GetCallerName(NULL), ":\n^7", admin_message));
129 sprint(client, strcat("\{1}\{13}^3", GetCallerName(NULL), "^7: ", admin_message, "\n"));
132 successful = strcat(successful, (successful ? ", " : ""), playername(client.netname, client.team, false));
133 LOG_TRACE("Message sent to ", playername(client.netname, client.team, false));
137 if (successful) bprint("Successfully sent message '", admin_message, "' to ", successful, ".\n");
138 else LOG_INFO("No players given (", original_targets, ") could receive the message.");
145 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
146 case CMD_REQUEST_USAGE:
148 LOG_HELP("Usage:^3 sv_cmd adminmsg <clients> \"<message>\" [<infobartime>]");
149 LOG_HELP(" <clients> is a list (separated by commas) of player entity ID's or nicknames");
150 LOG_HELP(" If <infobartime> is provided, the message will be sent to infobar.");
151 LOG_HELP(" Otherwise, it will just be sent as a centerprint message.");
152 LOG_HELP("Examples: adminmsg 2,4 \"this infomessage will last for ten seconds\" 10");
153 LOG_HELP(" adminmsg 2,5 \"this message will be a centerprint\"");
159 void GameCommand_allready(int request)
163 case CMD_REQUEST_COMMAND:
170 LOG_INFO("Not in warmup.");
176 case CMD_REQUEST_USAGE:
178 LOG_HELP("Usage:^3 sv_cmd allready");
179 LOG_HELP(" No arguments required.");
185 void GameCommand_allspec(int request, int argc)
189 case CMD_REQUEST_COMMAND:
191 string reason = argv(1);
193 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
194 PutObserverInServer(it, true);
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.");
203 case CMD_REQUEST_USAGE:
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");
213 void GameCommand_anticheat(int request, int argc)
217 case CMD_REQUEST_COMMAND:
219 entity client = GetIndexedEntity(argc, 1);
220 float accepted = VerifyClientEntity(client, false, false);
224 anticheat_report_to_eventlog(client);
229 LOG_INFO("anticheat: ", GetClientErrorString(accepted, argv(1)), ".");
234 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
235 case CMD_REQUEST_USAGE:
237 LOG_HELP("Usage:^3 sv_cmd anticheat <client>");
238 LOG_HELP(" <client> is the entity number or name of the player.");
244 void GameCommand_bbox(int request)
248 case CMD_REQUEST_COMMAND:
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,
258 size_min.x = (trace_startsolid) ? world.absmin.x : trace_endpos.x;
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,
266 size_min.y = (trace_startsolid) ? world.absmin.y : trace_endpos.y;
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,
274 size_min.z = (trace_startsolid) ? world.absmin.z : trace_endpos.z;
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,
282 size_max.x = (trace_startsolid) ? world.absmax.x : trace_endpos.x;
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,
290 size_max.y = (trace_startsolid) ? world.absmax.y : trace_endpos.y;
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,
298 size_max.z = (trace_startsolid) ? world.absmax.z : trace_endpos.z;
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);
307 case CMD_REQUEST_USAGE:
309 LOG_HELP("Usage:^3 sv_cmd bbox");
310 LOG_HELP(" No arguments required.");
311 LOG_HELP("See also: ^2gettaginfo, trace^7");
317 void GameCommand_bot_cmd(int request, int argc, string command)
321 case CMD_REQUEST_COMMAND:
325 if (argv(1) == "reset")
330 else if (argv(1) == "setbots")
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");
337 cvar_settemp("bot_number", argv(2));
338 if (!bot_fixcount()) LOG_INFO("Sorry, could not set requested bot count");
341 else if (argv(1) == "load" && argc == 3)
345 fh = fopen(argv(2), FILE_READ);
348 LOG_INFO("cannot open the file");
353 while ((s = fgets(fh)))
355 argc = tokenize_console(s);
357 if (argc >= 3 && argv(0) == "sv_cmd" && argv(1) == "bot_cmd")
359 if (argv(2) == "reset")
363 else if (argv(2) == "setbots")
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");
370 cvar_settemp("bot_number", argv(3));
371 if (!bot_fixcount()) LOG_INFO("Sorry, could not set requested bot count");
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));
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));
389 localcmd(strcat(s, "\n"));
394 LOG_INFO(ftos(i), " commands read");
398 else if (argv(1) == "help")
400 if (argv(2)) bot_cmdhelp(argv(2));
401 else bot_list_commands();
404 else if (argc >= 3) // this comes last
406 if(argv(1) == "*" || argv(1) == "all")
409 FOREACH_CLIENT(IS_BOT_CLIENT(it), {
410 bot_queuecommand(it, substring(command, argv_start_index(2), -1));
414 LOG_INFO("Command '", substring(command, argv_start_index(2), -1), "' sent to all bots (", ftos(bot_num), ")");
419 bot = find_bot_by_number(stof(argv(1)));
420 if (bot == NULL) bot = find_bot_by_name(argv(1));
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));
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
436 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
437 case CMD_REQUEST_USAGE:
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");
451 void GameCommand_cointoss(int request, int argc)
455 case CMD_REQUEST_COMMAND:
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);
461 Send_Notification(NOTIF_ALL, NULL, MSG_MULTI, MULTI_COINTOSS, choice);
466 case CMD_REQUEST_USAGE:
468 LOG_HELP("Usage:^3 sv_cmd cointoss [<result1> <result2>]");
469 LOG_HELP(" Where <result1> and <result2> are user created options.");
475 void GameCommand_database(int request, int argc)
479 case CMD_REQUEST_COMMAND:
483 if (argv(1) == "save")
485 db_save(ServerProgsDB, argv(2));
486 LOG_INFO("Copied serverprogs database to '", argv(2), "' in the data directory.");
489 else if (argv(1) == "dump")
491 db_dump(ServerProgsDB, argv(2));
492 LOG_INFO("DB dumped."); // wtf does this do?
495 else if (argv(1) == "load")
497 db_close(ServerProgsDB);
498 ServerProgsDB = db_load(argv(2));
499 LOG_INFO("Loaded '", argv(2), "' as new serverprogs database.");
506 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
507 case CMD_REQUEST_USAGE:
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.");
518 void GameCommand_defer_clear(int request, int argc)
522 case CMD_REQUEST_COMMAND:
529 client = GetIndexedEntity(argc, 1);
530 accepted = VerifyClientEntity(client, true, false);
534 stuffcmd(client, "defer clear\n");
535 LOG_INFO("defer clear stuffed to ", playername(client.netname, client.team, false));
537 else { LOG_INFO("defer_clear: ", GetClientErrorString(accepted, argv(1)), "."); }
544 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
545 case CMD_REQUEST_USAGE:
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");
555 void GameCommand_defer_clear_all(int request)
559 case CMD_REQUEST_COMMAND:
564 FOREACH_CLIENT(true, {
565 argc = tokenize_console(strcat("defer_clear ", ftos(etof(it))));
566 GameCommand_defer_clear(CMD_REQUEST_COMMAND, argc);
569 if (n) LOG_INFO("Successfully stuffed defer clear to all clients (", ftos(n), ")"); // should a message be added if no players were found?
574 case CMD_REQUEST_USAGE:
576 LOG_HELP("Usage:^3 sv_cmd defer_clear_all");
577 LOG_HELP(" No arguments required.");
578 LOG_HELP("See also: ^2defer_clear^7");
584 void GameCommand_delrec(int request, int argc) // perhaps merge later with records and printstats and such?
588 case CMD_REQUEST_COMMAND:
592 if (argv(2)) race_deleteTime(argv(2), stof(argv(1)));
593 else race_deleteTime(GetMapname(), stof(argv(1)));
599 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
600 case CMD_REQUEST_USAGE:
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.");
611 void print_Effect_Index(int d, string effect_name)
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");
618 void GameCommand_effectindexdump(int request)
622 case CMD_REQUEST_COMMAND:
628 LOG_INFO("begin of effects list");
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");
667 fh = fopen("effectinfo.txt", FILE_READ);
668 while ((s = fgets(fh)))
671 if (argv(0) == "effect")
673 if (db_get(d, argv(1)) != "1")
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");
681 LOG_INFO("end of effects list");
688 case CMD_REQUEST_USAGE:
690 LOG_HELP("Usage:^3 sv_cmd effectindexdump");
691 LOG_HELP(" No arguments required.");
697 void GameCommand_extendmatchtime(int request)
701 case CMD_REQUEST_COMMAND:
703 changematchtime(autocvar_timelimit_increment * 60, autocvar_timelimit_min * 60, autocvar_timelimit_max * 60);
708 case CMD_REQUEST_USAGE:
710 LOG_HELP("Usage:^3 sv_cmd extendmatchtime");
711 LOG_HELP(" No arguments required.");
712 LOG_HELP("See also: ^2reducematchtime^7");
718 void GameCommand_gametype(int request, int argc)
722 case CMD_REQUEST_COMMAND:
724 if (!world_initialized)
726 LOG_INFOF("This command works only when the server is running.");
732 Gametype t = MapInfo_Type_FromString(s, false), tsave = MapInfo_CurrentGametype();
736 MapInfo_SwitchGameType(t);
737 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
738 if (MapInfo_count > 0)
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");
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);
754 bprint("Failed to switch to ", s, ": this game type does not exist!\n");
762 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
763 case CMD_REQUEST_USAGE:
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");
773 void GameCommand_gettaginfo(int request, int argc)
777 case CMD_REQUEST_COMMAND:
785 tmp_entity = spawn();
788 .entity weaponentity = weaponentities[0];
789 _setmodel(tmp_entity, (nextent(NULL)).(weaponentity).model);
793 precache_model(argv(1));
794 _setmodel(tmp_entity, argv(1));
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));
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)
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));
813 localcmd(strcat(argv(4), vtos(v), argv(5), "\n"));
818 LOG_INFO("bone not found");
827 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
828 case CMD_REQUEST_USAGE:
830 LOG_HELP("Usage:^3 sv_cmd gettaginfo <model> <frame> <index> [<command1>] [<command2>]");
831 LOG_HELP("See also: ^2bbox, trace^7");
837 void GameCommand_animbench(int request, int argc)
841 case CMD_REQUEST_COMMAND:
847 tmp_entity = spawn();
850 .entity weaponentity = weaponentities[0];
851 _setmodel(tmp_entity, (nextent(NULL)).(weaponentity).model);
855 precache_model(argv(1));
856 _setmodel(tmp_entity, argv(1));
858 float f1 = stof(argv(2));
859 float f2 = stof(argv(3));
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;
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");
886 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
887 case CMD_REQUEST_USAGE:
889 LOG_HELP("Usage:^3 sv_cmd animbench <model> <frame1> <frame2>");
890 LOG_HELP("See also: ^2bbox, trace^7");
896 void GameCommand_gotomap(int request, int argc)
900 case CMD_REQUEST_COMMAND:
902 if (!world_initialized)
904 LOG_INFOF("This command works only when the server is running.");
909 LOG_INFO(GotoMap(argv(1)));
915 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
916 case CMD_REQUEST_USAGE:
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");
926 void GameCommand_lockteams(int request)
930 case CMD_REQUEST_COMMAND:
935 bprint("^1The teams are now locked.\n");
939 bprint("lockteams command can only be used in a team-based gamemode.\n");
945 case CMD_REQUEST_USAGE:
947 LOG_HELP("Usage:^3 sv_cmd lockteams");
948 LOG_HELP(" No arguments required.");
949 LOG_HELP("See also: ^2unlockteams^7");
955 void GameCommand_make_mapinfo(int request)
959 case CMD_REQUEST_COMMAND:
963 tmp_entity = new(make_mapinfo);
964 setthink(tmp_entity, make_mapinfo_Think);
965 tmp_entity.nextthink = time;
971 case CMD_REQUEST_USAGE:
973 LOG_HELP("Usage:^3 sv_cmd make_mapinfo");
974 LOG_HELP(" No arguments required.");
975 LOG_HELP("See also: ^2radarmap^7");
981 void GameCommand_moveplayer(int request, int argc)
985 case CMD_REQUEST_COMMAND:
990 string targets = strreplace(",", " ", argv(1));
991 string original_targets = strreplace(" ", ", ", targets);
992 string destination = argv(2);
993 if (destination == "spec")
994 destination = "spectator";
996 if ((targets) && (destination))
998 string successful = string_null;
1003 targets = cdr(targets);
1005 // Check to see if the player is a valid target
1006 client = GetFilteredEntity(t);
1007 accepted = VerifyClientEntity(client, false, false);
1008 string client_num_str = ftos(etof(client));
1012 LOG_INFO("moveplayer: ", GetClientErrorString(accepted, t), ".");
1014 else if (destination == "spectator")
1016 string pl_name = playername(client.netname, client.team, false);
1017 if (!IS_SPEC(client) && !IS_OBSERVER(client))
1019 PutObserverInServer(client, true);
1021 successful = strcat(successful, (successful ? ", " : ""), pl_name);
1025 LOG_INFO("Player #", client_num_str, " (", pl_name, ") is already spectating.");
1032 LOG_INFO("Can't change teams when currently not playing a team game.");
1036 string pl_name = playername(client.netname, client.team, false);
1037 if (IS_SPEC(client) || IS_OBSERVER(client))
1039 // well technically we could, but should we allow that? :P
1040 LOG_INFO("Player #", client_num_str, " (", pl_name, ") is not in the game.");
1045 int save = Player_GetForcedTeamIndex(client);
1046 Player_SetForcedTeamIndex(client, TEAM_FORCE_DEFAULT);
1048 // find the team to move the player to
1049 int team_num = Team_ColorToTeam(destination);
1051 if (team_num == client.team) // already on the destination team
1053 // keep the forcing undone
1054 LOG_INFO("Player #", client_num_str, " (", pl_name, ") is already on the ", Team_ColoredFullName(team_num), "^7.");
1057 else if (team_num == 0) // auto team
1059 balance = TeamBalance_CheckAllowedTeams(client);
1060 team_num = Team_IndexToTeam(TeamBalance_FindBestTeam(balance, client, false));
1064 balance = TeamBalance_CheckAllowedTeams(client);
1066 Player_SetForcedTeamIndex(client, save);
1068 // Check to see if the destination team is even available
1069 int team_id = Team_TeamToIndex(team_num);
1072 LOG_INFO("Can't move player to ", destination, " team because it doesn't exist.");
1073 TeamBalance_Destroy(balance);
1076 if (!IsTeamAvailable(team_num))
1078 LOG_INFO("Can't move player to ", destination, " team because it isn't available.");
1079 TeamBalance_Destroy(balance);
1082 if (!TeamBalance_IsTeamAllowed(balance, team_id))
1084 LOG_INFO("Player #", client_num_str, " (", pl_name, ") is not allowed to join the ", Team_ColoredFullName(team_num), "^7.");
1085 TeamBalance_Destroy(balance);
1088 TeamBalance_Destroy(balance);
1090 // If so, lets continue and finally move the player
1091 Player_SetForcedTeamIndex(client, TEAM_FORCE_DEFAULT);
1092 if (MoveToTeam(client, team_id, 6))
1094 successful = strcat(successful, (successful ? ", " : ""), pl_name);
1095 LOG_INFO("Player #", client_num_str, " (", pl_name, ") has been moved to the ", Team_ColoredFullName(team_num), "^7.");
1099 LOG_INFO("Unable to move player #", client_num_str, " (", pl_name, ")");
1104 if (successful) bprint("Successfully moved players ", successful, " to destination ", destination, ".\n");
1105 else LOG_INFO("No players given (", original_targets, ") are able to move.");
1107 return; // still correct parameters so return to avoid usage print
1112 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
1113 case CMD_REQUEST_USAGE:
1115 LOG_HELP("Usage:^3 sv_cmd moveplayer <clients> <destination>");
1116 LOG_HELP(" <clients> is a list (separated by commas) of player entity ID's or nicknames");
1117 LOG_HELP(" <destination> is what to send the player to, be it team or spectating");
1118 LOG_HELP(" Full list of destinations here: spec, spectator, red, blue, yellow, pink, auto.");
1119 LOG_HELP("Examples: sv_cmd moveplayer 1,3,5 red");
1120 LOG_HELP(" sv_cmd moveplayer 2 spec");
1121 LOG_HELP("See also: ^2allspec, shuffleteams^7");
1127 void GameCommand_nospectators(int request)
1131 case CMD_REQUEST_COMMAND:
1133 blockSpectators = 1;
1134 // give every spectator <g_maxplayers_spectator_blocktime> seconds time to become a player
1135 FOREACH_CLIENT(IS_REAL_CLIENT(it) && (IS_SPEC(it) || IS_OBSERVER(it)) && !it.caplayer, {
1138 CS(it).spectatortime = time;
1139 Send_Notification(NOTIF_ONE_ONLY, it, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
1142 bprint(strcat("^7All spectators will be automatically kicked when not joining the game after ", ftos(autocvar_g_maxplayers_spectator_blocktime), " seconds!\n"));
1147 case CMD_REQUEST_USAGE:
1149 LOG_HELP("Usage:^3 sv_cmd nospectators");
1150 LOG_HELP(" No arguments required.");
1156 void GameCommand_printstats(int request)
1160 case CMD_REQUEST_COMMAND:
1163 LOG_INFO("stats dumped.");
1168 case CMD_REQUEST_USAGE:
1170 LOG_HELP("Usage:^3 sv_cmd printstats");
1171 LOG_HELP(" No arguments required.");
1177 void GameCommand_radarmap(int request, int argc)
1181 case CMD_REQUEST_COMMAND:
1183 if (RadarMap_Make(argc)) return;
1187 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
1188 case CMD_REQUEST_USAGE:
1190 LOG_HELP("Usage:^3 sv_cmd radarmap [--force] [--loop] [--quit] [--block | --trace | --sample | --lineblock] [--sharpen N] [--res W H] [--qual Q]");
1191 LOG_HELP(" The quality factor Q is roughly proportional to the time taken.");
1192 LOG_HELP(" trace supports no quality factor; its result should look like --block with infinite quality factor.");
1193 LOG_HELP("See also: ^2make_mapinfo^7");
1199 void GameCommand_reducematchtime(int request)
1203 case CMD_REQUEST_COMMAND:
1205 changematchtime(autocvar_timelimit_decrement * -60, autocvar_timelimit_min * 60, autocvar_timelimit_max * 60);
1210 case CMD_REQUEST_USAGE:
1212 LOG_HELP("Usage:^3 sv_cmd reducematchtime");
1213 LOG_HELP(" No arguments required.");
1214 LOG_HELP("See also: ^2extendmatchtime^7");
1220 void GameCommand_setbots(int request, int argc)
1224 case CMD_REQUEST_COMMAND:
1228 cvar_settemp("minplayers", "0");
1229 cvar_settemp("minplayers_per_team", "0");
1230 cvar_settemp("bot_number", argv(1));
1237 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
1238 case CMD_REQUEST_USAGE:
1240 LOG_HELP("Usage:^3 sv_cmd setbots <botnumber>");
1241 LOG_HELP(" Where <botnumber> is the amount of bots to set bot_number cvar to.");
1242 LOG_HELP("See also: ^2bot_cmd^7");
1252 LOG_INFO("Can't shuffle teams when currently not playing a team game.");
1256 FOREACH_CLIENT(IS_PLAYER(it) || it.caplayer, {
1257 if (Player_HasRealForcedTeam(it)) {
1258 // we could theoretically assign forced players to their teams
1259 // and shuffle the rest to fill the empty spots but in practise
1260 // either all players or none are gonna have forced teams
1261 LOG_INFO("Can't shuffle teams because at least one player has a forced team.");
1266 int number_of_teams = 0;
1267 entity balance = TeamBalance_CheckAllowedTeams(NULL);
1268 for (int i = 1; i <= NUM_TEAMS; ++i)
1270 if (TeamBalance_IsTeamAllowed(balance, i))
1272 number_of_teams = max(i, number_of_teams);
1275 TeamBalance_Destroy(balance);
1278 FOREACH_CLIENT_RANDOM(IS_PLAYER(it) || it.caplayer, {
1279 int target_team_index = team_index + 1;
1280 if (Entity_GetTeamIndex(it) != target_team_index)
1282 MoveToTeam(it, target_team_index, 6);
1284 team_index = (team_index + 1) % number_of_teams;
1287 bprint("Successfully shuffled the players around randomly.\n");
1290 void GameCommand_shuffleteams(int request)
1294 case CMD_REQUEST_COMMAND:
1296 if (shuffleteams_on_reset_map)
1298 bprint("Players will be shuffled when this round is over.\n");
1299 shuffleteams_on_reset_map = true;
1307 case CMD_REQUEST_USAGE:
1309 LOG_HELP("Usage:^3 sv_cmd shuffleteams");
1310 LOG_HELP(" No arguments required.");
1311 LOG_HELP("See also: ^2moveplayer, allspec^7");
1317 void GameCommand_resetmatch(int request)
1321 case CMD_REQUEST_COMMAND:
1323 ReadyRestart(false);
1328 case CMD_REQUEST_USAGE:
1330 LOG_HELP("Usage:^3 sv_cmd resetmatch");
1331 LOG_HELP(" No arguments required.");
1337 void GameCommand_stuffto(int request, int argc)
1339 // This... is a fairly dangerous and powerful command... - It allows any arguments to be sent to a client via rcon.
1340 // Because of this, it is disabled by default and must be enabled by the server owner when doing compilation. That way,
1341 // we can be certain they understand the risks of it... So to enable, compile server with -DSTUFFTO_ENABLED argument.
1343 #ifdef STUFFTO_ENABLED
1346 case CMD_REQUEST_COMMAND:
1350 entity client = GetIndexedEntity(argc, 1);
1351 float accepted = VerifyClientEntity(client, true, false);
1355 stuffcmd(client, strcat("\n", argv(next_token), "\n"));
1356 LOG_INFO("Command: \"", argv(next_token), "\" sent to ", GetCallerName(client), " (", argv(1), ").");
1360 LOG_INFO("stuffto: ", GetClientErrorString(accepted, argv(1)), ".");
1368 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
1369 case CMD_REQUEST_USAGE:
1371 LOG_HELP("Usage:^3 sv_cmd stuffto <client> \"<command>\"");
1372 LOG_HELP(" <client> is the entity number or name of the player,");
1373 LOG_HELP(" and <command> is the command to be sent to that player.");
1380 LOG_HELP("stuffto command is not enabled on this server.");
1386 void GameCommand_trace(int request, int argc)
1390 case CMD_REQUEST_COMMAND:
1393 vector org, delta, start, end, p, q, q0, pos, vv, dv;
1394 float i, f, safe, unsafe, dq, dqf;
1401 LOG_INFO("TEST CASE. If this returns the runaway loop counter error, possibly everything is oaky.");
1402 float worst_endpos_bug = 0;
1406 delta = world.maxs - world.mins;
1408 start.x = org.x + random() * delta.x;
1409 start.y = org.y + random() * delta.y;
1410 start.z = org.z + random() * delta.z;
1412 end.x = org.x + random() * delta.x;
1413 end.y = org.y + random() * delta.y;
1414 end.z = org.z + random() * delta.z;
1416 start = stov(vtos(start));
1417 end = stov(vtos(end));
1419 tracebox(start, PL_MIN_CONST, PL_MAX_CONST, end, MOVE_NOMONSTERS, NULL);
1420 if (!trace_startsolid && trace_fraction < 1)
1423 tracebox(p, PL_MIN_CONST, PL_MAX_CONST, p, MOVE_NOMONSTERS, NULL);
1424 if (trace_startsolid)
1426 rint(42); // do an engine breakpoint on VM_rint so you can get the trace that errnoeously returns startsolid
1427 tracebox(start, PL_MIN_CONST, PL_MAX_CONST, end, MOVE_NOMONSTERS, NULL);
1429 // how much do we need to back off?
1434 pos = p * (1 - (safe + unsafe) * 0.5) + start * ((safe + unsafe) * 0.5);
1435 tracebox(pos, PL_MIN_CONST, PL_MAX_CONST, pos, MOVE_NOMONSTERS, NULL);
1436 if (trace_startsolid)
1438 if ((safe + unsafe) * 0.5 == unsafe) break;
1439 unsafe = (safe + unsafe) * 0.5;
1443 if ((safe + unsafe) * 0.5 == safe) break;
1444 safe = (safe + unsafe) * 0.5;
1448 LOG_INFO("safe distance to back off: ", ftos(safe * vlen(p - start)), "qu");
1449 LOG_INFO("unsafe distance to back off: ", ftos(unsafe * vlen(p - start)), "qu");
1451 tracebox(p, PL_MIN_CONST + '0.1 0.1 0.1', PL_MAX_CONST - '0.1 0.1 0.1', p, MOVE_NOMONSTERS, NULL);
1452 if (trace_startsolid) LOG_INFO("trace_endpos much in solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p));
1453 else LOG_INFO("trace_endpos just in solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p));
1454 if (++hitcount >= 10) break;
1463 q = p + normalize(end - p) * (dq + dqf);
1465 tracebox(p, PL_MIN_CONST, PL_MAX_CONST, q, MOVE_NOMONSTERS, NULL);
1466 if (trace_startsolid) error("THIS ONE cannot happen");
1467 if (trace_fraction > 0) dq += dqf * trace_fraction;
1471 if (dq > worst_endpos_bug)
1473 worst_endpos_bug = dq;
1474 LOG_INFO("trace_endpos still before solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p));
1475 LOG_INFO("could go ", ftos(dq), " units further to ", vtos(q));
1476 if (++hitcount >= 10) break;
1487 tracebox(e.origin + '0 0 32', e.mins, e.maxs, e.origin + '0 0 -1024', MOVE_NORMAL, e);
1489 if (trace_fraction == 1)
1491 LOG_INFO("not above ground, aborting");
1495 for (i = 0; i < 100000; ++i)
1498 if (dv.z > 0) dv = -1 * dv;
1499 tracebox(vv, e.mins, e.maxs, vv + dv, MOVE_NORMAL, e);
1500 if (trace_startsolid) LOG_INFO("bug 1");
1501 if (trace_fraction == 1)
1505 LOG_INFO("bug 2: ", ftos(dv.x), " ", ftos(dv.y), " ", ftos(dv.z));
1506 LOG_INFO(" (", ftos(asin(dv.z / vlen(dv)) * 180 / M_PI), " degrees)");
1511 LOG_INFO("highest possible dist: ", ftos(f));
1517 if (argc == 4 || argc == 5)
1520 int dphitcontentsmask_save = e.dphitcontentsmask;
1521 e.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
1522 if (tracewalk(e, stov(argv(2)), e.mins, e.maxs, stov(argv(3)), stof(argv(4)), MOVE_NORMAL))
1523 LOG_INFO("can walk");
1525 LOG_INFO("cannot walk");
1526 e.dphitcontentsmask = dphitcontentsmask_save;
1537 traceline(vv, dv, MOVE_NORMAL, NULL);
1538 __trailparticles(NULL, particleeffectnum(EFFECT_TR_NEXUIZPLASMA), vv, trace_endpos);
1539 __trailparticles(NULL, particleeffectnum(EFFECT_TR_CRYLINKPLASMA), trace_endpos, dv);
1544 // no default case, just go straight to invalid
1549 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
1550 case CMD_REQUEST_USAGE:
1552 LOG_HELP("Usage:^3 sv_cmd trace <command> [<startpos> <endpos>] [<endpos_height>]");
1553 LOG_HELP(" Where <startpos> and <endpos> are parameters for the 'walk' and 'showline' commands,");
1554 LOG_HELP(" <endpos_height> is an optional parameter for the 'walk' command,");
1555 LOG_HELP(" Full list of commands here: debug, debug2, walk, showline.");
1556 LOG_HELP("See also: ^2bbox, gettaginfo^7");
1562 void GameCommand_unlockteams(int request)
1566 case CMD_REQUEST_COMMAND:
1571 bprint("^1The teams are now unlocked.\n");
1575 bprint("unlockteams command can only be used in a team-based gamemode.\n");
1581 case CMD_REQUEST_USAGE:
1583 LOG_HELP("Usage:^3 sv_cmd unlockteams");
1584 LOG_HELP(" No arguments required.");
1585 LOG_HELP("See also: ^2lockteams^7");
1591 void GameCommand_warp(int request, int argc)
1595 case CMD_REQUEST_COMMAND:
1597 if (autocvar_g_campaign)
1601 CampaignLevelWarp(stof(argv(1)));
1602 LOG_INFO("Successfully warped to campaign level ", argv(1), ".");
1606 CampaignLevelWarp(-1);
1607 LOG_INFO("Successfully warped to next campaign level.");
1612 LOG_INFO("Not in campaign, can't level warp");
1618 case CMD_REQUEST_USAGE:
1620 LOG_HELP("Usage:^3 sv_cmd warp [<level>]");
1621 LOG_HELP(" <level> is the level to change campaign mode to.");
1622 LOG_HELP(" if <level> is not provided it will change to the next level.");
1628 /* use this when creating a new command, making sure to place it in alphabetical order... also,
1629 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
1630 void GameCommand_(int request)
1634 case CMD_REQUEST_COMMAND:
1641 case CMD_REQUEST_USAGE:
1643 LOG_HELP("Usage:^3 sv_cmd ");
1644 LOG_HELP(" No arguments required.");
1652 // ==================================
1653 // Macro system for server commands
1654 // ==================================
1656 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
1657 SERVER_COMMAND(adminmsg, "Send an admin message to a client directly") { GameCommand_adminmsg(request, arguments); }
1658 SERVER_COMMAND(allready, "Ends warmup and starts the match") { GameCommand_allready(request); }
1659 SERVER_COMMAND(allspec, "Force all players to spectate") { GameCommand_allspec(request, arguments); }
1660 SERVER_COMMAND(anticheat, "Create an anticheat report for a client") { GameCommand_anticheat(request, arguments); }
1661 SERVER_COMMAND(animbench, "Benchmark model animation (LAGS)") { GameCommand_animbench(request, arguments); }
1662 SERVER_COMMAND(bbox, "Print detailed information about world size") { GameCommand_bbox(request); }
1663 SERVER_COMMAND(bot_cmd, "Control and send commands to bots") { GameCommand_bot_cmd(request, arguments, command); }
1664 SERVER_COMMAND(cointoss, "Flip a virtual coin and give random result") { GameCommand_cointoss(request, arguments); }
1665 SERVER_COMMAND(database, "Extra controls of the serverprogs database") { GameCommand_database(request, arguments); }
1666 SERVER_COMMAND(defer_clear, "Clear all queued defer commands for a specific client") { GameCommand_defer_clear(request, arguments); }
1667 SERVER_COMMAND(defer_clear_all, "Clear all queued defer commands for all clients") { GameCommand_defer_clear_all(request); }
1668 SERVER_COMMAND(delrec, "Delete race time record for a map") { GameCommand_delrec(request, arguments); }
1669 SERVER_COMMAND(effectindexdump, "Dump list of effects from code and effectinfo.txt") { GameCommand_effectindexdump(request); }
1670 SERVER_COMMAND(extendmatchtime, "Increase the timelimit value incrementally") { GameCommand_extendmatchtime(request); }
1671 SERVER_COMMAND(gametype, "Simple command to change the active gametype") { GameCommand_gametype(request, arguments); }
1672 SERVER_COMMAND(gettaginfo, "Get specific information about a weapon model") { GameCommand_gettaginfo(request, arguments); }
1673 SERVER_COMMAND(gotomap, "Simple command to switch to another map") { GameCommand_gotomap(request, arguments); }
1674 SERVER_COMMAND(lockteams, "Disable the ability for players to switch or enter teams") { GameCommand_lockteams(request); }
1675 SERVER_COMMAND(make_mapinfo, "Automatically rebuild mapinfo files") { GameCommand_make_mapinfo(request); }
1676 SERVER_COMMAND(moveplayer, "Change the team/status of a player") { GameCommand_moveplayer(request, arguments); }
1677 SERVER_COMMAND(nospectators, "Automatically remove spectators from a match") { GameCommand_nospectators(request); }
1678 SERVER_COMMAND(printstats, "Dump eventlog player stats and other score information") { GameCommand_printstats(request); }
1679 SERVER_COMMAND(radarmap, "Generate a radar image of the map") { GameCommand_radarmap(request, arguments); }
1680 SERVER_COMMAND(reducematchtime, "Decrease the timelimit value incrementally") { GameCommand_reducematchtime(request); }
1681 SERVER_COMMAND(resetmatch, "Soft restart the game without changing teams; goes back to warmup if enabled") { GameCommand_resetmatch(request); }
1682 SERVER_COMMAND(setbots, "Adjust how many bots are in the match") { GameCommand_setbots(request, arguments); }
1683 SERVER_COMMAND(shuffleteams, "Randomly move players to different teams") { GameCommand_shuffleteams(request); }
1684 SERVER_COMMAND(stuffto, "Send a command to be executed on a client") { GameCommand_stuffto(request, arguments); }
1685 SERVER_COMMAND(trace, "Various debugging tools with tracing") { GameCommand_trace(request, arguments); }
1686 SERVER_COMMAND(unlockteams, "Enable the ability for players to switch or enter teams") { GameCommand_unlockteams(request); }
1687 SERVER_COMMAND(warp, "Choose different level in campaign") { GameCommand_warp(request, arguments); }
1689 void GameCommand_macro_help()
1691 FOREACH(SERVER_COMMANDS, true, { LOG_HELPF(" ^2%s^7: %s", it.m_name, it.m_description); });
1694 float GameCommand_macro_command(int argc, string command)
1696 string c = strtolower(argv(0));
1697 FOREACH(SERVER_COMMANDS, it.m_name == c, {
1698 it.m_invokecmd(it, CMD_REQUEST_COMMAND, NULL, argc, command);
1704 float GameCommand_macro_usage(int argc)
1706 string c = strtolower(argv(1));
1707 FOREACH(SERVER_COMMANDS, it.m_name == c, {
1708 it.m_invokecmd(it, CMD_REQUEST_USAGE, NULL, argc, "");
1714 void GameCommand_macro_write_aliases(float fh)
1716 FOREACH(SERVER_COMMANDS, true, { CMD_Write_Alias("qc_cmd_sv", it.m_name, it.m_description); });
1720 // =========================================
1721 // Main Function Called By Engine (sv_cmd)
1722 // =========================================
1723 // If this function exists, game code handles gamecommand instead of the engine code.
1725 void GameCommand(string command)
1727 int argc = tokenize_console(command);
1729 // Guide for working with argc arguments by example:
1730 // argc: 1 - 2 - 3 - 4
1731 // argv: 0 - 1 - 2 - 3
1732 // cmd vote - master - login - password
1734 if (strtolower(argv(0)) == "help")
1738 LOG_HELP("Server console commands:");
1739 GameCommand_macro_help();
1741 LOG_HELP("\nBanning commands:");
1742 BanCommand_macro_help();
1744 LOG_HELP("\nCommon networked commands:");
1745 CommonCommand_macro_help(NULL);
1747 LOG_HELP("\nGeneric commands shared by all programs:");
1748 GenericCommand_macro_help();
1750 LOG_HELP("\nUsage:^3 sv_cmd <command>^7, where possible commands are listed above.\n"
1751 "For help about a specific command, type sv_cmd help <command>");
1755 else if (BanCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
1759 else if (CommonCommand_macro_usage(argc, NULL)) // same here, but for common commands instead
1763 else if (GenericCommand_macro_usage(argc)) // same here, but for generic commands instead
1767 else if (GameCommand_macro_usage(argc)) // finally try for normal commands too
1772 else if (MUTATOR_CALLHOOK(SV_ParseServerCommand, strtolower(argv(0)), argc, command))
1774 return; // handled by a mutator
1776 else if (BanCommand(command))
1778 return; // handled by server/command/ipban.qc
1780 else if (CommonCommand_macro_command(argc, NULL, command))
1782 return; // handled by server/command/common.qc
1784 else if (GenericCommand(command))
1786 return; // handled by common/command/generic.qc
1788 else if (GameCommand_macro_command(argc, command)) // continue as usual and scan for normal commands
1790 return; // handled by one of the above GameCommand_* functions
1793 // nothing above caught the command, must be invalid
1794 LOG_INFO(((command != "") ? strcat("Unknown server command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try sv_cmd help.");