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 case PROTOCOL_DARKPLACES6: protocolname = "PROTOCOL_DARKPLACES6";break;
79 default: protocolname = "PROTOCOL_UNKNOWN";break;
81 print ("protocol: %i (%s)\n", sv.protocol, protocolname);
82 print ("map: %s\n", sv.name);
83 print ("players: %i active (%i max)\n\n", players, svs.maxclients);
84 for (j = 0, client = svs.clients;j < svs.maxclients;j++, client++)
88 seconds = (int)(realtime - client->connecttime);
89 minutes = seconds / 60;
92 seconds -= (minutes * 60);
95 minutes -= (hours * 60);
99 print ("#%-2u %-16.16s %3i %2i:%02i:%02i\n", j+1, client->name, (int)client->edict->v->frags, hours, minutes, seconds);
100 print (" %s\n", client->netconnection ? client->netconnection->address : "botclient");
109 Sets client to godmode
112 void Host_God_f (void)
114 if (cmd_source == src_command)
116 Cmd_ForwardToServer ();
122 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
126 host_client->edict->v->flags = (int)host_client->edict->v->flags ^ FL_GODMODE;
127 if (!((int)host_client->edict->v->flags & FL_GODMODE) )
128 SV_ClientPrint("godmode OFF\n");
130 SV_ClientPrint("godmode ON\n");
133 void Host_Notarget_f (void)
135 if (cmd_source == src_command)
137 Cmd_ForwardToServer ();
143 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
147 host_client->edict->v->flags = (int)host_client->edict->v->flags ^ FL_NOTARGET;
148 if (!((int)host_client->edict->v->flags & FL_NOTARGET) )
149 SV_ClientPrint("notarget OFF\n");
151 SV_ClientPrint("notarget ON\n");
154 qboolean noclip_anglehack;
156 void Host_Noclip_f (void)
158 if (cmd_source == src_command)
160 Cmd_ForwardToServer ();
166 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
170 if (host_client->edict->v->movetype != MOVETYPE_NOCLIP)
172 noclip_anglehack = true;
173 host_client->edict->v->movetype = MOVETYPE_NOCLIP;
174 SV_ClientPrint("noclip ON\n");
178 noclip_anglehack = false;
179 host_client->edict->v->movetype = MOVETYPE_WALK;
180 SV_ClientPrint("noclip OFF\n");
188 Sets client to flymode
191 void Host_Fly_f (void)
193 if (cmd_source == src_command)
195 Cmd_ForwardToServer ();
201 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
205 if (host_client->edict->v->movetype != MOVETYPE_FLY)
207 host_client->edict->v->movetype = MOVETYPE_FLY;
208 SV_ClientPrint("flymode ON\n");
212 host_client->edict->v->movetype = MOVETYPE_WALK;
213 SV_ClientPrint("flymode OFF\n");
224 void Host_Ping_f (void)
230 if (cmd_source == src_command)
232 Cmd_ForwardToServer ();
236 SV_ClientPrint("Client ping times:\n");
237 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
242 for (j=0 ; j<NUM_PING_TIMES ; j++)
243 total+=client->ping_times[j];
244 total /= NUM_PING_TIMES;
245 SV_ClientPrintf("%4i %s\n", (int)(total*1000), client->name);
250 ===============================================================================
254 ===============================================================================
258 ======================
263 command from the console. Active clients are kicked off.
264 ======================
266 void Host_Map_f (void)
268 char level[MAX_QPATH];
272 Con_Print("map <levelname> : start a new game (kicks off all players)\n");
276 if (cmd_source != src_command)
279 SCR_BeginLoadingPlaque ();
280 cls.demonum = -1; // stop demo loop in case this fails
283 Host_ShutdownServer(false);
285 // remove console or menu
287 key_consoleactive = 0;
289 svs.serverflags = 0; // haven't completed an episode yet
290 allowcheats = sv_cheats.integer != 0;
291 strcpy(level, Cmd_Argv(1));
292 SV_SpawnServer(level);
293 if (sv.active && cls.state == ca_disconnected)
294 CL_EstablishConnection("local:1");
301 Goes to a new map, taking all clients along
304 void Host_Changelevel_f (void)
306 char level[MAX_QPATH];
310 Con_Print("changelevel <levelname> : continue game on a new level\n");
313 if (!sv.active || cls.demoplayback)
315 Con_Print("Only the server may changelevel\n");
318 if (cmd_source != src_command)
321 // remove console or menu
323 key_consoleactive = 0;
325 SV_SaveSpawnparms ();
326 SCR_BeginLoadingPlaque();
327 allowcheats = sv_cheats.integer != 0;
328 strcpy(level, Cmd_Argv(1));
329 SV_SpawnServer(level);
330 if (sv.active && cls.state == ca_disconnected)
331 CL_EstablishConnection("local:1");
338 Restarts the current server for a dead player
341 void Host_Restart_f (void)
343 char mapname[MAX_QPATH];
347 Con_Print("restart : restart current level\n");
350 if (!sv.active || cls.demoplayback)
352 Con_Print("Only the server may restart\n");
355 if (cmd_source != src_command)
358 // remove console or menu
360 key_consoleactive = 0;
362 SCR_BeginLoadingPlaque();
363 allowcheats = sv_cheats.integer != 0;
364 strcpy(mapname, sv.name);
365 SV_SpawnServer(mapname);
366 if (sv.active && cls.state == ca_disconnected)
367 CL_EstablishConnection("local:1");
374 This command causes the client to wait for the signon messages again.
375 This is sent just before a server changes levels
378 void Host_Reconnect_f (void)
382 Con_Print("reconnect : wait for signon messages again\n");
387 //Con_Print("reconnect: no signon, ignoring reconnect\n");
390 SCR_BeginLoadingPlaque();
391 cls.signon = 0; // need new connection messages
395 =====================
398 User command to connect to server
399 =====================
401 void Host_Connect_f (void)
405 Con_Print("connect <serveraddress> : connect to a multiplayer game\n");
408 CL_EstablishConnection(Cmd_Argv(1));
413 ===============================================================================
417 ===============================================================================
420 #define SAVEGAME_VERSION 5
426 Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
429 void Host_SavegameComment (char *text)
434 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
436 memcpy (text, cl.levelname, strlen(cl.levelname));
437 sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
438 memcpy (text+22, kills, strlen(kills));
439 // convert space to _ to make stdio happy
440 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
443 text[SAVEGAME_COMMENT_LENGTH] = '\0';
452 void Host_Savegame_f (void)
457 char comment[SAVEGAME_COMMENT_LENGTH+1];
459 if (cmd_source != src_command)
462 if (cls.state != ca_connected || !sv.active)
464 Con_Print("Not playing a local game.\n");
470 Con_Print("Can't save in intermission.\n");
474 for (i = 0;i < svs.maxclients;i++)
476 if (svs.clients[i].active)
480 Con_Print("Can't save multiplayer games.\n");
483 if (svs.clients[i].edict->v->deadflag)
485 Con_Print("Can't savegame with a dead player\n");
493 Con_Print("save <savename> : save a game\n");
497 if (strstr(Cmd_Argv(1), ".."))
499 Con_Print("Relative pathnames are not allowed.\n");
503 strlcpy (name, Cmd_Argv(1), sizeof (name));
504 FS_DefaultExtension (name, ".sav", sizeof (name));
506 Con_Printf("Saving game to %s...\n", name);
507 f = FS_Open (name, "w", false);
510 Con_Print("ERROR: couldn't open.\n");
514 FS_Printf(f, "%i\n", SAVEGAME_VERSION);
515 Host_SavegameComment (comment);
516 FS_Printf(f, "%s\n", comment);
517 for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
518 FS_Printf(f, "%f\n", svs.clients[0].spawn_parms[i]);
519 FS_Printf(f, "%d\n", current_skill);
520 FS_Printf(f, "%s\n", sv.name);
521 FS_Printf(f, "%f\n",sv.time);
523 // write the light styles
525 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
527 if (sv.lightstyles[i])
528 FS_Printf(f, "%s\n", sv.lightstyles[i]);
535 for (i=0 ; i<sv.num_edicts ; i++)
537 ED_Write (f, EDICT_NUM(i));
541 Con_Print("done.\n");
545 extern mempool_t *edictstring_mempool;
552 void Host_Loadgame_f (void)
555 char filename[MAX_QPATH];
556 char mapname[MAX_QPATH];
565 float spawn_parms[NUM_SPAWN_PARMS];
567 if (cmd_source != src_command)
572 Con_Print("load <savename> : load a game\n");
576 strcpy (filename, Cmd_Argv(1));
577 FS_DefaultExtension (filename, ".sav", sizeof (filename));
579 Con_Printf("Loading game from %s...\n", filename);
581 cls.demonum = -1; // stop demo loop in case this fails
583 f = FS_Open (filename, "r", false);
586 Con_Print("ERROR: couldn't open.\n");
590 str = FS_Getline (f);
591 sscanf (str, "%i\n", &version);
592 if (version != SAVEGAME_VERSION)
595 Con_Printf("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
599 SCR_BeginLoadingPlaque ();
601 str = FS_Getline (f);
602 for (i = 0;i < NUM_SPAWN_PARMS;i++)
604 str = FS_Getline (f);
605 sscanf (str, "%f\n", &spawn_parms[i]);
607 // this silliness is so we can load 1.06 save files, which have float skill values
608 str = FS_Getline (f);
609 sscanf (str, "%f\n", &tfloat);
610 current_skill = (int)(tfloat + 0.1);
611 Cvar_SetValue ("skill", (float)current_skill);
613 strcpy (mapname, FS_Getline (f));
615 str = FS_Getline (f);
616 sscanf (str, "%f\n",&time);
618 allowcheats = sv_cheats.integer != 0;
619 SV_SpawnServer (mapname);
622 Con_Print("Couldn't load map\n");
625 sv.paused = true; // pause until all clients connect
628 // load the light styles
630 for (i = 0;i < MAX_LIGHTSTYLES;i++)
632 str = FS_Getline (f);
633 sv.lightstyles[i] = Mem_Alloc(edictstring_mempool, strlen(str)+1);
634 strcpy (sv.lightstyles[i], str);
637 // load the edicts out of the savegame file
643 for (i = 0;i < (int)sizeof(buf) - 1;i++)
657 if (i == sizeof(buf)-1)
658 Host_Error ("Loadgame buffer overflow");
661 if (!COM_ParseToken(&start, false))
666 if (strcmp(com_token,"{"))
667 Host_Error ("First token isn't a brace");
671 // parse the global vars
672 ED_ParseGlobals (start);
677 if (entnum >= MAX_EDICTS)
678 Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)\n", MAX_EDICTS);
679 while (entnum >= sv.max_edicts)
681 ent = EDICT_NUM(entnum);
682 memset (ent->v, 0, progs->entityfields * 4);
683 ent->e->free = false;
684 ED_ParseEdict (start, ent);
686 // link it into the bsp tree
688 SV_LinkEdict (ent, false);
694 sv.num_edicts = entnum;
699 for (i = 0;i < NUM_SPAWN_PARMS;i++)
700 svs.clients[0].spawn_parms[i] = spawn_parms[i];
702 // make sure we're connected to loopback
703 if (cls.state == ca_disconnected || !(cls.state == ca_connected && cls.netcon != NULL && LHNETADDRESS_GetAddressType(&cls.netcon->peeraddress) == LHNETADDRESSTYPE_LOOP))
704 CL_EstablishConnection("local:1");
707 //============================================================================
710 ======================
712 ======================
714 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player"};
715 void Host_Name_f (void)
718 char newName[sizeof(host_client->name)];
720 if (Cmd_Argc () == 1)
722 Con_Printf("\"name\" is \"%s\"\n", cl_name.string);
726 if (Cmd_Argc () == 2)
727 strlcpy (newName, Cmd_Argv(1), sizeof (newName));
729 strlcpy (newName, Cmd_Args(), sizeof (newName));
731 for (i = 0, j = 0;newName[i];i++)
732 if (newName[i] != '\r' && newName[i] != '\n')
733 newName[j++] = newName[i];
736 if (cmd_source == src_command)
738 Cvar_Set ("_cl_name", newName);
739 if (cls.state == ca_connected)
740 Cmd_ForwardToServer ();
744 if (sv.time < host_client->nametime)
746 SV_ClientPrintf("You can't change name more than once every 5 seconds!\n");
750 host_client->nametime = sv.time + 5;
752 // point the string back at updateclient->name to keep it safe
753 strlcpy (host_client->name, newName, sizeof (host_client->name));
754 host_client->edict->v->netname = PR_SetString(host_client->name);
755 if (strcmp(host_client->old_name, host_client->name))
757 if (host_client->spawned)
758 SV_BroadcastPrintf("%s changed name to %s\n", host_client->old_name, host_client->name);
759 strcpy(host_client->old_name, host_client->name);
760 // send notification to all clients
761 MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
762 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
763 MSG_WriteString (&sv.reliable_datagram, host_client->name);
768 void Host_Version_f (void)
770 Con_Printf("Version: %s build %s\n", gamename, buildstring);
773 void Host_Say(qboolean teamonly)
779 // LordHavoc: 256 char say messages
780 unsigned char text[256];
781 qboolean fromServer = false;
783 if (cmd_source == src_command)
785 if (cls.state == ca_dedicated)
792 Cmd_ForwardToServer ();
800 if (!teamplay.integer)
803 // turn on color set 1
812 snprintf (text, sizeof(text), "%c%s: %s", 1, host_client->name, p1);
814 snprintf (text, sizeof(text), "%c<%s> %s", 1, hostname.string, p1);
815 p2 = text + strlen(text);
816 while ((const char *)p2 > (const char *)text && (p2[-1] == '\r' || p2[-1] == '\n' || (p2[-1] == '\"' && quoted)))
818 if (p2[-1] == '\"' && quoted)
823 strlcat(text, "\n", sizeof(text));
825 // note: save is not a valid edict if fromServer is true
827 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
828 if (host_client->spawned && (!teamonly || host_client->edict->v->team == save->edict->v->team))
829 SV_ClientPrint(text);
836 void Host_Say_f(void)
842 void Host_Say_Team_f(void)
848 void Host_Tell_f(void)
853 char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
854 qboolean fromServer = false;
856 if (cmd_source == src_command)
858 if (cls.state == ca_dedicated)
862 Cmd_ForwardToServer ();
871 sprintf (text, "%s: ", host_client->name);
873 sprintf (text, "<%s> ", hostname.string);
876 p2 = p1 + strlen(p1);
877 // remove the target name
878 while (p1 < p2 && *p1 != ' ')
880 while (p1 < p2 && *p1 == ' ')
882 // remove trailing newlines
883 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
885 // remove quotes if present
892 Con_Print("Host_Tell: missing end quote\n");
894 SV_ClientPrint("Host_Tell: missing end quote\n");
896 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
898 for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
904 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
905 if (host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1)))
906 SV_ClientPrint(text);
916 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0"};
917 void Host_Color_f(void)
922 func_t SV_ChangeTeam;
926 Con_Printf("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
927 Con_Print("color <0-15> [0-15]\n");
932 top = bottom = atoi(Cmd_Argv(1));
935 top = atoi(Cmd_Argv(1));
936 bottom = atoi(Cmd_Argv(2));
940 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
944 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
948 playercolor = top*16 + bottom;
950 if (cmd_source == src_command)
952 Cvar_SetValue ("_cl_color", playercolor);
953 if (cls.state == ca_connected)
954 Cmd_ForwardToServer ();
958 if (host_client->edict && (f = ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - pr_functions)))
960 Con_DPrint("Calling SV_ChangeTeam\n");
961 pr_global_struct->time = sv.time;
962 pr_globals[OFS_PARM0] = playercolor;
963 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
964 PR_ExecuteProgram (SV_ChangeTeam, "QC function SV_ChangeTeam is missing");
969 if (host_client->edict)
971 if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_clientcolors)))
972 val->_float = playercolor;
973 host_client->edict->v->team = bottom + 1;
975 host_client->colors = playercolor;
976 if (host_client->old_colors != host_client->colors)
978 host_client->old_colors = host_client->colors;
979 // send notification to all clients
980 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
981 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
982 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
987 cvar_t cl_rate = {CVAR_SAVE, "_cl_rate", "10000"};
988 void Host_Rate_f(void)
994 Con_Printf("\"rate\" is \"%i\"\n", cl_rate.integer);
995 Con_Print("rate <500-25000>\n");
999 rate = atoi(Cmd_Argv(1));
1001 if (cmd_source == src_command)
1003 Cvar_SetValue ("_cl_rate", bound(NET_MINRATE, rate, NET_MAXRATE));
1004 if (cls.state == ca_connected)
1005 Cmd_ForwardToServer ();
1009 host_client->rate = rate;
1017 void Host_Kill_f (void)
1019 if (cmd_source == src_command)
1021 Cmd_ForwardToServer ();
1025 if (host_client->edict->v->health <= 0)
1027 SV_ClientPrint("Can't suicide -- already dead!\n");
1031 pr_global_struct->time = sv.time;
1032 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1033 PR_ExecuteProgram (pr_global_struct->ClientKill, "QC function ClientKill is missing");
1042 void Host_Pause_f (void)
1045 if (cmd_source == src_command)
1047 Cmd_ForwardToServer ();
1050 if (!pausable.integer)
1051 SV_ClientPrint("Pause not allowed.\n");
1055 SV_BroadcastPrintf("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
1056 // send notification to all clients
1057 MSG_WriteByte(&sv.reliable_datagram, svc_setpause);
1058 MSG_WriteByte(&sv.reliable_datagram, sv.paused);
1063 ======================
1065 LordHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
1066 ======================
1068 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0"};
1069 static void Host_PModel_f (void)
1074 if (Cmd_Argc () == 1)
1076 Con_Printf("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
1079 i = atoi(Cmd_Argv(1));
1081 if (cmd_source == src_command)
1083 if (cl_pmodel.integer == i)
1085 Cvar_SetValue ("_cl_pmodel", i);
1086 if (cls.state == ca_connected)
1087 Cmd_ForwardToServer ();
1091 if (host_client->edict && (val = GETEDICTFIELDVALUE(host_client->edict, eval_pmodel)))
1095 //===========================================================================
1103 void Host_PreSpawn_f (void)
1105 if (cmd_source == src_command)
1107 Con_Print("prespawn is not valid from the console\n");
1111 if (host_client->spawned)
1113 Con_Print("prespawn not valid -- already spawned\n");
1117 SZ_Write (&host_client->message, sv.signon.data, sv.signon.cursize);
1118 MSG_WriteByte (&host_client->message, svc_signonnum);
1119 MSG_WriteByte (&host_client->message, 2);
1120 host_client->sendsignon = true;
1122 // reset the name change timer because the client will send name soon
1123 host_client->nametime = 0;
1131 void Host_Spawn_f (void)
1137 int stats[MAX_CL_STATS];
1139 if (cmd_source == src_command)
1141 Con_Print("spawn is not valid from the console\n");
1145 if (host_client->spawned)
1147 Con_Print("Spawn not valid -- already spawned\n");
1151 // reset name change timer again because they might want to change name
1152 // again in the first 5 seconds after connecting
1153 host_client->nametime = 0;
1155 // LordHavoc: moved this above the QC calls at FrikaC's request
1156 // send all current names, colors, and frag counts
1157 SZ_Clear (&host_client->message);
1159 // run the entrance script
1162 // loaded games are fully initialized already
1163 // if this is the last client to be connected, unpause
1166 if ((f = ED_FindFunction ("RestoreGame")))
1167 if ((RestoreGame = (func_t)(f - pr_functions)))
1169 Con_DPrint("Calling RestoreGame\n");
1170 pr_global_struct->time = sv.time;
1171 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1172 PR_ExecuteProgram (RestoreGame, "QC function RestoreGame is missing");
1178 ED_ClearEdict(host_client->edict);
1180 //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);
1182 // copy spawn parms out of the client_t
1183 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1184 (&pr_global_struct->parm1)[i] = host_client->spawn_parms[i];
1186 // call the spawn function
1187 pr_global_struct->time = sv.time;
1188 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1189 PR_ExecuteProgram (pr_global_struct->ClientConnect, "QC function ClientConnect is missing");
1191 if ((Sys_DoubleTime() - host_client->connecttime) <= sv.time)
1192 Sys_Printf("%s entered the game\n", host_client->name);
1194 PR_ExecuteProgram (pr_global_struct->PutClientInServer, "QC function PutClientInServer is missing");
1198 // send time of update
1199 MSG_WriteByte (&host_client->message, svc_time);
1200 MSG_WriteFloat (&host_client->message, sv.time);
1202 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
1204 if (!client->active)
1206 MSG_WriteByte (&host_client->message, svc_updatename);
1207 MSG_WriteByte (&host_client->message, i);
1208 MSG_WriteString (&host_client->message, client->name);
1209 MSG_WriteByte (&host_client->message, svc_updatefrags);
1210 MSG_WriteByte (&host_client->message, i);
1211 MSG_WriteShort (&host_client->message, client->frags);
1212 MSG_WriteByte (&host_client->message, svc_updatecolors);
1213 MSG_WriteByte (&host_client->message, i);
1214 MSG_WriteByte (&host_client->message, client->colors);
1217 // send all current light styles
1218 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1220 MSG_WriteByte (&host_client->message, svc_lightstyle);
1221 MSG_WriteByte (&host_client->message, (char)i);
1222 MSG_WriteString (&host_client->message, sv.lightstyles[i]);
1226 MSG_WriteByte (&host_client->message, svc_updatestat);
1227 MSG_WriteByte (&host_client->message, STAT_TOTALSECRETS);
1228 MSG_WriteLong (&host_client->message, pr_global_struct->total_secrets);
1230 MSG_WriteByte (&host_client->message, svc_updatestat);
1231 MSG_WriteByte (&host_client->message, STAT_TOTALMONSTERS);
1232 MSG_WriteLong (&host_client->message, pr_global_struct->total_monsters);
1234 MSG_WriteByte (&host_client->message, svc_updatestat);
1235 MSG_WriteByte (&host_client->message, STAT_SECRETS);
1236 MSG_WriteLong (&host_client->message, pr_global_struct->found_secrets);
1238 MSG_WriteByte (&host_client->message, svc_updatestat);
1239 MSG_WriteByte (&host_client->message, STAT_MONSTERS);
1240 MSG_WriteLong (&host_client->message, pr_global_struct->killed_monsters);
1243 // Never send a roll angle, because savegames can catch the server
1244 // in a state where it is expecting the client to correct the angle
1245 // and it won't happen if the game was just loaded, so you wind up
1246 // with a permanent head tilt
1247 MSG_WriteByte (&host_client->message, svc_setangle);
1248 MSG_WriteAngle (&host_client->message, host_client->edict->v->angles[0], sv.protocol);
1249 MSG_WriteAngle (&host_client->message, host_client->edict->v->angles[1], sv.protocol);
1250 MSG_WriteAngle (&host_client->message, 0, sv.protocol);
1252 SV_WriteClientdataToMessage (host_client, host_client->edict, &host_client->message, stats);
1254 MSG_WriteByte (&host_client->message, svc_signonnum);
1255 MSG_WriteByte (&host_client->message, 3);
1256 host_client->sendsignon = true;
1264 void Host_Begin_f (void)
1266 if (cmd_source == src_command)
1268 Con_Print("begin is not valid from the console\n");
1272 host_client->spawned = true;
1275 //===========================================================================
1282 Kicks a user off of the server
1285 void Host_Kick_f (void)
1288 const char *message = NULL;
1291 qboolean byNumber = false;
1293 if (cmd_source != src_command || !sv.active)
1298 if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1300 i = atof(Cmd_Argv(2)) - 1;
1301 if (i < 0 || i >= svs.maxclients || !(host_client = svs.clients + i)->active)
1307 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1309 if (!host_client->active)
1311 if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1316 if (i < svs.maxclients)
1318 if (cmd_source == src_command)
1320 if (cls.state == ca_dedicated)
1323 who = cl_name.string;
1328 // can't kick yourself!
1329 if (host_client == save)
1334 message = Cmd_Args();
1335 COM_ParseToken(&message, false);
1338 message++; // skip the #
1339 while (*message == ' ') // skip white space
1341 message += strlen(Cmd_Argv(2)); // skip the number
1343 while (*message && *message == ' ')
1347 SV_ClientPrintf("Kicked by %s: %s\n", who, message);
1349 SV_ClientPrintf("Kicked by %s\n", who);
1350 SV_DropClient (false); // kicked
1357 ===============================================================================
1361 ===============================================================================
1369 void Host_Give_f (void)
1375 if (cmd_source == src_command)
1377 Cmd_ForwardToServer ();
1383 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
1388 v = atoi (Cmd_Argv(2));
1402 // MED 01/04/97 added hipnotic give stuff
1403 if (gamemode == GAME_HIPNOTIC)
1408 host_client->edict->v->items = (int)host_client->edict->v->items | HIT_PROXIMITY_GUN;
1410 host_client->edict->v->items = (int)host_client->edict->v->items | IT_GRENADE_LAUNCHER;
1412 else if (t[0] == '9')
1413 host_client->edict->v->items = (int)host_client->edict->v->items | HIT_LASER_CANNON;
1414 else if (t[0] == '0')
1415 host_client->edict->v->items = (int)host_client->edict->v->items | HIT_MJOLNIR;
1416 else if (t[0] >= '2')
1417 host_client->edict->v->items = (int)host_client->edict->v->items | (IT_SHOTGUN << (t[0] - '2'));
1422 host_client->edict->v->items = (int)host_client->edict->v->items | (IT_SHOTGUN << (t[0] - '2'));
1427 if (gamemode == GAME_ROGUE && (val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_shells1)))
1430 host_client->edict->v->ammo_shells = v;
1433 if (gamemode == GAME_ROGUE)
1435 if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_nails1)))
1438 if (host_client->edict->v->weapon <= IT_LIGHTNING)
1439 host_client->edict->v->ammo_nails = v;
1444 host_client->edict->v->ammo_nails = v;
1448 if (gamemode == GAME_ROGUE)
1450 val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_lava_nails);
1454 if (host_client->edict->v->weapon > IT_LIGHTNING)
1455 host_client->edict->v->ammo_nails = v;
1460 if (gamemode == GAME_ROGUE)
1462 val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_rockets1);
1466 if (host_client->edict->v->weapon <= IT_LIGHTNING)
1467 host_client->edict->v->ammo_rockets = v;
1472 host_client->edict->v->ammo_rockets = v;
1476 if (gamemode == GAME_ROGUE)
1478 val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_multi_rockets);
1482 if (host_client->edict->v->weapon > IT_LIGHTNING)
1483 host_client->edict->v->ammo_rockets = v;
1488 host_client->edict->v->health = v;
1491 if (gamemode == GAME_ROGUE)
1493 val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_cells1);
1497 if (host_client->edict->v->weapon <= IT_LIGHTNING)
1498 host_client->edict->v->ammo_cells = v;
1503 host_client->edict->v->ammo_cells = v;
1507 if (gamemode == GAME_ROGUE)
1509 val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_plasma);
1513 if (host_client->edict->v->weapon > IT_LIGHTNING)
1514 host_client->edict->v->ammo_cells = v;
1521 edict_t *FindViewthing (void)
1526 for (i=0 ; i<sv.num_edicts ; i++)
1529 if (!strcmp (PR_GetString(e->v->classname), "viewthing"))
1532 Con_Print("No viewthing on map\n");
1541 void Host_Viewmodel_f (void)
1546 e = FindViewthing ();
1550 m = Mod_ForName (Cmd_Argv(1), false, true, false);
1553 Con_Printf("Can't load %s\n", Cmd_Argv(1));
1558 cl.model_precache[(int)e->v->modelindex] = m;
1566 void Host_Viewframe_f (void)
1572 e = FindViewthing ();
1575 m = cl.model_precache[(int)e->v->modelindex];
1577 f = atoi(Cmd_Argv(1));
1578 if (f >= m->numframes)
1585 void PrintFrameName (model_t *m, int frame)
1588 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1590 Con_Printf("frame %i\n", frame);
1598 void Host_Viewnext_f (void)
1603 e = FindViewthing ();
1606 m = cl.model_precache[(int)e->v->modelindex];
1608 e->v->frame = e->v->frame + 1;
1609 if (e->v->frame >= m->numframes)
1610 e->v->frame = m->numframes - 1;
1612 PrintFrameName (m, e->v->frame);
1620 void Host_Viewprev_f (void)
1625 e = FindViewthing ();
1629 m = cl.model_precache[(int)e->v->modelindex];
1631 e->v->frame = e->v->frame - 1;
1632 if (e->v->frame < 0)
1635 PrintFrameName (m, e->v->frame);
1639 ===============================================================================
1643 ===============================================================================
1652 void Host_Startdemos_f (void)
1656 if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
1662 Con_Printf("Max %i demos in demoloop\n", MAX_DEMOS);
1665 Con_DPrintf("%i demo(s) in loop\n", c);
1667 for (i=1 ; i<c+1 ; i++)
1668 strlcpy (cls.demos[i-1], Cmd_Argv(i), sizeof (cls.demos[i-1]));
1670 // LordHavoc: clear the remaining slots
1671 for (;i <= MAX_DEMOS;i++)
1672 cls.demos[i-1][0] = 0;
1674 if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
1688 Return to looping demos
1691 void Host_Demos_f (void)
1693 if (cls.state == ca_dedicated)
1695 if (cls.demonum == -1)
1705 Return to looping demos
1708 void Host_Stopdemo_f (void)
1710 if (!cls.demoplayback)
1713 Host_ShutdownServer (false);
1716 static void MaxPlayers_f(void)
1720 if (Cmd_Argc() != 2)
1722 Con_Printf("\"maxplayers\" is \"%u\"\n", svs.maxclients);
1728 Con_Print("maxplayers can not be changed while a server is running.\n");
1732 n = atoi(Cmd_Argv(1));
1733 n = bound(1, n, MAX_SCOREBOARD);
1734 Con_Printf("\"maxplayers\" set to \"%u\"\n", n);
1737 Mem_Free(svs.clients);
1739 svs.clients = Mem_Alloc(sv_clients_mempool, sizeof(client_t) * svs.maxclients);
1741 Cvar_Set ("deathmatch", "0");
1743 Cvar_Set ("deathmatch", "1");
1746 //=============================================================================
1753 void Host_InitCommands (void)
1755 Cmd_AddCommand ("status", Host_Status_f);
1756 Cmd_AddCommand ("quit", Host_Quit_f);
1757 if (gamemode == GAME_NEHAHRA)
1759 Cmd_AddCommand ("max", Host_God_f);
1760 Cmd_AddCommand ("monster", Host_Notarget_f);
1761 Cmd_AddCommand ("scrag", Host_Fly_f);
1762 Cmd_AddCommand ("wraith", Host_Noclip_f);
1763 Cmd_AddCommand ("gimme", Host_Give_f);
1767 Cmd_AddCommand ("god", Host_God_f);
1768 Cmd_AddCommand ("notarget", Host_Notarget_f);
1769 Cmd_AddCommand ("fly", Host_Fly_f);
1770 Cmd_AddCommand ("noclip", Host_Noclip_f);
1771 Cmd_AddCommand ("give", Host_Give_f);
1773 Cmd_AddCommand ("map", Host_Map_f);
1774 Cmd_AddCommand ("restart", Host_Restart_f);
1775 Cmd_AddCommand ("changelevel", Host_Changelevel_f);
1776 Cmd_AddCommand ("connect", Host_Connect_f);
1777 Cmd_AddCommand ("reconnect", Host_Reconnect_f);
1778 Cmd_AddCommand ("version", Host_Version_f);
1779 Cmd_AddCommand ("say", Host_Say_f);
1780 Cmd_AddCommand ("say_team", Host_Say_Team_f);
1781 Cmd_AddCommand ("tell", Host_Tell_f);
1782 Cmd_AddCommand ("kill", Host_Kill_f);
1783 Cmd_AddCommand ("pause", Host_Pause_f);
1784 Cmd_AddCommand ("kick", Host_Kick_f);
1785 Cmd_AddCommand ("ping", Host_Ping_f);
1786 Cmd_AddCommand ("load", Host_Loadgame_f);
1787 Cmd_AddCommand ("save", Host_Savegame_f);
1789 Cmd_AddCommand ("startdemos", Host_Startdemos_f);
1790 Cmd_AddCommand ("demos", Host_Demos_f);
1791 Cmd_AddCommand ("stopdemo", Host_Stopdemo_f);
1793 Cmd_AddCommand ("viewmodel", Host_Viewmodel_f);
1794 Cmd_AddCommand ("viewframe", Host_Viewframe_f);
1795 Cmd_AddCommand ("viewnext", Host_Viewnext_f);
1796 Cmd_AddCommand ("viewprev", Host_Viewprev_f);
1798 Cvar_RegisterVariable (&cl_name);
1799 Cmd_AddCommand ("name", Host_Name_f);
1800 Cvar_RegisterVariable (&cl_color);
1801 Cmd_AddCommand ("color", Host_Color_f);
1802 Cvar_RegisterVariable (&cl_rate);
1803 Cmd_AddCommand ("rate", Host_Rate_f);
1804 if (gamemode == GAME_NEHAHRA)
1806 Cvar_RegisterVariable (&cl_pmodel);
1807 Cmd_AddCommand ("pmodel", Host_PModel_f);
1809 Cmd_AddCommand ("prespawn", Host_PreSpawn_f);
1810 Cmd_AddCommand ("spawn", Host_Spawn_f);
1811 Cmd_AddCommand ("begin", Host_Begin_f);
1812 Cmd_AddCommand ("maxplayers", MaxPlayers_f);
1814 Cvar_RegisterVariable(&sv_cheats);