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 < svs.maxclients;j++)
73 if (svs.clients[j].active)
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, svs.maxclients);
79 for (j = 0, client = svs.clients;j < svs.maxclients;j++, client++)
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, client = svs.clients;i < svs.maxclients;i++, client++)
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));
289 if (host_initialized)
290 Host_PerformSpawnServerAndLoadGame();
297 Goes to a new map, taking all clients along
300 void Host_Changelevel_f (void)
304 Con_Printf ("changelevel <levelname> : continue game on a new level\n");
307 if (!sv.active || cls.demoplayback)
309 Con_Printf ("Only the server may changelevel\n");
312 SV_SaveSpawnparms ();
313 strcpy (sv_spawnmap, Cmd_Argv(1));
314 if (host_initialized)
315 Host_PerformSpawnServerAndLoadGame();
322 Restarts the current server for a dead player
325 void Host_Restart_f (void)
327 if (cls.demoplayback || !sv.active)
330 if (cmd_source != src_command)
332 strcpy (sv_spawnmap, sv.name);
333 if (host_initialized)
334 Host_PerformSpawnServerAndLoadGame();
341 This command causes the client to wait for the signon messages again.
342 This is sent just before a server changes levels
345 void Host_Reconnect_f (void)
347 SCR_BeginLoadingPlaque();
348 cls.signon = 0; // need new connection messages
352 =====================
355 User command to connect to server
356 =====================
358 void Host_Connect_f (void)
360 CL_EstablishConnection(Cmd_Argv(1));
365 ===============================================================================
369 ===============================================================================
372 #define SAVEGAME_VERSION 5
378 Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
381 void Host_SavegameComment (char *text)
386 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
388 memcpy (text, cl.levelname, strlen(cl.levelname));
389 sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
390 memcpy (text+22, kills, strlen(kills));
391 // convert space to _ to make stdio happy
392 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
395 text[SAVEGAME_COMMENT_LENGTH] = '\0';
404 void Host_Savegame_f (void)
409 char comment[SAVEGAME_COMMENT_LENGTH+1];
411 if (cmd_source != src_command)
414 if (cls.state != ca_connected || !sv.active)
416 Con_Printf ("Not playing a local game.\n");
422 Con_Printf ("Can't save in intermission.\n");
426 for (i = 0;i < svs.maxclients;i++)
428 if (svs.clients[i].active)
432 Con_Printf("Can't save multiplayer games.\n");
435 if (svs.clients[i].edict->v->deadflag)
437 Con_Printf("Can't savegame with a dead player\n");
445 Con_Printf ("save <savename> : save a game\n");
449 if (strstr(Cmd_Argv(1), ".."))
451 Con_Printf ("Relative pathnames are not allowed.\n");
455 strlcpy (name, Cmd_Argv(1), sizeof (name));
456 FS_DefaultExtension (name, ".sav", sizeof (name));
458 Con_Printf ("Saving game to %s...\n", name);
459 f = FS_Open (name, "w", false);
462 Con_Printf ("ERROR: couldn't open.\n");
466 FS_Printf (f, "%i\n", SAVEGAME_VERSION);
467 Host_SavegameComment (comment);
468 FS_Printf (f, "%s\n", comment);
469 for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
470 FS_Printf (f, "%f\n", svs.clients[0].spawn_parms[i]);
471 FS_Printf (f, "%d\n", current_skill);
472 FS_Printf (f, "%s\n", sv.name);
473 FS_Printf (f, "%f\n",sv.time);
475 // write the light styles
477 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
479 if (sv.lightstyles[i])
480 FS_Printf (f, "%s\n", sv.lightstyles[i]);
487 for (i=0 ; i<sv.num_edicts ; i++)
489 ED_Write (f, EDICT_NUM(i));
493 Con_Printf ("done.\n");
497 extern mempool_t *edictstring_mempool;
504 void Host_Loadgame_f (void)
506 if (cmd_source != src_command)
511 Con_Printf ("load <savename> : load a game\n");
515 strcpy (sv_loadgame, Cmd_Argv(1));
516 FS_DefaultExtension (sv_loadgame, ".sav", sizeof (sv_loadgame));
518 Con_Printf ("Loading game from %s...\n", sv_loadgame);
521 void Host_PerformLoadGame(char *name)
524 char mapname[MAX_QPATH];
533 float spawn_parms[NUM_SPAWN_PARMS];
535 cls.demonum = -1; // stop demo loop in case this fails
537 f = FS_Open (name, "r", false);
540 Con_Printf ("ERROR: couldn't open.\n");
544 str = FS_Getline (f);
545 sscanf (str, "%i\n", &version);
546 if (version != SAVEGAME_VERSION)
549 Con_Printf ("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
553 SCR_BeginLoadingPlaque ();
555 str = FS_Getline (f);
556 for (i = 0;i < NUM_SPAWN_PARMS;i++)
558 str = FS_Getline (f);
559 sscanf (str, "%f\n", &spawn_parms[i]);
561 // this silliness is so we can load 1.06 save files, which have float skill values
562 str = FS_Getline (f);
563 sscanf (str, "%f\n", &tfloat);
564 current_skill = (int)(tfloat + 0.1);
565 Cvar_SetValue ("skill", (float)current_skill);
567 strcpy (mapname, FS_Getline (f));
569 str = FS_Getline (f);
570 sscanf (str, "%f\n",&time);
572 allowcheats = sv_cheats.integer != 0;
573 SV_SpawnServer (mapname);
576 Con_Printf ("Couldn't load map\n");
579 sv.paused = true; // pause until all clients connect
582 // load the light styles
584 for (i = 0;i < MAX_LIGHTSTYLES;i++)
586 str = FS_Getline (f);
587 sv.lightstyles[i] = Mem_Alloc(edictstring_mempool, strlen(str)+1);
588 strcpy (sv.lightstyles[i], str);
591 // load the edicts out of the savegame file
596 for (i = 0;i < (int)sizeof(buf) - 1;i++)
608 if (i == sizeof(buf)-1)
609 Host_Error ("Loadgame buffer overflow");
612 if (!COM_ParseToken(&start, false))
617 if (strcmp(com_token,"{"))
618 Host_Error ("First token isn't a brace");
622 // parse the global vars
623 ED_ParseGlobals (start);
628 if (entnum >= MAX_EDICTS)
629 Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)\n", MAX_EDICTS);
630 while (entnum >= sv.max_edicts)
632 ent = EDICT_NUM(entnum);
633 memset (ent->v, 0, progs->entityfields * 4);
634 ent->e->free = false;
635 ED_ParseEdict (start, ent);
637 // link it into the bsp tree
639 SV_LinkEdict (ent, false);
645 sv.num_edicts = entnum;
650 for (i = 0;i < NUM_SPAWN_PARMS;i++)
651 svs.clients[0].spawn_parms[i] = spawn_parms[i];
653 // make sure we're connected to loopback
654 if (cls.state == ca_disconnected || !(cls.state == ca_connected && cls.netcon != NULL && LHNETADDRESS_GetAddressType(&cls.netcon->peeraddress) == LHNETADDRESSTYPE_LOOP))
655 CL_EstablishConnection("local");
658 //============================================================================
661 ======================
663 ======================
665 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player"};
666 void Host_Name_f (void)
668 char newName[sizeof(host_client->name)];
670 if (Cmd_Argc () == 1)
672 Con_Printf ("\"name\" is \"%s\"\n", cl_name.string);
676 if (Cmd_Argc () == 2)
677 strlcpy (newName, Cmd_Argv(1), sizeof (newName));
679 strlcpy (newName, Cmd_Args(), sizeof (newName));
681 if (cmd_source == src_command)
683 if (strcmp(cl_name.string, newName) == 0)
685 Cvar_Set ("_cl_name", newName);
686 if (cls.state == ca_connected)
687 Cmd_ForwardToServer ();
691 if (strcmp(host_client->name, newName) && host_client->name[0] && strcmp(host_client->name, "unconnected"))
692 SV_BroadcastPrintf("%s changed name to %s\n", host_client->name, newName);
693 strcpy(host_client->name, newName);
694 strcpy(host_client->old_name, newName);
696 sv_player->v->netname = PR_SetString(host_client->name);
697 //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);
699 // send notification to all clients
701 MSG_WriteByte(&sv.reliable_datagram, svc_updatename);
702 MSG_WriteByte(&sv.reliable_datagram, host_client->number);
703 MSG_WriteString(&sv.reliable_datagram, host_client->name);
707 void Host_Version_f (void)
709 Con_Printf ("Version: %s build %s\n", gamename, buildstring);
712 void Host_Say(qboolean teamonly)
717 // LordHavoc: 256 char say messages
718 unsigned char text[256];
719 qboolean fromServer = false;
721 if (cmd_source == src_command)
723 if (cls.state == ca_dedicated)
730 Cmd_ForwardToServer ();
740 // turn on color set 1
742 sprintf (text, "%c%s: ", 1, host_client->name);
744 sprintf (text, "%c<%s> ", 1, hostname.string);
747 p2 = p1 + strlen(p1);
748 // remove trailing newlines
749 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
751 // remove quotes if present
758 Con_Printf("Host_Say: missing end quote\n");
760 SV_ClientPrintf("Host_Say: missing end quote\n");
762 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
764 for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
769 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
770 if (host_client->spawned && (!teamplay.integer || host_client->edict->v->team == save->edict->v->team))
771 SV_ClientPrintf("%s", text);
774 Sys_Printf("%s", &text[1]);
778 void Host_Say_f(void)
784 void Host_Say_Team_f(void)
790 void Host_Tell_f(void)
795 char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
796 qboolean fromServer = false;
798 if (cmd_source == src_command)
800 if (cls.state == ca_dedicated)
804 Cmd_ForwardToServer ();
813 sprintf (text, "%s: ", host_client->name);
815 sprintf (text, "<%s> ", hostname.string);
818 p2 = p1 + strlen(p1);
819 // remove the target name
820 while (p1 < p2 && *p1 != ' ')
822 while (p1 < p2 && *p1 == ' ')
824 // remove trailing newlines
825 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
827 // remove quotes if present
834 Con_Printf("Host_Tell: missing end quote\n");
836 SV_ClientPrintf("Host_Tell: missing end quote\n");
838 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
840 for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
846 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
847 if (host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1)))
848 SV_ClientPrintf("%s", text);
858 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0"};
859 void Host_Color_f(void)
864 func_t SV_ChangeTeam;
868 Con_Printf ("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
869 Con_Printf ("color <0-15> [0-15]\n");
874 top = bottom = atoi(Cmd_Argv(1));
877 top = atoi(Cmd_Argv(1));
878 bottom = atoi(Cmd_Argv(2));
882 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
886 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
890 playercolor = top*16 + bottom;
892 if (cmd_source == src_command)
894 Cvar_SetValue ("_cl_color", playercolor);
895 if (cls.state == ca_connected)
896 Cmd_ForwardToServer ();
900 if (sv_player && (f = ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - pr_functions)))
902 Con_DPrintf("Calling SV_ChangeTeam\n");
903 pr_global_struct->time = sv.time;
904 pr_globals[OFS_PARM0] = playercolor;
905 pr_global_struct->self = EDICT_TO_PROG(sv_player);
906 PR_ExecuteProgram (SV_ChangeTeam, "");
913 if ((val = GETEDICTFIELDVALUE(sv_player, eval_clientcolors)))
914 val->_float = playercolor;
915 sv_player->v->team = bottom + 1;
917 host_client->colors = playercolor;
918 host_client->old_colors = playercolor;
920 // send notification to all clients
921 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
922 MSG_WriteByte (&sv.reliable_datagram, host_client->number);
923 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
932 void Host_Kill_f (void)
934 if (cmd_source == src_command)
936 Cmd_ForwardToServer ();
940 if (!sv_player || sv_player->v->health <= 0)
942 SV_ClientPrintf ("Can't suicide -- already dead!\n");
946 pr_global_struct->time = sv.time;
947 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
948 PR_ExecuteProgram (pr_global_struct->ClientKill, "QC function ClientKill is missing");
957 void Host_Pause_f (void)
960 if (cmd_source == src_command)
962 Cmd_ForwardToServer ();
965 if (!pausable.integer)
966 SV_ClientPrintf ("Pause not allowed.\n");
970 SV_BroadcastPrintf ("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
971 // send notification to all clients
972 MSG_WriteByte (&sv.reliable_datagram, svc_setpause);
973 MSG_WriteByte (&sv.reliable_datagram, sv.paused);
978 ======================
980 LordHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
981 ======================
983 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0"};
984 static void Host_PModel_f (void)
989 if (Cmd_Argc () == 1)
991 Con_Printf ("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
994 i = atoi(Cmd_Argv(1));
996 if (cmd_source == src_command)
998 if (cl_pmodel.integer == i)
1000 Cvar_SetValue ("_cl_pmodel", i);
1001 if (cls.state == ca_connected)
1002 Cmd_ForwardToServer ();
1006 host_client->pmodel = i;
1007 if (sv_player && (val = GETEDICTFIELDVALUE(sv_player, eval_pmodel)))
1011 //===========================================================================
1019 void Host_PreSpawn_f (void)
1021 if (cmd_source == src_command)
1023 Con_Printf ("prespawn is not valid from the console\n");
1027 if (host_client->spawned)
1029 Con_Printf ("prespawn not valid -- already spawned\n");
1033 SZ_Write (&host_client->message, sv.signon.data, sv.signon.cursize);
1034 MSG_WriteByte (&host_client->message, svc_signonnum);
1035 MSG_WriteByte (&host_client->message, 2);
1036 host_client->sendsignon = true;
1044 void Host_Spawn_f (void)
1051 if (cmd_source == src_command)
1053 Con_Printf("spawn is not valid from the console\n");
1057 if (host_client->spawned)
1059 Con_Printf("Spawn not valid -- already spawned\n");
1065 Con_Printf("Host_Spawn: no edict??\n");
1069 // LordHavoc: moved this above the QC calls at FrikaC's request
1070 // send all current names, colors, and frag counts
1071 SZ_Clear (&host_client->message);
1073 // run the entrance script
1076 // loaded games are fully initialized already
1077 // if this is the last client to be connected, unpause
1080 if ((f = ED_FindFunction ("RestoreGame")))
1081 if ((RestoreGame = (func_t)(f - pr_functions)))
1083 Con_DPrintf("Calling RestoreGame\n");
1084 pr_global_struct->time = sv.time;
1085 pr_global_struct->self = EDICT_TO_PROG(sv_player);
1086 PR_ExecuteProgram (RestoreGame, "");
1092 ED_ClearEdict(sv_player);
1094 //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);
1096 // copy spawn parms out of the client_t
1097 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1098 (&pr_global_struct->parm1)[i] = host_client->spawn_parms[i];
1100 // call the spawn function
1101 pr_global_struct->time = sv.time;
1102 pr_global_struct->self = EDICT_TO_PROG(sv_player);
1103 PR_ExecuteProgram (pr_global_struct->ClientConnect, "QC function ClientConnect is missing");
1105 if ((Sys_DoubleTime() - host_client->netconnection->connecttime) <= sv.time)
1106 Sys_Printf ("%s entered the game\n", host_client->name);
1108 PR_ExecuteProgram (pr_global_struct->PutClientInServer, "QC function PutClientInServer is missing");
1112 // send time of update
1113 MSG_WriteByte (&host_client->message, svc_time);
1114 MSG_WriteFloat (&host_client->message, sv.time);
1116 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
1118 if (!client->active)
1120 MSG_WriteByte (&host_client->message, svc_updatename);
1121 MSG_WriteByte (&host_client->message, i);
1122 MSG_WriteString (&host_client->message, client->old_name);
1123 MSG_WriteByte (&host_client->message, svc_updatefrags);
1124 MSG_WriteByte (&host_client->message, i);
1125 MSG_WriteShort (&host_client->message, client->old_frags);
1126 MSG_WriteByte (&host_client->message, svc_updatecolors);
1127 MSG_WriteByte (&host_client->message, i);
1128 MSG_WriteByte (&host_client->message, client->old_colors);
1131 // send all current light styles
1132 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1134 MSG_WriteByte (&host_client->message, svc_lightstyle);
1135 MSG_WriteByte (&host_client->message, (char)i);
1136 MSG_WriteString (&host_client->message, sv.lightstyles[i]);
1140 MSG_WriteByte (&host_client->message, svc_updatestat);
1141 MSG_WriteByte (&host_client->message, STAT_TOTALSECRETS);
1142 MSG_WriteLong (&host_client->message, pr_global_struct->total_secrets);
1144 MSG_WriteByte (&host_client->message, svc_updatestat);
1145 MSG_WriteByte (&host_client->message, STAT_TOTALMONSTERS);
1146 MSG_WriteLong (&host_client->message, pr_global_struct->total_monsters);
1148 MSG_WriteByte (&host_client->message, svc_updatestat);
1149 MSG_WriteByte (&host_client->message, STAT_SECRETS);
1150 MSG_WriteLong (&host_client->message, pr_global_struct->found_secrets);
1152 MSG_WriteByte (&host_client->message, svc_updatestat);
1153 MSG_WriteByte (&host_client->message, STAT_MONSTERS);
1154 MSG_WriteLong (&host_client->message, pr_global_struct->killed_monsters);
1157 // Never send a roll angle, because savegames can catch the server
1158 // in a state where it is expecting the client to correct the angle
1159 // and it won't happen if the game was just loaded, so you wind up
1160 // with a permanent head tilt
1161 MSG_WriteByte (&host_client->message, svc_setangle);
1162 for (i=0 ; i < 2 ; i++)
1163 MSG_WriteAngle (&host_client->message, sv_player->v->angles[i] );
1164 MSG_WriteAngle (&host_client->message, 0 );
1166 SV_WriteClientdataToMessage (sv_player, &host_client->message);
1168 MSG_WriteByte (&host_client->message, svc_signonnum);
1169 MSG_WriteByte (&host_client->message, 3);
1170 host_client->sendsignon = true;
1178 void Host_Begin_f (void)
1180 if (cmd_source == src_command)
1182 Con_Printf ("begin is not valid from the console\n");
1186 host_client->spawned = true;
1189 //===========================================================================
1196 Kicks a user off of the server
1199 void Host_Kick_f (void)
1202 const char *message = NULL;
1205 qboolean byNumber = false;
1207 if (cmd_source != src_command || !sv.active)
1212 if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1214 i = atof(Cmd_Argv(2)) - 1;
1215 if (i < 0 || i >= svs.maxclients || !(host_client = svs.clients + i)->active)
1221 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1223 if (!host_client->active)
1225 if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1230 if (i < svs.maxclients)
1232 if (cmd_source == src_command)
1234 if (cls.state == ca_dedicated)
1237 who = cl_name.string;
1242 // can't kick yourself!
1243 if (host_client == save)
1248 message = Cmd_Args();
1249 COM_ParseToken(&message, false);
1252 message++; // skip the #
1253 while (*message == ' ') // skip white space
1255 message += strlen(Cmd_Argv(2)); // skip the number
1257 while (*message && *message == ' ')
1261 SV_ClientPrintf ("Kicked by %s: %s\n", who, message);
1263 SV_ClientPrintf ("Kicked by %s\n", who);
1264 SV_DropClient (false); // kicked
1271 ===============================================================================
1275 ===============================================================================
1283 void Host_Give_f (void)
1289 if (cmd_source == src_command)
1291 Cmd_ForwardToServer ();
1300 SV_ClientPrintf("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
1305 v = atoi (Cmd_Argv(2));
1319 // MED 01/04/97 added hipnotic give stuff
1320 if (gamemode == GAME_HIPNOTIC)
1325 sv_player->v->items = (int)sv_player->v->items | HIT_PROXIMITY_GUN;
1327 sv_player->v->items = (int)sv_player->v->items | IT_GRENADE_LAUNCHER;
1329 else if (t[0] == '9')
1330 sv_player->v->items = (int)sv_player->v->items | HIT_LASER_CANNON;
1331 else if (t[0] == '0')
1332 sv_player->v->items = (int)sv_player->v->items | HIT_MJOLNIR;
1333 else if (t[0] >= '2')
1334 sv_player->v->items = (int)sv_player->v->items | (IT_SHOTGUN << (t[0] - '2'));
1339 sv_player->v->items = (int)sv_player->v->items | (IT_SHOTGUN << (t[0] - '2'));
1344 if (gamemode == GAME_ROGUE && (val = GETEDICTFIELDVALUE(sv_player, eval_ammo_shells1)))
1347 sv_player->v->ammo_shells = v;
1350 if (gamemode == GAME_ROGUE)
1352 if ((val = GETEDICTFIELDVALUE(sv_player, eval_ammo_nails1)))
1355 if (sv_player->v->weapon <= IT_LIGHTNING)
1356 sv_player->v->ammo_nails = v;
1361 sv_player->v->ammo_nails = v;
1365 if (gamemode == GAME_ROGUE)
1367 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_lava_nails);
1371 if (sv_player->v->weapon > IT_LIGHTNING)
1372 sv_player->v->ammo_nails = v;
1377 if (gamemode == GAME_ROGUE)
1379 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_rockets1);
1383 if (sv_player->v->weapon <= IT_LIGHTNING)
1384 sv_player->v->ammo_rockets = v;
1389 sv_player->v->ammo_rockets = v;
1393 if (gamemode == GAME_ROGUE)
1395 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_multi_rockets);
1399 if (sv_player->v->weapon > IT_LIGHTNING)
1400 sv_player->v->ammo_rockets = v;
1405 sv_player->v->health = v;
1408 if (gamemode == GAME_ROGUE)
1410 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_cells1);
1414 if (sv_player->v->weapon <= IT_LIGHTNING)
1415 sv_player->v->ammo_cells = v;
1420 sv_player->v->ammo_cells = v;
1424 if (gamemode == GAME_ROGUE)
1426 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_plasma);
1430 if (sv_player->v->weapon > IT_LIGHTNING)
1431 sv_player->v->ammo_cells = v;
1438 edict_t *FindViewthing (void)
1443 for (i=0 ; i<sv.num_edicts ; i++)
1446 if (!strcmp (PR_GetString(e->v->classname), "viewthing"))
1449 Con_Printf ("No viewthing on map\n");
1458 void Host_Viewmodel_f (void)
1463 e = FindViewthing ();
1467 m = Mod_ForName (Cmd_Argv(1), false, true, false);
1470 Con_Printf ("Can't load %s\n", Cmd_Argv(1));
1475 cl.model_precache[(int)e->v->modelindex] = m;
1483 void Host_Viewframe_f (void)
1489 e = FindViewthing ();
1492 m = cl.model_precache[(int)e->v->modelindex];
1494 f = atoi(Cmd_Argv(1));
1495 if (f >= m->numframes)
1502 void PrintFrameName (model_t *m, int frame)
1505 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1507 Con_Printf("frame %i\n", frame);
1515 void Host_Viewnext_f (void)
1520 e = FindViewthing ();
1523 m = cl.model_precache[(int)e->v->modelindex];
1525 e->v->frame = e->v->frame + 1;
1526 if (e->v->frame >= m->numframes)
1527 e->v->frame = m->numframes - 1;
1529 PrintFrameName (m, e->v->frame);
1537 void Host_Viewprev_f (void)
1542 e = FindViewthing ();
1546 m = cl.model_precache[(int)e->v->modelindex];
1548 e->v->frame = e->v->frame - 1;
1549 if (e->v->frame < 0)
1552 PrintFrameName (m, e->v->frame);
1556 ===============================================================================
1560 ===============================================================================
1569 void Host_Startdemos_f (void)
1573 if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
1575 if (!sv.active && !sv_spawnmap[0])
1577 if (gamemode == GAME_TRANSFUSION)
1578 Cbuf_AddText ("map bb1\n");
1580 Cbuf_AddText ("map start\n");
1588 Con_Printf ("Max %i demos in demoloop\n", MAX_DEMOS);
1591 Con_DPrintf ("%i demo(s) in loop\n", c);
1593 for (i=1 ; i<c+1 ; i++)
1594 strlcpy (cls.demos[i-1], Cmd_Argv(i), sizeof (cls.demos[i-1]));
1596 // LordHavoc: clear the remaining slots
1597 for (;i <= MAX_DEMOS;i++)
1598 cls.demos[i-1][0] = 0;
1600 if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
1614 Return to looping demos
1617 void Host_Demos_f (void)
1619 if (cls.state == ca_dedicated)
1621 if (cls.demonum == -1)
1631 Return to looping demos
1634 void Host_Stopdemo_f (void)
1636 if (!cls.demoplayback)
1641 // LordHavoc: because we don't want to load things before the video starts,
1642 // we have to delay map and game loads until AFTER video is initialized
1643 void Host_PerformSpawnServerAndLoadGame(void)
1645 if (vid_hidden && cls.state != ca_dedicated)
1648 Host_PerformLoadGame(sv_loadgame);
1649 else if (sv_spawnmap[0])
1651 allowcheats = sv_cheats.integer != 0;
1652 SV_SpawnServer(sv_spawnmap);
1656 if (sv.active && cls.state == ca_disconnected)
1657 Cbuf_AddText ("connect local");
1660 static void MaxPlayers_f(void)
1664 if (Cmd_Argc() != 2)
1666 Con_Printf("\"maxplayers\" is \"%u\"\n", svs.maxclients);
1672 Con_Printf("maxplayers can not be changed while a server is running.\n");
1676 n = atoi(Cmd_Argv(1));
1677 n = bound(1, n, MAX_SCOREBOARD);
1678 Con_Printf ("\"maxplayers\" set to \"%u\"\n", n);
1681 Mem_Free(svs.clients);
1683 svs.clients = Mem_Alloc(sv_clients_mempool, sizeof(client_t) * svs.maxclients);
1685 Cvar_Set ("deathmatch", "0");
1687 Cvar_Set ("deathmatch", "1");
1690 //=============================================================================
1697 void Host_InitCommands (void)
1699 Cmd_AddCommand ("status", Host_Status_f);
1700 Cmd_AddCommand ("quit", Host_Quit_f);
1701 if (gamemode == GAME_NEHAHRA)
1703 Cmd_AddCommand ("max", Host_God_f);
1704 Cmd_AddCommand ("monster", Host_Notarget_f);
1705 Cmd_AddCommand ("scrag", Host_Fly_f);
1706 Cmd_AddCommand ("wraith", Host_Noclip_f);
1707 Cmd_AddCommand ("gimme", Host_Give_f);
1711 Cmd_AddCommand ("god", Host_God_f);
1712 Cmd_AddCommand ("notarget", Host_Notarget_f);
1713 Cmd_AddCommand ("fly", Host_Fly_f);
1714 Cmd_AddCommand ("noclip", Host_Noclip_f);
1715 Cmd_AddCommand ("give", Host_Give_f);
1717 Cmd_AddCommand ("map", Host_Map_f);
1718 Cmd_AddCommand ("restart", Host_Restart_f);
1719 Cmd_AddCommand ("changelevel", Host_Changelevel_f);
1720 Cmd_AddCommand ("connect", Host_Connect_f);
1721 Cmd_AddCommand ("reconnect", Host_Reconnect_f);
1722 Cmd_AddCommand ("version", Host_Version_f);
1723 Cmd_AddCommand ("say", Host_Say_f);
1724 Cmd_AddCommand ("say_team", Host_Say_Team_f);
1725 Cmd_AddCommand ("tell", Host_Tell_f);
1726 Cmd_AddCommand ("kill", Host_Kill_f);
1727 Cmd_AddCommand ("pause", Host_Pause_f);
1728 Cmd_AddCommand ("kick", Host_Kick_f);
1729 Cmd_AddCommand ("ping", Host_Ping_f);
1730 Cmd_AddCommand ("load", Host_Loadgame_f);
1731 Cmd_AddCommand ("save", Host_Savegame_f);
1733 Cmd_AddCommand ("startdemos", Host_Startdemos_f);
1734 Cmd_AddCommand ("demos", Host_Demos_f);
1735 Cmd_AddCommand ("stopdemo", Host_Stopdemo_f);
1737 Cmd_AddCommand ("viewmodel", Host_Viewmodel_f);
1738 Cmd_AddCommand ("viewframe", Host_Viewframe_f);
1739 Cmd_AddCommand ("viewnext", Host_Viewnext_f);
1740 Cmd_AddCommand ("viewprev", Host_Viewprev_f);
1742 Cvar_RegisterVariable (&cl_name);
1743 Cmd_AddCommand ("name", Host_Name_f);
1744 Cvar_RegisterVariable (&cl_color);
1745 Cmd_AddCommand ("color", Host_Color_f);
1746 if (gamemode == GAME_NEHAHRA)
1748 Cvar_RegisterVariable (&cl_pmodel);
1749 Cmd_AddCommand ("pmodel", Host_PModel_f);
1751 Cmd_AddCommand ("prespawn", Host_PreSpawn_f);
1752 Cmd_AddCommand ("spawn", Host_Spawn_f);
1753 Cmd_AddCommand ("begin", Host_Begin_f);
1754 Cmd_AddCommand ("maxplayers", MaxPlayers_f);
1756 Cvar_RegisterVariable(&sv_cheats);