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");
297 if (!sv.active || cls.demoplayback)
299 Con_Print("Only the server may changelevel\n");
302 if (cmd_source != src_command)
305 // remove console or menu
307 key_consoleactive = 0;
310 SV_SaveSpawnparms ();
312 allowcheats = sv_cheats.integer != 0;
313 strcpy(level, Cmd_Argv(1));
314 SV_SpawnServer(level);
315 if (sv.active && cls.state == ca_disconnected)
318 CL_EstablishConnection("local:1");
327 Restarts the current server for a dead player
330 void Host_Restart_f (void)
332 char mapname[MAX_QPATH];
336 Con_Print("restart : restart current level\n");
339 if (!sv.active || cls.demoplayback)
341 Con_Print("Only the server may restart\n");
344 if (cmd_source != src_command)
347 // remove console or menu
349 key_consoleactive = 0;
351 allowcheats = sv_cheats.integer != 0;
352 strcpy(mapname, sv.name);
353 SV_SpawnServer(mapname);
354 if (sv.active && cls.state == ca_disconnected)
357 CL_EstablishConnection("local:1");
366 This command causes the client to wait for the signon messages again.
367 This is sent just before a server changes levels
370 void Host_Reconnect_f (void)
372 if (cmd_source == src_command)
374 Con_Print("reconnect is not valid from the console\n");
379 Con_Print("reconnect : wait for signon messages again\n");
384 //Con_Print("reconnect: no signon, ignoring reconnect\n");
387 cls.signon = 0; // need new connection messages
391 =====================
394 User command to connect to server
395 =====================
397 void Host_Connect_f (void)
401 Con_Print("connect <serveraddress> : connect to a multiplayer game\n");
406 CL_EstablishConnection(Cmd_Argv(1));
409 CL_EstablishConnection(Cmd_Argv(1));
415 ===============================================================================
419 ===============================================================================
422 #define SAVEGAME_VERSION 5
428 Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
431 void Host_SavegameComment (char *text)
436 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
438 memcpy (text, cl.levelname, strlen(cl.levelname));
439 sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
440 memcpy (text+22, kills, strlen(kills));
441 // convert space to _ to make stdio happy
442 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
445 text[SAVEGAME_COMMENT_LENGTH] = '\0';
454 void Host_Savegame_f (void)
459 char comment[SAVEGAME_COMMENT_LENGTH+1];
461 if (cmd_source != src_command)
464 if (cls.state != ca_connected || !sv.active)
466 Con_Print("Not playing a local game.\n");
472 Con_Print("Can't save in intermission.\n");
476 for (i = 0;i < svs.maxclients;i++)
478 if (svs.clients[i].active)
482 Con_Print("Can't save multiplayer games.\n");
485 if (svs.clients[i].edict->fields.server->deadflag)
487 Con_Print("Can't savegame with a dead player\n");
495 Con_Print("save <savename> : save a game\n");
499 if (strstr(Cmd_Argv(1), ".."))
501 Con_Print("Relative pathnames are not allowed.\n");
505 strlcpy (name, Cmd_Argv(1), sizeof (name));
506 FS_DefaultExtension (name, ".sav", sizeof (name));
508 Con_Printf("Saving game to %s...\n", name);
509 f = FS_Open (name, "wb", false, false);
512 Con_Print("ERROR: couldn't open.\n");
516 FS_Printf(f, "%i\n", SAVEGAME_VERSION);
517 Host_SavegameComment (comment);
518 FS_Printf(f, "%s\n", comment);
519 for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
520 FS_Printf(f, "%f\n", svs.clients[0].spawn_parms[i]);
521 FS_Printf(f, "%d\n", current_skill);
522 FS_Printf(f, "%s\n", sv.name);
523 FS_Printf(f, "%f\n",sv.time);
525 // write the light styles
526 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
528 if (sv.lightstyles[i][0])
529 FS_Printf(f, "%s\n", sv.lightstyles[i]);
536 PRVM_ED_WriteGlobals (f);
537 for (i=0 ; i<prog->num_edicts ; i++)
538 PRVM_ED_Write (f, PRVM_EDICT_NUM(i));
543 Con_Print("done.\n");
552 void Host_Loadgame_f (void)
554 char filename[MAX_QPATH];
555 char mapname[MAX_QPATH];
564 float spawn_parms[NUM_SPAWN_PARMS];
566 if (cmd_source != src_command)
571 Con_Print("load <savename> : load a game\n");
575 strcpy (filename, Cmd_Argv(1));
576 FS_DefaultExtension (filename, ".sav", sizeof (filename));
578 Con_Printf("Loading game from %s...\n", filename);
580 cls.demonum = -1; // stop demo loop in case this fails
582 t = text = FS_LoadFile (filename, tempmempool, false);
585 Con_Print("ERROR: couldn't open.\n");
590 COM_ParseToken(&t, false);
591 version = atoi(com_token);
592 if (version != SAVEGAME_VERSION)
595 Con_Printf("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
600 // this is a little hard to parse, as : is a separator in COM_ParseToken,
601 // so use the console parser instead
602 COM_ParseTokenConsole(&t);
604 for (i = 0;i < NUM_SPAWN_PARMS;i++)
606 COM_ParseToken(&t, false);
607 spawn_parms[i] = atof(com_token);
610 COM_ParseToken(&t, false);
611 // this silliness is so we can load 1.06 save files, which have float skill values
612 current_skill = (int)(atof(com_token) + 0.5);
613 Cvar_SetValue ("skill", (float)current_skill);
616 COM_ParseToken(&t, false);
617 strcpy (mapname, com_token);
620 COM_ParseToken(&t, false);
621 time = atof(com_token);
623 allowcheats = sv_cheats.integer != 0;
625 SV_SpawnServer (mapname);
629 Con_Print("Couldn't load map\n");
632 sv.paused = true; // pause until all clients connect
635 // load the light styles
637 for (i = 0;i < MAX_LIGHTSTYLES;i++)
640 COM_ParseToken(&t, false);
641 strlcpy(sv.lightstyles[i], com_token, sizeof(sv.lightstyles[i]));
644 // load the edicts out of the savegame file
651 while (COM_ParseToken(&t, false))
652 if (!strcmp(com_token, "}"))
654 if (!COM_ParseToken(&start, false))
659 if (strcmp(com_token,"{"))
662 Host_Error ("First token isn't a brace");
667 // parse the global vars
668 PRVM_ED_ParseGlobals (start);
673 if (entnum >= MAX_EDICTS)
676 Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)\n", MAX_EDICTS);
678 while (entnum >= prog->max_edicts)
679 //SV_IncreaseEdicts();
680 PRVM_MEM_IncreaseEdicts();
681 ent = PRVM_EDICT_NUM(entnum);
682 memset (ent->fields.server, 0, prog->progs->entityfields * 4);
683 ent->priv.server->free = false;
684 PRVM_ED_ParseEdict (start, ent);
686 // link it into the bsp tree
687 if (!ent->priv.server->free)
688 SV_LinkEdict (ent, false);
694 prog->num_edicts = entnum;
697 for (i = 0;i < NUM_SPAWN_PARMS;i++)
698 svs.clients[0].spawn_parms[i] = spawn_parms[i];
700 // make sure we're connected to loopback
701 if (cls.state == ca_disconnected || !(cls.state == ca_connected && cls.netcon != NULL && LHNETADDRESS_GetAddressType(&cls.netcon->peeraddress) == LHNETADDRESSTYPE_LOOP))
702 CL_EstablishConnection("local:1");
707 //============================================================================
710 ======================
712 ======================
714 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player"};
715 void Host_Name_f (void)
718 char newName[sizeof(host_client->name)];
720 if (Cmd_Argc () == 1)
722 Con_Printf("\"name\" is \"%s\"\n", cl_name.string);
726 if (Cmd_Argc () == 2)
727 strlcpy (newName, Cmd_Argv(1), sizeof (newName));
729 strlcpy (newName, Cmd_Args(), sizeof (newName));
731 for (i = 0, j = 0;newName[i];i++)
732 if (newName[i] != '\r' && newName[i] != '\n')
733 newName[j++] = newName[i];
736 if (cmd_source == src_command)
738 Cvar_Set ("_cl_name", newName);
739 if (cls.state == ca_connected)
740 Cmd_ForwardToServer ();
744 if (sv.time < host_client->nametime)
746 SV_ClientPrintf("You can't change name more than once every 5 seconds!\n");
750 host_client->nametime = sv.time + 5;
752 // point the string back at updateclient->name to keep it safe
753 strlcpy (host_client->name, newName, sizeof (host_client->name));
754 host_client->edict->fields.server->netname = PRVM_SetEngineString(host_client->name);
755 if (strcmp(host_client->old_name, host_client->name))
757 if (host_client->spawned)
758 SV_BroadcastPrintf("%s changed name to %s\n", host_client->old_name, host_client->name);
759 strcpy(host_client->old_name, host_client->name);
760 // send notification to all clients
761 MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
762 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
763 MSG_WriteString (&sv.reliable_datagram, host_client->name);
768 ======================
770 ======================
772 cvar_t cl_playermodel = {CVAR_SAVE, "_cl_playermodel", ""};
773 // the old cl_playermodel in cl_main has been renamed to __cl_playermodel
774 void Host_Playermodel_f (void)
777 char newPath[sizeof(host_client->playermodel)];
779 if (Cmd_Argc () == 1)
781 Con_Printf("\"playermodel\" is \"%s\"\n", cl_playermodel.string);
785 if (Cmd_Argc () == 2)
786 strlcpy (newPath, Cmd_Argv(1), sizeof (newPath));
788 strlcpy (newPath, Cmd_Args(), sizeof (newPath));
790 for (i = 0, j = 0;newPath[i];i++)
791 if (newPath[i] != '\r' && newPath[i] != '\n')
792 newPath[j++] = newPath[i];
795 if (cmd_source == src_command)
797 Cvar_Set ("_cl_playermodel", newPath);
798 if (cls.state == ca_connected)
799 Cmd_ForwardToServer ();
804 if (sv.time < host_client->nametime)
806 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
810 host_client->nametime = sv.time + 5;
813 // point the string back at updateclient->name to keep it safe
814 strlcpy (host_client->playermodel, newPath, sizeof (host_client->playermodel));
815 if( eval_playermodel )
816 PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_playermodel)->string = PRVM_SetEngineString(host_client->playermodel);
817 if (strcmp(host_client->old_model, host_client->playermodel))
819 if (host_client->spawned)
820 SV_BroadcastPrintf("%s changed model to %s\n", host_client->name, host_client->playermodel);
821 strcpy(host_client->old_model, host_client->playermodel);
822 /*// send notification to all clients
823 MSG_WriteByte (&sv.reliable_datagram, svc_updatepmodel);
824 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
825 MSG_WriteString (&sv.reliable_datagram, host_client->playermodel);*/
830 ======================
832 ======================
834 cvar_t cl_playerskin = {CVAR_SAVE, "_cl_playerskin", ""};
835 void Host_Playerskin_f (void)
838 char newPath[sizeof(host_client->playerskin)];
840 if (Cmd_Argc () == 1)
842 Con_Printf("\"playerskin\" is \"%s\"\n", cl_playerskin.string);
846 if (Cmd_Argc () == 2)
847 strlcpy (newPath, Cmd_Argv(1), sizeof (newPath));
849 strlcpy (newPath, Cmd_Args(), sizeof (newPath));
851 for (i = 0, j = 0;newPath[i];i++)
852 if (newPath[i] != '\r' && newPath[i] != '\n')
853 newPath[j++] = newPath[i];
856 if (cmd_source == src_command)
858 Cvar_Set ("_cl_playerskin", newPath);
859 if (cls.state == ca_connected)
860 Cmd_ForwardToServer ();
865 if (sv.time < host_client->nametime)
867 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
871 host_client->nametime = sv.time + 5;
874 // point the string back at updateclient->name to keep it safe
875 strlcpy (host_client->playerskin, newPath, sizeof (host_client->playerskin));
876 if( eval_playerskin )
877 PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_playerskin)->string = PRVM_SetEngineString(host_client->playerskin);
878 if (strcmp(host_client->old_skin, host_client->playerskin))
880 if (host_client->spawned)
881 SV_BroadcastPrintf("%s changed skin to %s\n", host_client->name, host_client->playerskin);
882 strcpy(host_client->old_skin, host_client->playerskin);
883 /*// send notification to all clients
884 MSG_WriteByte (&sv.reliable_datagram, svc_updatepskin);
885 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
886 MSG_WriteString (&sv.reliable_datagram, host_client->playerskin);*/
890 void Host_Version_f (void)
892 Con_Printf("Version: %s build %s\n", gamename, buildstring);
895 void Host_Say(qboolean teamonly)
901 // LordHavoc: 256 char say messages
902 unsigned char text[256];
903 qboolean fromServer = false;
905 if (cmd_source == src_command)
907 if (cls.state == ca_dedicated)
914 Cmd_ForwardToServer ();
922 if (!teamplay.integer)
925 // turn on color set 1
934 dpsnprintf (text, sizeof(text), "%c%s: %s", 1, host_client->name, p1);
936 dpsnprintf (text, sizeof(text), "%c<%s> %s", 1, hostname.string, p1);
937 p2 = text + strlen(text);
938 while ((const char *)p2 > (const char *)text && (p2[-1] == '\r' || p2[-1] == '\n' || (p2[-1] == '\"' && quoted)))
940 if (p2[-1] == '\"' && quoted)
945 strlcat(text, "\n", sizeof(text));
947 // note: save is not a valid edict if fromServer is true
949 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
950 if (host_client->spawned && (!teamonly || host_client->edict->fields.server->team == save->edict->fields.server->team))
951 SV_ClientPrint(text);
954 if (cls.state == ca_dedicated)
959 void Host_Say_f(void)
965 void Host_Say_Team_f(void)
971 void Host_Tell_f(void)
976 char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
977 qboolean fromServer = false;
979 if (cmd_source == src_command)
981 if (cls.state == ca_dedicated)
985 Cmd_ForwardToServer ();
994 sprintf (text, "%s: ", host_client->name);
996 sprintf (text, "<%s> ", hostname.string);
999 p2 = p1 + strlen(p1);
1000 // remove the target name
1001 while (p1 < p2 && *p1 != ' ')
1003 while (p1 < p2 && *p1 == ' ')
1005 // remove trailing newlines
1006 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
1008 // remove quotes if present
1014 else if (fromServer)
1015 Con_Print("Host_Tell: missing end quote\n");
1017 SV_ClientPrint("Host_Tell: missing end quote\n");
1019 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
1021 for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
1027 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
1028 if (host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1)))
1029 SV_ClientPrint(text);
1039 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0"};
1040 void Host_Color_f(void)
1045 func_t SV_ChangeTeam;
1047 if (Cmd_Argc() == 1)
1049 Con_Printf("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
1050 Con_Print("color <0-15> [0-15]\n");
1054 if (Cmd_Argc() == 2)
1055 top = bottom = atoi(Cmd_Argv(1));
1058 top = atoi(Cmd_Argv(1));
1059 bottom = atoi(Cmd_Argv(2));
1063 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
1067 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
1071 playercolor = top*16 + bottom;
1073 if (cmd_source == src_command)
1075 Cvar_SetValue ("_cl_color", playercolor);
1076 if (cls.state == ca_connected)
1077 Cmd_ForwardToServer ();
1081 if (host_client->edict && (f = PRVM_ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - prog->functions)))
1083 Con_DPrint("Calling SV_ChangeTeam\n");
1084 prog->globals.server->time = sv.time;
1085 prog->globals.generic[OFS_PARM0] = playercolor;
1086 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1087 PRVM_ExecuteProgram (SV_ChangeTeam, "QC function SV_ChangeTeam is missing");
1092 if (host_client->edict)
1094 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_clientcolors)))
1095 val->_float = playercolor;
1096 host_client->edict->fields.server->team = bottom + 1;
1098 host_client->colors = playercolor;
1099 if (host_client->old_colors != host_client->colors)
1101 host_client->old_colors = host_client->colors;
1102 // send notification to all clients
1103 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
1104 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
1105 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
1110 cvar_t cl_rate = {CVAR_SAVE, "_cl_rate", "10000"};
1111 void Host_Rate_f(void)
1115 if (Cmd_Argc() != 2)
1117 Con_Printf("\"rate\" is \"%i\"\n", cl_rate.integer);
1118 Con_Print("rate <500-25000>\n");
1122 rate = atoi(Cmd_Argv(1));
1124 if (cmd_source == src_command)
1126 Cvar_SetValue ("_cl_rate", bound(NET_MINRATE, rate, NET_MAXRATE));
1127 if (cls.state == ca_connected)
1128 Cmd_ForwardToServer ();
1132 host_client->rate = rate;
1140 void Host_Kill_f (void)
1142 if (cmd_source == src_command)
1144 Cmd_ForwardToServer ();
1148 if (host_client->edict->fields.server->health <= 0)
1150 SV_ClientPrint("Can't suicide -- already dead!\n");
1154 prog->globals.server->time = sv.time;
1155 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1156 PRVM_ExecuteProgram (prog->globals.server->ClientKill, "QC function ClientKill is missing");
1165 void Host_Pause_f (void)
1168 if (cmd_source == src_command)
1170 Cmd_ForwardToServer ();
1173 if (!pausable.integer)
1174 SV_ClientPrint("Pause not allowed.\n");
1178 SV_BroadcastPrintf("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
1179 // send notification to all clients
1180 MSG_WriteByte(&sv.reliable_datagram, svc_setpause);
1181 MSG_WriteByte(&sv.reliable_datagram, sv.paused);
1186 ======================
1188 LordHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
1189 ======================
1191 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0"};
1192 static void Host_PModel_f (void)
1197 if (Cmd_Argc () == 1)
1199 Con_Printf("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
1202 i = atoi(Cmd_Argv(1));
1204 if (cmd_source == src_command)
1206 if (cl_pmodel.integer == i)
1208 Cvar_SetValue ("_cl_pmodel", i);
1209 if (cls.state == ca_connected)
1210 Cmd_ForwardToServer ();
1214 if (host_client->edict && (val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_pmodel)))
1218 //===========================================================================
1226 void Host_PreSpawn_f (void)
1228 if (cmd_source == src_command)
1230 Con_Print("prespawn is not valid from the console\n");
1234 if (host_client->spawned)
1236 Con_Print("prespawn not valid -- already spawned\n");
1240 SZ_Write (&host_client->message, sv.signon.data, sv.signon.cursize);
1241 MSG_WriteByte (&host_client->message, svc_signonnum);
1242 MSG_WriteByte (&host_client->message, 2);
1243 host_client->sendsignon = true;
1245 // reset the name change timer because the client will send name soon
1246 host_client->nametime = 0;
1254 void Host_Spawn_f (void)
1260 int stats[MAX_CL_STATS];
1262 if (cmd_source == src_command)
1264 Con_Print("spawn is not valid from the console\n");
1268 if (host_client->spawned)
1270 Con_Print("Spawn not valid -- already spawned\n");
1274 // reset name change timer again because they might want to change name
1275 // again in the first 5 seconds after connecting
1276 host_client->nametime = 0;
1278 // LordHavoc: moved this above the QC calls at FrikaC's request
1279 // send all current names, colors, and frag counts
1280 SZ_Clear (&host_client->message);
1282 // run the entrance script
1285 // loaded games are fully initialized already
1286 // if this is the last client to be connected, unpause
1289 if ((f = PRVM_ED_FindFunction ("RestoreGame")))
1290 if ((RestoreGame = (func_t)(f - prog->functions)))
1292 Con_DPrint("Calling RestoreGame\n");
1293 prog->globals.server->time = sv.time;
1294 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1295 PRVM_ExecuteProgram (RestoreGame, "QC function RestoreGame is missing");
1301 PRVM_ED_ClearEdict(host_client->edict);
1303 //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);
1305 // copy spawn parms out of the client_t
1306 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1307 (&prog->globals.server->parm1)[i] = host_client->spawn_parms[i];
1309 // call the spawn function
1310 host_client->clientconnectcalled = true;
1311 prog->globals.server->time = sv.time;
1312 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1313 PRVM_ExecuteProgram (prog->globals.server->ClientConnect, "QC function ClientConnect is missing");
1315 if ((Sys_DoubleTime() - host_client->connecttime) <= sv.time)
1316 Con_Printf("%s entered the game\n", host_client->name);
1318 PRVM_ExecuteProgram (prog->globals.server->PutClientInServer, "QC function PutClientInServer is missing");
1322 // send time of update
1323 MSG_WriteByte (&host_client->message, svc_time);
1324 MSG_WriteFloat (&host_client->message, sv.time);
1326 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
1328 if (!client->active)
1330 MSG_WriteByte (&host_client->message, svc_updatename);
1331 MSG_WriteByte (&host_client->message, i);
1332 MSG_WriteString (&host_client->message, client->name);
1333 MSG_WriteByte (&host_client->message, svc_updatefrags);
1334 MSG_WriteByte (&host_client->message, i);
1335 MSG_WriteShort (&host_client->message, client->frags);
1336 MSG_WriteByte (&host_client->message, svc_updatecolors);
1337 MSG_WriteByte (&host_client->message, i);
1338 MSG_WriteByte (&host_client->message, client->colors);
1341 // send all current light styles
1342 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1344 MSG_WriteByte (&host_client->message, svc_lightstyle);
1345 MSG_WriteByte (&host_client->message, (char)i);
1346 MSG_WriteString (&host_client->message, sv.lightstyles[i]);
1350 MSG_WriteByte (&host_client->message, svc_updatestat);
1351 MSG_WriteByte (&host_client->message, STAT_TOTALSECRETS);
1352 MSG_WriteLong (&host_client->message, prog->globals.server->total_secrets);
1354 MSG_WriteByte (&host_client->message, svc_updatestat);
1355 MSG_WriteByte (&host_client->message, STAT_TOTALMONSTERS);
1356 MSG_WriteLong (&host_client->message, prog->globals.server->total_monsters);
1358 MSG_WriteByte (&host_client->message, svc_updatestat);
1359 MSG_WriteByte (&host_client->message, STAT_SECRETS);
1360 MSG_WriteLong (&host_client->message, prog->globals.server->found_secrets);
1362 MSG_WriteByte (&host_client->message, svc_updatestat);
1363 MSG_WriteByte (&host_client->message, STAT_MONSTERS);
1364 MSG_WriteLong (&host_client->message, prog->globals.server->killed_monsters);
1367 // Never send a roll angle, because savegames can catch the server
1368 // in a state where it is expecting the client to correct the angle
1369 // and it won't happen if the game was just loaded, so you wind up
1370 // with a permanent head tilt
1371 MSG_WriteByte (&host_client->message, svc_setangle);
1372 MSG_WriteAngle (&host_client->message, host_client->edict->fields.server->angles[0], sv.protocol);
1373 MSG_WriteAngle (&host_client->message, host_client->edict->fields.server->angles[1], sv.protocol);
1374 MSG_WriteAngle (&host_client->message, 0, sv.protocol);
1376 SV_WriteClientdataToMessage (host_client, host_client->edict, &host_client->message, stats);
1378 MSG_WriteByte (&host_client->message, svc_signonnum);
1379 MSG_WriteByte (&host_client->message, 3);
1380 host_client->sendsignon = true;
1388 void Host_Begin_f (void)
1390 if (cmd_source == src_command)
1392 Con_Print("begin is not valid from the console\n");
1396 host_client->spawned = true;
1399 //===========================================================================
1406 Kicks a user off of the server
1409 void Host_Kick_f (void)
1412 const char *message = NULL;
1415 qboolean byNumber = false;
1417 if (cmd_source != src_command || !sv.active)
1423 if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1425 i = atof(Cmd_Argv(2)) - 1;
1426 if (i < 0 || i >= svs.maxclients || !(host_client = svs.clients + i)->active)
1432 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1434 if (!host_client->active)
1436 if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1441 if (i < svs.maxclients)
1443 if (cmd_source == src_command)
1445 if (cls.state == ca_dedicated)
1448 who = cl_name.string;
1453 // can't kick yourself!
1454 if (host_client == save)
1459 message = Cmd_Args();
1460 COM_ParseToken(&message, false);
1463 message++; // skip the #
1464 while (*message == ' ') // skip white space
1466 message += strlen(Cmd_Argv(2)); // skip the number
1468 while (*message && *message == ' ')
1472 SV_ClientPrintf("Kicked by %s: %s\n", who, message);
1474 SV_ClientPrintf("Kicked by %s\n", who);
1475 SV_DropClient (false); // kicked
1483 ===============================================================================
1487 ===============================================================================
1495 void Host_Give_f (void)
1501 if (cmd_source == src_command)
1503 Cmd_ForwardToServer ();
1509 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
1514 v = atoi (Cmd_Argv(2));
1528 // MED 01/04/97 added hipnotic give stuff
1529 if (gamemode == GAME_HIPNOTIC)
1534 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | HIT_PROXIMITY_GUN;
1536 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | IT_GRENADE_LAUNCHER;
1538 else if (t[0] == '9')
1539 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | HIT_LASER_CANNON;
1540 else if (t[0] == '0')
1541 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | HIT_MJOLNIR;
1542 else if (t[0] >= '2')
1543 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | (IT_SHOTGUN << (t[0] - '2'));
1548 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | (IT_SHOTGUN << (t[0] - '2'));
1553 if (gamemode == GAME_ROGUE && (val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_shells1)))
1556 host_client->edict->fields.server->ammo_shells = v;
1559 if (gamemode == GAME_ROGUE)
1561 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_nails1)))
1564 if (host_client->edict->fields.server->weapon <= IT_LIGHTNING)
1565 host_client->edict->fields.server->ammo_nails = v;
1570 host_client->edict->fields.server->ammo_nails = v;
1574 if (gamemode == GAME_ROGUE)
1576 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_lava_nails);
1580 if (host_client->edict->fields.server->weapon > IT_LIGHTNING)
1581 host_client->edict->fields.server->ammo_nails = v;
1586 if (gamemode == GAME_ROGUE)
1588 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_rockets1);
1592 if (host_client->edict->fields.server->weapon <= IT_LIGHTNING)
1593 host_client->edict->fields.server->ammo_rockets = v;
1598 host_client->edict->fields.server->ammo_rockets = v;
1602 if (gamemode == GAME_ROGUE)
1604 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_multi_rockets);
1608 if (host_client->edict->fields.server->weapon > IT_LIGHTNING)
1609 host_client->edict->fields.server->ammo_rockets = v;
1614 host_client->edict->fields.server->health = v;
1617 if (gamemode == GAME_ROGUE)
1619 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_cells1);
1623 if (host_client->edict->fields.server->weapon <= IT_LIGHTNING)
1624 host_client->edict->fields.server->ammo_cells = v;
1629 host_client->edict->fields.server->ammo_cells = v;
1633 if (gamemode == GAME_ROGUE)
1635 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_plasma);
1639 if (host_client->edict->fields.server->weapon > IT_LIGHTNING)
1640 host_client->edict->fields.server->ammo_cells = v;
1647 prvm_edict_t *FindViewthing (void)
1652 for (i=0 ; i<prog->num_edicts ; i++)
1654 e = PRVM_EDICT_NUM(i);
1655 if (!strcmp (PRVM_GetString(e->fields.server->classname), "viewthing"))
1658 Con_Print("No viewthing on map\n");
1667 void Host_Viewmodel_f (void)
1676 e = FindViewthing ();
1681 m = Mod_ForName (Cmd_Argv(1), false, true, false);
1684 Con_Printf("Can't load %s\n", Cmd_Argv(1));
1688 e->fields.server->frame = 0;
1689 cl.model_precache[(int)e->fields.server->modelindex] = m;
1697 void Host_Viewframe_f (void)
1707 e = FindViewthing ();
1711 m = cl.model_precache[(int)e->fields.server->modelindex];
1713 f = atoi(Cmd_Argv(1));
1714 if (f >= m->numframes)
1717 e->fields.server->frame = f;
1721 void PrintFrameName (model_t *m, int frame)
1724 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1726 Con_Printf("frame %i\n", frame);
1734 void Host_Viewnext_f (void)
1743 e = FindViewthing ();
1747 m = cl.model_precache[(int)e->fields.server->modelindex];
1749 e->fields.server->frame = e->fields.server->frame + 1;
1750 if (e->fields.server->frame >= m->numframes)
1751 e->fields.server->frame = m->numframes - 1;
1753 PrintFrameName (m, e->fields.server->frame);
1761 void Host_Viewprev_f (void)
1770 e = FindViewthing ();
1775 m = cl.model_precache[(int)e->fields.server->modelindex];
1777 e->fields.server->frame = e->fields.server->frame - 1;
1778 if (e->fields.server->frame < 0)
1779 e->fields.server->frame = 0;
1781 PrintFrameName (m, e->fields.server->frame);
1785 ===============================================================================
1789 ===============================================================================
1798 void Host_Startdemos_f (void)
1802 if (cls.state == ca_dedicated || COM_CheckParm("-listen") || COM_CheckParm("-benchmark") || COM_CheckParm("-demo") || COM_CheckParm("-demolooponly"))
1808 Con_Printf("Max %i demos in demoloop\n", MAX_DEMOS);
1811 Con_Printf("%i demo(s) in loop\n", c);
1813 for (i=1 ; i<c+1 ; i++)
1814 strlcpy (cls.demos[i-1], Cmd_Argv(i), sizeof (cls.demos[i-1]));
1816 // LordHavoc: clear the remaining slots
1817 for (;i <= MAX_DEMOS;i++)
1818 cls.demos[i-1][0] = 0;
1820 if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
1834 Return to looping demos
1837 void Host_Demos_f (void)
1839 if (cls.state == ca_dedicated)
1841 if (cls.demonum == -1)
1851 Return to looping demos
1854 void Host_Stopdemo_f (void)
1856 if (!cls.demoplayback)
1859 Host_ShutdownServer (false);
1862 static void MaxPlayers_f(void)
1866 if (Cmd_Argc() != 2)
1868 Con_Printf("\"maxplayers\" is \"%u\"\n", svs.maxclients);
1874 Con_Print("maxplayers can not be changed while a server is running.\n");
1878 n = atoi(Cmd_Argv(1));
1879 n = bound(1, n, MAX_SCOREBOARD);
1880 Con_Printf("\"maxplayers\" set to \"%u\"\n", n);
1883 Mem_Free(svs.clients);
1885 svs.clients = Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients);
1887 Cvar_Set ("deathmatch", "0");
1889 Cvar_Set ("deathmatch", "1");
1892 //=============================================================================
1899 void Host_InitCommands (void)
1901 Cmd_AddCommand ("status", Host_Status_f);
1902 Cmd_AddCommand ("quit", Host_Quit_f);
1903 if (gamemode == GAME_NEHAHRA)
1905 Cmd_AddCommand ("max", Host_God_f);
1906 Cmd_AddCommand ("monster", Host_Notarget_f);
1907 Cmd_AddCommand ("scrag", Host_Fly_f);
1908 Cmd_AddCommand ("wraith", Host_Noclip_f);
1909 Cmd_AddCommand ("gimme", Host_Give_f);
1913 Cmd_AddCommand ("god", Host_God_f);
1914 Cmd_AddCommand ("notarget", Host_Notarget_f);
1915 Cmd_AddCommand ("fly", Host_Fly_f);
1916 Cmd_AddCommand ("noclip", Host_Noclip_f);
1917 Cmd_AddCommand ("give", Host_Give_f);
1919 Cmd_AddCommand ("map", Host_Map_f);
1920 Cmd_AddCommand ("restart", Host_Restart_f);
1921 Cmd_AddCommand ("changelevel", Host_Changelevel_f);
1922 Cmd_AddCommand ("connect", Host_Connect_f);
1923 Cmd_AddCommand ("reconnect", Host_Reconnect_f);
1924 Cmd_AddCommand ("version", Host_Version_f);
1925 Cmd_AddCommand ("say", Host_Say_f);
1926 Cmd_AddCommand ("say_team", Host_Say_Team_f);
1927 Cmd_AddCommand ("tell", Host_Tell_f);
1928 Cmd_AddCommand ("kill", Host_Kill_f);
1929 Cmd_AddCommand ("pause", Host_Pause_f);
1930 Cmd_AddCommand ("kick", Host_Kick_f);
1931 Cmd_AddCommand ("ping", Host_Ping_f);
1932 Cmd_AddCommand ("load", Host_Loadgame_f);
1933 Cmd_AddCommand ("save", Host_Savegame_f);
1935 Cmd_AddCommand ("startdemos", Host_Startdemos_f);
1936 Cmd_AddCommand ("demos", Host_Demos_f);
1937 Cmd_AddCommand ("stopdemo", Host_Stopdemo_f);
1939 Cmd_AddCommand ("viewmodel", Host_Viewmodel_f);
1940 Cmd_AddCommand ("viewframe", Host_Viewframe_f);
1941 Cmd_AddCommand ("viewnext", Host_Viewnext_f);
1942 Cmd_AddCommand ("viewprev", Host_Viewprev_f);
1944 Cvar_RegisterVariable (&cl_name);
1945 Cmd_AddCommand ("name", Host_Name_f);
1946 Cvar_RegisterVariable (&cl_color);
1947 Cmd_AddCommand ("color", Host_Color_f);
1948 Cvar_RegisterVariable (&cl_rate);
1949 Cmd_AddCommand ("rate", Host_Rate_f);
1950 if (gamemode == GAME_NEHAHRA)
1952 Cvar_RegisterVariable (&cl_pmodel);
1953 Cmd_AddCommand ("pmodel", Host_PModel_f);
1956 // BLACK: This isnt game specific anymore (it was GAME_NEXUIZ at first)
1957 Cvar_RegisterVariable (&cl_playermodel);
1958 Cmd_AddCommand ("playermodel", Host_Playermodel_f);
1959 Cvar_RegisterVariable (&cl_playerskin);
1960 Cmd_AddCommand ("playerskin", Host_Playerskin_f);
1962 Cmd_AddCommand ("prespawn", Host_PreSpawn_f);
1963 Cmd_AddCommand ("spawn", Host_Spawn_f);
1964 Cmd_AddCommand ("begin", Host_Begin_f);
1965 Cmd_AddCommand ("maxplayers", MaxPlayers_f);
1967 Cvar_RegisterVariable(&sv_cheats);