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;
27 mfunction_t *ED_FindFunction (char *name);
35 void Host_Quit_f (void)
46 void Host_Status_f (void)
49 int seconds, minutes, hours = 0, j, players;
50 void (*print) (const char *fmt, ...);
52 if (cmd_source == src_command)
56 Cmd_ForwardToServer ();
62 print = SV_ClientPrintf;
64 for (players = 0, j = 0;j < svs.maxclients;j++)
65 if (svs.clients[j].active)
67 print ("host: %s\n", Cvar_VariableString ("hostname"));
68 print ("version: %s build %s\n", gamename, buildstring);
69 print ("protocol: %i (%s)\n", Protocol_NumberForEnum(sv.protocol), Protocol_NameForEnum(sv.protocol));
70 print ("map: %s\n", sv.name);
71 print ("players: %i active (%i max)\n\n", players, svs.maxclients);
72 for (j = 0, client = svs.clients;j < svs.maxclients;j++, client++)
76 seconds = (int)(realtime - client->connecttime);
77 minutes = seconds / 60;
80 seconds -= (minutes * 60);
83 minutes -= (hours * 60);
87 print ("#%-2u %-16.16s %3i %2i:%02i:%02i\n", j+1, client->name, (int)client->edict->v->frags, hours, minutes, seconds);
88 print (" %s\n", client->netconnection ? client->netconnection->address : "botclient");
97 Sets client to godmode
100 void Host_God_f (void)
102 if (cmd_source == src_command)
104 Cmd_ForwardToServer ();
110 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
114 host_client->edict->v->flags = (int)host_client->edict->v->flags ^ FL_GODMODE;
115 if (!((int)host_client->edict->v->flags & FL_GODMODE) )
116 SV_ClientPrint("godmode OFF\n");
118 SV_ClientPrint("godmode ON\n");
121 void Host_Notarget_f (void)
123 if (cmd_source == src_command)
125 Cmd_ForwardToServer ();
131 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
135 host_client->edict->v->flags = (int)host_client->edict->v->flags ^ FL_NOTARGET;
136 if (!((int)host_client->edict->v->flags & FL_NOTARGET) )
137 SV_ClientPrint("notarget OFF\n");
139 SV_ClientPrint("notarget ON\n");
142 qboolean noclip_anglehack;
144 void Host_Noclip_f (void)
146 if (cmd_source == src_command)
148 Cmd_ForwardToServer ();
154 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
158 if (host_client->edict->v->movetype != MOVETYPE_NOCLIP)
160 noclip_anglehack = true;
161 host_client->edict->v->movetype = MOVETYPE_NOCLIP;
162 SV_ClientPrint("noclip ON\n");
166 noclip_anglehack = false;
167 host_client->edict->v->movetype = MOVETYPE_WALK;
168 SV_ClientPrint("noclip OFF\n");
176 Sets client to flymode
179 void Host_Fly_f (void)
181 if (cmd_source == src_command)
183 Cmd_ForwardToServer ();
189 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
193 if (host_client->edict->v->movetype != MOVETYPE_FLY)
195 host_client->edict->v->movetype = MOVETYPE_FLY;
196 SV_ClientPrint("flymode ON\n");
200 host_client->edict->v->movetype = MOVETYPE_WALK;
201 SV_ClientPrint("flymode OFF\n");
212 void Host_Ping_f (void)
218 if (cmd_source == src_command)
220 Cmd_ForwardToServer ();
224 SV_ClientPrint("Client ping times:\n");
225 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
230 for (j=0 ; j<NUM_PING_TIMES ; j++)
231 total+=client->ping_times[j];
232 total /= NUM_PING_TIMES;
233 SV_ClientPrintf("%4i %s\n", (int)(total*1000), 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(false);
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)
281 CL_EstablishConnection("local:1");
288 Goes to a new map, taking all clients along
291 void Host_Changelevel_f (void)
293 char level[MAX_QPATH];
297 Con_Print("changelevel <levelname> : continue game on a new level\n");
300 if (!sv.active || cls.demoplayback)
302 Con_Print("Only the server may changelevel\n");
305 if (cmd_source != src_command)
308 // remove console or menu
310 key_consoleactive = 0;
312 SV_SaveSpawnparms ();
313 allowcheats = sv_cheats.integer != 0;
314 strcpy(level, Cmd_Argv(1));
315 SV_SpawnServer(level);
316 if (sv.active && cls.state == ca_disconnected)
317 CL_EstablishConnection("local:1");
324 Restarts the current server for a dead player
327 void Host_Restart_f (void)
329 char mapname[MAX_QPATH];
333 Con_Print("restart : restart current level\n");
336 if (!sv.active || cls.demoplayback)
338 Con_Print("Only the server may restart\n");
341 if (cmd_source != src_command)
344 // remove console or menu
346 key_consoleactive = 0;
348 allowcheats = sv_cheats.integer != 0;
349 strcpy(mapname, sv.name);
350 SV_SpawnServer(mapname);
351 if (sv.active && cls.state == ca_disconnected)
352 CL_EstablishConnection("local:1");
359 This command causes the client to wait for the signon messages again.
360 This is sent just before a server changes levels
363 void Host_Reconnect_f (void)
367 Con_Print("reconnect : wait for signon messages again\n");
372 //Con_Print("reconnect: no signon, ignoring reconnect\n");
375 cls.signon = 0; // need new connection messages
379 =====================
382 User command to connect to server
383 =====================
385 void Host_Connect_f (void)
389 Con_Print("connect <serveraddress> : connect to a multiplayer game\n");
392 CL_EstablishConnection(Cmd_Argv(1));
397 ===============================================================================
401 ===============================================================================
404 #define SAVEGAME_VERSION 5
410 Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
413 void Host_SavegameComment (char *text)
418 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
420 memcpy (text, cl.levelname, strlen(cl.levelname));
421 sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
422 memcpy (text+22, kills, strlen(kills));
423 // convert space to _ to make stdio happy
424 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
427 text[SAVEGAME_COMMENT_LENGTH] = '\0';
436 void Host_Savegame_f (void)
441 char comment[SAVEGAME_COMMENT_LENGTH+1];
443 if (cmd_source != src_command)
446 if (cls.state != ca_connected || !sv.active)
448 Con_Print("Not playing a local game.\n");
454 Con_Print("Can't save in intermission.\n");
458 for (i = 0;i < svs.maxclients;i++)
460 if (svs.clients[i].active)
464 Con_Print("Can't save multiplayer games.\n");
467 if (svs.clients[i].edict->v->deadflag)
469 Con_Print("Can't savegame with a dead player\n");
477 Con_Print("save <savename> : save a game\n");
481 if (strstr(Cmd_Argv(1), ".."))
483 Con_Print("Relative pathnames are not allowed.\n");
487 strlcpy (name, Cmd_Argv(1), sizeof (name));
488 FS_DefaultExtension (name, ".sav", sizeof (name));
490 Con_Printf("Saving game to %s...\n", name);
491 f = FS_Open (name, "wb", false, false);
494 Con_Print("ERROR: couldn't open.\n");
498 FS_Printf(f, "%i\n", SAVEGAME_VERSION);
499 Host_SavegameComment (comment);
500 FS_Printf(f, "%s\n", comment);
501 for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
502 FS_Printf(f, "%f\n", svs.clients[0].spawn_parms[i]);
503 FS_Printf(f, "%d\n", current_skill);
504 FS_Printf(f, "%s\n", sv.name);
505 FS_Printf(f, "%f\n",sv.time);
507 // write the light styles
508 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
510 if (sv.lightstyles[i][0])
511 FS_Printf(f, "%s\n", sv.lightstyles[i]);
517 for (i=0 ; i<sv.num_edicts ; i++)
518 ED_Write (f, EDICT_NUM(i));
520 Con_Print("done.\n");
529 void Host_Loadgame_f (void)
531 char filename[MAX_QPATH];
532 char mapname[MAX_QPATH];
541 float spawn_parms[NUM_SPAWN_PARMS];
543 if (cmd_source != src_command)
548 Con_Print("load <savename> : load a game\n");
552 strcpy (filename, Cmd_Argv(1));
553 FS_DefaultExtension (filename, ".sav", sizeof (filename));
555 Con_Printf("Loading game from %s...\n", filename);
557 cls.demonum = -1; // stop demo loop in case this fails
559 t = text = FS_LoadFile (filename, tempmempool, false);
562 Con_Print("ERROR: couldn't open.\n");
567 COM_ParseToken(&t, false);
568 version = atoi(com_token);
569 if (version != SAVEGAME_VERSION)
572 Con_Printf("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
577 // this is a little hard to parse, as : is a separator in COM_ParseToken,
578 // so use the console parser instead
579 COM_ParseTokenConsole(&t);
581 for (i = 0;i < NUM_SPAWN_PARMS;i++)
583 COM_ParseToken(&t, false);
584 spawn_parms[i] = atof(com_token);
587 COM_ParseToken(&t, false);
588 // this silliness is so we can load 1.06 save files, which have float skill values
589 current_skill = (int)(atof(com_token) + 0.5);
590 Cvar_SetValue ("skill", (float)current_skill);
593 COM_ParseToken(&t, false);
594 strcpy (mapname, com_token);
597 COM_ParseToken(&t, false);
598 time = atof(com_token);
600 allowcheats = sv_cheats.integer != 0;
602 SV_SpawnServer (mapname);
606 Con_Print("Couldn't load map\n");
609 sv.paused = true; // pause until all clients connect
612 // load the light styles
614 for (i = 0;i < MAX_LIGHTSTYLES;i++)
617 COM_ParseToken(&t, false);
618 strlcpy(sv.lightstyles[i], com_token, sizeof(sv.lightstyles[i]));
621 // load the edicts out of the savegame file
627 while (COM_ParseToken(&t, false))
628 if (!strcmp(com_token, "}"))
630 if (!COM_ParseToken(&start, false))
635 if (strcmp(com_token,"{"))
638 Host_Error ("First token isn't a brace");
643 // parse the global vars
644 ED_ParseGlobals (start);
649 if (entnum >= MAX_EDICTS)
652 Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)\n", MAX_EDICTS);
654 while (entnum >= sv.max_edicts)
656 ent = EDICT_NUM(entnum);
657 memset (ent->v, 0, progs->entityfields * 4);
658 ent->e->free = false;
659 ED_ParseEdict (start, ent);
661 // link it into the bsp tree
663 SV_LinkEdict (ent, false);
669 sv.num_edicts = entnum;
672 for (i = 0;i < NUM_SPAWN_PARMS;i++)
673 svs.clients[0].spawn_parms[i] = spawn_parms[i];
675 // make sure we're connected to loopback
676 if (cls.state == ca_disconnected || !(cls.state == ca_connected && cls.netcon != NULL && LHNETADDRESS_GetAddressType(&cls.netcon->peeraddress) == LHNETADDRESSTYPE_LOOP))
677 CL_EstablishConnection("local:1");
680 //============================================================================
683 ======================
685 ======================
687 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player"};
688 void Host_Name_f (void)
691 char newName[sizeof(host_client->name)];
693 if (Cmd_Argc () == 1)
695 Con_Printf("\"name\" is \"%s\"\n", cl_name.string);
699 if (Cmd_Argc () == 2)
700 strlcpy (newName, Cmd_Argv(1), sizeof (newName));
702 strlcpy (newName, Cmd_Args(), sizeof (newName));
704 for (i = 0, j = 0;newName[i];i++)
705 if (newName[i] != '\r' && newName[i] != '\n')
706 newName[j++] = newName[i];
709 if (cmd_source == src_command)
711 Cvar_Set ("_cl_name", newName);
712 if (cls.state == ca_connected)
713 Cmd_ForwardToServer ();
717 if (sv.time < host_client->nametime)
719 SV_ClientPrintf("You can't change name more than once every 5 seconds!\n");
723 host_client->nametime = sv.time + 5;
725 // point the string back at updateclient->name to keep it safe
726 strlcpy (host_client->name, newName, sizeof (host_client->name));
727 host_client->edict->v->netname = PR_SetEngineString(host_client->name);
728 if (strcmp(host_client->old_name, host_client->name))
730 if (host_client->spawned)
731 SV_BroadcastPrintf("%s changed name to %s\n", host_client->old_name, host_client->name);
732 strcpy(host_client->old_name, host_client->name);
733 // send notification to all clients
734 MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
735 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
736 MSG_WriteString (&sv.reliable_datagram, host_client->name);
741 ======================
743 ======================
745 cvar_t cl_playermodel = {CVAR_SAVE, "_cl_playermodel", ""};
746 // the old cl_playermodel in cl_main has been renamed to __cl_playermodel
747 void Host_Playermodel_f (void)
750 char newPath[sizeof(host_client->playermodel)];
752 if (Cmd_Argc () == 1)
754 Con_Printf("\"playermodel\" is \"%s\"\n", cl_playermodel.string);
758 if (Cmd_Argc () == 2)
759 strlcpy (newPath, Cmd_Argv(1), sizeof (newPath));
761 strlcpy (newPath, Cmd_Args(), sizeof (newPath));
763 for (i = 0, j = 0;newPath[i];i++)
764 if (newPath[i] != '\r' && newPath[i] != '\n')
765 newPath[j++] = newPath[i];
768 if (cmd_source == src_command)
770 Cvar_Set ("_cl_playermodel", newPath);
771 if (cls.state == ca_connected)
772 Cmd_ForwardToServer ();
777 if (sv.time < host_client->nametime)
779 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
783 host_client->nametime = sv.time + 5;
786 // point the string back at updateclient->name to keep it safe
787 strlcpy (host_client->playermodel, newPath, sizeof (host_client->playermodel));
788 if( eval_playermodel )
789 GETEDICTFIELDVALUE(host_client->edict, eval_playermodel)->string = PR_SetEngineString(host_client->playermodel);
790 if (strcmp(host_client->old_model, host_client->playermodel))
792 if (host_client->spawned)
793 SV_BroadcastPrintf("%s changed model to %s\n", host_client->old_model, host_client->playermodel);
794 strcpy(host_client->old_model, host_client->playermodel);
795 /*// send notification to all clients
796 MSG_WriteByte (&sv.reliable_datagram, svc_updatepmodel);
797 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
798 MSG_WriteString (&sv.reliable_datagram, host_client->playermodel);*/
803 ======================
805 ======================
807 cvar_t cl_playerskin = {CVAR_SAVE, "_cl_playerskin", ""};
808 void Host_Playerskin_f (void)
811 char newPath[sizeof(host_client->playerskin)];
813 if (Cmd_Argc () == 1)
815 Con_Printf("\"playerskin\" is \"%s\"\n", cl_playerskin.string);
819 if (Cmd_Argc () == 2)
820 strlcpy (newPath, Cmd_Argv(1), sizeof (newPath));
822 strlcpy (newPath, Cmd_Args(), sizeof (newPath));
824 for (i = 0, j = 0;newPath[i];i++)
825 if (newPath[i] != '\r' && newPath[i] != '\n')
826 newPath[j++] = newPath[i];
829 if (cmd_source == src_command)
831 Cvar_Set ("_cl_playerskin", newPath);
832 if (cls.state == ca_connected)
833 Cmd_ForwardToServer ();
838 if (sv.time < host_client->nametime)
840 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
844 host_client->nametime = sv.time + 5;
847 // point the string back at updateclient->name to keep it safe
848 strlcpy (host_client->playerskin, newPath, sizeof (host_client->playerskin));
849 if( eval_playerskin )
850 GETEDICTFIELDVALUE(host_client->edict, eval_playerskin)->string = PR_SetEngineString(host_client->playerskin);
851 if (strcmp(host_client->old_skin, host_client->playerskin))
853 if (host_client->spawned)
854 SV_BroadcastPrintf("%s changed skin to %s\n", host_client->old_skin, host_client->playerskin);
855 strcpy(host_client->old_skin, host_client->playerskin);
856 /*// send notification to all clients
857 MSG_WriteByte (&sv.reliable_datagram, svc_updatepskin);
858 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
859 MSG_WriteString (&sv.reliable_datagram, host_client->playerskin);*/
863 void Host_Version_f (void)
865 Con_Printf("Version: %s build %s\n", gamename, buildstring);
868 void Host_Say(qboolean teamonly)
874 // LordHavoc: 256 char say messages
875 unsigned char text[256];
876 qboolean fromServer = false;
878 if (cmd_source == src_command)
880 if (cls.state == ca_dedicated)
887 Cmd_ForwardToServer ();
895 if (!teamplay.integer)
898 // turn on color set 1
907 dpsnprintf (text, sizeof(text), "%c%s: %s", 1, host_client->name, p1);
909 dpsnprintf (text, sizeof(text), "%c<%s> %s", 1, hostname.string, p1);
910 p2 = text + strlen(text);
911 while ((const char *)p2 > (const char *)text && (p2[-1] == '\r' || p2[-1] == '\n' || (p2[-1] == '\"' && quoted)))
913 if (p2[-1] == '\"' && quoted)
918 strlcat(text, "\n", sizeof(text));
920 // note: save is not a valid edict if fromServer is true
922 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
923 if (host_client->spawned && (!teamonly || host_client->edict->v->team == save->edict->v->team))
924 SV_ClientPrint(text);
927 //Con_Print(&text[1]);
931 void Host_Say_f(void)
937 void Host_Say_Team_f(void)
943 void Host_Tell_f(void)
948 char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
949 qboolean fromServer = false;
951 if (cmd_source == src_command)
953 if (cls.state == ca_dedicated)
957 Cmd_ForwardToServer ();
966 sprintf (text, "%s: ", host_client->name);
968 sprintf (text, "<%s> ", hostname.string);
971 p2 = p1 + strlen(p1);
972 // remove the target name
973 while (p1 < p2 && *p1 != ' ')
975 while (p1 < p2 && *p1 == ' ')
977 // remove trailing newlines
978 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
980 // remove quotes if present
987 Con_Print("Host_Tell: missing end quote\n");
989 SV_ClientPrint("Host_Tell: missing end quote\n");
991 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
993 for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
999 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
1000 if (host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1)))
1001 SV_ClientPrint(text);
1011 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0"};
1012 void Host_Color_f(void)
1017 func_t SV_ChangeTeam;
1019 if (Cmd_Argc() == 1)
1021 Con_Printf("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
1022 Con_Print("color <0-15> [0-15]\n");
1026 if (Cmd_Argc() == 2)
1027 top = bottom = atoi(Cmd_Argv(1));
1030 top = atoi(Cmd_Argv(1));
1031 bottom = atoi(Cmd_Argv(2));
1035 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
1039 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
1043 playercolor = top*16 + bottom;
1045 if (cmd_source == src_command)
1047 Cvar_SetValue ("_cl_color", playercolor);
1048 if (cls.state == ca_connected)
1049 Cmd_ForwardToServer ();
1053 if (host_client->edict && (f = ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - pr_functions)))
1055 Con_DPrint("Calling SV_ChangeTeam\n");
1056 pr_global_struct->time = sv.time;
1057 pr_globals[OFS_PARM0] = playercolor;
1058 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1059 PR_ExecuteProgram (SV_ChangeTeam, "QC function SV_ChangeTeam is missing");
1064 if (host_client->edict)
1066 if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_clientcolors)))
1067 val->_float = playercolor;
1068 host_client->edict->v->team = bottom + 1;
1070 host_client->colors = playercolor;
1071 if (host_client->old_colors != host_client->colors)
1073 host_client->old_colors = host_client->colors;
1074 // send notification to all clients
1075 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
1076 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
1077 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
1082 cvar_t cl_rate = {CVAR_SAVE, "_cl_rate", "10000"};
1083 void Host_Rate_f(void)
1087 if (Cmd_Argc() != 2)
1089 Con_Printf("\"rate\" is \"%i\"\n", cl_rate.integer);
1090 Con_Print("rate <500-25000>\n");
1094 rate = atoi(Cmd_Argv(1));
1096 if (cmd_source == src_command)
1098 Cvar_SetValue ("_cl_rate", bound(NET_MINRATE, rate, NET_MAXRATE));
1099 if (cls.state == ca_connected)
1100 Cmd_ForwardToServer ();
1104 host_client->rate = rate;
1112 void Host_Kill_f (void)
1114 if (cmd_source == src_command)
1116 Cmd_ForwardToServer ();
1120 if (host_client->edict->v->health <= 0)
1122 SV_ClientPrint("Can't suicide -- already dead!\n");
1126 pr_global_struct->time = sv.time;
1127 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1128 PR_ExecuteProgram (pr_global_struct->ClientKill, "QC function ClientKill is missing");
1137 void Host_Pause_f (void)
1140 if (cmd_source == src_command)
1142 Cmd_ForwardToServer ();
1145 if (!pausable.integer)
1146 SV_ClientPrint("Pause not allowed.\n");
1150 SV_BroadcastPrintf("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
1151 // send notification to all clients
1152 MSG_WriteByte(&sv.reliable_datagram, svc_setpause);
1153 MSG_WriteByte(&sv.reliable_datagram, sv.paused);
1158 ======================
1160 LordHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
1161 ======================
1163 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0"};
1164 static void Host_PModel_f (void)
1169 if (Cmd_Argc () == 1)
1171 Con_Printf("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
1174 i = atoi(Cmd_Argv(1));
1176 if (cmd_source == src_command)
1178 if (cl_pmodel.integer == i)
1180 Cvar_SetValue ("_cl_pmodel", i);
1181 if (cls.state == ca_connected)
1182 Cmd_ForwardToServer ();
1186 if (host_client->edict && (val = GETEDICTFIELDVALUE(host_client->edict, eval_pmodel)))
1190 //===========================================================================
1198 void Host_PreSpawn_f (void)
1200 if (cmd_source == src_command)
1202 Con_Print("prespawn is not valid from the console\n");
1206 if (host_client->spawned)
1208 Con_Print("prespawn not valid -- already spawned\n");
1212 SZ_Write (&host_client->message, sv.signon.data, sv.signon.cursize);
1213 MSG_WriteByte (&host_client->message, svc_signonnum);
1214 MSG_WriteByte (&host_client->message, 2);
1215 host_client->sendsignon = true;
1217 // reset the name change timer because the client will send name soon
1218 host_client->nametime = 0;
1226 void Host_Spawn_f (void)
1232 int stats[MAX_CL_STATS];
1234 if (cmd_source == src_command)
1236 Con_Print("spawn is not valid from the console\n");
1240 if (host_client->spawned)
1242 Con_Print("Spawn not valid -- already spawned\n");
1246 // reset name change timer again because they might want to change name
1247 // again in the first 5 seconds after connecting
1248 host_client->nametime = 0;
1250 // LordHavoc: moved this above the QC calls at FrikaC's request
1251 // send all current names, colors, and frag counts
1252 SZ_Clear (&host_client->message);
1254 // run the entrance script
1257 // loaded games are fully initialized already
1258 // if this is the last client to be connected, unpause
1261 if ((f = ED_FindFunction ("RestoreGame")))
1262 if ((RestoreGame = (func_t)(f - pr_functions)))
1264 Con_DPrint("Calling RestoreGame\n");
1265 pr_global_struct->time = sv.time;
1266 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1267 PR_ExecuteProgram (RestoreGame, "QC function RestoreGame is missing");
1273 ED_ClearEdict(host_client->edict);
1275 //Con_Printf("Host_Spawn_f: host_client->edict->netname = %s, host_client->edict->netname = %s, host_client->name = %s\n", PR_GetString(host_client->edict->v->netname), PR_GetString(host_client->edict->v->netname), host_client->name);
1277 // copy spawn parms out of the client_t
1278 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1279 (&pr_global_struct->parm1)[i] = host_client->spawn_parms[i];
1281 // call the spawn function
1282 pr_global_struct->time = sv.time;
1283 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1284 PR_ExecuteProgram (pr_global_struct->ClientConnect, "QC function ClientConnect is missing");
1286 if ((Sys_DoubleTime() - host_client->connecttime) <= sv.time)
1287 Con_Printf("%s entered the game\n", host_client->name);
1289 PR_ExecuteProgram (pr_global_struct->PutClientInServer, "QC function PutClientInServer is missing");
1293 // send time of update
1294 MSG_WriteByte (&host_client->message, svc_time);
1295 MSG_WriteFloat (&host_client->message, sv.time);
1297 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
1299 if (!client->active)
1301 MSG_WriteByte (&host_client->message, svc_updatename);
1302 MSG_WriteByte (&host_client->message, i);
1303 MSG_WriteString (&host_client->message, client->name);
1304 MSG_WriteByte (&host_client->message, svc_updatefrags);
1305 MSG_WriteByte (&host_client->message, i);
1306 MSG_WriteShort (&host_client->message, client->frags);
1307 MSG_WriteByte (&host_client->message, svc_updatecolors);
1308 MSG_WriteByte (&host_client->message, i);
1309 MSG_WriteByte (&host_client->message, client->colors);
1312 // send all current light styles
1313 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1315 MSG_WriteByte (&host_client->message, svc_lightstyle);
1316 MSG_WriteByte (&host_client->message, (char)i);
1317 MSG_WriteString (&host_client->message, sv.lightstyles[i]);
1321 MSG_WriteByte (&host_client->message, svc_updatestat);
1322 MSG_WriteByte (&host_client->message, STAT_TOTALSECRETS);
1323 MSG_WriteLong (&host_client->message, pr_global_struct->total_secrets);
1325 MSG_WriteByte (&host_client->message, svc_updatestat);
1326 MSG_WriteByte (&host_client->message, STAT_TOTALMONSTERS);
1327 MSG_WriteLong (&host_client->message, pr_global_struct->total_monsters);
1329 MSG_WriteByte (&host_client->message, svc_updatestat);
1330 MSG_WriteByte (&host_client->message, STAT_SECRETS);
1331 MSG_WriteLong (&host_client->message, pr_global_struct->found_secrets);
1333 MSG_WriteByte (&host_client->message, svc_updatestat);
1334 MSG_WriteByte (&host_client->message, STAT_MONSTERS);
1335 MSG_WriteLong (&host_client->message, pr_global_struct->killed_monsters);
1338 // Never send a roll angle, because savegames can catch the server
1339 // in a state where it is expecting the client to correct the angle
1340 // and it won't happen if the game was just loaded, so you wind up
1341 // with a permanent head tilt
1342 MSG_WriteByte (&host_client->message, svc_setangle);
1343 MSG_WriteAngle (&host_client->message, host_client->edict->v->angles[0], sv.protocol);
1344 MSG_WriteAngle (&host_client->message, host_client->edict->v->angles[1], sv.protocol);
1345 MSG_WriteAngle (&host_client->message, 0, sv.protocol);
1347 SV_WriteClientdataToMessage (host_client, host_client->edict, &host_client->message, stats);
1349 MSG_WriteByte (&host_client->message, svc_signonnum);
1350 MSG_WriteByte (&host_client->message, 3);
1351 host_client->sendsignon = true;
1359 void Host_Begin_f (void)
1361 if (cmd_source == src_command)
1363 Con_Print("begin is not valid from the console\n");
1367 host_client->spawned = true;
1370 //===========================================================================
1377 Kicks a user off of the server
1380 void Host_Kick_f (void)
1383 const char *message = NULL;
1386 qboolean byNumber = false;
1388 if (cmd_source != src_command || !sv.active)
1393 if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1395 i = atof(Cmd_Argv(2)) - 1;
1396 if (i < 0 || i >= svs.maxclients || !(host_client = svs.clients + i)->active)
1402 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1404 if (!host_client->active)
1406 if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1411 if (i < svs.maxclients)
1413 if (cmd_source == src_command)
1415 if (cls.state == ca_dedicated)
1418 who = cl_name.string;
1423 // can't kick yourself!
1424 if (host_client == save)
1429 message = Cmd_Args();
1430 COM_ParseToken(&message, false);
1433 message++; // skip the #
1434 while (*message == ' ') // skip white space
1436 message += strlen(Cmd_Argv(2)); // skip the number
1438 while (*message && *message == ' ')
1442 SV_ClientPrintf("Kicked by %s: %s\n", who, message);
1444 SV_ClientPrintf("Kicked by %s\n", who);
1445 SV_DropClient (false); // kicked
1452 ===============================================================================
1456 ===============================================================================
1464 void Host_Give_f (void)
1470 if (cmd_source == src_command)
1472 Cmd_ForwardToServer ();
1478 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
1483 v = atoi (Cmd_Argv(2));
1497 // MED 01/04/97 added hipnotic give stuff
1498 if (gamemode == GAME_HIPNOTIC)
1503 host_client->edict->v->items = (int)host_client->edict->v->items | HIT_PROXIMITY_GUN;
1505 host_client->edict->v->items = (int)host_client->edict->v->items | IT_GRENADE_LAUNCHER;
1507 else if (t[0] == '9')
1508 host_client->edict->v->items = (int)host_client->edict->v->items | HIT_LASER_CANNON;
1509 else if (t[0] == '0')
1510 host_client->edict->v->items = (int)host_client->edict->v->items | HIT_MJOLNIR;
1511 else if (t[0] >= '2')
1512 host_client->edict->v->items = (int)host_client->edict->v->items | (IT_SHOTGUN << (t[0] - '2'));
1517 host_client->edict->v->items = (int)host_client->edict->v->items | (IT_SHOTGUN << (t[0] - '2'));
1522 if (gamemode == GAME_ROGUE && (val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_shells1)))
1525 host_client->edict->v->ammo_shells = v;
1528 if (gamemode == GAME_ROGUE)
1530 if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_nails1)))
1533 if (host_client->edict->v->weapon <= IT_LIGHTNING)
1534 host_client->edict->v->ammo_nails = v;
1539 host_client->edict->v->ammo_nails = v;
1543 if (gamemode == GAME_ROGUE)
1545 val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_lava_nails);
1549 if (host_client->edict->v->weapon > IT_LIGHTNING)
1550 host_client->edict->v->ammo_nails = v;
1555 if (gamemode == GAME_ROGUE)
1557 val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_rockets1);
1561 if (host_client->edict->v->weapon <= IT_LIGHTNING)
1562 host_client->edict->v->ammo_rockets = v;
1567 host_client->edict->v->ammo_rockets = v;
1571 if (gamemode == GAME_ROGUE)
1573 val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_multi_rockets);
1577 if (host_client->edict->v->weapon > IT_LIGHTNING)
1578 host_client->edict->v->ammo_rockets = v;
1583 host_client->edict->v->health = v;
1586 if (gamemode == GAME_ROGUE)
1588 val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_cells1);
1592 if (host_client->edict->v->weapon <= IT_LIGHTNING)
1593 host_client->edict->v->ammo_cells = v;
1598 host_client->edict->v->ammo_cells = v;
1602 if (gamemode == GAME_ROGUE)
1604 val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_plasma);
1608 if (host_client->edict->v->weapon > IT_LIGHTNING)
1609 host_client->edict->v->ammo_cells = v;
1616 edict_t *FindViewthing (void)
1621 for (i=0 ; i<sv.num_edicts ; i++)
1624 if (!strcmp (PR_GetString(e->v->classname), "viewthing"))
1627 Con_Print("No viewthing on map\n");
1636 void Host_Viewmodel_f (void)
1641 e = FindViewthing ();
1645 m = Mod_ForName (Cmd_Argv(1), false, true, false);
1648 Con_Printf("Can't load %s\n", Cmd_Argv(1));
1653 cl.model_precache[(int)e->v->modelindex] = m;
1661 void Host_Viewframe_f (void)
1667 e = FindViewthing ();
1670 m = cl.model_precache[(int)e->v->modelindex];
1672 f = atoi(Cmd_Argv(1));
1673 if (f >= m->numframes)
1680 void PrintFrameName (model_t *m, int frame)
1683 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1685 Con_Printf("frame %i\n", frame);
1693 void Host_Viewnext_f (void)
1698 e = FindViewthing ();
1701 m = cl.model_precache[(int)e->v->modelindex];
1703 e->v->frame = e->v->frame + 1;
1704 if (e->v->frame >= m->numframes)
1705 e->v->frame = m->numframes - 1;
1707 PrintFrameName (m, e->v->frame);
1715 void Host_Viewprev_f (void)
1720 e = FindViewthing ();
1724 m = cl.model_precache[(int)e->v->modelindex];
1726 e->v->frame = e->v->frame - 1;
1727 if (e->v->frame < 0)
1730 PrintFrameName (m, e->v->frame);
1734 ===============================================================================
1738 ===============================================================================
1747 void Host_Startdemos_f (void)
1751 if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
1757 Con_Printf("Max %i demos in demoloop\n", MAX_DEMOS);
1760 Con_Printf("%i demo(s) in loop\n", c);
1762 for (i=1 ; i<c+1 ; i++)
1763 strlcpy (cls.demos[i-1], Cmd_Argv(i), sizeof (cls.demos[i-1]));
1765 // LordHavoc: clear the remaining slots
1766 for (;i <= MAX_DEMOS;i++)
1767 cls.demos[i-1][0] = 0;
1769 if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
1783 Return to looping demos
1786 void Host_Demos_f (void)
1788 if (cls.state == ca_dedicated)
1790 if (cls.demonum == -1)
1800 Return to looping demos
1803 void Host_Stopdemo_f (void)
1805 if (!cls.demoplayback)
1808 Host_ShutdownServer (false);
1811 static void MaxPlayers_f(void)
1815 if (Cmd_Argc() != 2)
1817 Con_Printf("\"maxplayers\" is \"%u\"\n", svs.maxclients);
1823 Con_Print("maxplayers can not be changed while a server is running.\n");
1827 n = atoi(Cmd_Argv(1));
1828 n = bound(1, n, MAX_SCOREBOARD);
1829 Con_Printf("\"maxplayers\" set to \"%u\"\n", n);
1832 Mem_Free(svs.clients);
1834 svs.clients = Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients);
1836 Cvar_Set ("deathmatch", "0");
1838 Cvar_Set ("deathmatch", "1");
1841 //=============================================================================
1848 void Host_InitCommands (void)
1850 Cmd_AddCommand ("status", Host_Status_f);
1851 Cmd_AddCommand ("quit", Host_Quit_f);
1852 if (gamemode == GAME_NEHAHRA)
1854 Cmd_AddCommand ("max", Host_God_f);
1855 Cmd_AddCommand ("monster", Host_Notarget_f);
1856 Cmd_AddCommand ("scrag", Host_Fly_f);
1857 Cmd_AddCommand ("wraith", Host_Noclip_f);
1858 Cmd_AddCommand ("gimme", Host_Give_f);
1862 Cmd_AddCommand ("god", Host_God_f);
1863 Cmd_AddCommand ("notarget", Host_Notarget_f);
1864 Cmd_AddCommand ("fly", Host_Fly_f);
1865 Cmd_AddCommand ("noclip", Host_Noclip_f);
1866 Cmd_AddCommand ("give", Host_Give_f);
1868 Cmd_AddCommand ("map", Host_Map_f);
1869 Cmd_AddCommand ("restart", Host_Restart_f);
1870 Cmd_AddCommand ("changelevel", Host_Changelevel_f);
1871 Cmd_AddCommand ("connect", Host_Connect_f);
1872 Cmd_AddCommand ("reconnect", Host_Reconnect_f);
1873 Cmd_AddCommand ("version", Host_Version_f);
1874 Cmd_AddCommand ("say", Host_Say_f);
1875 Cmd_AddCommand ("say_team", Host_Say_Team_f);
1876 Cmd_AddCommand ("tell", Host_Tell_f);
1877 Cmd_AddCommand ("kill", Host_Kill_f);
1878 Cmd_AddCommand ("pause", Host_Pause_f);
1879 Cmd_AddCommand ("kick", Host_Kick_f);
1880 Cmd_AddCommand ("ping", Host_Ping_f);
1881 Cmd_AddCommand ("load", Host_Loadgame_f);
1882 Cmd_AddCommand ("save", Host_Savegame_f);
1884 Cmd_AddCommand ("startdemos", Host_Startdemos_f);
1885 Cmd_AddCommand ("demos", Host_Demos_f);
1886 Cmd_AddCommand ("stopdemo", Host_Stopdemo_f);
1888 Cmd_AddCommand ("viewmodel", Host_Viewmodel_f);
1889 Cmd_AddCommand ("viewframe", Host_Viewframe_f);
1890 Cmd_AddCommand ("viewnext", Host_Viewnext_f);
1891 Cmd_AddCommand ("viewprev", Host_Viewprev_f);
1893 Cvar_RegisterVariable (&cl_name);
1894 Cmd_AddCommand ("name", Host_Name_f);
1895 Cvar_RegisterVariable (&cl_color);
1896 Cmd_AddCommand ("color", Host_Color_f);
1897 Cvar_RegisterVariable (&cl_rate);
1898 Cmd_AddCommand ("rate", Host_Rate_f);
1899 if (gamemode == GAME_NEHAHRA)
1901 Cvar_RegisterVariable (&cl_pmodel);
1902 Cmd_AddCommand ("pmodel", Host_PModel_f);
1905 // BLACK: This isnt game specific anymore (it was GAME_NEXUIZ at first)
1906 Cvar_RegisterVariable (&cl_playermodel);
1907 Cmd_AddCommand ("playermodel", Host_Playermodel_f);
1908 Cvar_RegisterVariable (&cl_playerskin);
1909 Cmd_AddCommand ("playerskin", Host_Playerskin_f);
1911 Cmd_AddCommand ("prespawn", Host_PreSpawn_f);
1912 Cmd_AddCommand ("spawn", Host_Spawn_f);
1913 Cmd_AddCommand ("begin", Host_Begin_f);
1914 Cmd_AddCommand ("maxplayers", MaxPlayers_f);
1916 Cvar_RegisterVariable(&sv_cheats);