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 void Host_Quit_f (void)
46 void Host_Status_f (void)
48 const char *protocolname;
50 int seconds, minutes, hours = 0, j, players;
51 void (*print) (const char *fmt, ...);
53 if (cmd_source == src_command)
57 Cmd_ForwardToServer ();
63 print = SV_ClientPrintf;
65 for (players = 0, j = 0;j < svs.maxclients;j++)
66 if (svs.clients[j].active)
68 print ("host: %s\n", Cvar_VariableString ("hostname"));
69 print ("version: %s build %s\n", gamename, buildstring);
72 case PROTOCOL_QUAKE: protocolname = sv.netquakecompatible ? "QUAKE" : "QUAKEDP";break;
73 case PROTOCOL_DARKPLACES1: protocolname = "PROTOCOL_DARKPLACES1";break;
74 case PROTOCOL_DARKPLACES2: protocolname = "PROTOCOL_DARKPLACES2";break;
75 case PROTOCOL_DARKPLACES3: protocolname = "PROTOCOL_DARKPLACES3";break;
76 case PROTOCOL_DARKPLACES4: protocolname = "PROTOCOL_DARKPLACES4";break;
77 case PROTOCOL_DARKPLACES5: protocolname = "PROTOCOL_DARKPLACES5";break;
78 default: protocolname = "PROTOCOL_UNKNOWN";break;
80 print ("protocol: %i (%s)\n", sv.protocol, protocolname);
81 print ("map: %s\n", sv.name);
82 print ("players: %i active (%i max)\n\n", players, svs.maxclients);
83 for (j = 0, client = svs.clients;j < svs.maxclients;j++, client++)
87 seconds = (int)(realtime - client->connecttime);
88 minutes = seconds / 60;
91 seconds -= (minutes * 60);
94 minutes -= (hours * 60);
98 print ("#%-2u %-16.16s %3i %2i:%02i:%02i\n", j+1, client->name, (int)client->edict->v->frags, hours, minutes, seconds);
99 print (" %s\n", client->netconnection ? client->netconnection->address : "botclient");
108 Sets client to godmode
111 void Host_God_f (void)
113 if (cmd_source == src_command)
115 Cmd_ForwardToServer ();
121 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
125 host_client->edict->v->flags = (int)host_client->edict->v->flags ^ FL_GODMODE;
126 if (!((int)host_client->edict->v->flags & FL_GODMODE) )
127 SV_ClientPrint("godmode OFF\n");
129 SV_ClientPrint("godmode ON\n");
132 void Host_Notarget_f (void)
134 if (cmd_source == src_command)
136 Cmd_ForwardToServer ();
142 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
146 host_client->edict->v->flags = (int)host_client->edict->v->flags ^ FL_NOTARGET;
147 if (!((int)host_client->edict->v->flags & FL_NOTARGET) )
148 SV_ClientPrint("notarget OFF\n");
150 SV_ClientPrint("notarget ON\n");
153 qboolean noclip_anglehack;
155 void Host_Noclip_f (void)
157 if (cmd_source == src_command)
159 Cmd_ForwardToServer ();
165 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
169 if (host_client->edict->v->movetype != MOVETYPE_NOCLIP)
171 noclip_anglehack = true;
172 host_client->edict->v->movetype = MOVETYPE_NOCLIP;
173 SV_ClientPrint("noclip ON\n");
177 noclip_anglehack = false;
178 host_client->edict->v->movetype = MOVETYPE_WALK;
179 SV_ClientPrint("noclip OFF\n");
187 Sets client to flymode
190 void Host_Fly_f (void)
192 if (cmd_source == src_command)
194 Cmd_ForwardToServer ();
200 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
204 if (host_client->edict->v->movetype != MOVETYPE_FLY)
206 host_client->edict->v->movetype = MOVETYPE_FLY;
207 SV_ClientPrint("flymode ON\n");
211 host_client->edict->v->movetype = MOVETYPE_WALK;
212 SV_ClientPrint("flymode OFF\n");
223 void Host_Ping_f (void)
229 if (cmd_source == src_command)
231 Cmd_ForwardToServer ();
235 SV_ClientPrint("Client ping times:\n");
236 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
241 for (j=0 ; j<NUM_PING_TIMES ; j++)
242 total+=client->ping_times[j];
243 total /= NUM_PING_TIMES;
244 SV_ClientPrintf("%4i %s\n", (int)(total*1000), client->name);
249 ===============================================================================
253 ===============================================================================
257 ======================
262 command from the console. Active clients are kicked off.
263 ======================
265 void Host_Map_f (void)
267 char level[MAX_QPATH];
271 Con_Print("map <levelname> : start a new game (kicks off all players)\n");
275 if (cmd_source != src_command)
278 SCR_BeginLoadingPlaque ();
279 cls.demonum = -1; // stop demo loop in case this fails
282 Host_ShutdownServer(false);
284 // remove console or menu
286 key_consoleactive = 0;
288 svs.serverflags = 0; // haven't completed an episode yet
289 allowcheats = sv_cheats.integer != 0;
290 strcpy(level, Cmd_Argv(1));
291 SV_SpawnServer(level);
292 if (sv.active && cls.state == ca_disconnected)
293 CL_EstablishConnection("local:1");
300 Goes to a new map, taking all clients along
303 void Host_Changelevel_f (void)
305 char level[MAX_QPATH];
309 Con_Print("changelevel <levelname> : continue game on a new level\n");
312 if (!sv.active || cls.demoplayback)
314 Con_Print("Only the server may changelevel\n");
317 if (cmd_source != src_command)
320 // remove console or menu
322 key_consoleactive = 0;
324 SV_SaveSpawnparms ();
325 SCR_BeginLoadingPlaque();
326 allowcheats = sv_cheats.integer != 0;
327 strcpy(level, Cmd_Argv(1));
328 SV_SpawnServer(level);
329 if (sv.active && cls.state == ca_disconnected)
330 CL_EstablishConnection("local:1");
337 Restarts the current server for a dead player
340 void Host_Restart_f (void)
342 char mapname[MAX_QPATH];
346 Con_Print("restart : restart current level\n");
349 if (!sv.active || cls.demoplayback)
351 Con_Print("Only the server may restart\n");
354 if (cmd_source != src_command)
357 // remove console or menu
359 key_consoleactive = 0;
361 SCR_BeginLoadingPlaque();
362 allowcheats = sv_cheats.integer != 0;
363 strcpy(mapname, sv.name);
364 SV_SpawnServer(mapname);
365 if (sv.active && cls.state == ca_disconnected)
366 CL_EstablishConnection("local:1");
373 This command causes the client to wait for the signon messages again.
374 This is sent just before a server changes levels
377 void Host_Reconnect_f (void)
381 Con_Print("reconnect : wait for signon messages again\n");
386 //Con_Print("reconnect: no signon, ignoring reconnect\n");
389 SCR_BeginLoadingPlaque();
390 cls.signon = 0; // need new connection messages
394 =====================
397 User command to connect to server
398 =====================
400 void Host_Connect_f (void)
404 Con_Print("connect <serveraddress> : connect to a multiplayer game\n");
407 CL_EstablishConnection(Cmd_Argv(1));
412 ===============================================================================
416 ===============================================================================
419 #define SAVEGAME_VERSION 5
425 Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
428 void Host_SavegameComment (char *text)
433 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
435 memcpy (text, cl.levelname, strlen(cl.levelname));
436 sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
437 memcpy (text+22, kills, strlen(kills));
438 // convert space to _ to make stdio happy
439 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
442 text[SAVEGAME_COMMENT_LENGTH] = '\0';
451 void Host_Savegame_f (void)
456 char comment[SAVEGAME_COMMENT_LENGTH+1];
458 if (cmd_source != src_command)
461 if (cls.state != ca_connected || !sv.active)
463 Con_Print("Not playing a local game.\n");
469 Con_Print("Can't save in intermission.\n");
473 for (i = 0;i < svs.maxclients;i++)
475 if (svs.clients[i].active)
479 Con_Print("Can't save multiplayer games.\n");
482 if (svs.clients[i].edict->v->deadflag)
484 Con_Print("Can't savegame with a dead player\n");
492 Con_Print("save <savename> : save a game\n");
496 if (strstr(Cmd_Argv(1), ".."))
498 Con_Print("Relative pathnames are not allowed.\n");
502 strlcpy (name, Cmd_Argv(1), sizeof (name));
503 FS_DefaultExtension (name, ".sav", sizeof (name));
505 Con_Printf("Saving game to %s...\n", name);
506 f = FS_Open (name, "w", false);
509 Con_Print("ERROR: couldn't open.\n");
513 FS_Printf(f, "%i\n", SAVEGAME_VERSION);
514 Host_SavegameComment (comment);
515 FS_Printf(f, "%s\n", comment);
516 for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
517 FS_Printf(f, "%f\n", svs.clients[0].spawn_parms[i]);
518 FS_Printf(f, "%d\n", current_skill);
519 FS_Printf(f, "%s\n", sv.name);
520 FS_Printf(f, "%f\n",sv.time);
522 // write the light styles
524 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
526 if (sv.lightstyles[i])
527 FS_Printf(f, "%s\n", sv.lightstyles[i]);
534 for (i=0 ; i<sv.num_edicts ; i++)
536 ED_Write (f, EDICT_NUM(i));
540 Con_Print("done.\n");
544 extern mempool_t *edictstring_mempool;
551 void Host_Loadgame_f (void)
554 char filename[MAX_QPATH];
555 char mapname[MAX_QPATH];
564 float spawn_parms[NUM_SPAWN_PARMS];
566 if (cmd_source != src_command)
571 Con_Print("load <savename> : load a game\n");
575 strcpy (filename, Cmd_Argv(1));
576 FS_DefaultExtension (filename, ".sav", sizeof (filename));
578 Con_Printf("Loading game from %s...\n", filename);
580 cls.demonum = -1; // stop demo loop in case this fails
582 f = FS_Open (filename, "r", false);
585 Con_Print("ERROR: couldn't open.\n");
589 str = FS_Getline (f);
590 sscanf (str, "%i\n", &version);
591 if (version != SAVEGAME_VERSION)
594 Con_Printf("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
598 SCR_BeginLoadingPlaque ();
600 str = FS_Getline (f);
601 for (i = 0;i < NUM_SPAWN_PARMS;i++)
603 str = FS_Getline (f);
604 sscanf (str, "%f\n", &spawn_parms[i]);
606 // this silliness is so we can load 1.06 save files, which have float skill values
607 str = FS_Getline (f);
608 sscanf (str, "%f\n", &tfloat);
609 current_skill = (int)(tfloat + 0.1);
610 Cvar_SetValue ("skill", (float)current_skill);
612 strcpy (mapname, FS_Getline (f));
614 str = FS_Getline (f);
615 sscanf (str, "%f\n",&time);
617 allowcheats = sv_cheats.integer != 0;
618 SV_SpawnServer (mapname);
621 Con_Print("Couldn't load map\n");
624 sv.paused = true; // pause until all clients connect
627 // load the light styles
629 for (i = 0;i < MAX_LIGHTSTYLES;i++)
631 str = FS_Getline (f);
632 sv.lightstyles[i] = Mem_Alloc(edictstring_mempool, strlen(str)+1);
633 strcpy (sv.lightstyles[i], str);
636 // load the edicts out of the savegame file
641 for (i = 0;i < (int)sizeof(buf) - 1;i++)
655 if (i == sizeof(buf)-1)
656 Host_Error ("Loadgame buffer overflow");
659 if (!COM_ParseToken(&start, false))
664 if (strcmp(com_token,"{"))
665 Host_Error ("First token isn't a brace");
669 // parse the global vars
670 ED_ParseGlobals (start);
675 if (entnum >= MAX_EDICTS)
676 Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)\n", MAX_EDICTS);
677 while (entnum >= sv.max_edicts)
679 ent = EDICT_NUM(entnum);
680 memset (ent->v, 0, progs->entityfields * 4);
681 ent->e->free = false;
682 ED_ParseEdict (start, ent);
684 // link it into the bsp tree
686 SV_LinkEdict (ent, false);
692 sv.num_edicts = entnum;
697 for (i = 0;i < NUM_SPAWN_PARMS;i++)
698 svs.clients[0].spawn_parms[i] = spawn_parms[i];
700 // make sure we're connected to loopback
701 if (cls.state == ca_disconnected || !(cls.state == ca_connected && cls.netcon != NULL && LHNETADDRESS_GetAddressType(&cls.netcon->peeraddress) == LHNETADDRESSTYPE_LOOP))
702 CL_EstablishConnection("local:1");
705 //============================================================================
708 ======================
710 ======================
712 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player"};
713 void Host_Name_f (void)
716 char newName[sizeof(host_client->name)];
718 if (Cmd_Argc () == 1)
720 Con_Printf("\"name\" is \"%s\"\n", cl_name.string);
724 if (Cmd_Argc () == 2)
725 strlcpy (newName, Cmd_Argv(1), sizeof (newName));
727 strlcpy (newName, Cmd_Args(), sizeof (newName));
729 for (i = 0, j = 0;newName[i];i++)
730 if (newName[i] != '\r' && newName[i] != '\n')
731 newName[j++] = newName[i];
734 if (cmd_source == src_command)
736 Cvar_Set ("_cl_name", newName);
737 if (cls.state == ca_connected)
738 Cmd_ForwardToServer ();
742 if (sv.time < host_client->nametime)
744 SV_ClientPrintf("You can't change name more than once every 5 seconds!\n");
748 host_client->nametime = sv.time + 5;
750 // point the string back at updateclient->name to keep it safe
751 strlcpy (host_client->name, newName, sizeof (host_client->name));
752 host_client->edict->v->netname = PR_SetString(host_client->name);
753 if (strcmp(host_client->old_name, host_client->name))
755 if (host_client->spawned)
756 SV_BroadcastPrintf("%s changed name to %s\n", host_client->old_name, host_client->name);
757 strcpy(host_client->old_name, host_client->name);
758 // send notification to all clients
759 MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
760 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
761 MSG_WriteString (&sv.reliable_datagram, host_client->name);
766 void Host_Version_f (void)
768 Con_Printf("Version: %s build %s\n", gamename, buildstring);
771 void Host_Say(qboolean teamonly)
777 // LordHavoc: 256 char say messages
778 unsigned char text[256];
779 qboolean fromServer = false;
781 if (cmd_source == src_command)
783 if (cls.state == ca_dedicated)
790 Cmd_ForwardToServer ();
798 if (!teamplay.integer)
801 // turn on color set 1
810 snprintf (text, sizeof(text), "%c%s: %s", 1, host_client->name, p1);
812 snprintf (text, sizeof(text), "%c<%s> %s", 1, hostname.string, p1);
813 p2 = text + strlen(text);
814 while ((const char *)p2 > (const char *)text && (p2[-1] == '\r' || p2[-1] == '\n' || (p2[-1] == '\"' && quoted)))
816 if (p2[-1] == '\"' && quoted)
821 strlcat(text, "\n", sizeof(text));
823 // note: save is not a valid edict if fromServer is true
825 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
826 if (host_client->spawned && (!teamonly || host_client->edict->v->team == save->edict->v->team))
827 SV_ClientPrint(text);
834 void Host_Say_f(void)
840 void Host_Say_Team_f(void)
846 void Host_Tell_f(void)
851 char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
852 qboolean fromServer = false;
854 if (cmd_source == src_command)
856 if (cls.state == ca_dedicated)
860 Cmd_ForwardToServer ();
869 sprintf (text, "%s: ", host_client->name);
871 sprintf (text, "<%s> ", hostname.string);
874 p2 = p1 + strlen(p1);
875 // remove the target name
876 while (p1 < p2 && *p1 != ' ')
878 while (p1 < p2 && *p1 == ' ')
880 // remove trailing newlines
881 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
883 // remove quotes if present
890 Con_Print("Host_Tell: missing end quote\n");
892 SV_ClientPrint("Host_Tell: missing end quote\n");
894 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
896 for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
902 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
903 if (host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1)))
904 SV_ClientPrint(text);
914 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0"};
915 void Host_Color_f(void)
920 func_t SV_ChangeTeam;
924 Con_Printf("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
925 Con_Print("color <0-15> [0-15]\n");
930 top = bottom = atoi(Cmd_Argv(1));
933 top = atoi(Cmd_Argv(1));
934 bottom = atoi(Cmd_Argv(2));
938 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
942 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
946 playercolor = top*16 + bottom;
948 if (cmd_source == src_command)
950 Cvar_SetValue ("_cl_color", playercolor);
951 if (cls.state == ca_connected)
952 Cmd_ForwardToServer ();
956 if (host_client->edict && (f = ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - pr_functions)))
958 Con_DPrint("Calling SV_ChangeTeam\n");
959 pr_global_struct->time = sv.time;
960 pr_globals[OFS_PARM0] = playercolor;
961 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
962 PR_ExecuteProgram (SV_ChangeTeam, "QC function SV_ChangeTeam is missing");
967 if (host_client->edict)
969 if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_clientcolors)))
970 val->_float = playercolor;
971 host_client->edict->v->team = bottom + 1;
973 host_client->colors = playercolor;
974 if (host_client->old_colors != host_client->colors)
976 host_client->old_colors = host_client->colors;
977 // send notification to all clients
978 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
979 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
980 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
985 cvar_t cl_rate = {CVAR_SAVE, "_cl_rate", "10000"};
986 void Host_Rate_f(void)
992 Con_Printf("\"rate\" is \"%i\"\n", cl_rate.integer);
993 Con_Print("rate <500-25000>\n");
997 rate = atoi(Cmd_Argv(1));
999 if (cmd_source == src_command)
1001 Cvar_SetValue ("_cl_rate", bound(NET_MINRATE, rate, NET_MAXRATE));
1002 if (cls.state == ca_connected)
1003 Cmd_ForwardToServer ();
1007 host_client->rate = rate;
1015 void Host_Kill_f (void)
1017 if (cmd_source == src_command)
1019 Cmd_ForwardToServer ();
1023 if (host_client->edict->v->health <= 0)
1025 SV_ClientPrint("Can't suicide -- already dead!\n");
1029 pr_global_struct->time = sv.time;
1030 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1031 PR_ExecuteProgram (pr_global_struct->ClientKill, "QC function ClientKill is missing");
1040 void Host_Pause_f (void)
1043 if (cmd_source == src_command)
1045 Cmd_ForwardToServer ();
1048 if (!pausable.integer)
1049 SV_ClientPrint("Pause not allowed.\n");
1053 SV_BroadcastPrintf("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
1054 // send notification to all clients
1055 MSG_WriteByte(&sv.reliable_datagram, svc_setpause);
1056 MSG_WriteByte(&sv.reliable_datagram, sv.paused);
1061 ======================
1063 LordHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
1064 ======================
1066 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0"};
1067 static void Host_PModel_f (void)
1072 if (Cmd_Argc () == 1)
1074 Con_Printf("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
1077 i = atoi(Cmd_Argv(1));
1079 if (cmd_source == src_command)
1081 if (cl_pmodel.integer == i)
1083 Cvar_SetValue ("_cl_pmodel", i);
1084 if (cls.state == ca_connected)
1085 Cmd_ForwardToServer ();
1089 if (host_client->edict && (val = GETEDICTFIELDVALUE(host_client->edict, eval_pmodel)))
1093 //===========================================================================
1101 void Host_PreSpawn_f (void)
1103 if (cmd_source == src_command)
1105 Con_Print("prespawn is not valid from the console\n");
1109 if (host_client->spawned)
1111 Con_Print("prespawn not valid -- already spawned\n");
1115 SZ_Write (&host_client->message, sv.signon.data, sv.signon.cursize);
1116 MSG_WriteByte (&host_client->message, svc_signonnum);
1117 MSG_WriteByte (&host_client->message, 2);
1118 host_client->sendsignon = true;
1120 // reset the name change timer because the client will send name soon
1121 host_client->nametime = 0;
1129 void Host_Spawn_f (void)
1136 if (cmd_source == src_command)
1138 Con_Print("spawn is not valid from the console\n");
1142 if (host_client->spawned)
1144 Con_Print("Spawn not valid -- already spawned\n");
1148 // reset name change timer again because they might want to change name
1149 // again in the first 5 seconds after connecting
1150 host_client->nametime = 0;
1152 // LordHavoc: moved this above the QC calls at FrikaC's request
1153 // send all current names, colors, and frag counts
1154 SZ_Clear (&host_client->message);
1156 // run the entrance script
1159 // loaded games are fully initialized already
1160 // if this is the last client to be connected, unpause
1163 if ((f = ED_FindFunction ("RestoreGame")))
1164 if ((RestoreGame = (func_t)(f - pr_functions)))
1166 Con_DPrint("Calling RestoreGame\n");
1167 pr_global_struct->time = sv.time;
1168 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1169 PR_ExecuteProgram (RestoreGame, "QC function RestoreGame is missing");
1175 ED_ClearEdict(host_client->edict);
1177 //Con_Printf("Host_Spawn_f: host_client->edict->netname = %s, host_client->edict->netname = %s, host_client->name = %s\n", PR_GetString(host_client->edict->v->netname), PR_GetString(host_client->edict->v->netname), host_client->name);
1179 // copy spawn parms out of the client_t
1180 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1181 (&pr_global_struct->parm1)[i] = host_client->spawn_parms[i];
1183 // call the spawn function
1184 pr_global_struct->time = sv.time;
1185 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1186 PR_ExecuteProgram (pr_global_struct->ClientConnect, "QC function ClientConnect is missing");
1188 if ((Sys_DoubleTime() - host_client->connecttime) <= sv.time)
1189 Sys_Printf("%s entered the game\n", host_client->name);
1191 PR_ExecuteProgram (pr_global_struct->PutClientInServer, "QC function PutClientInServer is missing");
1195 // send time of update
1196 MSG_WriteByte (&host_client->message, svc_time);
1197 MSG_WriteFloat (&host_client->message, sv.time);
1199 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
1201 if (!client->active)
1203 MSG_WriteByte (&host_client->message, svc_updatename);
1204 MSG_WriteByte (&host_client->message, i);
1205 MSG_WriteString (&host_client->message, client->name);
1206 MSG_WriteByte (&host_client->message, svc_updatefrags);
1207 MSG_WriteByte (&host_client->message, i);
1208 MSG_WriteShort (&host_client->message, client->frags);
1209 MSG_WriteByte (&host_client->message, svc_updatecolors);
1210 MSG_WriteByte (&host_client->message, i);
1211 MSG_WriteByte (&host_client->message, client->colors);
1214 // send all current light styles
1215 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1217 MSG_WriteByte (&host_client->message, svc_lightstyle);
1218 MSG_WriteByte (&host_client->message, (char)i);
1219 MSG_WriteString (&host_client->message, sv.lightstyles[i]);
1223 MSG_WriteByte (&host_client->message, svc_updatestat);
1224 MSG_WriteByte (&host_client->message, STAT_TOTALSECRETS);
1225 MSG_WriteLong (&host_client->message, pr_global_struct->total_secrets);
1227 MSG_WriteByte (&host_client->message, svc_updatestat);
1228 MSG_WriteByte (&host_client->message, STAT_TOTALMONSTERS);
1229 MSG_WriteLong (&host_client->message, pr_global_struct->total_monsters);
1231 MSG_WriteByte (&host_client->message, svc_updatestat);
1232 MSG_WriteByte (&host_client->message, STAT_SECRETS);
1233 MSG_WriteLong (&host_client->message, pr_global_struct->found_secrets);
1235 MSG_WriteByte (&host_client->message, svc_updatestat);
1236 MSG_WriteByte (&host_client->message, STAT_MONSTERS);
1237 MSG_WriteLong (&host_client->message, pr_global_struct->killed_monsters);
1240 // Never send a roll angle, because savegames can catch the server
1241 // in a state where it is expecting the client to correct the angle
1242 // and it won't happen if the game was just loaded, so you wind up
1243 // with a permanent head tilt
1244 MSG_WriteByte (&host_client->message, svc_setangle);
1245 MSG_WriteAngle (&host_client->message, host_client->edict->v->angles[0], sv.protocol);
1246 MSG_WriteAngle (&host_client->message, host_client->edict->v->angles[1], sv.protocol);
1247 MSG_WriteAngle (&host_client->message, 0, sv.protocol);
1249 SV_WriteClientdataToMessage (host_client->edict, &host_client->message);
1251 MSG_WriteByte (&host_client->message, svc_signonnum);
1252 MSG_WriteByte (&host_client->message, 3);
1253 host_client->sendsignon = true;
1261 void Host_Begin_f (void)
1263 if (cmd_source == src_command)
1265 Con_Print("begin is not valid from the console\n");
1269 host_client->spawned = true;
1272 //===========================================================================
1279 Kicks a user off of the server
1282 void Host_Kick_f (void)
1285 const char *message = NULL;
1288 qboolean byNumber = false;
1290 if (cmd_source != src_command || !sv.active)
1295 if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1297 i = atof(Cmd_Argv(2)) - 1;
1298 if (i < 0 || i >= svs.maxclients || !(host_client = svs.clients + i)->active)
1304 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1306 if (!host_client->active)
1308 if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1313 if (i < svs.maxclients)
1315 if (cmd_source == src_command)
1317 if (cls.state == ca_dedicated)
1320 who = cl_name.string;
1325 // can't kick yourself!
1326 if (host_client == save)
1331 message = Cmd_Args();
1332 COM_ParseToken(&message, false);
1335 message++; // skip the #
1336 while (*message == ' ') // skip white space
1338 message += strlen(Cmd_Argv(2)); // skip the number
1340 while (*message && *message == ' ')
1344 SV_ClientPrintf("Kicked by %s: %s\n", who, message);
1346 SV_ClientPrintf("Kicked by %s\n", who);
1347 SV_DropClient (false); // kicked
1354 ===============================================================================
1358 ===============================================================================
1366 void Host_Give_f (void)
1372 if (cmd_source == src_command)
1374 Cmd_ForwardToServer ();
1380 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
1385 v = atoi (Cmd_Argv(2));
1399 // MED 01/04/97 added hipnotic give stuff
1400 if (gamemode == GAME_HIPNOTIC)
1405 host_client->edict->v->items = (int)host_client->edict->v->items | HIT_PROXIMITY_GUN;
1407 host_client->edict->v->items = (int)host_client->edict->v->items | IT_GRENADE_LAUNCHER;
1409 else if (t[0] == '9')
1410 host_client->edict->v->items = (int)host_client->edict->v->items | HIT_LASER_CANNON;
1411 else if (t[0] == '0')
1412 host_client->edict->v->items = (int)host_client->edict->v->items | HIT_MJOLNIR;
1413 else if (t[0] >= '2')
1414 host_client->edict->v->items = (int)host_client->edict->v->items | (IT_SHOTGUN << (t[0] - '2'));
1419 host_client->edict->v->items = (int)host_client->edict->v->items | (IT_SHOTGUN << (t[0] - '2'));
1424 if (gamemode == GAME_ROGUE && (val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_shells1)))
1427 host_client->edict->v->ammo_shells = v;
1430 if (gamemode == GAME_ROGUE)
1432 if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_nails1)))
1435 if (host_client->edict->v->weapon <= IT_LIGHTNING)
1436 host_client->edict->v->ammo_nails = v;
1441 host_client->edict->v->ammo_nails = v;
1445 if (gamemode == GAME_ROGUE)
1447 val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_lava_nails);
1451 if (host_client->edict->v->weapon > IT_LIGHTNING)
1452 host_client->edict->v->ammo_nails = v;
1457 if (gamemode == GAME_ROGUE)
1459 val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_rockets1);
1463 if (host_client->edict->v->weapon <= IT_LIGHTNING)
1464 host_client->edict->v->ammo_rockets = v;
1469 host_client->edict->v->ammo_rockets = v;
1473 if (gamemode == GAME_ROGUE)
1475 val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_multi_rockets);
1479 if (host_client->edict->v->weapon > IT_LIGHTNING)
1480 host_client->edict->v->ammo_rockets = v;
1485 host_client->edict->v->health = v;
1488 if (gamemode == GAME_ROGUE)
1490 val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_cells1);
1494 if (host_client->edict->v->weapon <= IT_LIGHTNING)
1495 host_client->edict->v->ammo_cells = v;
1500 host_client->edict->v->ammo_cells = v;
1504 if (gamemode == GAME_ROGUE)
1506 val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_plasma);
1510 if (host_client->edict->v->weapon > IT_LIGHTNING)
1511 host_client->edict->v->ammo_cells = v;
1518 edict_t *FindViewthing (void)
1523 for (i=0 ; i<sv.num_edicts ; i++)
1526 if (!strcmp (PR_GetString(e->v->classname), "viewthing"))
1529 Con_Print("No viewthing on map\n");
1538 void Host_Viewmodel_f (void)
1543 e = FindViewthing ();
1547 m = Mod_ForName (Cmd_Argv(1), false, true, false);
1550 Con_Printf("Can't load %s\n", Cmd_Argv(1));
1555 cl.model_precache[(int)e->v->modelindex] = m;
1563 void Host_Viewframe_f (void)
1569 e = FindViewthing ();
1572 m = cl.model_precache[(int)e->v->modelindex];
1574 f = atoi(Cmd_Argv(1));
1575 if (f >= m->numframes)
1582 void PrintFrameName (model_t *m, int frame)
1585 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1587 Con_Printf("frame %i\n", frame);
1595 void Host_Viewnext_f (void)
1600 e = FindViewthing ();
1603 m = cl.model_precache[(int)e->v->modelindex];
1605 e->v->frame = e->v->frame + 1;
1606 if (e->v->frame >= m->numframes)
1607 e->v->frame = m->numframes - 1;
1609 PrintFrameName (m, e->v->frame);
1617 void Host_Viewprev_f (void)
1622 e = FindViewthing ();
1626 m = cl.model_precache[(int)e->v->modelindex];
1628 e->v->frame = e->v->frame - 1;
1629 if (e->v->frame < 0)
1632 PrintFrameName (m, e->v->frame);
1636 ===============================================================================
1640 ===============================================================================
1649 void Host_Startdemos_f (void)
1653 if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
1659 Con_Printf("Max %i demos in demoloop\n", MAX_DEMOS);
1662 Con_DPrintf("%i demo(s) in loop\n", c);
1664 for (i=1 ; i<c+1 ; i++)
1665 strlcpy (cls.demos[i-1], Cmd_Argv(i), sizeof (cls.demos[i-1]));
1667 // LordHavoc: clear the remaining slots
1668 for (;i <= MAX_DEMOS;i++)
1669 cls.demos[i-1][0] = 0;
1671 if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
1685 Return to looping demos
1688 void Host_Demos_f (void)
1690 if (cls.state == ca_dedicated)
1692 if (cls.demonum == -1)
1702 Return to looping demos
1705 void Host_Stopdemo_f (void)
1707 if (!cls.demoplayback)
1710 Host_ShutdownServer (false);
1713 static void MaxPlayers_f(void)
1717 if (Cmd_Argc() != 2)
1719 Con_Printf("\"maxplayers\" is \"%u\"\n", svs.maxclients);
1725 Con_Print("maxplayers can not be changed while a server is running.\n");
1729 n = atoi(Cmd_Argv(1));
1730 n = bound(1, n, MAX_SCOREBOARD);
1731 Con_Printf("\"maxplayers\" set to \"%u\"\n", n);
1734 Mem_Free(svs.clients);
1736 svs.clients = Mem_Alloc(sv_clients_mempool, sizeof(client_t) * svs.maxclients);
1738 Cvar_Set ("deathmatch", "0");
1740 Cvar_Set ("deathmatch", "1");
1743 //=============================================================================
1750 void Host_InitCommands (void)
1752 Cmd_AddCommand ("status", Host_Status_f);
1753 Cmd_AddCommand ("quit", Host_Quit_f);
1754 if (gamemode == GAME_NEHAHRA)
1756 Cmd_AddCommand ("max", Host_God_f);
1757 Cmd_AddCommand ("monster", Host_Notarget_f);
1758 Cmd_AddCommand ("scrag", Host_Fly_f);
1759 Cmd_AddCommand ("wraith", Host_Noclip_f);
1760 Cmd_AddCommand ("gimme", Host_Give_f);
1764 Cmd_AddCommand ("god", Host_God_f);
1765 Cmd_AddCommand ("notarget", Host_Notarget_f);
1766 Cmd_AddCommand ("fly", Host_Fly_f);
1767 Cmd_AddCommand ("noclip", Host_Noclip_f);
1768 Cmd_AddCommand ("give", Host_Give_f);
1770 Cmd_AddCommand ("map", Host_Map_f);
1771 Cmd_AddCommand ("restart", Host_Restart_f);
1772 Cmd_AddCommand ("changelevel", Host_Changelevel_f);
1773 Cmd_AddCommand ("connect", Host_Connect_f);
1774 Cmd_AddCommand ("reconnect", Host_Reconnect_f);
1775 Cmd_AddCommand ("version", Host_Version_f);
1776 Cmd_AddCommand ("say", Host_Say_f);
1777 Cmd_AddCommand ("say_team", Host_Say_Team_f);
1778 Cmd_AddCommand ("tell", Host_Tell_f);
1779 Cmd_AddCommand ("kill", Host_Kill_f);
1780 Cmd_AddCommand ("pause", Host_Pause_f);
1781 Cmd_AddCommand ("kick", Host_Kick_f);
1782 Cmd_AddCommand ("ping", Host_Ping_f);
1783 Cmd_AddCommand ("load", Host_Loadgame_f);
1784 Cmd_AddCommand ("save", Host_Savegame_f);
1786 Cmd_AddCommand ("startdemos", Host_Startdemos_f);
1787 Cmd_AddCommand ("demos", Host_Demos_f);
1788 Cmd_AddCommand ("stopdemo", Host_Stopdemo_f);
1790 Cmd_AddCommand ("viewmodel", Host_Viewmodel_f);
1791 Cmd_AddCommand ("viewframe", Host_Viewframe_f);
1792 Cmd_AddCommand ("viewnext", Host_Viewnext_f);
1793 Cmd_AddCommand ("viewprev", Host_Viewprev_f);
1795 Cvar_RegisterVariable (&cl_name);
1796 Cmd_AddCommand ("name", Host_Name_f);
1797 Cvar_RegisterVariable (&cl_color);
1798 Cmd_AddCommand ("color", Host_Color_f);
1799 Cvar_RegisterVariable (&cl_rate);
1800 Cmd_AddCommand ("rate", Host_Rate_f);
1801 if (gamemode == GAME_NEHAHRA)
1803 Cvar_RegisterVariable (&cl_pmodel);
1804 Cmd_AddCommand ("pmodel", Host_PModel_f);
1806 Cmd_AddCommand ("prespawn", Host_PreSpawn_f);
1807 Cmd_AddCommand ("spawn", Host_Spawn_f);
1808 Cmd_AddCommand ("begin", Host_Begin_f);
1809 Cmd_AddCommand ("maxplayers", MaxPlayers_f);
1811 Cvar_RegisterVariable(&sv_cheats);