1 // =====================================================
2 // Server side game commands code, reworked by Samual
3 // Last updated: July 13th, 2011
4 // =====================================================
6 #define GC_REQUEST_HELP 1
7 #define GC_REQUEST_COMMAND 2
8 #define GC_REQUEST_USAGE 3
12 float RADAR_WIDTH_MAX = 512;
13 float RADAR_HEIGHT_MAX = 512;
14 float sharpen_buffer[RADAR_WIDTH_MAX * 3];
16 string GotoMap(string m);
17 string doublehex = "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFFFF";
18 // FF is contained twice, to map 256 to FF too
19 // removes the need to bound()
21 void race_deleteTime(string map, float pos);
24 // ============================
25 // Misc. Supporting Functions
26 // ============================
28 // used by GameCommand_radarmap()
29 float FullTraceFraction(vector a, vector mi, vector ma, vector b)
42 while(vlen(c - b) > 1)
46 tracebox(c, mi, ma, b, MOVE_WORLDONLY, world);
51 black += vlen(trace_endpos - c);
55 n += tracebox_inverted(c, mi, ma, b, MOVE_WORLDONLY, world);
57 white += vlen(trace_endpos - c);
62 dprint("HOLY SHIT! FullTraceFraction: ", ftos(n), " total traces, ", ftos(m), " iterations\n");
64 return white / (black + white);
66 float RadarMapAtPoint_Trace(float x, float y, float w, float h, float zmin, float zsize, float q)
71 ma = '1 0 0' * w + '0 1 0' * h;
72 a = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
73 b = '1 0 0' * x + '0 1 0' * y + '0 0 1' * (zsize + zmin);
75 return FullTraceFraction(a, mi, ma, b);
77 float RadarMapAtPoint_LineBlock(float x, float y, float w, float h, float zmin, float zsize, float q)
84 // 256q-1 is the ideal sample count to map equal amount of sample values to one pixel value
87 dz = (zsize / q) * '0 0 1';
88 ma = '1 0 0' * w + '0 1 0' * h + dz;
89 o = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
91 if(x < world.absmin_x - w)
93 if(y < world.absmin_y - h)
95 if(x > world.absmax_x)
97 if(y > world.absmax_y)
101 for(i = 0; i < q; ++i)
104 v1 = v2 = o + dz * i + mi;
105 v1_x += random() * (ma_x - mi_x);
106 v1_y += random() * (ma_y - mi_y);
107 v1_z += random() * (ma_z - mi_z);
108 v2_x += random() * (ma_x - mi_x);
109 v2_y += random() * (ma_y - mi_y);
110 v2_z += random() * (ma_z - mi_z);
111 traceline(v1, v2, MOVE_WORLDONLY, world);
112 if(trace_startsolid || trace_fraction < 1)
117 float RadarMapAtPoint_Block(float x, float y, float w, float h, float zmin, float zsize, float q)
124 // 256q-1 is the ideal sample count to map equal amount of sample values to one pixel value
127 dz = (zsize / q) * '0 0 1';
128 ma = '1 0 0' * w + '0 1 0' * h + dz;
129 o = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
131 if(x < world.absmin_x - w)
133 if(y < world.absmin_y - h)
135 if(x > world.absmax_x)
137 if(y > world.absmax_y)
141 for(i = 0; i < q; ++i)
143 tracebox(o + dz * i, mi, ma, o + dz * i, MOVE_WORLDONLY, world);
149 float RadarMapAtPoint_Sample(float x, float y, float w, float h, float zmin, float zsize, float q)
153 q *= 4; // choose q so it matches the regular algorithm in speed
156 // 256q-1 is the ideal sample count to map equal amount of sample values to one pixel value
159 ma = '1 0 0' * w + '0 1 0' * h;
160 a = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
161 b = '1 0 0' * w + '0 1 0' * h + '0 0 1' * zsize;
166 for(i = 0; i < q; ++i)
169 v_x = a_x + random() * b_x;
170 v_y = a_y + random() * b_y;
171 v_z = a_z + random() * b_z;
172 traceline(v, v, MOVE_WORLDONLY, world);
179 void sharpen_set(float x, float v)
181 sharpen_buffer[x + 2 * RADAR_WIDTH_MAX] = v;
183 float sharpen_getpixel(float x, float y)
187 if(x >= RADAR_WIDTH_MAX)
193 return sharpen_buffer[x + y * RADAR_WIDTH_MAX];
195 float sharpen_get(float x, float a)
198 sum = sharpen_getpixel(x, 1);
202 sum -= sharpen_getpixel(x - 1, 0);
203 sum -= sharpen_getpixel(x - 1, 1);
204 sum -= sharpen_getpixel(x - 1, 2);
205 sum -= sharpen_getpixel(x + 1, 0);
206 sum -= sharpen_getpixel(x + 1, 1);
207 sum -= sharpen_getpixel(x + 1, 2);
208 sum -= sharpen_getpixel(x, 0);
209 sum -= sharpen_getpixel(x, 2);
210 return bound(0, sum * a, 1);
212 void sharpen_shift(float w)
215 for(i = 0; i < w; ++i)
217 sharpen_buffer[i] = sharpen_buffer[i + RADAR_WIDTH_MAX];
218 sharpen_buffer[i + RADAR_WIDTH_MAX] = sharpen_buffer[i + 2 * RADAR_WIDTH_MAX];
219 sharpen_buffer[i + 2 * RADAR_WIDTH_MAX] = 0;
222 void sharpen_init(float w)
225 for(i = 0; i < w; ++i)
227 sharpen_buffer[i] = 0;
228 sharpen_buffer[i + RADAR_WIDTH_MAX] = 0;
229 sharpen_buffer[i + 2 * RADAR_WIDTH_MAX] = 0;
234 if(radarmapper.count & 4)
238 else if(radarmapper.count & 2)
240 localcmd(strcat("defer 1 \"sv_cmd radarmap --flags ", ftos(radarmapper.count), strcat(" --res ", ftos(radarmapper.size_x), " ", ftos(radarmapper.size_y), " --sharpen ", ftos(radarmapper.ltime), " --qual ", ftos(radarmapper.size_z)), "\"\n"));
246 void RadarMap_Think()
250 // size: pixel width/height
251 // maxs: cell width/height
260 get_mi_min_max_texcoords(1);
261 self.mins = mi_picmin;
262 self.maxs_x = (mi_picmax_x - mi_picmin_x) / self.size_x;
263 self.maxs_y = (mi_picmax_y - mi_picmin_y) / self.size_y;
264 self.maxs_z = mi_max_z - mi_min_z;
265 print("Picture mins/maxs: ", ftos(self.maxs_x), " and ", ftos(self.maxs_y), " should match\n");
266 self.netname = strzone(strcat("gfx/", mi_shortname, "_radar.xpm"));
267 if(!(self.count & 1))
269 self.cnt = fopen(self.netname, FILE_READ);
271 self.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.tga"), FILE_READ);
273 self.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.png"), FILE_READ);
275 self.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.jpg"), FILE_READ);
277 self.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.tga"), FILE_READ);
279 self.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.png"), FILE_READ);
281 self.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.jpg"), FILE_READ);
286 print(self.netname, " already exists, aborting (you may want to specify --force)\n");
291 self.cnt = fopen(self.netname, FILE_WRITE);
294 print("Error writing ", self.netname, "\n");
299 print("Writing to ", self.netname, "...\n");
300 fputs(self.cnt, "/* XPM */\n");
301 fputs(self.cnt, "static char *RadarMap[] = {\n");
302 fputs(self.cnt, "/* columns rows colors chars-per-pixel */\n");
303 fputs(self.cnt, strcat("\"", ftos(self.size_x), " ", ftos(self.size_y), " 256 2\",\n"));
304 for(i = 0; i < 256; ++i)
306 si = substring(doublehex, i*2, 2);
307 fputs(self.cnt, strcat("\"", si, " c #", si, si, si, "\",\n"));
310 self.nextthink = time;
311 sharpen_init(self.size_x);
313 else if(self.frame <= self.size_y)
315 // fill the sharpen buffer with this line
316 sharpen_shift(self.size_x);
323 for(x = 0; x < self.size_x; ++x)
325 l = RadarMapAtPoint_Block(self.mins_x + x * self.maxs_x, self.mins_y + (self.size_y - self.frame) * self.maxs_y, self.maxs_x, self.maxs_y, self.mins_z, self.maxs_z, self.size_z);
330 for(x = 0; x < self.size_x; ++x)
332 l = RadarMapAtPoint_Trace(self.mins_x + x * self.maxs_x, self.mins_y + (self.size_y - self.frame) * self.maxs_y, self.maxs_x, self.maxs_y, self.mins_z, self.maxs_z, self.size_z);
337 for(x = 0; x < self.size_x; ++x)
339 l = RadarMapAtPoint_Sample(self.mins_x + x * self.maxs_x, self.mins_y + (self.size_y - self.frame) * self.maxs_y, self.maxs_x, self.maxs_y, self.mins_z, self.maxs_z, self.size_z);
344 for(x = 0; x < self.size_x; ++x)
346 l = RadarMapAtPoint_LineBlock(self.mins_x + x * self.maxs_x, self.mins_y + (self.size_y - self.frame) * self.maxs_y, self.maxs_x, self.maxs_y, self.mins_z, self.maxs_z, self.size_z);
352 // do we have enough lines?
355 // write a pixel line
356 fputs(self.cnt, "\"");
357 for(x = 0; x < self.size_x; ++x)
359 l = sharpen_get(x, self.ltime);
360 fputs(self.cnt, substring(doublehex, 2 * floor(l * 256.0), 2));
362 if(self.frame == self.size_y)
363 fputs(self.cnt, "\"\n");
366 fputs(self.cnt, "\",\n");
367 print(ftos(self.size_y - self.frame), " lines left\n");
371 // is this the last line? then write back the missing line
372 if(self.frame == self.size_y)
374 sharpen_shift(self.size_x);
375 // write a pixel line
376 fputs(self.cnt, "\"");
377 for(x = 0; x < self.size_x; ++x)
379 l = sharpen_get(x, self.ltime);
380 fputs(self.cnt, substring(doublehex, 2 * floor(l * 256.0), 2));
382 if(self.frame == self.size_y)
383 fputs(self.cnt, "\"\n");
386 fputs(self.cnt, "\",\n");
387 print(ftos(self.size_y - self.frame), " lines left\n");
392 self.nextthink = time;
397 fputs(self.cnt, "};\n");
399 print("Finished. Please edit data/", self.netname, " with an image editing application and place it in the TGA format in the gfx folder.\n");
404 // used by GameCommand_make_mapinfo()
405 void make_mapinfo_Think()
407 if(MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 1))
409 print("Done rebuiling mapinfos.\n");
410 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
415 self.think = make_mapinfo_Think;
416 self.nextthink = time;
420 // used by GameCommand_extendmatchtime() and GameCommand_reducematchtime()
421 void changematchtime(float delta, float mi, float ma)
429 if(autocvar_timelimit < 0)
433 mi = 10; // at least ten sec in the future
434 cur = time - game_starttime;
436 mi += cur; // from current time!
438 lim = autocvar_timelimit * 60;
443 return; // cannot increase any further
445 new = min(ma, lim + delta);
446 else // already above maximum: FAIL
451 if(lim == 0) // infinite: try reducing to max, if we are allowed to
453 else if(lim > mi) // above minimum: decrease
454 new = max(mi, lim + delta);
455 else // already below minimum: FAIL
459 cvar_set("timelimit", ftos(new / 60));
462 // used by GameCommand_modelbug() // TODO: is this even needed?
463 float g_clientmodel_genericsendentity (entity to, float sf);
464 void modelbug_make_svqc();
465 void modelbug_make_csqc()
467 Net_LinkEntity(self, TRUE, 0, g_clientmodel_genericsendentity);
468 self.think = modelbug_make_svqc;
469 self.nextthink = time + 1;
470 setorigin(self, self.origin - '0 0 8');
472 void modelbug_make_svqc()
474 self.SendEntity = func_null;
475 self.think = modelbug_make_csqc;
476 self.nextthink = time + 1;
477 setorigin(self, self.origin + '0 0 8');
483 setorigin(e, nextent(world).origin);
484 precache_model("models_portal.md3");
485 setmodel(e, "models/portal.md3");
486 e.think = modelbug_make_svqc;
487 e.nextthink = time + 1;
491 // =======================
492 // Command Sub-Functions
493 // =======================
495 void GameCommand_adminmsg(float request, float argc)
498 float entno = stof(argv(1));
504 case GC_REQUEST_HELP:
505 print(" ^2adminmsg^7: Send an admin message to a client directly\n");
508 case GC_REQUEST_COMMAND:
509 if(argc >= 3 && argc <= 4) {
510 if((entno < 0) | (entno > maxclients)) {
511 print("Player ", argv(1), " doesn't exist\n");
515 for(i = (entno ? entno : 1); i <= (entno ? entno : maxclients); ++i)
517 client = edict_num(i);
518 if(client.flags & FL_CLIENT)
522 // make the string console safe
524 s = strreplace("\n", "", s);
525 s = strreplace("\\", "\\\\", s);
526 s = strreplace("$", "$$", s);
527 s = strreplace("\"", "\\\"", s);
528 stuffcmd(client, sprintf("\ninfobar %f \"%s\"\n", stof(argv(3)), s));
532 centerprint_atprio(client, CENTERPRIO_ADMIN, strcat("^3", admin_name(), ":\n\n^7", argv(2)));
533 sprint(client, strcat("\{1}\{13}^3", admin_name(), "^7: ", argv(2), "\n"));
535 dprint("Message sent to ", client.netname, "\n");
539 if(!n) { print("Client not found\n"); }
544 print("Incorrect parameters for \"adminmsg\"\n");
545 case GC_REQUEST_USAGE:
546 print("\nUsage:^3 sv_cmd adminmsg clientnumber \"message\" [infobartime]\n");
547 print(" If infobartime is provided, the message will be sent to infobar.\n");
548 print(" Otherwise, it will just be sent as a centerprint message.\n");
549 print("Examples: adminmsg 4 \"this message will last for ten seconds\" 10\n");
550 print(" adminmsg 2 \"this message will be a centerprint\"\n");
555 void GameCommand_allready(float request)
559 case GC_REQUEST_HELP:
560 print(" ^2allready^7: Restart the server and reset the players\n");
563 case GC_REQUEST_COMMAND:
568 case GC_REQUEST_USAGE:
569 print("\nUsage:^3 sv_cmd allready\n");
570 print(" No arguments required.\n");
575 void GameCommand_allspec(float request) // todo: Add ability to provide a reason string?
582 case GC_REQUEST_HELP:
583 print(" ^2allspec^7: Force all players to spectate\n");
586 case GC_REQUEST_COMMAND:
587 FOR_EACH_PLAYER(client)
590 PutObserverInServer();
593 if(i) { bprint(strcat("Successfully forced all players to spectate (", ftos(i), ")\n")); } // should a message be added if no players were found?
597 case GC_REQUEST_USAGE:
598 print("\nUsage:^3 sv_cmd allspec\n");
599 print(" No arguments required.\n");
600 print("See also: ^2moveplayer^7\n");
605 void GameCommand_anticheat(float request, float argc) // FIXME: player entity is never found
608 float entno = stof(argv(1));
612 case GC_REQUEST_HELP:
613 print(" ^2anticheat^7: Create an anticheat report for a client\n");
616 case GC_REQUEST_COMMAND:
617 if((entno < 1) | (entno > maxclients)) {
618 print("Player ", argv(1), " doesn't exist\n");
621 client = edict_num(entno);
622 if(clienttype(client) != CLIENTTYPE_REAL && clienttype(client) != CLIENTTYPE_BOT) {
623 print("Player ", client.netname, " is not active\n");
631 print("Incorrect parameters for \"anticheat\"\n");
632 case GC_REQUEST_USAGE:
633 print("\nUsage:^3 sv_cmd anticheat clientnumber\n");
634 print(" where clientnumber is player entity number.\n");
639 void GameCommand_bbox(float request)
643 case GC_REQUEST_HELP:
644 print(" ^2bbox^7: Print detailed information about world size\n");
647 case GC_REQUEST_COMMAND:
648 print("Original size: ", ftos(world.absmin_x), " ", ftos(world.absmin_y), " ", ftos(world.absmin_z));
649 print(" ", ftos(world.absmax_x), " ", ftos(world.absmax_y), " ", ftos(world.absmax_z), "\n");
650 print("Currently set size: ", ftos(world.mins_x), " ", ftos(world.mins_y), " ", ftos(world.mins_z));
651 print(" ", ftos(world.maxs_x), " ", ftos(world.maxs_y), " ", ftos(world.maxs_z), "\n");
652 print("Solid bounding box size:");
654 tracebox('1 0 0' * world.absmin_x,
655 '0 1 0' * world.absmin_y + '0 0 1' * world.absmin_z,
656 '0 1 0' * world.absmax_y + '0 0 1' * world.absmax_z,
657 '1 0 0' * world.absmax_x,
661 print(" ", ftos(world.absmin_x));
663 print(" ", ftos(trace_endpos_x));
665 tracebox('0 1 0' * world.absmin_y,
666 '1 0 0' * world.absmin_x + '0 0 1' * world.absmin_z,
667 '1 0 0' * world.absmax_x + '0 0 1' * world.absmax_z,
668 '0 1 0' * world.absmax_y,
672 print(" ", ftos(world.absmin_y));
674 print(" ", ftos(trace_endpos_y));
676 tracebox('0 0 1' * world.absmin_z,
677 '1 0 0' * world.absmin_x + '0 1 0' * world.absmin_y,
678 '1 0 0' * world.absmax_x + '0 1 0' * world.absmax_y,
679 '0 0 1' * world.absmax_z,
683 print(" ", ftos(world.absmin_z));
685 print(" ", ftos(trace_endpos_z));
687 tracebox('1 0 0' * world.absmax_x,
688 '0 1 0' * world.absmin_y + '0 0 1' * world.absmin_z,
689 '0 1 0' * world.absmax_y + '0 0 1' * world.absmax_z,
690 '1 0 0' * world.absmin_x,
694 print(" ", ftos(world.absmax_x));
696 print(" ", ftos(trace_endpos_x));
698 tracebox('0 1 0' * world.absmax_y,
699 '1 0 0' * world.absmin_x + '0 0 1' * world.absmin_z,
700 '1 0 0' * world.absmax_x + '0 0 1' * world.absmax_z,
701 '0 1 0' * world.absmin_y,
705 print(" ", ftos(world.absmax_y));
707 print(" ", ftos(trace_endpos_y));
709 tracebox('0 0 1' * world.absmax_z,
710 '1 0 0' * world.absmin_x + '0 1 0' * world.absmin_y,
711 '1 0 0' * world.absmax_x + '0 1 0' * world.absmax_y,
712 '0 0 1' * world.absmin_z,
716 print(" ", ftos(world.absmax_z));
718 print(" ", ftos(trace_endpos_z));
724 case GC_REQUEST_USAGE:
725 print("\nUsage:^3 sv_cmd bbox\n");
726 print(" No arguments required.\n");
727 print("See also: ^2gettaginfo^7\n");
732 void GameCommand_bot_cmd(float request, float argc) // what a mess... old old code.
738 case GC_REQUEST_HELP:
739 print(" ^2bot_cmd^7: Control and send commands to bots\n");
742 case GC_REQUEST_COMMAND:
743 if(argv(1) == "reset")
748 else if(argv(1) == "load" && argc == 3)
752 fh = fopen(argv(2), FILE_READ);
755 print("cannot open the file\n");
760 while((s = fgets(fh)))
762 argc = tokenize_console(s);
764 if(argc >= 3 && argv(0) == "sv_cmd" && argv(1) == "bot_cmd")
766 // let's start at token 2 so we can skip sv_cmd bot_cmd
767 bot = find_bot_by_number(stof(argv(2)));
769 bot = find_bot_by_name(argv(2));
771 bot_queuecommand(bot, strcat(argv(3), " ", argv(4)));
774 localcmd(strcat(s, "\n"));
778 print(ftos(i), " commands read\n");
782 else if(argv(1) == "help")
785 bot_cmdhelp(argv(2));
790 else if(argc >= 3) // this comes last
792 bot = find_bot_by_number(stof(argv(1)));
794 bot = find_bot_by_name(argv(1));
797 print(strcat("Command '", (argv(2), " ", argv(3)), "' sent to bot ", bot.netname, "\n"));
798 bot_queuecommand(bot, strcat(argv(2), " ", argv(3)));
802 print(strcat("Error: Can't find bot with the name or id '", argv(1),"' - Did you mistype the command?\n")); // don't return so that usage is shown
806 print("Incorrect parameters for \"bot_cmd\"\n");
807 case GC_REQUEST_USAGE:
808 print("\nUsage:^3 sv_cmd bot_cmd client command [argument]\n");
809 print(" 'client' can be either the name or entity id of the bot\n");
810 print(" For full list of commands, see bot_cmd help [command].\n");
811 print("Examples: bot_cmd <id> cc \"say something\"\n");
812 print(" bot_cmd <id> presskey jump\n");
817 void GameCommand_cointoss(float request) // todo: Perhaps add the ability to give your own arguments to pick between? (Like player names)
820 float choice = (random() > 0.5);
824 case GC_REQUEST_HELP:
825 print(" ^2cointoss^7: Flip a virtual coin and give random result\n");
828 case GC_REQUEST_COMMAND:
829 FOR_EACH_CLIENT(client)
830 centerprint(client, strcat("^3Throwing coin... Result: ", (choice ? "^1HEADS^3!\n" : "^4TAILS^3!\n")));
831 bprint(strcat("^3Throwing coin... Result: ", (choice ? "^1HEADS^3!\n" : "^4TAILS^3!\n")));
835 case GC_REQUEST_USAGE:
836 print("\nUsage:^3 sv_cmd cointoss\n");
837 print(" No arguments required.\n");
842 void GameCommand_cvar_changes(float request)
846 case GC_REQUEST_HELP:
847 print(" ^2cvar_changes^7: Prints a list of all changed server cvars\n");
850 case GC_REQUEST_COMMAND:
855 case GC_REQUEST_USAGE:
856 print("\nUsage:^3 sv_cmd \n");
857 print(" No arguments required.\n");
858 print("See also: ^2cvar_purechanges^7\n");
863 void GameCommand_cvar_purechanges(float request)
867 case GC_REQUEST_HELP:
868 print(" ^2cvar_purechanges^7: Prints a list of all changed gameplay cvars\n");
871 case GC_REQUEST_COMMAND:
872 print(cvar_purechanges);
876 case GC_REQUEST_USAGE:
877 print("\nUsage:^3 sv_cmd cvar_purechanges\n");
878 print(" No arguments required.\n");
879 print("See also: ^2cvar_changes^7\n");
884 void GameCommand_database(float request, float argc)
888 case GC_REQUEST_HELP:
889 print(" ^2database^7: Extra controls of the serverprogs database\n");
892 case GC_REQUEST_COMMAND:
895 if(argv(1) == "save")
897 db_save(ServerProgsDB, argv(2));
898 print(strcat("Copied serverprogs database to '", argv(2), "' in the data directory.\n"));
901 else if(argv(1) == "dump")
903 db_dump(ServerProgsDB, argv(2));
904 print("DB dumped.\n"); // wtf does this do?
907 else if(argv(1) == "load")
909 db_close(ServerProgsDB);
910 ServerProgsDB = db_load(argv(2));
911 print(strcat("Loaded '", argv(2), "' as new serverprogs database.\n"));
917 print("Incorrect parameters for \"database\"\n");
918 case GC_REQUEST_USAGE:
919 print("\nUsage:^3 sv_cmd database action filename\n");
920 print(" Where 'action' is the command to complete,\n");
921 print(" and 'filename' is what it acts upon.\n");
922 print(" Full list of commands here: \"save, dump, load.\"\n");
927 void GameCommand_defer_clear(float request, float argc)
930 float entno = stof(argv(1));
934 case GC_REQUEST_HELP:
935 print(" ^2defer_clear^7: Clear all queued defer commands for client\n");
938 case GC_REQUEST_COMMAND:
941 // player_id is out of range
942 if((entno < 1) | (entno > maxclients)) {
943 print("Player ", argv(1), " doesn't exist\n");
946 client = edict_num(entno);
947 if not(client.flags & FL_CLIENT) {
948 print("Player ", argv(1), " doesn't exist\n");
951 if(clienttype(client) == CLIENTTYPE_BOT) {
952 print("Player ", argv(1), " (", client.netname, ") is a bot\n");
955 stuffcmd(client, "defer clear\n");
956 print("defer clear stuffed to ", argv(1), " (", client.netname, ")\n");
961 print("Incorrect parameters for \"defer_clear\"\n");
962 case GC_REQUEST_USAGE:
963 print("\nUsage:^3 sv_cmd defer_clear clientnumber\n");
964 print(" where 'clientnumber' is player entity number.\n");
965 print("See also: ^2defer_clear_all^7\n");
970 void GameCommand_defer_clear_all(float request)
978 case GC_REQUEST_HELP:
979 print(" ^2defer_clear_all^7: Clear all queued defer commands for all clients\n");
982 case GC_REQUEST_COMMAND:
983 FOR_EACH_CLIENT(client)
985 argc = tokenize_console(strcat("defer_clear ", ftos(num_for_edict(client))));
986 GameCommand_defer_clear(GC_REQUEST_COMMAND, argc);
989 if(i) { bprint(strcat("Successfully stuffed defer clear to all clients (", ftos(i), ")\n")); } // should a message be added if no players were found?
993 case GC_REQUEST_USAGE:
994 print("\nUsage:^3 sv_cmd defer_clear_all\n");
995 print(" No arguments required.\n");
996 print("See also: ^2defer_clear^7\n");
1001 void GameCommand_delrec(float request, float argc) // UNTESTED
1005 case GC_REQUEST_HELP:
1006 print(" ^2delrec^7: Delete race time record for a map\n");
1009 case GC_REQUEST_COMMAND:
1013 race_deleteTime(argv(2), stof(argv(1)));
1015 race_deleteTime(GetMapname(), stof(argv(1)));
1020 print("Incorrect parameters for \"delrec\"\n");
1021 case GC_REQUEST_USAGE:
1022 print("\nUsage:^3 sv_cmd delrec ranking [map]\n");
1023 print(" 'ranking' is which ranking level to clear up to, \n");
1024 print(" it will clear all records up to nth place.\n");
1025 print(" if 'map' is not provided it will use current map.\n");
1030 void GameCommand_effectindexdump(float request)
1037 case GC_REQUEST_HELP:
1038 print(" ^2effectindexdump^7: Dump list of effects from code and effectinfo.txt\n");
1041 case GC_REQUEST_COMMAND:
1043 print("begin of effects list\n");
1044 db_put(d, "TE_GUNSHOT", "1"); print("effect TE_GUNSHOT is ", ftos(particleeffectnum("TE_GUNSHOT")), "\n");
1045 db_put(d, "TE_GUNSHOTQUAD", "1"); print("effect TE_GUNSHOTQUAD is ", ftos(particleeffectnum("TE_GUNSHOTQUAD")), "\n");
1046 db_put(d, "TE_SPIKE", "1"); print("effect TE_SPIKE is ", ftos(particleeffectnum("TE_SPIKE")), "\n");
1047 db_put(d, "TE_SPIKEQUAD", "1"); print("effect TE_SPIKEQUAD is ", ftos(particleeffectnum("TE_SPIKEQUAD")), "\n");
1048 db_put(d, "TE_SUPERSPIKE", "1"); print("effect TE_SUPERSPIKE is ", ftos(particleeffectnum("TE_SUPERSPIKE")), "\n");
1049 db_put(d, "TE_SUPERSPIKEQUAD", "1"); print("effect TE_SUPERSPIKEQUAD is ", ftos(particleeffectnum("TE_SUPERSPIKEQUAD")), "\n");
1050 db_put(d, "TE_WIZSPIKE", "1"); print("effect TE_WIZSPIKE is ", ftos(particleeffectnum("TE_WIZSPIKE")), "\n");
1051 db_put(d, "TE_KNIGHTSPIKE", "1"); print("effect TE_KNIGHTSPIKE is ", ftos(particleeffectnum("TE_KNIGHTSPIKE")), "\n");
1052 db_put(d, "TE_EXPLOSION", "1"); print("effect TE_EXPLOSION is ", ftos(particleeffectnum("TE_EXPLOSION")), "\n");
1053 db_put(d, "TE_EXPLOSIONQUAD", "1"); print("effect TE_EXPLOSIONQUAD is ", ftos(particleeffectnum("TE_EXPLOSIONQUAD")), "\n");
1054 db_put(d, "TE_TAREXPLOSION", "1"); print("effect TE_TAREXPLOSION is ", ftos(particleeffectnum("TE_TAREXPLOSION")), "\n");
1055 db_put(d, "TE_TELEPORT", "1"); print("effect TE_TELEPORT is ", ftos(particleeffectnum("TE_TELEPORT")), "\n");
1056 db_put(d, "TE_LAVASPLASH", "1"); print("effect TE_LAVASPLASH is ", ftos(particleeffectnum("TE_LAVASPLASH")), "\n");
1057 db_put(d, "TE_SMALLFLASH", "1"); print("effect TE_SMALLFLASH is ", ftos(particleeffectnum("TE_SMALLFLASH")), "\n");
1058 db_put(d, "TE_FLAMEJET", "1"); print("effect TE_FLAMEJET is ", ftos(particleeffectnum("TE_FLAMEJET")), "\n");
1059 db_put(d, "EF_FLAME", "1"); print("effect EF_FLAME is ", ftos(particleeffectnum("EF_FLAME")), "\n");
1060 db_put(d, "TE_BLOOD", "1"); print("effect TE_BLOOD is ", ftos(particleeffectnum("TE_BLOOD")), "\n");
1061 db_put(d, "TE_SPARK", "1"); print("effect TE_SPARK is ", ftos(particleeffectnum("TE_SPARK")), "\n");
1062 db_put(d, "TE_PLASMABURN", "1"); print("effect TE_PLASMABURN is ", ftos(particleeffectnum("TE_PLASMABURN")), "\n");
1063 db_put(d, "TE_TEI_G3", "1"); print("effect TE_TEI_G3 is ", ftos(particleeffectnum("TE_TEI_G3")), "\n");
1064 db_put(d, "TE_TEI_SMOKE", "1"); print("effect TE_TEI_SMOKE is ", ftos(particleeffectnum("TE_TEI_SMOKE")), "\n");
1065 db_put(d, "TE_TEI_BIGEXPLOSION", "1"); print("effect TE_TEI_BIGEXPLOSION is ", ftos(particleeffectnum("TE_TEI_BIGEXPLOSION")), "\n");
1066 db_put(d, "TE_TEI_PLASMAHIT", "1"); print("effect TE_TEI_PLASMAHIT is ", ftos(particleeffectnum("TE_TEI_PLASMAHIT")), "\n");
1067 db_put(d, "EF_STARDUST", "1"); print("effect EF_STARDUST is ", ftos(particleeffectnum("EF_STARDUST")), "\n");
1068 db_put(d, "TR_ROCKET", "1"); print("effect TR_ROCKET is ", ftos(particleeffectnum("TR_ROCKET")), "\n");
1069 db_put(d, "TR_GRENADE", "1"); print("effect TR_GRENADE is ", ftos(particleeffectnum("TR_GRENADE")), "\n");
1070 db_put(d, "TR_BLOOD", "1"); print("effect TR_BLOOD is ", ftos(particleeffectnum("TR_BLOOD")), "\n");
1071 db_put(d, "TR_WIZSPIKE", "1"); print("effect TR_WIZSPIKE is ", ftos(particleeffectnum("TR_WIZSPIKE")), "\n");
1072 db_put(d, "TR_SLIGHTBLOOD", "1"); print("effect TR_SLIGHTBLOOD is ", ftos(particleeffectnum("TR_SLIGHTBLOOD")), "\n");
1073 db_put(d, "TR_KNIGHTSPIKE", "1"); print("effect TR_KNIGHTSPIKE is ", ftos(particleeffectnum("TR_KNIGHTSPIKE")), "\n");
1074 db_put(d, "TR_VORESPIKE", "1"); print("effect TR_VORESPIKE is ", ftos(particleeffectnum("TR_VORESPIKE")), "\n");
1075 db_put(d, "TR_NEHAHRASMOKE", "1"); print("effect TR_NEHAHRASMOKE is ", ftos(particleeffectnum("TR_NEHAHRASMOKE")), "\n");
1076 db_put(d, "TR_NEXUIZPLASMA", "1"); print("effect TR_NEXUIZPLASMA is ", ftos(particleeffectnum("TR_NEXUIZPLASMA")), "\n");
1077 db_put(d, "TR_GLOWTRAIL", "1"); print("effect TR_GLOWTRAIL is ", ftos(particleeffectnum("TR_GLOWTRAIL")), "\n");
1078 db_put(d, "TR_SEEKER", "1"); print("effect TR_SEEKER is ", ftos(particleeffectnum("TR_SEEKER")), "\n");
1079 db_put(d, "SVC_PARTICLE", "1"); print("effect SVC_PARTICLE is ", ftos(particleeffectnum("SVC_PARTICLE")), "\n");
1081 fh = fopen("effectinfo.txt", FILE_READ);
1082 while((s = fgets(fh)))
1084 tokenize(s); // tokenize_console would hit the loop counter :(
1085 if(argv(0) == "effect")
1087 if(db_get(d, argv(1)) != "1")
1089 if(particleeffectnum(argv(1)) >= 0)
1090 print("effect ", argv(1), " is ", ftos(particleeffectnum(argv(1))), "\n");
1091 db_put(d, argv(1), "1");
1095 print("end of effects list\n");
1101 case GC_REQUEST_USAGE:
1102 print("\nUsage:^3 sv_cmd effectindexdump\n");
1103 print(" No arguments required.\n");
1108 void GameCommand_extendmatchtime(float request) // todo: Perhaps allows the user to send a specific time to extend it.
1112 case GC_REQUEST_HELP:
1113 print(" ^2extendmatchtime^7: Increase the timelimit value incrementally\n");
1116 case GC_REQUEST_COMMAND:
1117 changematchtime(autocvar_timelimit_increment* 60, autocvar_timelimit_min*60, autocvar_timelimit_max*60);
1121 case GC_REQUEST_USAGE:
1122 print("\nUsage:^3 sv_cmd extendmatchtime\n");
1123 print(" No arguments required.\n");
1124 print("See also: ^2reducematchtime^7\n");
1129 void GameCommand_find(float request, float argc)
1135 case GC_REQUEST_HELP:
1136 print(" ^2find^7: Search through entities for matching classname\n");
1139 case GC_REQUEST_COMMAND:
1140 for(client = world; (client = find(client, classname, argv(1))); )
1141 print(etos(client), "\n");
1145 print("Incorrect parameters for \"find\"\n");
1146 case GC_REQUEST_USAGE:
1147 print("\nUsage:^3 sv_cmd find classname\n");
1148 print(" Where 'classname' is the classname to search for.\n");
1153 void GameCommand_gametype(float request, float argc)
1156 float t = MapInfo_Type_FromString(s), tsave = MapInfo_CurrentGametype();
1160 case GC_REQUEST_HELP:
1161 print(" ^2gametype^7: Simple command to change the active gametype\n");
1164 case GC_REQUEST_COMMAND:
1167 MapInfo_SwitchGameType(t);
1168 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
1169 if(MapInfo_count > 0)
1170 bprint("Game type successfully switched to ", s, "\n");
1173 bprint("Cannot use this game type: no map for it found\n");
1174 MapInfo_SwitchGameType(tsave);
1175 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
1179 bprint("Game type switch to ", s, " failed: this type does not exist!\n");
1183 print("Incorrect parameters for \"gametype\"\n");
1184 case GC_REQUEST_USAGE:
1185 print("\nUsage:^3 sv_cmd gametype mode\n");
1186 print(" Where 'mode' is the gametype mode to switch to.\n");
1187 print("See also: ^2gotomap^7\n");
1192 void GameCommand_gettaginfo(float request, float argc) // UNTESTED // todo: finish usage description for it (but, must first learn this shit)
1200 case GC_REQUEST_HELP:
1201 print(" ^2gettaginfo^7: Get specific information about a weapon model\n");
1204 case GC_REQUEST_COMMAND:
1207 tmp_entity = spawn();
1209 setmodel(tmp_entity, (nextent(world)).weaponentity.model);
1212 precache_model(argv(1));
1213 setmodel(tmp_entity, argv(1));
1215 tmp_entity.frame = stof(argv(2));
1216 if(substring(argv(3), 0, 1) == "#")
1217 i = stof(substring(argv(3), 1, -1));
1219 i = gettagindex(tmp_entity, argv(3));
1222 v = gettaginfo(tmp_entity, i);
1223 print("model ", tmp_entity.model, " frame ", ftos(tmp_entity.frame), " tag ", gettaginfo_name);
1224 print(" index ", ftos(i), " parent ", ftos(gettaginfo_parent), "\n");
1225 print(" vector = ", ftos(v_x), " ", ftos(v_y), " ", ftos(v_z), "\n");
1226 print(" offset = ", ftos(gettaginfo_offset_x), " ", ftos(gettaginfo_offset_y), " ", ftos(gettaginfo_offset_z), "\n");
1227 print(" forward = ", ftos(gettaginfo_forward_x), " ", ftos(gettaginfo_forward_y), " ", ftos(gettaginfo_forward_z), "\n");
1228 print(" right = ", ftos(gettaginfo_right_x), " ", ftos(gettaginfo_right_y), " ", ftos(gettaginfo_right_z), "\n");
1229 print(" up = ", ftos(gettaginfo_up_x), " ", ftos(gettaginfo_up_y), " ", ftos(gettaginfo_up_z), "\n");
1233 localcmd(strcat(argv(4), vtos(v), argv(5), "\n"));
1237 print("bone not found\n");
1244 print("Incorrect parameters for \"gettaginfo\"\n");
1245 case GC_REQUEST_USAGE:
1246 print("\nUsage:^3 sv_cmd gettaginfo\n");
1247 print(" FIXME: Arguments currently unknown\n");
1248 print("See also: ^2bbox^7\n");
1253 void GameCommand_gotomap(float request, float argc)
1257 case GC_REQUEST_HELP:
1258 print(" ^2gotomap^7: Simple command to switch to another map\n");
1261 case GC_REQUEST_COMMAND:
1264 print(GotoMap(argv(1)), "\n");
1269 print("Incorrect parameters for \"gotomap\"\n");
1270 case GC_REQUEST_USAGE:
1271 print("\nUsage:^3 sv_cmd gotomap map\n");
1272 print(" Where 'map' is the *.bsp file to change to.\n");
1273 print("See also: ^2gametype^7\n");
1278 void GameCommand_ladder(float request)
1282 case GC_REQUEST_HELP:
1283 print(" ^2ladder^7: Get information about top players if supported\n");
1286 case GC_REQUEST_COMMAND:
1287 print(ladder_reply);
1291 case GC_REQUEST_USAGE:
1292 print("\nUsage:^3 sv_cmd ladder\n");
1293 print(" No arguments required.\n");
1298 void GameCommand_lockteams(float request)
1302 case GC_REQUEST_HELP:
1303 print(" ^2lockteams^7: Disable the ability for players to switch or enter teams\n");
1306 case GC_REQUEST_COMMAND:
1310 bprint("^1The teams are now locked.\n");
1313 bprint("That command can only be used in a team-based gamemode.\n");
1317 case GC_REQUEST_USAGE:
1318 print("\nUsage:^3 sv_cmd lockteams\n");
1319 print(" No arguments required.\n");
1320 print("See also: ^2unlockteams^7\n");
1325 void GameCommand_make_mapinfo(float request) // UNTESTED
1331 case GC_REQUEST_HELP:
1332 print(" ^2make_mapinfo^7: Automatically rebuild mapinfo files\n");
1335 case GC_REQUEST_COMMAND:
1336 tmp_entity = spawn();
1337 tmp_entity.classname = "make_mapinfo";
1338 tmp_entity.think = make_mapinfo_Think;
1339 tmp_entity.nextthink = time; // this sucks... todo: re-write this -- Use initializeentity later
1340 MapInfo_Enumerate();
1344 case GC_REQUEST_USAGE:
1345 print("\nUsage:^3 sv_cmd make_mapinfo\n");
1346 print(" No arguments required.\n");
1351 void GameCommand_modelbug(float request) // UNTESTED // is this even needed anymore?
1355 case GC_REQUEST_HELP:
1356 print(" ^2modelbug^7: foobar\n");
1359 case GC_REQUEST_COMMAND:
1364 case GC_REQUEST_USAGE:
1365 print("\nUsage:^3 sv_cmd modelbug\n");
1366 print(" No arguments required.\n");
1371 void GameCommand_moveplayer(float request, float argc)
1374 string targets = argv(1);
1375 string destination = argv(2);
1376 string notify = argv(3);
1378 argc = tokenizebyseparator(targets, ","); // re-use argc for the targets
1382 case GC_REQUEST_HELP:
1383 print(" ^2moveplayer^7: Change the team/status of a player\n");
1386 case GC_REQUEST_COMMAND:
1387 // lets see if the target(s) even actually exist.
1388 if((targets) && (destination))
1390 for(i = 0; i < argc; ++i)
1392 // Check to see if the player is a valid target
1393 if((stof(argv(i)) < 1) | (stof(argv(i)) > maxclients)) // player_id is out of range
1395 print(strcat("Player ", argv(i), " doesn't exist", (((i + 1) < argc) ? ", skipping to next player.\n" : ".\n")));
1398 client = edict_num(stof(argv(i)));
1399 if not(client.flags & FL_CLIENT) // player entity is not a client
1401 print(strcat("Player ", argv(i), " doesn't exist", (((i + 1) < argc) ? ", skipping to next player.\n" : ".\n")));
1405 // Where are we putting this player?
1406 if(destination == "spec" || destination == "spectator")
1408 if(client.classname != "spectator" && client.classname != "observer")
1411 PutObserverInServer();
1415 print("Player ", argv(i), " (", client.netname, ") is already spectating.\n");
1421 if(client.classname != "spectator" && client.classname != "observer")
1427 float save = client.team_forced;
1428 client.team_forced = 0;
1430 // find the team to move the player to
1431 team_color = ColourToNumber(destination);
1432 if(team_color == client.team) // already on the destination team
1434 // keep the forcing undone
1435 print("Player ", argv(i), " (", client.netname, ") is already on the ", ColoredTeamName(client.team), ".\n");
1438 else if(team_color == 0) // auto team
1440 team_color = NumberToTeamNumber(FindSmallestTeam(client, FALSE));
1444 CheckAllowedTeams(client);
1446 client.team_forced = save;
1448 // Check to see if the destination team is even available
1453 print("Sorry, can't move player to red team if it doesn't exist.\n");
1460 print("Sorry, can't move player to blue team if it doesn't exist.\n");
1467 print("Sorry, can't move player to yellow team if it doesn't exist.\n");
1474 print("Sorry, can't move player to pink team if it doesn't exist.\n");
1480 print("Sorry, can't move player here if team ", destination, " doesn't exist.\n");
1484 // If so, lets continue and finally move the player
1485 client.team_forced = 0;
1486 MoveToTeam(client, team_color, 6, stof(notify));
1487 print("Player ", argv(i), " (", client.netname, ") has been moved to the ", ColoredTeamName(team_color), ".\n");
1492 print("Can't change teams when currently not playing a team game.\n");
1498 print("Can't change teams if the player isn't in the game.\n"); // well technically we could, but should we allow that? :P
1503 print("No acceptable players given, aborting.\n");
1504 return; // still correct parameters so return to avoid usage print
1508 print("Incorrect parameters for \"moveplayer\"\n");
1509 case GC_REQUEST_USAGE:
1510 print("\nUsage:^3 sv_cmd moveplayer clientnumbers destination [notify]\n");
1511 print(" 'clientnumbers' is a list (separated by commas) of player entity ID's\n");
1512 print(" 'destination' is what to send the player to, be it team or spectating\n");
1513 print(" Full list of destinations here: \"spec, spectator, red, blue, yellow, pink, auto.\"\n");
1514 print(" 'notify' is whether or not to send messages notifying of the move. Detail below.\n");
1515 print(" 0 (00) automove centerprint, admin message; 1 (01) automove centerprint, no admin message\n");
1516 print(" 2 (10) no centerprint, admin message; 3 (11) no centerprint, no admin message\n");
1517 print("Examples: moveplayer 1,3,5 red 3\n");
1518 print(" moveplayer 2 spec \n");
1519 print("See also: ^2allspec^7\n");
1524 void GameCommand_nospectators(float request)
1528 case GC_REQUEST_HELP:
1529 print(" ^2nospectators^7: Automatically remove spectators from a match\n");
1532 case GC_REQUEST_COMMAND:
1533 blockSpectators = 1;
1535 FOR_EACH_CLIENT(plr) //give every spectator <g_maxplayers_spectator_blocktime> seconds time to become a player
1537 if(plr.classname == "spectator" || plr.classname == "observer")
1539 plr.spectatortime = time;
1540 sprint(plr, strcat("^7You have to become a player within the next ", ftos(autocvar_g_maxplayers_spectator_blocktime), " seconds, otherwise you will be kicked, because spectators aren't allowed at this time!\n"));
1543 bprint(strcat("^7All spectators will be automatically kicked when not joining the game after ", ftos(autocvar_g_maxplayers_spectator_blocktime), " seconds!\n"));
1547 case GC_REQUEST_USAGE:
1548 print("\nUsage:^3 sv_cmd nospectators\n");
1549 print(" No arguments required.\n");
1554 void GameCommand_onslaught_updatelinks(float request) // UNTESTED // should this be here? Perhaps some mutatorhook call instead....
1558 case GC_REQUEST_HELP:
1559 print(" ^2onslaught_updatelinks^7: Refresh link status for onslaught\n");
1562 case GC_REQUEST_COMMAND:
1563 onslaught_updatelinks();
1564 print("ONS links updated\n");
1568 case GC_REQUEST_USAGE:
1569 print("\nUsage:^3 sv_cmd onslaught_updatelinks\n");
1570 print(" No arguments required.\n");
1575 void GameCommand_playerdemo(float request, float argc) // UNTESTED
1583 case GC_REQUEST_HELP:
1584 print(" ^2playerdemo^7: Control the ability to save demos of players\n");
1587 case GC_REQUEST_COMMAND:
1588 if(argv(1) == "read")
1590 // TODO: Create a general command for looking this up, save a lot of space everywhere in this file
1591 entno = stof(argv(2));
1592 if((entno < 1) | (entno > maxclients)) {
1593 print("Player ", argv(2), " doesn't exist\n");
1596 client = edict_num(entno);
1597 if(clienttype(client) != CLIENTTYPE_BOT) {
1598 print("Player ", client.netname, " is not a bot\n");
1602 playerdemo_open_read(argv(3));
1605 else if(argv(1) == "write")
1607 entno = stof(argv(2));
1608 if((entno < 1) | (entno > maxclients)) {
1609 print("Player ", argv(2), " doesn't exist\n");
1612 client = edict_num(entno);
1614 playerdemo_open_write(argv(3));
1617 else if(argv(1) == "auto_read_and_write")
1621 cvar_set("bot_number", ftos(n));
1622 localcmd("wait; wait; wait\n");
1623 for(i = 0; i < n; ++i)
1624 localcmd("sv_cmd playerdemo read ", ftos(i+2), " ", s, ftos(i+1), "\n");
1625 localcmd("sv_cmd playerdemo write 1 ", ftos(n+1), "\n");
1628 else if(argv(1) == "auto_read")
1632 cvar_set("bot_number", ftos(n));
1633 localcmd("wait; wait; wait\n");
1634 for(i = 0; i < n; ++i)
1635 localcmd("sv_cmd playerdemo read ", ftos(i+2), " ", s, ftos(i+1), "\n");
1641 case GC_REQUEST_USAGE:
1642 print("\nUsage:^3 sv_cmd \n");
1643 print(" No arguments required.\n");
1644 print(" FIXME: Arguments currently unknown\n");
1649 void GameCommand_printstats(float request)
1653 case GC_REQUEST_HELP:
1654 print(" ^2printstats^7: foobar\n");
1657 case GC_REQUEST_COMMAND:
1659 print("stats dumped.\n");
1663 case GC_REQUEST_USAGE:
1664 print("\nUsage:^3 sv_cmd printstats\n");
1665 print(" No arguments required.\n");
1670 void GameCommand_radarmap(float request, float argc)
1676 case GC_REQUEST_HELP:
1677 print(" ^2radarmap^7: Generate a radar image of the map\n");
1680 case GC_REQUEST_COMMAND:
1683 radarmapper = spawn();
1684 radarmapper.classname = "radarmapper";
1685 radarmapper.think = RadarMap_Think;
1686 radarmapper.nextthink = time;
1687 radarmapper.count = 8; // default to the --trace method, as it is faster now
1688 radarmapper.ltime = 1;
1689 radarmapper.size = '512 512 1';
1691 for(i = 1; i < argc; ++i)
1695 case "--force": { radarmapper.count |= 1; break; }
1696 case "--loop": { radarmapper.count |= 2; break; }
1697 case "--quit": { radarmapper.count |= 4; break; }
1698 case "--block": { radarmapper.count &~= 24; break; }
1699 case "--trace": { radarmapper.count &~= 24; radarmapper.count |= 8; break; }
1700 case "--sample": { radarmapper.count &~= 24; radarmapper.count |= 16; break; }
1701 case "--lineblock": { radarmapper.count |= 24; break; }
1702 case "--flags": { ++i; radarmapper.count = stof(argv(i)); break; } // for the recursive call
1703 case "--sharpen": { ++i; radarmapper.ltime = stof(argv(i)); break; } // for the recursive call
1704 case "--res": // allow minor alias
1705 case "--resolution": { ++i; radarmapper.size_x = stof(argv(i)); ++i; radarmapper.size_y = stof(argv(i)); break; }
1706 case "--qual": // allow minor alias
1707 case "--quality": { ++i; radarmapper.size_z = stof(argv(i)); break; }
1711 remove(radarmapper);
1712 radarmapper = world;
1717 if(radarmapper) // after doing the arguments, see if we successfully went forward.
1719 print("Radarmap entity spawned.\n");
1720 return; // if so, don't print usage.
1725 print("Incorrect parameters for \"radarmap\"\n");
1726 case GC_REQUEST_USAGE:
1727 print("\nUsage:^3 sv_cmd radarmap [--force] [--loop] [--quit] [--block | --trace | --sample | --lineblock] [--sharpen N] [--res W H] [--qual Q]\n");
1728 print(" The quality factor Q is roughly proportional to the time taken.\n");
1729 print(" trace supports no quality factor; its result should look like --block with infinite quality factor.\n");
1734 void GameCommand_rankings(float request) // this is OLD.... jeez.
1738 case GC_REQUEST_HELP:
1739 print(" ^2rankings^7: Print information about rankings\n");
1742 case GC_REQUEST_COMMAND:
1743 strunzone(rankings_reply);
1744 rankings_reply = strzone(getrankings());
1745 print(rankings_reply);
1749 case GC_REQUEST_USAGE:
1750 print("\nUsage:^3 sv_cmd rankings\n");
1751 print(" No arguments required.\n");
1756 void GameCommand_records(float request)
1762 case GC_REQUEST_HELP:
1763 print(" ^2records^7: List top 10 records for the current map\n");
1766 case GC_REQUEST_COMMAND:
1767 for (i = 0; i < 10; ++i)
1768 print(records_reply[i]);
1772 case GC_REQUEST_USAGE:
1773 print("\nUsage:^3 sv_cmd records\n");
1774 print(" No arguments required.\n");
1779 void GameCommand_reducematchtime(float request) // todo: Perhaps allows the user to send a specific time to reduce it.
1783 case GC_REQUEST_HELP:
1784 print(" ^2reducematchtime^7: Decrease the timelimit value incrementally\n");
1787 case GC_REQUEST_COMMAND:
1788 changematchtime(autocvar_timelimit_decrement*-60, autocvar_timelimit_min*60, autocvar_timelimit_max*60);
1792 case GC_REQUEST_USAGE:
1793 print("\nUsage:^3 sv_cmd reducematchtime\n");
1794 print(" No arguments required.\n");
1795 print("See also: ^2extendmatchtime^7\n");
1800 void GameCommand_stuffto(float request, float argc)
1802 // This, stuffto, is a fairly dangerous and powerful command... - It allows any arguments to be sent to a client via rcon
1803 // because of this, it is disabled by default and must be enabled by the server owner when doing compilation. That way,
1804 // we can be certain they understand the risks of it... So to enable, compile server with -DSTUFFTO_ENABLED argument.
1809 #ifdef STUFFTO_ENABLED
1812 case GC_REQUEST_HELP:
1813 print(" ^2stuffto^7: Send a command to be executed on a client\n");
1816 case GC_REQUEST_COMMAND:
1819 entno = stof(argv(1));
1821 if(entno <= maxclients)
1822 client = edict_num(entno);
1823 if(client.flags & FL_CLIENT)
1825 stuffcmd(client, strcat("\n", argv(2), "\n"));
1826 print(strcat("Command: \"", argv(2), "\" sent to ", client.netname, " (", argv(1) ,").\n"));
1829 print(strcat("Client: ", client.netname, " (", argv(1) ,") not found.\n"));
1835 print("Incorrect parameters for \"stuffto\"\n");
1836 case GC_REQUEST_USAGE:
1837 print("\nUsage:^3 sv_cmd stuffto clientnumber command\n");
1838 print(" No arguments required.\n");
1841 #else // give the response for missing command to fake them out ;3
1842 if(request == GC_REQUEST_COMMAND)
1844 print("Invalid command. For a list of supported commands, try sv_cmd help.\n");
1851 // =========================================
1852 // Main Function Called By Engine (sv_cmd)
1853 // =========================================
1855 void GameCommand(string command)
1857 // ===== TODO list =====
1858 // test some of the older commands and if they're still wanted, fix them if they're broken.
1860 // Finish adding the rest of the commands
1862 // Add ifdef to stuffto so that is can only be used when the game code is compiled for it
1863 //(this way it's more obscure and harder to abuse on normal servers)
1865 float search_request_type;
1866 float argc = tokenize_console(command);
1868 if(argv(0) == "help")
1872 print("\nUsage:^3 sv_cmd COMMAND...^7, where possible commands are:\n");
1873 GameCommand_adminmsg(GC_REQUEST_HELP, 0);
1874 GameCommand_allready(GC_REQUEST_HELP);
1875 GameCommand_allspec(GC_REQUEST_HELP);
1876 GameCommand_anticheat(GC_REQUEST_HELP, 0);
1877 GameCommand_bbox(GC_REQUEST_HELP);
1878 GameCommand_bot_cmd(GC_REQUEST_HELP, 0);
1879 GameCommand_cointoss(GC_REQUEST_HELP);
1880 GameCommand_cvar_changes(GC_REQUEST_HELP);
1881 GameCommand_cvar_purechanges(GC_REQUEST_HELP);
1882 GameCommand_database(GC_REQUEST_HELP, 0);
1883 GameCommand_defer_clear(GC_REQUEST_HELP, 0);
1884 GameCommand_defer_clear_all(GC_REQUEST_HELP);
1885 GameCommand_delrec(GC_REQUEST_HELP, 0);
1886 GameCommand_effectindexdump(GC_REQUEST_HELP);
1887 GameCommand_extendmatchtime(GC_REQUEST_HELP);
1888 GameCommand_find(GC_REQUEST_HELP, 0);
1889 GameCommand_gametype(GC_REQUEST_HELP, 0);
1890 GameCommand_gettaginfo(GC_REQUEST_HELP, 0);
1891 GameCommand_gotomap(GC_REQUEST_HELP, 0);
1892 GameCommand_ladder(GC_REQUEST_HELP);
1893 GameCommand_lockteams(GC_REQUEST_HELP);
1894 GameCommand_make_mapinfo(GC_REQUEST_HELP);
1895 GameCommand_modelbug(GC_REQUEST_HELP);
1896 GameCommand_moveplayer(GC_REQUEST_HELP, 0);
1897 GameCommand_nospectators(GC_REQUEST_HELP);
1898 GameCommand_onslaught_updatelinks(GC_REQUEST_HELP);
1899 GameCommand_playerdemo(GC_REQUEST_HELP, 0);
1900 GameCommand_printstats(GC_REQUEST_HELP);
1901 GameCommand_radarmap(GC_REQUEST_HELP, 0);
1902 GameCommand_rankings(GC_REQUEST_HELP);
1903 GameCommand_records(GC_REQUEST_HELP);
1904 GameCommand_reducematchtime(GC_REQUEST_HELP);
1905 GameCommand_stuffto(GC_REQUEST_HELP, 0);
1906 GameCommand_Vote("help", world);
1907 GameCommand_Ban("help");
1908 GameCommand_Generic("help");
1909 print("For help about specific commands, type sv_cmd help COMMAND\n");
1913 search_request_type = GC_REQUEST_USAGE; // Instead of trying to call a command, we're going to see detailed information about it
1915 else if(GameCommand_Vote(command, world))
1917 return; // handled by server/vote.qc
1919 else if(GameCommand_Ban(command))
1921 return; // handled by server/ipban.qc
1923 else if(GameCommand_Generic(command))
1925 return; // handled by common/gamecommand.qc
1928 search_request_type = GC_REQUEST_COMMAND; // continue as usual and scan for normal commands
1930 switch( ((argv(0) == "help") ? argv(1) : argv(0)) ) // if first argument is help, then search for the second argument. Else, search for first.
1932 // keep in alphabetical order, please ;)
1933 // also: Do not hard code aliases for these, instead create them in defaultXonotic.cfg
1935 case "adminmsg": GameCommand_adminmsg(search_request_type, argc); break;
1936 case "allready": GameCommand_allready(search_request_type); break;
1937 case "allspec": GameCommand_allspec(search_request_type); break;
1938 case "anticheat": GameCommand_anticheat(search_request_type, argc); break;
1939 case "bbox": GameCommand_bbox(search_request_type); break;
1940 case "bot_cmd": GameCommand_bot_cmd(search_request_type, argc); break;
1941 case "cointoss": GameCommand_cointoss(search_request_type); break;
1942 case "cvar_changes": GameCommand_cvar_changes(search_request_type); break;
1943 case "cvar_purechanges": GameCommand_cvar_purechanges(search_request_type); break;
1944 case "database": GameCommand_database(search_request_type, argc); break;
1945 case "defer_clear": GameCommand_defer_clear(search_request_type, argc); break;
1946 case "defer_clear_all": GameCommand_defer_clear_all(search_request_type); break;
1947 case "delrec": GameCommand_delrec(search_request_type, argc); break;
1948 case "effectindexdump": GameCommand_effectindexdump(search_request_type); break;
1949 case "extendmatchtime": GameCommand_extendmatchtime(search_request_type); break;
1950 case "find": GameCommand_find(search_request_type, argc); break;
1951 case "gametype": GameCommand_gametype(search_request_type, argc); break;
1952 case "gettaginfo": GameCommand_gettaginfo(search_request_type, argc); break;
1953 case "gotomap": GameCommand_gotomap(search_request_type, argc); break;
1954 case "ladder": GameCommand_ladder(search_request_type); break;
1955 case "lockteams": GameCommand_lockteams(search_request_type); break;
1956 case "make_mapinfo": GameCommand_make_mapinfo(search_request_type); break;
1957 case "modelbug": GameCommand_modelbug(search_request_type); break;
1958 case "moveplayer": GameCommand_moveplayer(search_request_type, argc); break;
1959 case "nospectators": GameCommand_nospectators(search_request_type); break;
1960 case "onslaught_updatelinks": GameCommand_onslaught_updatelinks(search_request_type); break;
1961 case "playerdemo": GameCommand_playerdemo(search_request_type, argc); break;
1962 case "printstats": GameCommand_printstats(search_request_type); break;
1963 case "radarmap": GameCommand_radarmap(search_request_type, argc); break;
1964 case "rankings": GameCommand_rankings(search_request_type); break;
1965 case "records": GameCommand_records(search_request_type); break;
1966 case "reducematchtime": GameCommand_reducematchtime(search_request_type); break;
1967 case "stuffto": GameCommand_stuffto(search_request_type, argc); break;
1970 print("Invalid command. For a list of supported commands, try sv_cmd help.\n");