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)
374 Con_Print("reconnect : wait for signon messages again\n");
379 //Con_Print("reconnect: no signon, ignoring reconnect\n");
382 cls.signon = 0; // need new connection messages
386 =====================
389 User command to connect to server
390 =====================
392 void Host_Connect_f (void)
396 Con_Print("connect <serveraddress> : connect to a multiplayer game\n");
401 CL_EstablishConnection(Cmd_Argv(1));
404 CL_EstablishConnection(Cmd_Argv(1));
410 ===============================================================================
414 ===============================================================================
417 #define SAVEGAME_VERSION 5
423 Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
426 void Host_SavegameComment (char *text)
431 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
433 memcpy (text, cl.levelname, strlen(cl.levelname));
434 sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
435 memcpy (text+22, kills, strlen(kills));
436 // convert space to _ to make stdio happy
437 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
440 text[SAVEGAME_COMMENT_LENGTH] = '\0';
449 void Host_Savegame_f (void)
454 char comment[SAVEGAME_COMMENT_LENGTH+1];
456 if (cmd_source != src_command)
459 if (cls.state != ca_connected || !sv.active)
461 Con_Print("Not playing a local game.\n");
467 Con_Print("Can't save in intermission.\n");
471 for (i = 0;i < svs.maxclients;i++)
473 if (svs.clients[i].active)
477 Con_Print("Can't save multiplayer games.\n");
480 if (svs.clients[i].edict->fields.server->deadflag)
482 Con_Print("Can't savegame with a dead player\n");
490 Con_Print("save <savename> : save a game\n");
494 if (strstr(Cmd_Argv(1), ".."))
496 Con_Print("Relative pathnames are not allowed.\n");
500 strlcpy (name, Cmd_Argv(1), sizeof (name));
501 FS_DefaultExtension (name, ".sav", sizeof (name));
503 Con_Printf("Saving game to %s...\n", name);
504 f = FS_Open (name, "wb", false, false);
507 Con_Print("ERROR: couldn't open.\n");
511 FS_Printf(f, "%i\n", SAVEGAME_VERSION);
512 Host_SavegameComment (comment);
513 FS_Printf(f, "%s\n", comment);
514 for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
515 FS_Printf(f, "%f\n", svs.clients[0].spawn_parms[i]);
516 FS_Printf(f, "%d\n", current_skill);
517 FS_Printf(f, "%s\n", sv.name);
518 FS_Printf(f, "%f\n",sv.time);
520 // write the light styles
521 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
523 if (sv.lightstyles[i][0])
524 FS_Printf(f, "%s\n", sv.lightstyles[i]);
531 PRVM_ED_WriteGlobals (f);
532 for (i=0 ; i<prog->num_edicts ; i++)
533 PRVM_ED_Write (f, PRVM_EDICT_NUM(i));
538 Con_Print("done.\n");
547 void Host_Loadgame_f (void)
549 char filename[MAX_QPATH];
550 char mapname[MAX_QPATH];
559 float spawn_parms[NUM_SPAWN_PARMS];
561 if (cmd_source != src_command)
566 Con_Print("load <savename> : load a game\n");
570 strcpy (filename, Cmd_Argv(1));
571 FS_DefaultExtension (filename, ".sav", sizeof (filename));
573 Con_Printf("Loading game from %s...\n", filename);
575 cls.demonum = -1; // stop demo loop in case this fails
577 t = text = FS_LoadFile (filename, tempmempool, false);
580 Con_Print("ERROR: couldn't open.\n");
585 COM_ParseToken(&t, false);
586 version = atoi(com_token);
587 if (version != SAVEGAME_VERSION)
590 Con_Printf("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
595 // this is a little hard to parse, as : is a separator in COM_ParseToken,
596 // so use the console parser instead
597 COM_ParseTokenConsole(&t);
599 for (i = 0;i < NUM_SPAWN_PARMS;i++)
601 COM_ParseToken(&t, false);
602 spawn_parms[i] = atof(com_token);
605 COM_ParseToken(&t, false);
606 // this silliness is so we can load 1.06 save files, which have float skill values
607 current_skill = (int)(atof(com_token) + 0.5);
608 Cvar_SetValue ("skill", (float)current_skill);
611 COM_ParseToken(&t, false);
612 strcpy (mapname, com_token);
615 COM_ParseToken(&t, false);
616 time = atof(com_token);
618 allowcheats = sv_cheats.integer != 0;
620 SV_SpawnServer (mapname);
624 Con_Print("Couldn't load map\n");
627 sv.paused = true; // pause until all clients connect
630 // load the light styles
632 for (i = 0;i < MAX_LIGHTSTYLES;i++)
635 COM_ParseToken(&t, false);
636 strlcpy(sv.lightstyles[i], com_token, sizeof(sv.lightstyles[i]));
639 // load the edicts out of the savegame file
646 while (COM_ParseToken(&t, false))
647 if (!strcmp(com_token, "}"))
649 if (!COM_ParseToken(&start, false))
654 if (strcmp(com_token,"{"))
657 Host_Error ("First token isn't a brace");
662 // parse the global vars
663 PRVM_ED_ParseGlobals (start);
668 if (entnum >= MAX_EDICTS)
671 Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)\n", MAX_EDICTS);
673 while (entnum >= prog->max_edicts)
674 //SV_IncreaseEdicts();
675 PRVM_MEM_IncreaseEdicts();
676 ent = PRVM_EDICT_NUM(entnum);
677 memset (ent->fields.server, 0, prog->progs->entityfields * 4);
678 ent->priv.server->free = false;
679 PRVM_ED_ParseEdict (start, ent);
681 // link it into the bsp tree
682 if (!ent->priv.server->free)
683 SV_LinkEdict (ent, false);
689 prog->num_edicts = entnum;
692 for (i = 0;i < NUM_SPAWN_PARMS;i++)
693 svs.clients[0].spawn_parms[i] = spawn_parms[i];
695 // make sure we're connected to loopback
696 if (cls.state == ca_disconnected || !(cls.state == ca_connected && cls.netcon != NULL && LHNETADDRESS_GetAddressType(&cls.netcon->peeraddress) == LHNETADDRESSTYPE_LOOP))
697 CL_EstablishConnection("local:1");
702 //============================================================================
705 ======================
707 ======================
709 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player"};
710 void Host_Name_f (void)
713 char newName[sizeof(host_client->name)];
715 if (Cmd_Argc () == 1)
717 Con_Printf("\"name\" is \"%s\"\n", cl_name.string);
721 if (Cmd_Argc () == 2)
722 strlcpy (newName, Cmd_Argv(1), sizeof (newName));
724 strlcpy (newName, Cmd_Args(), sizeof (newName));
726 for (i = 0, j = 0;newName[i];i++)
727 if (newName[i] != '\r' && newName[i] != '\n')
728 newName[j++] = newName[i];
731 if (cmd_source == src_command)
733 Cvar_Set ("_cl_name", newName);
734 if (cls.state == ca_connected)
735 Cmd_ForwardToServer ();
739 if (sv.time < host_client->nametime)
741 SV_ClientPrintf("You can't change name more than once every 5 seconds!\n");
745 host_client->nametime = sv.time + 5;
747 // point the string back at updateclient->name to keep it safe
748 strlcpy (host_client->name, newName, sizeof (host_client->name));
749 host_client->edict->fields.server->netname = PRVM_SetEngineString(host_client->name);
750 if (strcmp(host_client->old_name, host_client->name))
752 if (host_client->spawned)
753 SV_BroadcastPrintf("%s changed name to %s\n", host_client->old_name, host_client->name);
754 strcpy(host_client->old_name, host_client->name);
755 // send notification to all clients
756 MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
757 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
758 MSG_WriteString (&sv.reliable_datagram, host_client->name);
763 ======================
765 ======================
767 cvar_t cl_playermodel = {CVAR_SAVE, "_cl_playermodel", ""};
768 // the old cl_playermodel in cl_main has been renamed to __cl_playermodel
769 void Host_Playermodel_f (void)
772 char newPath[sizeof(host_client->playermodel)];
774 if (Cmd_Argc () == 1)
776 Con_Printf("\"playermodel\" is \"%s\"\n", cl_playermodel.string);
780 if (Cmd_Argc () == 2)
781 strlcpy (newPath, Cmd_Argv(1), sizeof (newPath));
783 strlcpy (newPath, Cmd_Args(), sizeof (newPath));
785 for (i = 0, j = 0;newPath[i];i++)
786 if (newPath[i] != '\r' && newPath[i] != '\n')
787 newPath[j++] = newPath[i];
790 if (cmd_source == src_command)
792 Cvar_Set ("_cl_playermodel", newPath);
793 if (cls.state == ca_connected)
794 Cmd_ForwardToServer ();
799 if (sv.time < host_client->nametime)
801 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
805 host_client->nametime = sv.time + 5;
808 // point the string back at updateclient->name to keep it safe
809 strlcpy (host_client->playermodel, newPath, sizeof (host_client->playermodel));
810 if( eval_playermodel )
811 PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_playermodel)->string = PRVM_SetEngineString(host_client->playermodel);
812 if (strcmp(host_client->old_model, host_client->playermodel))
814 if (host_client->spawned)
815 SV_BroadcastPrintf("%s changed model to %s\n", host_client->name, host_client->playermodel);
816 strcpy(host_client->old_model, host_client->playermodel);
817 /*// send notification to all clients
818 MSG_WriteByte (&sv.reliable_datagram, svc_updatepmodel);
819 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
820 MSG_WriteString (&sv.reliable_datagram, host_client->playermodel);*/
825 ======================
827 ======================
829 cvar_t cl_playerskin = {CVAR_SAVE, "_cl_playerskin", ""};
830 void Host_Playerskin_f (void)
833 char newPath[sizeof(host_client->playerskin)];
835 if (Cmd_Argc () == 1)
837 Con_Printf("\"playerskin\" is \"%s\"\n", cl_playerskin.string);
841 if (Cmd_Argc () == 2)
842 strlcpy (newPath, Cmd_Argv(1), sizeof (newPath));
844 strlcpy (newPath, Cmd_Args(), sizeof (newPath));
846 for (i = 0, j = 0;newPath[i];i++)
847 if (newPath[i] != '\r' && newPath[i] != '\n')
848 newPath[j++] = newPath[i];
851 if (cmd_source == src_command)
853 Cvar_Set ("_cl_playerskin", newPath);
854 if (cls.state == ca_connected)
855 Cmd_ForwardToServer ();
860 if (sv.time < host_client->nametime)
862 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
866 host_client->nametime = sv.time + 5;
869 // point the string back at updateclient->name to keep it safe
870 strlcpy (host_client->playerskin, newPath, sizeof (host_client->playerskin));
871 if( eval_playerskin )
872 PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_playerskin)->string = PRVM_SetEngineString(host_client->playerskin);
873 if (strcmp(host_client->old_skin, host_client->playerskin))
875 if (host_client->spawned)
876 SV_BroadcastPrintf("%s changed skin to %s\n", host_client->name, host_client->playerskin);
877 strcpy(host_client->old_skin, host_client->playerskin);
878 /*// send notification to all clients
879 MSG_WriteByte (&sv.reliable_datagram, svc_updatepskin);
880 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
881 MSG_WriteString (&sv.reliable_datagram, host_client->playerskin);*/
885 void Host_Version_f (void)
887 Con_Printf("Version: %s build %s\n", gamename, buildstring);
890 void Host_Say(qboolean teamonly)
896 // LordHavoc: 256 char say messages
897 unsigned char text[256];
898 qboolean fromServer = false;
900 if (cmd_source == src_command)
902 if (cls.state == ca_dedicated)
909 Cmd_ForwardToServer ();
917 if (!teamplay.integer)
920 // turn on color set 1
929 dpsnprintf (text, sizeof(text), "%c%s: %s", 1, host_client->name, p1);
931 dpsnprintf (text, sizeof(text), "%c<%s> %s", 1, hostname.string, p1);
932 p2 = text + strlen(text);
933 while ((const char *)p2 > (const char *)text && (p2[-1] == '\r' || p2[-1] == '\n' || (p2[-1] == '\"' && quoted)))
935 if (p2[-1] == '\"' && quoted)
940 strlcat(text, "\n", sizeof(text));
942 // note: save is not a valid edict if fromServer is true
944 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
945 if (host_client->spawned && (!teamonly || host_client->edict->fields.server->team == save->edict->fields.server->team))
946 SV_ClientPrint(text);
949 if (cls.state == ca_dedicated)
954 void Host_Say_f(void)
960 void Host_Say_Team_f(void)
966 void Host_Tell_f(void)
971 char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
972 qboolean fromServer = false;
974 if (cmd_source == src_command)
976 if (cls.state == ca_dedicated)
980 Cmd_ForwardToServer ();
989 sprintf (text, "%s: ", host_client->name);
991 sprintf (text, "<%s> ", hostname.string);
994 p2 = p1 + strlen(p1);
995 // remove the target name
996 while (p1 < p2 && *p1 != ' ')
998 while (p1 < p2 && *p1 == ' ')
1000 // remove trailing newlines
1001 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
1003 // remove quotes if present
1009 else if (fromServer)
1010 Con_Print("Host_Tell: missing end quote\n");
1012 SV_ClientPrint("Host_Tell: missing end quote\n");
1014 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
1016 for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
1022 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
1023 if (host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1)))
1024 SV_ClientPrint(text);
1034 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0"};
1035 void Host_Color_f(void)
1040 func_t SV_ChangeTeam;
1042 if (Cmd_Argc() == 1)
1044 Con_Printf("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
1045 Con_Print("color <0-15> [0-15]\n");
1049 if (Cmd_Argc() == 2)
1050 top = bottom = atoi(Cmd_Argv(1));
1053 top = atoi(Cmd_Argv(1));
1054 bottom = atoi(Cmd_Argv(2));
1058 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
1062 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
1066 playercolor = top*16 + bottom;
1068 if (cmd_source == src_command)
1070 Cvar_SetValue ("_cl_color", playercolor);
1071 if (cls.state == ca_connected)
1072 Cmd_ForwardToServer ();
1076 if (host_client->edict && (f = PRVM_ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - prog->functions)))
1078 Con_DPrint("Calling SV_ChangeTeam\n");
1079 prog->globals.server->time = sv.time;
1080 prog->globals.generic[OFS_PARM0] = playercolor;
1081 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1082 PRVM_ExecuteProgram (SV_ChangeTeam, "QC function SV_ChangeTeam is missing");
1087 if (host_client->edict)
1089 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_clientcolors)))
1090 val->_float = playercolor;
1091 host_client->edict->fields.server->team = bottom + 1;
1093 host_client->colors = playercolor;
1094 if (host_client->old_colors != host_client->colors)
1096 host_client->old_colors = host_client->colors;
1097 // send notification to all clients
1098 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
1099 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
1100 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
1105 cvar_t cl_rate = {CVAR_SAVE, "_cl_rate", "10000"};
1106 void Host_Rate_f(void)
1110 if (Cmd_Argc() != 2)
1112 Con_Printf("\"rate\" is \"%i\"\n", cl_rate.integer);
1113 Con_Print("rate <500-25000>\n");
1117 rate = atoi(Cmd_Argv(1));
1119 if (cmd_source == src_command)
1121 Cvar_SetValue ("_cl_rate", bound(NET_MINRATE, rate, NET_MAXRATE));
1122 if (cls.state == ca_connected)
1123 Cmd_ForwardToServer ();
1127 host_client->rate = rate;
1135 void Host_Kill_f (void)
1137 if (cmd_source == src_command)
1139 Cmd_ForwardToServer ();
1143 if (host_client->edict->fields.server->health <= 0)
1145 SV_ClientPrint("Can't suicide -- already dead!\n");
1149 prog->globals.server->time = sv.time;
1150 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1151 PRVM_ExecuteProgram (prog->globals.server->ClientKill, "QC function ClientKill is missing");
1160 void Host_Pause_f (void)
1163 if (cmd_source == src_command)
1165 Cmd_ForwardToServer ();
1168 if (!pausable.integer)
1169 SV_ClientPrint("Pause not allowed.\n");
1173 SV_BroadcastPrintf("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
1174 // send notification to all clients
1175 MSG_WriteByte(&sv.reliable_datagram, svc_setpause);
1176 MSG_WriteByte(&sv.reliable_datagram, sv.paused);
1181 ======================
1183 LordHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
1184 ======================
1186 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0"};
1187 static void Host_PModel_f (void)
1192 if (Cmd_Argc () == 1)
1194 Con_Printf("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
1197 i = atoi(Cmd_Argv(1));
1199 if (cmd_source == src_command)
1201 if (cl_pmodel.integer == i)
1203 Cvar_SetValue ("_cl_pmodel", i);
1204 if (cls.state == ca_connected)
1205 Cmd_ForwardToServer ();
1209 if (host_client->edict && (val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_pmodel)))
1213 //===========================================================================
1221 void Host_PreSpawn_f (void)
1223 if (cmd_source == src_command)
1225 Con_Print("prespawn is not valid from the console\n");
1229 if (host_client->spawned)
1231 Con_Print("prespawn not valid -- already spawned\n");
1235 SZ_Write (&host_client->message, sv.signon.data, sv.signon.cursize);
1236 MSG_WriteByte (&host_client->message, svc_signonnum);
1237 MSG_WriteByte (&host_client->message, 2);
1238 host_client->sendsignon = true;
1240 // reset the name change timer because the client will send name soon
1241 host_client->nametime = 0;
1249 void Host_Spawn_f (void)
1255 int stats[MAX_CL_STATS];
1257 if (cmd_source == src_command)
1259 Con_Print("spawn is not valid from the console\n");
1263 if (host_client->spawned)
1265 Con_Print("Spawn not valid -- already spawned\n");
1269 // reset name change timer again because they might want to change name
1270 // again in the first 5 seconds after connecting
1271 host_client->nametime = 0;
1273 // LordHavoc: moved this above the QC calls at FrikaC's request
1274 // send all current names, colors, and frag counts
1275 SZ_Clear (&host_client->message);
1277 // run the entrance script
1280 // loaded games are fully initialized already
1281 // if this is the last client to be connected, unpause
1284 if ((f = PRVM_ED_FindFunction ("RestoreGame")))
1285 if ((RestoreGame = (func_t)(f - prog->functions)))
1287 Con_DPrint("Calling RestoreGame\n");
1288 prog->globals.server->time = sv.time;
1289 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1290 PRVM_ExecuteProgram (RestoreGame, "QC function RestoreGame is missing");
1296 PRVM_ED_ClearEdict(host_client->edict);
1298 //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);
1300 // copy spawn parms out of the client_t
1301 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1302 (&prog->globals.server->parm1)[i] = host_client->spawn_parms[i];
1304 // call the spawn function
1305 host_client->clientconnectcalled = true;
1306 prog->globals.server->time = sv.time;
1307 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1308 PRVM_ExecuteProgram (prog->globals.server->ClientConnect, "QC function ClientConnect is missing");
1310 if ((Sys_DoubleTime() - host_client->connecttime) <= sv.time)
1311 Con_Printf("%s entered the game\n", host_client->name);
1313 PRVM_ExecuteProgram (prog->globals.server->PutClientInServer, "QC function PutClientInServer is missing");
1317 // send time of update
1318 MSG_WriteByte (&host_client->message, svc_time);
1319 MSG_WriteFloat (&host_client->message, sv.time);
1321 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
1323 if (!client->active)
1325 MSG_WriteByte (&host_client->message, svc_updatename);
1326 MSG_WriteByte (&host_client->message, i);
1327 MSG_WriteString (&host_client->message, client->name);
1328 MSG_WriteByte (&host_client->message, svc_updatefrags);
1329 MSG_WriteByte (&host_client->message, i);
1330 MSG_WriteShort (&host_client->message, client->frags);
1331 MSG_WriteByte (&host_client->message, svc_updatecolors);
1332 MSG_WriteByte (&host_client->message, i);
1333 MSG_WriteByte (&host_client->message, client->colors);
1336 // send all current light styles
1337 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1339 MSG_WriteByte (&host_client->message, svc_lightstyle);
1340 MSG_WriteByte (&host_client->message, (char)i);
1341 MSG_WriteString (&host_client->message, sv.lightstyles[i]);
1345 MSG_WriteByte (&host_client->message, svc_updatestat);
1346 MSG_WriteByte (&host_client->message, STAT_TOTALSECRETS);
1347 MSG_WriteLong (&host_client->message, prog->globals.server->total_secrets);
1349 MSG_WriteByte (&host_client->message, svc_updatestat);
1350 MSG_WriteByte (&host_client->message, STAT_TOTALMONSTERS);
1351 MSG_WriteLong (&host_client->message, prog->globals.server->total_monsters);
1353 MSG_WriteByte (&host_client->message, svc_updatestat);
1354 MSG_WriteByte (&host_client->message, STAT_SECRETS);
1355 MSG_WriteLong (&host_client->message, prog->globals.server->found_secrets);
1357 MSG_WriteByte (&host_client->message, svc_updatestat);
1358 MSG_WriteByte (&host_client->message, STAT_MONSTERS);
1359 MSG_WriteLong (&host_client->message, prog->globals.server->killed_monsters);
1362 // Never send a roll angle, because savegames can catch the server
1363 // in a state where it is expecting the client to correct the angle
1364 // and it won't happen if the game was just loaded, so you wind up
1365 // with a permanent head tilt
1366 MSG_WriteByte (&host_client->message, svc_setangle);
1367 MSG_WriteAngle (&host_client->message, host_client->edict->fields.server->angles[0], sv.protocol);
1368 MSG_WriteAngle (&host_client->message, host_client->edict->fields.server->angles[1], sv.protocol);
1369 MSG_WriteAngle (&host_client->message, 0, sv.protocol);
1371 SV_WriteClientdataToMessage (host_client, host_client->edict, &host_client->message, stats);
1373 MSG_WriteByte (&host_client->message, svc_signonnum);
1374 MSG_WriteByte (&host_client->message, 3);
1375 host_client->sendsignon = true;
1383 void Host_Begin_f (void)
1385 if (cmd_source == src_command)
1387 Con_Print("begin is not valid from the console\n");
1391 host_client->spawned = true;
1394 //===========================================================================
1401 Kicks a user off of the server
1404 void Host_Kick_f (void)
1407 const char *message = NULL;
1410 qboolean byNumber = false;
1412 if (cmd_source != src_command || !sv.active)
1418 if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1420 i = atof(Cmd_Argv(2)) - 1;
1421 if (i < 0 || i >= svs.maxclients || !(host_client = svs.clients + i)->active)
1427 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1429 if (!host_client->active)
1431 if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1436 if (i < svs.maxclients)
1438 if (cmd_source == src_command)
1440 if (cls.state == ca_dedicated)
1443 who = cl_name.string;
1448 // can't kick yourself!
1449 if (host_client == save)
1454 message = Cmd_Args();
1455 COM_ParseToken(&message, false);
1458 message++; // skip the #
1459 while (*message == ' ') // skip white space
1461 message += strlen(Cmd_Argv(2)); // skip the number
1463 while (*message && *message == ' ')
1467 SV_ClientPrintf("Kicked by %s: %s\n", who, message);
1469 SV_ClientPrintf("Kicked by %s\n", who);
1470 SV_DropClient (false); // kicked
1478 ===============================================================================
1482 ===============================================================================
1490 void Host_Give_f (void)
1496 if (cmd_source == src_command)
1498 Cmd_ForwardToServer ();
1504 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
1509 v = atoi (Cmd_Argv(2));
1523 // MED 01/04/97 added hipnotic give stuff
1524 if (gamemode == GAME_HIPNOTIC)
1529 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | HIT_PROXIMITY_GUN;
1531 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | IT_GRENADE_LAUNCHER;
1533 else if (t[0] == '9')
1534 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | HIT_LASER_CANNON;
1535 else if (t[0] == '0')
1536 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | HIT_MJOLNIR;
1537 else if (t[0] >= '2')
1538 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | (IT_SHOTGUN << (t[0] - '2'));
1543 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | (IT_SHOTGUN << (t[0] - '2'));
1548 if (gamemode == GAME_ROGUE && (val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_shells1)))
1551 host_client->edict->fields.server->ammo_shells = v;
1554 if (gamemode == GAME_ROGUE)
1556 if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_nails1)))
1559 if (host_client->edict->fields.server->weapon <= IT_LIGHTNING)
1560 host_client->edict->fields.server->ammo_nails = v;
1565 host_client->edict->fields.server->ammo_nails = v;
1569 if (gamemode == GAME_ROGUE)
1571 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_lava_nails);
1575 if (host_client->edict->fields.server->weapon > IT_LIGHTNING)
1576 host_client->edict->fields.server->ammo_nails = v;
1581 if (gamemode == GAME_ROGUE)
1583 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_rockets1);
1587 if (host_client->edict->fields.server->weapon <= IT_LIGHTNING)
1588 host_client->edict->fields.server->ammo_rockets = v;
1593 host_client->edict->fields.server->ammo_rockets = v;
1597 if (gamemode == GAME_ROGUE)
1599 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_multi_rockets);
1603 if (host_client->edict->fields.server->weapon > IT_LIGHTNING)
1604 host_client->edict->fields.server->ammo_rockets = v;
1609 host_client->edict->fields.server->health = v;
1612 if (gamemode == GAME_ROGUE)
1614 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_cells1);
1618 if (host_client->edict->fields.server->weapon <= IT_LIGHTNING)
1619 host_client->edict->fields.server->ammo_cells = v;
1624 host_client->edict->fields.server->ammo_cells = v;
1628 if (gamemode == GAME_ROGUE)
1630 val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_plasma);
1634 if (host_client->edict->fields.server->weapon > IT_LIGHTNING)
1635 host_client->edict->fields.server->ammo_cells = v;
1642 prvm_edict_t *FindViewthing (void)
1647 for (i=0 ; i<prog->num_edicts ; i++)
1649 e = PRVM_EDICT_NUM(i);
1650 if (!strcmp (PRVM_GetString(e->fields.server->classname), "viewthing"))
1653 Con_Print("No viewthing on map\n");
1662 void Host_Viewmodel_f (void)
1671 e = FindViewthing ();
1676 m = Mod_ForName (Cmd_Argv(1), false, true, false);
1679 Con_Printf("Can't load %s\n", Cmd_Argv(1));
1683 e->fields.server->frame = 0;
1684 cl.model_precache[(int)e->fields.server->modelindex] = m;
1692 void Host_Viewframe_f (void)
1702 e = FindViewthing ();
1706 m = cl.model_precache[(int)e->fields.server->modelindex];
1708 f = atoi(Cmd_Argv(1));
1709 if (f >= m->numframes)
1712 e->fields.server->frame = f;
1716 void PrintFrameName (model_t *m, int frame)
1719 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1721 Con_Printf("frame %i\n", frame);
1729 void Host_Viewnext_f (void)
1738 e = FindViewthing ();
1742 m = cl.model_precache[(int)e->fields.server->modelindex];
1744 e->fields.server->frame = e->fields.server->frame + 1;
1745 if (e->fields.server->frame >= m->numframes)
1746 e->fields.server->frame = m->numframes - 1;
1748 PrintFrameName (m, e->fields.server->frame);
1756 void Host_Viewprev_f (void)
1765 e = FindViewthing ();
1770 m = cl.model_precache[(int)e->fields.server->modelindex];
1772 e->fields.server->frame = e->fields.server->frame - 1;
1773 if (e->fields.server->frame < 0)
1774 e->fields.server->frame = 0;
1776 PrintFrameName (m, e->fields.server->frame);
1780 ===============================================================================
1784 ===============================================================================
1793 void Host_Startdemos_f (void)
1797 if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
1803 Con_Printf("Max %i demos in demoloop\n", MAX_DEMOS);
1806 Con_Printf("%i demo(s) in loop\n", c);
1808 for (i=1 ; i<c+1 ; i++)
1809 strlcpy (cls.demos[i-1], Cmd_Argv(i), sizeof (cls.demos[i-1]));
1811 // LordHavoc: clear the remaining slots
1812 for (;i <= MAX_DEMOS;i++)
1813 cls.demos[i-1][0] = 0;
1815 if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
1829 Return to looping demos
1832 void Host_Demos_f (void)
1834 if (cls.state == ca_dedicated)
1836 if (cls.demonum == -1)
1846 Return to looping demos
1849 void Host_Stopdemo_f (void)
1851 if (!cls.demoplayback)
1854 Host_ShutdownServer (false);
1857 static void MaxPlayers_f(void)
1861 if (Cmd_Argc() != 2)
1863 Con_Printf("\"maxplayers\" is \"%u\"\n", svs.maxclients);
1869 Con_Print("maxplayers can not be changed while a server is running.\n");
1873 n = atoi(Cmd_Argv(1));
1874 n = bound(1, n, MAX_SCOREBOARD);
1875 Con_Printf("\"maxplayers\" set to \"%u\"\n", n);
1878 Mem_Free(svs.clients);
1880 svs.clients = Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients);
1882 Cvar_Set ("deathmatch", "0");
1884 Cvar_Set ("deathmatch", "1");
1887 //=============================================================================
1894 void Host_InitCommands (void)
1896 Cmd_AddCommand ("status", Host_Status_f);
1897 Cmd_AddCommand ("quit", Host_Quit_f);
1898 if (gamemode == GAME_NEHAHRA)
1900 Cmd_AddCommand ("max", Host_God_f);
1901 Cmd_AddCommand ("monster", Host_Notarget_f);
1902 Cmd_AddCommand ("scrag", Host_Fly_f);
1903 Cmd_AddCommand ("wraith", Host_Noclip_f);
1904 Cmd_AddCommand ("gimme", Host_Give_f);
1908 Cmd_AddCommand ("god", Host_God_f);
1909 Cmd_AddCommand ("notarget", Host_Notarget_f);
1910 Cmd_AddCommand ("fly", Host_Fly_f);
1911 Cmd_AddCommand ("noclip", Host_Noclip_f);
1912 Cmd_AddCommand ("give", Host_Give_f);
1914 Cmd_AddCommand ("map", Host_Map_f);
1915 Cmd_AddCommand ("restart", Host_Restart_f);
1916 Cmd_AddCommand ("changelevel", Host_Changelevel_f);
1917 Cmd_AddCommand ("connect", Host_Connect_f);
1918 Cmd_AddCommand ("reconnect", Host_Reconnect_f);
1919 Cmd_AddCommand ("version", Host_Version_f);
1920 Cmd_AddCommand ("say", Host_Say_f);
1921 Cmd_AddCommand ("say_team", Host_Say_Team_f);
1922 Cmd_AddCommand ("tell", Host_Tell_f);
1923 Cmd_AddCommand ("kill", Host_Kill_f);
1924 Cmd_AddCommand ("pause", Host_Pause_f);
1925 Cmd_AddCommand ("kick", Host_Kick_f);
1926 Cmd_AddCommand ("ping", Host_Ping_f);
1927 Cmd_AddCommand ("load", Host_Loadgame_f);
1928 Cmd_AddCommand ("save", Host_Savegame_f);
1930 Cmd_AddCommand ("startdemos", Host_Startdemos_f);
1931 Cmd_AddCommand ("demos", Host_Demos_f);
1932 Cmd_AddCommand ("stopdemo", Host_Stopdemo_f);
1934 Cmd_AddCommand ("viewmodel", Host_Viewmodel_f);
1935 Cmd_AddCommand ("viewframe", Host_Viewframe_f);
1936 Cmd_AddCommand ("viewnext", Host_Viewnext_f);
1937 Cmd_AddCommand ("viewprev", Host_Viewprev_f);
1939 Cvar_RegisterVariable (&cl_name);
1940 Cmd_AddCommand ("name", Host_Name_f);
1941 Cvar_RegisterVariable (&cl_color);
1942 Cmd_AddCommand ("color", Host_Color_f);
1943 Cvar_RegisterVariable (&cl_rate);
1944 Cmd_AddCommand ("rate", Host_Rate_f);
1945 if (gamemode == GAME_NEHAHRA)
1947 Cvar_RegisterVariable (&cl_pmodel);
1948 Cmd_AddCommand ("pmodel", Host_PModel_f);
1951 // BLACK: This isnt game specific anymore (it was GAME_NEXUIZ at first)
1952 Cvar_RegisterVariable (&cl_playermodel);
1953 Cmd_AddCommand ("playermodel", Host_Playermodel_f);
1954 Cvar_RegisterVariable (&cl_playerskin);
1955 Cmd_AddCommand ("playerskin", Host_Playerskin_f);
1957 Cmd_AddCommand ("prespawn", Host_PreSpawn_f);
1958 Cmd_AddCommand ("spawn", Host_Spawn_f);
1959 Cmd_AddCommand ("begin", Host_Begin_f);
1960 Cmd_AddCommand ("maxplayers", MaxPlayers_f);
1962 Cvar_RegisterVariable(&sv_cheats);