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 mfunction_t *ED_FindFunction (char *name);
35 extern qboolean host_shuttingdown;
36 void Host_Quit_f (void)
38 host_shuttingdown = true;
40 Host_ShutdownServer(false);
51 void Host_Status_f (void)
54 int seconds, minutes, hours = 0, j, players;
55 void (*print) (const char *fmt, ...);
57 if (cmd_source == src_command)
61 Cmd_ForwardToServer ();
67 print = SV_ClientPrintf;
69 for (players = 0, j = 0;j < MAX_SCOREBOARD;j++)
70 if (svs.connectedclients[j])
72 print ("host: %s\n", Cvar_VariableString ("hostname"));
73 print ("version: %s build %s\n", gamename, buildstring);
74 print ("map: %s\n", sv.name);
75 print ("players: %i active (%i max)\n\n", players, min(sv_maxplayers.integer, MAX_SCOREBOARD));
76 for (j = 0;j < MAX_SCOREBOARD;j++)
78 if (!(client = svs.connectedclients[j]))
80 seconds = (int)(realtime - client->netconnection->connecttime);
81 minutes = seconds / 60;
84 seconds -= (minutes * 60);
87 minutes -= (hours * 60);
91 print ("#%-2u %-16.16s %3i %2i:%02i:%02i\n", j+1, client->name, (int)client->edict->v->frags, hours, minutes, seconds);
92 print (" %s\n", client->netconnection->address);
101 Sets client to godmode
104 void Host_God_f (void)
106 if (cmd_source == src_command)
108 Cmd_ForwardToServer ();
112 if (pr_global_struct->deathmatch || !sv_player)
115 sv_player->v->flags = (int)sv_player->v->flags ^ FL_GODMODE;
116 if (!((int)sv_player->v->flags & FL_GODMODE) )
117 SV_ClientPrintf ("godmode OFF\n");
119 SV_ClientPrintf ("godmode ON\n");
122 void Host_Notarget_f (void)
124 if (cmd_source == src_command)
126 Cmd_ForwardToServer ();
130 if (pr_global_struct->deathmatch || !sv_player)
133 sv_player->v->flags = (int)sv_player->v->flags ^ FL_NOTARGET;
134 if (!((int)sv_player->v->flags & FL_NOTARGET) )
135 SV_ClientPrintf ("notarget OFF\n");
137 SV_ClientPrintf ("notarget ON\n");
140 qboolean noclip_anglehack;
142 void Host_Noclip_f (void)
144 if (cmd_source == src_command)
146 Cmd_ForwardToServer ();
150 if (pr_global_struct->deathmatch || !sv_player)
153 if (sv_player->v->movetype != MOVETYPE_NOCLIP)
155 noclip_anglehack = true;
156 sv_player->v->movetype = MOVETYPE_NOCLIP;
157 SV_ClientPrintf ("noclip ON\n");
161 noclip_anglehack = false;
162 sv_player->v->movetype = MOVETYPE_WALK;
163 SV_ClientPrintf ("noclip OFF\n");
171 Sets client to flymode
174 void Host_Fly_f (void)
176 if (cmd_source == src_command)
178 Cmd_ForwardToServer ();
182 if (pr_global_struct->deathmatch || !sv_player)
185 if (sv_player->v->movetype != MOVETYPE_FLY)
187 sv_player->v->movetype = MOVETYPE_FLY;
188 SV_ClientPrintf ("flymode ON\n");
192 sv_player->v->movetype = MOVETYPE_WALK;
193 SV_ClientPrintf ("flymode OFF\n");
204 void Host_Ping_f (void)
210 if (cmd_source == src_command)
212 Cmd_ForwardToServer ();
216 SV_ClientPrintf ("Client ping times:\n");
217 for (i = 0;i < MAX_SCOREBOARD;i++)
219 if (!(client = svs.connectedclients[i]))
222 for (j=0 ; j<NUM_PING_TIMES ; j++)
223 total+=client->ping_times[j];
224 total /= NUM_PING_TIMES;
225 SV_ClientPrintf ("%4i %s\n", (int)(total*1000), client->name);
230 ===============================================================================
234 ===============================================================================
238 ======================
243 command from the console. Active clients are kicked off.
244 ======================
246 void Host_Map_f (void)
248 if (cmd_source != src_command)
251 cls.demonum = -1; // stop demo loop in case this fails
254 Host_ShutdownServer(false);
256 key_dest = key_game; // remove console or menu
257 SCR_BeginLoadingPlaque ();
260 svs.serverflags = 0; // haven't completed an episode yet
261 strcpy (sv_spawnmap, Cmd_Argv(1));
268 Goes to a new map, taking all clients along
271 void Host_Changelevel_f (void)
275 Con_Printf ("changelevel <levelname> : continue game on a new level\n");
278 if (!sv.active || cls.demoplayback)
280 Con_Printf ("Only the server may changelevel\n");
283 SV_SaveSpawnparms ();
284 strcpy (sv_spawnmap, Cmd_Argv(1));
291 Restarts the current server for a dead player
294 void Host_Restart_f (void)
296 if (cls.demoplayback || !sv.active)
299 if (cmd_source != src_command)
301 strcpy (sv_spawnmap, sv.name);
308 This command causes the client to wait for the signon messages again.
309 This is sent just before a server changes levels
312 void Host_Reconnect_f (void)
314 SCR_BeginLoadingPlaque();
315 cls.signon = 0; // need new connection messages
319 =====================
322 User command to connect to server
323 =====================
325 void Host_Connect_f (void)
327 CL_EstablishConnection(Cmd_Argv(1));
332 ===============================================================================
336 ===============================================================================
339 #define SAVEGAME_VERSION 5
345 Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
348 void Host_SavegameComment (char *text)
353 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
355 memcpy (text, cl.levelname, strlen(cl.levelname));
356 sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
357 memcpy (text+22, kills, strlen(kills));
358 // convert space to _ to make stdio happy
359 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
362 text[SAVEGAME_COMMENT_LENGTH] = '\0';
371 void Host_Savegame_f (void)
376 char comment[SAVEGAME_COMMENT_LENGTH+1];
378 if (cmd_source != src_command)
383 Con_Printf ("Not playing a local game.\n");
389 Con_Printf ("Can't save in intermission.\n");
393 for (i = 0;i < MAX_SCOREBOARD;i++)
395 if (svs.connectedclients[i])
399 Con_Printf("Can't save multiplayer games.\n");
402 if (svs.connectedclients[i]->edict->v->deadflag)
404 Con_Printf("Can't savegame with a dead player\n");
412 Con_Printf ("save <savename> : save a game\n");
416 if (strstr(Cmd_Argv(1), ".."))
418 Con_Printf ("Relative pathnames are not allowed.\n");
422 strncpy (name, Cmd_Argv(1), sizeof (name) - 1);
423 name[sizeof (name) - 1] = '\0';
424 FS_DefaultExtension (name, ".sav");
426 Con_Printf ("Saving game to %s...\n", name);
427 f = FS_Open (name, "w", false);
430 Con_Printf ("ERROR: couldn't open.\n");
434 FS_Printf (f, "%i\n", SAVEGAME_VERSION);
435 Host_SavegameComment (comment);
436 FS_Printf (f, "%s\n", comment);
437 for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
438 FS_Printf (f, "%f\n", svs.connectedclients[0]->spawn_parms[i]);
439 FS_Printf (f, "%d\n", current_skill);
440 FS_Printf (f, "%s\n", sv.name);
441 FS_Printf (f, "%f\n",sv.time);
443 // write the light styles
445 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
447 if (sv.lightstyles[i])
448 FS_Printf (f, "%s\n", sv.lightstyles[i]);
455 for (i=0 ; i<sv.num_edicts ; i++)
457 ED_Write (f, EDICT_NUM(i));
461 Con_Printf ("done.\n");
465 extern mempool_t *edictstring_mempool;
472 void Host_Loadgame_f (void)
474 if (cmd_source != src_command)
479 Con_Printf ("load <savename> : load a game\n");
483 strcpy (sv_loadgame, Cmd_Argv(1));
484 FS_DefaultExtension (sv_loadgame, ".sav");
486 Con_Printf ("Loading game from %s...\n", sv_loadgame);
489 void Host_PerformLoadGame(char *name)
492 char mapname[MAX_QPATH];
501 float spawn_parms[NUM_SPAWN_PARMS];
503 cls.demonum = -1; // stop demo loop in case this fails
505 f = FS_Open (name, "r", false);
508 Con_Printf ("ERROR: couldn't open.\n");
512 str = FS_Getline (f);
513 sscanf (str, "%i\n", &version);
514 if (version != SAVEGAME_VERSION)
517 Con_Printf ("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
521 SCR_BeginLoadingPlaque ();
523 str = FS_Getline (f);
524 for (i = 0;i < NUM_SPAWN_PARMS;i++)
526 str = FS_Getline (f);
527 sscanf (str, "%f\n", &spawn_parms[i]);
529 // this silliness is so we can load 1.06 save files, which have float skill values
530 str = FS_Getline (f);
531 sscanf (str, "%f\n", &tfloat);
532 current_skill = (int)(tfloat + 0.1);
533 Cvar_SetValue ("skill", (float)current_skill);
535 strcpy (mapname, FS_Getline (f));
537 str = FS_Getline (f);
538 sscanf (str, "%f\n",&time);
540 SV_SpawnServer (mapname);
543 Con_Printf ("Couldn't load map\n");
546 sv.paused = true; // pause until all clients connect
549 // load the light styles
551 for (i = 0;i < MAX_LIGHTSTYLES;i++)
553 str = FS_Getline (f);
554 sv.lightstyles[i] = Mem_Alloc(edictstring_mempool, strlen(str)+1);
555 strcpy (sv.lightstyles[i], str);
558 // load the edicts out of the savegame file
563 for (i = 0;i < (int)sizeof(buf) - 1;i++)
575 if (i == sizeof(buf)-1)
576 Host_Error ("Loadgame buffer overflow");
579 if (!COM_ParseToken(&start, false))
584 if (strcmp(com_token,"{"))
585 Host_Error ("First token isn't a brace");
589 // parse the global vars
590 ED_ParseGlobals (start);
595 if (entnum >= MAX_EDICTS)
596 Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)\n", MAX_EDICTS);
597 while (entnum >= sv.max_edicts)
599 ent = EDICT_NUM(entnum);
600 memset (ent->v, 0, progs->entityfields * 4);
601 ent->e->free = false;
602 ED_ParseEdict (start, ent);
604 // link it into the bsp tree
606 SV_LinkEdict (ent, false);
612 sv.num_edicts = entnum;
617 for (i = 0;i < NUM_SPAWN_PARMS;i++)
618 svs.connectedclients[0]->spawn_parms[i] = spawn_parms[i];
620 // make sure we're connected to loopback
621 if (cls.state == ca_disconnected || !(cls.state == ca_connected && cls.netcon != NULL && LHNETADDRESS_GetAddressType(&cls.netcon->peeraddress) == LHNETADDRESSTYPE_LOOP))
622 CL_EstablishConnection("local");
625 //============================================================================
628 ======================
630 ======================
632 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player"};
633 void Host_Name_f (void)
635 char newName[sizeof(host_client->name)];
637 if (Cmd_Argc () == 1)
639 Con_Printf ("\"name\" is \"%s\"\n", cl_name.string);
643 if (Cmd_Argc () == 2)
644 strncpy(newName, Cmd_Argv(1), sizeof(host_client->name) - 1);
646 strncpy(newName, Cmd_Args(), sizeof(host_client->name) - 1);
647 newName[sizeof(host_client->name) - 1] = 0;
649 if (cmd_source == src_command)
651 if (strcmp(cl_name.string, newName) == 0)
653 Cvar_Set ("_cl_name", newName);
654 if (cls.state == ca_connected)
655 Cmd_ForwardToServer ();
659 if (strcmp(host_client->name, newName) && host_client->name[0] && strcmp(host_client->name, "unconnected"))
660 SV_BroadcastPrintf("%s changed name to %s\n", host_client->name, newName);
661 strcpy(host_client->name, newName);
662 strcpy(host_client->old_name, newName);
664 sv_player->v->netname = PR_SetString(host_client->name);
665 //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);
667 // send notification to all clients
669 MSG_WriteByte(&sv.reliable_datagram, svc_updatename);
670 MSG_WriteByte(&sv.reliable_datagram, host_client->number);
671 MSG_WriteString(&sv.reliable_datagram, host_client->name);
675 void Host_Version_f (void)
677 Con_Printf ("Version: %s build %s\n", gamename, buildstring);
680 void Host_Say(qboolean teamonly)
685 // LordHavoc: 256 char say messages
686 unsigned char text[256];
687 qboolean fromServer = false;
689 if (cmd_source == src_command)
691 if (cls.state == ca_dedicated)
698 Cmd_ForwardToServer ();
708 // turn on color set 1
710 sprintf (text, "%c%s: ", 1, host_client->name);
712 sprintf (text, "%c<%s> ", 1, hostname.string);
715 p2 = p1 + strlen(p1);
716 // remove trailing newlines
717 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
719 // remove quotes if present
726 Con_Printf("Host_Say: missing end quote\n");
728 SV_ClientPrintf("Host_Say: missing end quote\n");
730 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
732 for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
737 for (j = 0;j < MAX_SCOREBOARD;j++)
738 if ((host_client = svs.connectedclients[j]) && host_client->spawned && (!teamplay.integer || host_client->edict->v->team == save->edict->v->team))
739 SV_ClientPrintf("%s", text);
742 Sys_Printf("%s", &text[1]);
746 void Host_Say_f(void)
752 void Host_Say_Team_f(void)
758 void Host_Tell_f(void)
763 char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
764 qboolean fromServer = false;
766 if (cmd_source == src_command)
768 if (cls.state == ca_dedicated)
772 Cmd_ForwardToServer ();
781 sprintf (text, "%s: ", host_client->name);
783 sprintf (text, "<%s> ", hostname.string);
786 p2 = p1 + strlen(p1);
787 // remove the target name
788 while (p1 < p2 && *p1 != ' ')
790 while (p1 < p2 && *p1 == ' ')
792 // remove trailing newlines
793 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
795 // remove quotes if present
802 Con_Printf("Host_Tell: missing end quote\n");
804 SV_ClientPrintf("Host_Tell: missing end quote\n");
806 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
808 for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
814 for (j = 0;j < MAX_SCOREBOARD;j++)
815 if ((host_client = svs.connectedclients[j]) && host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1)))
816 SV_ClientPrintf("%s", text);
826 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0"};
827 void Host_Color_f(void)
832 func_t SV_ChangeTeam;
836 Con_Printf ("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
837 Con_Printf ("color <0-15> [0-15]\n");
842 top = bottom = atoi(Cmd_Argv(1));
845 top = atoi(Cmd_Argv(1));
846 bottom = atoi(Cmd_Argv(2));
850 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
854 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
858 playercolor = top*16 + bottom;
860 if (cmd_source == src_command)
862 Cvar_SetValue ("_cl_color", playercolor);
863 if (cls.state == ca_connected)
864 Cmd_ForwardToServer ();
868 if (sv_player && (f = ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - pr_functions)))
870 Con_DPrintf("Calling SV_ChangeTeam\n");
871 pr_global_struct->time = sv.time;
872 pr_globals[OFS_PARM0] = playercolor;
873 pr_global_struct->self = EDICT_TO_PROG(sv_player);
874 PR_ExecuteProgram (SV_ChangeTeam, "");
881 if ((val = GETEDICTFIELDVALUE(sv_player, eval_clientcolors)))
882 val->_float = playercolor;
883 sv_player->v->team = bottom + 1;
885 host_client->colors = playercolor;
886 host_client->old_colors = playercolor;
888 // send notification to all clients
889 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
890 MSG_WriteByte (&sv.reliable_datagram, host_client->number);
891 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
900 void Host_Kill_f (void)
902 if (cmd_source == src_command)
904 Cmd_ForwardToServer ();
908 if (!sv_player || sv_player->v->health <= 0)
910 SV_ClientPrintf ("Can't suicide -- already dead!\n");
914 pr_global_struct->time = sv.time;
915 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
916 PR_ExecuteProgram (pr_global_struct->ClientKill, "QC function ClientKill is missing");
925 void Host_Pause_f (void)
928 if (cmd_source == src_command)
930 Cmd_ForwardToServer ();
933 if (!pausable.integer)
934 SV_ClientPrintf ("Pause not allowed.\n");
938 SV_BroadcastPrintf ("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
939 // send notification to all clients
940 MSG_WriteByte (&sv.reliable_datagram, svc_setpause);
941 MSG_WriteByte (&sv.reliable_datagram, sv.paused);
946 ======================
948 LordHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
949 ======================
951 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0"};
952 static void Host_PModel_f (void)
957 if (Cmd_Argc () == 1)
959 Con_Printf ("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
962 i = atoi(Cmd_Argv(1));
964 if (cmd_source == src_command)
966 if (cl_pmodel.integer == i)
968 Cvar_SetValue ("_cl_pmodel", i);
969 if (cls.state == ca_connected)
970 Cmd_ForwardToServer ();
974 host_client->pmodel = i;
975 if (sv_player && (val = GETEDICTFIELDVALUE(sv_player, eval_pmodel)))
979 //===========================================================================
987 void Host_PreSpawn_f (void)
989 if (cmd_source == src_command)
991 Con_Printf ("prespawn is not valid from the console\n");
995 if (host_client->spawned)
997 Con_Printf ("prespawn not valid -- already spawned\n");
1001 SZ_Write (&host_client->message, sv.signon.data, sv.signon.cursize);
1002 MSG_WriteByte (&host_client->message, svc_signonnum);
1003 MSG_WriteByte (&host_client->message, 2);
1004 host_client->sendsignon = true;
1012 void Host_Spawn_f (void)
1019 if (cmd_source == src_command)
1021 Con_Printf("spawn is not valid from the console\n");
1025 if (host_client->spawned)
1027 Con_Printf("Spawn not valid -- already spawned\n");
1033 Con_Printf("Host_Spawn: no edict??\n");
1037 // LordHavoc: moved this above the QC calls at FrikaC's request
1038 // send all current names, colors, and frag counts
1039 SZ_Clear (&host_client->message);
1041 // run the entrance script
1044 // loaded games are fully initialized already
1045 // if this is the last client to be connected, unpause
1048 if ((f = ED_FindFunction ("RestoreGame")))
1049 if ((RestoreGame = (func_t)(f - pr_functions)))
1051 Con_DPrintf("Calling RestoreGame\n");
1052 pr_global_struct->time = sv.time;
1053 pr_global_struct->self = EDICT_TO_PROG(sv_player);
1054 PR_ExecuteProgram (RestoreGame, "");
1060 ED_ClearEdict(sv_player);
1062 //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);
1064 // copy spawn parms out of the client_t
1065 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1066 (&pr_global_struct->parm1)[i] = host_client->spawn_parms[i];
1068 // call the spawn function
1069 pr_global_struct->time = sv.time;
1070 pr_global_struct->self = EDICT_TO_PROG(sv_player);
1071 PR_ExecuteProgram (pr_global_struct->ClientConnect, "QC function ClientConnect is missing");
1073 if ((Sys_DoubleTime() - host_client->netconnection->connecttime) <= sv.time)
1074 Sys_Printf ("%s entered the game\n", host_client->name);
1076 PR_ExecuteProgram (pr_global_struct->PutClientInServer, "QC function PutClientInServer is missing");
1080 // send time of update
1081 MSG_WriteByte (&host_client->message, svc_time);
1082 MSG_WriteFloat (&host_client->message, sv.time);
1084 for (i = 0;i < MAX_SCOREBOARD;i++)
1086 if (!(client = svs.connectedclients[i]))
1088 MSG_WriteByte (&host_client->message, svc_updatename);
1089 MSG_WriteByte (&host_client->message, i);
1090 MSG_WriteString (&host_client->message, client->old_name);
1091 MSG_WriteByte (&host_client->message, svc_updatefrags);
1092 MSG_WriteByte (&host_client->message, i);
1093 MSG_WriteShort (&host_client->message, client->old_frags);
1094 MSG_WriteByte (&host_client->message, svc_updatecolors);
1095 MSG_WriteByte (&host_client->message, i);
1096 MSG_WriteByte (&host_client->message, client->old_colors);
1099 // send all current light styles
1100 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1102 MSG_WriteByte (&host_client->message, svc_lightstyle);
1103 MSG_WriteByte (&host_client->message, (char)i);
1104 MSG_WriteString (&host_client->message, sv.lightstyles[i]);
1108 MSG_WriteByte (&host_client->message, svc_updatestat);
1109 MSG_WriteByte (&host_client->message, STAT_TOTALSECRETS);
1110 MSG_WriteLong (&host_client->message, pr_global_struct->total_secrets);
1112 MSG_WriteByte (&host_client->message, svc_updatestat);
1113 MSG_WriteByte (&host_client->message, STAT_TOTALMONSTERS);
1114 MSG_WriteLong (&host_client->message, pr_global_struct->total_monsters);
1116 MSG_WriteByte (&host_client->message, svc_updatestat);
1117 MSG_WriteByte (&host_client->message, STAT_SECRETS);
1118 MSG_WriteLong (&host_client->message, pr_global_struct->found_secrets);
1120 MSG_WriteByte (&host_client->message, svc_updatestat);
1121 MSG_WriteByte (&host_client->message, STAT_MONSTERS);
1122 MSG_WriteLong (&host_client->message, pr_global_struct->killed_monsters);
1125 // Never send a roll angle, because savegames can catch the server
1126 // in a state where it is expecting the client to correct the angle
1127 // and it won't happen if the game was just loaded, so you wind up
1128 // with a permanent head tilt
1129 MSG_WriteByte (&host_client->message, svc_setangle);
1130 for (i=0 ; i < 2 ; i++)
1131 MSG_WriteAngle (&host_client->message, sv_player->v->angles[i] );
1132 MSG_WriteAngle (&host_client->message, 0 );
1134 SV_WriteClientdataToMessage (sv_player, &host_client->message);
1136 MSG_WriteByte (&host_client->message, svc_signonnum);
1137 MSG_WriteByte (&host_client->message, 3);
1138 host_client->sendsignon = true;
1146 void Host_Begin_f (void)
1148 if (cmd_source == src_command)
1150 Con_Printf ("begin is not valid from the console\n");
1154 host_client->spawned = true;
1157 //===========================================================================
1164 Kicks a user off of the server
1167 void Host_Kick_f (void)
1170 const char *message = NULL;
1173 qboolean byNumber = false;
1175 if (cmd_source == src_command)
1179 Cmd_ForwardToServer ();
1183 else if (pr_global_struct->deathmatch)
1188 if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1190 i = atof(Cmd_Argv(2)) - 1;
1191 if (i < 0 || i >= MAX_SCOREBOARD || !(host_client = svs.connectedclients[i]))
1197 for (i = 0;i < MAX_SCOREBOARD;i++)
1199 if (!(host_client = svs.connectedclients[i]))
1201 if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1206 if (i < MAX_SCOREBOARD)
1208 if (cmd_source == src_command)
1210 if (cls.state == ca_dedicated)
1213 who = cl_name.string;
1218 // can't kick yourself!
1219 if (host_client == save)
1224 message = Cmd_Args();
1225 COM_ParseToken(&message, false);
1228 message++; // skip the #
1229 while (*message == ' ') // skip white space
1231 message += strlen(Cmd_Argv(2)); // skip the number
1233 while (*message && *message == ' ')
1237 SV_ClientPrintf ("Kicked by %s: %s\n", who, message);
1239 SV_ClientPrintf ("Kicked by %s\n", who);
1240 SV_DropClient (false); // kicked
1247 ===============================================================================
1251 ===============================================================================
1259 void Host_Give_f (void)
1265 if (cmd_source == src_command)
1267 Cmd_ForwardToServer ();
1271 if (pr_global_struct->deathmatch || !sv_player)
1275 v = atoi (Cmd_Argv(2));
1289 // MED 01/04/97 added hipnotic give stuff
1290 if (gamemode == GAME_HIPNOTIC)
1295 sv_player->v->items = (int)sv_player->v->items | HIT_PROXIMITY_GUN;
1297 sv_player->v->items = (int)sv_player->v->items | IT_GRENADE_LAUNCHER;
1299 else if (t[0] == '9')
1300 sv_player->v->items = (int)sv_player->v->items | HIT_LASER_CANNON;
1301 else if (t[0] == '0')
1302 sv_player->v->items = (int)sv_player->v->items | HIT_MJOLNIR;
1303 else if (t[0] >= '2')
1304 sv_player->v->items = (int)sv_player->v->items | (IT_SHOTGUN << (t[0] - '2'));
1309 sv_player->v->items = (int)sv_player->v->items | (IT_SHOTGUN << (t[0] - '2'));
1314 if (gamemode == GAME_ROGUE && (val = GETEDICTFIELDVALUE(sv_player, eval_ammo_shells1)))
1317 sv_player->v->ammo_shells = v;
1320 if (gamemode == GAME_ROGUE)
1322 if ((val = GETEDICTFIELDVALUE(sv_player, eval_ammo_nails1)))
1325 if (sv_player->v->weapon <= IT_LIGHTNING)
1326 sv_player->v->ammo_nails = v;
1331 sv_player->v->ammo_nails = v;
1335 if (gamemode == GAME_ROGUE)
1337 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_lava_nails);
1341 if (sv_player->v->weapon > IT_LIGHTNING)
1342 sv_player->v->ammo_nails = v;
1347 if (gamemode == GAME_ROGUE)
1349 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_rockets1);
1353 if (sv_player->v->weapon <= IT_LIGHTNING)
1354 sv_player->v->ammo_rockets = v;
1359 sv_player->v->ammo_rockets = v;
1363 if (gamemode == GAME_ROGUE)
1365 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_multi_rockets);
1369 if (sv_player->v->weapon > IT_LIGHTNING)
1370 sv_player->v->ammo_rockets = v;
1375 sv_player->v->health = v;
1378 if (gamemode == GAME_ROGUE)
1380 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_cells1);
1384 if (sv_player->v->weapon <= IT_LIGHTNING)
1385 sv_player->v->ammo_cells = v;
1390 sv_player->v->ammo_cells = v;
1394 if (gamemode == GAME_ROGUE)
1396 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_plasma);
1400 if (sv_player->v->weapon > IT_LIGHTNING)
1401 sv_player->v->ammo_cells = v;
1408 edict_t *FindViewthing (void)
1413 for (i=0 ; i<sv.num_edicts ; i++)
1416 if (!strcmp (PR_GetString(e->v->classname), "viewthing"))
1419 Con_Printf ("No viewthing on map\n");
1428 void Host_Viewmodel_f (void)
1433 e = FindViewthing ();
1437 m = Mod_ForName (Cmd_Argv(1), false, true, false);
1440 Con_Printf ("Can't load %s\n", Cmd_Argv(1));
1445 cl.model_precache[(int)e->v->modelindex] = m;
1453 void Host_Viewframe_f (void)
1459 e = FindViewthing ();
1462 m = cl.model_precache[(int)e->v->modelindex];
1464 f = atoi(Cmd_Argv(1));
1465 if (f >= m->numframes)
1472 void PrintFrameName (model_t *m, int frame)
1475 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1477 Con_Printf("frame %i\n", frame);
1485 void Host_Viewnext_f (void)
1490 e = FindViewthing ();
1493 m = cl.model_precache[(int)e->v->modelindex];
1495 e->v->frame = e->v->frame + 1;
1496 if (e->v->frame >= m->numframes)
1497 e->v->frame = m->numframes - 1;
1499 PrintFrameName (m, e->v->frame);
1507 void Host_Viewprev_f (void)
1512 e = FindViewthing ();
1516 m = cl.model_precache[(int)e->v->modelindex];
1518 e->v->frame = e->v->frame - 1;
1519 if (e->v->frame < 0)
1522 PrintFrameName (m, e->v->frame);
1526 ===============================================================================
1530 ===============================================================================
1539 void Host_Startdemos_f (void)
1543 if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
1545 if (!sv.active && !sv_spawnmap[0])
1547 if (gamemode == GAME_TRANSFUSION)
1548 Cbuf_AddText ("map bb1\n");
1550 Cbuf_AddText ("map start\n");
1558 Con_Printf ("Max %i demos in demoloop\n", MAX_DEMOS);
1561 Con_DPrintf ("%i demo(s) in loop\n", c);
1563 for (i=1 ; i<c+1 ; i++)
1564 strncpy (cls.demos[i-1], Cmd_Argv(i), sizeof(cls.demos[0])-1);
1566 // LordHavoc: clear the remaining slots
1567 for (;i <= MAX_DEMOS;i++)
1568 cls.demos[i-1][0] = 0;
1570 if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
1584 Return to looping demos
1587 void Host_Demos_f (void)
1589 if (cls.state == ca_dedicated)
1591 if (cls.demonum == -1)
1601 Return to looping demos
1604 void Host_Stopdemo_f (void)
1606 if (!cls.demoplayback)
1611 // LordHavoc: because we don't want to load things before the video starts,
1612 // we have to delay map and game loads until AFTER video is initialized
1613 void Host_PerformSpawnServerAndLoadGame(void)
1615 if (vid_hidden && cls.state != ca_dedicated)
1618 Host_PerformLoadGame(sv_loadgame);
1619 else if (sv_spawnmap[0])
1620 SV_SpawnServer(sv_spawnmap);
1623 if (sv.active && cls.state == ca_disconnected)
1624 Cmd_ExecuteString ("connect local", src_command);
1627 //=============================================================================
1634 void Host_InitCommands (void)
1636 Cmd_AddCommand ("status", Host_Status_f);
1637 Cmd_AddCommand ("quit", Host_Quit_f);
1638 if (gamemode == GAME_NEHAHRA)
1640 Cmd_AddCommand ("max", Host_God_f);
1641 Cmd_AddCommand ("monster", Host_Notarget_f);
1642 Cmd_AddCommand ("scrag", Host_Fly_f);
1643 Cmd_AddCommand ("wraith", Host_Noclip_f);
1644 Cmd_AddCommand ("gimme", Host_Give_f);
1648 Cmd_AddCommand ("god", Host_God_f);
1649 Cmd_AddCommand ("notarget", Host_Notarget_f);
1650 Cmd_AddCommand ("fly", Host_Fly_f);
1651 Cmd_AddCommand ("noclip", Host_Noclip_f);
1652 Cmd_AddCommand ("give", Host_Give_f);
1654 Cmd_AddCommand ("map", Host_Map_f);
1655 Cmd_AddCommand ("restart", Host_Restart_f);
1656 Cmd_AddCommand ("changelevel", Host_Changelevel_f);
1657 Cmd_AddCommand ("connect", Host_Connect_f);
1658 Cmd_AddCommand ("reconnect", Host_Reconnect_f);
1659 Cmd_AddCommand ("version", Host_Version_f);
1660 Cmd_AddCommand ("say", Host_Say_f);
1661 Cmd_AddCommand ("say_team", Host_Say_Team_f);
1662 Cmd_AddCommand ("tell", Host_Tell_f);
1663 Cmd_AddCommand ("kill", Host_Kill_f);
1664 Cmd_AddCommand ("pause", Host_Pause_f);
1665 Cmd_AddCommand ("kick", Host_Kick_f);
1666 Cmd_AddCommand ("ping", Host_Ping_f);
1667 Cmd_AddCommand ("load", Host_Loadgame_f);
1668 Cmd_AddCommand ("save", Host_Savegame_f);
1670 Cmd_AddCommand ("startdemos", Host_Startdemos_f);
1671 Cmd_AddCommand ("demos", Host_Demos_f);
1672 Cmd_AddCommand ("stopdemo", Host_Stopdemo_f);
1674 Cmd_AddCommand ("viewmodel", Host_Viewmodel_f);
1675 Cmd_AddCommand ("viewframe", Host_Viewframe_f);
1676 Cmd_AddCommand ("viewnext", Host_Viewnext_f);
1677 Cmd_AddCommand ("viewprev", Host_Viewprev_f);
1679 Cvar_RegisterVariable (&cl_name);
1680 Cmd_AddCommand ("name", Host_Name_f);
1681 Cvar_RegisterVariable (&cl_color);
1682 Cmd_AddCommand ("color", Host_Color_f);
1683 if (gamemode == GAME_NEHAHRA)
1685 Cvar_RegisterVariable (&cl_pmodel);
1686 Cmd_AddCommand ("pmodel", Host_PModel_f);
1688 Cmd_AddCommand ("prespawn", Host_PreSpawn_f);
1689 Cmd_AddCommand ("spawn", Host_Spawn_f);
1690 Cmd_AddCommand ("begin", Host_Begin_f);