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 qboolean allowcheats = false;
33 void Host_Quit_f (void)
44 void Host_Status_f (void)
47 int seconds, minutes, hours = 0, j, players;
48 void (*print) (const char *fmt, ...);
50 if (cmd_source == src_command)
54 Cmd_ForwardToServer ();
60 print = SV_ClientPrintf;
62 for (players = 0, j = 0;j < svs.maxclients;j++)
63 if (svs.clients[j].active)
65 print ("host: %s\n", Cvar_VariableString ("hostname"));
66 print ("version: %s build %s\n", gamename, buildstring);
67 print ("protocol: %i (%s)\n", Protocol_NumberForEnum(sv.protocol), Protocol_NameForEnum(sv.protocol));
68 print ("map: %s\n", sv.name);
69 print ("players: %i active (%i max)\n\n", players, svs.maxclients);
70 for (j = 0, client = svs.clients;j < svs.maxclients;j++, client++)
74 seconds = (int)(realtime - client->connecttime);
75 minutes = seconds / 60;
78 seconds -= (minutes * 60);
81 minutes -= (hours * 60);
85 print ("#%-2u %-16.16s %3i %2i:%02i:%02i\n", j+1, client->name, (int)client->edict->fields.server->frags, hours, minutes, seconds);
86 print (" %s\n", client->netconnection ? client->netconnection->address : "botclient");
95 Sets client to godmode
98 void Host_God_f (void)
100 if (cmd_source == src_command)
102 Cmd_ForwardToServer ();
108 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
112 host_client->edict->fields.server->flags = (int)host_client->edict->fields.server->flags ^ FL_GODMODE;
113 if (!((int)host_client->edict->fields.server->flags & FL_GODMODE) )
114 SV_ClientPrint("godmode OFF\n");
116 SV_ClientPrint("godmode ON\n");
119 void Host_Notarget_f (void)
121 if (cmd_source == src_command)
123 Cmd_ForwardToServer ();
129 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
133 host_client->edict->fields.server->flags = (int)host_client->edict->fields.server->flags ^ FL_NOTARGET;
134 if (!((int)host_client->edict->fields.server->flags & FL_NOTARGET) )
135 SV_ClientPrint("notarget OFF\n");
137 SV_ClientPrint("notarget ON\n");
140 qboolean noclip_anglehack;
142 void Host_Noclip_f (void)
144 if (cmd_source == src_command)
146 Cmd_ForwardToServer ();
152 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
156 if (host_client->edict->fields.server->movetype != MOVETYPE_NOCLIP)
158 noclip_anglehack = true;
159 host_client->edict->fields.server->movetype = MOVETYPE_NOCLIP;
160 SV_ClientPrint("noclip ON\n");
164 noclip_anglehack = false;
165 host_client->edict->fields.server->movetype = MOVETYPE_WALK;
166 SV_ClientPrint("noclip OFF\n");
174 Sets client to flymode
177 void Host_Fly_f (void)
179 if (cmd_source == src_command)
181 Cmd_ForwardToServer ();
187 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
191 if (host_client->edict->fields.server->movetype != MOVETYPE_FLY)
193 host_client->edict->fields.server->movetype = MOVETYPE_FLY;
194 SV_ClientPrint("flymode ON\n");
198 host_client->edict->fields.server->movetype = MOVETYPE_WALK;
199 SV_ClientPrint("flymode OFF\n");
210 void Host_Ping_f (void)
214 void (*print) (const char *fmt, ...);
216 if (cmd_source == src_command)
220 Cmd_ForwardToServer ();
226 print = SV_ClientPrintf;
228 print("Client ping times:\n");
229 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
233 print("%4i %s\n", (int)floor(client->ping*1000+0.5), client->name);
238 ===============================================================================
242 ===============================================================================
246 ======================
251 command from the console. Active clients are kicked off.
252 ======================
254 void Host_Map_f (void)
256 char level[MAX_QPATH];
260 Con_Print("map <levelname> : start a new game (kicks off all players)\n");
264 if (cmd_source != src_command)
267 cls.demonum = -1; // stop demo loop in case this fails
270 Host_ShutdownServer();
272 // remove console or menu
274 key_consoleactive = 0;
276 svs.serverflags = 0; // haven't completed an episode yet
277 allowcheats = sv_cheats.integer != 0;
278 strcpy(level, Cmd_Argv(1));
279 SV_SpawnServer(level);
280 if (sv.active && cls.state == ca_disconnected)
283 CL_EstablishConnection("local:1");
292 Goes to a new map, taking all clients along
295 void Host_Changelevel_f (void)
297 char level[MAX_QPATH];
301 Con_Print("changelevel <levelname> : continue game on a new level\n");
309 if (cls.demoplayback)
311 Con_Print("Only the server may changelevel\n");
314 if (cmd_source != src_command)
317 // remove console or menu
319 key_consoleactive = 0;
322 SV_SaveSpawnparms ();
324 allowcheats = sv_cheats.integer != 0;
325 strcpy(level, Cmd_Argv(1));
326 SV_SpawnServer(level);
327 if (sv.active && cls.state == ca_disconnected)
330 CL_EstablishConnection("local:1");
339 Restarts the current server for a dead player
342 void Host_Restart_f (void)
344 char mapname[MAX_QPATH];
348 Con_Print("restart : restart current level\n");
351 if (!sv.active || cls.demoplayback)
353 Con_Print("Only the server may restart\n");
356 if (cmd_source != src_command)
359 // remove console or menu
361 key_consoleactive = 0;
363 allowcheats = sv_cheats.integer != 0;
364 strcpy(mapname, sv.name);
365 SV_SpawnServer(mapname);
366 if (sv.active && cls.state == ca_disconnected)
369 CL_EstablishConnection("local:1");
378 This command causes the client to wait for the signon messages again.
379 This is sent just before a server changes levels
382 void Host_Reconnect_f (void)
384 if (cmd_source == src_command)
386 Con_Print("reconnect is not valid from the console\n");
391 Con_Print("reconnect : wait for signon messages again\n");
396 //Con_Print("reconnect: no signon, ignoring reconnect\n");
399 cls.signon = 0; // need new connection messages
403 =====================
406 User command to connect to server
407 =====================
409 void Host_Connect_f (void)
413 Con_Print("connect <serveraddress> : connect to a multiplayer game\n");
418 CL_EstablishConnection(Cmd_Argv(1));
421 CL_EstablishConnection(Cmd_Argv(1));
427 ===============================================================================
431 ===============================================================================
434 #define SAVEGAME_VERSION 5
440 Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
443 void Host_SavegameComment (char *text)
448 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
450 // LordHavoc: added min() to prevent overflow
451 memcpy (text, cl.levelname, min(strlen(cl.levelname), SAVEGAME_COMMENT_LENGTH));
452 sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
453 memcpy (text+22, kills, strlen(kills));
454 // convert space to _ to make stdio happy
455 // LordHavoc: convert control characters to _ as well
456 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
459 text[SAVEGAME_COMMENT_LENGTH] = '\0';
468 void Host_Savegame_f (void)
470 char name[MAX_QPATH];
473 char comment[SAVEGAME_COMMENT_LENGTH+1];
475 if (cmd_source != src_command)
478 if (cls.state != ca_connected || !sv.active)
480 Con_Print("Not playing a local game.\n");
486 Con_Print("Can't save in intermission.\n");
490 for (i = 0;i < svs.maxclients;i++)
492 if (svs.clients[i].active)
496 Con_Print("Can't save multiplayer games.\n");
499 if (svs.clients[i].edict->fields.server->deadflag)
501 Con_Print("Can't savegame with a dead player\n");
509 Con_Print("save <savename> : save a game\n");
513 if (strstr(Cmd_Argv(1), ".."))
515 Con_Print("Relative pathnames are not allowed.\n");
519 strlcpy (name, Cmd_Argv(1), sizeof (name));
520 FS_DefaultExtension (name, ".sav", sizeof (name));
522 Con_Printf("Saving game to %s...\n", name);
523 f = FS_Open (name, "wb", false, false);
526 Con_Print("ERROR: couldn't open.\n");
530 FS_Printf(f, "%i\n", SAVEGAME_VERSION);
531 Host_SavegameComment (comment);
532 FS_Printf(f, "%s\n", comment);
533 for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
534 FS_Printf(f, "%f\n", svs.clients[0].spawn_parms[i]);
535 FS_Printf(f, "%d\n", current_skill);
536 FS_Printf(f, "%s\n", sv.name);
537 FS_Printf(f, "%f\n",sv.time);
539 // write the light styles
540 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
542 if (sv.lightstyles[i][0])
543 FS_Printf(f, "%s\n", sv.lightstyles[i]);
550 PRVM_ED_WriteGlobals (f);
551 for (i=0 ; i<prog->num_edicts ; i++)
552 PRVM_ED_Write (f, PRVM_EDICT_NUM(i));
557 Con_Print("done.\n");
566 void Host_Loadgame_f (void)
568 char filename[MAX_QPATH];
569 char mapname[MAX_QPATH];
579 float spawn_parms[NUM_SPAWN_PARMS];
581 if (cmd_source != src_command)
586 Con_Print("load <savename> : load a game\n");
590 strcpy (filename, Cmd_Argv(1));
591 FS_DefaultExtension (filename, ".sav", sizeof (filename));
593 Con_Printf("Loading game from %s...\n", filename);
595 cls.demonum = -1; // stop demo loop in case this fails
597 t = text = (char *)FS_LoadFile (filename, tempmempool, false, NULL);
600 Con_Print("ERROR: couldn't open.\n");
605 COM_ParseToken(&t, false);
606 version = atoi(com_token);
607 if (version != SAVEGAME_VERSION)
610 Con_Printf("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
615 // this is a little hard to parse, as : is a separator in COM_ParseToken,
616 // so use the console parser instead
617 COM_ParseTokenConsole(&t);
619 for (i = 0;i < NUM_SPAWN_PARMS;i++)
621 COM_ParseToken(&t, false);
622 spawn_parms[i] = atof(com_token);
625 COM_ParseToken(&t, false);
626 // this silliness is so we can load 1.06 save files, which have float skill values
627 current_skill = (int)(atof(com_token) + 0.5);
628 Cvar_SetValue ("skill", (float)current_skill);
631 COM_ParseToken(&t, false);
632 strcpy (mapname, com_token);
635 COM_ParseToken(&t, false);
636 time = atof(com_token);
638 allowcheats = sv_cheats.integer != 0;
640 SV_SpawnServer (mapname);
644 Con_Print("Couldn't load map\n");
647 sv.paused = true; // pause until all clients connect
650 // load the light styles
652 for (i = 0;i < MAX_LIGHTSTYLES;i++)
656 COM_ParseToken(&t, false);
657 // if this is a 64 lightstyle savegame produced by Quake, stop now
658 // we have to check this because darkplaces saves 256 lightstyle savegames
659 if (com_token[0] == '{')
664 strlcpy(sv.lightstyles[i], com_token, sizeof(sv.lightstyles[i]));
667 // now skip everything before the first opening brace
668 // (this is for forward compatibility, so that older versions (at
669 // least ones with this fix) can load savegames with extra data before the
670 // first brace, as might be produced by a later engine version)
674 COM_ParseToken(&t, false);
675 if (com_token[0] == '{')
682 // load the edicts out of the savegame file
689 while (COM_ParseToken(&t, false))
690 if (!strcmp(com_token, "}"))
692 if (!COM_ParseToken(&start, false))
697 if (strcmp(com_token,"{"))
700 Host_Error ("First token isn't a brace");
705 // parse the global vars
706 PRVM_ED_ParseGlobals (start);
711 if (entnum >= MAX_EDICTS)
714 Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)", MAX_EDICTS);
716 while (entnum >= prog->max_edicts)
717 //SV_IncreaseEdicts();
718 PRVM_MEM_IncreaseEdicts();
719 ent = PRVM_EDICT_NUM(entnum);
720 memset (ent->fields.server, 0, prog->progs->entityfields * 4);
721 ent->priv.server->free = false;
722 PRVM_ED_ParseEdict (start, ent);
724 // link it into the bsp tree
725 if (!ent->priv.server->free)
726 SV_LinkEdict (ent, false);
732 prog->num_edicts = entnum;
735 for (i = 0;i < NUM_SPAWN_PARMS;i++)
736 svs.clients[0].spawn_parms[i] = spawn_parms[i];
738 // make sure we're connected to loopback
739 if (cls.state == ca_disconnected || !(cls.state == ca_connected && cls.netcon != NULL && LHNETADDRESS_GetAddressType(&cls.netcon->peeraddress) == LHNETADDRESSTYPE_LOOP))
740 CL_EstablishConnection("local:1");
745 //============================================================================
748 ======================
750 ======================
752 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player", "internal storage cvar for current player name (changed by name command)"};
753 void Host_Name_f (void)
756 char newName[sizeof(host_client->name)];
758 if (Cmd_Argc () == 1)
760 Con_Printf("\"name\" is \"%s\"\n", cl_name.string);
764 if (Cmd_Argc () == 2)
765 strlcpy (newName, Cmd_Argv(1), sizeof (newName));
767 strlcpy (newName, Cmd_Args(), sizeof (newName));
769 for (i = 0, j = 0;newName[i];i++)
770 if (newName[i] != '\r' && newName[i] != '\n')
771 newName[j++] = newName[i];
774 if (cmd_source == src_command)
776 Cvar_Set ("_cl_name", newName);
777 if (cls.state == ca_connected)
778 Cmd_ForwardToServer ();
782 if (sv.time < host_client->nametime)
784 SV_ClientPrintf("You can't change name more than once every 5 seconds!\n");
788 host_client->nametime = sv.time + 5;
790 // point the string back at updateclient->name to keep it safe
791 strlcpy (host_client->name, newName, sizeof (host_client->name));
792 host_client->edict->fields.server->netname = PRVM_SetEngineString(host_client->name);
793 if (strcmp(host_client->old_name, host_client->name))
795 if (host_client->spawned)
796 SV_BroadcastPrintf("%s changed name to %s\n", host_client->old_name, host_client->name);
797 strcpy(host_client->old_name, host_client->name);
798 // send notification to all clients
799 MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
800 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
801 MSG_WriteString (&sv.reliable_datagram, host_client->name);
806 ======================
808 ======================
810 cvar_t cl_playermodel = {CVAR_SAVE, "_cl_playermodel", "", "internal storage cvar for current player model in Nexuiz (changed by playermodel command)"};
811 // the old cl_playermodel in cl_main has been renamed to __cl_playermodel
812 void Host_Playermodel_f (void)
815 char newPath[sizeof(host_client->playermodel)];
817 if (Cmd_Argc () == 1)
819 Con_Printf("\"playermodel\" is \"%s\"\n", cl_playermodel.string);
823 if (Cmd_Argc () == 2)
824 strlcpy (newPath, Cmd_Argv(1), sizeof (newPath));
826 strlcpy (newPath, Cmd_Args(), sizeof (newPath));
828 for (i = 0, j = 0;newPath[i];i++)
829 if (newPath[i] != '\r' && newPath[i] != '\n')
830 newPath[j++] = newPath[i];
833 if (cmd_source == src_command)
835 Cvar_Set ("_cl_playermodel", newPath);
836 if (cls.state == ca_connected)
837 Cmd_ForwardToServer ();
842 if (sv.time < host_client->nametime)
844 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
848 host_client->nametime = sv.time + 5;
851 // point the string back at updateclient->name to keep it safe
852 strlcpy (host_client->playermodel, newPath, sizeof (host_client->playermodel));
853 if( eval_playermodel )
854 PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_playermodel)->string = PRVM_SetEngineString(host_client->playermodel);
855 if (strcmp(host_client->old_model, host_client->playermodel))
857 strcpy(host_client->old_model, host_client->playermodel);
858 /*// send notification to all clients
859 MSG_WriteByte (&sv.reliable_datagram, svc_updatepmodel);
860 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
861 MSG_WriteString (&sv.reliable_datagram, host_client->playermodel);*/
866 ======================
868 ======================
870 cvar_t cl_playerskin = {CVAR_SAVE, "_cl_playerskin", "", "internal storage cvar for current player skin in Nexuiz (changed by playerskin command)"};
871 void Host_Playerskin_f (void)
874 char newPath[sizeof(host_client->playerskin)];
876 if (Cmd_Argc () == 1)
878 Con_Printf("\"playerskin\" is \"%s\"\n", cl_playerskin.string);
882 if (Cmd_Argc () == 2)
883 strlcpy (newPath, Cmd_Argv(1), sizeof (newPath));
885 strlcpy (newPath, Cmd_Args(), sizeof (newPath));
887 for (i = 0, j = 0;newPath[i];i++)
888 if (newPath[i] != '\r' && newPath[i] != '\n')
889 newPath[j++] = newPath[i];
892 if (cmd_source == src_command)
894 Cvar_Set ("_cl_playerskin", newPath);
895 if (cls.state == ca_connected)
896 Cmd_ForwardToServer ();
901 if (sv.time < host_client->nametime)
903 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
907 host_client->nametime = sv.time + 5;
910 // point the string back at updateclient->name to keep it safe
911 strlcpy (host_client->playerskin, newPath, sizeof (host_client->playerskin));
912 if( eval_playerskin )
913 PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_playerskin)->string = PRVM_SetEngineString(host_client->playerskin);
914 if (strcmp(host_client->old_skin, host_client->playerskin))
916 if (host_client->spawned)
917 SV_BroadcastPrintf("%s changed skin to %s\n", host_client->name, host_client->playerskin);
918 strcpy(host_client->old_skin, host_client->playerskin);
919 /*// send notification to all clients
920 MSG_WriteByte (&sv.reliable_datagram, svc_updatepskin);
921 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
922 MSG_WriteString (&sv.reliable_datagram, host_client->playerskin);*/
926 void Host_Version_f (void)
928 Con_Printf("Version: %s build %s\n", gamename, buildstring);
931 void Host_Say(qboolean teamonly)
937 // LordHavoc: long say messages
939 qboolean fromServer = false;
941 if (cmd_source == src_command)
943 if (cls.state == ca_dedicated)
950 Cmd_ForwardToServer ();
958 if (!teamplay.integer)
961 // turn on color set 1
970 dpsnprintf (text, sizeof(text), "%c%s" STRING_COLOR_DEFAULT_STR ": %s", 1, host_client->name, p1);
972 dpsnprintf (text, sizeof(text), "%c<%s" STRING_COLOR_DEFAULT_STR "> %s", 1, hostname.string, p1);
973 p2 = text + strlen(text);
974 while ((const char *)p2 > (const char *)text && (p2[-1] == '\r' || p2[-1] == '\n' || (p2[-1] == '\"' && quoted)))
976 if (p2[-1] == '\"' && quoted)
981 strlcat(text, "\n", sizeof(text));
983 // note: save is not a valid edict if fromServer is true
985 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
986 if (host_client->spawned && (!teamonly || host_client->edict->fields.server->team == save->edict->fields.server->team))
987 SV_ClientPrint(text);
990 if (cls.state == ca_dedicated)
995 void Host_Say_f(void)
1001 void Host_Say_Team_f(void)
1007 void Host_Tell_f(void)
1011 const char *p1, *p2;
1012 char text[MAX_INPUTLINE]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
1013 qboolean fromServer = false;
1015 if (cmd_source == src_command)
1017 if (cls.state == ca_dedicated)
1021 Cmd_ForwardToServer ();
1026 if (Cmd_Argc () < 3)
1030 sprintf (text, "%s: ", host_client->name);
1032 sprintf (text, "<%s> ", hostname.string);
1035 p2 = p1 + strlen(p1);
1036 // remove the target name
1037 while (p1 < p2 && *p1 != ' ')
1039 while (p1 < p2 && *p1 == ' ')
1041 // remove trailing newlines
1042 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
1044 // remove quotes if present
1050 else if (fromServer)
1051 Con_Print("Host_Tell: missing end quote\n");
1053 SV_ClientPrint("Host_Tell: missing end quote\n");
1055 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
1057 for (j = (int)strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
1063 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
1064 if (host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1)))
1065 SV_ClientPrint(text);
1075 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0", "internal storage cvar for current player colors (changed by color command)"};
1076 void Host_Color_f(void)
1081 func_t SV_ChangeTeam;
1083 if (Cmd_Argc() == 1)
1085 Con_Printf("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
1086 Con_Print("color <0-15> [0-15]\n");
1090 if (Cmd_Argc() == 2)
1091 top = bottom = atoi(Cmd_Argv(1));
1094 top = atoi(Cmd_Argv(1));
1095 bottom = atoi(Cmd_Argv(2));
1099 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
1103 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
1107 playercolor = top*16 + bottom;
1109 if (cmd_source == src_command)
1111 Cvar_SetValue ("_cl_color", playercolor);
1112 if (cls.state == ca_connected)
1113 Cmd_ForwardToServer ();
1117 if (host_client->edict && (f = PRVM_ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - prog->functions)))
1119 Con_DPrint("Calling SV_ChangeTeam\n");
1120 prog->globals.server->time = sv.time;
1121 prog->globals.generic[OFS_PARM0] = playercolor;
1122 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1123 PRVM_ExecuteProgram (SV_ChangeTeam, "QC function SV_ChangeTeam is missing");
1128 if (host_client->edict)
1130 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_clientcolors)))
1131 val->_float = playercolor;
1132 host_client->edict->fields.server->team = bottom + 1;
1134 host_client->colors = playercolor;
1135 if (host_client->old_colors != host_client->colors)
1137 host_client->old_colors = host_client->colors;
1138 // send notification to all clients
1139 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
1140 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
1141 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
1146 cvar_t cl_rate = {CVAR_SAVE, "_cl_rate", "10000", "internal storage cvar for current rate (changed by rate command)"};
1147 void Host_Rate_f(void)
1151 if (Cmd_Argc() != 2)
1153 Con_Printf("\"rate\" is \"%i\"\n", cl_rate.integer);
1154 Con_Print("rate <500-25000>\n");
1158 rate = atoi(Cmd_Argv(1));
1160 if (cmd_source == src_command)
1162 Cvar_SetValue ("_cl_rate", bound(NET_MINRATE, rate, NET_MAXRATE));
1163 if (cls.state == ca_connected)
1164 Cmd_ForwardToServer ();
1168 host_client->rate = rate;
1176 void Host_Kill_f (void)
1178 if (cmd_source == src_command)
1180 Cmd_ForwardToServer ();
1184 if (host_client->edict->fields.server->health <= 0)
1186 SV_ClientPrint("Can't suicide -- already dead!\n");
1190 prog->globals.server->time = sv.time;
1191 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1192 PRVM_ExecuteProgram (prog->globals.server->ClientKill, "QC function ClientKill is missing");
1201 void Host_Pause_f (void)
1204 if (cmd_source == src_command)
1206 Cmd_ForwardToServer ();
1209 if (!pausable.integer)
1210 SV_ClientPrint("Pause not allowed.\n");
1214 SV_BroadcastPrintf("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
1215 // send notification to all clients
1216 MSG_WriteByte(&sv.reliable_datagram, svc_setpause);
1217 MSG_WriteByte(&sv.reliable_datagram, sv.paused);
1222 ======================
1224 LordHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
1225 LordHavoc: correction, Mindcrime will be removing pmodel in the future, but it's still stuck here for compatibility.
1226 ======================
1228 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0", "internal storage cvar for current player model number in nehahra (changed by pmodel command)"};
1229 static void Host_PModel_f (void)
1234 if (Cmd_Argc () == 1)
1236 Con_Printf("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
1239 i = atoi(Cmd_Argv(1));
1241 if (cmd_source == src_command)
1243 if (cl_pmodel.integer == i)
1245 Cvar_SetValue ("_cl_pmodel", i);
1246 if (cls.state == ca_connected)
1247 Cmd_ForwardToServer ();
1251 if (host_client->edict && (val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_pmodel)))
1255 //===========================================================================
1263 void Host_PreSpawn_f (void)
1265 if (cmd_source == src_command)
1267 Con_Print("prespawn is not valid from the console\n");
1271 if (host_client->spawned)
1273 Con_Print("prespawn not valid -- already spawned\n");
1277 if (host_client->netconnection)
1279 SZ_Write (&host_client->netconnection->message, sv.signon.data, sv.signon.cursize);
1280 MSG_WriteByte (&host_client->netconnection->message, svc_signonnum);
1281 MSG_WriteByte (&host_client->netconnection->message, 2);
1283 host_client->sendsignon = true;
1285 // reset the name change timer because the client will send name soon
1286 host_client->nametime = 0;
1294 void Host_Spawn_f (void)
1300 int stats[MAX_CL_STATS];
1302 if (cmd_source == src_command)
1304 Con_Print("spawn is not valid from the console\n");
1308 if (host_client->spawned)
1310 Con_Print("Spawn not valid -- already spawned\n");
1314 // reset name change timer again because they might want to change name
1315 // again in the first 5 seconds after connecting
1316 host_client->nametime = 0;
1318 // LordHavoc: moved this above the QC calls at FrikaC's request
1319 // LordHavoc: commented this out
1320 //if (host_client->netconnection)
1321 // SZ_Clear (&host_client->netconnection->message);
1323 // run the entrance script
1326 // loaded games are fully initialized already
1327 // if this is the last client to be connected, unpause
1330 if ((f = PRVM_ED_FindFunction ("RestoreGame")))
1331 if ((RestoreGame = (func_t)(f - prog->functions)))
1333 Con_DPrint("Calling RestoreGame\n");
1334 prog->globals.server->time = sv.time;
1335 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1336 PRVM_ExecuteProgram (RestoreGame, "QC function RestoreGame is missing");
1341 //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);
1343 // copy spawn parms out of the client_t
1344 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1345 (&prog->globals.server->parm1)[i] = host_client->spawn_parms[i];
1347 // call the spawn function
1348 host_client->clientconnectcalled = true;
1349 prog->globals.server->time = sv.time;
1350 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1351 PRVM_ExecuteProgram (prog->globals.server->ClientConnect, "QC function ClientConnect is missing");
1353 if ((Sys_DoubleTime() - host_client->connecttime) <= sv.time)
1354 Con_Printf("%s entered the game\n", host_client->name);
1356 PRVM_ExecuteProgram (prog->globals.server->PutClientInServer, "QC function PutClientInServer is missing");
1359 if (!host_client->netconnection)
1362 // send time of update
1363 MSG_WriteByte (&host_client->netconnection->message, svc_time);
1364 MSG_WriteFloat (&host_client->netconnection->message, sv.time);
1366 // send all current names, colors, and frag counts
1367 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
1369 if (!client->active)
1371 MSG_WriteByte (&host_client->netconnection->message, svc_updatename);
1372 MSG_WriteByte (&host_client->netconnection->message, i);
1373 MSG_WriteString (&host_client->netconnection->message, client->name);
1374 MSG_WriteByte (&host_client->netconnection->message, svc_updatefrags);
1375 MSG_WriteByte (&host_client->netconnection->message, i);
1376 MSG_WriteShort (&host_client->netconnection->message, client->frags);
1377 MSG_WriteByte (&host_client->netconnection->message, svc_updatecolors);
1378 MSG_WriteByte (&host_client->netconnection->message, i);
1379 MSG_WriteByte (&host_client->netconnection->message, client->colors);
1382 // send all current light styles
1383 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1385 if (sv.lightstyles[i][0])
1387 MSG_WriteByte (&host_client->netconnection->message, svc_lightstyle);
1388 MSG_WriteByte (&host_client->netconnection->message, (char)i);
1389 MSG_WriteString (&host_client->netconnection->message, sv.lightstyles[i]);
1394 MSG_WriteByte (&host_client->netconnection->message, svc_updatestat);
1395 MSG_WriteByte (&host_client->netconnection->message, STAT_TOTALSECRETS);
1396 MSG_WriteLong (&host_client->netconnection->message, prog->globals.server->total_secrets);
1398 MSG_WriteByte (&host_client->netconnection->message, svc_updatestat);
1399 MSG_WriteByte (&host_client->netconnection->message, STAT_TOTALMONSTERS);
1400 MSG_WriteLong (&host_client->netconnection->message, prog->globals.server->total_monsters);
1402 MSG_WriteByte (&host_client->netconnection->message, svc_updatestat);
1403 MSG_WriteByte (&host_client->netconnection->message, STAT_SECRETS);
1404 MSG_WriteLong (&host_client->netconnection->message, prog->globals.server->found_secrets);
1406 MSG_WriteByte (&host_client->netconnection->message, svc_updatestat);
1407 MSG_WriteByte (&host_client->netconnection->message, STAT_MONSTERS);
1408 MSG_WriteLong (&host_client->netconnection->message, prog->globals.server->killed_monsters);
1411 // Never send a roll angle, because savegames can catch the server
1412 // in a state where it is expecting the client to correct the angle
1413 // and it won't happen if the game was just loaded, so you wind up
1414 // with a permanent head tilt
1415 MSG_WriteByte (&host_client->netconnection->message, svc_setangle);
1416 MSG_WriteAngle (&host_client->netconnection->message, host_client->edict->fields.server->angles[0], sv.protocol);
1417 MSG_WriteAngle (&host_client->netconnection->message, host_client->edict->fields.server->angles[1], sv.protocol);
1418 MSG_WriteAngle (&host_client->netconnection->message, 0, sv.protocol);
1420 SV_WriteClientdataToMessage (host_client, host_client->edict, &host_client->netconnection->message, stats);
1422 MSG_WriteByte (&host_client->netconnection->message, svc_signonnum);
1423 MSG_WriteByte (&host_client->netconnection->message, 3);
1425 host_client->sendsignon = true;
1433 void Host_Begin_f (void)
1435 if (cmd_source == src_command)
1437 Con_Print("begin is not valid from the console\n");
1441 host_client->spawned = true;
1444 //===========================================================================
1451 Kicks a user off of the server
1454 void Host_Kick_f (void)
1457 const char *message = NULL;
1460 qboolean byNumber = false;
1462 if (cmd_source != src_command || !sv.active)
1468 if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1470 i = atof(Cmd_Argv(2)) - 1;
1471 if (i < 0 || i >= svs.maxclients || !(host_client = svs.clients + i)->active)
1477 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1479 if (!host_client->active)
1481 if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1486 if (i < svs.maxclients)
1488 if (cmd_source == src_command)
1490 if (cls.state == ca_dedicated)
1493 who = cl_name.string;
1498 // can't kick yourself!
1499 if (host_client == save)
1504 message = Cmd_Args();
1505 COM_ParseToken(&message, false);
1508 message++; // skip the #
1509 while (*message == ' ') // skip white space
1511 message += strlen(Cmd_Argv(2)); // skip the number
1513 while (*message && *message == ' ')
1517 SV_ClientPrintf("Kicked by %s: %s\n", who, message);
1519 SV_ClientPrintf("Kicked by %s\n", who);
1520 SV_DropClient (false); // kicked
1528 ===============================================================================
1532 ===============================================================================
1540 void Host_Give_f (void)
1546 if (cmd_source == src_command)
1548 Cmd_ForwardToServer ();
1554 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
1559 v = atoi (Cmd_Argv(2));
1573 // MED 01/04/97 added hipnotic give stuff
1574 if (gamemode == GAME_HIPNOTIC)
1579 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | HIT_PROXIMITY_GUN;
1581 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | IT_GRENADE_LAUNCHER;
1583 else if (t[0] == '9')
1584 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | HIT_LASER_CANNON;
1585 else if (t[0] == '0')
1586 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | HIT_MJOLNIR;
1587 else if (t[0] >= '2')
1588 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | (IT_SHOTGUN << (t[0] - '2'));
1593 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | (IT_SHOTGUN << (t[0] - '2'));
1598 if (gamemode == GAME_ROGUE && (val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_shells1)))
1601 host_client->edict->fields.server->ammo_shells = v;
1604 if (gamemode == GAME_ROGUE)
1606 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_nails1)))
1609 if (host_client->edict->fields.server->weapon <= IT_LIGHTNING)
1610 host_client->edict->fields.server->ammo_nails = v;
1615 host_client->edict->fields.server->ammo_nails = v;
1619 if (gamemode == GAME_ROGUE)
1621 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_lava_nails);
1625 if (host_client->edict->fields.server->weapon > IT_LIGHTNING)
1626 host_client->edict->fields.server->ammo_nails = v;
1631 if (gamemode == GAME_ROGUE)
1633 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_rockets1);
1637 if (host_client->edict->fields.server->weapon <= IT_LIGHTNING)
1638 host_client->edict->fields.server->ammo_rockets = v;
1643 host_client->edict->fields.server->ammo_rockets = v;
1647 if (gamemode == GAME_ROGUE)
1649 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_multi_rockets);
1653 if (host_client->edict->fields.server->weapon > IT_LIGHTNING)
1654 host_client->edict->fields.server->ammo_rockets = v;
1659 host_client->edict->fields.server->health = v;
1662 if (gamemode == GAME_ROGUE)
1664 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_cells1);
1668 if (host_client->edict->fields.server->weapon <= IT_LIGHTNING)
1669 host_client->edict->fields.server->ammo_cells = v;
1674 host_client->edict->fields.server->ammo_cells = v;
1678 if (gamemode == GAME_ROGUE)
1680 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_plasma);
1684 if (host_client->edict->fields.server->weapon > IT_LIGHTNING)
1685 host_client->edict->fields.server->ammo_cells = v;
1692 prvm_edict_t *FindViewthing (void)
1697 for (i=0 ; i<prog->num_edicts ; i++)
1699 e = PRVM_EDICT_NUM(i);
1700 if (!strcmp (PRVM_GetString(e->fields.server->classname), "viewthing"))
1703 Con_Print("No viewthing on map\n");
1712 void Host_Viewmodel_f (void)
1721 e = FindViewthing ();
1726 m = Mod_ForName (Cmd_Argv(1), false, true, false);
1727 if (!m || !m->loaded || !m->Draw)
1729 Con_Printf("viewmodel: can't load %s\n", Cmd_Argv(1));
1733 e->fields.server->frame = 0;
1734 cl.model_precache[(int)e->fields.server->modelindex] = m;
1742 void Host_Viewframe_f (void)
1752 e = FindViewthing ();
1756 m = cl.model_precache[(int)e->fields.server->modelindex];
1758 f = atoi(Cmd_Argv(1));
1759 if (f >= m->numframes)
1762 e->fields.server->frame = f;
1766 void PrintFrameName (model_t *m, int frame)
1769 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1771 Con_Printf("frame %i\n", frame);
1779 void Host_Viewnext_f (void)
1788 e = FindViewthing ();
1792 m = cl.model_precache[(int)e->fields.server->modelindex];
1794 e->fields.server->frame = e->fields.server->frame + 1;
1795 if (e->fields.server->frame >= m->numframes)
1796 e->fields.server->frame = m->numframes - 1;
1798 PrintFrameName (m, e->fields.server->frame);
1806 void Host_Viewprev_f (void)
1815 e = FindViewthing ();
1820 m = cl.model_precache[(int)e->fields.server->modelindex];
1822 e->fields.server->frame = e->fields.server->frame - 1;
1823 if (e->fields.server->frame < 0)
1824 e->fields.server->frame = 0;
1826 PrintFrameName (m, e->fields.server->frame);
1830 ===============================================================================
1834 ===============================================================================
1843 void Host_Startdemos_f (void)
1847 if (cls.state == ca_dedicated || COM_CheckParm("-listen") || COM_CheckParm("-benchmark") || COM_CheckParm("-demo") || COM_CheckParm("-demolooponly"))
1853 Con_Printf("Max %i demos in demoloop\n", MAX_DEMOS);
1856 Con_Printf("%i demo(s) in loop\n", c);
1858 for (i=1 ; i<c+1 ; i++)
1859 strlcpy (cls.demos[i-1], Cmd_Argv(i), sizeof (cls.demos[i-1]));
1861 // LordHavoc: clear the remaining slots
1862 for (;i <= MAX_DEMOS;i++)
1863 cls.demos[i-1][0] = 0;
1865 if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
1879 Return to looping demos
1882 void Host_Demos_f (void)
1884 if (cls.state == ca_dedicated)
1886 if (cls.demonum == -1)
1896 Return to looping demos
1899 void Host_Stopdemo_f (void)
1901 if (!cls.demoplayback)
1904 Host_ShutdownServer ();
1907 void Host_SendCvar_f (void)
1915 if(!(c = Cvar_FindVar(Cmd_Argv(1))))
1917 if (cls.state != ca_dedicated)
1918 Cmd_ForwardStringToServer(va("sentcvar %s %s\n", c->name, c->string));
1919 if(!sv.active)// || !SV_ParseClientCommandQC)
1923 if (cls.state != ca_dedicated)
1927 for(;i<svs.maxclients;i++)
1928 if(svs.clients[i].active && svs.clients[i].netconnection)
1930 host_client = &svs.clients[i];
1931 Host_ClientCommands(va("sendcvar %s\n", c->name));
1936 static void MaxPlayers_f(void)
1940 if (Cmd_Argc() != 2)
1942 Con_Printf("\"maxplayers\" is \"%u\"\n", svs.maxclients);
1948 Con_Print("maxplayers can not be changed while a server is running.\n");
1952 n = atoi(Cmd_Argv(1));
1953 n = bound(1, n, MAX_SCOREBOARD);
1954 Con_Printf("\"maxplayers\" set to \"%u\"\n", n);
1957 Mem_Free(svs.clients);
1959 svs.clients = (client_t *)Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients);
1961 Cvar_Set ("deathmatch", "0");
1963 Cvar_Set ("deathmatch", "1");
1966 //=============================================================================
1973 void Host_InitCommands (void)
1975 Cmd_AddCommand ("status", Host_Status_f, "print server status information");
1976 Cmd_AddCommand ("quit", Host_Quit_f, "quit the game");
1977 if (gamemode == GAME_NEHAHRA)
1979 Cmd_AddCommand ("max", Host_God_f, "god mode (invulnerability)");
1980 Cmd_AddCommand ("monster", Host_Notarget_f, "notarget mode (monsters do not see you)");
1981 Cmd_AddCommand ("scrag", Host_Fly_f, "fly mode (flight)");
1982 Cmd_AddCommand ("wraith", Host_Noclip_f, "noclip mode (flight without collisions, move through walls)");
1983 Cmd_AddCommand ("gimme", Host_Give_f, "alter inventory");
1987 Cmd_AddCommand ("god", Host_God_f, "god mode (invulnerability)");
1988 Cmd_AddCommand ("notarget", Host_Notarget_f, "notarget mode (monsters do not see you)");
1989 Cmd_AddCommand ("fly", Host_Fly_f, "fly mode (flight)");
1990 Cmd_AddCommand ("noclip", Host_Noclip_f, "noclip mode (flight without collisions, move through walls)");
1991 Cmd_AddCommand ("give", Host_Give_f, "alter inventory");
1993 Cmd_AddCommand ("map", Host_Map_f, "kick everyone off the server and start a new level");
1994 Cmd_AddCommand ("restart", Host_Restart_f, "restart current level");
1995 Cmd_AddCommand ("changelevel", Host_Changelevel_f, "change to another level, bringing along all connected clients");
1996 Cmd_AddCommand ("connect", Host_Connect_f, "connect to a server by IP address or hostname");
1997 Cmd_AddCommand ("reconnect", Host_Reconnect_f, "reset signon level in preparation for a new level (do not use)");
1998 Cmd_AddCommand ("version", Host_Version_f, "print engine version");
1999 Cmd_AddCommand ("say", Host_Say_f, "send a chat message to everyone on the server");
2000 Cmd_AddCommand ("say_team", Host_Say_Team_f, "send a chat message to your team on the server");
2001 Cmd_AddCommand ("tell", Host_Tell_f, "send a chat message to only one person on the server");
2002 Cmd_AddCommand ("kill", Host_Kill_f, "die instantly");
2003 Cmd_AddCommand ("pause", Host_Pause_f, "pause the game (if the server allows pausing)");
2004 Cmd_AddCommand ("kick", Host_Kick_f, "kick a player off the server by number or name");
2005 Cmd_AddCommand ("ping", Host_Ping_f, "print ping times of all players on the server");
2006 Cmd_AddCommand ("load", Host_Loadgame_f, "load a saved game file");
2007 Cmd_AddCommand ("save", Host_Savegame_f, "save the game to a file");
2009 Cmd_AddCommand ("startdemos", Host_Startdemos_f, "start playing back the selected demos sequentially (used at end of startup script)");
2010 Cmd_AddCommand ("demos", Host_Demos_f, "restart looping demos defined by the last startdemos command");
2011 Cmd_AddCommand ("stopdemo", Host_Stopdemo_f, "stop playing or recording demo (like stop command) and return to looping demos");
2013 Cmd_AddCommand ("viewmodel", Host_Viewmodel_f, "change model of viewthing entity in current level");
2014 Cmd_AddCommand ("viewframe", Host_Viewframe_f, "change animation frame of viewthing entity in current level");
2015 Cmd_AddCommand ("viewnext", Host_Viewnext_f, "change to next animation frame of viewthing entity in current level");
2016 Cmd_AddCommand ("viewprev", Host_Viewprev_f, "change to previous animation frame of viewthing entity in current level");
2018 Cvar_RegisterVariable (&cl_name);
2019 Cmd_AddCommand ("name", Host_Name_f, "change your player name");
2020 Cvar_RegisterVariable (&cl_color);
2021 Cmd_AddCommand ("color", Host_Color_f, "change your player shirt and pants colors");
2022 Cvar_RegisterVariable (&cl_rate);
2023 Cmd_AddCommand ("rate", Host_Rate_f, "change your network connection speed");
2024 if (gamemode == GAME_NEHAHRA)
2026 Cvar_RegisterVariable (&cl_pmodel);
2027 Cmd_AddCommand ("pmodel", Host_PModel_f, "change your player model choice (Nehahra specific)");
2030 // BLACK: This isnt game specific anymore (it was GAME_NEXUIZ at first)
2031 Cvar_RegisterVariable (&cl_playermodel);
2032 Cmd_AddCommand ("playermodel", Host_Playermodel_f, "change your player model");
2033 Cvar_RegisterVariable (&cl_playerskin);
2034 Cmd_AddCommand ("playerskin", Host_Playerskin_f, "change your player skin number");
2036 Cmd_AddCommand ("prespawn", Host_PreSpawn_f, "signon 1 (client acknowledges that server information has been received)");
2037 Cmd_AddCommand ("spawn", Host_Spawn_f, "signon 2 (client has sent player information, and is asking server to send scoreboard rankings)");
2038 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)");
2039 Cmd_AddCommand ("maxplayers", MaxPlayers_f, "sets limit on how many players (or bots) may be connected to the server at once");
2041 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]
2043 Cvar_RegisterVariable(&sv_cheats);