2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 cvar_t sv_cheats = {0, "sv_cheats", "0", "enables cheat commands in any game, and cheat impulses in dpmod"};
25 cvar_t rcon_password = {CVAR_PRIVATE, "rcon_password", "", "password to authenticate rcon commands"};
26 cvar_t rcon_address = {0, "rcon_address", "", "server address to send rcon commands to (when not connected to a server)"};
27 cvar_t team = {CVAR_USERINFO | CVAR_SAVE, "team", "none", "QW team (4 character limit, example: blue)"};
28 cvar_t skin = {CVAR_USERINFO | CVAR_SAVE, "skin", "", "QW player skin name (example: base)"};
29 cvar_t noaim = {CVAR_USERINFO | CVAR_SAVE, "noaim", "1", "QW option to disable vertical autoaim"};
30 qboolean allowcheats = false;
38 void Host_Quit_f (void)
49 void Host_Status_f (void)
52 int seconds, minutes, hours = 0, j, players;
53 void (*print) (const char *fmt, ...);
55 if (cmd_source == src_command)
57 // if running a client, try to send over network so the client's status report parser will see the report
58 if (cls.state == ca_connected)
60 Cmd_ForwardToServer ();
66 print = SV_ClientPrintf;
71 for (players = 0, j = 0;j < svs.maxclients;j++)
72 if (svs.clients[j].active)
74 print ("host: %s\n", Cvar_VariableString ("hostname"));
75 print ("version: %s build %s\n", gamename, buildstring);
76 print ("protocol: %i (%s)\n", Protocol_NumberForEnum(sv.protocol), Protocol_NameForEnum(sv.protocol));
77 print ("map: %s\n", sv.name);
78 print ("players: %i active (%i max)\n\n", players, svs.maxclients);
79 for (j = 0, client = svs.clients;j < svs.maxclients;j++, client++)
83 seconds = (int)(realtime - client->connecttime);
84 minutes = seconds / 60;
87 seconds -= (minutes * 60);
90 minutes -= (hours * 60);
94 print ("#%-3u %-16.16s %3i %2i:%02i:%02i\n", j+1, client->name, (int)client->edict->fields.server->frags, hours, minutes, seconds);
95 print (" %s\n", client->netconnection ? client->netconnection->address : "botclient");
104 Sets client to godmode
107 void Host_God_f (void)
109 if (cmd_source == src_command)
111 Cmd_ForwardToServer ();
117 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
121 host_client->edict->fields.server->flags = (int)host_client->edict->fields.server->flags ^ FL_GODMODE;
122 if (!((int)host_client->edict->fields.server->flags & FL_GODMODE) )
123 SV_ClientPrint("godmode OFF\n");
125 SV_ClientPrint("godmode ON\n");
128 void Host_Notarget_f (void)
130 if (cmd_source == src_command)
132 Cmd_ForwardToServer ();
138 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
142 host_client->edict->fields.server->flags = (int)host_client->edict->fields.server->flags ^ FL_NOTARGET;
143 if (!((int)host_client->edict->fields.server->flags & FL_NOTARGET) )
144 SV_ClientPrint("notarget OFF\n");
146 SV_ClientPrint("notarget ON\n");
149 qboolean noclip_anglehack;
151 void Host_Noclip_f (void)
153 if (cmd_source == src_command)
155 Cmd_ForwardToServer ();
161 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
165 if (host_client->edict->fields.server->movetype != MOVETYPE_NOCLIP)
167 noclip_anglehack = true;
168 host_client->edict->fields.server->movetype = MOVETYPE_NOCLIP;
169 SV_ClientPrint("noclip ON\n");
173 noclip_anglehack = false;
174 host_client->edict->fields.server->movetype = MOVETYPE_WALK;
175 SV_ClientPrint("noclip OFF\n");
183 Sets client to flymode
186 void Host_Fly_f (void)
188 if (cmd_source == src_command)
190 Cmd_ForwardToServer ();
196 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
200 if (host_client->edict->fields.server->movetype != MOVETYPE_FLY)
202 host_client->edict->fields.server->movetype = MOVETYPE_FLY;
203 SV_ClientPrint("flymode ON\n");
207 host_client->edict->fields.server->movetype = MOVETYPE_WALK;
208 SV_ClientPrint("flymode OFF\n");
219 void Host_Pings_f (void); // called by Host_Ping_f
220 void Host_Ping_f (void)
224 void (*print) (const char *fmt, ...);
226 if (cmd_source == src_command)
228 // if running a client, try to send over network so the client's ping report parser will see the report
229 if (cls.state == ca_connected)
231 Cmd_ForwardToServer ();
237 print = SV_ClientPrintf;
242 print("Client ping times:\n");
243 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
247 print("%4i %s\n", bound(0, (int)floor(client->ping*1000+0.5), 9999), client->name);
250 // now call the Pings command also, which will send a report that contains packet loss for the scoreboard (as well as a simpler ping report)
255 ===============================================================================
259 ===============================================================================
263 ======================
268 command from the console. Active clients are kicked off.
269 ======================
271 void Host_Map_f (void)
273 char level[MAX_QPATH];
277 Con_Print("map <levelname> : start a new game (kicks off all players)\n");
281 if (cmd_source != src_command)
284 cls.demonum = -1; // stop demo loop in case this fails
287 Host_ShutdownServer();
292 svs.serverflags = 0; // haven't completed an episode yet
293 allowcheats = sv_cheats.integer != 0;
294 strlcpy(level, Cmd_Argv(1), sizeof(level));
295 SV_SpawnServer(level);
296 if (sv.active && cls.state == ca_disconnected)
297 CL_EstablishConnection("local:1");
299 #ifdef AUTODEMO_BROKEN
300 // if cl_autodemo is set, automatically start recording a demo if one isn't being recorded already
301 if (cl_autodemo.integer && !cls.demorecording)
303 char demofile[MAX_OSPATH];
305 dpsnprintf (demofile, sizeof(demofile), "%s_%s.dem", Sys_TimeString (cl_autodemo_nameformat.string), level);
307 Con_Printf ("Recording to %s.\n", demofile);
309 cls.demofile = FS_Open (demofile, "wb", false, false);
313 FS_Printf (cls.demofile, "%i\n", cls.forcetrack);
316 Con_Print ("ERROR: couldn't open.\n");
318 cls.demorecording = true;
327 Goes to a new map, taking all clients along
330 void Host_Changelevel_f (void)
332 char level[MAX_QPATH];
336 Con_Print("changelevel <levelname> : continue game on a new level\n");
344 if (cmd_source != src_command)
351 SV_SaveSpawnparms ();
353 allowcheats = sv_cheats.integer != 0;
354 strlcpy(level, Cmd_Argv(1), sizeof(level));
355 SV_SpawnServer(level);
356 if (sv.active && cls.state == ca_disconnected)
357 CL_EstablishConnection("local:1");
364 Restarts the current server for a dead player
367 void Host_Restart_f (void)
369 char mapname[MAX_QPATH];
373 Con_Print("restart : restart current level\n");
378 Con_Print("Only the server may restart\n");
381 if (cmd_source != src_command)
387 allowcheats = sv_cheats.integer != 0;
388 strlcpy(mapname, sv.name, sizeof(mapname));
389 SV_SpawnServer(mapname);
390 if (sv.active && cls.state == ca_disconnected)
391 CL_EstablishConnection("local:1");
398 This command causes the client to wait for the signon messages again.
399 This is sent just before a server changes levels
402 void Host_Reconnect_f (void)
404 if (cls.protocol == PROTOCOL_QUAKEWORLD)
406 if (cls.qw_downloadmemory) // don't change when downloading
413 if (cls.state == ca_connected && cls.signon < SIGNONS)
415 Con_Printf("reconnecting...\n");
416 MSG_WriteChar(&cls.netcon->message, qw_clc_stringcmd);
417 MSG_WriteString(&cls.netcon->message, "new");
422 // if we have connected to a server recently, the userinfo
423 // will still contain its IP address, so get the address...
424 InfoString_GetValue(cls.userinfo, "*ip", temp, sizeof(temp));
426 CL_EstablishConnection(temp);
428 Con_Printf("Reconnect to what server? (you have not connected to a server yet)\n");
436 Con_Print("reconnect : wait for signon messages again\n");
441 Con_Print("reconnect: no signon, ignoring reconnect\n");
444 cls.signon = 0; // need new connection messages
449 =====================
452 User command to connect to server
453 =====================
455 void Host_Connect_f (void)
459 Con_Print("connect <serveraddress> : connect to a multiplayer game\n");
462 CL_EstablishConnection(Cmd_Argv(1));
467 ===============================================================================
471 ===============================================================================
474 #define SAVEGAME_VERSION 5
480 Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
483 void Host_SavegameComment (char *text)
488 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
490 // LordHavoc: added min() to prevent overflow
491 memcpy (text, cl.levelname, min(strlen(cl.levelname), SAVEGAME_COMMENT_LENGTH));
492 sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
493 memcpy (text+22, kills, strlen(kills));
494 // convert space to _ to make stdio happy
495 // LordHavoc: convert control characters to _ as well
496 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
499 text[SAVEGAME_COMMENT_LENGTH] = '\0';
508 void Host_Savegame_f (void)
510 char name[MAX_QPATH];
513 char comment[SAVEGAME_COMMENT_LENGTH+1];
515 if (cmd_source != src_command)
518 if (cls.state != ca_connected || !sv.active)
520 Con_Print("Not playing a local game.\n");
526 Con_Print("Can't save in intermission.\n");
530 for (i = 0;i < svs.maxclients;i++)
532 if (svs.clients[i].active)
536 Con_Print("Can't save multiplayer games.\n");
539 if (svs.clients[i].edict->fields.server->deadflag)
541 Con_Print("Can't savegame with a dead player\n");
549 Con_Print("save <savename> : save a game\n");
553 if (strstr(Cmd_Argv(1), ".."))
555 Con_Print("Relative pathnames are not allowed.\n");
559 strlcpy (name, Cmd_Argv(1), sizeof (name));
560 FS_DefaultExtension (name, ".sav", sizeof (name));
562 Con_Printf("Saving game to %s...\n", name);
563 f = FS_Open (name, "wb", false, false);
566 Con_Print("ERROR: couldn't open.\n");
570 FS_Printf(f, "%i\n", SAVEGAME_VERSION);
571 Host_SavegameComment (comment);
572 FS_Printf(f, "%s\n", comment);
573 for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
574 FS_Printf(f, "%f\n", svs.clients[0].spawn_parms[i]);
575 FS_Printf(f, "%d\n", current_skill);
576 FS_Printf(f, "%s\n", sv.name);
577 FS_Printf(f, "%f\n",sv.time);
579 // write the light styles
580 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
582 if (sv.lightstyles[i][0])
583 FS_Printf(f, "%s\n", sv.lightstyles[i]);
590 PRVM_ED_WriteGlobals (f);
591 for (i=0 ; i<prog->num_edicts ; i++)
592 PRVM_ED_Write (f, PRVM_EDICT_NUM(i));
597 Con_Print("done.\n");
606 void Host_Loadgame_f (void)
608 char filename[MAX_QPATH];
609 char mapname[MAX_QPATH];
619 float spawn_parms[NUM_SPAWN_PARMS];
621 if (cmd_source != src_command)
626 Con_Print("load <savename> : load a game\n");
630 strlcpy (filename, Cmd_Argv(1), sizeof(filename));
631 FS_DefaultExtension (filename, ".sav", sizeof (filename));
633 Con_Printf("Loading game from %s...\n", filename);
635 cls.demonum = -1; // stop demo loop in case this fails
637 t = text = (char *)FS_LoadFile (filename, tempmempool, false, NULL);
640 Con_Print("ERROR: couldn't open.\n");
645 COM_ParseTokenConsole(&t);
646 version = atoi(com_token);
647 if (version != SAVEGAME_VERSION)
650 Con_Printf("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
655 // this is a little hard to parse, as : is a separator in COM_ParseToken,
656 // so use the console parser instead
657 COM_ParseTokenConsole(&t);
659 for (i = 0;i < NUM_SPAWN_PARMS;i++)
661 COM_ParseTokenConsole(&t);
662 spawn_parms[i] = atof(com_token);
665 COM_ParseTokenConsole(&t);
666 // this silliness is so we can load 1.06 save files, which have float skill values
667 current_skill = (int)(atof(com_token) + 0.5);
668 Cvar_SetValue ("skill", (float)current_skill);
671 COM_ParseTokenConsole(&t);
672 strlcpy (mapname, com_token, sizeof(mapname));
675 COM_ParseTokenConsole(&t);
676 time = atof(com_token);
678 allowcheats = sv_cheats.integer != 0;
680 SV_SpawnServer (mapname);
684 Con_Print("Couldn't load map\n");
687 sv.paused = true; // pause until all clients connect
690 // load the light styles
692 for (i = 0;i < MAX_LIGHTSTYLES;i++)
696 COM_ParseTokenConsole(&t);
697 // if this is a 64 lightstyle savegame produced by Quake, stop now
698 // we have to check this because darkplaces saves 256 lightstyle savegames
699 if (com_token[0] == '{')
704 strlcpy(sv.lightstyles[i], com_token, sizeof(sv.lightstyles[i]));
707 // now skip everything before the first opening brace
708 // (this is for forward compatibility, so that older versions (at
709 // least ones with this fix) can load savegames with extra data before the
710 // first brace, as might be produced by a later engine version)
714 COM_ParseTokenConsole(&t);
715 if (com_token[0] == '{')
722 // load the edicts out of the savegame file
729 while (COM_ParseTokenConsole(&t))
730 if (!strcmp(com_token, "}"))
732 if (!COM_ParseTokenConsole(&start))
737 if (strcmp(com_token,"{"))
740 Host_Error ("First token isn't a brace");
745 // parse the global vars
746 PRVM_ED_ParseGlobals (start);
751 if (entnum >= MAX_EDICTS)
754 Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)", MAX_EDICTS);
756 while (entnum >= prog->max_edicts)
757 //SV_IncreaseEdicts();
758 PRVM_MEM_IncreaseEdicts();
759 ent = PRVM_EDICT_NUM(entnum);
760 memset (ent->fields.server, 0, prog->progs->entityfields * 4);
761 ent->priv.server->free = false;
762 PRVM_ED_ParseEdict (start, ent);
764 // link it into the bsp tree
765 if (!ent->priv.server->free)
766 SV_LinkEdict (ent, false);
773 prog->num_edicts = entnum;
776 for (i = 0;i < NUM_SPAWN_PARMS;i++)
777 svs.clients[0].spawn_parms[i] = spawn_parms[i];
781 // make sure we're connected to loopback
782 if (cls.state == ca_disconnected || !(cls.state == ca_connected && cls.netcon != NULL && LHNETADDRESS_GetAddressType(&cls.netcon->peeraddress) == LHNETADDRESSTYPE_LOOP))
783 CL_EstablishConnection("local:1");
786 //============================================================================
789 ======================
791 ======================
793 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player", "internal storage cvar for current player name (changed by name command)"};
794 void Host_Name_f (void)
797 char newName[sizeof(host_client->name)];
799 if (Cmd_Argc () == 1)
801 Con_Printf("\"name\" is \"%s\"\n", cl_name.string);
805 if (Cmd_Argc () == 2)
806 strlcpy (newName, Cmd_Argv(1), sizeof (newName));
808 strlcpy (newName, Cmd_Args(), sizeof (newName));
810 for (i = 0, j = 0;newName[i];i++)
811 if (newName[i] != '\r' && newName[i] != '\n')
812 newName[j++] = newName[i];
815 if (cmd_source == src_command)
817 Cvar_Set ("_cl_name", newName);
818 CL_SetInfo("name", newName, true, false, false, false);
822 if (sv.time < host_client->nametime)
824 SV_ClientPrintf("You can't change name more than once every 5 seconds!\n");
828 host_client->nametime = sv.time + 5;
830 // point the string back at updateclient->name to keep it safe
831 strlcpy (host_client->name, newName, sizeof (host_client->name));
832 host_client->edict->fields.server->netname = PRVM_SetEngineString(host_client->name);
833 if (strcmp(host_client->old_name, host_client->name))
835 if (host_client->spawned)
836 SV_BroadcastPrintf("%s changed name to %s\n", host_client->old_name, host_client->name);
837 strlcpy(host_client->old_name, host_client->name, sizeof(host_client->old_name));
838 // send notification to all clients
839 MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
840 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
841 MSG_WriteString (&sv.reliable_datagram, host_client->name);
846 ======================
848 ======================
850 cvar_t cl_playermodel = {CVAR_SAVE, "_cl_playermodel", "", "internal storage cvar for current player model in Nexuiz (changed by playermodel command)"};
851 // the old cl_playermodel in cl_main has been renamed to __cl_playermodel
852 void Host_Playermodel_f (void)
855 char newPath[sizeof(host_client->playermodel)];
857 if (Cmd_Argc () == 1)
859 Con_Printf("\"playermodel\" is \"%s\"\n", cl_playermodel.string);
863 if (Cmd_Argc () == 2)
864 strlcpy (newPath, Cmd_Argv(1), sizeof (newPath));
866 strlcpy (newPath, Cmd_Args(), sizeof (newPath));
868 for (i = 0, j = 0;newPath[i];i++)
869 if (newPath[i] != '\r' && newPath[i] != '\n')
870 newPath[j++] = newPath[i];
873 if (cmd_source == src_command)
875 Cvar_Set ("_cl_playermodel", newPath);
876 CL_SetInfo("playermodel", newPath, true, false, false, false);
881 if (sv.time < host_client->nametime)
883 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
887 host_client->nametime = sv.time + 5;
890 // point the string back at updateclient->name to keep it safe
891 strlcpy (host_client->playermodel, newPath, sizeof (host_client->playermodel));
892 if( eval_playermodel )
893 PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_playermodel)->string = PRVM_SetEngineString(host_client->playermodel);
894 if (strcmp(host_client->old_model, host_client->playermodel))
896 strlcpy(host_client->old_model, host_client->playermodel, sizeof(host_client->old_model));
897 /*// send notification to all clients
898 MSG_WriteByte (&sv.reliable_datagram, svc_updatepmodel);
899 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
900 MSG_WriteString (&sv.reliable_datagram, host_client->playermodel);*/
905 ======================
907 ======================
909 cvar_t cl_playerskin = {CVAR_SAVE, "_cl_playerskin", "", "internal storage cvar for current player skin in Nexuiz (changed by playerskin command)"};
910 void Host_Playerskin_f (void)
913 char newPath[sizeof(host_client->playerskin)];
915 if (Cmd_Argc () == 1)
917 Con_Printf("\"playerskin\" is \"%s\"\n", cl_playerskin.string);
921 if (Cmd_Argc () == 2)
922 strlcpy (newPath, Cmd_Argv(1), sizeof (newPath));
924 strlcpy (newPath, Cmd_Args(), sizeof (newPath));
926 for (i = 0, j = 0;newPath[i];i++)
927 if (newPath[i] != '\r' && newPath[i] != '\n')
928 newPath[j++] = newPath[i];
931 if (cmd_source == src_command)
933 Cvar_Set ("_cl_playerskin", newPath);
934 CL_SetInfo("playerskin", newPath, true, false, false, false);
939 if (sv.time < host_client->nametime)
941 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
945 host_client->nametime = sv.time + 5;
948 // point the string back at updateclient->name to keep it safe
949 strlcpy (host_client->playerskin, newPath, sizeof (host_client->playerskin));
950 if( eval_playerskin )
951 PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_playerskin)->string = PRVM_SetEngineString(host_client->playerskin);
952 if (strcmp(host_client->old_skin, host_client->playerskin))
954 //if (host_client->spawned)
955 // SV_BroadcastPrintf("%s changed skin to %s\n", host_client->name, host_client->playerskin);
956 strlcpy(host_client->old_skin, host_client->playerskin, sizeof(host_client->old_skin));
957 /*// send notification to all clients
958 MSG_WriteByte (&sv.reliable_datagram, svc_updatepskin);
959 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
960 MSG_WriteString (&sv.reliable_datagram, host_client->playerskin);*/
964 void Host_Version_f (void)
966 Con_Printf("Version: %s build %s\n", gamename, buildstring);
969 void Host_Say(qboolean teamonly)
975 // LordHavoc: long say messages
977 qboolean fromServer = false;
979 if (cmd_source == src_command)
981 if (cls.state == ca_dedicated)
988 Cmd_ForwardToServer ();
996 if (!teamplay.integer)
1006 // note this uses the chat prefix \001
1008 dpsnprintf (text, sizeof(text), "\001%s" STRING_COLOR_DEFAULT_STR ": %s", host_client->name, p1);
1010 dpsnprintf (text, sizeof(text), "\001<%s" STRING_COLOR_DEFAULT_STR "> %s", hostname.string, p1);
1011 p2 = text + strlen(text);
1012 while ((const char *)p2 > (const char *)text && (p2[-1] == '\r' || p2[-1] == '\n' || (p2[-1] == '\"' && quoted)))
1014 if (p2[-1] == '\"' && quoted)
1019 strlcat(text, "\n", sizeof(text));
1021 // note: save is not a valid edict if fromServer is true
1023 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
1024 if (host_client->spawned && (!teamonly || host_client->edict->fields.server->team == save->edict->fields.server->team))
1025 SV_ClientPrint(text);
1028 if (cls.state == ca_dedicated)
1029 Con_Print(&text[1]);
1033 void Host_Say_f(void)
1039 void Host_Say_Team_f(void)
1045 void Host_Tell_f(void)
1049 const char *p1, *p2;
1050 char text[MAX_INPUTLINE]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
1051 qboolean fromServer = false;
1053 if (cmd_source == src_command)
1055 if (cls.state == ca_dedicated)
1059 Cmd_ForwardToServer ();
1064 if (Cmd_Argc () < 3)
1067 // note this uses the chat prefix \001
1069 sprintf (text, "\001%s tells you: ", host_client->name);
1071 sprintf (text, "\001<%s tells you> ", hostname.string);
1074 p2 = p1 + strlen(p1);
1075 // remove the target name
1076 while (p1 < p2 && *p1 != ' ')
1078 while (p1 < p2 && *p1 == ' ')
1080 // remove trailing newlines
1081 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
1083 // remove quotes if present
1089 else if (fromServer)
1090 Con_Print("Host_Tell: missing end quote\n");
1092 SV_ClientPrint("Host_Tell: missing end quote\n");
1094 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
1096 for (j = (int)strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
1102 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
1103 if (host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1)))
1104 SV_ClientPrint(text);
1114 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0", "internal storage cvar for current player colors (changed by color command)"};
1115 void Host_Color(int changetop, int changebottom)
1117 int top, bottom, playercolor;
1119 func_t SV_ChangeTeam;
1121 // get top and bottom either from the provided values or the current values
1122 // (allows changing only top or bottom, or both at once)
1123 top = changetop >= 0 ? changetop : (cl_color.integer >> 4);
1124 bottom = changebottom >= 0 ? changebottom : cl_color.integer;
1128 // LordHavoc: allowing skin colormaps 14 and 15 by commenting this out
1134 playercolor = top*16 + bottom;
1136 if (cmd_source == src_command)
1138 Cvar_SetValueQuick(&cl_color, playercolor);
1140 CL_SetInfo("topcolor", va("%i", top), true, false, false, false);
1141 if (changebottom >= 0)
1142 CL_SetInfo("bottomcolor", va("%i", bottom), true, false, false, false);
1143 if (cls.protocol != PROTOCOL_QUAKEWORLD && cls.netcon)
1145 MSG_WriteByte(&cls.netcon->message, clc_stringcmd);
1146 MSG_WriteString(&cls.netcon->message, va("color %i %i", top, bottom));
1151 if (cls.protocol == PROTOCOL_QUAKEWORLD)
1154 if (host_client->edict && (f = PRVM_ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - prog->functions)))
1156 Con_DPrint("Calling SV_ChangeTeam\n");
1157 prog->globals.server->time = sv.time;
1158 prog->globals.generic[OFS_PARM0] = playercolor;
1159 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1160 PRVM_ExecuteProgram (SV_ChangeTeam, "QC function SV_ChangeTeam is missing");
1165 if (host_client->edict)
1167 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_clientcolors)))
1168 val->_float = playercolor;
1169 host_client->edict->fields.server->team = bottom + 1;
1171 host_client->colors = playercolor;
1172 if (host_client->old_colors != host_client->colors)
1174 host_client->old_colors = host_client->colors;
1175 // send notification to all clients
1176 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
1177 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
1178 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
1183 void Host_Color_f(void)
1187 if (Cmd_Argc() == 1)
1189 Con_Printf("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
1190 Con_Print("color <0-15> [0-15]\n");
1194 if (Cmd_Argc() == 2)
1195 top = bottom = atoi(Cmd_Argv(1));
1198 top = atoi(Cmd_Argv(1));
1199 bottom = atoi(Cmd_Argv(2));
1201 Host_Color(top, bottom);
1204 void Host_TopColor_f(void)
1206 if (Cmd_Argc() == 1)
1208 Con_Printf("\"topcolor\" is \"%i\"\n", (cl_color.integer >> 4) & 15);
1209 Con_Print("topcolor <0-15>\n");
1213 Host_Color(atoi(Cmd_Argv(1)), -1);
1216 void Host_BottomColor_f(void)
1218 if (Cmd_Argc() == 1)
1220 Con_Printf("\"bottomcolor\" is \"%i\"\n", cl_color.integer & 15);
1221 Con_Print("bottomcolor <0-15>\n");
1225 Host_Color(-1, atoi(Cmd_Argv(1)));
1228 cvar_t cl_rate = {CVAR_SAVE, "_cl_rate", "10000", "internal storage cvar for current rate (changed by rate command)"};
1229 void Host_Rate_f(void)
1233 if (Cmd_Argc() != 2)
1235 Con_Printf("\"rate\" is \"%i\"\n", cl_rate.integer);
1236 Con_Print("rate <500-25000>\n");
1240 rate = atoi(Cmd_Argv(1));
1242 if (cmd_source == src_command)
1244 Cvar_SetValue ("_cl_rate", bound(NET_MINRATE, rate, NET_MAXRATE));
1245 CL_SetInfo("rate", va("%i", rate), true, false, false, false);
1249 host_client->rate = rate;
1257 void Host_Kill_f (void)
1259 if (cmd_source == src_command)
1261 Cmd_ForwardToServer ();
1265 if (host_client->edict->fields.server->health <= 0)
1267 SV_ClientPrint("Can't suicide -- already dead!\n");
1271 prog->globals.server->time = sv.time;
1272 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1273 PRVM_ExecuteProgram (prog->globals.server->ClientKill, "QC function ClientKill is missing");
1282 void Host_Pause_f (void)
1285 if (cmd_source == src_command)
1287 Cmd_ForwardToServer ();
1290 if (!pausable.integer)
1291 SV_ClientPrint("Pause not allowed.\n");
1295 SV_BroadcastPrintf("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
1296 // send notification to all clients
1297 MSG_WriteByte(&sv.reliable_datagram, svc_setpause);
1298 MSG_WriteByte(&sv.reliable_datagram, sv.paused);
1303 ======================
1305 LordHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
1306 LordHavoc: correction, Mindcrime will be removing pmodel in the future, but it's still stuck here for compatibility.
1307 ======================
1309 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0", "internal storage cvar for current player model number in nehahra (changed by pmodel command)"};
1310 static void Host_PModel_f (void)
1315 if (Cmd_Argc () == 1)
1317 Con_Printf("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
1320 i = atoi(Cmd_Argv(1));
1322 if (cmd_source == src_command)
1324 if (cl_pmodel.integer == i)
1326 Cvar_SetValue ("_cl_pmodel", i);
1327 if (cls.state == ca_connected)
1328 Cmd_ForwardToServer ();
1332 if (host_client->edict && (val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_pmodel)))
1336 //===========================================================================
1344 void Host_PreSpawn_f (void)
1346 if (cmd_source == src_command)
1348 Con_Print("prespawn is not valid from the console\n");
1352 if (host_client->spawned)
1354 Con_Print("prespawn not valid -- already spawned\n");
1358 if (host_client->netconnection)
1360 SZ_Write (&host_client->netconnection->message, sv.signon.data, sv.signon.cursize);
1361 MSG_WriteByte (&host_client->netconnection->message, svc_signonnum);
1362 MSG_WriteByte (&host_client->netconnection->message, 2);
1365 // reset the name change timer because the client will send name soon
1366 host_client->nametime = 0;
1374 void Host_Spawn_f (void)
1380 int stats[MAX_CL_STATS];
1382 if (cmd_source == src_command)
1384 Con_Print("spawn is not valid from the console\n");
1388 if (host_client->spawned)
1390 Con_Print("Spawn not valid -- already spawned\n");
1394 // reset name change timer again because they might want to change name
1395 // again in the first 5 seconds after connecting
1396 host_client->nametime = 0;
1398 // LordHavoc: moved this above the QC calls at FrikaC's request
1399 // LordHavoc: commented this out
1400 //if (host_client->netconnection)
1401 // SZ_Clear (&host_client->netconnection->message);
1403 // run the entrance script
1406 // loaded games are fully initialized already
1407 // if this is the last client to be connected, unpause
1410 if ((f = PRVM_ED_FindFunction ("RestoreGame")))
1411 if ((RestoreGame = (func_t)(f - prog->functions)))
1413 Con_DPrint("Calling RestoreGame\n");
1414 prog->globals.server->time = sv.time;
1415 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1416 PRVM_ExecuteProgram (RestoreGame, "QC function RestoreGame is missing");
1421 //Con_Printf("Host_Spawn_f: host_client->edict->netname = %s, host_client->edict->netname = %s, host_client->name = %s\n", PRVM_GetString(host_client->edict->fields.server->netname), PRVM_GetString(host_client->edict->fields.server->netname), host_client->name);
1423 // copy spawn parms out of the client_t
1424 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1425 (&prog->globals.server->parm1)[i] = host_client->spawn_parms[i];
1427 // call the spawn function
1428 host_client->clientconnectcalled = true;
1429 prog->globals.server->time = sv.time;
1430 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1431 PRVM_ExecuteProgram (prog->globals.server->ClientConnect, "QC function ClientConnect is missing");
1433 if ((Sys_DoubleTime() - host_client->connecttime) <= sv.time)
1434 Con_Printf("%s entered the game\n", host_client->name);
1436 PRVM_ExecuteProgram (prog->globals.server->PutClientInServer, "QC function PutClientInServer is missing");
1439 if (!host_client->netconnection)
1442 // send time of update
1443 MSG_WriteByte (&host_client->netconnection->message, svc_time);
1444 MSG_WriteFloat (&host_client->netconnection->message, sv.time);
1446 // send all current names, colors, and frag counts
1447 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
1449 if (!client->active)
1451 MSG_WriteByte (&host_client->netconnection->message, svc_updatename);
1452 MSG_WriteByte (&host_client->netconnection->message, i);
1453 MSG_WriteString (&host_client->netconnection->message, client->name);
1454 MSG_WriteByte (&host_client->netconnection->message, svc_updatefrags);
1455 MSG_WriteByte (&host_client->netconnection->message, i);
1456 MSG_WriteShort (&host_client->netconnection->message, client->frags);
1457 MSG_WriteByte (&host_client->netconnection->message, svc_updatecolors);
1458 MSG_WriteByte (&host_client->netconnection->message, i);
1459 MSG_WriteByte (&host_client->netconnection->message, client->colors);
1462 // send all current light styles
1463 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1465 if (sv.lightstyles[i][0])
1467 MSG_WriteByte (&host_client->netconnection->message, svc_lightstyle);
1468 MSG_WriteByte (&host_client->netconnection->message, (char)i);
1469 MSG_WriteString (&host_client->netconnection->message, sv.lightstyles[i]);
1474 MSG_WriteByte (&host_client->netconnection->message, svc_updatestat);
1475 MSG_WriteByte (&host_client->netconnection->message, STAT_TOTALSECRETS);
1476 MSG_WriteLong (&host_client->netconnection->message, (int)prog->globals.server->total_secrets);
1478 MSG_WriteByte (&host_client->netconnection->message, svc_updatestat);
1479 MSG_WriteByte (&host_client->netconnection->message, STAT_TOTALMONSTERS);
1480 MSG_WriteLong (&host_client->netconnection->message, (int)prog->globals.server->total_monsters);
1482 MSG_WriteByte (&host_client->netconnection->message, svc_updatestat);
1483 MSG_WriteByte (&host_client->netconnection->message, STAT_SECRETS);
1484 MSG_WriteLong (&host_client->netconnection->message, (int)prog->globals.server->found_secrets);
1486 MSG_WriteByte (&host_client->netconnection->message, svc_updatestat);
1487 MSG_WriteByte (&host_client->netconnection->message, STAT_MONSTERS);
1488 MSG_WriteLong (&host_client->netconnection->message, (int)prog->globals.server->killed_monsters);
1491 // Never send a roll angle, because savegames can catch the server
1492 // in a state where it is expecting the client to correct the angle
1493 // and it won't happen if the game was just loaded, so you wind up
1494 // with a permanent head tilt
1497 MSG_WriteByte (&host_client->netconnection->message, svc_setangle);
1498 MSG_WriteAngle (&host_client->netconnection->message, host_client->edict->fields.server->v_angle[0], sv.protocol);
1499 MSG_WriteAngle (&host_client->netconnection->message, host_client->edict->fields.server->v_angle[1], sv.protocol);
1500 MSG_WriteAngle (&host_client->netconnection->message, 0, sv.protocol);
1501 sv.loadgame = false; // we're basically done with loading now
1505 MSG_WriteByte (&host_client->netconnection->message, svc_setangle);
1506 MSG_WriteAngle (&host_client->netconnection->message, host_client->edict->fields.server->angles[0], sv.protocol);
1507 MSG_WriteAngle (&host_client->netconnection->message, host_client->edict->fields.server->angles[1], sv.protocol);
1508 MSG_WriteAngle (&host_client->netconnection->message, 0, sv.protocol);
1511 SV_WriteClientdataToMessage (host_client, host_client->edict, &host_client->netconnection->message, stats);
1513 MSG_WriteByte (&host_client->netconnection->message, svc_signonnum);
1514 MSG_WriteByte (&host_client->netconnection->message, 3);
1522 void Host_Begin_f (void)
1524 if (cmd_source == src_command)
1526 Con_Print("begin is not valid from the console\n");
1530 host_client->spawned = true;
1533 //===========================================================================
1540 Kicks a user off of the server
1543 void Host_Kick_f (void)
1546 const char *message = NULL;
1549 qboolean byNumber = false;
1551 if (cmd_source != src_command || !sv.active)
1557 if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1559 i = (int)(atof(Cmd_Argv(2)) - 1);
1560 if (i < 0 || i >= svs.maxclients || !(host_client = svs.clients + i)->active)
1566 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1568 if (!host_client->active)
1570 if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1575 if (i < svs.maxclients)
1577 if (cmd_source == src_command)
1579 if (cls.state == ca_dedicated)
1582 who = cl_name.string;
1587 // can't kick yourself!
1588 if (host_client == save)
1593 message = Cmd_Args();
1594 COM_ParseTokenConsole(&message);
1597 message++; // skip the #
1598 while (*message == ' ') // skip white space
1600 message += strlen(Cmd_Argv(2)); // skip the number
1602 while (*message && *message == ' ')
1606 SV_ClientPrintf("Kicked by %s: %s\n", who, message);
1608 SV_ClientPrintf("Kicked by %s\n", who);
1609 SV_DropClient (false); // kicked
1617 ===============================================================================
1621 ===============================================================================
1629 void Host_Give_f (void)
1635 if (cmd_source == src_command)
1637 Cmd_ForwardToServer ();
1643 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
1648 v = atoi (Cmd_Argv(2));
1662 // MED 01/04/97 added hipnotic give stuff
1663 if (gamemode == GAME_HIPNOTIC)
1668 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | HIT_PROXIMITY_GUN;
1670 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | IT_GRENADE_LAUNCHER;
1672 else if (t[0] == '9')
1673 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | HIT_LASER_CANNON;
1674 else if (t[0] == '0')
1675 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | HIT_MJOLNIR;
1676 else if (t[0] >= '2')
1677 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | (IT_SHOTGUN << (t[0] - '2'));
1682 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | (IT_SHOTGUN << (t[0] - '2'));
1687 if (gamemode == GAME_ROGUE && (val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_shells1)))
1690 host_client->edict->fields.server->ammo_shells = v;
1693 if (gamemode == GAME_ROGUE)
1695 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_nails1)))
1698 if (host_client->edict->fields.server->weapon <= IT_LIGHTNING)
1699 host_client->edict->fields.server->ammo_nails = v;
1704 host_client->edict->fields.server->ammo_nails = v;
1708 if (gamemode == GAME_ROGUE)
1710 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_lava_nails);
1714 if (host_client->edict->fields.server->weapon > IT_LIGHTNING)
1715 host_client->edict->fields.server->ammo_nails = v;
1720 if (gamemode == GAME_ROGUE)
1722 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_rockets1);
1726 if (host_client->edict->fields.server->weapon <= IT_LIGHTNING)
1727 host_client->edict->fields.server->ammo_rockets = v;
1732 host_client->edict->fields.server->ammo_rockets = v;
1736 if (gamemode == GAME_ROGUE)
1738 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_multi_rockets);
1742 if (host_client->edict->fields.server->weapon > IT_LIGHTNING)
1743 host_client->edict->fields.server->ammo_rockets = v;
1748 host_client->edict->fields.server->health = v;
1751 if (gamemode == GAME_ROGUE)
1753 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_cells1);
1757 if (host_client->edict->fields.server->weapon <= IT_LIGHTNING)
1758 host_client->edict->fields.server->ammo_cells = v;
1763 host_client->edict->fields.server->ammo_cells = v;
1767 if (gamemode == GAME_ROGUE)
1769 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_plasma);
1773 if (host_client->edict->fields.server->weapon > IT_LIGHTNING)
1774 host_client->edict->fields.server->ammo_cells = v;
1781 prvm_edict_t *FindViewthing (void)
1786 for (i=0 ; i<prog->num_edicts ; i++)
1788 e = PRVM_EDICT_NUM(i);
1789 if (!strcmp (PRVM_GetString(e->fields.server->classname), "viewthing"))
1792 Con_Print("No viewthing on map\n");
1801 void Host_Viewmodel_f (void)
1810 e = FindViewthing ();
1815 m = Mod_ForName (Cmd_Argv(1), false, true, false);
1816 if (!m || !m->loaded || !m->Draw)
1818 Con_Printf("viewmodel: can't load %s\n", Cmd_Argv(1));
1822 e->fields.server->frame = 0;
1823 cl.model_precache[(int)e->fields.server->modelindex] = m;
1831 void Host_Viewframe_f (void)
1841 e = FindViewthing ();
1845 m = cl.model_precache[(int)e->fields.server->modelindex];
1847 f = atoi(Cmd_Argv(1));
1848 if (f >= m->numframes)
1851 e->fields.server->frame = f;
1855 void PrintFrameName (model_t *m, int frame)
1858 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1860 Con_Printf("frame %i\n", frame);
1868 void Host_Viewnext_f (void)
1877 e = FindViewthing ();
1881 m = cl.model_precache[(int)e->fields.server->modelindex];
1883 e->fields.server->frame = e->fields.server->frame + 1;
1884 if (e->fields.server->frame >= m->numframes)
1885 e->fields.server->frame = m->numframes - 1;
1887 PrintFrameName (m, (int)e->fields.server->frame);
1895 void Host_Viewprev_f (void)
1904 e = FindViewthing ();
1909 m = cl.model_precache[(int)e->fields.server->modelindex];
1911 e->fields.server->frame = e->fields.server->frame - 1;
1912 if (e->fields.server->frame < 0)
1913 e->fields.server->frame = 0;
1915 PrintFrameName (m, (int)e->fields.server->frame);
1919 ===============================================================================
1923 ===============================================================================
1932 void Host_Startdemos_f (void)
1936 if (cls.state == ca_dedicated || COM_CheckParm("-listen") || COM_CheckParm("-benchmark") || COM_CheckParm("-demo") || COM_CheckParm("-demolooponly"))
1942 Con_Printf("Max %i demos in demoloop\n", MAX_DEMOS);
1945 Con_Printf("%i demo(s) in loop\n", c);
1947 for (i=1 ; i<c+1 ; i++)
1948 strlcpy (cls.demos[i-1], Cmd_Argv(i), sizeof (cls.demos[i-1]));
1950 // LordHavoc: clear the remaining slots
1951 for (;i <= MAX_DEMOS;i++)
1952 cls.demos[i-1][0] = 0;
1954 if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
1968 Return to looping demos
1971 void Host_Demos_f (void)
1973 if (cls.state == ca_dedicated)
1975 if (cls.demonum == -1)
1985 Return to looping demos
1988 void Host_Stopdemo_f (void)
1990 if (!cls.demoplayback)
1993 Host_ShutdownServer ();
1996 void Host_SendCvar_f (void)
2004 if(!(c = Cvar_FindVar(Cmd_Argv(1))) || (c->flags & CVAR_PRIVATE))
2006 if (cls.state != ca_dedicated)
2007 Cmd_ForwardStringToServer(va("sentcvar %s %s\n", c->name, c->string));
2008 if(!sv.active)// || !SV_ParseClientCommandQC)
2012 if (cls.state != ca_dedicated)
2016 for(;i<svs.maxclients;i++)
2017 if(svs.clients[i].active && svs.clients[i].netconnection)
2019 host_client = &svs.clients[i];
2020 Host_ClientCommands(va("sendcvar %s\n", c->name));
2025 static void MaxPlayers_f(void)
2029 if (Cmd_Argc() != 2)
2031 Con_Printf("\"maxplayers\" is \"%u\"\n", svs.maxclients);
2037 Con_Print("maxplayers can not be changed while a server is running.\n");
2041 n = atoi(Cmd_Argv(1));
2042 n = bound(1, n, MAX_SCOREBOARD);
2043 Con_Printf("\"maxplayers\" set to \"%u\"\n", n);
2046 Mem_Free(svs.clients);
2048 svs.clients = (client_t *)Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients);
2050 Cvar_Set ("deathmatch", "0");
2052 Cvar_Set ("deathmatch", "1");
2055 //=============================================================================
2057 // QuakeWorld commands
2060 =====================
2063 Send the rest of the command line over as
2064 an unconnected command.
2065 =====================
2067 void Host_Rcon_f (void) // credit: taken from QuakeWorld
2071 lhnetsocket_t *mysocket;
2073 if (!rcon_password.string || !rcon_password.string[0])
2075 Con_Printf ("You must set rcon_password before issuing an rcon command.\n");
2079 for (i = 0;rcon_password.string[i];i++)
2081 if (rcon_password.string[i] <= ' ')
2083 Con_Printf("rcon_password is not allowed to have any whitespace.\n");
2089 to = cls.netcon->peeraddress;
2092 if (!rcon_address.string[0])
2094 Con_Printf ("You must either be connected, or set the rcon_address cvar to issue rcon commands\n");
2097 LHNETADDRESS_FromString(&to, rcon_address.string, sv_netport.integer);
2099 mysocket = NetConn_ChooseClientSocketForAddress(&to);
2102 // simply put together the rcon packet and send it
2103 NetConn_WriteString(mysocket, va("\377\377\377\377rcon %s %s", rcon_password.string, Cmd_Args()), &to);
2108 ====================
2111 user <name or userid>
2113 Dump userdata / masterdata for a user
2114 ====================
2116 void Host_User_f (void) // credit: taken from QuakeWorld
2121 if (Cmd_Argc() != 2)
2123 Con_Printf ("Usage: user <username / userid>\n");
2127 uid = atoi(Cmd_Argv(1));
2129 for (i = 0;i < cl.maxclients;i++)
2131 if (!cl.scores[i].name[0])
2133 if (cl.scores[i].qw_userid == uid || !strcasecmp(cl.scores[i].name, Cmd_Argv(1)))
2135 InfoString_Print(cl.scores[i].qw_userinfo);
2139 Con_Printf ("User not in server.\n");
2143 ====================
2146 Dump userids for all current players
2147 ====================
2149 void Host_Users_f (void) // credit: taken from QuakeWorld
2155 Con_Printf ("userid frags name\n");
2156 Con_Printf ("------ ----- ----\n");
2157 for (i = 0;i < cl.maxclients;i++)
2159 if (cl.scores[i].name[0])
2161 Con_Printf ("%6i %4i %s\n", cl.scores[i].qw_userid, cl.scores[i].frags, cl.scores[i].name);
2166 Con_Printf ("%i total users\n", c);
2171 Host_FullServerinfo_f
2173 Sent by server when serverinfo changes
2176 // TODO: shouldn't this be a cvar instead?
2177 void Host_FullServerinfo_f (void) // credit: taken from QuakeWorld
2180 if (Cmd_Argc() != 2)
2182 Con_Printf ("usage: fullserverinfo <complete info string>\n");
2186 strlcpy (cl.qw_serverinfo, Cmd_Argv(1), sizeof(cl.qw_serverinfo));
2187 InfoString_GetValue(cl.qw_serverinfo, "teamplay", temp, sizeof(temp));
2188 cl.qw_teamplay = atoi(temp);
2195 Allow clients to change userinfo
2199 void Host_FullInfo_f (void) // credit: taken from QuakeWorld
2206 if (Cmd_Argc() != 2)
2208 Con_Printf ("fullinfo <complete info string>\n");
2218 while (*s && *s != '\\')
2224 Con_Printf ("MISSING VALUE\n");
2230 while (*s && *s != '\\')
2237 CL_SetInfo(key, value, false, false, false, false);
2245 Allow clients to change userinfo
2248 void Host_SetInfo_f (void) // credit: taken from QuakeWorld
2250 if (Cmd_Argc() == 1)
2252 InfoString_Print(cls.userinfo);
2255 if (Cmd_Argc() != 3)
2257 Con_Printf ("usage: setinfo [ <key> <value> ]\n");
2260 CL_SetInfo(Cmd_Argv(1), Cmd_Argv(2), true, false, false, false);
2264 ====================
2267 packet <destination> <contents>
2269 Contents allows \n escape character
2270 ====================
2272 void Host_Packet_f (void) // credit: taken from QuakeWorld
2278 lhnetaddress_t address;
2279 lhnetsocket_t *mysocket;
2281 if (Cmd_Argc() != 3)
2283 Con_Printf ("packet <destination> <contents>\n");
2287 if (!LHNETADDRESS_FromString (&address, Cmd_Argv(1), sv_netport.integer))
2289 Con_Printf ("Bad address\n");
2295 send[0] = send[1] = send[2] = send[3] = 0xff;
2297 l = (int)strlen (in);
2298 for (i=0 ; i<l ; i++)
2300 if (out >= send + sizeof(send) - 1)
2302 if (in[i] == '\\' && in[i+1] == 'n')
2307 else if (in[i] == '\\' && in[i+1] == '0')
2312 else if (in[i] == '\\' && in[i+1] == 't')
2317 else if (in[i] == '\\' && in[i+1] == 'r')
2322 else if (in[i] == '\\' && in[i+1] == '"')
2331 mysocket = NetConn_ChooseClientSocketForAddress(&address);
2333 NetConn_Write(mysocket, send, out - send, &address);
2337 ====================
2340 Send back ping and packet loss update for all current players to this player
2341 ====================
2343 void Host_Pings_f (void)
2345 int i, j, ping, packetloss;
2348 if (cmd_source == src_command)
2350 Cmd_ForwardToServer ();
2353 if (!host_client->netconnection)
2356 if (sv.protocol != PROTOCOL_QUAKEWORLD)
2358 MSG_WriteByte(&host_client->netconnection->message, svc_stufftext);
2359 MSG_WriteUnterminatedString(&host_client->netconnection->message, "pingplreport");
2361 for (i = 0;i < svs.maxclients;i++)
2364 if (svs.clients[i].netconnection)
2365 for (j = 0;j < 100;j++)
2366 packetloss += svs.clients[i].netconnection->packetlost[j];
2367 ping = (int)floor(svs.clients[i].ping*1000+0.5);
2368 ping = bound(0, ping, 9999);
2369 if (sv.protocol == PROTOCOL_QUAKEWORLD)
2371 // send qw_svc_updateping and qw_svc_updatepl messages
2372 MSG_WriteByte(&host_client->netconnection->message, qw_svc_updateping);
2373 MSG_WriteShort(&host_client->netconnection->message, ping);
2374 MSG_WriteByte(&host_client->netconnection->message, qw_svc_updatepl);
2375 MSG_WriteByte(&host_client->netconnection->message, packetloss);
2379 // write the string into the packet as multiple unterminated strings to avoid needing a local buffer
2380 dpsnprintf(temp, sizeof(temp), " %d %d", ping, packetloss);
2381 MSG_WriteUnterminatedString(&host_client->netconnection->message, temp);
2384 if (sv.protocol != PROTOCOL_QUAKEWORLD)
2385 MSG_WriteString(&host_client->netconnection->message, "\n");
2388 void Host_PingPLReport_f(void)
2392 if (l > cl.maxclients)
2394 for (i = 0;i < l;i++)
2396 cl.scores[i].qw_ping = atoi(Cmd_Argv(1+i*2));
2397 cl.scores[i].qw_packetloss = atoi(Cmd_Argv(1+i*2+1));
2401 //=============================================================================
2408 void Host_InitCommands (void)
2410 dpsnprintf(cls.userinfo, sizeof(cls.userinfo), "\\name\\player\\team\\none\\topcolor\\0\\bottomcolor\\0\\rate\\10000\\msg\\1\\noaim\\1\\*ver\\%s", engineversion);
2412 Cmd_AddCommand ("status", Host_Status_f, "print server status information");
2413 Cmd_AddCommand ("quit", Host_Quit_f, "quit the game");
2414 if (gamemode == GAME_NEHAHRA)
2416 Cmd_AddCommand ("max", Host_God_f, "god mode (invulnerability)");
2417 Cmd_AddCommand ("monster", Host_Notarget_f, "notarget mode (monsters do not see you)");
2418 Cmd_AddCommand ("scrag", Host_Fly_f, "fly mode (flight)");
2419 Cmd_AddCommand ("wraith", Host_Noclip_f, "noclip mode (flight without collisions, move through walls)");
2420 Cmd_AddCommand ("gimme", Host_Give_f, "alter inventory");
2424 Cmd_AddCommand ("god", Host_God_f, "god mode (invulnerability)");
2425 Cmd_AddCommand ("notarget", Host_Notarget_f, "notarget mode (monsters do not see you)");
2426 Cmd_AddCommand ("fly", Host_Fly_f, "fly mode (flight)");
2427 Cmd_AddCommand ("noclip", Host_Noclip_f, "noclip mode (flight without collisions, move through walls)");
2428 Cmd_AddCommand ("give", Host_Give_f, "alter inventory");
2430 Cmd_AddCommand ("map", Host_Map_f, "kick everyone off the server and start a new level");
2431 Cmd_AddCommand ("restart", Host_Restart_f, "restart current level");
2432 Cmd_AddCommand ("changelevel", Host_Changelevel_f, "change to another level, bringing along all connected clients");
2433 Cmd_AddCommand ("connect", Host_Connect_f, "connect to a server by IP address or hostname");
2434 Cmd_AddCommand ("reconnect", Host_Reconnect_f, "reset signon level in preparation for a new level (do not use)");
2435 Cmd_AddCommand ("version", Host_Version_f, "print engine version");
2436 Cmd_AddCommand ("say", Host_Say_f, "send a chat message to everyone on the server");
2437 Cmd_AddCommand ("say_team", Host_Say_Team_f, "send a chat message to your team on the server");
2438 Cmd_AddCommand ("tell", Host_Tell_f, "send a chat message to only one person on the server");
2439 Cmd_AddCommand ("kill", Host_Kill_f, "die instantly");
2440 Cmd_AddCommand ("pause", Host_Pause_f, "pause the game (if the server allows pausing)");
2441 Cmd_AddCommand ("kick", Host_Kick_f, "kick a player off the server by number or name");
2442 Cmd_AddCommand ("ping", Host_Ping_f, "print ping times of all players on the server");
2443 Cmd_AddCommand ("load", Host_Loadgame_f, "load a saved game file");
2444 Cmd_AddCommand ("save", Host_Savegame_f, "save the game to a file");
2446 Cmd_AddCommand ("startdemos", Host_Startdemos_f, "start playing back the selected demos sequentially (used at end of startup script)");
2447 Cmd_AddCommand ("demos", Host_Demos_f, "restart looping demos defined by the last startdemos command");
2448 Cmd_AddCommand ("stopdemo", Host_Stopdemo_f, "stop playing or recording demo (like stop command) and return to looping demos");
2450 Cmd_AddCommand ("viewmodel", Host_Viewmodel_f, "change model of viewthing entity in current level");
2451 Cmd_AddCommand ("viewframe", Host_Viewframe_f, "change animation frame of viewthing entity in current level");
2452 Cmd_AddCommand ("viewnext", Host_Viewnext_f, "change to next animation frame of viewthing entity in current level");
2453 Cmd_AddCommand ("viewprev", Host_Viewprev_f, "change to previous animation frame of viewthing entity in current level");
2455 Cvar_RegisterVariable (&cl_name);
2456 Cmd_AddCommand ("name", Host_Name_f, "change your player name");
2457 Cvar_RegisterVariable (&cl_color);
2458 Cmd_AddCommand ("color", Host_Color_f, "change your player shirt and pants colors");
2459 Cvar_RegisterVariable (&cl_rate);
2460 Cmd_AddCommand ("rate", Host_Rate_f, "change your network connection speed");
2461 if (gamemode == GAME_NEHAHRA)
2463 Cvar_RegisterVariable (&cl_pmodel);
2464 Cmd_AddCommand ("pmodel", Host_PModel_f, "change your player model choice (Nehahra specific)");
2467 // BLACK: This isnt game specific anymore (it was GAME_NEXUIZ at first)
2468 Cvar_RegisterVariable (&cl_playermodel);
2469 Cmd_AddCommand ("playermodel", Host_Playermodel_f, "change your player model");
2470 Cvar_RegisterVariable (&cl_playerskin);
2471 Cmd_AddCommand ("playerskin", Host_Playerskin_f, "change your player skin number");
2473 Cmd_AddCommand ("prespawn", Host_PreSpawn_f, "signon 1 (client acknowledges that server information has been received)");
2474 Cmd_AddCommand ("spawn", Host_Spawn_f, "signon 2 (client has sent player information, and is asking server to send scoreboard rankings)");
2475 Cmd_AddCommand ("begin", Host_Begin_f, "signon 3 (client asks server to start sending entities, and will go to signon 4 (playing) when the first entity update is received)");
2476 Cmd_AddCommand ("maxplayers", MaxPlayers_f, "sets limit on how many players (or bots) may be connected to the server at once");
2478 Cmd_AddCommand ("sendcvar", Host_SendCvar_f, "sends the value of a cvar to the server as a sentcvar command, for use by QuakeC"); // By [515]
2480 Cvar_RegisterVariable (&rcon_password);
2481 Cvar_RegisterVariable (&rcon_address);
2482 Cmd_AddCommand ("rcon", Host_Rcon_f, "sends a command to the server console (if your rcon_password matches the server's rcon_password), or to the address specified by rcon_address when not connected (again rcon_password must match the server's)");
2483 Cmd_AddCommand ("user", Host_User_f, "prints additional information about a player number or name on the scoreboard");
2484 Cmd_AddCommand ("users", Host_Users_f, "prints additional information about all players on the scoreboard");
2485 Cmd_AddCommand ("fullserverinfo", Host_FullServerinfo_f, "internal use only, sent by server to client to update client's local copy of serverinfo string");
2486 Cmd_AddCommand ("fullinfo", Host_FullInfo_f, "allows client to modify their userinfo");
2487 Cmd_AddCommand ("setinfo", Host_SetInfo_f, "modifies your userinfo");
2488 Cmd_AddCommand ("packet", Host_Packet_f, "send a packet to the specified address:port containing a text string");
2489 Cmd_AddCommand ("topcolor", Host_TopColor_f, "QW command to set top color without changing bottom color");
2490 Cmd_AddCommand ("bottomcolor", Host_BottomColor_f, "QW command to set bottom color without changing top color");
2492 Cmd_AddCommand ("pings", Host_Pings_f, "command sent by clients to request updated ping and packetloss of players on scoreboard (originally from QW, but also used on NQ servers)");
2493 Cmd_AddCommand ("pingplreport", Host_PingPLReport_f, "command sent by server containing client ping and packet loss values for scoreboard, triggered by pings command from client (not used by QW servers)");
2495 Cvar_RegisterVariable (&team);
2496 Cvar_RegisterVariable (&skin);
2497 Cvar_RegisterVariable (&noaim);
2499 Cvar_RegisterVariable(&sv_cheats);