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)
53 const char *protocolname;
55 int seconds, minutes, hours = 0, j, players;
56 void (*print) (const char *fmt, ...);
58 if (cmd_source == src_command)
62 Cmd_ForwardToServer ();
68 print = SV_ClientPrintf;
70 for (players = 0, j = 0;j < svs.maxclients;j++)
71 if (svs.clients[j].active)
73 print ("host: %s\n", Cvar_VariableString ("hostname"));
74 print ("version: %s build %s\n", gamename, buildstring);
77 case PROTOCOL_QUAKE: protocolname = sv.netquakecompatible ? "QUAKE" : "QUAKEDP";break;
78 case PROTOCOL_DARKPLACES1: protocolname = "PROTOCOL_DARKPLACES1";break;
79 case PROTOCOL_DARKPLACES2: protocolname = "PROTOCOL_DARKPLACES2";break;
80 case PROTOCOL_DARKPLACES3: protocolname = "PROTOCOL_DARKPLACES3";break;
81 case PROTOCOL_DARKPLACES4: protocolname = "PROTOCOL_DARKPLACES4";break;
82 case PROTOCOL_DARKPLACES5: protocolname = "PROTOCOL_DARKPLACES5";break;
83 default: protocolname = "PROTOCOL_UNKNOWN";break;
85 print ("protocol: %i (%s)\n", sv.protocol, protocolname);
86 print ("map: %s\n", sv.name);
87 print ("players: %i active (%i max)\n\n", players, svs.maxclients);
88 for (j = 0, client = svs.clients;j < svs.maxclients;j++, client++)
92 seconds = (int)(realtime - client->netconnection->connecttime);
93 minutes = seconds / 60;
96 seconds -= (minutes * 60);
99 minutes -= (hours * 60);
103 print ("#%-2u %-16.16s %3i %2i:%02i:%02i\n", j+1, client->name, (int)client->edict->v->frags, hours, minutes, seconds);
104 print (" %s\n", client->netconnection->address);
113 Sets client to godmode
116 void Host_God_f (void)
118 if (cmd_source == src_command)
120 Cmd_ForwardToServer ();
129 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
133 sv_player->v->flags = (int)sv_player->v->flags ^ FL_GODMODE;
134 if (!((int)sv_player->v->flags & FL_GODMODE) )
135 SV_ClientPrint("godmode OFF\n");
137 SV_ClientPrint("godmode ON\n");
140 void Host_Notarget_f (void)
142 if (cmd_source == src_command)
144 Cmd_ForwardToServer ();
153 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
157 sv_player->v->flags = (int)sv_player->v->flags ^ FL_NOTARGET;
158 if (!((int)sv_player->v->flags & FL_NOTARGET) )
159 SV_ClientPrint("notarget OFF\n");
161 SV_ClientPrint("notarget ON\n");
164 qboolean noclip_anglehack;
166 void Host_Noclip_f (void)
168 if (cmd_source == src_command)
170 Cmd_ForwardToServer ();
179 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
183 if (sv_player->v->movetype != MOVETYPE_NOCLIP)
185 noclip_anglehack = true;
186 sv_player->v->movetype = MOVETYPE_NOCLIP;
187 SV_ClientPrint("noclip ON\n");
191 noclip_anglehack = false;
192 sv_player->v->movetype = MOVETYPE_WALK;
193 SV_ClientPrint("noclip OFF\n");
201 Sets client to flymode
204 void Host_Fly_f (void)
206 if (cmd_source == src_command)
208 Cmd_ForwardToServer ();
217 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
221 if (sv_player->v->movetype != MOVETYPE_FLY)
223 sv_player->v->movetype = MOVETYPE_FLY;
224 SV_ClientPrint("flymode ON\n");
228 sv_player->v->movetype = MOVETYPE_WALK;
229 SV_ClientPrint("flymode OFF\n");
240 void Host_Ping_f (void)
246 if (cmd_source == src_command)
248 Cmd_ForwardToServer ();
252 SV_ClientPrint("Client ping times:\n");
253 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
258 for (j=0 ; j<NUM_PING_TIMES ; j++)
259 total+=client->ping_times[j];
260 total /= NUM_PING_TIMES;
261 SV_ClientPrintf("%4i %s\n", (int)(total*1000), client->name);
266 ===============================================================================
270 ===============================================================================
274 ======================
279 command from the console. Active clients are kicked off.
280 ======================
282 void Host_Map_f (void)
284 char level[MAX_QPATH];
288 Con_Print("map <levelname> : start a new game (kicks off all players)\n");
292 if (cmd_source != src_command)
295 SCR_BeginLoadingPlaque ();
296 cls.demonum = -1; // stop demo loop in case this fails
299 Host_ShutdownServer(false);
301 // remove console or menu
303 key_consoleactive = 0;
305 svs.serverflags = 0; // haven't completed an episode yet
306 allowcheats = sv_cheats.integer != 0;
307 strcpy(level, Cmd_Argv(1));
308 SV_SpawnServer(level);
309 if (sv.active && cls.state == ca_disconnected)
310 CL_EstablishConnection("local:1");
317 Goes to a new map, taking all clients along
320 void Host_Changelevel_f (void)
322 char level[MAX_QPATH];
326 Con_Print("changelevel <levelname> : continue game on a new level\n");
329 if (!sv.active || cls.demoplayback)
331 Con_Print("Only the server may changelevel\n");
334 if (cmd_source != src_command)
337 // remove console or menu
339 key_consoleactive = 0;
341 SV_SaveSpawnparms ();
342 SCR_BeginLoadingPlaque();
343 allowcheats = sv_cheats.integer != 0;
344 strcpy(level, Cmd_Argv(1));
345 SV_SpawnServer(level);
346 if (sv.active && cls.state == ca_disconnected)
347 CL_EstablishConnection("local:1");
354 Restarts the current server for a dead player
357 void Host_Restart_f (void)
359 char mapname[MAX_QPATH];
363 Con_Print("restart : restart current level\n");
366 if (!sv.active || cls.demoplayback)
368 Con_Print("Only the server may restart\n");
371 if (cmd_source != src_command)
374 // remove console or menu
376 key_consoleactive = 0;
378 SCR_BeginLoadingPlaque();
379 allowcheats = sv_cheats.integer != 0;
380 strcpy(mapname, sv.name);
381 SV_SpawnServer(mapname);
382 if (sv.active && cls.state == ca_disconnected)
383 CL_EstablishConnection("local:1");
390 This command causes the client to wait for the signon messages again.
391 This is sent just before a server changes levels
394 void Host_Reconnect_f (void)
398 Con_Print("reconnect : wait for signon messages again\n");
401 if (cmd_source == src_command)
403 Con_Print("reconnect not valid from console\n");
408 Con_Print("reconnect: no signon, ignoring reconnect\n");
411 SCR_BeginLoadingPlaque();
412 cls.signon = 0; // need new connection messages
416 =====================
419 User command to connect to server
420 =====================
422 void Host_Connect_f (void)
426 Con_Print("connect <serveraddress> : connect to a multiplayer game\n");
429 CL_EstablishConnection(Cmd_Argv(1));
434 ===============================================================================
438 ===============================================================================
441 #define SAVEGAME_VERSION 5
447 Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
450 void Host_SavegameComment (char *text)
455 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
457 memcpy (text, cl.levelname, strlen(cl.levelname));
458 sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
459 memcpy (text+22, kills, strlen(kills));
460 // convert space to _ to make stdio happy
461 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
464 text[SAVEGAME_COMMENT_LENGTH] = '\0';
473 void Host_Savegame_f (void)
478 char comment[SAVEGAME_COMMENT_LENGTH+1];
480 if (cmd_source != src_command)
483 if (cls.state != ca_connected || !sv.active)
485 Con_Print("Not playing a local game.\n");
491 Con_Print("Can't save in intermission.\n");
495 for (i = 0;i < svs.maxclients;i++)
497 if (svs.clients[i].active)
501 Con_Print("Can't save multiplayer games.\n");
504 if (svs.clients[i].edict->v->deadflag)
506 Con_Print("Can't savegame with a dead player\n");
514 Con_Print("save <savename> : save a game\n");
518 if (strstr(Cmd_Argv(1), ".."))
520 Con_Print("Relative pathnames are not allowed.\n");
524 strlcpy (name, Cmd_Argv(1), sizeof (name));
525 FS_DefaultExtension (name, ".sav", sizeof (name));
527 Con_Printf("Saving game to %s...\n", name);
528 f = FS_Open (name, "w", false);
531 Con_Print("ERROR: couldn't open.\n");
535 FS_Printf(f, "%i\n", SAVEGAME_VERSION);
536 Host_SavegameComment (comment);
537 FS_Printf(f, "%s\n", comment);
538 for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
539 FS_Printf(f, "%f\n", svs.clients[0].spawn_parms[i]);
540 FS_Printf(f, "%d\n", current_skill);
541 FS_Printf(f, "%s\n", sv.name);
542 FS_Printf(f, "%f\n",sv.time);
544 // write the light styles
546 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
548 if (sv.lightstyles[i])
549 FS_Printf(f, "%s\n", sv.lightstyles[i]);
556 for (i=0 ; i<sv.num_edicts ; i++)
558 ED_Write (f, EDICT_NUM(i));
562 Con_Print("done.\n");
566 extern mempool_t *edictstring_mempool;
573 void Host_Loadgame_f (void)
576 char filename[MAX_QPATH];
577 char mapname[MAX_QPATH];
586 float spawn_parms[NUM_SPAWN_PARMS];
588 if (cmd_source != src_command)
593 Con_Print("load <savename> : load a game\n");
597 strcpy (filename, Cmd_Argv(1));
598 FS_DefaultExtension (filename, ".sav", sizeof (filename));
600 Con_Printf("Loading game from %s...\n", filename);
602 cls.demonum = -1; // stop demo loop in case this fails
604 f = FS_Open (filename, "r", false);
607 Con_Print("ERROR: couldn't open.\n");
611 str = FS_Getline (f);
612 sscanf (str, "%i\n", &version);
613 if (version != SAVEGAME_VERSION)
616 Con_Printf("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
620 SCR_BeginLoadingPlaque ();
622 str = FS_Getline (f);
623 for (i = 0;i < NUM_SPAWN_PARMS;i++)
625 str = FS_Getline (f);
626 sscanf (str, "%f\n", &spawn_parms[i]);
628 // this silliness is so we can load 1.06 save files, which have float skill values
629 str = FS_Getline (f);
630 sscanf (str, "%f\n", &tfloat);
631 current_skill = (int)(tfloat + 0.1);
632 Cvar_SetValue ("skill", (float)current_skill);
634 strcpy (mapname, FS_Getline (f));
636 str = FS_Getline (f);
637 sscanf (str, "%f\n",&time);
639 allowcheats = sv_cheats.integer != 0;
640 SV_SpawnServer (mapname);
643 Con_Print("Couldn't load map\n");
646 sv.paused = true; // pause until all clients connect
649 // load the light styles
651 for (i = 0;i < MAX_LIGHTSTYLES;i++)
653 str = FS_Getline (f);
654 sv.lightstyles[i] = Mem_Alloc(edictstring_mempool, strlen(str)+1);
655 strcpy (sv.lightstyles[i], str);
658 // load the edicts out of the savegame file
663 for (i = 0;i < (int)sizeof(buf) - 1;i++)
675 if (i == sizeof(buf)-1)
676 Host_Error ("Loadgame buffer overflow");
679 if (!COM_ParseToken(&start, false))
684 if (strcmp(com_token,"{"))
685 Host_Error ("First token isn't a brace");
689 // parse the global vars
690 ED_ParseGlobals (start);
695 if (entnum >= MAX_EDICTS)
696 Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)\n", MAX_EDICTS);
697 while (entnum >= sv.max_edicts)
699 ent = EDICT_NUM(entnum);
700 memset (ent->v, 0, progs->entityfields * 4);
701 ent->e->free = false;
702 ED_ParseEdict (start, ent);
704 // link it into the bsp tree
706 SV_LinkEdict (ent, false);
712 sv.num_edicts = entnum;
717 for (i = 0;i < NUM_SPAWN_PARMS;i++)
718 svs.clients[0].spawn_parms[i] = spawn_parms[i];
720 // make sure we're connected to loopback
721 if (cls.state == ca_disconnected || !(cls.state == ca_connected && cls.netcon != NULL && LHNETADDRESS_GetAddressType(&cls.netcon->peeraddress) == LHNETADDRESSTYPE_LOOP))
722 CL_EstablishConnection("local:1");
725 //============================================================================
728 ======================
730 ======================
732 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player"};
733 void Host_Name_f (void)
736 char newName[sizeof(host_client->name)];
738 if (Cmd_Argc () == 1)
740 Con_Printf("\"name\" is \"%s\"\n", cl_name.string);
744 if (Cmd_Argc () == 2)
745 strlcpy (newName, Cmd_Argv(1), sizeof (newName));
747 strlcpy (newName, Cmd_Args(), sizeof (newName));
749 for (i = 0, j = 0;newName[i];i++)
750 if (newName[i] != '\r' && newName[i] != '\n')
751 newName[j++] = newName[i];
754 if (cmd_source == src_command)
756 Cvar_Set ("_cl_name", newName);
757 if (cls.state == ca_connected)
758 Cmd_ForwardToServer ();
762 if (sv.time < host_client->nametime)
764 SV_ClientPrintf("You can't change name more than once every 5 seconds!\n");
768 host_client->nametime = sv.time + 5;
770 if (strcmp(host_client->name, newName) && host_client->name[0] && strcmp(host_client->name, "unconnected"))
771 SV_BroadcastPrintf("%s changed name to %s\n", host_client->name, newName);
772 strcpy(host_client->name, newName);
773 strcpy(host_client->old_name, newName);
775 sv_player->v->netname = PR_SetString(host_client->name);
776 //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);
778 // send notification to all clients
780 MSG_WriteByte(&sv.reliable_datagram, svc_updatename);
781 MSG_WriteByte(&sv.reliable_datagram, host_client->number);
782 MSG_WriteString(&sv.reliable_datagram, host_client->name);
786 void Host_Version_f (void)
788 Con_Printf("Version: %s build %s\n", gamename, buildstring);
791 void Host_Say(qboolean teamonly)
796 // LordHavoc: 256 char say messages
797 unsigned char text[256];
798 qboolean fromServer = false;
800 if (cmd_source == src_command)
802 if (cls.state == ca_dedicated)
809 Cmd_ForwardToServer ();
817 if (!teamplay.integer)
820 // turn on color set 1
823 snprintf (text, sizeof(text), "%c%s: %s\n", 1, host_client->name, p1);
825 snprintf (text, sizeof(text), "%c<%s> %s\n", 1, hostname.string, p1);
827 // note: save is not a valid edict if fromServer is true
829 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
830 if (host_client->spawned && (!teamonly || host_client->edict->v->team == save->edict->v->team))
831 SV_ClientPrint(text);
838 void Host_Say_f(void)
844 void Host_Say_Team_f(void)
850 void Host_Tell_f(void)
855 char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
856 qboolean fromServer = false;
858 if (cmd_source == src_command)
860 if (cls.state == ca_dedicated)
864 Cmd_ForwardToServer ();
873 sprintf (text, "%s: ", host_client->name);
875 sprintf (text, "<%s> ", hostname.string);
878 p2 = p1 + strlen(p1);
879 // remove the target name
880 while (p1 < p2 && *p1 != ' ')
882 while (p1 < p2 && *p1 == ' ')
884 // remove trailing newlines
885 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
887 // remove quotes if present
894 Con_Print("Host_Tell: missing end quote\n");
896 SV_ClientPrint("Host_Tell: missing end quote\n");
898 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
900 for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
906 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
907 if (host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1)))
908 SV_ClientPrint(text);
918 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0"};
919 void Host_Color_f(void)
924 func_t SV_ChangeTeam;
928 Con_Printf("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
929 Con_Print("color <0-15> [0-15]\n");
934 top = bottom = atoi(Cmd_Argv(1));
937 top = atoi(Cmd_Argv(1));
938 bottom = atoi(Cmd_Argv(2));
942 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
946 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
950 playercolor = top*16 + bottom;
952 if (cmd_source == src_command)
954 Cvar_SetValue ("_cl_color", playercolor);
955 if (cls.state == ca_connected)
956 Cmd_ForwardToServer ();
960 if (sv_player && (f = ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - pr_functions)))
962 Con_DPrint("Calling SV_ChangeTeam\n");
963 pr_global_struct->time = sv.time;
964 pr_globals[OFS_PARM0] = playercolor;
965 pr_global_struct->self = EDICT_TO_PROG(sv_player);
966 PR_ExecuteProgram (SV_ChangeTeam, "QC function SV_ChangeTeam is missing");
973 if ((val = GETEDICTFIELDVALUE(sv_player, eval_clientcolors)))
974 val->_float = playercolor;
975 sv_player->v->team = bottom + 1;
977 host_client->colors = playercolor;
978 host_client->old_colors = playercolor;
980 // send notification to all clients
981 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
982 MSG_WriteByte (&sv.reliable_datagram, host_client->number);
983 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->netconnection->rate = rate;
1017 void Host_Kill_f (void)
1019 if (cmd_source == src_command)
1021 Cmd_ForwardToServer ();
1025 if (!sv_player || sv_player->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 host_client->pmodel = i;
1092 if (sv_player && (val = GETEDICTFIELDVALUE(sv_player, eval_pmodel)))
1096 //===========================================================================
1104 void Host_PreSpawn_f (void)
1106 if (cmd_source == src_command)
1108 Con_Print("prespawn is not valid from the console\n");
1112 if (host_client->spawned)
1114 Con_Print("prespawn not valid -- already spawned\n");
1118 SZ_Write (&host_client->message, sv.signon.data, sv.signon.cursize);
1119 MSG_WriteByte (&host_client->message, svc_signonnum);
1120 MSG_WriteByte (&host_client->message, 2);
1121 host_client->sendsignon = true;
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");
1150 Con_Print("Host_Spawn: no edict??\n");
1154 host_client->nametime = 0;
1156 // LordHavoc: moved this above the QC calls at FrikaC's request
1157 // send all current names, colors, and frag counts
1158 SZ_Clear (&host_client->message);
1160 // run the entrance script
1163 // loaded games are fully initialized already
1164 // if this is the last client to be connected, unpause
1167 if ((f = ED_FindFunction ("RestoreGame")))
1168 if ((RestoreGame = (func_t)(f - pr_functions)))
1170 Con_DPrint("Calling RestoreGame\n");
1171 pr_global_struct->time = sv.time;
1172 pr_global_struct->self = EDICT_TO_PROG(sv_player);
1173 PR_ExecuteProgram (RestoreGame, "QC function RestoreGame is missing");
1179 ED_ClearEdict(sv_player);
1181 //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);
1183 // copy spawn parms out of the client_t
1184 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1185 (&pr_global_struct->parm1)[i] = host_client->spawn_parms[i];
1187 // call the spawn function
1188 pr_global_struct->time = sv.time;
1189 pr_global_struct->self = EDICT_TO_PROG(sv_player);
1190 PR_ExecuteProgram (pr_global_struct->ClientConnect, "QC function ClientConnect is missing");
1192 if ((Sys_DoubleTime() - host_client->netconnection->connecttime) <= sv.time)
1193 Sys_Printf("%s entered the game\n", host_client->name);
1195 PR_ExecuteProgram (pr_global_struct->PutClientInServer, "QC function PutClientInServer is missing");
1199 // send time of update
1200 MSG_WriteByte (&host_client->message, svc_time);
1201 MSG_WriteFloat (&host_client->message, sv.time);
1203 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
1205 if (!client->active)
1207 MSG_WriteByte (&host_client->message, svc_updatename);
1208 MSG_WriteByte (&host_client->message, i);
1209 MSG_WriteString (&host_client->message, client->old_name);
1210 MSG_WriteByte (&host_client->message, svc_updatefrags);
1211 MSG_WriteByte (&host_client->message, i);
1212 MSG_WriteShort (&host_client->message, client->old_frags);
1213 MSG_WriteByte (&host_client->message, svc_updatecolors);
1214 MSG_WriteByte (&host_client->message, i);
1215 MSG_WriteByte (&host_client->message, client->old_colors);
1218 // send all current light styles
1219 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1221 MSG_WriteByte (&host_client->message, svc_lightstyle);
1222 MSG_WriteByte (&host_client->message, (char)i);
1223 MSG_WriteString (&host_client->message, sv.lightstyles[i]);
1227 MSG_WriteByte (&host_client->message, svc_updatestat);
1228 MSG_WriteByte (&host_client->message, STAT_TOTALSECRETS);
1229 MSG_WriteLong (&host_client->message, pr_global_struct->total_secrets);
1231 MSG_WriteByte (&host_client->message, svc_updatestat);
1232 MSG_WriteByte (&host_client->message, STAT_TOTALMONSTERS);
1233 MSG_WriteLong (&host_client->message, pr_global_struct->total_monsters);
1235 MSG_WriteByte (&host_client->message, svc_updatestat);
1236 MSG_WriteByte (&host_client->message, STAT_SECRETS);
1237 MSG_WriteLong (&host_client->message, pr_global_struct->found_secrets);
1239 MSG_WriteByte (&host_client->message, svc_updatestat);
1240 MSG_WriteByte (&host_client->message, STAT_MONSTERS);
1241 MSG_WriteLong (&host_client->message, pr_global_struct->killed_monsters);
1244 // Never send a roll angle, because savegames can catch the server
1245 // in a state where it is expecting the client to correct the angle
1246 // and it won't happen if the game was just loaded, so you wind up
1247 // with a permanent head tilt
1248 MSG_WriteByte (&host_client->message, svc_setangle);
1249 MSG_WriteAngle (&host_client->message, sv_player->v->angles[0], sv.protocol);
1250 MSG_WriteAngle (&host_client->message, sv_player->v->angles[1], sv.protocol);
1251 MSG_WriteAngle (&host_client->message, 0, sv.protocol);
1253 SV_WriteClientdataToMessage (sv_player, &host_client->message);
1255 MSG_WriteByte (&host_client->message, svc_signonnum);
1256 MSG_WriteByte (&host_client->message, 3);
1257 host_client->sendsignon = true;
1265 void Host_Begin_f (void)
1267 if (cmd_source == src_command)
1269 Con_Print("begin is not valid from the console\n");
1273 host_client->spawned = true;
1276 //===========================================================================
1283 Kicks a user off of the server
1286 void Host_Kick_f (void)
1289 const char *message = NULL;
1292 qboolean byNumber = false;
1294 if (cmd_source != src_command || !sv.active)
1299 if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1301 i = atof(Cmd_Argv(2)) - 1;
1302 if (i < 0 || i >= svs.maxclients || !(host_client = svs.clients + i)->active)
1308 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1310 if (!host_client->active)
1312 if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1317 if (i < svs.maxclients)
1319 if (cmd_source == src_command)
1321 if (cls.state == ca_dedicated)
1324 who = cl_name.string;
1329 // can't kick yourself!
1330 if (host_client == save)
1335 message = Cmd_Args();
1336 COM_ParseToken(&message, false);
1339 message++; // skip the #
1340 while (*message == ' ') // skip white space
1342 message += strlen(Cmd_Argv(2)); // skip the number
1344 while (*message && *message == ' ')
1348 SV_ClientPrintf("Kicked by %s: %s\n", who, message);
1350 SV_ClientPrintf("Kicked by %s\n", who);
1351 SV_DropClient (false); // kicked
1358 ===============================================================================
1362 ===============================================================================
1370 void Host_Give_f (void)
1376 if (cmd_source == src_command)
1378 Cmd_ForwardToServer ();
1387 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
1392 v = atoi (Cmd_Argv(2));
1406 // MED 01/04/97 added hipnotic give stuff
1407 if (gamemode == GAME_HIPNOTIC)
1412 sv_player->v->items = (int)sv_player->v->items | HIT_PROXIMITY_GUN;
1414 sv_player->v->items = (int)sv_player->v->items | IT_GRENADE_LAUNCHER;
1416 else if (t[0] == '9')
1417 sv_player->v->items = (int)sv_player->v->items | HIT_LASER_CANNON;
1418 else if (t[0] == '0')
1419 sv_player->v->items = (int)sv_player->v->items | HIT_MJOLNIR;
1420 else if (t[0] >= '2')
1421 sv_player->v->items = (int)sv_player->v->items | (IT_SHOTGUN << (t[0] - '2'));
1426 sv_player->v->items = (int)sv_player->v->items | (IT_SHOTGUN << (t[0] - '2'));
1431 if (gamemode == GAME_ROGUE && (val = GETEDICTFIELDVALUE(sv_player, eval_ammo_shells1)))
1434 sv_player->v->ammo_shells = v;
1437 if (gamemode == GAME_ROGUE)
1439 if ((val = GETEDICTFIELDVALUE(sv_player, eval_ammo_nails1)))
1442 if (sv_player->v->weapon <= IT_LIGHTNING)
1443 sv_player->v->ammo_nails = v;
1448 sv_player->v->ammo_nails = v;
1452 if (gamemode == GAME_ROGUE)
1454 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_lava_nails);
1458 if (sv_player->v->weapon > IT_LIGHTNING)
1459 sv_player->v->ammo_nails = v;
1464 if (gamemode == GAME_ROGUE)
1466 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_rockets1);
1470 if (sv_player->v->weapon <= IT_LIGHTNING)
1471 sv_player->v->ammo_rockets = v;
1476 sv_player->v->ammo_rockets = v;
1480 if (gamemode == GAME_ROGUE)
1482 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_multi_rockets);
1486 if (sv_player->v->weapon > IT_LIGHTNING)
1487 sv_player->v->ammo_rockets = v;
1492 sv_player->v->health = v;
1495 if (gamemode == GAME_ROGUE)
1497 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_cells1);
1501 if (sv_player->v->weapon <= IT_LIGHTNING)
1502 sv_player->v->ammo_cells = v;
1507 sv_player->v->ammo_cells = v;
1511 if (gamemode == GAME_ROGUE)
1513 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_plasma);
1517 if (sv_player->v->weapon > IT_LIGHTNING)
1518 sv_player->v->ammo_cells = v;
1525 edict_t *FindViewthing (void)
1530 for (i=0 ; i<sv.num_edicts ; i++)
1533 if (!strcmp (PR_GetString(e->v->classname), "viewthing"))
1536 Con_Print("No viewthing on map\n");
1545 void Host_Viewmodel_f (void)
1550 e = FindViewthing ();
1554 m = Mod_ForName (Cmd_Argv(1), false, true, false);
1557 Con_Printf("Can't load %s\n", Cmd_Argv(1));
1562 cl.model_precache[(int)e->v->modelindex] = m;
1570 void Host_Viewframe_f (void)
1576 e = FindViewthing ();
1579 m = cl.model_precache[(int)e->v->modelindex];
1581 f = atoi(Cmd_Argv(1));
1582 if (f >= m->numframes)
1589 void PrintFrameName (model_t *m, int frame)
1592 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1594 Con_Printf("frame %i\n", frame);
1602 void Host_Viewnext_f (void)
1607 e = FindViewthing ();
1610 m = cl.model_precache[(int)e->v->modelindex];
1612 e->v->frame = e->v->frame + 1;
1613 if (e->v->frame >= m->numframes)
1614 e->v->frame = m->numframes - 1;
1616 PrintFrameName (m, e->v->frame);
1624 void Host_Viewprev_f (void)
1629 e = FindViewthing ();
1633 m = cl.model_precache[(int)e->v->modelindex];
1635 e->v->frame = e->v->frame - 1;
1636 if (e->v->frame < 0)
1639 PrintFrameName (m, e->v->frame);
1643 ===============================================================================
1647 ===============================================================================
1656 void Host_Startdemos_f (void)
1660 if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
1664 if (gamemode == GAME_TRANSFUSION)
1665 Cbuf_AddText ("map bb1\n");
1667 Cbuf_AddText ("map start\n");
1675 Con_Printf("Max %i demos in demoloop\n", MAX_DEMOS);
1678 Con_DPrintf("%i demo(s) in loop\n", c);
1680 for (i=1 ; i<c+1 ; i++)
1681 strlcpy (cls.demos[i-1], Cmd_Argv(i), sizeof (cls.demos[i-1]));
1683 // LordHavoc: clear the remaining slots
1684 for (;i <= MAX_DEMOS;i++)
1685 cls.demos[i-1][0] = 0;
1687 if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
1701 Return to looping demos
1704 void Host_Demos_f (void)
1706 if (cls.state == ca_dedicated)
1708 if (cls.demonum == -1)
1718 Return to looping demos
1721 void Host_Stopdemo_f (void)
1723 if (!cls.demoplayback)
1726 Host_ShutdownServer (false);
1729 static void MaxPlayers_f(void)
1733 if (Cmd_Argc() != 2)
1735 Con_Printf("\"maxplayers\" is \"%u\"\n", svs.maxclients);
1741 Con_Print("maxplayers can not be changed while a server is running.\n");
1745 n = atoi(Cmd_Argv(1));
1746 n = bound(1, n, MAX_SCOREBOARD);
1747 Con_Printf("\"maxplayers\" set to \"%u\"\n", n);
1750 Mem_Free(svs.clients);
1752 svs.clients = Mem_Alloc(sv_clients_mempool, sizeof(client_t) * svs.maxclients);
1754 Cvar_Set ("deathmatch", "0");
1756 Cvar_Set ("deathmatch", "1");
1759 //=============================================================================
1766 void Host_InitCommands (void)
1768 Cmd_AddCommand ("status", Host_Status_f);
1769 Cmd_AddCommand ("quit", Host_Quit_f);
1770 if (gamemode == GAME_NEHAHRA)
1772 Cmd_AddCommand ("max", Host_God_f);
1773 Cmd_AddCommand ("monster", Host_Notarget_f);
1774 Cmd_AddCommand ("scrag", Host_Fly_f);
1775 Cmd_AddCommand ("wraith", Host_Noclip_f);
1776 Cmd_AddCommand ("gimme", Host_Give_f);
1780 Cmd_AddCommand ("god", Host_God_f);
1781 Cmd_AddCommand ("notarget", Host_Notarget_f);
1782 Cmd_AddCommand ("fly", Host_Fly_f);
1783 Cmd_AddCommand ("noclip", Host_Noclip_f);
1784 Cmd_AddCommand ("give", Host_Give_f);
1786 Cmd_AddCommand ("map", Host_Map_f);
1787 Cmd_AddCommand ("restart", Host_Restart_f);
1788 Cmd_AddCommand ("changelevel", Host_Changelevel_f);
1789 Cmd_AddCommand ("connect", Host_Connect_f);
1790 Cmd_AddCommand ("reconnect", Host_Reconnect_f);
1791 Cmd_AddCommand ("version", Host_Version_f);
1792 Cmd_AddCommand ("say", Host_Say_f);
1793 Cmd_AddCommand ("say_team", Host_Say_Team_f);
1794 Cmd_AddCommand ("tell", Host_Tell_f);
1795 Cmd_AddCommand ("kill", Host_Kill_f);
1796 Cmd_AddCommand ("pause", Host_Pause_f);
1797 Cmd_AddCommand ("kick", Host_Kick_f);
1798 Cmd_AddCommand ("ping", Host_Ping_f);
1799 Cmd_AddCommand ("load", Host_Loadgame_f);
1800 Cmd_AddCommand ("save", Host_Savegame_f);
1802 Cmd_AddCommand ("startdemos", Host_Startdemos_f);
1803 Cmd_AddCommand ("demos", Host_Demos_f);
1804 Cmd_AddCommand ("stopdemo", Host_Stopdemo_f);
1806 Cmd_AddCommand ("viewmodel", Host_Viewmodel_f);
1807 Cmd_AddCommand ("viewframe", Host_Viewframe_f);
1808 Cmd_AddCommand ("viewnext", Host_Viewnext_f);
1809 Cmd_AddCommand ("viewprev", Host_Viewprev_f);
1811 Cvar_RegisterVariable (&cl_name);
1812 Cmd_AddCommand ("name", Host_Name_f);
1813 Cvar_RegisterVariable (&cl_color);
1814 Cmd_AddCommand ("color", Host_Color_f);
1815 Cvar_RegisterVariable (&cl_rate);
1816 Cmd_AddCommand ("rate", Host_Rate_f);
1817 if (gamemode == GAME_NEHAHRA)
1819 Cvar_RegisterVariable (&cl_pmodel);
1820 Cmd_AddCommand ("pmodel", Host_PModel_f);
1822 Cmd_AddCommand ("prespawn", Host_PreSpawn_f);
1823 Cmd_AddCommand ("spawn", Host_Spawn_f);
1824 Cmd_AddCommand ("begin", Host_Begin_f);
1825 Cmd_AddCommand ("maxplayers", MaxPlayers_f);
1827 Cvar_RegisterVariable(&sv_cheats);