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 strncpy (name, Cmd_Argv(1), sizeof (name) - 1);
456 name[sizeof (name) - 1] = '\0';
457 FS_DefaultExtension (name, ".sav");
459 Con_Printf ("Saving game to %s...\n", name);
460 f = FS_Open (name, "w", false);
463 Con_Printf ("ERROR: couldn't open.\n");
467 FS_Printf (f, "%i\n", SAVEGAME_VERSION);
468 Host_SavegameComment (comment);
469 FS_Printf (f, "%s\n", comment);
470 for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
471 FS_Printf (f, "%f\n", svs.clients[0].spawn_parms[i]);
472 FS_Printf (f, "%d\n", current_skill);
473 FS_Printf (f, "%s\n", sv.name);
474 FS_Printf (f, "%f\n",sv.time);
476 // write the light styles
478 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
480 if (sv.lightstyles[i])
481 FS_Printf (f, "%s\n", sv.lightstyles[i]);
488 for (i=0 ; i<sv.num_edicts ; i++)
490 ED_Write (f, EDICT_NUM(i));
494 Con_Printf ("done.\n");
498 extern mempool_t *edictstring_mempool;
505 void Host_Loadgame_f (void)
507 if (cmd_source != src_command)
512 Con_Printf ("load <savename> : load a game\n");
516 strcpy (sv_loadgame, Cmd_Argv(1));
517 FS_DefaultExtension (sv_loadgame, ".sav");
519 Con_Printf ("Loading game from %s...\n", sv_loadgame);
522 void Host_PerformLoadGame(char *name)
525 char mapname[MAX_QPATH];
534 float spawn_parms[NUM_SPAWN_PARMS];
536 cls.demonum = -1; // stop demo loop in case this fails
538 f = FS_Open (name, "r", false);
541 Con_Printf ("ERROR: couldn't open.\n");
545 str = FS_Getline (f);
546 sscanf (str, "%i\n", &version);
547 if (version != SAVEGAME_VERSION)
550 Con_Printf ("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
554 SCR_BeginLoadingPlaque ();
556 str = FS_Getline (f);
557 for (i = 0;i < NUM_SPAWN_PARMS;i++)
559 str = FS_Getline (f);
560 sscanf (str, "%f\n", &spawn_parms[i]);
562 // this silliness is so we can load 1.06 save files, which have float skill values
563 str = FS_Getline (f);
564 sscanf (str, "%f\n", &tfloat);
565 current_skill = (int)(tfloat + 0.1);
566 Cvar_SetValue ("skill", (float)current_skill);
568 strcpy (mapname, FS_Getline (f));
570 str = FS_Getline (f);
571 sscanf (str, "%f\n",&time);
573 allowcheats = sv_cheats.integer != 0;
574 SV_SpawnServer (mapname);
577 Con_Printf ("Couldn't load map\n");
580 sv.paused = true; // pause until all clients connect
583 // load the light styles
585 for (i = 0;i < MAX_LIGHTSTYLES;i++)
587 str = FS_Getline (f);
588 sv.lightstyles[i] = Mem_Alloc(edictstring_mempool, strlen(str)+1);
589 strcpy (sv.lightstyles[i], str);
592 // load the edicts out of the savegame file
597 for (i = 0;i < (int)sizeof(buf) - 1;i++)
609 if (i == sizeof(buf)-1)
610 Host_Error ("Loadgame buffer overflow");
613 if (!COM_ParseToken(&start, false))
618 if (strcmp(com_token,"{"))
619 Host_Error ("First token isn't a brace");
623 // parse the global vars
624 ED_ParseGlobals (start);
629 if (entnum >= MAX_EDICTS)
630 Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)\n", MAX_EDICTS);
631 while (entnum >= sv.max_edicts)
633 ent = EDICT_NUM(entnum);
634 memset (ent->v, 0, progs->entityfields * 4);
635 ent->e->free = false;
636 ED_ParseEdict (start, ent);
638 // link it into the bsp tree
640 SV_LinkEdict (ent, false);
646 sv.num_edicts = entnum;
651 for (i = 0;i < NUM_SPAWN_PARMS;i++)
652 svs.clients[0].spawn_parms[i] = spawn_parms[i];
654 // make sure we're connected to loopback
655 if (cls.state == ca_disconnected || !(cls.state == ca_connected && cls.netcon != NULL && LHNETADDRESS_GetAddressType(&cls.netcon->peeraddress) == LHNETADDRESSTYPE_LOOP))
656 CL_EstablishConnection("local");
659 //============================================================================
662 ======================
664 ======================
666 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player"};
667 void Host_Name_f (void)
669 char newName[sizeof(host_client->name)];
671 if (Cmd_Argc () == 1)
673 Con_Printf ("\"name\" is \"%s\"\n", cl_name.string);
677 if (Cmd_Argc () == 2)
678 strncpy(newName, Cmd_Argv(1), sizeof(host_client->name) - 1);
680 strncpy(newName, Cmd_Args(), sizeof(host_client->name) - 1);
681 newName[sizeof(host_client->name) - 1] = 0;
683 if (cmd_source == src_command)
685 if (strcmp(cl_name.string, newName) == 0)
687 Cvar_Set ("_cl_name", newName);
688 if (cls.state == ca_connected)
689 Cmd_ForwardToServer ();
693 if (strcmp(host_client->name, newName) && host_client->name[0] && strcmp(host_client->name, "unconnected"))
694 SV_BroadcastPrintf("%s changed name to %s\n", host_client->name, newName);
695 strcpy(host_client->name, newName);
696 strcpy(host_client->old_name, newName);
698 sv_player->v->netname = PR_SetString(host_client->name);
699 //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);
701 // send notification to all clients
703 MSG_WriteByte(&sv.reliable_datagram, svc_updatename);
704 MSG_WriteByte(&sv.reliable_datagram, host_client->number);
705 MSG_WriteString(&sv.reliable_datagram, host_client->name);
709 void Host_Version_f (void)
711 Con_Printf ("Version: %s build %s\n", gamename, buildstring);
714 void Host_Say(qboolean teamonly)
719 // LordHavoc: 256 char say messages
720 unsigned char text[256];
721 qboolean fromServer = false;
723 if (cmd_source == src_command)
725 if (cls.state == ca_dedicated)
732 Cmd_ForwardToServer ();
742 // turn on color set 1
744 sprintf (text, "%c%s: ", 1, host_client->name);
746 sprintf (text, "%c<%s> ", 1, hostname.string);
749 p2 = p1 + strlen(p1);
750 // remove trailing newlines
751 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
753 // remove quotes if present
760 Con_Printf("Host_Say: missing end quote\n");
762 SV_ClientPrintf("Host_Say: missing end quote\n");
764 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
766 for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
771 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
772 if (host_client->spawned && (!teamplay.integer || host_client->edict->v->team == save->edict->v->team))
773 SV_ClientPrintf("%s", text);
776 Sys_Printf("%s", &text[1]);
780 void Host_Say_f(void)
786 void Host_Say_Team_f(void)
792 void Host_Tell_f(void)
797 char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
798 qboolean fromServer = false;
800 if (cmd_source == src_command)
802 if (cls.state == ca_dedicated)
806 Cmd_ForwardToServer ();
815 sprintf (text, "%s: ", host_client->name);
817 sprintf (text, "<%s> ", hostname.string);
820 p2 = p1 + strlen(p1);
821 // remove the target name
822 while (p1 < p2 && *p1 != ' ')
824 while (p1 < p2 && *p1 == ' ')
826 // remove trailing newlines
827 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
829 // remove quotes if present
836 Con_Printf("Host_Tell: missing end quote\n");
838 SV_ClientPrintf("Host_Tell: missing end quote\n");
840 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
842 for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
848 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
849 if (host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1)))
850 SV_ClientPrintf("%s", text);
860 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0"};
861 void Host_Color_f(void)
866 func_t SV_ChangeTeam;
870 Con_Printf ("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
871 Con_Printf ("color <0-15> [0-15]\n");
876 top = bottom = atoi(Cmd_Argv(1));
879 top = atoi(Cmd_Argv(1));
880 bottom = atoi(Cmd_Argv(2));
884 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
888 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
892 playercolor = top*16 + bottom;
894 if (cmd_source == src_command)
896 Cvar_SetValue ("_cl_color", playercolor);
897 if (cls.state == ca_connected)
898 Cmd_ForwardToServer ();
902 if (sv_player && (f = ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - pr_functions)))
904 Con_DPrintf("Calling SV_ChangeTeam\n");
905 pr_global_struct->time = sv.time;
906 pr_globals[OFS_PARM0] = playercolor;
907 pr_global_struct->self = EDICT_TO_PROG(sv_player);
908 PR_ExecuteProgram (SV_ChangeTeam, "");
915 if ((val = GETEDICTFIELDVALUE(sv_player, eval_clientcolors)))
916 val->_float = playercolor;
917 sv_player->v->team = bottom + 1;
919 host_client->colors = playercolor;
920 host_client->old_colors = playercolor;
922 // send notification to all clients
923 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
924 MSG_WriteByte (&sv.reliable_datagram, host_client->number);
925 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
934 void Host_Kill_f (void)
936 if (cmd_source == src_command)
938 Cmd_ForwardToServer ();
942 if (!sv_player || sv_player->v->health <= 0)
944 SV_ClientPrintf ("Can't suicide -- already dead!\n");
948 pr_global_struct->time = sv.time;
949 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
950 PR_ExecuteProgram (pr_global_struct->ClientKill, "QC function ClientKill is missing");
959 void Host_Pause_f (void)
962 if (cmd_source == src_command)
964 Cmd_ForwardToServer ();
967 if (!pausable.integer)
968 SV_ClientPrintf ("Pause not allowed.\n");
972 SV_BroadcastPrintf ("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
973 // send notification to all clients
974 MSG_WriteByte (&sv.reliable_datagram, svc_setpause);
975 MSG_WriteByte (&sv.reliable_datagram, sv.paused);
980 ======================
982 LordHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
983 ======================
985 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0"};
986 static void Host_PModel_f (void)
991 if (Cmd_Argc () == 1)
993 Con_Printf ("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
996 i = atoi(Cmd_Argv(1));
998 if (cmd_source == src_command)
1000 if (cl_pmodel.integer == i)
1002 Cvar_SetValue ("_cl_pmodel", i);
1003 if (cls.state == ca_connected)
1004 Cmd_ForwardToServer ();
1008 host_client->pmodel = i;
1009 if (sv_player && (val = GETEDICTFIELDVALUE(sv_player, eval_pmodel)))
1013 //===========================================================================
1021 void Host_PreSpawn_f (void)
1023 if (cmd_source == src_command)
1025 Con_Printf ("prespawn is not valid from the console\n");
1029 if (host_client->spawned)
1031 Con_Printf ("prespawn not valid -- already spawned\n");
1035 SZ_Write (&host_client->message, sv.signon.data, sv.signon.cursize);
1036 MSG_WriteByte (&host_client->message, svc_signonnum);
1037 MSG_WriteByte (&host_client->message, 2);
1038 host_client->sendsignon = true;
1046 void Host_Spawn_f (void)
1053 if (cmd_source == src_command)
1055 Con_Printf("spawn is not valid from the console\n");
1059 if (host_client->spawned)
1061 Con_Printf("Spawn not valid -- already spawned\n");
1067 Con_Printf("Host_Spawn: no edict??\n");
1071 // LordHavoc: moved this above the QC calls at FrikaC's request
1072 // send all current names, colors, and frag counts
1073 SZ_Clear (&host_client->message);
1075 // run the entrance script
1078 // loaded games are fully initialized already
1079 // if this is the last client to be connected, unpause
1082 if ((f = ED_FindFunction ("RestoreGame")))
1083 if ((RestoreGame = (func_t)(f - pr_functions)))
1085 Con_DPrintf("Calling RestoreGame\n");
1086 pr_global_struct->time = sv.time;
1087 pr_global_struct->self = EDICT_TO_PROG(sv_player);
1088 PR_ExecuteProgram (RestoreGame, "");
1094 ED_ClearEdict(sv_player);
1096 //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);
1098 // copy spawn parms out of the client_t
1099 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1100 (&pr_global_struct->parm1)[i] = host_client->spawn_parms[i];
1102 // call the spawn function
1103 pr_global_struct->time = sv.time;
1104 pr_global_struct->self = EDICT_TO_PROG(sv_player);
1105 PR_ExecuteProgram (pr_global_struct->ClientConnect, "QC function ClientConnect is missing");
1107 if ((Sys_DoubleTime() - host_client->netconnection->connecttime) <= sv.time)
1108 Sys_Printf ("%s entered the game\n", host_client->name);
1110 PR_ExecuteProgram (pr_global_struct->PutClientInServer, "QC function PutClientInServer is missing");
1114 // send time of update
1115 MSG_WriteByte (&host_client->message, svc_time);
1116 MSG_WriteFloat (&host_client->message, sv.time);
1118 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
1120 if (!client->active)
1122 MSG_WriteByte (&host_client->message, svc_updatename);
1123 MSG_WriteByte (&host_client->message, i);
1124 MSG_WriteString (&host_client->message, client->old_name);
1125 MSG_WriteByte (&host_client->message, svc_updatefrags);
1126 MSG_WriteByte (&host_client->message, i);
1127 MSG_WriteShort (&host_client->message, client->old_frags);
1128 MSG_WriteByte (&host_client->message, svc_updatecolors);
1129 MSG_WriteByte (&host_client->message, i);
1130 MSG_WriteByte (&host_client->message, client->old_colors);
1133 // send all current light styles
1134 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1136 MSG_WriteByte (&host_client->message, svc_lightstyle);
1137 MSG_WriteByte (&host_client->message, (char)i);
1138 MSG_WriteString (&host_client->message, sv.lightstyles[i]);
1142 MSG_WriteByte (&host_client->message, svc_updatestat);
1143 MSG_WriteByte (&host_client->message, STAT_TOTALSECRETS);
1144 MSG_WriteLong (&host_client->message, pr_global_struct->total_secrets);
1146 MSG_WriteByte (&host_client->message, svc_updatestat);
1147 MSG_WriteByte (&host_client->message, STAT_TOTALMONSTERS);
1148 MSG_WriteLong (&host_client->message, pr_global_struct->total_monsters);
1150 MSG_WriteByte (&host_client->message, svc_updatestat);
1151 MSG_WriteByte (&host_client->message, STAT_SECRETS);
1152 MSG_WriteLong (&host_client->message, pr_global_struct->found_secrets);
1154 MSG_WriteByte (&host_client->message, svc_updatestat);
1155 MSG_WriteByte (&host_client->message, STAT_MONSTERS);
1156 MSG_WriteLong (&host_client->message, pr_global_struct->killed_monsters);
1159 // Never send a roll angle, because savegames can catch the server
1160 // in a state where it is expecting the client to correct the angle
1161 // and it won't happen if the game was just loaded, so you wind up
1162 // with a permanent head tilt
1163 MSG_WriteByte (&host_client->message, svc_setangle);
1164 for (i=0 ; i < 2 ; i++)
1165 MSG_WriteAngle (&host_client->message, sv_player->v->angles[i] );
1166 MSG_WriteAngle (&host_client->message, 0 );
1168 SV_WriteClientdataToMessage (sv_player, &host_client->message);
1170 MSG_WriteByte (&host_client->message, svc_signonnum);
1171 MSG_WriteByte (&host_client->message, 3);
1172 host_client->sendsignon = true;
1180 void Host_Begin_f (void)
1182 if (cmd_source == src_command)
1184 Con_Printf ("begin is not valid from the console\n");
1188 host_client->spawned = true;
1191 //===========================================================================
1198 Kicks a user off of the server
1201 void Host_Kick_f (void)
1204 const char *message = NULL;
1207 qboolean byNumber = false;
1209 if (cmd_source != src_command || !sv.active)
1214 if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1216 i = atof(Cmd_Argv(2)) - 1;
1217 if (i < 0 || i >= svs.maxclients || !(host_client = svs.clients + i)->active)
1223 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1225 if (!host_client->active)
1227 if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1232 if (i < svs.maxclients)
1234 if (cmd_source == src_command)
1236 if (cls.state == ca_dedicated)
1239 who = cl_name.string;
1244 // can't kick yourself!
1245 if (host_client == save)
1250 message = Cmd_Args();
1251 COM_ParseToken(&message, false);
1254 message++; // skip the #
1255 while (*message == ' ') // skip white space
1257 message += strlen(Cmd_Argv(2)); // skip the number
1259 while (*message && *message == ' ')
1263 SV_ClientPrintf ("Kicked by %s: %s\n", who, message);
1265 SV_ClientPrintf ("Kicked by %s\n", who);
1266 SV_DropClient (false); // kicked
1273 ===============================================================================
1277 ===============================================================================
1285 void Host_Give_f (void)
1291 if (cmd_source == src_command)
1293 Cmd_ForwardToServer ();
1302 SV_ClientPrintf("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
1307 v = atoi (Cmd_Argv(2));
1321 // MED 01/04/97 added hipnotic give stuff
1322 if (gamemode == GAME_HIPNOTIC)
1327 sv_player->v->items = (int)sv_player->v->items | HIT_PROXIMITY_GUN;
1329 sv_player->v->items = (int)sv_player->v->items | IT_GRENADE_LAUNCHER;
1331 else if (t[0] == '9')
1332 sv_player->v->items = (int)sv_player->v->items | HIT_LASER_CANNON;
1333 else if (t[0] == '0')
1334 sv_player->v->items = (int)sv_player->v->items | HIT_MJOLNIR;
1335 else if (t[0] >= '2')
1336 sv_player->v->items = (int)sv_player->v->items | (IT_SHOTGUN << (t[0] - '2'));
1341 sv_player->v->items = (int)sv_player->v->items | (IT_SHOTGUN << (t[0] - '2'));
1346 if (gamemode == GAME_ROGUE && (val = GETEDICTFIELDVALUE(sv_player, eval_ammo_shells1)))
1349 sv_player->v->ammo_shells = v;
1352 if (gamemode == GAME_ROGUE)
1354 if ((val = GETEDICTFIELDVALUE(sv_player, eval_ammo_nails1)))
1357 if (sv_player->v->weapon <= IT_LIGHTNING)
1358 sv_player->v->ammo_nails = v;
1363 sv_player->v->ammo_nails = v;
1367 if (gamemode == GAME_ROGUE)
1369 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_lava_nails);
1373 if (sv_player->v->weapon > IT_LIGHTNING)
1374 sv_player->v->ammo_nails = v;
1379 if (gamemode == GAME_ROGUE)
1381 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_rockets1);
1385 if (sv_player->v->weapon <= IT_LIGHTNING)
1386 sv_player->v->ammo_rockets = v;
1391 sv_player->v->ammo_rockets = v;
1395 if (gamemode == GAME_ROGUE)
1397 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_multi_rockets);
1401 if (sv_player->v->weapon > IT_LIGHTNING)
1402 sv_player->v->ammo_rockets = v;
1407 sv_player->v->health = v;
1410 if (gamemode == GAME_ROGUE)
1412 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_cells1);
1416 if (sv_player->v->weapon <= IT_LIGHTNING)
1417 sv_player->v->ammo_cells = v;
1422 sv_player->v->ammo_cells = v;
1426 if (gamemode == GAME_ROGUE)
1428 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_plasma);
1432 if (sv_player->v->weapon > IT_LIGHTNING)
1433 sv_player->v->ammo_cells = v;
1440 edict_t *FindViewthing (void)
1445 for (i=0 ; i<sv.num_edicts ; i++)
1448 if (!strcmp (PR_GetString(e->v->classname), "viewthing"))
1451 Con_Printf ("No viewthing on map\n");
1460 void Host_Viewmodel_f (void)
1465 e = FindViewthing ();
1469 m = Mod_ForName (Cmd_Argv(1), false, true, false);
1472 Con_Printf ("Can't load %s\n", Cmd_Argv(1));
1477 cl.model_precache[(int)e->v->modelindex] = m;
1485 void Host_Viewframe_f (void)
1491 e = FindViewthing ();
1494 m = cl.model_precache[(int)e->v->modelindex];
1496 f = atoi(Cmd_Argv(1));
1497 if (f >= m->numframes)
1504 void PrintFrameName (model_t *m, int frame)
1507 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1509 Con_Printf("frame %i\n", frame);
1517 void Host_Viewnext_f (void)
1522 e = FindViewthing ();
1525 m = cl.model_precache[(int)e->v->modelindex];
1527 e->v->frame = e->v->frame + 1;
1528 if (e->v->frame >= m->numframes)
1529 e->v->frame = m->numframes - 1;
1531 PrintFrameName (m, e->v->frame);
1539 void Host_Viewprev_f (void)
1544 e = FindViewthing ();
1548 m = cl.model_precache[(int)e->v->modelindex];
1550 e->v->frame = e->v->frame - 1;
1551 if (e->v->frame < 0)
1554 PrintFrameName (m, e->v->frame);
1558 ===============================================================================
1562 ===============================================================================
1571 void Host_Startdemos_f (void)
1575 if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
1577 if (!sv.active && !sv_spawnmap[0])
1579 if (gamemode == GAME_TRANSFUSION)
1580 Cbuf_AddText ("map bb1\n");
1582 Cbuf_AddText ("map start\n");
1590 Con_Printf ("Max %i demos in demoloop\n", MAX_DEMOS);
1593 Con_DPrintf ("%i demo(s) in loop\n", c);
1595 for (i=1 ; i<c+1 ; i++)
1596 strncpy (cls.demos[i-1], Cmd_Argv(i), sizeof(cls.demos[0])-1);
1598 // LordHavoc: clear the remaining slots
1599 for (;i <= MAX_DEMOS;i++)
1600 cls.demos[i-1][0] = 0;
1602 if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
1616 Return to looping demos
1619 void Host_Demos_f (void)
1621 if (cls.state == ca_dedicated)
1623 if (cls.demonum == -1)
1633 Return to looping demos
1636 void Host_Stopdemo_f (void)
1638 if (!cls.demoplayback)
1643 // LordHavoc: because we don't want to load things before the video starts,
1644 // we have to delay map and game loads until AFTER video is initialized
1645 void Host_PerformSpawnServerAndLoadGame(void)
1647 if (vid_hidden && cls.state != ca_dedicated)
1650 Host_PerformLoadGame(sv_loadgame);
1651 else if (sv_spawnmap[0])
1653 allowcheats = sv_cheats.integer != 0;
1654 SV_SpawnServer(sv_spawnmap);
1658 if (sv.active && cls.state == ca_disconnected)
1659 Cbuf_AddText ("connect local");
1662 static void MaxPlayers_f(void)
1666 if (Cmd_Argc() != 2)
1668 Con_Printf("\"maxplayers\" is \"%u\"\n", svs.maxclients);
1674 Con_Printf("maxplayers can not be changed while a server is running.\n");
1678 n = atoi(Cmd_Argv(1));
1679 n = bound(1, n, MAX_SCOREBOARD);
1680 Con_Printf ("\"maxplayers\" set to \"%u\"\n", n);
1683 Mem_Free(svs.clients);
1685 svs.clients = Mem_Alloc(sv_clients_mempool, sizeof(client_t) * svs.maxclients);
1687 Cvar_Set ("deathmatch", "0");
1689 Cvar_Set ("deathmatch", "1");
1692 //=============================================================================
1699 void Host_InitCommands (void)
1701 Cmd_AddCommand ("status", Host_Status_f);
1702 Cmd_AddCommand ("quit", Host_Quit_f);
1703 if (gamemode == GAME_NEHAHRA)
1705 Cmd_AddCommand ("max", Host_God_f);
1706 Cmd_AddCommand ("monster", Host_Notarget_f);
1707 Cmd_AddCommand ("scrag", Host_Fly_f);
1708 Cmd_AddCommand ("wraith", Host_Noclip_f);
1709 Cmd_AddCommand ("gimme", Host_Give_f);
1713 Cmd_AddCommand ("god", Host_God_f);
1714 Cmd_AddCommand ("notarget", Host_Notarget_f);
1715 Cmd_AddCommand ("fly", Host_Fly_f);
1716 Cmd_AddCommand ("noclip", Host_Noclip_f);
1717 Cmd_AddCommand ("give", Host_Give_f);
1719 Cmd_AddCommand ("map", Host_Map_f);
1720 Cmd_AddCommand ("restart", Host_Restart_f);
1721 Cmd_AddCommand ("changelevel", Host_Changelevel_f);
1722 Cmd_AddCommand ("connect", Host_Connect_f);
1723 Cmd_AddCommand ("reconnect", Host_Reconnect_f);
1724 Cmd_AddCommand ("version", Host_Version_f);
1725 Cmd_AddCommand ("say", Host_Say_f);
1726 Cmd_AddCommand ("say_team", Host_Say_Team_f);
1727 Cmd_AddCommand ("tell", Host_Tell_f);
1728 Cmd_AddCommand ("kill", Host_Kill_f);
1729 Cmd_AddCommand ("pause", Host_Pause_f);
1730 Cmd_AddCommand ("kick", Host_Kick_f);
1731 Cmd_AddCommand ("ping", Host_Ping_f);
1732 Cmd_AddCommand ("load", Host_Loadgame_f);
1733 Cmd_AddCommand ("save", Host_Savegame_f);
1735 Cmd_AddCommand ("startdemos", Host_Startdemos_f);
1736 Cmd_AddCommand ("demos", Host_Demos_f);
1737 Cmd_AddCommand ("stopdemo", Host_Stopdemo_f);
1739 Cmd_AddCommand ("viewmodel", Host_Viewmodel_f);
1740 Cmd_AddCommand ("viewframe", Host_Viewframe_f);
1741 Cmd_AddCommand ("viewnext", Host_Viewnext_f);
1742 Cmd_AddCommand ("viewprev", Host_Viewprev_f);
1744 Cvar_RegisterVariable (&cl_name);
1745 Cmd_AddCommand ("name", Host_Name_f);
1746 Cvar_RegisterVariable (&cl_color);
1747 Cmd_AddCommand ("color", Host_Color_f);
1748 if (gamemode == GAME_NEHAHRA)
1750 Cvar_RegisterVariable (&cl_pmodel);
1751 Cmd_AddCommand ("pmodel", Host_PModel_f);
1753 Cmd_AddCommand ("prespawn", Host_PreSpawn_f);
1754 Cmd_AddCommand ("spawn", Host_Spawn_f);
1755 Cmd_AddCommand ("begin", Host_Begin_f);
1756 Cmd_AddCommand ("maxplayers", MaxPlayers_f);
1758 Cvar_RegisterVariable(&sv_cheats);