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];
286 if (cmd_source != src_command)
289 cls.demonum = -1; // stop demo loop in case this fails
292 Host_ShutdownServer(false);
294 key_dest = key_game; // remove console or menu
295 SCR_BeginLoadingPlaque ();
297 svs.serverflags = 0; // haven't completed an episode yet
298 allowcheats = sv_cheats.integer != 0;
299 strcpy(level, Cmd_Argv(1));
300 SV_SpawnServer(level);
301 if (sv.active && cls.state == ca_disconnected)
302 CL_EstablishConnection("local:1");
309 Goes to a new map, taking all clients along
312 void Host_Changelevel_f (void)
314 char level[MAX_QPATH];
318 Con_Print("changelevel <levelname> : continue game on a new level\n");
321 if (!sv.active || cls.demoplayback)
323 Con_Print("Only the server may changelevel\n");
326 SV_SaveSpawnparms ();
327 allowcheats = sv_cheats.integer != 0;
328 strcpy(level, Cmd_Argv(1));
329 SV_SpawnServer(level);
330 if (sv.active && cls.state == ca_disconnected)
331 CL_EstablishConnection("local:1");
338 Restarts the current server for a dead player
341 void Host_Restart_f (void)
343 char mapname[MAX_QPATH];
345 if (cls.demoplayback || !sv.active)
348 if (cmd_source != src_command)
350 allowcheats = sv_cheats.integer != 0;
351 strcpy(mapname, sv.name);
352 SV_SpawnServer(mapname);
353 if (sv.active && cls.state == ca_disconnected)
354 CL_EstablishConnection("local:1");
361 This command causes the client to wait for the signon messages again.
362 This is sent just before a server changes levels
365 void Host_Reconnect_f (void)
367 SCR_BeginLoadingPlaque();
368 cls.signon = 0; // need new connection messages
372 =====================
375 User command to connect to server
376 =====================
378 void Host_Connect_f (void)
380 CL_EstablishConnection(Cmd_Argv(1));
385 ===============================================================================
389 ===============================================================================
392 #define SAVEGAME_VERSION 5
398 Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
401 void Host_SavegameComment (char *text)
406 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
408 memcpy (text, cl.levelname, strlen(cl.levelname));
409 sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
410 memcpy (text+22, kills, strlen(kills));
411 // convert space to _ to make stdio happy
412 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
415 text[SAVEGAME_COMMENT_LENGTH] = '\0';
424 void Host_Savegame_f (void)
429 char comment[SAVEGAME_COMMENT_LENGTH+1];
431 if (cmd_source != src_command)
434 if (cls.state != ca_connected || !sv.active)
436 Con_Print("Not playing a local game.\n");
442 Con_Print("Can't save in intermission.\n");
446 for (i = 0;i < svs.maxclients;i++)
448 if (svs.clients[i].active)
452 Con_Print("Can't save multiplayer games.\n");
455 if (svs.clients[i].edict->v->deadflag)
457 Con_Print("Can't savegame with a dead player\n");
465 Con_Print("save <savename> : save a game\n");
469 if (strstr(Cmd_Argv(1), ".."))
471 Con_Print("Relative pathnames are not allowed.\n");
475 strlcpy (name, Cmd_Argv(1), sizeof (name));
476 FS_DefaultExtension (name, ".sav", sizeof (name));
478 Con_Printf("Saving game to %s...\n", name);
479 f = FS_Open (name, "w", false);
482 Con_Print("ERROR: couldn't open.\n");
486 FS_Printf(f, "%i\n", SAVEGAME_VERSION);
487 Host_SavegameComment (comment);
488 FS_Printf(f, "%s\n", comment);
489 for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
490 FS_Printf(f, "%f\n", svs.clients[0].spawn_parms[i]);
491 FS_Printf(f, "%d\n", current_skill);
492 FS_Printf(f, "%s\n", sv.name);
493 FS_Printf(f, "%f\n",sv.time);
495 // write the light styles
497 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
499 if (sv.lightstyles[i])
500 FS_Printf(f, "%s\n", sv.lightstyles[i]);
507 for (i=0 ; i<sv.num_edicts ; i++)
509 ED_Write (f, EDICT_NUM(i));
513 Con_Print("done.\n");
517 extern mempool_t *edictstring_mempool;
524 void Host_Loadgame_f (void)
527 char filename[MAX_QPATH];
528 char mapname[MAX_QPATH];
537 float spawn_parms[NUM_SPAWN_PARMS];
539 if (cmd_source != src_command)
544 Con_Print("load <savename> : load a game\n");
548 strcpy (filename, Cmd_Argv(1));
549 FS_DefaultExtension (filename, ".sav", sizeof (filename));
551 Con_Printf("Loading game from %s...\n", filename);
553 cls.demonum = -1; // stop demo loop in case this fails
555 f = FS_Open (filename, "r", false);
558 Con_Print("ERROR: couldn't open.\n");
562 str = FS_Getline (f);
563 sscanf (str, "%i\n", &version);
564 if (version != SAVEGAME_VERSION)
567 Con_Printf("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
571 SCR_BeginLoadingPlaque ();
573 str = FS_Getline (f);
574 for (i = 0;i < NUM_SPAWN_PARMS;i++)
576 str = FS_Getline (f);
577 sscanf (str, "%f\n", &spawn_parms[i]);
579 // this silliness is so we can load 1.06 save files, which have float skill values
580 str = FS_Getline (f);
581 sscanf (str, "%f\n", &tfloat);
582 current_skill = (int)(tfloat + 0.1);
583 Cvar_SetValue ("skill", (float)current_skill);
585 strcpy (mapname, FS_Getline (f));
587 str = FS_Getline (f);
588 sscanf (str, "%f\n",&time);
590 allowcheats = sv_cheats.integer != 0;
591 SV_SpawnServer (mapname);
594 Con_Print("Couldn't load map\n");
597 sv.paused = true; // pause until all clients connect
600 // load the light styles
602 for (i = 0;i < MAX_LIGHTSTYLES;i++)
604 str = FS_Getline (f);
605 sv.lightstyles[i] = Mem_Alloc(edictstring_mempool, strlen(str)+1);
606 strcpy (sv.lightstyles[i], str);
609 // load the edicts out of the savegame file
614 for (i = 0;i < (int)sizeof(buf) - 1;i++)
626 if (i == sizeof(buf)-1)
627 Host_Error ("Loadgame buffer overflow");
630 if (!COM_ParseToken(&start, false))
635 if (strcmp(com_token,"{"))
636 Host_Error ("First token isn't a brace");
640 // parse the global vars
641 ED_ParseGlobals (start);
646 if (entnum >= MAX_EDICTS)
647 Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)\n", MAX_EDICTS);
648 while (entnum >= sv.max_edicts)
650 ent = EDICT_NUM(entnum);
651 memset (ent->v, 0, progs->entityfields * 4);
652 ent->e->free = false;
653 ED_ParseEdict (start, ent);
655 // link it into the bsp tree
657 SV_LinkEdict (ent, false);
663 sv.num_edicts = entnum;
668 for (i = 0;i < NUM_SPAWN_PARMS;i++)
669 svs.clients[0].spawn_parms[i] = spawn_parms[i];
671 // make sure we're connected to loopback
672 if (cls.state == ca_disconnected || !(cls.state == ca_connected && cls.netcon != NULL && LHNETADDRESS_GetAddressType(&cls.netcon->peeraddress) == LHNETADDRESSTYPE_LOOP))
673 CL_EstablishConnection("local:1");
676 //============================================================================
679 ======================
681 ======================
683 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player"};
684 void Host_Name_f (void)
687 char newName[sizeof(host_client->name)];
689 if (Cmd_Argc () == 1)
691 Con_Printf("\"name\" is \"%s\"\n", cl_name.string);
695 if (Cmd_Argc () == 2)
696 strlcpy (newName, Cmd_Argv(1), sizeof (newName));
698 strlcpy (newName, Cmd_Args(), sizeof (newName));
700 for (i = 0, j = 0;newName[i];i++)
701 if (newName[i] != '\r' && newName[i] != '\n')
702 newName[j++] = newName[i];
705 if (cmd_source == src_command)
707 Cvar_Set ("_cl_name", newName);
708 if (cls.state == ca_connected)
709 Cmd_ForwardToServer ();
713 if (sv.time < host_client->nametime)
715 SV_ClientPrintf("You can't change name more than once every 5 seconds!\n");
719 host_client->nametime = sv.time + 5;
721 if (strcmp(host_client->name, newName) && host_client->name[0] && strcmp(host_client->name, "unconnected"))
722 SV_BroadcastPrintf("%s changed name to %s\n", host_client->name, newName);
723 strcpy(host_client->name, newName);
724 strcpy(host_client->old_name, newName);
726 sv_player->v->netname = PR_SetString(host_client->name);
727 //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);
729 // send notification to all clients
731 MSG_WriteByte(&sv.reliable_datagram, svc_updatename);
732 MSG_WriteByte(&sv.reliable_datagram, host_client->number);
733 MSG_WriteString(&sv.reliable_datagram, host_client->name);
737 void Host_Version_f (void)
739 Con_Printf("Version: %s build %s\n", gamename, buildstring);
742 void Host_Say(qboolean teamonly)
747 // LordHavoc: 256 char say messages
748 unsigned char text[256];
749 qboolean fromServer = false;
751 if (cmd_source == src_command)
753 if (cls.state == ca_dedicated)
760 Cmd_ForwardToServer ();
770 // turn on color set 1
772 sprintf (text, "%c%s: ", 1, host_client->name);
774 sprintf (text, "%c<%s> ", 1, hostname.string);
777 p2 = p1 + strlen(p1);
778 // remove trailing newlines
779 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
781 // remove quotes if present
788 Con_Print("Host_Say: missing end quote\n");
790 SV_ClientPrint("Host_Say: missing end quote\n");
792 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
794 for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
799 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
800 if (host_client->spawned && (!teamplay.integer || host_client->edict->v->team == save->edict->v->team))
801 SV_ClientPrint(text);
808 void Host_Say_f(void)
814 void Host_Say_Team_f(void)
820 void Host_Tell_f(void)
825 char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
826 qboolean fromServer = false;
828 if (cmd_source == src_command)
830 if (cls.state == ca_dedicated)
834 Cmd_ForwardToServer ();
843 sprintf (text, "%s: ", host_client->name);
845 sprintf (text, "<%s> ", hostname.string);
848 p2 = p1 + strlen(p1);
849 // remove the target name
850 while (p1 < p2 && *p1 != ' ')
852 while (p1 < p2 && *p1 == ' ')
854 // remove trailing newlines
855 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
857 // remove quotes if present
864 Con_Print("Host_Tell: missing end quote\n");
866 SV_ClientPrint("Host_Tell: missing end quote\n");
868 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
870 for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
876 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
877 if (host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1)))
878 SV_ClientPrint(text);
888 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0"};
889 void Host_Color_f(void)
894 func_t SV_ChangeTeam;
898 Con_Printf("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
899 Con_Print("color <0-15> [0-15]\n");
904 top = bottom = atoi(Cmd_Argv(1));
907 top = atoi(Cmd_Argv(1));
908 bottom = atoi(Cmd_Argv(2));
912 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
916 // LordHavoc: allow skin colormaps 14 and 15 (was 13)
920 playercolor = top*16 + bottom;
922 if (cmd_source == src_command)
924 Cvar_SetValue ("_cl_color", playercolor);
925 if (cls.state == ca_connected)
926 Cmd_ForwardToServer ();
930 if (sv_player && (f = ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - pr_functions)))
932 Con_DPrint("Calling SV_ChangeTeam\n");
933 pr_global_struct->time = sv.time;
934 pr_globals[OFS_PARM0] = playercolor;
935 pr_global_struct->self = EDICT_TO_PROG(sv_player);
936 PR_ExecuteProgram (SV_ChangeTeam, "");
943 if ((val = GETEDICTFIELDVALUE(sv_player, eval_clientcolors)))
944 val->_float = playercolor;
945 sv_player->v->team = bottom + 1;
947 host_client->colors = playercolor;
948 host_client->old_colors = playercolor;
950 // send notification to all clients
951 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
952 MSG_WriteByte (&sv.reliable_datagram, host_client->number);
953 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
957 cvar_t cl_rate = {CVAR_SAVE, "_cl_rate", "10000"};
958 void Host_Rate_f(void)
964 Con_Printf("\"rate\" is \"%i\"\n", cl_rate.integer);
965 Con_Print("rate <500-25000>\n");
969 rate = atoi(Cmd_Argv(1));
971 if (cmd_source == src_command)
973 Cvar_SetValue ("_cl_rate", bound(NET_MINRATE, rate, NET_MAXRATE));
974 if (cls.state == ca_connected)
975 Cmd_ForwardToServer ();
979 host_client->netconnection->rate = rate;
987 void Host_Kill_f (void)
989 if (cmd_source == src_command)
991 Cmd_ForwardToServer ();
995 if (!sv_player || sv_player->v->health <= 0)
997 SV_ClientPrint("Can't suicide -- already dead!\n");
1001 pr_global_struct->time = sv.time;
1002 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1003 PR_ExecuteProgram (pr_global_struct->ClientKill, "QC function ClientKill is missing");
1012 void Host_Pause_f (void)
1015 if (cmd_source == src_command)
1017 Cmd_ForwardToServer ();
1020 if (!pausable.integer)
1021 SV_ClientPrint("Pause not allowed.\n");
1025 SV_BroadcastPrintf("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
1026 // send notification to all clients
1027 MSG_WriteByte(&sv.reliable_datagram, svc_setpause);
1028 MSG_WriteByte(&sv.reliable_datagram, sv.paused);
1033 ======================
1035 LordHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
1036 ======================
1038 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0"};
1039 static void Host_PModel_f (void)
1044 if (Cmd_Argc () == 1)
1046 Con_Printf("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
1049 i = atoi(Cmd_Argv(1));
1051 if (cmd_source == src_command)
1053 if (cl_pmodel.integer == i)
1055 Cvar_SetValue ("_cl_pmodel", i);
1056 if (cls.state == ca_connected)
1057 Cmd_ForwardToServer ();
1061 host_client->pmodel = i;
1062 if (sv_player && (val = GETEDICTFIELDVALUE(sv_player, eval_pmodel)))
1066 //===========================================================================
1074 void Host_PreSpawn_f (void)
1076 if (cmd_source == src_command)
1078 Con_Print("prespawn is not valid from the console\n");
1082 if (host_client->spawned)
1084 Con_Print("prespawn not valid -- already spawned\n");
1088 SZ_Write (&host_client->message, sv.signon.data, sv.signon.cursize);
1089 MSG_WriteByte (&host_client->message, svc_signonnum);
1090 MSG_WriteByte (&host_client->message, 2);
1091 host_client->sendsignon = true;
1099 void Host_Spawn_f (void)
1106 if (cmd_source == src_command)
1108 Con_Print("spawn is not valid from the console\n");
1112 if (host_client->spawned)
1114 Con_Print("Spawn not valid -- already spawned\n");
1120 Con_Print("Host_Spawn: no edict??\n");
1124 host_client->nametime = 0;
1126 // LordHavoc: moved this above the QC calls at FrikaC's request
1127 // send all current names, colors, and frag counts
1128 SZ_Clear (&host_client->message);
1130 // run the entrance script
1133 // loaded games are fully initialized already
1134 // if this is the last client to be connected, unpause
1137 if ((f = ED_FindFunction ("RestoreGame")))
1138 if ((RestoreGame = (func_t)(f - pr_functions)))
1140 Con_DPrint("Calling RestoreGame\n");
1141 pr_global_struct->time = sv.time;
1142 pr_global_struct->self = EDICT_TO_PROG(sv_player);
1143 PR_ExecuteProgram (RestoreGame, "");
1149 ED_ClearEdict(sv_player);
1151 //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);
1153 // copy spawn parms out of the client_t
1154 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1155 (&pr_global_struct->parm1)[i] = host_client->spawn_parms[i];
1157 // call the spawn function
1158 pr_global_struct->time = sv.time;
1159 pr_global_struct->self = EDICT_TO_PROG(sv_player);
1160 PR_ExecuteProgram (pr_global_struct->ClientConnect, "QC function ClientConnect is missing");
1162 if ((Sys_DoubleTime() - host_client->netconnection->connecttime) <= sv.time)
1163 Sys_Printf("%s entered the game\n", host_client->name);
1165 PR_ExecuteProgram (pr_global_struct->PutClientInServer, "QC function PutClientInServer is missing");
1169 // send time of update
1170 MSG_WriteByte (&host_client->message, svc_time);
1171 MSG_WriteFloat (&host_client->message, sv.time);
1173 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
1175 if (!client->active)
1177 MSG_WriteByte (&host_client->message, svc_updatename);
1178 MSG_WriteByte (&host_client->message, i);
1179 MSG_WriteString (&host_client->message, client->old_name);
1180 MSG_WriteByte (&host_client->message, svc_updatefrags);
1181 MSG_WriteByte (&host_client->message, i);
1182 MSG_WriteShort (&host_client->message, client->old_frags);
1183 MSG_WriteByte (&host_client->message, svc_updatecolors);
1184 MSG_WriteByte (&host_client->message, i);
1185 MSG_WriteByte (&host_client->message, client->old_colors);
1188 // send all current light styles
1189 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1191 MSG_WriteByte (&host_client->message, svc_lightstyle);
1192 MSG_WriteByte (&host_client->message, (char)i);
1193 MSG_WriteString (&host_client->message, sv.lightstyles[i]);
1197 MSG_WriteByte (&host_client->message, svc_updatestat);
1198 MSG_WriteByte (&host_client->message, STAT_TOTALSECRETS);
1199 MSG_WriteLong (&host_client->message, pr_global_struct->total_secrets);
1201 MSG_WriteByte (&host_client->message, svc_updatestat);
1202 MSG_WriteByte (&host_client->message, STAT_TOTALMONSTERS);
1203 MSG_WriteLong (&host_client->message, pr_global_struct->total_monsters);
1205 MSG_WriteByte (&host_client->message, svc_updatestat);
1206 MSG_WriteByte (&host_client->message, STAT_SECRETS);
1207 MSG_WriteLong (&host_client->message, pr_global_struct->found_secrets);
1209 MSG_WriteByte (&host_client->message, svc_updatestat);
1210 MSG_WriteByte (&host_client->message, STAT_MONSTERS);
1211 MSG_WriteLong (&host_client->message, pr_global_struct->killed_monsters);
1214 // Never send a roll angle, because savegames can catch the server
1215 // in a state where it is expecting the client to correct the angle
1216 // and it won't happen if the game was just loaded, so you wind up
1217 // with a permanent head tilt
1218 MSG_WriteByte (&host_client->message, svc_setangle);
1219 MSG_WriteAngle (&host_client->message, sv_player->v->angles[0], sv.protocol);
1220 MSG_WriteAngle (&host_client->message, sv_player->v->angles[1], sv.protocol);
1221 MSG_WriteAngle (&host_client->message, 0, sv.protocol);
1223 SV_WriteClientdataToMessage (sv_player, &host_client->message);
1225 MSG_WriteByte (&host_client->message, svc_signonnum);
1226 MSG_WriteByte (&host_client->message, 3);
1227 host_client->sendsignon = true;
1235 void Host_Begin_f (void)
1237 if (cmd_source == src_command)
1239 Con_Print("begin is not valid from the console\n");
1243 host_client->spawned = true;
1246 //===========================================================================
1253 Kicks a user off of the server
1256 void Host_Kick_f (void)
1259 const char *message = NULL;
1262 qboolean byNumber = false;
1264 if (cmd_source != src_command || !sv.active)
1269 if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1271 i = atof(Cmd_Argv(2)) - 1;
1272 if (i < 0 || i >= svs.maxclients || !(host_client = svs.clients + i)->active)
1278 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1280 if (!host_client->active)
1282 if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1287 if (i < svs.maxclients)
1289 if (cmd_source == src_command)
1291 if (cls.state == ca_dedicated)
1294 who = cl_name.string;
1299 // can't kick yourself!
1300 if (host_client == save)
1305 message = Cmd_Args();
1306 COM_ParseToken(&message, false);
1309 message++; // skip the #
1310 while (*message == ' ') // skip white space
1312 message += strlen(Cmd_Argv(2)); // skip the number
1314 while (*message && *message == ' ')
1318 SV_ClientPrintf("Kicked by %s: %s\n", who, message);
1320 SV_ClientPrintf("Kicked by %s\n", who);
1321 SV_DropClient (false); // kicked
1328 ===============================================================================
1332 ===============================================================================
1340 void Host_Give_f (void)
1346 if (cmd_source == src_command)
1348 Cmd_ForwardToServer ();
1357 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
1362 v = atoi (Cmd_Argv(2));
1376 // MED 01/04/97 added hipnotic give stuff
1377 if (gamemode == GAME_HIPNOTIC)
1382 sv_player->v->items = (int)sv_player->v->items | HIT_PROXIMITY_GUN;
1384 sv_player->v->items = (int)sv_player->v->items | IT_GRENADE_LAUNCHER;
1386 else if (t[0] == '9')
1387 sv_player->v->items = (int)sv_player->v->items | HIT_LASER_CANNON;
1388 else if (t[0] == '0')
1389 sv_player->v->items = (int)sv_player->v->items | HIT_MJOLNIR;
1390 else if (t[0] >= '2')
1391 sv_player->v->items = (int)sv_player->v->items | (IT_SHOTGUN << (t[0] - '2'));
1396 sv_player->v->items = (int)sv_player->v->items | (IT_SHOTGUN << (t[0] - '2'));
1401 if (gamemode == GAME_ROGUE && (val = GETEDICTFIELDVALUE(sv_player, eval_ammo_shells1)))
1404 sv_player->v->ammo_shells = v;
1407 if (gamemode == GAME_ROGUE)
1409 if ((val = GETEDICTFIELDVALUE(sv_player, eval_ammo_nails1)))
1412 if (sv_player->v->weapon <= IT_LIGHTNING)
1413 sv_player->v->ammo_nails = v;
1418 sv_player->v->ammo_nails = v;
1422 if (gamemode == GAME_ROGUE)
1424 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_lava_nails);
1428 if (sv_player->v->weapon > IT_LIGHTNING)
1429 sv_player->v->ammo_nails = v;
1434 if (gamemode == GAME_ROGUE)
1436 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_rockets1);
1440 if (sv_player->v->weapon <= IT_LIGHTNING)
1441 sv_player->v->ammo_rockets = v;
1446 sv_player->v->ammo_rockets = v;
1450 if (gamemode == GAME_ROGUE)
1452 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_multi_rockets);
1456 if (sv_player->v->weapon > IT_LIGHTNING)
1457 sv_player->v->ammo_rockets = v;
1462 sv_player->v->health = v;
1465 if (gamemode == GAME_ROGUE)
1467 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_cells1);
1471 if (sv_player->v->weapon <= IT_LIGHTNING)
1472 sv_player->v->ammo_cells = v;
1477 sv_player->v->ammo_cells = v;
1481 if (gamemode == GAME_ROGUE)
1483 val = GETEDICTFIELDVALUE(sv_player, eval_ammo_plasma);
1487 if (sv_player->v->weapon > IT_LIGHTNING)
1488 sv_player->v->ammo_cells = v;
1495 edict_t *FindViewthing (void)
1500 for (i=0 ; i<sv.num_edicts ; i++)
1503 if (!strcmp (PR_GetString(e->v->classname), "viewthing"))
1506 Con_Print("No viewthing on map\n");
1515 void Host_Viewmodel_f (void)
1520 e = FindViewthing ();
1524 m = Mod_ForName (Cmd_Argv(1), false, true, false);
1527 Con_Printf("Can't load %s\n", Cmd_Argv(1));
1532 cl.model_precache[(int)e->v->modelindex] = m;
1540 void Host_Viewframe_f (void)
1546 e = FindViewthing ();
1549 m = cl.model_precache[(int)e->v->modelindex];
1551 f = atoi(Cmd_Argv(1));
1552 if (f >= m->numframes)
1559 void PrintFrameName (model_t *m, int frame)
1562 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1564 Con_Printf("frame %i\n", frame);
1572 void Host_Viewnext_f (void)
1577 e = FindViewthing ();
1580 m = cl.model_precache[(int)e->v->modelindex];
1582 e->v->frame = e->v->frame + 1;
1583 if (e->v->frame >= m->numframes)
1584 e->v->frame = m->numframes - 1;
1586 PrintFrameName (m, e->v->frame);
1594 void Host_Viewprev_f (void)
1599 e = FindViewthing ();
1603 m = cl.model_precache[(int)e->v->modelindex];
1605 e->v->frame = e->v->frame - 1;
1606 if (e->v->frame < 0)
1609 PrintFrameName (m, e->v->frame);
1613 ===============================================================================
1617 ===============================================================================
1626 void Host_Startdemos_f (void)
1630 if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
1634 if (gamemode == GAME_TRANSFUSION)
1635 Cbuf_AddText ("map bb1\n");
1637 Cbuf_AddText ("map start\n");
1645 Con_Printf("Max %i demos in demoloop\n", MAX_DEMOS);
1648 Con_DPrintf("%i demo(s) in loop\n", c);
1650 for (i=1 ; i<c+1 ; i++)
1651 strlcpy (cls.demos[i-1], Cmd_Argv(i), sizeof (cls.demos[i-1]));
1653 // LordHavoc: clear the remaining slots
1654 for (;i <= MAX_DEMOS;i++)
1655 cls.demos[i-1][0] = 0;
1657 if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
1671 Return to looping demos
1674 void Host_Demos_f (void)
1676 if (cls.state == ca_dedicated)
1678 if (cls.demonum == -1)
1688 Return to looping demos
1691 void Host_Stopdemo_f (void)
1693 if (!cls.demoplayback)
1696 Host_ShutdownServer (false);
1699 static void MaxPlayers_f(void)
1703 if (Cmd_Argc() != 2)
1705 Con_Printf("\"maxplayers\" is \"%u\"\n", svs.maxclients);
1711 Con_Print("maxplayers can not be changed while a server is running.\n");
1715 n = atoi(Cmd_Argv(1));
1716 n = bound(1, n, MAX_SCOREBOARD);
1717 Con_Printf("\"maxplayers\" set to \"%u\"\n", n);
1720 Mem_Free(svs.clients);
1722 svs.clients = Mem_Alloc(sv_clients_mempool, sizeof(client_t) * svs.maxclients);
1724 Cvar_Set ("deathmatch", "0");
1726 Cvar_Set ("deathmatch", "1");
1729 //=============================================================================
1736 void Host_InitCommands (void)
1738 Cmd_AddCommand ("status", Host_Status_f);
1739 Cmd_AddCommand ("quit", Host_Quit_f);
1740 if (gamemode == GAME_NEHAHRA)
1742 Cmd_AddCommand ("max", Host_God_f);
1743 Cmd_AddCommand ("monster", Host_Notarget_f);
1744 Cmd_AddCommand ("scrag", Host_Fly_f);
1745 Cmd_AddCommand ("wraith", Host_Noclip_f);
1746 Cmd_AddCommand ("gimme", Host_Give_f);
1750 Cmd_AddCommand ("god", Host_God_f);
1751 Cmd_AddCommand ("notarget", Host_Notarget_f);
1752 Cmd_AddCommand ("fly", Host_Fly_f);
1753 Cmd_AddCommand ("noclip", Host_Noclip_f);
1754 Cmd_AddCommand ("give", Host_Give_f);
1756 Cmd_AddCommand ("map", Host_Map_f);
1757 Cmd_AddCommand ("restart", Host_Restart_f);
1758 Cmd_AddCommand ("changelevel", Host_Changelevel_f);
1759 Cmd_AddCommand ("connect", Host_Connect_f);
1760 Cmd_AddCommand ("reconnect", Host_Reconnect_f);
1761 Cmd_AddCommand ("version", Host_Version_f);
1762 Cmd_AddCommand ("say", Host_Say_f);
1763 Cmd_AddCommand ("say_team", Host_Say_Team_f);
1764 Cmd_AddCommand ("tell", Host_Tell_f);
1765 Cmd_AddCommand ("kill", Host_Kill_f);
1766 Cmd_AddCommand ("pause", Host_Pause_f);
1767 Cmd_AddCommand ("kick", Host_Kick_f);
1768 Cmd_AddCommand ("ping", Host_Ping_f);
1769 Cmd_AddCommand ("load", Host_Loadgame_f);
1770 Cmd_AddCommand ("save", Host_Savegame_f);
1772 Cmd_AddCommand ("startdemos", Host_Startdemos_f);
1773 Cmd_AddCommand ("demos", Host_Demos_f);
1774 Cmd_AddCommand ("stopdemo", Host_Stopdemo_f);
1776 Cmd_AddCommand ("viewmodel", Host_Viewmodel_f);
1777 Cmd_AddCommand ("viewframe", Host_Viewframe_f);
1778 Cmd_AddCommand ("viewnext", Host_Viewnext_f);
1779 Cmd_AddCommand ("viewprev", Host_Viewprev_f);
1781 Cvar_RegisterVariable (&cl_name);
1782 Cmd_AddCommand ("name", Host_Name_f);
1783 Cvar_RegisterVariable (&cl_color);
1784 Cmd_AddCommand ("color", Host_Color_f);
1785 Cvar_RegisterVariable (&cl_rate);
1786 Cmd_AddCommand ("rate", Host_Rate_f);
1787 if (gamemode == GAME_NEHAHRA)
1789 Cvar_RegisterVariable (&cl_pmodel);
1790 Cmd_AddCommand ("pmodel", Host_PModel_f);
1792 Cmd_AddCommand ("prespawn", Host_PreSpawn_f);
1793 Cmd_AddCommand ("spawn", Host_Spawn_f);
1794 Cmd_AddCommand ("begin", Host_Begin_f);
1795 Cmd_AddCommand ("maxplayers", MaxPlayers_f);
1797 Cvar_RegisterVariable(&sv_cheats);