2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 cvar_t sv_cheats = {0, "sv_cheats", "0"};
25 qboolean allowcheats = false;
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 < svs.maxclients;j++)
70 if (svs.clients[j].active)
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, svs.maxclients);
76 for (j = 0, client = svs.clients;j < svs.maxclients;j++, client++)
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 ();
117 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
121 sv_player->v->flags = (int)sv_player->v->flags ^ FL_GODMODE;
122 if (!((int)sv_player->v->flags & FL_GODMODE) )
123 SV_ClientPrint("godmode OFF\n");
125 SV_ClientPrint("godmode ON\n");
128 void Host_Notarget_f (void)
130 if (cmd_source == src_command)
132 Cmd_ForwardToServer ();
141 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
145 sv_player->v->flags = (int)sv_player->v->flags ^ FL_NOTARGET;
146 if (!((int)sv_player->v->flags & FL_NOTARGET) )
147 SV_ClientPrint("notarget OFF\n");
149 SV_ClientPrint("notarget ON\n");
152 qboolean noclip_anglehack;
154 void Host_Noclip_f (void)
156 if (cmd_source == src_command)
158 Cmd_ForwardToServer ();
167 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
171 if (sv_player->v->movetype != MOVETYPE_NOCLIP)
173 noclip_anglehack = true;
174 sv_player->v->movetype = MOVETYPE_NOCLIP;
175 SV_ClientPrint("noclip ON\n");
179 noclip_anglehack = false;
180 sv_player->v->movetype = MOVETYPE_WALK;
181 SV_ClientPrint("noclip OFF\n");
189 Sets client to flymode
192 void Host_Fly_f (void)
194 if (cmd_source == src_command)
196 Cmd_ForwardToServer ();
205 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
209 if (sv_player->v->movetype != MOVETYPE_FLY)
211 sv_player->v->movetype = MOVETYPE_FLY;
212 SV_ClientPrint("flymode ON\n");
216 sv_player->v->movetype = MOVETYPE_WALK;
217 SV_ClientPrint("flymode OFF\n");
228 void Host_Ping_f (void)
234 if (cmd_source == src_command)
236 Cmd_ForwardToServer ();
240 SV_ClientPrint("Client ping times:\n");
241 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
246 for (j=0 ; j<NUM_PING_TIMES ; j++)
247 total+=client->ping_times[j];
248 total /= NUM_PING_TIMES;
249 SV_ClientPrintf("%4i %s\n", (int)(total*1000), client->name);
254 ===============================================================================
258 ===============================================================================
262 ======================
267 command from the console. Active clients are kicked off.
268 ======================
270 void Host_Map_f (void)
272 char level[MAX_QPATH];
274 if (cmd_source != src_command)
277 cls.demonum = -1; // stop demo loop in case this fails
280 Host_ShutdownServer(false);
282 key_dest = key_game; // remove console or menu
283 SCR_BeginLoadingPlaque ();
285 svs.serverflags = 0; // haven't completed an episode yet
286 allowcheats = sv_cheats.integer != 0;
287 strcpy(level, Cmd_Argv(1));
288 SV_SpawnServer(level);
289 if (sv.active && cls.state == ca_disconnected)
290 CL_EstablishConnection("local:1");
297 Goes to a new map, taking all clients along
300 void Host_Changelevel_f (void)
302 char level[MAX_QPATH];
306 Con_Print("changelevel <levelname> : continue game on a new level\n");
309 if (!sv.active || cls.demoplayback)
311 Con_Print("Only the server may changelevel\n");
314 SV_SaveSpawnparms ();
315 allowcheats = sv_cheats.integer != 0;
316 strcpy(level, Cmd_Argv(1));
317 SV_SpawnServer(level);
318 if (sv.active && cls.state == ca_disconnected)
319 CL_EstablishConnection("local:1");
326 Restarts the current server for a dead player
329 void Host_Restart_f (void)
331 char mapname[MAX_QPATH];
333 if (cls.demoplayback || !sv.active)
336 if (cmd_source != src_command)
338 allowcheats = sv_cheats.integer != 0;
339 strcpy(mapname, sv.name);
340 SV_SpawnServer(mapname);
341 if (sv.active && cls.state == ca_disconnected)
342 CL_EstablishConnection("local:1");
349 This command causes the client to wait for the signon messages again.
350 This is sent just before a server changes levels
353 void Host_Reconnect_f (void)
355 SCR_BeginLoadingPlaque();
356 cls.signon = 0; // need new connection messages
360 =====================
363 User command to connect to server
364 =====================
366 void Host_Connect_f (void)
368 CL_EstablishConnection(Cmd_Argv(1));
373 ===============================================================================
377 ===============================================================================
380 #define SAVEGAME_VERSION 5
386 Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
389 void Host_SavegameComment (char *text)
394 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
396 memcpy (text, cl.levelname, strlen(cl.levelname));
397 sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
398 memcpy (text+22, kills, strlen(kills));
399 // convert space to _ to make stdio happy
400 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
403 text[SAVEGAME_COMMENT_LENGTH] = '\0';
412 void Host_Savegame_f (void)
417 char comment[SAVEGAME_COMMENT_LENGTH+1];
419 if (cmd_source != src_command)
422 if (cls.state != ca_connected || !sv.active)
424 Con_Print("Not playing a local game.\n");
430 Con_Print("Can't save in intermission.\n");
434 for (i = 0;i < svs.maxclients;i++)
436 if (svs.clients[i].active)
440 Con_Print("Can't save multiplayer games.\n");
443 if (svs.clients[i].edict->v->deadflag)
445 Con_Print("Can't savegame with a dead player\n");
453 Con_Print("save <savename> : save a game\n");
457 if (strstr(Cmd_Argv(1), ".."))
459 Con_Print("Relative pathnames are not allowed.\n");
463 strlcpy (name, Cmd_Argv(1), sizeof (name));
464 FS_DefaultExtension (name, ".sav", sizeof (name));
466 Con_Printf("Saving game to %s...\n", name);
467 f = FS_Open (name, "w", false);
470 Con_Print("ERROR: couldn't open.\n");
474 FS_Printf(f, "%i\n", SAVEGAME_VERSION);
475 Host_SavegameComment (comment);
476 FS_Printf(f, "%s\n", comment);
477 for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
478 FS_Printf(f, "%f\n", svs.clients[0].spawn_parms[i]);
479 FS_Printf(f, "%d\n", current_skill);
480 FS_Printf(f, "%s\n", sv.name);
481 FS_Printf(f, "%f\n",sv.time);
483 // write the light styles
485 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
487 if (sv.lightstyles[i])
488 FS_Printf(f, "%s\n", sv.lightstyles[i]);
495 for (i=0 ; i<sv.num_edicts ; i++)
497 ED_Write (f, EDICT_NUM(i));
501 Con_Print("done.\n");
505 extern mempool_t *edictstring_mempool;
512 void Host_Loadgame_f (void)
515 char filename[MAX_QPATH];
516 char mapname[MAX_QPATH];
525 float spawn_parms[NUM_SPAWN_PARMS];
527 if (cmd_source != src_command)
532 Con_Print("load <savename> : load a game\n");
536 strcpy (filename, Cmd_Argv(1));
537 FS_DefaultExtension (filename, ".sav", sizeof (filename));
539 Con_Printf("Loading game from %s...\n", filename);
541 cls.demonum = -1; // stop demo loop in case this fails
543 f = FS_Open (filename, "r", false);
546 Con_Print("ERROR: couldn't open.\n");
550 str = FS_Getline (f);
551 sscanf (str, "%i\n", &version);
552 if (version != SAVEGAME_VERSION)
555 Con_Printf("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
559 SCR_BeginLoadingPlaque ();
561 str = FS_Getline (f);
562 for (i = 0;i < NUM_SPAWN_PARMS;i++)
564 str = FS_Getline (f);
565 sscanf (str, "%f\n", &spawn_parms[i]);
567 // this silliness is so we can load 1.06 save files, which have float skill values
568 str = FS_Getline (f);
569 sscanf (str, "%f\n", &tfloat);
570 current_skill = (int)(tfloat + 0.1);
571 Cvar_SetValue ("skill", (float)current_skill);
573 strcpy (mapname, FS_Getline (f));
575 str = FS_Getline (f);
576 sscanf (str, "%f\n",&time);
578 allowcheats = sv_cheats.integer != 0;
579 SV_SpawnServer (mapname);
582 Con_Print("Couldn't load map\n");
585 sv.paused = true; // pause until all clients connect
588 // load the light styles
590 for (i = 0;i < MAX_LIGHTSTYLES;i++)
592 str = FS_Getline (f);
593 sv.lightstyles[i] = Mem_Alloc(edictstring_mempool, strlen(str)+1);
594 strcpy (sv.lightstyles[i], str);
597 // load the edicts out of the savegame file
602 for (i = 0;i < (int)sizeof(buf) - 1;i++)
614 if (i == sizeof(buf)-1)
615 Host_Error ("Loadgame buffer overflow");
618 if (!COM_ParseToken(&start, false))
623 if (strcmp(com_token,"{"))
624 Host_Error ("First token isn't a brace");
628 // parse the global vars
629 ED_ParseGlobals (start);
634 if (entnum >= MAX_EDICTS)
635 Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)\n", MAX_EDICTS);
636 while (entnum >= sv.max_edicts)
638 ent = EDICT_NUM(entnum);
639 memset (ent->v, 0, progs->entityfields * 4);
640 ent->e->free = false;
641 ED_ParseEdict (start, ent);
643 // link it into the bsp tree
645 SV_LinkEdict (ent, false);
651 sv.num_edicts = entnum;
656 for (i = 0;i < NUM_SPAWN_PARMS;i++)
657 svs.clients[0].spawn_parms[i] = spawn_parms[i];
659 // make sure we're connected to loopback
660 if (cls.state == ca_disconnected || !(cls.state == ca_connected && cls.netcon != NULL && LHNETADDRESS_GetAddressType(&cls.netcon->peeraddress) == LHNETADDRESSTYPE_LOOP))
661 CL_EstablishConnection("local:1");
664 //============================================================================
667 ======================
669 ======================
671 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player"};
672 void Host_Name_f (void)
674 char newName[sizeof(host_client->name)];
676 if (Cmd_Argc () == 1)
678 Con_Printf("\"name\" is \"%s\"\n", cl_name.string);
682 if (Cmd_Argc () == 2)
683 strlcpy (newName, Cmd_Argv(1), sizeof (newName));
685 strlcpy (newName, Cmd_Args(), sizeof (newName));
687 if (cmd_source == src_command)
689 if (strcmp(cl_name.string, newName) == 0)
691 Cvar_Set ("_cl_name", newName);
692 if (cls.state == ca_connected)
693 Cmd_ForwardToServer ();
697 if (strcmp(host_client->name, newName) && host_client->name[0] && strcmp(host_client->name, "unconnected"))
698 SV_BroadcastPrintf("%s changed name to %s\n", host_client->name, newName);
699 strcpy(host_client->name, newName);
700 strcpy(host_client->old_name, newName);
702 sv_player->v->netname = PR_SetString(host_client->name);
703 //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);
705 // send notification to all clients
707 MSG_WriteByte(&sv.reliable_datagram, svc_updatename);
708 MSG_WriteByte(&sv.reliable_datagram, host_client->number);
709 MSG_WriteString(&sv.reliable_datagram, host_client->name);
713 void Host_Version_f (void)
715 Con_Printf("Version: %s build %s\n", gamename, buildstring);
718 void Host_Say(qboolean teamonly)
723 // LordHavoc: 256 char say messages
724 unsigned char text[256];
725 qboolean fromServer = false;
727 if (cmd_source == src_command)
729 if (cls.state == ca_dedicated)
736 Cmd_ForwardToServer ();
746 // turn on color set 1
748 sprintf (text, "%c%s: ", 1, host_client->name);
750 sprintf (text, "%c<%s> ", 1, hostname.string);
753 p2 = p1 + strlen(p1);
754 // remove trailing newlines
755 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
757 // remove quotes if present
764 Con_Print("Host_Say: missing end quote\n");
766 SV_ClientPrint("Host_Say: missing end quote\n");
768 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
770 for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
775 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
776 if (host_client->spawned && (!teamplay.integer || host_client->edict->v->team == save->edict->v->team))
777 SV_ClientPrint(text);
784 void Host_Say_f(void)
790 void Host_Say_Team_f(void)
796 void Host_Tell_f(void)
801 char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
802 qboolean fromServer = false;
804 if (cmd_source == src_command)
806 if (cls.state == ca_dedicated)
810 Cmd_ForwardToServer ();
819 sprintf (text, "%s: ", host_client->name);
821 sprintf (text, "<%s> ", hostname.string);
824 p2 = p1 + strlen(p1);
825 // remove the target name
826 while (p1 < p2 && *p1 != ' ')
828 while (p1 < p2 && *p1 == ' ')
830 // remove trailing newlines
831 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
833 // remove quotes if present
840 Con_Print("Host_Tell: missing end quote\n");
842 SV_ClientPrint("Host_Tell: missing end quote\n");
844 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
846 for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
852 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
853 if (host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1)))
854 SV_ClientPrint(text);
864 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0"};
865 void Host_Color_f(void)
870 func_t SV_ChangeTeam;
874 Con_Printf("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
875 Con_Print("color <0-15> [0-15]\n");
880 top = bottom = atoi(Cmd_Argv(1));
883 top = atoi(Cmd_Argv(1));
884 bottom = atoi(Cmd_Argv(2));
888 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
892 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
896 playercolor = top*16 + bottom;
898 if (cmd_source == src_command)
900 Cvar_SetValue ("_cl_color", playercolor);
901 if (cls.state == ca_connected)
902 Cmd_ForwardToServer ();
906 if (sv_player && (f = ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - pr_functions)))
908 Con_DPrint("Calling SV_ChangeTeam\n");
909 pr_global_struct->time = sv.time;
910 pr_globals[OFS_PARM0] = playercolor;
911 pr_global_struct->self = EDICT_TO_PROG(sv_player);
912 PR_ExecuteProgram (SV_ChangeTeam, "");
919 if ((val = GETEDICTFIELDVALUE(sv_player, eval_clientcolors)))
920 val->_float = playercolor;
921 sv_player->v->team = bottom + 1;
923 host_client->colors = playercolor;
924 host_client->old_colors = playercolor;
926 // send notification to all clients
927 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
928 MSG_WriteByte (&sv.reliable_datagram, host_client->number);
929 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
933 cvar_t cl_rate = {CVAR_SAVE, "_cl_rate", "10000"};
934 cvar_t sv_maxrate = {CVAR_SAVE | CVAR_NOTIFY, "sv_maxrate", "10000"};
935 void Host_Rate_f(void)
941 Con_Printf("\"rate\" is \"%i\"\n", cl_rate.integer);
942 Con_Print("rate <500-25000>\n");
946 rate = atoi(Cmd_Argv(1));
948 if (cmd_source == src_command)
950 Cvar_SetValue ("_cl_rate", bound(NET_MINRATE, rate, NET_MAXRATE));
951 if (cls.state == ca_connected)
952 Cmd_ForwardToServer ();
956 maxrate = bound(NET_MINRATE, sv_maxrate.integer, NET_MAXRATE);
957 if (sv_maxrate.integer != maxrate)
958 Cvar_SetValueQuick(&sv_maxrate, maxrate);
960 if (LHNETADDRESS_GetAddressType(&host_client->netconnection->peeraddress) != LHNETADDRESSTYPE_LOOP)
961 host_client->netconnection->rate = bound(NET_MINRATE, rate, maxrate);
969 void Host_Kill_f (void)
971 if (cmd_source == src_command)
973 Cmd_ForwardToServer ();
977 if (!sv_player || sv_player->v->health <= 0)
979 SV_ClientPrint("Can't suicide -- already dead!\n");
983 pr_global_struct->time = sv.time;
984 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
985 PR_ExecuteProgram (pr_global_struct->ClientKill, "QC function ClientKill is missing");
994 void Host_Pause_f (void)
997 if (cmd_source == src_command)
999 Cmd_ForwardToServer ();
1002 if (!pausable.integer)
1003 SV_ClientPrint("Pause not allowed.\n");
1007 SV_BroadcastPrintf("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
1008 // send notification to all clients
1009 MSG_WriteByte(&sv.reliable_datagram, svc_setpause);
1010 MSG_WriteByte(&sv.reliable_datagram, sv.paused);
1015 ======================
1017 LordHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
1018 ======================
1020 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0"};
1021 static void Host_PModel_f (void)
1026 if (Cmd_Argc () == 1)
1028 Con_Printf("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
1031 i = atoi(Cmd_Argv(1));
1033 if (cmd_source == src_command)
1035 if (cl_pmodel.integer == i)
1037 Cvar_SetValue ("_cl_pmodel", i);
1038 if (cls.state == ca_connected)
1039 Cmd_ForwardToServer ();
1043 host_client->pmodel = i;
1044 if (sv_player && (val = GETEDICTFIELDVALUE(sv_player, eval_pmodel)))
1048 //===========================================================================
1056 void Host_PreSpawn_f (void)
1058 if (cmd_source == src_command)
1060 Con_Print("prespawn is not valid from the console\n");
1064 if (host_client->spawned)
1066 Con_Print("prespawn not valid -- already spawned\n");
1070 SZ_Write (&host_client->message, sv.signon.data, sv.signon.cursize);
1071 MSG_WriteByte (&host_client->message, svc_signonnum);
1072 MSG_WriteByte (&host_client->message, 2);
1073 host_client->sendsignon = true;
1081 void Host_Spawn_f (void)
1088 if (cmd_source == src_command)
1090 Con_Print("spawn is not valid from the console\n");
1094 if (host_client->spawned)
1096 Con_Print("Spawn not valid -- already spawned\n");
1102 Con_Print("Host_Spawn: no edict??\n");
1106 // LordHavoc: moved this above the QC calls at FrikaC's request
1107 // send all current names, colors, and frag counts
1108 SZ_Clear (&host_client->message);
1110 // run the entrance script
1113 // loaded games are fully initialized already
1114 // if this is the last client to be connected, unpause
1117 if ((f = ED_FindFunction ("RestoreGame")))
1118 if ((RestoreGame = (func_t)(f - pr_functions)))
1120 Con_DPrint("Calling RestoreGame\n");
1121 pr_global_struct->time = sv.time;
1122 pr_global_struct->self = EDICT_TO_PROG(sv_player);
1123 PR_ExecuteProgram (RestoreGame, "");
1129 ED_ClearEdict(sv_player);
1131 //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);
1133 // copy spawn parms out of the client_t
1134 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1135 (&pr_global_struct->parm1)[i] = host_client->spawn_parms[i];
1137 // call the spawn function
1138 pr_global_struct->time = sv.time;
1139 pr_global_struct->self = EDICT_TO_PROG(sv_player);
1140 PR_ExecuteProgram (pr_global_struct->ClientConnect, "QC function ClientConnect is missing");
1142 if ((Sys_DoubleTime() - host_client->netconnection->connecttime) <= sv.time)
1143 Sys_Printf("%s entered the game\n", host_client->name);
1145 PR_ExecuteProgram (pr_global_struct->PutClientInServer, "QC function PutClientInServer is missing");
1149 // send time of update
1150 MSG_WriteByte (&host_client->message, svc_time);
1151 MSG_WriteFloat (&host_client->message, sv.time);
1153 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
1155 if (!client->active)
1157 MSG_WriteByte (&host_client->message, svc_updatename);
1158 MSG_WriteByte (&host_client->message, i);
1159 MSG_WriteString (&host_client->message, client->old_name);
1160 MSG_WriteByte (&host_client->message, svc_updatefrags);
1161 MSG_WriteByte (&host_client->message, i);
1162 MSG_WriteShort (&host_client->message, client->old_frags);
1163 MSG_WriteByte (&host_client->message, svc_updatecolors);
1164 MSG_WriteByte (&host_client->message, i);
1165 MSG_WriteByte (&host_client->message, client->old_colors);
1168 // send all current light styles
1169 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1171 MSG_WriteByte (&host_client->message, svc_lightstyle);
1172 MSG_WriteByte (&host_client->message, (char)i);
1173 MSG_WriteString (&host_client->message, sv.lightstyles[i]);
1177 MSG_WriteByte (&host_client->message, svc_updatestat);
1178 MSG_WriteByte (&host_client->message, STAT_TOTALSECRETS);
1179 MSG_WriteLong (&host_client->message, pr_global_struct->total_secrets);
1181 MSG_WriteByte (&host_client->message, svc_updatestat);
1182 MSG_WriteByte (&host_client->message, STAT_TOTALMONSTERS);
1183 MSG_WriteLong (&host_client->message, pr_global_struct->total_monsters);
1185 MSG_WriteByte (&host_client->message, svc_updatestat);
1186 MSG_WriteByte (&host_client->message, STAT_SECRETS);
1187 MSG_WriteLong (&host_client->message, pr_global_struct->found_secrets);
1189 MSG_WriteByte (&host_client->message, svc_updatestat);
1190 MSG_WriteByte (&host_client->message, STAT_MONSTERS);
1191 MSG_WriteLong (&host_client->message, pr_global_struct->killed_monsters);
1194 // Never send a roll angle, because savegames can catch the server
1195 // in a state where it is expecting the client to correct the angle
1196 // and it won't happen if the game was just loaded, so you wind up
1197 // with a permanent head tilt
1198 MSG_WriteByte (&host_client->message, svc_setangle);
1199 for (i=0 ; i < 2 ; i++)
1200 MSG_WriteAngle (&host_client->message, sv_player->v->angles[i] );
1201 MSG_WriteAngle (&host_client->message, 0 );
1203 SV_WriteClientdataToMessage (sv_player, &host_client->message);
1205 MSG_WriteByte (&host_client->message, svc_signonnum);
1206 MSG_WriteByte (&host_client->message, 3);
1207 host_client->sendsignon = true;
1215 void Host_Begin_f (void)
1217 if (cmd_source == src_command)
1219 Con_Print("begin is not valid from the console\n");
1223 host_client->spawned = true;
1226 //===========================================================================
1233 Kicks a user off of the server
1236 void Host_Kick_f (void)
1239 const char *message = NULL;
1242 qboolean byNumber = false;
1244 if (cmd_source != src_command || !sv.active)
1249 if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1251 i = atof(Cmd_Argv(2)) - 1;
1252 if (i < 0 || i >= svs.maxclients || !(host_client = svs.clients + i)->active)
1258 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1260 if (!host_client->active)
1262 if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1267 if (i < svs.maxclients)
1269 if (cmd_source == src_command)
1271 if (cls.state == ca_dedicated)
1274 who = cl_name.string;
1279 // can't kick yourself!
1280 if (host_client == save)
1285 message = Cmd_Args();
1286 COM_ParseToken(&message, false);
1289 message++; // skip the #
1290 while (*message == ' ') // skip white space
1292 message += strlen(Cmd_Argv(2)); // skip the number
1294 while (*message && *message == ' ')
1298 SV_ClientPrintf("Kicked by %s: %s\n", who, message);
1300 SV_ClientPrintf("Kicked by %s\n", who);
1301 SV_DropClient (false); // kicked
1308 ===============================================================================
1312 ===============================================================================
1320 void Host_Give_f (void)
1326 if (cmd_source == src_command)
1328 Cmd_ForwardToServer ();
1337 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
1342 v = atoi (Cmd_Argv(2));
1356 // MED 01/04/97 added hipnotic give stuff
1357 if (gamemode == GAME_HIPNOTIC)
1362 sv_player->v->items = (int)sv_player->v->items | HIT_PROXIMITY_GUN;
1364 sv_player->v->items = (int)sv_player->v->items | IT_GRENADE_LAUNCHER;
1366 else if (t[0] == '9')
1367 sv_player->v->items = (int)sv_player->v->items | HIT_LASER_CANNON;
1368 else if (t[0] == '0')
1369 sv_player->v->items = (int)sv_player->v->items | HIT_MJOLNIR;
1370 else if (t[0] >= '2')
1371 sv_player->v->items = (int)sv_player->v->items | (IT_SHOTGUN << (t[0] - '2'));
1376 sv_player->v->items = (int)sv_player->v->items | (IT_SHOTGUN << (t[0] - '2'));
1381 if (gamemode == GAME_ROGUE && (val = GETEDICTFIELDVALUE(sv_player, eval_ammo_shells1)))
1384 sv_player->v->ammo_shells = v;
1387 if (gamemode == GAME_ROGUE)
1389 if ((val = GETEDICTFIELDVALUE(sv_player, eval_ammo_nails1)))
1392 if (sv_player->v->weapon <= IT_LIGHTNING)
1393 sv_player->v->ammo_nails = v;
1398 sv_player->v->ammo_nails = v;
1402 if (gamemode == GAME_ROGUE)
1404 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_lava_nails);
1408 if (sv_player->v->weapon > IT_LIGHTNING)
1409 sv_player->v->ammo_nails = v;
1414 if (gamemode == GAME_ROGUE)
1416 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_rockets1);
1420 if (sv_player->v->weapon <= IT_LIGHTNING)
1421 sv_player->v->ammo_rockets = v;
1426 sv_player->v->ammo_rockets = v;
1430 if (gamemode == GAME_ROGUE)
1432 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_multi_rockets);
1436 if (sv_player->v->weapon > IT_LIGHTNING)
1437 sv_player->v->ammo_rockets = v;
1442 sv_player->v->health = v;
1445 if (gamemode == GAME_ROGUE)
1447 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_cells1);
1451 if (sv_player->v->weapon <= IT_LIGHTNING)
1452 sv_player->v->ammo_cells = v;
1457 sv_player->v->ammo_cells = v;
1461 if (gamemode == GAME_ROGUE)
1463 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_plasma);
1467 if (sv_player->v->weapon > IT_LIGHTNING)
1468 sv_player->v->ammo_cells = v;
1475 edict_t *FindViewthing (void)
1480 for (i=0 ; i<sv.num_edicts ; i++)
1483 if (!strcmp (PR_GetString(e->v->classname), "viewthing"))
1486 Con_Print("No viewthing on map\n");
1495 void Host_Viewmodel_f (void)
1500 e = FindViewthing ();
1504 m = Mod_ForName (Cmd_Argv(1), false, true, false);
1507 Con_Printf("Can't load %s\n", Cmd_Argv(1));
1512 cl.model_precache[(int)e->v->modelindex] = m;
1520 void Host_Viewframe_f (void)
1526 e = FindViewthing ();
1529 m = cl.model_precache[(int)e->v->modelindex];
1531 f = atoi(Cmd_Argv(1));
1532 if (f >= m->numframes)
1539 void PrintFrameName (model_t *m, int frame)
1542 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1544 Con_Printf("frame %i\n", frame);
1552 void Host_Viewnext_f (void)
1557 e = FindViewthing ();
1560 m = cl.model_precache[(int)e->v->modelindex];
1562 e->v->frame = e->v->frame + 1;
1563 if (e->v->frame >= m->numframes)
1564 e->v->frame = m->numframes - 1;
1566 PrintFrameName (m, e->v->frame);
1574 void Host_Viewprev_f (void)
1579 e = FindViewthing ();
1583 m = cl.model_precache[(int)e->v->modelindex];
1585 e->v->frame = e->v->frame - 1;
1586 if (e->v->frame < 0)
1589 PrintFrameName (m, e->v->frame);
1593 ===============================================================================
1597 ===============================================================================
1606 void Host_Startdemos_f (void)
1610 if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
1614 if (gamemode == GAME_TRANSFUSION)
1615 Cbuf_AddText ("map bb1\n");
1617 Cbuf_AddText ("map start\n");
1625 Con_Printf("Max %i demos in demoloop\n", MAX_DEMOS);
1628 Con_DPrintf("%i demo(s) in loop\n", c);
1630 for (i=1 ; i<c+1 ; i++)
1631 strlcpy (cls.demos[i-1], Cmd_Argv(i), sizeof (cls.demos[i-1]));
1633 // LordHavoc: clear the remaining slots
1634 for (;i <= MAX_DEMOS;i++)
1635 cls.demos[i-1][0] = 0;
1637 if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
1651 Return to looping demos
1654 void Host_Demos_f (void)
1656 if (cls.state == ca_dedicated)
1658 if (cls.demonum == -1)
1668 Return to looping demos
1671 void Host_Stopdemo_f (void)
1673 if (!cls.demoplayback)
1678 static void MaxPlayers_f(void)
1682 if (Cmd_Argc() != 2)
1684 Con_Printf("\"maxplayers\" is \"%u\"\n", svs.maxclients);
1690 Con_Print("maxplayers can not be changed while a server is running.\n");
1694 n = atoi(Cmd_Argv(1));
1695 n = bound(1, n, MAX_SCOREBOARD);
1696 Con_Printf("\"maxplayers\" set to \"%u\"\n", n);
1699 Mem_Free(svs.clients);
1701 svs.clients = Mem_Alloc(sv_clients_mempool, sizeof(client_t) * svs.maxclients);
1703 Cvar_Set ("deathmatch", "0");
1705 Cvar_Set ("deathmatch", "1");
1708 //=============================================================================
1715 void Host_InitCommands (void)
1717 Cmd_AddCommand ("status", Host_Status_f);
1718 Cmd_AddCommand ("quit", Host_Quit_f);
1719 if (gamemode == GAME_NEHAHRA)
1721 Cmd_AddCommand ("max", Host_God_f);
1722 Cmd_AddCommand ("monster", Host_Notarget_f);
1723 Cmd_AddCommand ("scrag", Host_Fly_f);
1724 Cmd_AddCommand ("wraith", Host_Noclip_f);
1725 Cmd_AddCommand ("gimme", Host_Give_f);
1729 Cmd_AddCommand ("god", Host_God_f);
1730 Cmd_AddCommand ("notarget", Host_Notarget_f);
1731 Cmd_AddCommand ("fly", Host_Fly_f);
1732 Cmd_AddCommand ("noclip", Host_Noclip_f);
1733 Cmd_AddCommand ("give", Host_Give_f);
1735 Cmd_AddCommand ("map", Host_Map_f);
1736 Cmd_AddCommand ("restart", Host_Restart_f);
1737 Cmd_AddCommand ("changelevel", Host_Changelevel_f);
1738 Cmd_AddCommand ("connect", Host_Connect_f);
1739 Cmd_AddCommand ("reconnect", Host_Reconnect_f);
1740 Cmd_AddCommand ("version", Host_Version_f);
1741 Cmd_AddCommand ("say", Host_Say_f);
1742 Cmd_AddCommand ("say_team", Host_Say_Team_f);
1743 Cmd_AddCommand ("tell", Host_Tell_f);
1744 Cmd_AddCommand ("kill", Host_Kill_f);
1745 Cmd_AddCommand ("pause", Host_Pause_f);
1746 Cmd_AddCommand ("kick", Host_Kick_f);
1747 Cmd_AddCommand ("ping", Host_Ping_f);
1748 Cmd_AddCommand ("load", Host_Loadgame_f);
1749 Cmd_AddCommand ("save", Host_Savegame_f);
1751 Cmd_AddCommand ("startdemos", Host_Startdemos_f);
1752 Cmd_AddCommand ("demos", Host_Demos_f);
1753 Cmd_AddCommand ("stopdemo", Host_Stopdemo_f);
1755 Cmd_AddCommand ("viewmodel", Host_Viewmodel_f);
1756 Cmd_AddCommand ("viewframe", Host_Viewframe_f);
1757 Cmd_AddCommand ("viewnext", Host_Viewnext_f);
1758 Cmd_AddCommand ("viewprev", Host_Viewprev_f);
1760 Cvar_RegisterVariable (&cl_name);
1761 Cmd_AddCommand ("name", Host_Name_f);
1762 Cvar_RegisterVariable (&cl_color);
1763 Cmd_AddCommand ("color", Host_Color_f);
1764 Cvar_RegisterVariable (&cl_rate);
1765 Cmd_AddCommand ("rate", Host_Rate_f);
1766 Cvar_RegisterVariable (&sv_maxrate);
1767 if (gamemode == GAME_NEHAHRA)
1769 Cvar_RegisterVariable (&cl_pmodel);
1770 Cmd_AddCommand ("pmodel", Host_PModel_f);
1772 Cmd_AddCommand ("prespawn", Host_PreSpawn_f);
1773 Cmd_AddCommand ("spawn", Host_Spawn_f);
1774 Cmd_AddCommand ("begin", Host_Begin_f);
1775 Cmd_AddCommand ("maxplayers", MaxPlayers_f);
1777 Cvar_RegisterVariable(&sv_cheats);