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");
403 Con_Print("reconnect: no signon, ignoring reconnect\n");
406 SCR_BeginLoadingPlaque();
407 cls.signon = 0; // need new connection messages
411 =====================
414 User command to connect to server
415 =====================
417 void Host_Connect_f (void)
421 Con_Print("connect <serveraddress> : connect to a multiplayer game\n");
424 CL_EstablishConnection(Cmd_Argv(1));
429 ===============================================================================
433 ===============================================================================
436 #define SAVEGAME_VERSION 5
442 Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
445 void Host_SavegameComment (char *text)
450 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
452 memcpy (text, cl.levelname, strlen(cl.levelname));
453 sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
454 memcpy (text+22, kills, strlen(kills));
455 // convert space to _ to make stdio happy
456 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
459 text[SAVEGAME_COMMENT_LENGTH] = '\0';
468 void Host_Savegame_f (void)
473 char comment[SAVEGAME_COMMENT_LENGTH+1];
475 if (cmd_source != src_command)
478 if (cls.state != ca_connected || !sv.active)
480 Con_Print("Not playing a local game.\n");
486 Con_Print("Can't save in intermission.\n");
490 for (i = 0;i < svs.maxclients;i++)
492 if (svs.clients[i].active)
496 Con_Print("Can't save multiplayer games.\n");
499 if (svs.clients[i].edict->v->deadflag)
501 Con_Print("Can't savegame with a dead player\n");
509 Con_Print("save <savename> : save a game\n");
513 if (strstr(Cmd_Argv(1), ".."))
515 Con_Print("Relative pathnames are not allowed.\n");
519 strlcpy (name, Cmd_Argv(1), sizeof (name));
520 FS_DefaultExtension (name, ".sav", sizeof (name));
522 Con_Printf("Saving game to %s...\n", name);
523 f = FS_Open (name, "w", false);
526 Con_Print("ERROR: couldn't open.\n");
530 FS_Printf(f, "%i\n", SAVEGAME_VERSION);
531 Host_SavegameComment (comment);
532 FS_Printf(f, "%s\n", comment);
533 for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
534 FS_Printf(f, "%f\n", svs.clients[0].spawn_parms[i]);
535 FS_Printf(f, "%d\n", current_skill);
536 FS_Printf(f, "%s\n", sv.name);
537 FS_Printf(f, "%f\n",sv.time);
539 // write the light styles
541 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
543 if (sv.lightstyles[i])
544 FS_Printf(f, "%s\n", sv.lightstyles[i]);
551 for (i=0 ; i<sv.num_edicts ; i++)
553 ED_Write (f, EDICT_NUM(i));
557 Con_Print("done.\n");
561 extern mempool_t *edictstring_mempool;
568 void Host_Loadgame_f (void)
571 char filename[MAX_QPATH];
572 char mapname[MAX_QPATH];
581 float spawn_parms[NUM_SPAWN_PARMS];
583 if (cmd_source != src_command)
588 Con_Print("load <savename> : load a game\n");
592 strcpy (filename, Cmd_Argv(1));
593 FS_DefaultExtension (filename, ".sav", sizeof (filename));
595 Con_Printf("Loading game from %s...\n", filename);
597 cls.demonum = -1; // stop demo loop in case this fails
599 f = FS_Open (filename, "r", false);
602 Con_Print("ERROR: couldn't open.\n");
606 str = FS_Getline (f);
607 sscanf (str, "%i\n", &version);
608 if (version != SAVEGAME_VERSION)
611 Con_Printf("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
615 SCR_BeginLoadingPlaque ();
617 str = FS_Getline (f);
618 for (i = 0;i < NUM_SPAWN_PARMS;i++)
620 str = FS_Getline (f);
621 sscanf (str, "%f\n", &spawn_parms[i]);
623 // this silliness is so we can load 1.06 save files, which have float skill values
624 str = FS_Getline (f);
625 sscanf (str, "%f\n", &tfloat);
626 current_skill = (int)(tfloat + 0.1);
627 Cvar_SetValue ("skill", (float)current_skill);
629 strcpy (mapname, FS_Getline (f));
631 str = FS_Getline (f);
632 sscanf (str, "%f\n",&time);
634 allowcheats = sv_cheats.integer != 0;
635 SV_SpawnServer (mapname);
638 Con_Print("Couldn't load map\n");
641 sv.paused = true; // pause until all clients connect
644 // load the light styles
646 for (i = 0;i < MAX_LIGHTSTYLES;i++)
648 str = FS_Getline (f);
649 sv.lightstyles[i] = Mem_Alloc(edictstring_mempool, strlen(str)+1);
650 strcpy (sv.lightstyles[i], str);
653 // load the edicts out of the savegame file
658 for (i = 0;i < (int)sizeof(buf) - 1;i++)
670 if (i == sizeof(buf)-1)
671 Host_Error ("Loadgame buffer overflow");
674 if (!COM_ParseToken(&start, false))
679 if (strcmp(com_token,"{"))
680 Host_Error ("First token isn't a brace");
684 // parse the global vars
685 ED_ParseGlobals (start);
690 if (entnum >= MAX_EDICTS)
691 Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)\n", MAX_EDICTS);
692 while (entnum >= sv.max_edicts)
694 ent = EDICT_NUM(entnum);
695 memset (ent->v, 0, progs->entityfields * 4);
696 ent->e->free = false;
697 ED_ParseEdict (start, ent);
699 // link it into the bsp tree
701 SV_LinkEdict (ent, false);
707 sv.num_edicts = entnum;
712 for (i = 0;i < NUM_SPAWN_PARMS;i++)
713 svs.clients[0].spawn_parms[i] = spawn_parms[i];
715 // make sure we're connected to loopback
716 if (cls.state == ca_disconnected || !(cls.state == ca_connected && cls.netcon != NULL && LHNETADDRESS_GetAddressType(&cls.netcon->peeraddress) == LHNETADDRESSTYPE_LOOP))
717 CL_EstablishConnection("local:1");
720 //============================================================================
723 ======================
725 ======================
727 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player"};
728 void Host_Name_f (void)
731 char newName[sizeof(host_client->name)];
733 if (Cmd_Argc () == 1)
735 Con_Printf("\"name\" is \"%s\"\n", cl_name.string);
739 if (Cmd_Argc () == 2)
740 strlcpy (newName, Cmd_Argv(1), sizeof (newName));
742 strlcpy (newName, Cmd_Args(), sizeof (newName));
744 for (i = 0, j = 0;newName[i];i++)
745 if (newName[i] != '\r' && newName[i] != '\n')
746 newName[j++] = newName[i];
749 if (cmd_source == src_command)
751 Cvar_Set ("_cl_name", newName);
752 if (cls.state == ca_connected)
753 Cmd_ForwardToServer ();
757 if (sv.time < host_client->nametime)
759 SV_ClientPrintf("You can't change name more than once every 5 seconds!\n");
763 host_client->nametime = sv.time + 5;
765 if (strcmp(host_client->name, newName) && host_client->name[0] && strcmp(host_client->name, "unconnected"))
766 SV_BroadcastPrintf("%s changed name to %s\n", host_client->name, newName);
767 strcpy(host_client->name, newName);
768 strcpy(host_client->old_name, newName);
770 sv_player->v->netname = PR_SetString(host_client->name);
771 //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);
773 // send notification to all clients
775 MSG_WriteByte(&sv.reliable_datagram, svc_updatename);
776 MSG_WriteByte(&sv.reliable_datagram, host_client->number);
777 MSG_WriteString(&sv.reliable_datagram, host_client->name);
781 void Host_Version_f (void)
783 Con_Printf("Version: %s build %s\n", gamename, buildstring);
786 void Host_Say(qboolean teamonly)
792 // LordHavoc: 256 char say messages
793 unsigned char text[256];
794 qboolean fromServer = false;
796 if (cmd_source == src_command)
798 if (cls.state == ca_dedicated)
805 Cmd_ForwardToServer ();
813 if (!teamplay.integer)
816 // turn on color set 1
825 snprintf (text, sizeof(text), "%c%s: %s", 1, host_client->name, p1);
827 snprintf (text, sizeof(text), "%c<%s> %s", 1, hostname.string, p1);
828 p2 = text + strlen(text);
829 while ((const char *)p2 > (const char *)text && (p2[-1] == '\r' || p2[-1] == '\n' || (p2[-1] == '\"' && quoted)))
831 if (p2[-1] == '\"' && quoted)
836 strlcat(text, "\n", sizeof(text));
838 // note: save is not a valid edict if fromServer is true
840 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
841 if (host_client->spawned && (!teamonly || host_client->edict->v->team == save->edict->v->team))
842 SV_ClientPrint(text);
849 void Host_Say_f(void)
855 void Host_Say_Team_f(void)
861 void Host_Tell_f(void)
866 char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
867 qboolean fromServer = false;
869 if (cmd_source == src_command)
871 if (cls.state == ca_dedicated)
875 Cmd_ForwardToServer ();
884 sprintf (text, "%s: ", host_client->name);
886 sprintf (text, "<%s> ", hostname.string);
889 p2 = p1 + strlen(p1);
890 // remove the target name
891 while (p1 < p2 && *p1 != ' ')
893 while (p1 < p2 && *p1 == ' ')
895 // remove trailing newlines
896 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
898 // remove quotes if present
905 Con_Print("Host_Tell: missing end quote\n");
907 SV_ClientPrint("Host_Tell: missing end quote\n");
909 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
911 for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
917 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
918 if (host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1)))
919 SV_ClientPrint(text);
929 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0"};
930 void Host_Color_f(void)
935 func_t SV_ChangeTeam;
939 Con_Printf("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
940 Con_Print("color <0-15> [0-15]\n");
945 top = bottom = atoi(Cmd_Argv(1));
948 top = atoi(Cmd_Argv(1));
949 bottom = atoi(Cmd_Argv(2));
953 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
957 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
961 playercolor = top*16 + bottom;
963 if (cmd_source == src_command)
965 Cvar_SetValue ("_cl_color", playercolor);
966 if (cls.state == ca_connected)
967 Cmd_ForwardToServer ();
971 if (sv_player && (f = ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - pr_functions)))
973 Con_DPrint("Calling SV_ChangeTeam\n");
974 pr_global_struct->time = sv.time;
975 pr_globals[OFS_PARM0] = playercolor;
976 pr_global_struct->self = EDICT_TO_PROG(sv_player);
977 PR_ExecuteProgram (SV_ChangeTeam, "QC function SV_ChangeTeam is missing");
984 if ((val = GETEDICTFIELDVALUE(sv_player, eval_clientcolors)))
985 val->_float = playercolor;
986 sv_player->v->team = bottom + 1;
988 host_client->colors = playercolor;
989 host_client->old_colors = playercolor;
991 // send notification to all clients
992 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
993 MSG_WriteByte (&sv.reliable_datagram, host_client->number);
994 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
998 cvar_t cl_rate = {CVAR_SAVE, "_cl_rate", "10000"};
999 void Host_Rate_f(void)
1003 if (Cmd_Argc() != 2)
1005 Con_Printf("\"rate\" is \"%i\"\n", cl_rate.integer);
1006 Con_Print("rate <500-25000>\n");
1010 rate = atoi(Cmd_Argv(1));
1012 if (cmd_source == src_command)
1014 Cvar_SetValue ("_cl_rate", bound(NET_MINRATE, rate, NET_MAXRATE));
1015 if (cls.state == ca_connected)
1016 Cmd_ForwardToServer ();
1020 host_client->netconnection->rate = rate;
1028 void Host_Kill_f (void)
1030 if (cmd_source == src_command)
1032 Cmd_ForwardToServer ();
1036 if (!sv_player || sv_player->v->health <= 0)
1038 SV_ClientPrint("Can't suicide -- already dead!\n");
1042 pr_global_struct->time = sv.time;
1043 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1044 PR_ExecuteProgram (pr_global_struct->ClientKill, "QC function ClientKill is missing");
1053 void Host_Pause_f (void)
1056 if (cmd_source == src_command)
1058 Cmd_ForwardToServer ();
1061 if (!pausable.integer)
1062 SV_ClientPrint("Pause not allowed.\n");
1066 SV_BroadcastPrintf("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
1067 // send notification to all clients
1068 MSG_WriteByte(&sv.reliable_datagram, svc_setpause);
1069 MSG_WriteByte(&sv.reliable_datagram, sv.paused);
1074 ======================
1076 LordHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
1077 ======================
1079 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0"};
1080 static void Host_PModel_f (void)
1085 if (Cmd_Argc () == 1)
1087 Con_Printf("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
1090 i = atoi(Cmd_Argv(1));
1092 if (cmd_source == src_command)
1094 if (cl_pmodel.integer == i)
1096 Cvar_SetValue ("_cl_pmodel", i);
1097 if (cls.state == ca_connected)
1098 Cmd_ForwardToServer ();
1102 host_client->pmodel = i;
1103 if (sv_player && (val = GETEDICTFIELDVALUE(sv_player, eval_pmodel)))
1107 //===========================================================================
1115 void Host_PreSpawn_f (void)
1117 if (cmd_source == src_command)
1119 Con_Print("prespawn is not valid from the console\n");
1123 if (host_client->spawned)
1125 Con_Print("prespawn not valid -- already spawned\n");
1129 SZ_Write (&host_client->message, sv.signon.data, sv.signon.cursize);
1130 MSG_WriteByte (&host_client->message, svc_signonnum);
1131 MSG_WriteByte (&host_client->message, 2);
1132 host_client->sendsignon = true;
1140 void Host_Spawn_f (void)
1147 if (cmd_source == src_command)
1149 Con_Print("spawn is not valid from the console\n");
1153 if (host_client->spawned)
1155 Con_Print("Spawn not valid -- already spawned\n");
1161 Con_Print("Host_Spawn: no edict??\n");
1165 host_client->nametime = 0;
1167 // LordHavoc: moved this above the QC calls at FrikaC's request
1168 // send all current names, colors, and frag counts
1169 SZ_Clear (&host_client->message);
1171 // run the entrance script
1174 // loaded games are fully initialized already
1175 // if this is the last client to be connected, unpause
1178 if ((f = ED_FindFunction ("RestoreGame")))
1179 if ((RestoreGame = (func_t)(f - pr_functions)))
1181 Con_DPrint("Calling RestoreGame\n");
1182 pr_global_struct->time = sv.time;
1183 pr_global_struct->self = EDICT_TO_PROG(sv_player);
1184 PR_ExecuteProgram (RestoreGame, "QC function RestoreGame is missing");
1190 ED_ClearEdict(sv_player);
1192 //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);
1194 // copy spawn parms out of the client_t
1195 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1196 (&pr_global_struct->parm1)[i] = host_client->spawn_parms[i];
1198 // call the spawn function
1199 pr_global_struct->time = sv.time;
1200 pr_global_struct->self = EDICT_TO_PROG(sv_player);
1201 PR_ExecuteProgram (pr_global_struct->ClientConnect, "QC function ClientConnect is missing");
1203 if ((Sys_DoubleTime() - host_client->netconnection->connecttime) <= sv.time)
1204 Sys_Printf("%s entered the game\n", host_client->name);
1206 PR_ExecuteProgram (pr_global_struct->PutClientInServer, "QC function PutClientInServer is missing");
1210 // send time of update
1211 MSG_WriteByte (&host_client->message, svc_time);
1212 MSG_WriteFloat (&host_client->message, sv.time);
1214 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
1216 if (!client->active)
1218 MSG_WriteByte (&host_client->message, svc_updatename);
1219 MSG_WriteByte (&host_client->message, i);
1220 MSG_WriteString (&host_client->message, client->old_name);
1221 MSG_WriteByte (&host_client->message, svc_updatefrags);
1222 MSG_WriteByte (&host_client->message, i);
1223 MSG_WriteShort (&host_client->message, client->old_frags);
1224 MSG_WriteByte (&host_client->message, svc_updatecolors);
1225 MSG_WriteByte (&host_client->message, i);
1226 MSG_WriteByte (&host_client->message, client->old_colors);
1229 // send all current light styles
1230 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1232 MSG_WriteByte (&host_client->message, svc_lightstyle);
1233 MSG_WriteByte (&host_client->message, (char)i);
1234 MSG_WriteString (&host_client->message, sv.lightstyles[i]);
1238 MSG_WriteByte (&host_client->message, svc_updatestat);
1239 MSG_WriteByte (&host_client->message, STAT_TOTALSECRETS);
1240 MSG_WriteLong (&host_client->message, pr_global_struct->total_secrets);
1242 MSG_WriteByte (&host_client->message, svc_updatestat);
1243 MSG_WriteByte (&host_client->message, STAT_TOTALMONSTERS);
1244 MSG_WriteLong (&host_client->message, pr_global_struct->total_monsters);
1246 MSG_WriteByte (&host_client->message, svc_updatestat);
1247 MSG_WriteByte (&host_client->message, STAT_SECRETS);
1248 MSG_WriteLong (&host_client->message, pr_global_struct->found_secrets);
1250 MSG_WriteByte (&host_client->message, svc_updatestat);
1251 MSG_WriteByte (&host_client->message, STAT_MONSTERS);
1252 MSG_WriteLong (&host_client->message, pr_global_struct->killed_monsters);
1255 // Never send a roll angle, because savegames can catch the server
1256 // in a state where it is expecting the client to correct the angle
1257 // and it won't happen if the game was just loaded, so you wind up
1258 // with a permanent head tilt
1259 MSG_WriteByte (&host_client->message, svc_setangle);
1260 MSG_WriteAngle (&host_client->message, sv_player->v->angles[0], sv.protocol);
1261 MSG_WriteAngle (&host_client->message, sv_player->v->angles[1], sv.protocol);
1262 MSG_WriteAngle (&host_client->message, 0, sv.protocol);
1264 SV_WriteClientdataToMessage (sv_player, &host_client->message);
1266 MSG_WriteByte (&host_client->message, svc_signonnum);
1267 MSG_WriteByte (&host_client->message, 3);
1268 host_client->sendsignon = true;
1276 void Host_Begin_f (void)
1278 if (cmd_source == src_command)
1280 Con_Print("begin is not valid from the console\n");
1284 host_client->spawned = true;
1287 //===========================================================================
1294 Kicks a user off of the server
1297 void Host_Kick_f (void)
1300 const char *message = NULL;
1303 qboolean byNumber = false;
1305 if (cmd_source != src_command || !sv.active)
1310 if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1312 i = atof(Cmd_Argv(2)) - 1;
1313 if (i < 0 || i >= svs.maxclients || !(host_client = svs.clients + i)->active)
1319 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1321 if (!host_client->active)
1323 if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1328 if (i < svs.maxclients)
1330 if (cmd_source == src_command)
1332 if (cls.state == ca_dedicated)
1335 who = cl_name.string;
1340 // can't kick yourself!
1341 if (host_client == save)
1346 message = Cmd_Args();
1347 COM_ParseToken(&message, false);
1350 message++; // skip the #
1351 while (*message == ' ') // skip white space
1353 message += strlen(Cmd_Argv(2)); // skip the number
1355 while (*message && *message == ' ')
1359 SV_ClientPrintf("Kicked by %s: %s\n", who, message);
1361 SV_ClientPrintf("Kicked by %s\n", who);
1362 SV_DropClient (false); // kicked
1369 ===============================================================================
1373 ===============================================================================
1381 void Host_Give_f (void)
1387 if (cmd_source == src_command)
1389 Cmd_ForwardToServer ();
1398 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
1403 v = atoi (Cmd_Argv(2));
1417 // MED 01/04/97 added hipnotic give stuff
1418 if (gamemode == GAME_HIPNOTIC)
1423 sv_player->v->items = (int)sv_player->v->items | HIT_PROXIMITY_GUN;
1425 sv_player->v->items = (int)sv_player->v->items | IT_GRENADE_LAUNCHER;
1427 else if (t[0] == '9')
1428 sv_player->v->items = (int)sv_player->v->items | HIT_LASER_CANNON;
1429 else if (t[0] == '0')
1430 sv_player->v->items = (int)sv_player->v->items | HIT_MJOLNIR;
1431 else if (t[0] >= '2')
1432 sv_player->v->items = (int)sv_player->v->items | (IT_SHOTGUN << (t[0] - '2'));
1437 sv_player->v->items = (int)sv_player->v->items | (IT_SHOTGUN << (t[0] - '2'));
1442 if (gamemode == GAME_ROGUE && (val = GETEDICTFIELDVALUE(sv_player, eval_ammo_shells1)))
1445 sv_player->v->ammo_shells = v;
1448 if (gamemode == GAME_ROGUE)
1450 if ((val = GETEDICTFIELDVALUE(sv_player, eval_ammo_nails1)))
1453 if (sv_player->v->weapon <= IT_LIGHTNING)
1454 sv_player->v->ammo_nails = v;
1459 sv_player->v->ammo_nails = v;
1463 if (gamemode == GAME_ROGUE)
1465 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_lava_nails);
1469 if (sv_player->v->weapon > IT_LIGHTNING)
1470 sv_player->v->ammo_nails = v;
1475 if (gamemode == GAME_ROGUE)
1477 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_rockets1);
1481 if (sv_player->v->weapon <= IT_LIGHTNING)
1482 sv_player->v->ammo_rockets = v;
1487 sv_player->v->ammo_rockets = v;
1491 if (gamemode == GAME_ROGUE)
1493 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_multi_rockets);
1497 if (sv_player->v->weapon > IT_LIGHTNING)
1498 sv_player->v->ammo_rockets = v;
1503 sv_player->v->health = v;
1506 if (gamemode == GAME_ROGUE)
1508 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_cells1);
1512 if (sv_player->v->weapon <= IT_LIGHTNING)
1513 sv_player->v->ammo_cells = v;
1518 sv_player->v->ammo_cells = v;
1522 if (gamemode == GAME_ROGUE)
1524 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_plasma);
1528 if (sv_player->v->weapon > IT_LIGHTNING)
1529 sv_player->v->ammo_cells = v;
1536 edict_t *FindViewthing (void)
1541 for (i=0 ; i<sv.num_edicts ; i++)
1544 if (!strcmp (PR_GetString(e->v->classname), "viewthing"))
1547 Con_Print("No viewthing on map\n");
1556 void Host_Viewmodel_f (void)
1561 e = FindViewthing ();
1565 m = Mod_ForName (Cmd_Argv(1), false, true, false);
1568 Con_Printf("Can't load %s\n", Cmd_Argv(1));
1573 cl.model_precache[(int)e->v->modelindex] = m;
1581 void Host_Viewframe_f (void)
1587 e = FindViewthing ();
1590 m = cl.model_precache[(int)e->v->modelindex];
1592 f = atoi(Cmd_Argv(1));
1593 if (f >= m->numframes)
1600 void PrintFrameName (model_t *m, int frame)
1603 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1605 Con_Printf("frame %i\n", frame);
1613 void Host_Viewnext_f (void)
1618 e = FindViewthing ();
1621 m = cl.model_precache[(int)e->v->modelindex];
1623 e->v->frame = e->v->frame + 1;
1624 if (e->v->frame >= m->numframes)
1625 e->v->frame = m->numframes - 1;
1627 PrintFrameName (m, e->v->frame);
1635 void Host_Viewprev_f (void)
1640 e = FindViewthing ();
1644 m = cl.model_precache[(int)e->v->modelindex];
1646 e->v->frame = e->v->frame - 1;
1647 if (e->v->frame < 0)
1650 PrintFrameName (m, e->v->frame);
1654 ===============================================================================
1658 ===============================================================================
1667 void Host_Startdemos_f (void)
1671 if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
1675 if (gamemode == GAME_TRANSFUSION)
1676 Cbuf_AddText ("map bb1\n");
1678 Cbuf_AddText ("map start\n");
1686 Con_Printf("Max %i demos in demoloop\n", MAX_DEMOS);
1689 Con_DPrintf("%i demo(s) in loop\n", c);
1691 for (i=1 ; i<c+1 ; i++)
1692 strlcpy (cls.demos[i-1], Cmd_Argv(i), sizeof (cls.demos[i-1]));
1694 // LordHavoc: clear the remaining slots
1695 for (;i <= MAX_DEMOS;i++)
1696 cls.demos[i-1][0] = 0;
1698 if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
1712 Return to looping demos
1715 void Host_Demos_f (void)
1717 if (cls.state == ca_dedicated)
1719 if (cls.demonum == -1)
1729 Return to looping demos
1732 void Host_Stopdemo_f (void)
1734 if (!cls.demoplayback)
1737 Host_ShutdownServer (false);
1740 static void MaxPlayers_f(void)
1744 if (Cmd_Argc() != 2)
1746 Con_Printf("\"maxplayers\" is \"%u\"\n", svs.maxclients);
1752 Con_Print("maxplayers can not be changed while a server is running.\n");
1756 n = atoi(Cmd_Argv(1));
1757 n = bound(1, n, MAX_SCOREBOARD);
1758 Con_Printf("\"maxplayers\" set to \"%u\"\n", n);
1761 Mem_Free(svs.clients);
1763 svs.clients = Mem_Alloc(sv_clients_mempool, sizeof(client_t) * svs.maxclients);
1765 Cvar_Set ("deathmatch", "0");
1767 Cvar_Set ("deathmatch", "1");
1770 //=============================================================================
1777 void Host_InitCommands (void)
1779 Cmd_AddCommand ("status", Host_Status_f);
1780 Cmd_AddCommand ("quit", Host_Quit_f);
1781 if (gamemode == GAME_NEHAHRA)
1783 Cmd_AddCommand ("max", Host_God_f);
1784 Cmd_AddCommand ("monster", Host_Notarget_f);
1785 Cmd_AddCommand ("scrag", Host_Fly_f);
1786 Cmd_AddCommand ("wraith", Host_Noclip_f);
1787 Cmd_AddCommand ("gimme", Host_Give_f);
1791 Cmd_AddCommand ("god", Host_God_f);
1792 Cmd_AddCommand ("notarget", Host_Notarget_f);
1793 Cmd_AddCommand ("fly", Host_Fly_f);
1794 Cmd_AddCommand ("noclip", Host_Noclip_f);
1795 Cmd_AddCommand ("give", Host_Give_f);
1797 Cmd_AddCommand ("map", Host_Map_f);
1798 Cmd_AddCommand ("restart", Host_Restart_f);
1799 Cmd_AddCommand ("changelevel", Host_Changelevel_f);
1800 Cmd_AddCommand ("connect", Host_Connect_f);
1801 Cmd_AddCommand ("reconnect", Host_Reconnect_f);
1802 Cmd_AddCommand ("version", Host_Version_f);
1803 Cmd_AddCommand ("say", Host_Say_f);
1804 Cmd_AddCommand ("say_team", Host_Say_Team_f);
1805 Cmd_AddCommand ("tell", Host_Tell_f);
1806 Cmd_AddCommand ("kill", Host_Kill_f);
1807 Cmd_AddCommand ("pause", Host_Pause_f);
1808 Cmd_AddCommand ("kick", Host_Kick_f);
1809 Cmd_AddCommand ("ping", Host_Ping_f);
1810 Cmd_AddCommand ("load", Host_Loadgame_f);
1811 Cmd_AddCommand ("save", Host_Savegame_f);
1813 Cmd_AddCommand ("startdemos", Host_Startdemos_f);
1814 Cmd_AddCommand ("demos", Host_Demos_f);
1815 Cmd_AddCommand ("stopdemo", Host_Stopdemo_f);
1817 Cmd_AddCommand ("viewmodel", Host_Viewmodel_f);
1818 Cmd_AddCommand ("viewframe", Host_Viewframe_f);
1819 Cmd_AddCommand ("viewnext", Host_Viewnext_f);
1820 Cmd_AddCommand ("viewprev", Host_Viewprev_f);
1822 Cvar_RegisterVariable (&cl_name);
1823 Cmd_AddCommand ("name", Host_Name_f);
1824 Cvar_RegisterVariable (&cl_color);
1825 Cmd_AddCommand ("color", Host_Color_f);
1826 Cvar_RegisterVariable (&cl_rate);
1827 Cmd_AddCommand ("rate", Host_Rate_f);
1828 if (gamemode == GAME_NEHAHRA)
1830 Cvar_RegisterVariable (&cl_pmodel);
1831 Cmd_AddCommand ("pmodel", Host_PModel_f);
1833 Cmd_AddCommand ("prespawn", Host_PreSpawn_f);
1834 Cmd_AddCommand ("spawn", Host_Spawn_f);
1835 Cmd_AddCommand ("begin", Host_Begin_f);
1836 Cmd_AddCommand ("maxplayers", MaxPlayers_f);
1838 Cvar_RegisterVariable(&sv_cheats);