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 char sv_spawnmap[MAX_QPATH];
25 char sv_loadgame[MAX_OSPATH];
27 cvar_t sv_cheats = {0, "sv_cheats", "0"};
28 qboolean allowcheats = false;
30 mfunction_t *ED_FindFunction (char *name);
38 extern qboolean host_shuttingdown;
39 void Host_Quit_f (void)
41 host_shuttingdown = true;
43 Host_ShutdownServer(false);
54 void Host_Status_f (void)
57 int seconds, minutes, hours = 0, j, players;
58 void (*print) (const char *fmt, ...);
60 if (cmd_source == src_command)
64 Cmd_ForwardToServer ();
70 print = SV_ClientPrintf;
72 for (players = 0, j = 0;j < MAX_SCOREBOARD;j++)
73 if (svs.connectedclients[j])
75 print ("host: %s\n", Cvar_VariableString ("hostname"));
76 print ("version: %s build %s\n", gamename, buildstring);
77 print ("map: %s\n", sv.name);
78 print ("players: %i active (%i max)\n\n", players, min(sv_maxplayers.integer, MAX_SCOREBOARD));
79 for (j = 0;j < MAX_SCOREBOARD;j++)
81 if (!(client = svs.connectedclients[j]))
83 seconds = (int)(realtime - client->netconnection->connecttime);
84 minutes = seconds / 60;
87 seconds -= (minutes * 60);
90 minutes -= (hours * 60);
94 print ("#%-2u %-16.16s %3i %2i:%02i:%02i\n", j+1, client->name, (int)client->edict->v->frags, hours, minutes, seconds);
95 print (" %s\n", client->netconnection->address);
104 Sets client to godmode
107 void Host_God_f (void)
109 if (cmd_source == src_command)
111 Cmd_ForwardToServer ();
120 SV_ClientPrintf("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
124 sv_player->v->flags = (int)sv_player->v->flags ^ FL_GODMODE;
125 if (!((int)sv_player->v->flags & FL_GODMODE) )
126 SV_ClientPrintf ("godmode OFF\n");
128 SV_ClientPrintf ("godmode ON\n");
131 void Host_Notarget_f (void)
133 if (cmd_source == src_command)
135 Cmd_ForwardToServer ();
144 SV_ClientPrintf("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
148 sv_player->v->flags = (int)sv_player->v->flags ^ FL_NOTARGET;
149 if (!((int)sv_player->v->flags & FL_NOTARGET) )
150 SV_ClientPrintf ("notarget OFF\n");
152 SV_ClientPrintf ("notarget ON\n");
155 qboolean noclip_anglehack;
157 void Host_Noclip_f (void)
159 if (cmd_source == src_command)
161 Cmd_ForwardToServer ();
170 SV_ClientPrintf("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
174 if (sv_player->v->movetype != MOVETYPE_NOCLIP)
176 noclip_anglehack = true;
177 sv_player->v->movetype = MOVETYPE_NOCLIP;
178 SV_ClientPrintf ("noclip ON\n");
182 noclip_anglehack = false;
183 sv_player->v->movetype = MOVETYPE_WALK;
184 SV_ClientPrintf ("noclip OFF\n");
192 Sets client to flymode
195 void Host_Fly_f (void)
197 if (cmd_source == src_command)
199 Cmd_ForwardToServer ();
208 SV_ClientPrintf("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
212 if (sv_player->v->movetype != MOVETYPE_FLY)
214 sv_player->v->movetype = MOVETYPE_FLY;
215 SV_ClientPrintf ("flymode ON\n");
219 sv_player->v->movetype = MOVETYPE_WALK;
220 SV_ClientPrintf ("flymode OFF\n");
231 void Host_Ping_f (void)
237 if (cmd_source == src_command)
239 Cmd_ForwardToServer ();
243 SV_ClientPrintf ("Client ping times:\n");
244 for (i = 0;i < MAX_SCOREBOARD;i++)
246 if (!(client = svs.connectedclients[i]))
249 for (j=0 ; j<NUM_PING_TIMES ; j++)
250 total+=client->ping_times[j];
251 total /= NUM_PING_TIMES;
252 SV_ClientPrintf ("%4i %s\n", (int)(total*1000), client->name);
257 ===============================================================================
261 ===============================================================================
265 ======================
270 command from the console. Active clients are kicked off.
271 ======================
273 void Host_Map_f (void)
275 if (cmd_source != src_command)
278 cls.demonum = -1; // stop demo loop in case this fails
281 Host_ShutdownServer(false);
283 key_dest = key_game; // remove console or menu
284 SCR_BeginLoadingPlaque ();
287 svs.serverflags = 0; // haven't completed an episode yet
288 strcpy (sv_spawnmap, Cmd_Argv(1));
295 Goes to a new map, taking all clients along
298 void Host_Changelevel_f (void)
302 Con_Printf ("changelevel <levelname> : continue game on a new level\n");
305 if (!sv.active || cls.demoplayback)
307 Con_Printf ("Only the server may changelevel\n");
310 SV_SaveSpawnparms ();
311 strcpy (sv_spawnmap, Cmd_Argv(1));
318 Restarts the current server for a dead player
321 void Host_Restart_f (void)
323 if (cls.demoplayback || !sv.active)
326 if (cmd_source != src_command)
328 strcpy (sv_spawnmap, sv.name);
335 This command causes the client to wait for the signon messages again.
336 This is sent just before a server changes levels
339 void Host_Reconnect_f (void)
341 SCR_BeginLoadingPlaque();
342 cls.signon = 0; // need new connection messages
346 =====================
349 User command to connect to server
350 =====================
352 void Host_Connect_f (void)
354 CL_EstablishConnection(Cmd_Argv(1));
359 ===============================================================================
363 ===============================================================================
366 #define SAVEGAME_VERSION 5
372 Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
375 void Host_SavegameComment (char *text)
380 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
382 memcpy (text, cl.levelname, strlen(cl.levelname));
383 sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
384 memcpy (text+22, kills, strlen(kills));
385 // convert space to _ to make stdio happy
386 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
389 text[SAVEGAME_COMMENT_LENGTH] = '\0';
398 void Host_Savegame_f (void)
403 char comment[SAVEGAME_COMMENT_LENGTH+1];
405 if (cmd_source != src_command)
410 Con_Printf ("Not playing a local game.\n");
416 Con_Printf ("Can't save in intermission.\n");
420 for (i = 0;i < MAX_SCOREBOARD;i++)
422 if (svs.connectedclients[i])
426 Con_Printf("Can't save multiplayer games.\n");
429 if (svs.connectedclients[i]->edict->v->deadflag)
431 Con_Printf("Can't savegame with a dead player\n");
439 Con_Printf ("save <savename> : save a game\n");
443 if (strstr(Cmd_Argv(1), ".."))
445 Con_Printf ("Relative pathnames are not allowed.\n");
449 strncpy (name, Cmd_Argv(1), sizeof (name) - 1);
450 name[sizeof (name) - 1] = '\0';
451 FS_DefaultExtension (name, ".sav");
453 Con_Printf ("Saving game to %s...\n", name);
454 f = FS_Open (name, "w", false);
457 Con_Printf ("ERROR: couldn't open.\n");
461 FS_Printf (f, "%i\n", SAVEGAME_VERSION);
462 Host_SavegameComment (comment);
463 FS_Printf (f, "%s\n", comment);
464 for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
465 FS_Printf (f, "%f\n", svs.connectedclients[0]->spawn_parms[i]);
466 FS_Printf (f, "%d\n", current_skill);
467 FS_Printf (f, "%s\n", sv.name);
468 FS_Printf (f, "%f\n",sv.time);
470 // write the light styles
472 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
474 if (sv.lightstyles[i])
475 FS_Printf (f, "%s\n", sv.lightstyles[i]);
482 for (i=0 ; i<sv.num_edicts ; i++)
484 ED_Write (f, EDICT_NUM(i));
488 Con_Printf ("done.\n");
492 extern mempool_t *edictstring_mempool;
499 void Host_Loadgame_f (void)
501 if (cmd_source != src_command)
506 Con_Printf ("load <savename> : load a game\n");
510 strcpy (sv_loadgame, Cmd_Argv(1));
511 FS_DefaultExtension (sv_loadgame, ".sav");
513 Con_Printf ("Loading game from %s...\n", sv_loadgame);
516 void Host_PerformLoadGame(char *name)
519 char mapname[MAX_QPATH];
528 float spawn_parms[NUM_SPAWN_PARMS];
530 cls.demonum = -1; // stop demo loop in case this fails
532 f = FS_Open (name, "r", false);
535 Con_Printf ("ERROR: couldn't open.\n");
539 str = FS_Getline (f);
540 sscanf (str, "%i\n", &version);
541 if (version != SAVEGAME_VERSION)
544 Con_Printf ("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
548 SCR_BeginLoadingPlaque ();
550 str = FS_Getline (f);
551 for (i = 0;i < NUM_SPAWN_PARMS;i++)
553 str = FS_Getline (f);
554 sscanf (str, "%f\n", &spawn_parms[i]);
556 // this silliness is so we can load 1.06 save files, which have float skill values
557 str = FS_Getline (f);
558 sscanf (str, "%f\n", &tfloat);
559 current_skill = (int)(tfloat + 0.1);
560 Cvar_SetValue ("skill", (float)current_skill);
562 strcpy (mapname, FS_Getline (f));
564 str = FS_Getline (f);
565 sscanf (str, "%f\n",&time);
567 allowcheats = sv_cheats.integer != 0;
568 SV_SpawnServer (mapname);
571 Con_Printf ("Couldn't load map\n");
574 sv.paused = true; // pause until all clients connect
577 // load the light styles
579 for (i = 0;i < MAX_LIGHTSTYLES;i++)
581 str = FS_Getline (f);
582 sv.lightstyles[i] = Mem_Alloc(edictstring_mempool, strlen(str)+1);
583 strcpy (sv.lightstyles[i], str);
586 // load the edicts out of the savegame file
591 for (i = 0;i < (int)sizeof(buf) - 1;i++)
603 if (i == sizeof(buf)-1)
604 Host_Error ("Loadgame buffer overflow");
607 if (!COM_ParseToken(&start, false))
612 if (strcmp(com_token,"{"))
613 Host_Error ("First token isn't a brace");
617 // parse the global vars
618 ED_ParseGlobals (start);
623 if (entnum >= MAX_EDICTS)
624 Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)\n", MAX_EDICTS);
625 while (entnum >= sv.max_edicts)
627 ent = EDICT_NUM(entnum);
628 memset (ent->v, 0, progs->entityfields * 4);
629 ent->e->free = false;
630 ED_ParseEdict (start, ent);
632 // link it into the bsp tree
634 SV_LinkEdict (ent, false);
640 sv.num_edicts = entnum;
645 for (i = 0;i < NUM_SPAWN_PARMS;i++)
646 svs.connectedclients[0]->spawn_parms[i] = spawn_parms[i];
648 // make sure we're connected to loopback
649 if (cls.state == ca_disconnected || !(cls.state == ca_connected && cls.netcon != NULL && LHNETADDRESS_GetAddressType(&cls.netcon->peeraddress) == LHNETADDRESSTYPE_LOOP))
650 CL_EstablishConnection("local");
653 //============================================================================
656 ======================
658 ======================
660 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player"};
661 void Host_Name_f (void)
663 char newName[sizeof(host_client->name)];
665 if (Cmd_Argc () == 1)
667 Con_Printf ("\"name\" is \"%s\"\n", cl_name.string);
671 if (Cmd_Argc () == 2)
672 strncpy(newName, Cmd_Argv(1), sizeof(host_client->name) - 1);
674 strncpy(newName, Cmd_Args(), sizeof(host_client->name) - 1);
675 newName[sizeof(host_client->name) - 1] = 0;
677 if (cmd_source == src_command)
679 if (strcmp(cl_name.string, newName) == 0)
681 Cvar_Set ("_cl_name", newName);
682 if (cls.state == ca_connected)
683 Cmd_ForwardToServer ();
687 if (strcmp(host_client->name, newName) && host_client->name[0] && strcmp(host_client->name, "unconnected"))
688 SV_BroadcastPrintf("%s changed name to %s\n", host_client->name, newName);
689 strcpy(host_client->name, newName);
690 strcpy(host_client->old_name, newName);
692 sv_player->v->netname = PR_SetString(host_client->name);
693 //Con_Printf("Host_Name_f: host_client->edict->netname = %s, sv_player->netname = %s, host_client->name = %s\n", PR_GetString(host_client->edict->v->netname), PR_GetString(sv_player->v->netname), host_client->name);
695 // send notification to all clients
697 MSG_WriteByte(&sv.reliable_datagram, svc_updatename);
698 MSG_WriteByte(&sv.reliable_datagram, host_client->number);
699 MSG_WriteString(&sv.reliable_datagram, host_client->name);
703 void Host_Version_f (void)
705 Con_Printf ("Version: %s build %s\n", gamename, buildstring);
708 void Host_Say(qboolean teamonly)
713 // LordHavoc: 256 char say messages
714 unsigned char text[256];
715 qboolean fromServer = false;
717 if (cmd_source == src_command)
719 if (cls.state == ca_dedicated)
726 Cmd_ForwardToServer ();
736 // turn on color set 1
738 sprintf (text, "%c%s: ", 1, host_client->name);
740 sprintf (text, "%c<%s> ", 1, hostname.string);
743 p2 = p1 + strlen(p1);
744 // remove trailing newlines
745 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
747 // remove quotes if present
754 Con_Printf("Host_Say: missing end quote\n");
756 SV_ClientPrintf("Host_Say: missing end quote\n");
758 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
760 for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
765 for (j = 0;j < MAX_SCOREBOARD;j++)
766 if ((host_client = svs.connectedclients[j]) && host_client->spawned && (!teamplay.integer || host_client->edict->v->team == save->edict->v->team))
767 SV_ClientPrintf("%s", text);
770 Sys_Printf("%s", &text[1]);
774 void Host_Say_f(void)
780 void Host_Say_Team_f(void)
786 void Host_Tell_f(void)
791 char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
792 qboolean fromServer = false;
794 if (cmd_source == src_command)
796 if (cls.state == ca_dedicated)
800 Cmd_ForwardToServer ();
809 sprintf (text, "%s: ", host_client->name);
811 sprintf (text, "<%s> ", hostname.string);
814 p2 = p1 + strlen(p1);
815 // remove the target name
816 while (p1 < p2 && *p1 != ' ')
818 while (p1 < p2 && *p1 == ' ')
820 // remove trailing newlines
821 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
823 // remove quotes if present
830 Con_Printf("Host_Tell: missing end quote\n");
832 SV_ClientPrintf("Host_Tell: missing end quote\n");
834 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
836 for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
842 for (j = 0;j < MAX_SCOREBOARD;j++)
843 if ((host_client = svs.connectedclients[j]) && host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1)))
844 SV_ClientPrintf("%s", text);
854 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0"};
855 void Host_Color_f(void)
860 func_t SV_ChangeTeam;
864 Con_Printf ("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
865 Con_Printf ("color <0-15> [0-15]\n");
870 top = bottom = atoi(Cmd_Argv(1));
873 top = atoi(Cmd_Argv(1));
874 bottom = atoi(Cmd_Argv(2));
878 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
882 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
886 playercolor = top*16 + bottom;
888 if (cmd_source == src_command)
890 Cvar_SetValue ("_cl_color", playercolor);
891 if (cls.state == ca_connected)
892 Cmd_ForwardToServer ();
896 if (sv_player && (f = ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - pr_functions)))
898 Con_DPrintf("Calling SV_ChangeTeam\n");
899 pr_global_struct->time = sv.time;
900 pr_globals[OFS_PARM0] = playercolor;
901 pr_global_struct->self = EDICT_TO_PROG(sv_player);
902 PR_ExecuteProgram (SV_ChangeTeam, "");
909 if ((val = GETEDICTFIELDVALUE(sv_player, eval_clientcolors)))
910 val->_float = playercolor;
911 sv_player->v->team = bottom + 1;
913 host_client->colors = playercolor;
914 host_client->old_colors = playercolor;
916 // send notification to all clients
917 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
918 MSG_WriteByte (&sv.reliable_datagram, host_client->number);
919 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
928 void Host_Kill_f (void)
930 if (cmd_source == src_command)
932 Cmd_ForwardToServer ();
936 if (!sv_player || sv_player->v->health <= 0)
938 SV_ClientPrintf ("Can't suicide -- already dead!\n");
942 pr_global_struct->time = sv.time;
943 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
944 PR_ExecuteProgram (pr_global_struct->ClientKill, "QC function ClientKill is missing");
953 void Host_Pause_f (void)
956 if (cmd_source == src_command)
958 Cmd_ForwardToServer ();
961 if (!pausable.integer)
962 SV_ClientPrintf ("Pause not allowed.\n");
966 SV_BroadcastPrintf ("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
967 // send notification to all clients
968 MSG_WriteByte (&sv.reliable_datagram, svc_setpause);
969 MSG_WriteByte (&sv.reliable_datagram, sv.paused);
974 ======================
976 LordHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
977 ======================
979 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0"};
980 static void Host_PModel_f (void)
985 if (Cmd_Argc () == 1)
987 Con_Printf ("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
990 i = atoi(Cmd_Argv(1));
992 if (cmd_source == src_command)
994 if (cl_pmodel.integer == i)
996 Cvar_SetValue ("_cl_pmodel", i);
997 if (cls.state == ca_connected)
998 Cmd_ForwardToServer ();
1002 host_client->pmodel = i;
1003 if (sv_player && (val = GETEDICTFIELDVALUE(sv_player, eval_pmodel)))
1007 //===========================================================================
1015 void Host_PreSpawn_f (void)
1017 if (cmd_source == src_command)
1019 Con_Printf ("prespawn is not valid from the console\n");
1023 if (host_client->spawned)
1025 Con_Printf ("prespawn not valid -- already spawned\n");
1029 SZ_Write (&host_client->message, sv.signon.data, sv.signon.cursize);
1030 MSG_WriteByte (&host_client->message, svc_signonnum);
1031 MSG_WriteByte (&host_client->message, 2);
1032 host_client->sendsignon = true;
1040 void Host_Spawn_f (void)
1047 if (cmd_source == src_command)
1049 Con_Printf("spawn is not valid from the console\n");
1053 if (host_client->spawned)
1055 Con_Printf("Spawn not valid -- already spawned\n");
1061 Con_Printf("Host_Spawn: no edict??\n");
1065 // LordHavoc: moved this above the QC calls at FrikaC's request
1066 // send all current names, colors, and frag counts
1067 SZ_Clear (&host_client->message);
1069 // run the entrance script
1072 // loaded games are fully initialized already
1073 // if this is the last client to be connected, unpause
1076 if ((f = ED_FindFunction ("RestoreGame")))
1077 if ((RestoreGame = (func_t)(f - pr_functions)))
1079 Con_DPrintf("Calling RestoreGame\n");
1080 pr_global_struct->time = sv.time;
1081 pr_global_struct->self = EDICT_TO_PROG(sv_player);
1082 PR_ExecuteProgram (RestoreGame, "");
1088 ED_ClearEdict(sv_player);
1090 //Con_Printf("Host_Spawn_f: host_client->edict->netname = %s, sv_player->netname = %s, host_client->name = %s\n", PR_GetString(host_client->edict->v->netname), PR_GetString(sv_player->v->netname), host_client->name);
1092 // copy spawn parms out of the client_t
1093 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1094 (&pr_global_struct->parm1)[i] = host_client->spawn_parms[i];
1096 // call the spawn function
1097 pr_global_struct->time = sv.time;
1098 pr_global_struct->self = EDICT_TO_PROG(sv_player);
1099 PR_ExecuteProgram (pr_global_struct->ClientConnect, "QC function ClientConnect is missing");
1101 if ((Sys_DoubleTime() - host_client->netconnection->connecttime) <= sv.time)
1102 Sys_Printf ("%s entered the game\n", host_client->name);
1104 PR_ExecuteProgram (pr_global_struct->PutClientInServer, "QC function PutClientInServer is missing");
1108 // send time of update
1109 MSG_WriteByte (&host_client->message, svc_time);
1110 MSG_WriteFloat (&host_client->message, sv.time);
1112 for (i = 0;i < MAX_SCOREBOARD;i++)
1114 if (!(client = svs.connectedclients[i]))
1116 MSG_WriteByte (&host_client->message, svc_updatename);
1117 MSG_WriteByte (&host_client->message, i);
1118 MSG_WriteString (&host_client->message, client->old_name);
1119 MSG_WriteByte (&host_client->message, svc_updatefrags);
1120 MSG_WriteByte (&host_client->message, i);
1121 MSG_WriteShort (&host_client->message, client->old_frags);
1122 MSG_WriteByte (&host_client->message, svc_updatecolors);
1123 MSG_WriteByte (&host_client->message, i);
1124 MSG_WriteByte (&host_client->message, client->old_colors);
1127 // send all current light styles
1128 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1130 MSG_WriteByte (&host_client->message, svc_lightstyle);
1131 MSG_WriteByte (&host_client->message, (char)i);
1132 MSG_WriteString (&host_client->message, sv.lightstyles[i]);
1136 MSG_WriteByte (&host_client->message, svc_updatestat);
1137 MSG_WriteByte (&host_client->message, STAT_TOTALSECRETS);
1138 MSG_WriteLong (&host_client->message, pr_global_struct->total_secrets);
1140 MSG_WriteByte (&host_client->message, svc_updatestat);
1141 MSG_WriteByte (&host_client->message, STAT_TOTALMONSTERS);
1142 MSG_WriteLong (&host_client->message, pr_global_struct->total_monsters);
1144 MSG_WriteByte (&host_client->message, svc_updatestat);
1145 MSG_WriteByte (&host_client->message, STAT_SECRETS);
1146 MSG_WriteLong (&host_client->message, pr_global_struct->found_secrets);
1148 MSG_WriteByte (&host_client->message, svc_updatestat);
1149 MSG_WriteByte (&host_client->message, STAT_MONSTERS);
1150 MSG_WriteLong (&host_client->message, pr_global_struct->killed_monsters);
1153 // Never send a roll angle, because savegames can catch the server
1154 // in a state where it is expecting the client to correct the angle
1155 // and it won't happen if the game was just loaded, so you wind up
1156 // with a permanent head tilt
1157 MSG_WriteByte (&host_client->message, svc_setangle);
1158 for (i=0 ; i < 2 ; i++)
1159 MSG_WriteAngle (&host_client->message, sv_player->v->angles[i] );
1160 MSG_WriteAngle (&host_client->message, 0 );
1162 SV_WriteClientdataToMessage (sv_player, &host_client->message);
1164 MSG_WriteByte (&host_client->message, svc_signonnum);
1165 MSG_WriteByte (&host_client->message, 3);
1166 host_client->sendsignon = true;
1174 void Host_Begin_f (void)
1176 if (cmd_source == src_command)
1178 Con_Printf ("begin is not valid from the console\n");
1182 host_client->spawned = true;
1185 //===========================================================================
1192 Kicks a user off of the server
1195 void Host_Kick_f (void)
1198 const char *message = NULL;
1201 qboolean byNumber = false;
1203 if (cmd_source != src_command || !sv.active)
1208 if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1210 i = atof(Cmd_Argv(2)) - 1;
1211 if (i < 0 || i >= MAX_SCOREBOARD || !(host_client = svs.connectedclients[i]))
1217 for (i = 0;i < MAX_SCOREBOARD;i++)
1219 if (!(host_client = svs.connectedclients[i]))
1221 if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1226 if (i < MAX_SCOREBOARD)
1228 if (cmd_source == src_command)
1230 if (cls.state == ca_dedicated)
1233 who = cl_name.string;
1238 // can't kick yourself!
1239 if (host_client == save)
1244 message = Cmd_Args();
1245 COM_ParseToken(&message, false);
1248 message++; // skip the #
1249 while (*message == ' ') // skip white space
1251 message += strlen(Cmd_Argv(2)); // skip the number
1253 while (*message && *message == ' ')
1257 SV_ClientPrintf ("Kicked by %s: %s\n", who, message);
1259 SV_ClientPrintf ("Kicked by %s\n", who);
1260 SV_DropClient (false); // kicked
1267 ===============================================================================
1271 ===============================================================================
1279 void Host_Give_f (void)
1285 if (cmd_source == src_command)
1287 Cmd_ForwardToServer ();
1296 SV_ClientPrintf("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
1301 v = atoi (Cmd_Argv(2));
1315 // MED 01/04/97 added hipnotic give stuff
1316 if (gamemode == GAME_HIPNOTIC)
1321 sv_player->v->items = (int)sv_player->v->items | HIT_PROXIMITY_GUN;
1323 sv_player->v->items = (int)sv_player->v->items | IT_GRENADE_LAUNCHER;
1325 else if (t[0] == '9')
1326 sv_player->v->items = (int)sv_player->v->items | HIT_LASER_CANNON;
1327 else if (t[0] == '0')
1328 sv_player->v->items = (int)sv_player->v->items | HIT_MJOLNIR;
1329 else if (t[0] >= '2')
1330 sv_player->v->items = (int)sv_player->v->items | (IT_SHOTGUN << (t[0] - '2'));
1335 sv_player->v->items = (int)sv_player->v->items | (IT_SHOTGUN << (t[0] - '2'));
1340 if (gamemode == GAME_ROGUE && (val = GETEDICTFIELDVALUE(sv_player, eval_ammo_shells1)))
1343 sv_player->v->ammo_shells = v;
1346 if (gamemode == GAME_ROGUE)
1348 if ((val = GETEDICTFIELDVALUE(sv_player, eval_ammo_nails1)))
1351 if (sv_player->v->weapon <= IT_LIGHTNING)
1352 sv_player->v->ammo_nails = v;
1357 sv_player->v->ammo_nails = v;
1361 if (gamemode == GAME_ROGUE)
1363 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_lava_nails);
1367 if (sv_player->v->weapon > IT_LIGHTNING)
1368 sv_player->v->ammo_nails = v;
1373 if (gamemode == GAME_ROGUE)
1375 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_rockets1);
1379 if (sv_player->v->weapon <= IT_LIGHTNING)
1380 sv_player->v->ammo_rockets = v;
1385 sv_player->v->ammo_rockets = v;
1389 if (gamemode == GAME_ROGUE)
1391 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_multi_rockets);
1395 if (sv_player->v->weapon > IT_LIGHTNING)
1396 sv_player->v->ammo_rockets = v;
1401 sv_player->v->health = v;
1404 if (gamemode == GAME_ROGUE)
1406 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_cells1);
1410 if (sv_player->v->weapon <= IT_LIGHTNING)
1411 sv_player->v->ammo_cells = v;
1416 sv_player->v->ammo_cells = v;
1420 if (gamemode == GAME_ROGUE)
1422 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_plasma);
1426 if (sv_player->v->weapon > IT_LIGHTNING)
1427 sv_player->v->ammo_cells = v;
1434 edict_t *FindViewthing (void)
1439 for (i=0 ; i<sv.num_edicts ; i++)
1442 if (!strcmp (PR_GetString(e->v->classname), "viewthing"))
1445 Con_Printf ("No viewthing on map\n");
1454 void Host_Viewmodel_f (void)
1459 e = FindViewthing ();
1463 m = Mod_ForName (Cmd_Argv(1), false, true, false);
1466 Con_Printf ("Can't load %s\n", Cmd_Argv(1));
1471 cl.model_precache[(int)e->v->modelindex] = m;
1479 void Host_Viewframe_f (void)
1485 e = FindViewthing ();
1488 m = cl.model_precache[(int)e->v->modelindex];
1490 f = atoi(Cmd_Argv(1));
1491 if (f >= m->numframes)
1498 void PrintFrameName (model_t *m, int frame)
1501 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1503 Con_Printf("frame %i\n", frame);
1511 void Host_Viewnext_f (void)
1516 e = FindViewthing ();
1519 m = cl.model_precache[(int)e->v->modelindex];
1521 e->v->frame = e->v->frame + 1;
1522 if (e->v->frame >= m->numframes)
1523 e->v->frame = m->numframes - 1;
1525 PrintFrameName (m, e->v->frame);
1533 void Host_Viewprev_f (void)
1538 e = FindViewthing ();
1542 m = cl.model_precache[(int)e->v->modelindex];
1544 e->v->frame = e->v->frame - 1;
1545 if (e->v->frame < 0)
1548 PrintFrameName (m, e->v->frame);
1552 ===============================================================================
1556 ===============================================================================
1565 void Host_Startdemos_f (void)
1569 if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
1571 if (!sv.active && !sv_spawnmap[0])
1573 if (gamemode == GAME_TRANSFUSION)
1574 Cbuf_AddText ("map bb1\n");
1576 Cbuf_AddText ("map start\n");
1584 Con_Printf ("Max %i demos in demoloop\n", MAX_DEMOS);
1587 Con_DPrintf ("%i demo(s) in loop\n", c);
1589 for (i=1 ; i<c+1 ; i++)
1590 strncpy (cls.demos[i-1], Cmd_Argv(i), sizeof(cls.demos[0])-1);
1592 // LordHavoc: clear the remaining slots
1593 for (;i <= MAX_DEMOS;i++)
1594 cls.demos[i-1][0] = 0;
1596 if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
1610 Return to looping demos
1613 void Host_Demos_f (void)
1615 if (cls.state == ca_dedicated)
1617 if (cls.demonum == -1)
1627 Return to looping demos
1630 void Host_Stopdemo_f (void)
1632 if (!cls.demoplayback)
1637 // LordHavoc: because we don't want to load things before the video starts,
1638 // we have to delay map and game loads until AFTER video is initialized
1639 void Host_PerformSpawnServerAndLoadGame(void)
1641 if (vid_hidden && cls.state != ca_dedicated)
1644 Host_PerformLoadGame(sv_loadgame);
1645 else if (sv_spawnmap[0])
1647 allowcheats = sv_cheats.integer != 0;
1648 SV_SpawnServer(sv_spawnmap);
1652 if (sv.active && cls.state == ca_disconnected)
1653 Cmd_ExecuteString ("connect local", src_command);
1656 //=============================================================================
1663 void Host_InitCommands (void)
1665 Cmd_AddCommand ("status", Host_Status_f);
1666 Cmd_AddCommand ("quit", Host_Quit_f);
1667 if (gamemode == GAME_NEHAHRA)
1669 Cmd_AddCommand ("max", Host_God_f);
1670 Cmd_AddCommand ("monster", Host_Notarget_f);
1671 Cmd_AddCommand ("scrag", Host_Fly_f);
1672 Cmd_AddCommand ("wraith", Host_Noclip_f);
1673 Cmd_AddCommand ("gimme", Host_Give_f);
1677 Cmd_AddCommand ("god", Host_God_f);
1678 Cmd_AddCommand ("notarget", Host_Notarget_f);
1679 Cmd_AddCommand ("fly", Host_Fly_f);
1680 Cmd_AddCommand ("noclip", Host_Noclip_f);
1681 Cmd_AddCommand ("give", Host_Give_f);
1683 Cmd_AddCommand ("map", Host_Map_f);
1684 Cmd_AddCommand ("restart", Host_Restart_f);
1685 Cmd_AddCommand ("changelevel", Host_Changelevel_f);
1686 Cmd_AddCommand ("connect", Host_Connect_f);
1687 Cmd_AddCommand ("reconnect", Host_Reconnect_f);
1688 Cmd_AddCommand ("version", Host_Version_f);
1689 Cmd_AddCommand ("say", Host_Say_f);
1690 Cmd_AddCommand ("say_team", Host_Say_Team_f);
1691 Cmd_AddCommand ("tell", Host_Tell_f);
1692 Cmd_AddCommand ("kill", Host_Kill_f);
1693 Cmd_AddCommand ("pause", Host_Pause_f);
1694 Cmd_AddCommand ("kick", Host_Kick_f);
1695 Cmd_AddCommand ("ping", Host_Ping_f);
1696 Cmd_AddCommand ("load", Host_Loadgame_f);
1697 Cmd_AddCommand ("save", Host_Savegame_f);
1699 Cmd_AddCommand ("startdemos", Host_Startdemos_f);
1700 Cmd_AddCommand ("demos", Host_Demos_f);
1701 Cmd_AddCommand ("stopdemo", Host_Stopdemo_f);
1703 Cmd_AddCommand ("viewmodel", Host_Viewmodel_f);
1704 Cmd_AddCommand ("viewframe", Host_Viewframe_f);
1705 Cmd_AddCommand ("viewnext", Host_Viewnext_f);
1706 Cmd_AddCommand ("viewprev", Host_Viewprev_f);
1708 Cvar_RegisterVariable (&cl_name);
1709 Cmd_AddCommand ("name", Host_Name_f);
1710 Cvar_RegisterVariable (&cl_color);
1711 Cmd_AddCommand ("color", Host_Color_f);
1712 if (gamemode == GAME_NEHAHRA)
1714 Cvar_RegisterVariable (&cl_pmodel);
1715 Cmd_AddCommand ("pmodel", Host_PModel_f);
1717 Cmd_AddCommand ("prespawn", Host_PreSpawn_f);
1718 Cmd_AddCommand ("spawn", Host_Spawn_f);
1719 Cmd_AddCommand ("begin", Host_Begin_f);
1721 Cvar_RegisterVariable(&sv_cheats);