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)
48 const char *protocolname;
50 int seconds, minutes, hours = 0, j, players;
51 void (*print) (const char *fmt, ...);
53 if (cmd_source == src_command)
57 Cmd_ForwardToServer ();
63 print = SV_ClientPrintf;
65 for (players = 0, j = 0;j < svs.maxclients;j++)
66 if (svs.clients[j].active)
68 print ("host: %s\n", Cvar_VariableString ("hostname"));
69 print ("version: %s build %s\n", gamename, buildstring);
72 case PROTOCOL_QUAKE: protocolname = sv.netquakecompatible ? "QUAKE" : "QUAKEDP";break;
73 case PROTOCOL_DARKPLACES1: protocolname = "PROTOCOL_DARKPLACES1";break;
74 case PROTOCOL_DARKPLACES2: protocolname = "PROTOCOL_DARKPLACES2";break;
75 case PROTOCOL_DARKPLACES3: protocolname = "PROTOCOL_DARKPLACES3";break;
76 case PROTOCOL_DARKPLACES4: protocolname = "PROTOCOL_DARKPLACES4";break;
77 case PROTOCOL_DARKPLACES5: protocolname = "PROTOCOL_DARKPLACES5";break;
78 case PROTOCOL_DARKPLACES6: protocolname = "PROTOCOL_DARKPLACES6";break;
79 default: protocolname = "PROTOCOL_UNKNOWN";break;
81 print ("protocol: %i (%s)\n", sv.protocol, protocolname);
82 print ("map: %s\n", sv.name);
83 print ("players: %i active (%i max)\n\n", players, svs.maxclients);
84 for (j = 0, client = svs.clients;j < svs.maxclients;j++, client++)
88 seconds = (int)(realtime - client->connecttime);
89 minutes = seconds / 60;
92 seconds -= (minutes * 60);
95 minutes -= (hours * 60);
99 print ("#%-2u %-16.16s %3i %2i:%02i:%02i\n", j+1, client->name, (int)client->edict->v->frags, hours, minutes, seconds);
100 print (" %s\n", client->netconnection ? client->netconnection->address : "botclient");
109 Sets client to godmode
112 void Host_God_f (void)
114 if (cmd_source == src_command)
116 Cmd_ForwardToServer ();
122 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
126 host_client->edict->v->flags = (int)host_client->edict->v->flags ^ FL_GODMODE;
127 if (!((int)host_client->edict->v->flags & FL_GODMODE) )
128 SV_ClientPrint("godmode OFF\n");
130 SV_ClientPrint("godmode ON\n");
133 void Host_Notarget_f (void)
135 if (cmd_source == src_command)
137 Cmd_ForwardToServer ();
143 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
147 host_client->edict->v->flags = (int)host_client->edict->v->flags ^ FL_NOTARGET;
148 if (!((int)host_client->edict->v->flags & FL_NOTARGET) )
149 SV_ClientPrint("notarget OFF\n");
151 SV_ClientPrint("notarget ON\n");
154 qboolean noclip_anglehack;
156 void Host_Noclip_f (void)
158 if (cmd_source == src_command)
160 Cmd_ForwardToServer ();
166 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
170 if (host_client->edict->v->movetype != MOVETYPE_NOCLIP)
172 noclip_anglehack = true;
173 host_client->edict->v->movetype = MOVETYPE_NOCLIP;
174 SV_ClientPrint("noclip ON\n");
178 noclip_anglehack = false;
179 host_client->edict->v->movetype = MOVETYPE_WALK;
180 SV_ClientPrint("noclip OFF\n");
188 Sets client to flymode
191 void Host_Fly_f (void)
193 if (cmd_source == src_command)
195 Cmd_ForwardToServer ();
201 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
205 if (host_client->edict->v->movetype != MOVETYPE_FLY)
207 host_client->edict->v->movetype = MOVETYPE_FLY;
208 SV_ClientPrint("flymode ON\n");
212 host_client->edict->v->movetype = MOVETYPE_WALK;
213 SV_ClientPrint("flymode OFF\n");
224 void Host_Ping_f (void)
230 if (cmd_source == src_command)
232 Cmd_ForwardToServer ();
236 SV_ClientPrint("Client ping times:\n");
237 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
242 for (j=0 ; j<NUM_PING_TIMES ; j++)
243 total+=client->ping_times[j];
244 total /= NUM_PING_TIMES;
245 SV_ClientPrintf("%4i %s\n", (int)(total*1000), client->name);
250 ===============================================================================
254 ===============================================================================
258 ======================
263 command from the console. Active clients are kicked off.
264 ======================
266 void Host_Map_f (void)
268 char level[MAX_QPATH];
272 Con_Print("map <levelname> : start a new game (kicks off all players)\n");
276 if (cmd_source != src_command)
279 cls.demonum = -1; // stop demo loop in case this fails
282 Host_ShutdownServer(false);
284 // remove console or menu
286 key_consoleactive = 0;
288 svs.serverflags = 0; // haven't completed an episode yet
289 allowcheats = sv_cheats.integer != 0;
290 strcpy(level, Cmd_Argv(1));
291 SV_SpawnServer(level);
292 if (sv.active && cls.state == ca_disconnected)
293 CL_EstablishConnection("local:1");
300 Goes to a new map, taking all clients along
303 void Host_Changelevel_f (void)
305 char level[MAX_QPATH];
309 Con_Print("changelevel <levelname> : continue game on a new level\n");
312 if (!sv.active || cls.demoplayback)
314 Con_Print("Only the server may changelevel\n");
317 if (cmd_source != src_command)
320 // remove console or menu
322 key_consoleactive = 0;
324 SV_SaveSpawnparms ();
325 allowcheats = sv_cheats.integer != 0;
326 strcpy(level, Cmd_Argv(1));
327 SV_SpawnServer(level);
328 if (sv.active && cls.state == ca_disconnected)
329 CL_EstablishConnection("local:1");
336 Restarts the current server for a dead player
339 void Host_Restart_f (void)
341 char mapname[MAX_QPATH];
345 Con_Print("restart : restart current level\n");
348 if (!sv.active || cls.demoplayback)
350 Con_Print("Only the server may restart\n");
353 if (cmd_source != src_command)
356 // remove console or menu
358 key_consoleactive = 0;
360 allowcheats = sv_cheats.integer != 0;
361 strcpy(mapname, sv.name);
362 SV_SpawnServer(mapname);
363 if (sv.active && cls.state == ca_disconnected)
364 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)
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");
404 CL_EstablishConnection(Cmd_Argv(1));
409 ===============================================================================
413 ===============================================================================
416 #define SAVEGAME_VERSION 5
422 Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
425 void Host_SavegameComment (char *text)
430 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
432 memcpy (text, cl.levelname, strlen(cl.levelname));
433 sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
434 memcpy (text+22, kills, strlen(kills));
435 // convert space to _ to make stdio happy
436 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
439 text[SAVEGAME_COMMENT_LENGTH] = '\0';
448 void Host_Savegame_f (void)
453 char comment[SAVEGAME_COMMENT_LENGTH+1];
455 if (cmd_source != src_command)
458 if (cls.state != ca_connected || !sv.active)
460 Con_Print("Not playing a local game.\n");
466 Con_Print("Can't save in intermission.\n");
470 for (i = 0;i < svs.maxclients;i++)
472 if (svs.clients[i].active)
476 Con_Print("Can't save multiplayer games.\n");
479 if (svs.clients[i].edict->v->deadflag)
481 Con_Print("Can't savegame with a dead player\n");
489 Con_Print("save <savename> : save a game\n");
493 if (strstr(Cmd_Argv(1), ".."))
495 Con_Print("Relative pathnames are not allowed.\n");
499 strlcpy (name, Cmd_Argv(1), sizeof (name));
500 FS_DefaultExtension (name, ".sav", sizeof (name));
502 Con_Printf("Saving game to %s...\n", name);
503 f = FS_Open (name, "wb", false);
506 Con_Print("ERROR: couldn't open.\n");
510 FS_Printf(f, "%i\n", SAVEGAME_VERSION);
511 Host_SavegameComment (comment);
512 FS_Printf(f, "%s\n", comment);
513 for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
514 FS_Printf(f, "%f\n", svs.clients[0].spawn_parms[i]);
515 FS_Printf(f, "%d\n", current_skill);
516 FS_Printf(f, "%s\n", sv.name);
517 FS_Printf(f, "%f\n",sv.time);
519 // write the light styles
520 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
522 if (sv.lightstyles[i])
523 FS_Printf(f, "%s\n", sv.lightstyles[i]);
529 for (i=0 ; i<sv.num_edicts ; i++)
530 ED_Write (f, EDICT_NUM(i));
532 Con_Print("done.\n");
536 extern mempool_t *edictstring_mempool;
543 void Host_Loadgame_f (void)
546 char filename[MAX_QPATH];
547 char mapname[MAX_QPATH];
556 float spawn_parms[NUM_SPAWN_PARMS];
558 if (cmd_source != src_command)
563 Con_Print("load <savename> : load a game\n");
567 strcpy (filename, Cmd_Argv(1));
568 FS_DefaultExtension (filename, ".sav", sizeof (filename));
570 Con_Printf("Loading game from %s...\n", filename);
572 cls.demonum = -1; // stop demo loop in case this fails
574 t = text = FS_LoadFile (filename, tempmempool, false);
577 Con_Print("ERROR: couldn't open.\n");
582 COM_ParseToken(&t, false);
583 version = atoi(com_token);
584 if (version != SAVEGAME_VERSION)
587 Con_Printf("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
592 // this is a little hard to parse, as : is a separator in COM_ParseToken,
593 // so use the console parser instead
594 COM_ParseTokenConsole(&t);
596 for (i = 0;i < NUM_SPAWN_PARMS;i++)
598 COM_ParseToken(&t, false);
599 spawn_parms[i] = atof(com_token);
602 COM_ParseToken(&t, false);
603 // this silliness is so we can load 1.06 save files, which have float skill values
604 current_skill = (int)(atof(com_token) + 0.5);
605 Cvar_SetValue ("skill", (float)current_skill);
608 COM_ParseToken(&t, false);
609 strcpy (mapname, com_token);
612 COM_ParseToken(&t, false);
613 time = atof(com_token);
615 allowcheats = sv_cheats.integer != 0;
617 SV_SpawnServer (mapname);
621 Con_Print("Couldn't load map\n");
624 sv.paused = true; // pause until all clients connect
627 // load the light styles
629 for (i = 0;i < MAX_LIGHTSTYLES;i++)
632 COM_ParseToken(&t, false);
633 sv.lightstyles[i] = Mem_Alloc(edictstring_mempool, strlen(com_token)+1);
634 strcpy (sv.lightstyles[i], com_token);
637 // load the edicts out of the savegame file
643 while (COM_ParseToken(&t, false))
644 if (!strcmp(com_token, "}"))
646 if (!COM_ParseToken(&start, false))
651 if (strcmp(com_token,"{"))
654 Host_Error ("First token isn't a brace");
659 // parse the global vars
660 ED_ParseGlobals (start);
665 if (entnum >= MAX_EDICTS)
668 Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)\n", MAX_EDICTS);
670 while (entnum >= sv.max_edicts)
672 ent = EDICT_NUM(entnum);
673 memset (ent->v, 0, progs->entityfields * 4);
674 ent->e->free = false;
675 ED_ParseEdict (start, ent);
677 // link it into the bsp tree
679 SV_LinkEdict (ent, false);
685 sv.num_edicts = entnum;
690 for (i = 0;i < NUM_SPAWN_PARMS;i++)
691 svs.clients[0].spawn_parms[i] = spawn_parms[i];
693 // make sure we're connected to loopback
694 if (cls.state == ca_disconnected || !(cls.state == ca_connected && cls.netcon != NULL && LHNETADDRESS_GetAddressType(&cls.netcon->peeraddress) == LHNETADDRESSTYPE_LOOP))
695 CL_EstablishConnection("local:1");
698 //============================================================================
701 ======================
703 ======================
705 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player"};
706 void Host_Name_f (void)
709 char newName[sizeof(host_client->name)];
711 if (Cmd_Argc () == 1)
713 Con_Printf("\"name\" is \"%s\"\n", cl_name.string);
717 if (Cmd_Argc () == 2)
718 strlcpy (newName, Cmd_Argv(1), sizeof (newName));
720 strlcpy (newName, Cmd_Args(), sizeof (newName));
722 for (i = 0, j = 0;newName[i];i++)
723 if (newName[i] != '\r' && newName[i] != '\n')
724 newName[j++] = newName[i];
727 if (cmd_source == src_command)
729 Cvar_Set ("_cl_name", newName);
730 if (cls.state == ca_connected)
731 Cmd_ForwardToServer ();
735 if (sv.time < host_client->nametime)
737 SV_ClientPrintf("You can't change name more than once every 5 seconds!\n");
741 host_client->nametime = sv.time + 5;
743 // point the string back at updateclient->name to keep it safe
744 strlcpy (host_client->name, newName, sizeof (host_client->name));
745 host_client->edict->v->netname = PR_SetString(host_client->name);
746 if (strcmp(host_client->old_name, host_client->name))
748 if (host_client->spawned)
749 SV_BroadcastPrintf("%s changed name to %s\n", host_client->old_name, host_client->name);
750 strcpy(host_client->old_name, host_client->name);
751 // send notification to all clients
752 MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
753 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
754 MSG_WriteString (&sv.reliable_datagram, host_client->name);
759 ======================
761 ======================
763 cvar_t cl_playermodel = {CVAR_SAVE, "_cl_playermodel", ""};
764 // the old cl_playermodel in cl_main has been renamed to __cl_playermodel
765 void Host_Playermodel_f (void)
768 char newPath[sizeof(host_client->playermodel)];
770 if (Cmd_Argc () == 1)
772 Con_Printf("\"playermodel\" is \"%s\"\n", cl_playermodel.string);
776 if (Cmd_Argc () == 2)
777 strlcpy (newPath, Cmd_Argv(1), sizeof (newPath));
779 strlcpy (newPath, Cmd_Args(), sizeof (newPath));
781 for (i = 0, j = 0;newPath[i];i++)
782 if (newPath[i] != '\r' && newPath[i] != '\n')
783 newPath[j++] = newPath[i];
786 if (cmd_source == src_command)
788 Cvar_Set ("_cl_playermodel", newPath);
789 if (cls.state == ca_connected)
790 Cmd_ForwardToServer ();
795 if (sv.time < host_client->nametime)
797 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
801 host_client->nametime = sv.time + 5;
804 // point the string back at updateclient->name to keep it safe
805 strlcpy (host_client->playermodel, newPath, sizeof (host_client->playermodel));
806 if( eval_playermodel )
807 GETEDICTFIELDVALUE(host_client->edict, eval_playermodel)->string = PR_SetString(host_client->playermodel);
808 if (strcmp(host_client->old_model, host_client->playermodel))
810 if (host_client->spawned)
811 SV_BroadcastPrintf("%s changed model to %s\n", host_client->old_model, host_client->playermodel);
812 strcpy(host_client->old_model, host_client->playermodel);
813 /*// send notification to all clients
814 MSG_WriteByte (&sv.reliable_datagram, svc_updatepmodel);
815 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
816 MSG_WriteString (&sv.reliable_datagram, host_client->playermodel);*/
821 ======================
823 ======================
825 cvar_t cl_playerskin = {CVAR_SAVE, "_cl_playerskin", ""};
826 void Host_Playerskin_f (void)
829 char newPath[sizeof(host_client->playerskin)];
831 if (Cmd_Argc () == 1)
833 Con_Printf("\"playerskin\" is \"%s\"\n", cl_playerskin.string);
837 if (Cmd_Argc () == 2)
838 strlcpy (newPath, Cmd_Argv(1), sizeof (newPath));
840 strlcpy (newPath, Cmd_Args(), sizeof (newPath));
842 for (i = 0, j = 0;newPath[i];i++)
843 if (newPath[i] != '\r' && newPath[i] != '\n')
844 newPath[j++] = newPath[i];
847 if (cmd_source == src_command)
849 Cvar_Set ("_cl_playerskin", newPath);
850 if (cls.state == ca_connected)
851 Cmd_ForwardToServer ();
856 if (sv.time < host_client->nametime)
858 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
862 host_client->nametime = sv.time + 5;
865 // point the string back at updateclient->name to keep it safe
866 strlcpy (host_client->playerskin, newPath, sizeof (host_client->playerskin));
867 if( eval_playerskin )
868 GETEDICTFIELDVALUE(host_client->edict, eval_playerskin)->string = PR_SetString(host_client->playerskin);
869 if (strcmp(host_client->old_skin, host_client->playerskin))
871 if (host_client->spawned)
872 SV_BroadcastPrintf("%s changed skin to %s\n", host_client->old_skin, host_client->playerskin);
873 strcpy(host_client->old_skin, host_client->playerskin);
874 /*// send notification to all clients
875 MSG_WriteByte (&sv.reliable_datagram, svc_updatepskin);
876 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
877 MSG_WriteString (&sv.reliable_datagram, host_client->playerskin);*/
881 void Host_Version_f (void)
883 Con_Printf("Version: %s build %s\n", gamename, buildstring);
886 void Host_Say(qboolean teamonly)
892 // LordHavoc: 256 char say messages
893 unsigned char text[256];
894 qboolean fromServer = false;
896 if (cmd_source == src_command)
898 if (cls.state == ca_dedicated)
905 Cmd_ForwardToServer ();
913 if (!teamplay.integer)
916 // turn on color set 1
925 snprintf (text, sizeof(text), "%c%s: %s", 1, host_client->name, p1);
927 snprintf (text, sizeof(text), "%c<%s> %s", 1, hostname.string, p1);
928 p2 = text + strlen(text);
929 while ((const char *)p2 > (const char *)text && (p2[-1] == '\r' || p2[-1] == '\n' || (p2[-1] == '\"' && quoted)))
931 if (p2[-1] == '\"' && quoted)
936 strlcat(text, "\n", sizeof(text));
938 // note: save is not a valid edict if fromServer is true
940 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
941 if (host_client->spawned && (!teamonly || host_client->edict->v->team == save->edict->v->team))
942 SV_ClientPrint(text);
945 //Con_Print(&text[1]);
949 void Host_Say_f(void)
955 void Host_Say_Team_f(void)
961 void Host_Tell_f(void)
966 char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
967 qboolean fromServer = false;
969 if (cmd_source == src_command)
971 if (cls.state == ca_dedicated)
975 Cmd_ForwardToServer ();
984 sprintf (text, "%s: ", host_client->name);
986 sprintf (text, "<%s> ", hostname.string);
989 p2 = p1 + strlen(p1);
990 // remove the target name
991 while (p1 < p2 && *p1 != ' ')
993 while (p1 < p2 && *p1 == ' ')
995 // remove trailing newlines
996 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
998 // remove quotes if present
1004 else if (fromServer)
1005 Con_Print("Host_Tell: missing end quote\n");
1007 SV_ClientPrint("Host_Tell: missing end quote\n");
1009 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
1011 for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
1017 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
1018 if (host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1)))
1019 SV_ClientPrint(text);
1029 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0"};
1030 void Host_Color_f(void)
1035 func_t SV_ChangeTeam;
1037 if (Cmd_Argc() == 1)
1039 Con_Printf("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
1040 Con_Print("color <0-15> [0-15]\n");
1044 if (Cmd_Argc() == 2)
1045 top = bottom = atoi(Cmd_Argv(1));
1048 top = atoi(Cmd_Argv(1));
1049 bottom = atoi(Cmd_Argv(2));
1053 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
1057 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
1061 playercolor = top*16 + bottom;
1063 if (cmd_source == src_command)
1065 Cvar_SetValue ("_cl_color", playercolor);
1066 if (cls.state == ca_connected)
1067 Cmd_ForwardToServer ();
1071 if (host_client->edict && (f = ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - pr_functions)))
1073 Con_DPrint("Calling SV_ChangeTeam\n");
1074 pr_global_struct->time = sv.time;
1075 pr_globals[OFS_PARM0] = playercolor;
1076 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1077 PR_ExecuteProgram (SV_ChangeTeam, "QC function SV_ChangeTeam is missing");
1082 if (host_client->edict)
1084 if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_clientcolors)))
1085 val->_float = playercolor;
1086 host_client->edict->v->team = bottom + 1;
1088 host_client->colors = playercolor;
1089 if (host_client->old_colors != host_client->colors)
1091 host_client->old_colors = host_client->colors;
1092 // send notification to all clients
1093 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
1094 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
1095 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
1100 cvar_t cl_rate = {CVAR_SAVE, "_cl_rate", "10000"};
1101 void Host_Rate_f(void)
1105 if (Cmd_Argc() != 2)
1107 Con_Printf("\"rate\" is \"%i\"\n", cl_rate.integer);
1108 Con_Print("rate <500-25000>\n");
1112 rate = atoi(Cmd_Argv(1));
1114 if (cmd_source == src_command)
1116 Cvar_SetValue ("_cl_rate", bound(NET_MINRATE, rate, NET_MAXRATE));
1117 if (cls.state == ca_connected)
1118 Cmd_ForwardToServer ();
1122 host_client->rate = rate;
1130 void Host_Kill_f (void)
1132 if (cmd_source == src_command)
1134 Cmd_ForwardToServer ();
1138 if (host_client->edict->v->health <= 0)
1140 SV_ClientPrint("Can't suicide -- already dead!\n");
1144 pr_global_struct->time = sv.time;
1145 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1146 PR_ExecuteProgram (pr_global_struct->ClientKill, "QC function ClientKill is missing");
1155 void Host_Pause_f (void)
1158 if (cmd_source == src_command)
1160 Cmd_ForwardToServer ();
1163 if (!pausable.integer)
1164 SV_ClientPrint("Pause not allowed.\n");
1168 SV_BroadcastPrintf("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
1169 // send notification to all clients
1170 MSG_WriteByte(&sv.reliable_datagram, svc_setpause);
1171 MSG_WriteByte(&sv.reliable_datagram, sv.paused);
1176 ======================
1178 LordHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
1179 ======================
1181 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0"};
1182 static void Host_PModel_f (void)
1187 if (Cmd_Argc () == 1)
1189 Con_Printf("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
1192 i = atoi(Cmd_Argv(1));
1194 if (cmd_source == src_command)
1196 if (cl_pmodel.integer == i)
1198 Cvar_SetValue ("_cl_pmodel", i);
1199 if (cls.state == ca_connected)
1200 Cmd_ForwardToServer ();
1204 if (host_client->edict && (val = GETEDICTFIELDVALUE(host_client->edict, eval_pmodel)))
1208 //===========================================================================
1216 void Host_PreSpawn_f (void)
1218 if (cmd_source == src_command)
1220 Con_Print("prespawn is not valid from the console\n");
1224 if (host_client->spawned)
1226 Con_Print("prespawn not valid -- already spawned\n");
1230 SZ_Write (&host_client->message, sv.signon.data, sv.signon.cursize);
1231 MSG_WriteByte (&host_client->message, svc_signonnum);
1232 MSG_WriteByte (&host_client->message, 2);
1233 host_client->sendsignon = true;
1235 // reset the name change timer because the client will send name soon
1236 host_client->nametime = 0;
1244 void Host_Spawn_f (void)
1250 int stats[MAX_CL_STATS];
1252 if (cmd_source == src_command)
1254 Con_Print("spawn is not valid from the console\n");
1258 if (host_client->spawned)
1260 Con_Print("Spawn not valid -- already spawned\n");
1264 // reset name change timer again because they might want to change name
1265 // again in the first 5 seconds after connecting
1266 host_client->nametime = 0;
1268 // LordHavoc: moved this above the QC calls at FrikaC's request
1269 // send all current names, colors, and frag counts
1270 SZ_Clear (&host_client->message);
1272 // run the entrance script
1275 // loaded games are fully initialized already
1276 // if this is the last client to be connected, unpause
1279 if ((f = ED_FindFunction ("RestoreGame")))
1280 if ((RestoreGame = (func_t)(f - pr_functions)))
1282 Con_DPrint("Calling RestoreGame\n");
1283 pr_global_struct->time = sv.time;
1284 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1285 PR_ExecuteProgram (RestoreGame, "QC function RestoreGame is missing");
1291 ED_ClearEdict(host_client->edict);
1293 //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);
1295 // copy spawn parms out of the client_t
1296 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1297 (&pr_global_struct->parm1)[i] = host_client->spawn_parms[i];
1299 // call the spawn function
1300 pr_global_struct->time = sv.time;
1301 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1302 PR_ExecuteProgram (pr_global_struct->ClientConnect, "QC function ClientConnect is missing");
1304 if ((Sys_DoubleTime() - host_client->connecttime) <= sv.time)
1305 Con_Printf("%s entered the game\n", host_client->name);
1307 PR_ExecuteProgram (pr_global_struct->PutClientInServer, "QC function PutClientInServer is missing");
1311 // send time of update
1312 MSG_WriteByte (&host_client->message, svc_time);
1313 MSG_WriteFloat (&host_client->message, sv.time);
1315 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
1317 if (!client->active)
1319 MSG_WriteByte (&host_client->message, svc_updatename);
1320 MSG_WriteByte (&host_client->message, i);
1321 MSG_WriteString (&host_client->message, client->name);
1322 MSG_WriteByte (&host_client->message, svc_updatefrags);
1323 MSG_WriteByte (&host_client->message, i);
1324 MSG_WriteShort (&host_client->message, client->frags);
1325 MSG_WriteByte (&host_client->message, svc_updatecolors);
1326 MSG_WriteByte (&host_client->message, i);
1327 MSG_WriteByte (&host_client->message, client->colors);
1330 // send all current light styles
1331 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1333 MSG_WriteByte (&host_client->message, svc_lightstyle);
1334 MSG_WriteByte (&host_client->message, (char)i);
1335 MSG_WriteString (&host_client->message, sv.lightstyles[i]);
1339 MSG_WriteByte (&host_client->message, svc_updatestat);
1340 MSG_WriteByte (&host_client->message, STAT_TOTALSECRETS);
1341 MSG_WriteLong (&host_client->message, pr_global_struct->total_secrets);
1343 MSG_WriteByte (&host_client->message, svc_updatestat);
1344 MSG_WriteByte (&host_client->message, STAT_TOTALMONSTERS);
1345 MSG_WriteLong (&host_client->message, pr_global_struct->total_monsters);
1347 MSG_WriteByte (&host_client->message, svc_updatestat);
1348 MSG_WriteByte (&host_client->message, STAT_SECRETS);
1349 MSG_WriteLong (&host_client->message, pr_global_struct->found_secrets);
1351 MSG_WriteByte (&host_client->message, svc_updatestat);
1352 MSG_WriteByte (&host_client->message, STAT_MONSTERS);
1353 MSG_WriteLong (&host_client->message, pr_global_struct->killed_monsters);
1356 // Never send a roll angle, because savegames can catch the server
1357 // in a state where it is expecting the client to correct the angle
1358 // and it won't happen if the game was just loaded, so you wind up
1359 // with a permanent head tilt
1360 MSG_WriteByte (&host_client->message, svc_setangle);
1361 MSG_WriteAngle (&host_client->message, host_client->edict->v->angles[0], sv.protocol);
1362 MSG_WriteAngle (&host_client->message, host_client->edict->v->angles[1], sv.protocol);
1363 MSG_WriteAngle (&host_client->message, 0, sv.protocol);
1365 SV_WriteClientdataToMessage (host_client, host_client->edict, &host_client->message, stats);
1367 MSG_WriteByte (&host_client->message, svc_signonnum);
1368 MSG_WriteByte (&host_client->message, 3);
1369 host_client->sendsignon = true;
1377 void Host_Begin_f (void)
1379 if (cmd_source == src_command)
1381 Con_Print("begin is not valid from the console\n");
1385 host_client->spawned = true;
1388 //===========================================================================
1395 Kicks a user off of the server
1398 void Host_Kick_f (void)
1401 const char *message = NULL;
1404 qboolean byNumber = false;
1406 if (cmd_source != src_command || !sv.active)
1411 if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1413 i = atof(Cmd_Argv(2)) - 1;
1414 if (i < 0 || i >= svs.maxclients || !(host_client = svs.clients + i)->active)
1420 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1422 if (!host_client->active)
1424 if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1429 if (i < svs.maxclients)
1431 if (cmd_source == src_command)
1433 if (cls.state == ca_dedicated)
1436 who = cl_name.string;
1441 // can't kick yourself!
1442 if (host_client == save)
1447 message = Cmd_Args();
1448 COM_ParseToken(&message, false);
1451 message++; // skip the #
1452 while (*message == ' ') // skip white space
1454 message += strlen(Cmd_Argv(2)); // skip the number
1456 while (*message && *message == ' ')
1460 SV_ClientPrintf("Kicked by %s: %s\n", who, message);
1462 SV_ClientPrintf("Kicked by %s\n", who);
1463 SV_DropClient (false); // kicked
1470 ===============================================================================
1474 ===============================================================================
1482 void Host_Give_f (void)
1488 if (cmd_source == src_command)
1490 Cmd_ForwardToServer ();
1496 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
1501 v = atoi (Cmd_Argv(2));
1515 // MED 01/04/97 added hipnotic give stuff
1516 if (gamemode == GAME_HIPNOTIC)
1521 host_client->edict->v->items = (int)host_client->edict->v->items | HIT_PROXIMITY_GUN;
1523 host_client->edict->v->items = (int)host_client->edict->v->items | IT_GRENADE_LAUNCHER;
1525 else if (t[0] == '9')
1526 host_client->edict->v->items = (int)host_client->edict->v->items | HIT_LASER_CANNON;
1527 else if (t[0] == '0')
1528 host_client->edict->v->items = (int)host_client->edict->v->items | HIT_MJOLNIR;
1529 else if (t[0] >= '2')
1530 host_client->edict->v->items = (int)host_client->edict->v->items | (IT_SHOTGUN << (t[0] - '2'));
1535 host_client->edict->v->items = (int)host_client->edict->v->items | (IT_SHOTGUN << (t[0] - '2'));
1540 if (gamemode == GAME_ROGUE && (val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_shells1)))
1543 host_client->edict->v->ammo_shells = v;
1546 if (gamemode == GAME_ROGUE)
1548 if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_nails1)))
1551 if (host_client->edict->v->weapon <= IT_LIGHTNING)
1552 host_client->edict->v->ammo_nails = v;
1557 host_client->edict->v->ammo_nails = v;
1561 if (gamemode == GAME_ROGUE)
1563 val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_lava_nails);
1567 if (host_client->edict->v->weapon > IT_LIGHTNING)
1568 host_client->edict->v->ammo_nails = v;
1573 if (gamemode == GAME_ROGUE)
1575 val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_rockets1);
1579 if (host_client->edict->v->weapon <= IT_LIGHTNING)
1580 host_client->edict->v->ammo_rockets = v;
1585 host_client->edict->v->ammo_rockets = v;
1589 if (gamemode == GAME_ROGUE)
1591 val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_multi_rockets);
1595 if (host_client->edict->v->weapon > IT_LIGHTNING)
1596 host_client->edict->v->ammo_rockets = v;
1601 host_client->edict->v->health = v;
1604 if (gamemode == GAME_ROGUE)
1606 val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_cells1);
1610 if (host_client->edict->v->weapon <= IT_LIGHTNING)
1611 host_client->edict->v->ammo_cells = v;
1616 host_client->edict->v->ammo_cells = v;
1620 if (gamemode == GAME_ROGUE)
1622 val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_plasma);
1626 if (host_client->edict->v->weapon > IT_LIGHTNING)
1627 host_client->edict->v->ammo_cells = v;
1634 edict_t *FindViewthing (void)
1639 for (i=0 ; i<sv.num_edicts ; i++)
1642 if (!strcmp (PR_GetString(e->v->classname), "viewthing"))
1645 Con_Print("No viewthing on map\n");
1654 void Host_Viewmodel_f (void)
1659 e = FindViewthing ();
1663 m = Mod_ForName (Cmd_Argv(1), false, true, false);
1666 Con_Printf("Can't load %s\n", Cmd_Argv(1));
1671 cl.model_precache[(int)e->v->modelindex] = m;
1679 void Host_Viewframe_f (void)
1685 e = FindViewthing ();
1688 m = cl.model_precache[(int)e->v->modelindex];
1690 f = atoi(Cmd_Argv(1));
1691 if (f >= m->numframes)
1698 void PrintFrameName (model_t *m, int frame)
1701 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1703 Con_Printf("frame %i\n", frame);
1711 void Host_Viewnext_f (void)
1716 e = FindViewthing ();
1719 m = cl.model_precache[(int)e->v->modelindex];
1721 e->v->frame = e->v->frame + 1;
1722 if (e->v->frame >= m->numframes)
1723 e->v->frame = m->numframes - 1;
1725 PrintFrameName (m, e->v->frame);
1733 void Host_Viewprev_f (void)
1738 e = FindViewthing ();
1742 m = cl.model_precache[(int)e->v->modelindex];
1744 e->v->frame = e->v->frame - 1;
1745 if (e->v->frame < 0)
1748 PrintFrameName (m, e->v->frame);
1752 ===============================================================================
1756 ===============================================================================
1765 void Host_Startdemos_f (void)
1769 if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
1775 Con_Printf("Max %i demos in demoloop\n", MAX_DEMOS);
1778 Con_Printf("%i demo(s) in loop\n", c);
1780 for (i=1 ; i<c+1 ; i++)
1781 strlcpy (cls.demos[i-1], Cmd_Argv(i), sizeof (cls.demos[i-1]));
1783 // LordHavoc: clear the remaining slots
1784 for (;i <= MAX_DEMOS;i++)
1785 cls.demos[i-1][0] = 0;
1787 if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
1801 Return to looping demos
1804 void Host_Demos_f (void)
1806 if (cls.state == ca_dedicated)
1808 if (cls.demonum == -1)
1818 Return to looping demos
1821 void Host_Stopdemo_f (void)
1823 if (!cls.demoplayback)
1826 Host_ShutdownServer (false);
1829 static void MaxPlayers_f(void)
1833 if (Cmd_Argc() != 2)
1835 Con_Printf("\"maxplayers\" is \"%u\"\n", svs.maxclients);
1841 Con_Print("maxplayers can not be changed while a server is running.\n");
1845 n = atoi(Cmd_Argv(1));
1846 n = bound(1, n, MAX_SCOREBOARD);
1847 Con_Printf("\"maxplayers\" set to \"%u\"\n", n);
1850 Mem_Free(svs.clients);
1852 svs.clients = Mem_Alloc(sv_clients_mempool, sizeof(client_t) * svs.maxclients);
1854 Cvar_Set ("deathmatch", "0");
1856 Cvar_Set ("deathmatch", "1");
1859 //=============================================================================
1866 void Host_InitCommands (void)
1868 Cmd_AddCommand ("status", Host_Status_f);
1869 Cmd_AddCommand ("quit", Host_Quit_f);
1870 if (gamemode == GAME_NEHAHRA)
1872 Cmd_AddCommand ("max", Host_God_f);
1873 Cmd_AddCommand ("monster", Host_Notarget_f);
1874 Cmd_AddCommand ("scrag", Host_Fly_f);
1875 Cmd_AddCommand ("wraith", Host_Noclip_f);
1876 Cmd_AddCommand ("gimme", Host_Give_f);
1880 Cmd_AddCommand ("god", Host_God_f);
1881 Cmd_AddCommand ("notarget", Host_Notarget_f);
1882 Cmd_AddCommand ("fly", Host_Fly_f);
1883 Cmd_AddCommand ("noclip", Host_Noclip_f);
1884 Cmd_AddCommand ("give", Host_Give_f);
1886 Cmd_AddCommand ("map", Host_Map_f);
1887 Cmd_AddCommand ("restart", Host_Restart_f);
1888 Cmd_AddCommand ("changelevel", Host_Changelevel_f);
1889 Cmd_AddCommand ("connect", Host_Connect_f);
1890 Cmd_AddCommand ("reconnect", Host_Reconnect_f);
1891 Cmd_AddCommand ("version", Host_Version_f);
1892 Cmd_AddCommand ("say", Host_Say_f);
1893 Cmd_AddCommand ("say_team", Host_Say_Team_f);
1894 Cmd_AddCommand ("tell", Host_Tell_f);
1895 Cmd_AddCommand ("kill", Host_Kill_f);
1896 Cmd_AddCommand ("pause", Host_Pause_f);
1897 Cmd_AddCommand ("kick", Host_Kick_f);
1898 Cmd_AddCommand ("ping", Host_Ping_f);
1899 Cmd_AddCommand ("load", Host_Loadgame_f);
1900 Cmd_AddCommand ("save", Host_Savegame_f);
1902 Cmd_AddCommand ("startdemos", Host_Startdemos_f);
1903 Cmd_AddCommand ("demos", Host_Demos_f);
1904 Cmd_AddCommand ("stopdemo", Host_Stopdemo_f);
1906 Cmd_AddCommand ("viewmodel", Host_Viewmodel_f);
1907 Cmd_AddCommand ("viewframe", Host_Viewframe_f);
1908 Cmd_AddCommand ("viewnext", Host_Viewnext_f);
1909 Cmd_AddCommand ("viewprev", Host_Viewprev_f);
1911 Cvar_RegisterVariable (&cl_name);
1912 Cmd_AddCommand ("name", Host_Name_f);
1913 Cvar_RegisterVariable (&cl_color);
1914 Cmd_AddCommand ("color", Host_Color_f);
1915 Cvar_RegisterVariable (&cl_rate);
1916 Cmd_AddCommand ("rate", Host_Rate_f);
1917 if (gamemode == GAME_NEHAHRA)
1919 Cvar_RegisterVariable (&cl_pmodel);
1920 Cmd_AddCommand ("pmodel", Host_PModel_f);
1923 // BLACK: This isnt game specific anymore (it was GAME_NEXUIZ at first)
1924 Cvar_RegisterVariable (&cl_playermodel);
1925 Cmd_AddCommand ("playermodel", Host_Playermodel_f);
1926 Cvar_RegisterVariable (&cl_playerskin);
1927 Cmd_AddCommand ("playerskin", Host_Playerskin_f);
1929 Cmd_AddCommand ("prespawn", Host_PreSpawn_f);
1930 Cmd_AddCommand ("spawn", Host_Spawn_f);
1931 Cmd_AddCommand ("begin", Host_Begin_f);
1932 Cmd_AddCommand ("maxplayers", MaxPlayers_f);
1934 Cvar_RegisterVariable(&sv_cheats);