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"};
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)
215 if (cmd_source == src_command)
217 Cmd_ForwardToServer ();
221 SV_ClientPrint("Client ping times:\n");
222 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
226 SV_ClientPrintf("%4i %s\n", (int)floor(client->ping*1000+0.5), client->name);
231 ===============================================================================
235 ===============================================================================
239 ======================
244 command from the console. Active clients are kicked off.
245 ======================
247 void Host_Map_f (void)
249 char level[MAX_QPATH];
253 Con_Print("map <levelname> : start a new game (kicks off all players)\n");
257 if (cmd_source != src_command)
260 cls.demonum = -1; // stop demo loop in case this fails
263 Host_ShutdownServer(false);
265 // remove console or menu
267 key_consoleactive = 0;
269 svs.serverflags = 0; // haven't completed an episode yet
270 allowcheats = sv_cheats.integer != 0;
271 strcpy(level, Cmd_Argv(1));
272 SV_SpawnServer(level);
273 if (sv.active && cls.state == ca_disconnected)
276 CL_EstablishConnection("local:1");
285 Goes to a new map, taking all clients along
288 void Host_Changelevel_f (void)
290 char level[MAX_QPATH];
294 Con_Print("changelevel <levelname> : continue game on a new level\n");
302 if (cls.demoplayback)
304 Con_Print("Only the server may changelevel\n");
307 if (cmd_source != src_command)
310 // remove console or menu
312 key_consoleactive = 0;
315 SV_SaveSpawnparms ();
317 allowcheats = sv_cheats.integer != 0;
318 strcpy(level, Cmd_Argv(1));
319 SV_SpawnServer(level);
320 if (sv.active && cls.state == ca_disconnected)
323 CL_EstablishConnection("local:1");
332 Restarts the current server for a dead player
335 void Host_Restart_f (void)
337 char mapname[MAX_QPATH];
341 Con_Print("restart : restart current level\n");
344 if (!sv.active || cls.demoplayback)
346 Con_Print("Only the server may restart\n");
349 if (cmd_source != src_command)
352 // remove console or menu
354 key_consoleactive = 0;
356 allowcheats = sv_cheats.integer != 0;
357 strcpy(mapname, sv.name);
358 SV_SpawnServer(mapname);
359 if (sv.active && cls.state == ca_disconnected)
362 CL_EstablishConnection("local:1");
371 This command causes the client to wait for the signon messages again.
372 This is sent just before a server changes levels
375 void Host_Reconnect_f (void)
377 if (cmd_source == src_command)
379 Con_Print("reconnect is not valid from the console\n");
384 Con_Print("reconnect : wait for signon messages again\n");
389 //Con_Print("reconnect: no signon, ignoring reconnect\n");
392 cls.signon = 0; // need new connection messages
396 =====================
399 User command to connect to server
400 =====================
402 void Host_Connect_f (void)
406 Con_Print("connect <serveraddress> : connect to a multiplayer game\n");
411 CL_EstablishConnection(Cmd_Argv(1));
414 CL_EstablishConnection(Cmd_Argv(1));
420 ===============================================================================
424 ===============================================================================
427 #define SAVEGAME_VERSION 5
433 Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
436 void Host_SavegameComment (char *text)
441 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
443 // LordHavoc: added min() to prevent overflow
444 memcpy (text, cl.levelname, min(strlen(cl.levelname), SAVEGAME_COMMENT_LENGTH));
445 sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
446 memcpy (text+22, kills, strlen(kills));
447 // convert space to _ to make stdio happy
448 // LordHavoc: convert control characters to _ as well
449 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
452 text[SAVEGAME_COMMENT_LENGTH] = '\0';
461 void Host_Savegame_f (void)
466 char comment[SAVEGAME_COMMENT_LENGTH+1];
468 if (cmd_source != src_command)
471 if (cls.state != ca_connected || !sv.active)
473 Con_Print("Not playing a local game.\n");
479 Con_Print("Can't save in intermission.\n");
483 for (i = 0;i < svs.maxclients;i++)
485 if (svs.clients[i].active)
489 Con_Print("Can't save multiplayer games.\n");
492 if (svs.clients[i].edict->fields.server->deadflag)
494 Con_Print("Can't savegame with a dead player\n");
502 Con_Print("save <savename> : save a game\n");
506 if (strstr(Cmd_Argv(1), ".."))
508 Con_Print("Relative pathnames are not allowed.\n");
512 strlcpy (name, Cmd_Argv(1), sizeof (name));
513 FS_DefaultExtension (name, ".sav", sizeof (name));
515 Con_Printf("Saving game to %s...\n", name);
516 f = FS_Open (name, "wb", false, false);
519 Con_Print("ERROR: couldn't open.\n");
523 FS_Printf(f, "%i\n", SAVEGAME_VERSION);
524 Host_SavegameComment (comment);
525 FS_Printf(f, "%s\n", comment);
526 for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
527 FS_Printf(f, "%f\n", svs.clients[0].spawn_parms[i]);
528 FS_Printf(f, "%d\n", current_skill);
529 FS_Printf(f, "%s\n", sv.name);
530 FS_Printf(f, "%f\n",sv.time);
532 // write the light styles
533 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
535 if (sv.lightstyles[i][0])
536 FS_Printf(f, "%s\n", sv.lightstyles[i]);
543 PRVM_ED_WriteGlobals (f);
544 for (i=0 ; i<prog->num_edicts ; i++)
545 PRVM_ED_Write (f, PRVM_EDICT_NUM(i));
550 Con_Print("done.\n");
559 void Host_Loadgame_f (void)
561 char filename[MAX_QPATH];
562 char mapname[MAX_QPATH];
571 float spawn_parms[NUM_SPAWN_PARMS];
573 if (cmd_source != src_command)
578 Con_Print("load <savename> : load a game\n");
582 strcpy (filename, Cmd_Argv(1));
583 FS_DefaultExtension (filename, ".sav", sizeof (filename));
585 Con_Printf("Loading game from %s...\n", filename);
587 cls.demonum = -1; // stop demo loop in case this fails
589 t = text = FS_LoadFile (filename, tempmempool, false);
592 Con_Print("ERROR: couldn't open.\n");
597 COM_ParseToken(&t, false);
598 version = atoi(com_token);
599 if (version != SAVEGAME_VERSION)
602 Con_Printf("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
607 // this is a little hard to parse, as : is a separator in COM_ParseToken,
608 // so use the console parser instead
609 COM_ParseTokenConsole(&t);
611 for (i = 0;i < NUM_SPAWN_PARMS;i++)
613 COM_ParseToken(&t, false);
614 spawn_parms[i] = atof(com_token);
617 COM_ParseToken(&t, false);
618 // this silliness is so we can load 1.06 save files, which have float skill values
619 current_skill = (int)(atof(com_token) + 0.5);
620 Cvar_SetValue ("skill", (float)current_skill);
623 COM_ParseToken(&t, false);
624 strcpy (mapname, com_token);
627 COM_ParseToken(&t, false);
628 time = atof(com_token);
630 allowcheats = sv_cheats.integer != 0;
632 SV_SpawnServer (mapname);
636 Con_Print("Couldn't load map\n");
639 sv.paused = true; // pause until all clients connect
642 // load the light styles
644 for (i = 0;i < MAX_LIGHTSTYLES;i++)
647 COM_ParseToken(&t, false);
648 strlcpy(sv.lightstyles[i], com_token, sizeof(sv.lightstyles[i]));
651 // load the edicts out of the savegame file
658 while (COM_ParseToken(&t, false))
659 if (!strcmp(com_token, "}"))
661 if (!COM_ParseToken(&start, false))
666 if (strcmp(com_token,"{"))
669 Host_Error ("First token isn't a brace");
674 // parse the global vars
675 PRVM_ED_ParseGlobals (start);
680 if (entnum >= MAX_EDICTS)
683 Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)\n", MAX_EDICTS);
685 while (entnum >= prog->max_edicts)
686 //SV_IncreaseEdicts();
687 PRVM_MEM_IncreaseEdicts();
688 ent = PRVM_EDICT_NUM(entnum);
689 memset (ent->fields.server, 0, prog->progs->entityfields * 4);
690 ent->priv.server->free = false;
691 PRVM_ED_ParseEdict (start, ent);
693 // link it into the bsp tree
694 if (!ent->priv.server->free)
695 SV_LinkEdict (ent, false);
701 prog->num_edicts = entnum;
704 for (i = 0;i < NUM_SPAWN_PARMS;i++)
705 svs.clients[0].spawn_parms[i] = spawn_parms[i];
707 // make sure we're connected to loopback
708 if (cls.state == ca_disconnected || !(cls.state == ca_connected && cls.netcon != NULL && LHNETADDRESS_GetAddressType(&cls.netcon->peeraddress) == LHNETADDRESSTYPE_LOOP))
709 CL_EstablishConnection("local:1");
714 //============================================================================
717 ======================
719 ======================
721 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player"};
722 void Host_Name_f (void)
725 char newName[sizeof(host_client->name)];
727 if (Cmd_Argc () == 1)
729 Con_Printf("\"name\" is \"%s\"\n", cl_name.string);
733 if (Cmd_Argc () == 2)
734 strlcpy (newName, Cmd_Argv(1), sizeof (newName));
736 strlcpy (newName, Cmd_Args(), sizeof (newName));
738 for (i = 0, j = 0;newName[i];i++)
739 if (newName[i] != '\r' && newName[i] != '\n')
740 newName[j++] = newName[i];
743 if (cmd_source == src_command)
745 Cvar_Set ("_cl_name", newName);
746 if (cls.state == ca_connected)
747 Cmd_ForwardToServer ();
751 if (sv.time < host_client->nametime)
753 SV_ClientPrintf("You can't change name more than once every 5 seconds!\n");
757 host_client->nametime = sv.time + 5;
759 // point the string back at updateclient->name to keep it safe
760 strlcpy (host_client->name, newName, sizeof (host_client->name));
761 host_client->edict->fields.server->netname = PRVM_SetEngineString(host_client->name);
762 if (strcmp(host_client->old_name, host_client->name))
764 if (host_client->spawned)
765 SV_BroadcastPrintf("%s changed name to %s\n", host_client->old_name, host_client->name);
766 strcpy(host_client->old_name, host_client->name);
767 // send notification to all clients
768 MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
769 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
770 MSG_WriteString (&sv.reliable_datagram, host_client->name);
775 ======================
777 ======================
779 cvar_t cl_playermodel = {CVAR_SAVE, "_cl_playermodel", ""};
780 // the old cl_playermodel in cl_main has been renamed to __cl_playermodel
781 void Host_Playermodel_f (void)
784 char newPath[sizeof(host_client->playermodel)];
786 if (Cmd_Argc () == 1)
788 Con_Printf("\"playermodel\" is \"%s\"\n", cl_playermodel.string);
792 if (Cmd_Argc () == 2)
793 strlcpy (newPath, Cmd_Argv(1), sizeof (newPath));
795 strlcpy (newPath, Cmd_Args(), sizeof (newPath));
797 for (i = 0, j = 0;newPath[i];i++)
798 if (newPath[i] != '\r' && newPath[i] != '\n')
799 newPath[j++] = newPath[i];
802 if (cmd_source == src_command)
804 Cvar_Set ("_cl_playermodel", newPath);
805 if (cls.state == ca_connected)
806 Cmd_ForwardToServer ();
811 if (sv.time < host_client->nametime)
813 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
817 host_client->nametime = sv.time + 5;
820 // point the string back at updateclient->name to keep it safe
821 strlcpy (host_client->playermodel, newPath, sizeof (host_client->playermodel));
822 if( eval_playermodel )
823 PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_playermodel)->string = PRVM_SetEngineString(host_client->playermodel);
824 if (strcmp(host_client->old_model, host_client->playermodel))
826 strcpy(host_client->old_model, host_client->playermodel);
827 /*// send notification to all clients
828 MSG_WriteByte (&sv.reliable_datagram, svc_updatepmodel);
829 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
830 MSG_WriteString (&sv.reliable_datagram, host_client->playermodel);*/
835 ======================
837 ======================
839 cvar_t cl_playerskin = {CVAR_SAVE, "_cl_playerskin", ""};
840 void Host_Playerskin_f (void)
843 char newPath[sizeof(host_client->playerskin)];
845 if (Cmd_Argc () == 1)
847 Con_Printf("\"playerskin\" is \"%s\"\n", cl_playerskin.string);
851 if (Cmd_Argc () == 2)
852 strlcpy (newPath, Cmd_Argv(1), sizeof (newPath));
854 strlcpy (newPath, Cmd_Args(), sizeof (newPath));
856 for (i = 0, j = 0;newPath[i];i++)
857 if (newPath[i] != '\r' && newPath[i] != '\n')
858 newPath[j++] = newPath[i];
861 if (cmd_source == src_command)
863 Cvar_Set ("_cl_playerskin", newPath);
864 if (cls.state == ca_connected)
865 Cmd_ForwardToServer ();
870 if (sv.time < host_client->nametime)
872 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
876 host_client->nametime = sv.time + 5;
879 // point the string back at updateclient->name to keep it safe
880 strlcpy (host_client->playerskin, newPath, sizeof (host_client->playerskin));
881 if( eval_playerskin )
882 PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_playerskin)->string = PRVM_SetEngineString(host_client->playerskin);
883 if (strcmp(host_client->old_skin, host_client->playerskin))
885 if (host_client->spawned)
886 SV_BroadcastPrintf("%s changed skin to %s\n", host_client->name, host_client->playerskin);
887 strcpy(host_client->old_skin, host_client->playerskin);
888 /*// send notification to all clients
889 MSG_WriteByte (&sv.reliable_datagram, svc_updatepskin);
890 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
891 MSG_WriteString (&sv.reliable_datagram, host_client->playerskin);*/
895 void Host_Version_f (void)
897 Con_Printf("Version: %s build %s\n", gamename, buildstring);
900 void Host_Say(qboolean teamonly)
906 // LordHavoc: 256 char say messages
907 unsigned char text[256];
908 qboolean fromServer = false;
910 if (cmd_source == src_command)
912 if (cls.state == ca_dedicated)
919 Cmd_ForwardToServer ();
927 if (!teamplay.integer)
930 // turn on color set 1
939 dpsnprintf (text, sizeof(text), "%c%s" STRING_COLOR_DEFAULT_STR ": %s", 1, host_client->name, p1);
941 dpsnprintf (text, sizeof(text), "%c<%s" STRING_COLOR_DEFAULT_STR "> %s", 1, hostname.string, p1);
942 p2 = text + strlen(text);
943 while ((const char *)p2 > (const char *)text && (p2[-1] == '\r' || p2[-1] == '\n' || (p2[-1] == '\"' && quoted)))
945 if (p2[-1] == '\"' && quoted)
950 strlcat(text, "\n", sizeof(text));
952 // note: save is not a valid edict if fromServer is true
954 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
955 if (host_client->spawned && (!teamonly || host_client->edict->fields.server->team == save->edict->fields.server->team))
956 SV_ClientPrint(text);
959 if (cls.state == ca_dedicated)
964 void Host_Say_f(void)
970 void Host_Say_Team_f(void)
976 void Host_Tell_f(void)
981 char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
982 qboolean fromServer = false;
984 if (cmd_source == src_command)
986 if (cls.state == ca_dedicated)
990 Cmd_ForwardToServer ();
999 sprintf (text, "%s: ", host_client->name);
1001 sprintf (text, "<%s> ", hostname.string);
1004 p2 = p1 + strlen(p1);
1005 // remove the target name
1006 while (p1 < p2 && *p1 != ' ')
1008 while (p1 < p2 && *p1 == ' ')
1010 // remove trailing newlines
1011 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
1013 // remove quotes if present
1019 else if (fromServer)
1020 Con_Print("Host_Tell: missing end quote\n");
1022 SV_ClientPrint("Host_Tell: missing end quote\n");
1024 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
1026 for (j = (int)strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
1032 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
1033 if (host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1)))
1034 SV_ClientPrint(text);
1044 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0"};
1045 void Host_Color_f(void)
1050 func_t SV_ChangeTeam;
1052 if (Cmd_Argc() == 1)
1054 Con_Printf("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
1055 Con_Print("color <0-15> [0-15]\n");
1059 if (Cmd_Argc() == 2)
1060 top = bottom = atoi(Cmd_Argv(1));
1063 top = atoi(Cmd_Argv(1));
1064 bottom = atoi(Cmd_Argv(2));
1068 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
1072 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
1076 playercolor = top*16 + bottom;
1078 if (cmd_source == src_command)
1080 Cvar_SetValue ("_cl_color", playercolor);
1081 if (cls.state == ca_connected)
1082 Cmd_ForwardToServer ();
1086 if (host_client->edict && (f = PRVM_ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - prog->functions)))
1088 Con_DPrint("Calling SV_ChangeTeam\n");
1089 prog->globals.server->time = sv.time;
1090 prog->globals.generic[OFS_PARM0] = playercolor;
1091 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1092 PRVM_ExecuteProgram (SV_ChangeTeam, "QC function SV_ChangeTeam is missing");
1097 if (host_client->edict)
1099 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_clientcolors)))
1100 val->_float = playercolor;
1101 host_client->edict->fields.server->team = bottom + 1;
1103 host_client->colors = playercolor;
1104 if (host_client->old_colors != host_client->colors)
1106 host_client->old_colors = host_client->colors;
1107 // send notification to all clients
1108 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
1109 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
1110 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
1115 cvar_t cl_rate = {CVAR_SAVE, "_cl_rate", "10000"};
1116 void Host_Rate_f(void)
1120 if (Cmd_Argc() != 2)
1122 Con_Printf("\"rate\" is \"%i\"\n", cl_rate.integer);
1123 Con_Print("rate <500-25000>\n");
1127 rate = atoi(Cmd_Argv(1));
1129 if (cmd_source == src_command)
1131 Cvar_SetValue ("_cl_rate", bound(NET_MINRATE, rate, NET_MAXRATE));
1132 if (cls.state == ca_connected)
1133 Cmd_ForwardToServer ();
1137 host_client->rate = rate;
1145 void Host_Kill_f (void)
1147 if (cmd_source == src_command)
1149 Cmd_ForwardToServer ();
1153 if (host_client->edict->fields.server->health <= 0)
1155 SV_ClientPrint("Can't suicide -- already dead!\n");
1159 prog->globals.server->time = sv.time;
1160 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1161 PRVM_ExecuteProgram (prog->globals.server->ClientKill, "QC function ClientKill is missing");
1170 void Host_Pause_f (void)
1173 if (cmd_source == src_command)
1175 Cmd_ForwardToServer ();
1178 if (!pausable.integer)
1179 SV_ClientPrint("Pause not allowed.\n");
1183 SV_BroadcastPrintf("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
1184 // send notification to all clients
1185 MSG_WriteByte(&sv.reliable_datagram, svc_setpause);
1186 MSG_WriteByte(&sv.reliable_datagram, sv.paused);
1191 ======================
1193 LordHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
1194 LordHavoc: correction, Mindcrime will be removing pmodel in the future, but it's still stuck here for compatibility.
1195 ======================
1197 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0"};
1198 static void Host_PModel_f (void)
1203 if (Cmd_Argc () == 1)
1205 Con_Printf("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
1208 i = atoi(Cmd_Argv(1));
1210 if (cmd_source == src_command)
1212 if (cl_pmodel.integer == i)
1214 Cvar_SetValue ("_cl_pmodel", i);
1215 if (cls.state == ca_connected)
1216 Cmd_ForwardToServer ();
1220 if (host_client->edict && (val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_pmodel)))
1224 //===========================================================================
1232 void Host_PreSpawn_f (void)
1234 if (cmd_source == src_command)
1236 Con_Print("prespawn is not valid from the console\n");
1240 if (host_client->spawned)
1242 Con_Print("prespawn not valid -- already spawned\n");
1246 SZ_Write (&host_client->message, sv.signon.data, sv.signon.cursize);
1247 MSG_WriteByte (&host_client->message, svc_signonnum);
1248 MSG_WriteByte (&host_client->message, 2);
1249 host_client->sendsignon = true;
1251 // reset the name change timer because the client will send name soon
1252 host_client->nametime = 0;
1260 void Host_Spawn_f (void)
1266 int stats[MAX_CL_STATS];
1268 if (cmd_source == src_command)
1270 Con_Print("spawn is not valid from the console\n");
1274 if (host_client->spawned)
1276 Con_Print("Spawn not valid -- already spawned\n");
1280 // reset name change timer again because they might want to change name
1281 // again in the first 5 seconds after connecting
1282 host_client->nametime = 0;
1284 // LordHavoc: moved this above the QC calls at FrikaC's request
1285 // send all current names, colors, and frag counts
1286 SZ_Clear (&host_client->message);
1288 // run the entrance script
1291 // loaded games are fully initialized already
1292 // if this is the last client to be connected, unpause
1295 if ((f = PRVM_ED_FindFunction ("RestoreGame")))
1296 if ((RestoreGame = (func_t)(f - prog->functions)))
1298 Con_DPrint("Calling RestoreGame\n");
1299 prog->globals.server->time = sv.time;
1300 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1301 PRVM_ExecuteProgram (RestoreGame, "QC function RestoreGame is missing");
1307 PRVM_ED_ClearEdict(host_client->edict);
1309 //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);
1311 // copy spawn parms out of the client_t
1312 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1313 (&prog->globals.server->parm1)[i] = host_client->spawn_parms[i];
1315 // call the spawn function
1316 host_client->clientconnectcalled = true;
1317 prog->globals.server->time = sv.time;
1318 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1319 PRVM_ExecuteProgram (prog->globals.server->ClientConnect, "QC function ClientConnect is missing");
1321 if ((Sys_DoubleTime() - host_client->connecttime) <= sv.time)
1322 Con_Printf("%s entered the game\n", host_client->name);
1324 PRVM_ExecuteProgram (prog->globals.server->PutClientInServer, "QC function PutClientInServer is missing");
1328 // send time of update
1329 MSG_WriteByte (&host_client->message, svc_time);
1330 MSG_WriteFloat (&host_client->message, sv.time);
1332 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
1334 if (!client->active)
1336 MSG_WriteByte (&host_client->message, svc_updatename);
1337 MSG_WriteByte (&host_client->message, i);
1338 MSG_WriteString (&host_client->message, client->name);
1339 MSG_WriteByte (&host_client->message, svc_updatefrags);
1340 MSG_WriteByte (&host_client->message, i);
1341 MSG_WriteShort (&host_client->message, client->frags);
1342 MSG_WriteByte (&host_client->message, svc_updatecolors);
1343 MSG_WriteByte (&host_client->message, i);
1344 MSG_WriteByte (&host_client->message, client->colors);
1347 // send all current light styles
1348 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1350 MSG_WriteByte (&host_client->message, svc_lightstyle);
1351 MSG_WriteByte (&host_client->message, (char)i);
1352 MSG_WriteString (&host_client->message, sv.lightstyles[i]);
1356 MSG_WriteByte (&host_client->message, svc_updatestat);
1357 MSG_WriteByte (&host_client->message, STAT_TOTALSECRETS);
1358 MSG_WriteLong (&host_client->message, prog->globals.server->total_secrets);
1360 MSG_WriteByte (&host_client->message, svc_updatestat);
1361 MSG_WriteByte (&host_client->message, STAT_TOTALMONSTERS);
1362 MSG_WriteLong (&host_client->message, prog->globals.server->total_monsters);
1364 MSG_WriteByte (&host_client->message, svc_updatestat);
1365 MSG_WriteByte (&host_client->message, STAT_SECRETS);
1366 MSG_WriteLong (&host_client->message, prog->globals.server->found_secrets);
1368 MSG_WriteByte (&host_client->message, svc_updatestat);
1369 MSG_WriteByte (&host_client->message, STAT_MONSTERS);
1370 MSG_WriteLong (&host_client->message, prog->globals.server->killed_monsters);
1373 // Never send a roll angle, because savegames can catch the server
1374 // in a state where it is expecting the client to correct the angle
1375 // and it won't happen if the game was just loaded, so you wind up
1376 // with a permanent head tilt
1377 MSG_WriteByte (&host_client->message, svc_setangle);
1378 MSG_WriteAngle (&host_client->message, host_client->edict->fields.server->angles[0], sv.protocol);
1379 MSG_WriteAngle (&host_client->message, host_client->edict->fields.server->angles[1], sv.protocol);
1380 MSG_WriteAngle (&host_client->message, 0, sv.protocol);
1382 SV_WriteClientdataToMessage (host_client, host_client->edict, &host_client->message, stats);
1384 MSG_WriteByte (&host_client->message, svc_signonnum);
1385 MSG_WriteByte (&host_client->message, 3);
1386 host_client->sendsignon = true;
1394 void Host_Begin_f (void)
1396 if (cmd_source == src_command)
1398 Con_Print("begin is not valid from the console\n");
1402 host_client->spawned = true;
1405 //===========================================================================
1412 Kicks a user off of the server
1415 void Host_Kick_f (void)
1418 const char *message = NULL;
1421 qboolean byNumber = false;
1423 if (cmd_source != src_command || !sv.active)
1429 if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1431 i = atof(Cmd_Argv(2)) - 1;
1432 if (i < 0 || i >= svs.maxclients || !(host_client = svs.clients + i)->active)
1438 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1440 if (!host_client->active)
1442 if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1447 if (i < svs.maxclients)
1449 if (cmd_source == src_command)
1451 if (cls.state == ca_dedicated)
1454 who = cl_name.string;
1459 // can't kick yourself!
1460 if (host_client == save)
1465 message = Cmd_Args();
1466 COM_ParseToken(&message, false);
1469 message++; // skip the #
1470 while (*message == ' ') // skip white space
1472 message += strlen(Cmd_Argv(2)); // skip the number
1474 while (*message && *message == ' ')
1478 SV_ClientPrintf("Kicked by %s: %s\n", who, message);
1480 SV_ClientPrintf("Kicked by %s\n", who);
1481 SV_DropClient (false); // kicked
1489 ===============================================================================
1493 ===============================================================================
1501 void Host_Give_f (void)
1507 if (cmd_source == src_command)
1509 Cmd_ForwardToServer ();
1515 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
1520 v = atoi (Cmd_Argv(2));
1534 // MED 01/04/97 added hipnotic give stuff
1535 if (gamemode == GAME_HIPNOTIC)
1540 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | HIT_PROXIMITY_GUN;
1542 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | IT_GRENADE_LAUNCHER;
1544 else if (t[0] == '9')
1545 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | HIT_LASER_CANNON;
1546 else if (t[0] == '0')
1547 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | HIT_MJOLNIR;
1548 else if (t[0] >= '2')
1549 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | (IT_SHOTGUN << (t[0] - '2'));
1554 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | (IT_SHOTGUN << (t[0] - '2'));
1559 if (gamemode == GAME_ROGUE && (val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_shells1)))
1562 host_client->edict->fields.server->ammo_shells = v;
1565 if (gamemode == GAME_ROGUE)
1567 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_nails1)))
1570 if (host_client->edict->fields.server->weapon <= IT_LIGHTNING)
1571 host_client->edict->fields.server->ammo_nails = v;
1576 host_client->edict->fields.server->ammo_nails = v;
1580 if (gamemode == GAME_ROGUE)
1582 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_lava_nails);
1586 if (host_client->edict->fields.server->weapon > IT_LIGHTNING)
1587 host_client->edict->fields.server->ammo_nails = v;
1592 if (gamemode == GAME_ROGUE)
1594 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_rockets1);
1598 if (host_client->edict->fields.server->weapon <= IT_LIGHTNING)
1599 host_client->edict->fields.server->ammo_rockets = v;
1604 host_client->edict->fields.server->ammo_rockets = v;
1608 if (gamemode == GAME_ROGUE)
1610 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_multi_rockets);
1614 if (host_client->edict->fields.server->weapon > IT_LIGHTNING)
1615 host_client->edict->fields.server->ammo_rockets = v;
1620 host_client->edict->fields.server->health = v;
1623 if (gamemode == GAME_ROGUE)
1625 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_cells1);
1629 if (host_client->edict->fields.server->weapon <= IT_LIGHTNING)
1630 host_client->edict->fields.server->ammo_cells = v;
1635 host_client->edict->fields.server->ammo_cells = v;
1639 if (gamemode == GAME_ROGUE)
1641 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_plasma);
1645 if (host_client->edict->fields.server->weapon > IT_LIGHTNING)
1646 host_client->edict->fields.server->ammo_cells = v;
1653 prvm_edict_t *FindViewthing (void)
1658 for (i=0 ; i<prog->num_edicts ; i++)
1660 e = PRVM_EDICT_NUM(i);
1661 if (!strcmp (PRVM_GetString(e->fields.server->classname), "viewthing"))
1664 Con_Print("No viewthing on map\n");
1673 void Host_Viewmodel_f (void)
1682 e = FindViewthing ();
1687 m = Mod_ForName (Cmd_Argv(1), false, true, false);
1688 if (!m || !m->loaded || !m->Draw)
1690 Con_Printf("viewmodel: can't load %s\n", Cmd_Argv(1));
1694 e->fields.server->frame = 0;
1695 cl.model_precache[(int)e->fields.server->modelindex] = m;
1703 void Host_Viewframe_f (void)
1713 e = FindViewthing ();
1717 m = cl.model_precache[(int)e->fields.server->modelindex];
1719 f = atoi(Cmd_Argv(1));
1720 if (f >= m->numframes)
1723 e->fields.server->frame = f;
1727 void PrintFrameName (model_t *m, int frame)
1730 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1732 Con_Printf("frame %i\n", frame);
1740 void Host_Viewnext_f (void)
1749 e = FindViewthing ();
1753 m = cl.model_precache[(int)e->fields.server->modelindex];
1755 e->fields.server->frame = e->fields.server->frame + 1;
1756 if (e->fields.server->frame >= m->numframes)
1757 e->fields.server->frame = m->numframes - 1;
1759 PrintFrameName (m, e->fields.server->frame);
1767 void Host_Viewprev_f (void)
1776 e = FindViewthing ();
1781 m = cl.model_precache[(int)e->fields.server->modelindex];
1783 e->fields.server->frame = e->fields.server->frame - 1;
1784 if (e->fields.server->frame < 0)
1785 e->fields.server->frame = 0;
1787 PrintFrameName (m, e->fields.server->frame);
1791 ===============================================================================
1795 ===============================================================================
1804 void Host_Startdemos_f (void)
1808 if (cls.state == ca_dedicated || COM_CheckParm("-listen") || COM_CheckParm("-benchmark") || COM_CheckParm("-demo") || COM_CheckParm("-demolooponly"))
1814 Con_Printf("Max %i demos in demoloop\n", MAX_DEMOS);
1817 Con_Printf("%i demo(s) in loop\n", c);
1819 for (i=1 ; i<c+1 ; i++)
1820 strlcpy (cls.demos[i-1], Cmd_Argv(i), sizeof (cls.demos[i-1]));
1822 // LordHavoc: clear the remaining slots
1823 for (;i <= MAX_DEMOS;i++)
1824 cls.demos[i-1][0] = 0;
1826 if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
1840 Return to looping demos
1843 void Host_Demos_f (void)
1845 if (cls.state == ca_dedicated)
1847 if (cls.demonum == -1)
1857 Return to looping demos
1860 void Host_Stopdemo_f (void)
1862 if (!cls.demoplayback)
1865 Host_ShutdownServer (false);
1868 static void MaxPlayers_f(void)
1872 if (Cmd_Argc() != 2)
1874 Con_Printf("\"maxplayers\" is \"%u\"\n", svs.maxclients);
1880 Con_Print("maxplayers can not be changed while a server is running.\n");
1884 n = atoi(Cmd_Argv(1));
1885 n = bound(1, n, MAX_SCOREBOARD);
1886 Con_Printf("\"maxplayers\" set to \"%u\"\n", n);
1889 Mem_Free(svs.clients);
1891 svs.clients = Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients);
1893 Cvar_Set ("deathmatch", "0");
1895 Cvar_Set ("deathmatch", "1");
1898 //=============================================================================
1905 void Host_InitCommands (void)
1907 Cmd_AddCommand ("status", Host_Status_f);
1908 Cmd_AddCommand ("quit", Host_Quit_f);
1909 if (gamemode == GAME_NEHAHRA)
1911 Cmd_AddCommand ("max", Host_God_f);
1912 Cmd_AddCommand ("monster", Host_Notarget_f);
1913 Cmd_AddCommand ("scrag", Host_Fly_f);
1914 Cmd_AddCommand ("wraith", Host_Noclip_f);
1915 Cmd_AddCommand ("gimme", Host_Give_f);
1919 Cmd_AddCommand ("god", Host_God_f);
1920 Cmd_AddCommand ("notarget", Host_Notarget_f);
1921 Cmd_AddCommand ("fly", Host_Fly_f);
1922 Cmd_AddCommand ("noclip", Host_Noclip_f);
1923 Cmd_AddCommand ("give", Host_Give_f);
1925 Cmd_AddCommand ("map", Host_Map_f);
1926 Cmd_AddCommand ("restart", Host_Restart_f);
1927 Cmd_AddCommand ("changelevel", Host_Changelevel_f);
1928 Cmd_AddCommand ("connect", Host_Connect_f);
1929 Cmd_AddCommand ("reconnect", Host_Reconnect_f);
1930 Cmd_AddCommand ("version", Host_Version_f);
1931 Cmd_AddCommand ("say", Host_Say_f);
1932 Cmd_AddCommand ("say_team", Host_Say_Team_f);
1933 Cmd_AddCommand ("tell", Host_Tell_f);
1934 Cmd_AddCommand ("kill", Host_Kill_f);
1935 Cmd_AddCommand ("pause", Host_Pause_f);
1936 Cmd_AddCommand ("kick", Host_Kick_f);
1937 Cmd_AddCommand ("ping", Host_Ping_f);
1938 Cmd_AddCommand ("load", Host_Loadgame_f);
1939 Cmd_AddCommand ("save", Host_Savegame_f);
1941 Cmd_AddCommand ("startdemos", Host_Startdemos_f);
1942 Cmd_AddCommand ("demos", Host_Demos_f);
1943 Cmd_AddCommand ("stopdemo", Host_Stopdemo_f);
1945 Cmd_AddCommand ("viewmodel", Host_Viewmodel_f);
1946 Cmd_AddCommand ("viewframe", Host_Viewframe_f);
1947 Cmd_AddCommand ("viewnext", Host_Viewnext_f);
1948 Cmd_AddCommand ("viewprev", Host_Viewprev_f);
1950 Cvar_RegisterVariable (&cl_name);
1951 Cmd_AddCommand ("name", Host_Name_f);
1952 Cvar_RegisterVariable (&cl_color);
1953 Cmd_AddCommand ("color", Host_Color_f);
1954 Cvar_RegisterVariable (&cl_rate);
1955 Cmd_AddCommand ("rate", Host_Rate_f);
1956 if (gamemode == GAME_NEHAHRA)
1958 Cvar_RegisterVariable (&cl_pmodel);
1959 Cmd_AddCommand ("pmodel", Host_PModel_f);
1962 // BLACK: This isnt game specific anymore (it was GAME_NEXUIZ at first)
1963 Cvar_RegisterVariable (&cl_playermodel);
1964 Cmd_AddCommand ("playermodel", Host_Playermodel_f);
1965 Cvar_RegisterVariable (&cl_playerskin);
1966 Cmd_AddCommand ("playerskin", Host_Playerskin_f);
1968 Cmd_AddCommand ("prespawn", Host_PreSpawn_f);
1969 Cmd_AddCommand ("spawn", Host_Spawn_f);
1970 Cmd_AddCommand ("begin", Host_Begin_f);
1971 Cmd_AddCommand ("maxplayers", MaxPlayers_f);
1973 Cvar_RegisterVariable(&sv_cheats);