2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 cvar_t sv_cheats = {0, "sv_cheats", "0"};
25 qboolean allowcheats = false;
27 mfunction_t *ED_FindFunction (char *name);
35 void Host_Quit_f (void)
46 void Host_Status_f (void)
48 const char *protocolname;
50 int seconds, minutes, hours = 0, j, players;
51 void (*print) (const char *fmt, ...);
53 if (cmd_source == src_command)
57 Cmd_ForwardToServer ();
63 print = SV_ClientPrintf;
65 for (players = 0, j = 0;j < svs.maxclients;j++)
66 if (svs.clients[j].active)
68 print ("host: %s\n", Cvar_VariableString ("hostname"));
69 print ("version: %s build %s\n", gamename, buildstring);
72 case PROTOCOL_QUAKE: protocolname = sv.netquakecompatible ? "QUAKE" : "QUAKEDP";break;
73 case PROTOCOL_DARKPLACES1: protocolname = "PROTOCOL_DARKPLACES1";break;
74 case PROTOCOL_DARKPLACES2: protocolname = "PROTOCOL_DARKPLACES2";break;
75 case PROTOCOL_DARKPLACES3: protocolname = "PROTOCOL_DARKPLACES3";break;
76 case PROTOCOL_DARKPLACES4: protocolname = "PROTOCOL_DARKPLACES4";break;
77 case PROTOCOL_DARKPLACES5: protocolname = "PROTOCOL_DARKPLACES5";break;
78 default: protocolname = "PROTOCOL_UNKNOWN";break;
80 print ("protocol: %i (%s)\n", sv.protocol, protocolname);
81 print ("map: %s\n", sv.name);
82 print ("players: %i active (%i max)\n\n", players, svs.maxclients);
83 for (j = 0, client = svs.clients;j < svs.maxclients;j++, client++)
87 seconds = (int)(realtime - client->netconnection->connecttime);
88 minutes = seconds / 60;
91 seconds -= (minutes * 60);
94 minutes -= (hours * 60);
98 print ("#%-2u %-16.16s %3i %2i:%02i:%02i\n", j+1, client->name, (int)client->edict->v->frags, hours, minutes, seconds);
99 print (" %s\n", client->netconnection->address);
108 Sets client to godmode
111 void Host_God_f (void)
113 if (cmd_source == src_command)
115 Cmd_ForwardToServer ();
124 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
128 sv_player->v->flags = (int)sv_player->v->flags ^ FL_GODMODE;
129 if (!((int)sv_player->v->flags & FL_GODMODE) )
130 SV_ClientPrint("godmode OFF\n");
132 SV_ClientPrint("godmode ON\n");
135 void Host_Notarget_f (void)
137 if (cmd_source == src_command)
139 Cmd_ForwardToServer ();
148 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
152 sv_player->v->flags = (int)sv_player->v->flags ^ FL_NOTARGET;
153 if (!((int)sv_player->v->flags & FL_NOTARGET) )
154 SV_ClientPrint("notarget OFF\n");
156 SV_ClientPrint("notarget ON\n");
159 qboolean noclip_anglehack;
161 void Host_Noclip_f (void)
163 if (cmd_source == src_command)
165 Cmd_ForwardToServer ();
174 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
178 if (sv_player->v->movetype != MOVETYPE_NOCLIP)
180 noclip_anglehack = true;
181 sv_player->v->movetype = MOVETYPE_NOCLIP;
182 SV_ClientPrint("noclip ON\n");
186 noclip_anglehack = false;
187 sv_player->v->movetype = MOVETYPE_WALK;
188 SV_ClientPrint("noclip OFF\n");
196 Sets client to flymode
199 void Host_Fly_f (void)
201 if (cmd_source == src_command)
203 Cmd_ForwardToServer ();
212 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
216 if (sv_player->v->movetype != MOVETYPE_FLY)
218 sv_player->v->movetype = MOVETYPE_FLY;
219 SV_ClientPrint("flymode ON\n");
223 sv_player->v->movetype = MOVETYPE_WALK;
224 SV_ClientPrint("flymode OFF\n");
235 void Host_Ping_f (void)
241 if (cmd_source == src_command)
243 Cmd_ForwardToServer ();
247 SV_ClientPrint("Client ping times:\n");
248 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
253 for (j=0 ; j<NUM_PING_TIMES ; j++)
254 total+=client->ping_times[j];
255 total /= NUM_PING_TIMES;
256 SV_ClientPrintf("%4i %s\n", (int)(total*1000), client->name);
261 ===============================================================================
265 ===============================================================================
269 ======================
274 command from the console. Active clients are kicked off.
275 ======================
277 void Host_Map_f (void)
279 char level[MAX_QPATH];
283 Con_Print("map <levelname> : start a new game (kicks off all players)\n");
287 if (cmd_source != src_command)
290 SCR_BeginLoadingPlaque ();
291 cls.demonum = -1; // stop demo loop in case this fails
294 Host_ShutdownServer(false);
296 // remove console or menu
298 key_consoleactive = 0;
300 svs.serverflags = 0; // haven't completed an episode yet
301 allowcheats = sv_cheats.integer != 0;
302 strcpy(level, Cmd_Argv(1));
303 SV_SpawnServer(level);
304 if (sv.active && cls.state == ca_disconnected)
305 CL_EstablishConnection("local:1");
312 Goes to a new map, taking all clients along
315 void Host_Changelevel_f (void)
317 char level[MAX_QPATH];
321 Con_Print("changelevel <levelname> : continue game on a new level\n");
324 if (!sv.active || cls.demoplayback)
326 Con_Print("Only the server may changelevel\n");
329 if (cmd_source != src_command)
332 // remove console or menu
334 key_consoleactive = 0;
336 SV_SaveSpawnparms ();
337 SCR_BeginLoadingPlaque();
338 allowcheats = sv_cheats.integer != 0;
339 strcpy(level, Cmd_Argv(1));
340 SV_SpawnServer(level);
341 if (sv.active && cls.state == ca_disconnected)
342 CL_EstablishConnection("local:1");
349 Restarts the current server for a dead player
352 void Host_Restart_f (void)
354 char mapname[MAX_QPATH];
358 Con_Print("restart : restart current level\n");
361 if (!sv.active || cls.demoplayback)
363 Con_Print("Only the server may restart\n");
366 if (cmd_source != src_command)
369 // remove console or menu
371 key_consoleactive = 0;
373 SCR_BeginLoadingPlaque();
374 allowcheats = sv_cheats.integer != 0;
375 strcpy(mapname, sv.name);
376 SV_SpawnServer(mapname);
377 if (sv.active && cls.state == ca_disconnected)
378 CL_EstablishConnection("local:1");
385 This command causes the client to wait for the signon messages again.
386 This is sent just before a server changes levels
389 void Host_Reconnect_f (void)
393 Con_Print("reconnect : wait for signon messages again\n");
398 //Con_Print("reconnect: no signon, ignoring reconnect\n");
401 SCR_BeginLoadingPlaque();
402 cls.signon = 0; // need new connection messages
406 =====================
409 User command to connect to server
410 =====================
412 void Host_Connect_f (void)
416 Con_Print("connect <serveraddress> : connect to a multiplayer game\n");
419 CL_EstablishConnection(Cmd_Argv(1));
424 ===============================================================================
428 ===============================================================================
431 #define SAVEGAME_VERSION 5
437 Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
440 void Host_SavegameComment (char *text)
445 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
447 memcpy (text, cl.levelname, strlen(cl.levelname));
448 sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
449 memcpy (text+22, kills, strlen(kills));
450 // convert space to _ to make stdio happy
451 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
454 text[SAVEGAME_COMMENT_LENGTH] = '\0';
463 void Host_Savegame_f (void)
468 char comment[SAVEGAME_COMMENT_LENGTH+1];
470 if (cmd_source != src_command)
473 if (cls.state != ca_connected || !sv.active)
475 Con_Print("Not playing a local game.\n");
481 Con_Print("Can't save in intermission.\n");
485 for (i = 0;i < svs.maxclients;i++)
487 if (svs.clients[i].active)
491 Con_Print("Can't save multiplayer games.\n");
494 if (svs.clients[i].edict->v->deadflag)
496 Con_Print("Can't savegame with a dead player\n");
504 Con_Print("save <savename> : save a game\n");
508 if (strstr(Cmd_Argv(1), ".."))
510 Con_Print("Relative pathnames are not allowed.\n");
514 strlcpy (name, Cmd_Argv(1), sizeof (name));
515 FS_DefaultExtension (name, ".sav", sizeof (name));
517 Con_Printf("Saving game to %s...\n", name);
518 f = FS_Open (name, "w", false);
521 Con_Print("ERROR: couldn't open.\n");
525 FS_Printf(f, "%i\n", SAVEGAME_VERSION);
526 Host_SavegameComment (comment);
527 FS_Printf(f, "%s\n", comment);
528 for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
529 FS_Printf(f, "%f\n", svs.clients[0].spawn_parms[i]);
530 FS_Printf(f, "%d\n", current_skill);
531 FS_Printf(f, "%s\n", sv.name);
532 FS_Printf(f, "%f\n",sv.time);
534 // write the light styles
536 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
538 if (sv.lightstyles[i])
539 FS_Printf(f, "%s\n", sv.lightstyles[i]);
546 for (i=0 ; i<sv.num_edicts ; i++)
548 ED_Write (f, EDICT_NUM(i));
552 Con_Print("done.\n");
556 extern mempool_t *edictstring_mempool;
563 void Host_Loadgame_f (void)
566 char filename[MAX_QPATH];
567 char mapname[MAX_QPATH];
576 float spawn_parms[NUM_SPAWN_PARMS];
578 if (cmd_source != src_command)
583 Con_Print("load <savename> : load a game\n");
587 strcpy (filename, Cmd_Argv(1));
588 FS_DefaultExtension (filename, ".sav", sizeof (filename));
590 Con_Printf("Loading game from %s...\n", filename);
592 cls.demonum = -1; // stop demo loop in case this fails
594 f = FS_Open (filename, "r", false);
597 Con_Print("ERROR: couldn't open.\n");
601 str = FS_Getline (f);
602 sscanf (str, "%i\n", &version);
603 if (version != SAVEGAME_VERSION)
606 Con_Printf("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
610 SCR_BeginLoadingPlaque ();
612 str = FS_Getline (f);
613 for (i = 0;i < NUM_SPAWN_PARMS;i++)
615 str = FS_Getline (f);
616 sscanf (str, "%f\n", &spawn_parms[i]);
618 // this silliness is so we can load 1.06 save files, which have float skill values
619 str = FS_Getline (f);
620 sscanf (str, "%f\n", &tfloat);
621 current_skill = (int)(tfloat + 0.1);
622 Cvar_SetValue ("skill", (float)current_skill);
624 strcpy (mapname, FS_Getline (f));
626 str = FS_Getline (f);
627 sscanf (str, "%f\n",&time);
629 allowcheats = sv_cheats.integer != 0;
630 SV_SpawnServer (mapname);
633 Con_Print("Couldn't load map\n");
636 sv.paused = true; // pause until all clients connect
639 // load the light styles
641 for (i = 0;i < MAX_LIGHTSTYLES;i++)
643 str = FS_Getline (f);
644 sv.lightstyles[i] = Mem_Alloc(edictstring_mempool, strlen(str)+1);
645 strcpy (sv.lightstyles[i], str);
648 // load the edicts out of the savegame file
653 for (i = 0;i < (int)sizeof(buf) - 1;i++)
665 if (i == sizeof(buf)-1)
666 Host_Error ("Loadgame buffer overflow");
669 if (!COM_ParseToken(&start, false))
674 if (strcmp(com_token,"{"))
675 Host_Error ("First token isn't a brace");
679 // parse the global vars
680 ED_ParseGlobals (start);
685 if (entnum >= MAX_EDICTS)
686 Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)\n", MAX_EDICTS);
687 while (entnum >= sv.max_edicts)
689 ent = EDICT_NUM(entnum);
690 memset (ent->v, 0, progs->entityfields * 4);
691 ent->e->free = false;
692 ED_ParseEdict (start, ent);
694 // link it into the bsp tree
696 SV_LinkEdict (ent, false);
702 sv.num_edicts = entnum;
707 for (i = 0;i < NUM_SPAWN_PARMS;i++)
708 svs.clients[0].spawn_parms[i] = spawn_parms[i];
710 // make sure we're connected to loopback
711 if (cls.state == ca_disconnected || !(cls.state == ca_connected && cls.netcon != NULL && LHNETADDRESS_GetAddressType(&cls.netcon->peeraddress) == LHNETADDRESSTYPE_LOOP))
712 CL_EstablishConnection("local:1");
715 //============================================================================
718 ======================
720 ======================
722 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player"};
723 void Host_Name_f (void)
726 char newName[sizeof(host_client->name)];
728 if (Cmd_Argc () == 1)
730 Con_Printf("\"name\" is \"%s\"\n", cl_name.string);
734 if (Cmd_Argc () == 2)
735 strlcpy (newName, Cmd_Argv(1), sizeof (newName));
737 strlcpy (newName, Cmd_Args(), sizeof (newName));
739 for (i = 0, j = 0;newName[i];i++)
740 if (newName[i] != '\r' && newName[i] != '\n')
741 newName[j++] = newName[i];
744 if (cmd_source == src_command)
746 Cvar_Set ("_cl_name", newName);
747 if (cls.state == ca_connected)
748 Cmd_ForwardToServer ();
752 if (sv.time < host_client->nametime)
754 SV_ClientPrintf("You can't change name more than once every 5 seconds!\n");
758 host_client->nametime = sv.time + 5;
760 if (strcmp(host_client->name, newName) && host_client->name[0] && strcmp(host_client->name, "unconnected"))
761 SV_BroadcastPrintf("%s changed name to %s\n", host_client->name, newName);
762 strcpy(host_client->name, newName);
763 strcpy(host_client->old_name, newName);
765 sv_player->v->netname = PR_SetString(host_client->name);
766 //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);
768 // send notification to all clients
770 MSG_WriteByte(&sv.reliable_datagram, svc_updatename);
771 MSG_WriteByte(&sv.reliable_datagram, host_client->number);
772 MSG_WriteString(&sv.reliable_datagram, host_client->name);
776 void Host_Version_f (void)
778 Con_Printf("Version: %s build %s\n", gamename, buildstring);
781 void Host_Say(qboolean teamonly)
787 // LordHavoc: 256 char say messages
788 unsigned char text[256];
789 qboolean fromServer = false;
791 if (cmd_source == src_command)
793 if (cls.state == ca_dedicated)
800 Cmd_ForwardToServer ();
808 if (!teamplay.integer)
811 // turn on color set 1
820 snprintf (text, sizeof(text), "%c%s: %s", 1, host_client->name, p1);
822 snprintf (text, sizeof(text), "%c<%s> %s", 1, hostname.string, p1);
823 p2 = text + strlen(text);
824 while ((const char *)p2 > (const char *)text && (p2[-1] == '\r' || p2[-1] == '\n' || (p2[-1] == '\"' && quoted)))
826 if (p2[-1] == '\"' && quoted)
831 strlcat(text, "\n", sizeof(text));
833 // note: save is not a valid edict if fromServer is true
835 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
836 if (host_client->spawned && (!teamonly || host_client->edict->v->team == save->edict->v->team))
837 SV_ClientPrint(text);
844 void Host_Say_f(void)
850 void Host_Say_Team_f(void)
856 void Host_Tell_f(void)
861 char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
862 qboolean fromServer = false;
864 if (cmd_source == src_command)
866 if (cls.state == ca_dedicated)
870 Cmd_ForwardToServer ();
879 sprintf (text, "%s: ", host_client->name);
881 sprintf (text, "<%s> ", hostname.string);
884 p2 = p1 + strlen(p1);
885 // remove the target name
886 while (p1 < p2 && *p1 != ' ')
888 while (p1 < p2 && *p1 == ' ')
890 // remove trailing newlines
891 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
893 // remove quotes if present
900 Con_Print("Host_Tell: missing end quote\n");
902 SV_ClientPrint("Host_Tell: missing end quote\n");
904 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
906 for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
912 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
913 if (host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1)))
914 SV_ClientPrint(text);
924 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0"};
925 void Host_Color_f(void)
930 func_t SV_ChangeTeam;
934 Con_Printf("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
935 Con_Print("color <0-15> [0-15]\n");
940 top = bottom = atoi(Cmd_Argv(1));
943 top = atoi(Cmd_Argv(1));
944 bottom = atoi(Cmd_Argv(2));
948 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
952 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
956 playercolor = top*16 + bottom;
958 if (cmd_source == src_command)
960 Cvar_SetValue ("_cl_color", playercolor);
961 if (cls.state == ca_connected)
962 Cmd_ForwardToServer ();
966 if (sv_player && (f = ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - pr_functions)))
968 Con_DPrint("Calling SV_ChangeTeam\n");
969 pr_global_struct->time = sv.time;
970 pr_globals[OFS_PARM0] = playercolor;
971 pr_global_struct->self = EDICT_TO_PROG(sv_player);
972 PR_ExecuteProgram (SV_ChangeTeam, "QC function SV_ChangeTeam is missing");
979 if ((val = GETEDICTFIELDVALUE(sv_player, eval_clientcolors)))
980 val->_float = playercolor;
981 sv_player->v->team = bottom + 1;
983 host_client->colors = playercolor;
984 host_client->old_colors = playercolor;
986 // send notification to all clients
987 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
988 MSG_WriteByte (&sv.reliable_datagram, host_client->number);
989 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
993 cvar_t cl_rate = {CVAR_SAVE, "_cl_rate", "10000"};
994 void Host_Rate_f(void)
1000 Con_Printf("\"rate\" is \"%i\"\n", cl_rate.integer);
1001 Con_Print("rate <500-25000>\n");
1005 rate = atoi(Cmd_Argv(1));
1007 if (cmd_source == src_command)
1009 Cvar_SetValue ("_cl_rate", bound(NET_MINRATE, rate, NET_MAXRATE));
1010 if (cls.state == ca_connected)
1011 Cmd_ForwardToServer ();
1015 host_client->netconnection->rate = rate;
1023 void Host_Kill_f (void)
1025 if (cmd_source == src_command)
1027 Cmd_ForwardToServer ();
1031 if (!sv_player || sv_player->v->health <= 0)
1033 SV_ClientPrint("Can't suicide -- already dead!\n");
1037 pr_global_struct->time = sv.time;
1038 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1039 PR_ExecuteProgram (pr_global_struct->ClientKill, "QC function ClientKill is missing");
1048 void Host_Pause_f (void)
1051 if (cmd_source == src_command)
1053 Cmd_ForwardToServer ();
1056 if (!pausable.integer)
1057 SV_ClientPrint("Pause not allowed.\n");
1061 SV_BroadcastPrintf("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
1062 // send notification to all clients
1063 MSG_WriteByte(&sv.reliable_datagram, svc_setpause);
1064 MSG_WriteByte(&sv.reliable_datagram, sv.paused);
1069 ======================
1071 LordHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
1072 ======================
1074 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0"};
1075 static void Host_PModel_f (void)
1080 if (Cmd_Argc () == 1)
1082 Con_Printf("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
1085 i = atoi(Cmd_Argv(1));
1087 if (cmd_source == src_command)
1089 if (cl_pmodel.integer == i)
1091 Cvar_SetValue ("_cl_pmodel", i);
1092 if (cls.state == ca_connected)
1093 Cmd_ForwardToServer ();
1097 host_client->pmodel = i;
1098 if (sv_player && (val = GETEDICTFIELDVALUE(sv_player, eval_pmodel)))
1102 //===========================================================================
1110 void Host_PreSpawn_f (void)
1112 if (cmd_source == src_command)
1114 Con_Print("prespawn is not valid from the console\n");
1118 if (host_client->spawned)
1120 Con_Print("prespawn not valid -- already spawned\n");
1124 SZ_Write (&host_client->message, sv.signon.data, sv.signon.cursize);
1125 MSG_WriteByte (&host_client->message, svc_signonnum);
1126 MSG_WriteByte (&host_client->message, 2);
1127 host_client->sendsignon = true;
1135 void Host_Spawn_f (void)
1142 if (cmd_source == src_command)
1144 Con_Print("spawn is not valid from the console\n");
1148 if (host_client->spawned)
1150 Con_Print("Spawn not valid -- already spawned\n");
1156 Con_Print("Host_Spawn: no edict??\n");
1160 host_client->nametime = 0;
1162 // LordHavoc: moved this above the QC calls at FrikaC's request
1163 // send all current names, colors, and frag counts
1164 SZ_Clear (&host_client->message);
1166 // run the entrance script
1169 // loaded games are fully initialized already
1170 // if this is the last client to be connected, unpause
1173 if ((f = ED_FindFunction ("RestoreGame")))
1174 if ((RestoreGame = (func_t)(f - pr_functions)))
1176 Con_DPrint("Calling RestoreGame\n");
1177 pr_global_struct->time = sv.time;
1178 pr_global_struct->self = EDICT_TO_PROG(sv_player);
1179 PR_ExecuteProgram (RestoreGame, "QC function RestoreGame is missing");
1185 ED_ClearEdict(sv_player);
1187 //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);
1189 // copy spawn parms out of the client_t
1190 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1191 (&pr_global_struct->parm1)[i] = host_client->spawn_parms[i];
1193 // call the spawn function
1194 pr_global_struct->time = sv.time;
1195 pr_global_struct->self = EDICT_TO_PROG(sv_player);
1196 PR_ExecuteProgram (pr_global_struct->ClientConnect, "QC function ClientConnect is missing");
1198 if ((Sys_DoubleTime() - host_client->netconnection->connecttime) <= sv.time)
1199 Sys_Printf("%s entered the game\n", host_client->name);
1201 PR_ExecuteProgram (pr_global_struct->PutClientInServer, "QC function PutClientInServer is missing");
1205 // send time of update
1206 MSG_WriteByte (&host_client->message, svc_time);
1207 MSG_WriteFloat (&host_client->message, sv.time);
1209 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
1211 if (!client->active)
1213 MSG_WriteByte (&host_client->message, svc_updatename);
1214 MSG_WriteByte (&host_client->message, i);
1215 MSG_WriteString (&host_client->message, client->old_name);
1216 MSG_WriteByte (&host_client->message, svc_updatefrags);
1217 MSG_WriteByte (&host_client->message, i);
1218 MSG_WriteShort (&host_client->message, client->old_frags);
1219 MSG_WriteByte (&host_client->message, svc_updatecolors);
1220 MSG_WriteByte (&host_client->message, i);
1221 MSG_WriteByte (&host_client->message, client->old_colors);
1224 // send all current light styles
1225 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1227 MSG_WriteByte (&host_client->message, svc_lightstyle);
1228 MSG_WriteByte (&host_client->message, (char)i);
1229 MSG_WriteString (&host_client->message, sv.lightstyles[i]);
1233 MSG_WriteByte (&host_client->message, svc_updatestat);
1234 MSG_WriteByte (&host_client->message, STAT_TOTALSECRETS);
1235 MSG_WriteLong (&host_client->message, pr_global_struct->total_secrets);
1237 MSG_WriteByte (&host_client->message, svc_updatestat);
1238 MSG_WriteByte (&host_client->message, STAT_TOTALMONSTERS);
1239 MSG_WriteLong (&host_client->message, pr_global_struct->total_monsters);
1241 MSG_WriteByte (&host_client->message, svc_updatestat);
1242 MSG_WriteByte (&host_client->message, STAT_SECRETS);
1243 MSG_WriteLong (&host_client->message, pr_global_struct->found_secrets);
1245 MSG_WriteByte (&host_client->message, svc_updatestat);
1246 MSG_WriteByte (&host_client->message, STAT_MONSTERS);
1247 MSG_WriteLong (&host_client->message, pr_global_struct->killed_monsters);
1250 // Never send a roll angle, because savegames can catch the server
1251 // in a state where it is expecting the client to correct the angle
1252 // and it won't happen if the game was just loaded, so you wind up
1253 // with a permanent head tilt
1254 MSG_WriteByte (&host_client->message, svc_setangle);
1255 MSG_WriteAngle (&host_client->message, sv_player->v->angles[0], sv.protocol);
1256 MSG_WriteAngle (&host_client->message, sv_player->v->angles[1], sv.protocol);
1257 MSG_WriteAngle (&host_client->message, 0, sv.protocol);
1259 SV_WriteClientdataToMessage (sv_player, &host_client->message);
1261 MSG_WriteByte (&host_client->message, svc_signonnum);
1262 MSG_WriteByte (&host_client->message, 3);
1263 host_client->sendsignon = true;
1271 void Host_Begin_f (void)
1273 if (cmd_source == src_command)
1275 Con_Print("begin is not valid from the console\n");
1279 host_client->spawned = true;
1282 //===========================================================================
1289 Kicks a user off of the server
1292 void Host_Kick_f (void)
1295 const char *message = NULL;
1298 qboolean byNumber = false;
1300 if (cmd_source != src_command || !sv.active)
1305 if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1307 i = atof(Cmd_Argv(2)) - 1;
1308 if (i < 0 || i >= svs.maxclients || !(host_client = svs.clients + i)->active)
1314 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1316 if (!host_client->active)
1318 if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1323 if (i < svs.maxclients)
1325 if (cmd_source == src_command)
1327 if (cls.state == ca_dedicated)
1330 who = cl_name.string;
1335 // can't kick yourself!
1336 if (host_client == save)
1341 message = Cmd_Args();
1342 COM_ParseToken(&message, false);
1345 message++; // skip the #
1346 while (*message == ' ') // skip white space
1348 message += strlen(Cmd_Argv(2)); // skip the number
1350 while (*message && *message == ' ')
1354 SV_ClientPrintf("Kicked by %s: %s\n", who, message);
1356 SV_ClientPrintf("Kicked by %s\n", who);
1357 SV_DropClient (false); // kicked
1364 ===============================================================================
1368 ===============================================================================
1376 void Host_Give_f (void)
1382 if (cmd_source == src_command)
1384 Cmd_ForwardToServer ();
1393 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
1398 v = atoi (Cmd_Argv(2));
1412 // MED 01/04/97 added hipnotic give stuff
1413 if (gamemode == GAME_HIPNOTIC)
1418 sv_player->v->items = (int)sv_player->v->items | HIT_PROXIMITY_GUN;
1420 sv_player->v->items = (int)sv_player->v->items | IT_GRENADE_LAUNCHER;
1422 else if (t[0] == '9')
1423 sv_player->v->items = (int)sv_player->v->items | HIT_LASER_CANNON;
1424 else if (t[0] == '0')
1425 sv_player->v->items = (int)sv_player->v->items | HIT_MJOLNIR;
1426 else if (t[0] >= '2')
1427 sv_player->v->items = (int)sv_player->v->items | (IT_SHOTGUN << (t[0] - '2'));
1432 sv_player->v->items = (int)sv_player->v->items | (IT_SHOTGUN << (t[0] - '2'));
1437 if (gamemode == GAME_ROGUE && (val = GETEDICTFIELDVALUE(sv_player, eval_ammo_shells1)))
1440 sv_player->v->ammo_shells = v;
1443 if (gamemode == GAME_ROGUE)
1445 if ((val = GETEDICTFIELDVALUE(sv_player, eval_ammo_nails1)))
1448 if (sv_player->v->weapon <= IT_LIGHTNING)
1449 sv_player->v->ammo_nails = v;
1454 sv_player->v->ammo_nails = v;
1458 if (gamemode == GAME_ROGUE)
1460 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_lava_nails);
1464 if (sv_player->v->weapon > IT_LIGHTNING)
1465 sv_player->v->ammo_nails = v;
1470 if (gamemode == GAME_ROGUE)
1472 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_rockets1);
1476 if (sv_player->v->weapon <= IT_LIGHTNING)
1477 sv_player->v->ammo_rockets = v;
1482 sv_player->v->ammo_rockets = v;
1486 if (gamemode == GAME_ROGUE)
1488 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_multi_rockets);
1492 if (sv_player->v->weapon > IT_LIGHTNING)
1493 sv_player->v->ammo_rockets = v;
1498 sv_player->v->health = v;
1501 if (gamemode == GAME_ROGUE)
1503 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_cells1);
1507 if (sv_player->v->weapon <= IT_LIGHTNING)
1508 sv_player->v->ammo_cells = v;
1513 sv_player->v->ammo_cells = v;
1517 if (gamemode == GAME_ROGUE)
1519 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_plasma);
1523 if (sv_player->v->weapon > IT_LIGHTNING)
1524 sv_player->v->ammo_cells = v;
1531 edict_t *FindViewthing (void)
1536 for (i=0 ; i<sv.num_edicts ; i++)
1539 if (!strcmp (PR_GetString(e->v->classname), "viewthing"))
1542 Con_Print("No viewthing on map\n");
1551 void Host_Viewmodel_f (void)
1556 e = FindViewthing ();
1560 m = Mod_ForName (Cmd_Argv(1), false, true, false);
1563 Con_Printf("Can't load %s\n", Cmd_Argv(1));
1568 cl.model_precache[(int)e->v->modelindex] = m;
1576 void Host_Viewframe_f (void)
1582 e = FindViewthing ();
1585 m = cl.model_precache[(int)e->v->modelindex];
1587 f = atoi(Cmd_Argv(1));
1588 if (f >= m->numframes)
1595 void PrintFrameName (model_t *m, int frame)
1598 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1600 Con_Printf("frame %i\n", frame);
1608 void Host_Viewnext_f (void)
1613 e = FindViewthing ();
1616 m = cl.model_precache[(int)e->v->modelindex];
1618 e->v->frame = e->v->frame + 1;
1619 if (e->v->frame >= m->numframes)
1620 e->v->frame = m->numframes - 1;
1622 PrintFrameName (m, e->v->frame);
1630 void Host_Viewprev_f (void)
1635 e = FindViewthing ();
1639 m = cl.model_precache[(int)e->v->modelindex];
1641 e->v->frame = e->v->frame - 1;
1642 if (e->v->frame < 0)
1645 PrintFrameName (m, e->v->frame);
1649 ===============================================================================
1653 ===============================================================================
1662 void Host_Startdemos_f (void)
1666 if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
1670 if (gamemode == GAME_TRANSFUSION)
1671 Cbuf_AddText ("map bb1\n");
1673 Cbuf_AddText ("map start\n");
1681 Con_Printf("Max %i demos in demoloop\n", MAX_DEMOS);
1684 Con_DPrintf("%i demo(s) in loop\n", c);
1686 for (i=1 ; i<c+1 ; i++)
1687 strlcpy (cls.demos[i-1], Cmd_Argv(i), sizeof (cls.demos[i-1]));
1689 // LordHavoc: clear the remaining slots
1690 for (;i <= MAX_DEMOS;i++)
1691 cls.demos[i-1][0] = 0;
1693 if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
1707 Return to looping demos
1710 void Host_Demos_f (void)
1712 if (cls.state == ca_dedicated)
1714 if (cls.demonum == -1)
1724 Return to looping demos
1727 void Host_Stopdemo_f (void)
1729 if (!cls.demoplayback)
1732 Host_ShutdownServer (false);
1735 static void MaxPlayers_f(void)
1739 if (Cmd_Argc() != 2)
1741 Con_Printf("\"maxplayers\" is \"%u\"\n", svs.maxclients);
1747 Con_Print("maxplayers can not be changed while a server is running.\n");
1751 n = atoi(Cmd_Argv(1));
1752 n = bound(1, n, MAX_SCOREBOARD);
1753 Con_Printf("\"maxplayers\" set to \"%u\"\n", n);
1756 Mem_Free(svs.clients);
1758 svs.clients = Mem_Alloc(sv_clients_mempool, sizeof(client_t) * svs.maxclients);
1760 Cvar_Set ("deathmatch", "0");
1762 Cvar_Set ("deathmatch", "1");
1765 //=============================================================================
1772 void Host_InitCommands (void)
1774 Cmd_AddCommand ("status", Host_Status_f);
1775 Cmd_AddCommand ("quit", Host_Quit_f);
1776 if (gamemode == GAME_NEHAHRA)
1778 Cmd_AddCommand ("max", Host_God_f);
1779 Cmd_AddCommand ("monster", Host_Notarget_f);
1780 Cmd_AddCommand ("scrag", Host_Fly_f);
1781 Cmd_AddCommand ("wraith", Host_Noclip_f);
1782 Cmd_AddCommand ("gimme", Host_Give_f);
1786 Cmd_AddCommand ("god", Host_God_f);
1787 Cmd_AddCommand ("notarget", Host_Notarget_f);
1788 Cmd_AddCommand ("fly", Host_Fly_f);
1789 Cmd_AddCommand ("noclip", Host_Noclip_f);
1790 Cmd_AddCommand ("give", Host_Give_f);
1792 Cmd_AddCommand ("map", Host_Map_f);
1793 Cmd_AddCommand ("restart", Host_Restart_f);
1794 Cmd_AddCommand ("changelevel", Host_Changelevel_f);
1795 Cmd_AddCommand ("connect", Host_Connect_f);
1796 Cmd_AddCommand ("reconnect", Host_Reconnect_f);
1797 Cmd_AddCommand ("version", Host_Version_f);
1798 Cmd_AddCommand ("say", Host_Say_f);
1799 Cmd_AddCommand ("say_team", Host_Say_Team_f);
1800 Cmd_AddCommand ("tell", Host_Tell_f);
1801 Cmd_AddCommand ("kill", Host_Kill_f);
1802 Cmd_AddCommand ("pause", Host_Pause_f);
1803 Cmd_AddCommand ("kick", Host_Kick_f);
1804 Cmd_AddCommand ("ping", Host_Ping_f);
1805 Cmd_AddCommand ("load", Host_Loadgame_f);
1806 Cmd_AddCommand ("save", Host_Savegame_f);
1808 Cmd_AddCommand ("startdemos", Host_Startdemos_f);
1809 Cmd_AddCommand ("demos", Host_Demos_f);
1810 Cmd_AddCommand ("stopdemo", Host_Stopdemo_f);
1812 Cmd_AddCommand ("viewmodel", Host_Viewmodel_f);
1813 Cmd_AddCommand ("viewframe", Host_Viewframe_f);
1814 Cmd_AddCommand ("viewnext", Host_Viewnext_f);
1815 Cmd_AddCommand ("viewprev", Host_Viewprev_f);
1817 Cvar_RegisterVariable (&cl_name);
1818 Cmd_AddCommand ("name", Host_Name_f);
1819 Cvar_RegisterVariable (&cl_color);
1820 Cmd_AddCommand ("color", Host_Color_f);
1821 Cvar_RegisterVariable (&cl_rate);
1822 Cmd_AddCommand ("rate", Host_Rate_f);
1823 if (gamemode == GAME_NEHAHRA)
1825 Cvar_RegisterVariable (&cl_pmodel);
1826 Cmd_AddCommand ("pmodel", Host_PModel_f);
1828 Cmd_AddCommand ("prespawn", Host_PreSpawn_f);
1829 Cmd_AddCommand ("spawn", Host_Spawn_f);
1830 Cmd_AddCommand ("begin", Host_Begin_f);
1831 Cmd_AddCommand ("maxplayers", MaxPlayers_f);
1833 Cvar_RegisterVariable(&sv_cheats);