remove quotes on say commands at the server end (like it used to, this is done a...
[xonotic/darkplaces.git] / host_cmd.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
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.
8
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.
12
13 See the GNU General Public License for more details.
14
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.
18
19 */
20
21 #include "quakedef.h"
22
23 int current_skill;
24 cvar_t sv_cheats = {0, "sv_cheats", "0"};
25 qboolean allowcheats = false;
26
27 mfunction_t *ED_FindFunction (char *name);
28
29 /*
30 ==================
31 Host_Quit_f
32 ==================
33 */
34
35 extern qboolean host_shuttingdown;
36 void Host_Quit_f (void)
37 {
38         host_shuttingdown = true;
39         CL_Disconnect ();
40         Host_ShutdownServer(false);
41
42         Sys_Quit ();
43 }
44
45
46 /*
47 ==================
48 Host_Status_f
49 ==================
50 */
51 void Host_Status_f (void)
52 {
53         const char *protocolname;
54         client_t *client;
55         int seconds, minutes, hours = 0, j, players;
56         void (*print) (const char *fmt, ...);
57
58         if (cmd_source == src_command)
59         {
60                 if (!sv.active)
61                 {
62                         Cmd_ForwardToServer ();
63                         return;
64                 }
65                 print = Con_Printf;
66         }
67         else
68                 print = SV_ClientPrintf;
69
70         for (players = 0, j = 0;j < svs.maxclients;j++)
71                 if (svs.clients[j].active)
72                         players++;
73         print ("host:    %s\n", Cvar_VariableString ("hostname"));
74         print ("version: %s build %s\n", gamename, buildstring);
75         switch(sv.protocol)
76         {
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;
84         }
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++)
89         {
90                 if (!client->active)
91                         continue;
92                 seconds = (int)(realtime - client->netconnection->connecttime);
93                 minutes = seconds / 60;
94                 if (minutes)
95                 {
96                         seconds -= (minutes * 60);
97                         hours = minutes / 60;
98                         if (hours)
99                                 minutes -= (hours * 60);
100                 }
101                 else
102                         hours = 0;
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);
105         }
106 }
107
108
109 /*
110 ==================
111 Host_God_f
112
113 Sets client to godmode
114 ==================
115 */
116 void Host_God_f (void)
117 {
118         if (cmd_source == src_command)
119         {
120                 Cmd_ForwardToServer ();
121                 return;
122         }
123
124         if (!sv_player)
125                 return;
126
127         if (!allowcheats)
128         {
129                 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
130                 return;
131         }
132
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");
136         else
137                 SV_ClientPrint("godmode ON\n");
138 }
139
140 void Host_Notarget_f (void)
141 {
142         if (cmd_source == src_command)
143         {
144                 Cmd_ForwardToServer ();
145                 return;
146         }
147
148         if (!sv_player)
149                 return;
150
151         if (!allowcheats)
152         {
153                 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
154                 return;
155         }
156
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");
160         else
161                 SV_ClientPrint("notarget ON\n");
162 }
163
164 qboolean noclip_anglehack;
165
166 void Host_Noclip_f (void)
167 {
168         if (cmd_source == src_command)
169         {
170                 Cmd_ForwardToServer ();
171                 return;
172         }
173
174         if (!sv_player)
175                 return;
176
177         if (!allowcheats)
178         {
179                 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
180                 return;
181         }
182
183         if (sv_player->v->movetype != MOVETYPE_NOCLIP)
184         {
185                 noclip_anglehack = true;
186                 sv_player->v->movetype = MOVETYPE_NOCLIP;
187                 SV_ClientPrint("noclip ON\n");
188         }
189         else
190         {
191                 noclip_anglehack = false;
192                 sv_player->v->movetype = MOVETYPE_WALK;
193                 SV_ClientPrint("noclip OFF\n");
194         }
195 }
196
197 /*
198 ==================
199 Host_Fly_f
200
201 Sets client to flymode
202 ==================
203 */
204 void Host_Fly_f (void)
205 {
206         if (cmd_source == src_command)
207         {
208                 Cmd_ForwardToServer ();
209                 return;
210         }
211
212         if (!sv_player)
213                 return;
214
215         if (!allowcheats)
216         {
217                 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
218                 return;
219         }
220
221         if (sv_player->v->movetype != MOVETYPE_FLY)
222         {
223                 sv_player->v->movetype = MOVETYPE_FLY;
224                 SV_ClientPrint("flymode ON\n");
225         }
226         else
227         {
228                 sv_player->v->movetype = MOVETYPE_WALK;
229                 SV_ClientPrint("flymode OFF\n");
230         }
231 }
232
233
234 /*
235 ==================
236 Host_Ping_f
237
238 ==================
239 */
240 void Host_Ping_f (void)
241 {
242         int             i, j;
243         float   total;
244         client_t        *client;
245
246         if (cmd_source == src_command)
247         {
248                 Cmd_ForwardToServer ();
249                 return;
250         }
251
252         SV_ClientPrint("Client ping times:\n");
253         for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
254         {
255                 if (!client->active)
256                         continue;
257                 total = 0;
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);
262         }
263 }
264
265 /*
266 ===============================================================================
267
268 SERVER TRANSITIONS
269
270 ===============================================================================
271 */
272
273 /*
274 ======================
275 Host_Map_f
276
277 handle a
278 map <servername>
279 command from the console.  Active clients are kicked off.
280 ======================
281 */
282 void Host_Map_f (void)
283 {
284         char level[MAX_QPATH];
285
286         if (Cmd_Argc() != 2)
287         {
288                 Con_Print("map <levelname> : start a new game (kicks off all players)\n");
289                 return;
290         }
291
292         if (cmd_source != src_command)
293                 return;
294
295         SCR_BeginLoadingPlaque ();
296         cls.demonum = -1;               // stop demo loop in case this fails
297
298         CL_Disconnect ();
299         Host_ShutdownServer(false);
300
301         // remove console or menu
302         key_dest = key_game;
303         key_consoleactive = 0;
304
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");
311 }
312
313 /*
314 ==================
315 Host_Changelevel_f
316
317 Goes to a new map, taking all clients along
318 ==================
319 */
320 void Host_Changelevel_f (void)
321 {
322         char level[MAX_QPATH];
323         
324         if (Cmd_Argc() != 2)
325         {
326                 Con_Print("changelevel <levelname> : continue game on a new level\n");
327                 return;
328         }
329         if (!sv.active || cls.demoplayback)
330         {
331                 Con_Print("Only the server may changelevel\n");
332                 return;
333         }
334         if (cmd_source != src_command)
335                 return;
336
337         // remove console or menu
338         key_dest = key_game;
339         key_consoleactive = 0;
340
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");
348 }
349
350 /*
351 ==================
352 Host_Restart_f
353
354 Restarts the current server for a dead player
355 ==================
356 */
357 void Host_Restart_f (void)
358 {
359         char mapname[MAX_QPATH];
360         
361         if (Cmd_Argc() != 1)
362         {
363                 Con_Print("restart : restart current level\n");
364                 return;
365         }
366         if (!sv.active || cls.demoplayback)
367         {
368                 Con_Print("Only the server may restart\n");
369                 return;
370         }
371         if (cmd_source != src_command)
372                 return;
373
374         // remove console or menu
375         key_dest = key_game;
376         key_consoleactive = 0;
377
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");
384 }
385
386 /*
387 ==================
388 Host_Reconnect_f
389
390 This command causes the client to wait for the signon messages again.
391 This is sent just before a server changes levels
392 ==================
393 */
394 void Host_Reconnect_f (void)
395 {
396         if (Cmd_Argc() != 1)
397         {
398                 Con_Print("reconnect : wait for signon messages again\n");
399                 return;
400         }
401         if (!cls.signon)
402         {
403                 Con_Print("reconnect: no signon, ignoring reconnect\n");
404                 return;
405         }
406         SCR_BeginLoadingPlaque();
407         cls.signon = 0;         // need new connection messages
408 }
409
410 /*
411 =====================
412 Host_Connect_f
413
414 User command to connect to server
415 =====================
416 */
417 void Host_Connect_f (void)
418 {
419         if (Cmd_Argc() != 2)
420         {
421                 Con_Print("connect <serveraddress> : connect to a multiplayer game\n");
422                 return;
423         }
424         CL_EstablishConnection(Cmd_Argv(1));
425 }
426
427
428 /*
429 ===============================================================================
430
431 LOAD / SAVE GAME
432
433 ===============================================================================
434 */
435
436 #define SAVEGAME_VERSION        5
437
438 /*
439 ===============
440 Host_SavegameComment
441
442 Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
443 ===============
444 */
445 void Host_SavegameComment (char *text)
446 {
447         int             i;
448         char    kills[20];
449
450         for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
451                 text[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++)
457                 if (text[i] == ' ')
458                         text[i] = '_';
459         text[SAVEGAME_COMMENT_LENGTH] = '\0';
460 }
461
462
463 /*
464 ===============
465 Host_Savegame_f
466 ===============
467 */
468 void Host_Savegame_f (void)
469 {
470         char    name[256];
471         qfile_t *f;
472         int             i;
473         char    comment[SAVEGAME_COMMENT_LENGTH+1];
474
475         if (cmd_source != src_command)
476                 return;
477
478         if (cls.state != ca_connected || !sv.active)
479         {
480                 Con_Print("Not playing a local game.\n");
481                 return;
482         }
483
484         if (cl.intermission)
485         {
486                 Con_Print("Can't save in intermission.\n");
487                 return;
488         }
489
490         for (i = 0;i < svs.maxclients;i++)
491         {
492                 if (svs.clients[i].active)
493                 {
494                         if (i > 0)
495                         {
496                                 Con_Print("Can't save multiplayer games.\n");
497                                 return;
498                         }
499                         if (svs.clients[i].edict->v->deadflag)
500                         {
501                                 Con_Print("Can't savegame with a dead player\n");
502                                 return;
503                         }
504                 }
505         }
506
507         if (Cmd_Argc() != 2)
508         {
509                 Con_Print("save <savename> : save a game\n");
510                 return;
511         }
512
513         if (strstr(Cmd_Argv(1), ".."))
514         {
515                 Con_Print("Relative pathnames are not allowed.\n");
516                 return;
517         }
518
519         strlcpy (name, Cmd_Argv(1), sizeof (name));
520         FS_DefaultExtension (name, ".sav", sizeof (name));
521
522         Con_Printf("Saving game to %s...\n", name);
523         f = FS_Open (name, "w", false);
524         if (!f)
525         {
526                 Con_Print("ERROR: couldn't open.\n");
527                 return;
528         }
529
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);
538
539 // write the light styles
540
541         for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
542         {
543                 if (sv.lightstyles[i])
544                         FS_Printf(f, "%s\n", sv.lightstyles[i]);
545                 else
546                         FS_Print(f,"m\n");
547         }
548
549
550         ED_WriteGlobals (f);
551         for (i=0 ; i<sv.num_edicts ; i++)
552         {
553                 ED_Write (f, EDICT_NUM(i));
554                 FS_Flush (f);
555         }
556         FS_Close (f);
557         Con_Print("done.\n");
558 }
559
560
561 extern mempool_t *edictstring_mempool;
562
563 /*
564 ===============
565 Host_Loadgame_f
566 ===============
567 */
568 void Host_Loadgame_f (void)
569 {
570         qfile_t *f;
571         char filename[MAX_QPATH];
572         char mapname[MAX_QPATH];
573         float time, tfloat;
574         char buf[32768];
575         const char *start;
576         char *str;
577         int i, r;
578         edict_t *ent;
579         int entnum;
580         int version;
581         float spawn_parms[NUM_SPAWN_PARMS];
582
583         if (cmd_source != src_command)
584                 return;
585
586         if (Cmd_Argc() != 2)
587         {
588                 Con_Print("load <savename> : load a game\n");
589                 return;
590         }
591
592         strcpy (filename, Cmd_Argv(1));
593         FS_DefaultExtension (filename, ".sav", sizeof (filename));
594
595         Con_Printf("Loading game from %s...\n", filename);
596
597         cls.demonum = -1;               // stop demo loop in case this fails
598
599         f = FS_Open (filename, "r", false);
600         if (!f)
601         {
602                 Con_Print("ERROR: couldn't open.\n");
603                 return;
604         }
605
606         str = FS_Getline (f);
607         sscanf (str, "%i\n", &version);
608         if (version != SAVEGAME_VERSION)
609         {
610                 FS_Close (f);
611                 Con_Printf("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
612                 return;
613         }
614
615         SCR_BeginLoadingPlaque ();
616
617         str = FS_Getline (f);
618         for (i = 0;i < NUM_SPAWN_PARMS;i++)
619         {
620                 str = FS_Getline (f);
621                 sscanf (str, "%f\n", &spawn_parms[i]);
622         }
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);
628
629         strcpy (mapname, FS_Getline (f));
630
631         str = FS_Getline (f);
632         sscanf (str, "%f\n",&time);
633
634         allowcheats = sv_cheats.integer != 0;
635         SV_SpawnServer (mapname);
636         if (!sv.active)
637         {
638                 Con_Print("Couldn't load map\n");
639                 return;
640         }
641         sv.paused = true;               // pause until all clients connect
642         sv.loadgame = true;
643
644 // load the light styles
645
646         for (i = 0;i < MAX_LIGHTSTYLES;i++)
647         {
648                 str = FS_Getline (f);
649                 sv.lightstyles[i] = Mem_Alloc(edictstring_mempool, strlen(str)+1);
650                 strcpy (sv.lightstyles[i], str);
651         }
652
653 // load the edicts out of the savegame file
654         // -1 is the globals
655         entnum = -1;
656         while (!FS_Eof (f))
657         {
658                 for (i = 0;i < (int)sizeof(buf) - 1;i++)
659                 {
660                         r = FS_Getc (f);
661                         if (r == EOF || !r)
662                                 break;
663                         buf[i] = r;
664                         if (r == '}')
665                         {
666                                 i++;
667                                 break;
668                         }
669                 }
670                 if (i == sizeof(buf)-1)
671                         Host_Error ("Loadgame buffer overflow");
672                 buf[i] = 0;
673                 start = buf;
674                 if (!COM_ParseToken(&start, false))
675                 {
676                         // end of file
677                         break;
678                 }
679                 if (strcmp(com_token,"{"))
680                         Host_Error ("First token isn't a brace");
681
682                 if (entnum == -1)
683                 {
684                         // parse the global vars
685                         ED_ParseGlobals (start);
686                 }
687                 else
688                 {
689                         // parse an edict
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)
693                                 SV_IncreaseEdicts();
694                         ent = EDICT_NUM(entnum);
695                         memset (ent->v, 0, progs->entityfields * 4);
696                         ent->e->free = false;
697                         ED_ParseEdict (start, ent);
698
699                         // link it into the bsp tree
700                         if (!ent->e->free)
701                                 SV_LinkEdict (ent, false);
702                 }
703
704                 entnum++;
705         }
706
707         sv.num_edicts = entnum;
708         sv.time = time;
709
710         FS_Close (f);
711
712         for (i = 0;i < NUM_SPAWN_PARMS;i++)
713                 svs.clients[0].spawn_parms[i] = spawn_parms[i];
714
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");
718 }
719
720 //============================================================================
721
722 /*
723 ======================
724 Host_Name_f
725 ======================
726 */
727 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player"};
728 void Host_Name_f (void)
729 {
730         int i, j;
731         char newName[sizeof(host_client->name)];
732
733         if (Cmd_Argc () == 1)
734         {
735                 Con_Printf("\"name\" is \"%s\"\n", cl_name.string);
736                 return;
737         }
738
739         if (Cmd_Argc () == 2)
740                 strlcpy (newName, Cmd_Argv(1), sizeof (newName));
741         else
742                 strlcpy (newName, Cmd_Args(), sizeof (newName));
743
744         for (i = 0, j = 0;newName[i];i++)
745                 if (newName[i] != '\r' && newName[i] != '\n')
746                         newName[j++] = newName[i];
747         newName[j] = 0;
748
749         if (cmd_source == src_command)
750         {
751                 Cvar_Set ("_cl_name", newName);
752                 if (cls.state == ca_connected)
753                         Cmd_ForwardToServer ();
754                 return;
755         }
756
757         if (sv.time < host_client->nametime)
758         {
759                 SV_ClientPrintf("You can't change name more than once every 5 seconds!\n");
760                 return;
761         }
762         
763         host_client->nametime = sv.time + 5;
764
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);
769         if (sv_player)
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);
772
773 // send notification to all clients
774
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);
778 }
779
780
781 void Host_Version_f (void)
782 {
783         Con_Printf("Version: %s build %s\n", gamename, buildstring);
784 }
785
786 void Host_Say(qboolean teamonly)
787 {
788         client_t *save;
789         int j, quoted;
790         const char *p1;
791         char *p2;
792         // LordHavoc: 256 char say messages
793         unsigned char text[256];
794         qboolean fromServer = false;
795
796         if (cmd_source == src_command)
797         {
798                 if (cls.state == ca_dedicated)
799                 {
800                         fromServer = true;
801                         teamonly = false;
802                 }
803                 else
804                 {
805                         Cmd_ForwardToServer ();
806                         return;
807                 }
808         }
809
810         if (Cmd_Argc () < 2)
811                 return;
812
813         if (!teamplay.integer)
814                 teamonly = false;
815
816 // turn on color set 1
817         p1 = Cmd_Args();
818         quoted = false;
819         if (*p1 == '\"')
820         {
821                 quoted = true;
822                 p1++;
823         }
824         if (!fromServer)
825                 snprintf (text, sizeof(text), "%c%s: %s", 1, host_client->name, p1);
826         else
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)))
830         {
831                 if (p2[-1] == '\"' && quoted)
832                         quoted = false;
833                 p2[-1] = 0;
834                 p2--;
835         }
836
837         // note: save is not a valid edict if fromServer is true
838         save = host_client;
839         for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
840                 if (host_client->spawned && (!teamonly || host_client->edict->v->team == save->edict->v->team))
841                         SV_ClientPrint(text);
842         host_client = save;
843
844         Sys_Print(&text[1]);
845 }
846
847
848 void Host_Say_f(void)
849 {
850         Host_Say(false);
851 }
852
853
854 void Host_Say_Team_f(void)
855 {
856         Host_Say(true);
857 }
858
859
860 void Host_Tell_f(void)
861 {
862         client_t *save;
863         int j;
864         const char *p1, *p2;
865         char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
866         qboolean fromServer = false;
867
868         if (cmd_source == src_command)
869         {
870                 if (cls.state == ca_dedicated)
871                         fromServer = true;
872                 else
873                 {
874                         Cmd_ForwardToServer ();
875                         return;
876                 }
877         }
878
879         if (Cmd_Argc () < 3)
880                 return;
881
882         if (!fromServer)
883                 sprintf (text, "%s: ", host_client->name);
884         else
885                 sprintf (text, "<%s> ", hostname.string);
886
887         p1 = Cmd_Args();
888         p2 = p1 + strlen(p1);
889         // remove the target name
890         while (p1 < p2 && *p1 != ' ')
891                 p1++;
892         while (p1 < p2 && *p1 == ' ')
893                 p1++;
894         // remove trailing newlines
895         while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
896                 p2--;
897         // remove quotes if present
898         if (*p1 == '"')
899         {
900                 p1++;
901                 if (p2[-1] == '"')
902                         p2--;
903                 else if (fromServer)
904                         Con_Print("Host_Tell: missing end quote\n");
905                 else
906                         SV_ClientPrint("Host_Tell: missing end quote\n");
907         }
908         while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
909                 p2--;
910         for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
911                 text[j++] = *p1++;
912         text[j++] = '\n';
913         text[j++] = 0;
914
915         save = host_client;
916         for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
917                 if (host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1)))
918                         SV_ClientPrint(text);
919         host_client = save;
920 }
921
922
923 /*
924 ==================
925 Host_Color_f
926 ==================
927 */
928 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0"};
929 void Host_Color_f(void)
930 {
931         int             top, bottom;
932         int             playercolor;
933         mfunction_t *f;
934         func_t  SV_ChangeTeam;
935
936         if (Cmd_Argc() == 1)
937         {
938                 Con_Printf("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
939                 Con_Print("color <0-15> [0-15]\n");
940                 return;
941         }
942
943         if (Cmd_Argc() == 2)
944                 top = bottom = atoi(Cmd_Argv(1));
945         else
946         {
947                 top = atoi(Cmd_Argv(1));
948                 bottom = atoi(Cmd_Argv(2));
949         }
950
951         top &= 15;
952         // LordHavoc: allow skin colormaps 14 and 15 (was 13)
953         if (top > 15)
954                 top = 15;
955         bottom &= 15;
956         // LordHavoc: allow skin colormaps 14 and 15 (was 13)
957         if (bottom > 15)
958                 bottom = 15;
959
960         playercolor = top*16 + bottom;
961
962         if (cmd_source == src_command)
963         {
964                 Cvar_SetValue ("_cl_color", playercolor);
965                 if (cls.state == ca_connected)
966                         Cmd_ForwardToServer ();
967                 return;
968         }
969
970         if (sv_player && (f = ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - pr_functions)))
971         {
972                 Con_DPrint("Calling SV_ChangeTeam\n");
973                 pr_global_struct->time = sv.time;
974                 pr_globals[OFS_PARM0] = playercolor;
975                 pr_global_struct->self = EDICT_TO_PROG(sv_player);
976                 PR_ExecuteProgram (SV_ChangeTeam, "QC function SV_ChangeTeam is missing");
977         }
978         else
979         {
980                 eval_t *val;
981                 if (sv_player)
982                 {
983                         if ((val = GETEDICTFIELDVALUE(sv_player, eval_clientcolors)))
984                                 val->_float = playercolor;
985                         sv_player->v->team = bottom + 1;
986                 }
987                 host_client->colors = playercolor;
988                 host_client->old_colors = playercolor;
989
990                 // send notification to all clients
991                 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
992                 MSG_WriteByte (&sv.reliable_datagram, host_client->number);
993                 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
994         }
995 }
996
997 cvar_t cl_rate = {CVAR_SAVE, "_cl_rate", "10000"};
998 void Host_Rate_f(void)
999 {
1000         int rate;
1001
1002         if (Cmd_Argc() != 2)
1003         {
1004                 Con_Printf("\"rate\" is \"%i\"\n", cl_rate.integer);
1005                 Con_Print("rate <500-25000>\n");
1006                 return;
1007         }
1008
1009         rate = atoi(Cmd_Argv(1));
1010
1011         if (cmd_source == src_command)
1012         {
1013                 Cvar_SetValue ("_cl_rate", bound(NET_MINRATE, rate, NET_MAXRATE));
1014                 if (cls.state == ca_connected)
1015                         Cmd_ForwardToServer ();
1016                 return;
1017         }
1018
1019         host_client->netconnection->rate = rate;
1020 }
1021
1022 /*
1023 ==================
1024 Host_Kill_f
1025 ==================
1026 */
1027 void Host_Kill_f (void)
1028 {
1029         if (cmd_source == src_command)
1030         {
1031                 Cmd_ForwardToServer ();
1032                 return;
1033         }
1034
1035         if (!sv_player || sv_player->v->health <= 0)
1036         {
1037                 SV_ClientPrint("Can't suicide -- already dead!\n");
1038                 return;
1039         }
1040
1041         pr_global_struct->time = sv.time;
1042         pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1043         PR_ExecuteProgram (pr_global_struct->ClientKill, "QC function ClientKill is missing");
1044 }
1045
1046
1047 /*
1048 ==================
1049 Host_Pause_f
1050 ==================
1051 */
1052 void Host_Pause_f (void)
1053 {
1054
1055         if (cmd_source == src_command)
1056         {
1057                 Cmd_ForwardToServer ();
1058                 return;
1059         }
1060         if (!pausable.integer)
1061                 SV_ClientPrint("Pause not allowed.\n");
1062         else
1063         {
1064                 sv.paused ^= 1;
1065                 SV_BroadcastPrintf("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
1066                 // send notification to all clients
1067                 MSG_WriteByte(&sv.reliable_datagram, svc_setpause);
1068                 MSG_WriteByte(&sv.reliable_datagram, sv.paused);
1069         }
1070 }
1071
1072 /*
1073 ======================
1074 Host_PModel_f
1075 LordHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
1076 ======================
1077 */
1078 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0"};
1079 static void Host_PModel_f (void)
1080 {
1081         int i;
1082         eval_t *val;
1083
1084         if (Cmd_Argc () == 1)
1085         {
1086                 Con_Printf("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
1087                 return;
1088         }
1089         i = atoi(Cmd_Argv(1));
1090
1091         if (cmd_source == src_command)
1092         {
1093                 if (cl_pmodel.integer == i)
1094                         return;
1095                 Cvar_SetValue ("_cl_pmodel", i);
1096                 if (cls.state == ca_connected)
1097                         Cmd_ForwardToServer ();
1098                 return;
1099         }
1100
1101         host_client->pmodel = i;
1102         if (sv_player && (val = GETEDICTFIELDVALUE(sv_player, eval_pmodel)))
1103                 val->_float = i;
1104 }
1105
1106 //===========================================================================
1107
1108
1109 /*
1110 ==================
1111 Host_PreSpawn_f
1112 ==================
1113 */
1114 void Host_PreSpawn_f (void)
1115 {
1116         if (cmd_source == src_command)
1117         {
1118                 Con_Print("prespawn is not valid from the console\n");
1119                 return;
1120         }
1121
1122         if (host_client->spawned)
1123         {
1124                 Con_Print("prespawn not valid -- already spawned\n");
1125                 return;
1126         }
1127
1128         SZ_Write (&host_client->message, sv.signon.data, sv.signon.cursize);
1129         MSG_WriteByte (&host_client->message, svc_signonnum);
1130         MSG_WriteByte (&host_client->message, 2);
1131         host_client->sendsignon = true;
1132 }
1133
1134 /*
1135 ==================
1136 Host_Spawn_f
1137 ==================
1138 */
1139 void Host_Spawn_f (void)
1140 {
1141         int i;
1142         client_t *client;
1143         func_t RestoreGame;
1144         mfunction_t *f;
1145
1146         if (cmd_source == src_command)
1147         {
1148                 Con_Print("spawn is not valid from the console\n");
1149                 return;
1150         }
1151
1152         if (host_client->spawned)
1153         {
1154                 Con_Print("Spawn not valid -- already spawned\n");
1155                 return;
1156         }
1157
1158         if (!sv_player)
1159         {
1160                 Con_Print("Host_Spawn: no edict??\n");
1161                 return;
1162         }
1163
1164         host_client->nametime = 0;
1165
1166         // LordHavoc: moved this above the QC calls at FrikaC's request
1167         // send all current names, colors, and frag counts
1168         SZ_Clear (&host_client->message);
1169
1170         // run the entrance script
1171         if (sv.loadgame)
1172         {
1173                 // loaded games are fully initialized already
1174                 // if this is the last client to be connected, unpause
1175                 sv.paused = false;
1176
1177                 if ((f = ED_FindFunction ("RestoreGame")))
1178                 if ((RestoreGame = (func_t)(f - pr_functions)))
1179                 {
1180                         Con_DPrint("Calling RestoreGame\n");
1181                         pr_global_struct->time = sv.time;
1182                         pr_global_struct->self = EDICT_TO_PROG(sv_player);
1183                         PR_ExecuteProgram (RestoreGame, "QC function RestoreGame is missing");
1184                 }
1185         }
1186         else
1187         {
1188                 // set up the edict
1189                 ED_ClearEdict(sv_player);
1190
1191                 //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);
1192
1193                 // copy spawn parms out of the client_t
1194                 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1195                         (&pr_global_struct->parm1)[i] = host_client->spawn_parms[i];
1196
1197                 // call the spawn function
1198                 pr_global_struct->time = sv.time;
1199                 pr_global_struct->self = EDICT_TO_PROG(sv_player);
1200                 PR_ExecuteProgram (pr_global_struct->ClientConnect, "QC function ClientConnect is missing");
1201
1202                 if ((Sys_DoubleTime() - host_client->netconnection->connecttime) <= sv.time)
1203                         Sys_Printf("%s entered the game\n", host_client->name);
1204
1205                 PR_ExecuteProgram (pr_global_struct->PutClientInServer, "QC function PutClientInServer is missing");
1206         }
1207
1208
1209         // send time of update
1210         MSG_WriteByte (&host_client->message, svc_time);
1211         MSG_WriteFloat (&host_client->message, sv.time);
1212
1213         for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
1214         {
1215                 if (!client->active)
1216                         continue;
1217                 MSG_WriteByte (&host_client->message, svc_updatename);
1218                 MSG_WriteByte (&host_client->message, i);
1219                 MSG_WriteString (&host_client->message, client->old_name);
1220                 MSG_WriteByte (&host_client->message, svc_updatefrags);
1221                 MSG_WriteByte (&host_client->message, i);
1222                 MSG_WriteShort (&host_client->message, client->old_frags);
1223                 MSG_WriteByte (&host_client->message, svc_updatecolors);
1224                 MSG_WriteByte (&host_client->message, i);
1225                 MSG_WriteByte (&host_client->message, client->old_colors);
1226         }
1227
1228         // send all current light styles
1229         for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1230         {
1231                 MSG_WriteByte (&host_client->message, svc_lightstyle);
1232                 MSG_WriteByte (&host_client->message, (char)i);
1233                 MSG_WriteString (&host_client->message, sv.lightstyles[i]);
1234         }
1235
1236         // send some stats
1237         MSG_WriteByte (&host_client->message, svc_updatestat);
1238         MSG_WriteByte (&host_client->message, STAT_TOTALSECRETS);
1239         MSG_WriteLong (&host_client->message, pr_global_struct->total_secrets);
1240
1241         MSG_WriteByte (&host_client->message, svc_updatestat);
1242         MSG_WriteByte (&host_client->message, STAT_TOTALMONSTERS);
1243         MSG_WriteLong (&host_client->message, pr_global_struct->total_monsters);
1244
1245         MSG_WriteByte (&host_client->message, svc_updatestat);
1246         MSG_WriteByte (&host_client->message, STAT_SECRETS);
1247         MSG_WriteLong (&host_client->message, pr_global_struct->found_secrets);
1248
1249         MSG_WriteByte (&host_client->message, svc_updatestat);
1250         MSG_WriteByte (&host_client->message, STAT_MONSTERS);
1251         MSG_WriteLong (&host_client->message, pr_global_struct->killed_monsters);
1252
1253         // send a fixangle
1254         // Never send a roll angle, because savegames can catch the server
1255         // in a state where it is expecting the client to correct the angle
1256         // and it won't happen if the game was just loaded, so you wind up
1257         // with a permanent head tilt
1258         MSG_WriteByte (&host_client->message, svc_setangle);
1259         MSG_WriteAngle (&host_client->message, sv_player->v->angles[0], sv.protocol);
1260         MSG_WriteAngle (&host_client->message, sv_player->v->angles[1], sv.protocol);
1261         MSG_WriteAngle (&host_client->message, 0, sv.protocol);
1262
1263         SV_WriteClientdataToMessage (sv_player, &host_client->message);
1264
1265         MSG_WriteByte (&host_client->message, svc_signonnum);
1266         MSG_WriteByte (&host_client->message, 3);
1267         host_client->sendsignon = true;
1268 }
1269
1270 /*
1271 ==================
1272 Host_Begin_f
1273 ==================
1274 */
1275 void Host_Begin_f (void)
1276 {
1277         if (cmd_source == src_command)
1278         {
1279                 Con_Print("begin is not valid from the console\n");
1280                 return;
1281         }
1282
1283         host_client->spawned = true;
1284 }
1285
1286 //===========================================================================
1287
1288
1289 /*
1290 ==================
1291 Host_Kick_f
1292
1293 Kicks a user off of the server
1294 ==================
1295 */
1296 void Host_Kick_f (void)
1297 {
1298         char *who;
1299         const char *message = NULL;
1300         client_t *save;
1301         int i;
1302         qboolean byNumber = false;
1303
1304         if (cmd_source != src_command || !sv.active)
1305                 return;
1306
1307         save = host_client;
1308
1309         if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1310         {
1311                 i = atof(Cmd_Argv(2)) - 1;
1312                 if (i < 0 || i >= svs.maxclients || !(host_client = svs.clients + i)->active)
1313                         return;
1314                 byNumber = true;
1315         }
1316         else
1317         {
1318                 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1319                 {
1320                         if (!host_client->active)
1321                                 continue;
1322                         if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1323                                 break;
1324                 }
1325         }
1326
1327         if (i < svs.maxclients)
1328         {
1329                 if (cmd_source == src_command)
1330                 {
1331                         if (cls.state == ca_dedicated)
1332                                 who = "Console";
1333                         else
1334                                 who = cl_name.string;
1335                 }
1336                 else
1337                         who = save->name;
1338
1339                 // can't kick yourself!
1340                 if (host_client == save)
1341                         return;
1342
1343                 if (Cmd_Argc() > 2)
1344                 {
1345                         message = Cmd_Args();
1346                         COM_ParseToken(&message, false);
1347                         if (byNumber)
1348                         {
1349                                 message++;                                                      // skip the #
1350                                 while (*message == ' ')                         // skip white space
1351                                         message++;
1352                                 message += strlen(Cmd_Argv(2)); // skip the number
1353                         }
1354                         while (*message && *message == ' ')
1355                                 message++;
1356                 }
1357                 if (message)
1358                         SV_ClientPrintf("Kicked by %s: %s\n", who, message);
1359                 else
1360                         SV_ClientPrintf("Kicked by %s\n", who);
1361                 SV_DropClient (false); // kicked
1362         }
1363
1364         host_client = save;
1365 }
1366
1367 /*
1368 ===============================================================================
1369
1370 DEBUGGING TOOLS
1371
1372 ===============================================================================
1373 */
1374
1375 /*
1376 ==================
1377 Host_Give_f
1378 ==================
1379 */
1380 void Host_Give_f (void)
1381 {
1382         const char *t;
1383         int v;
1384         eval_t *val;
1385
1386         if (cmd_source == src_command)
1387         {
1388                 Cmd_ForwardToServer ();
1389                 return;
1390         }
1391
1392         if (!sv_player)
1393                 return;
1394
1395         if (!allowcheats)
1396         {
1397                 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
1398                 return;
1399         }
1400
1401         t = Cmd_Argv(1);
1402         v = atoi (Cmd_Argv(2));
1403
1404         switch (t[0])
1405         {
1406         case '0':
1407         case '1':
1408         case '2':
1409         case '3':
1410         case '4':
1411         case '5':
1412         case '6':
1413         case '7':
1414         case '8':
1415         case '9':
1416                 // MED 01/04/97 added hipnotic give stuff
1417                 if (gamemode == GAME_HIPNOTIC)
1418                 {
1419                         if (t[0] == '6')
1420                         {
1421                                 if (t[1] == 'a')
1422                                         sv_player->v->items = (int)sv_player->v->items | HIT_PROXIMITY_GUN;
1423                                 else
1424                                         sv_player->v->items = (int)sv_player->v->items | IT_GRENADE_LAUNCHER;
1425                         }
1426                         else if (t[0] == '9')
1427                                 sv_player->v->items = (int)sv_player->v->items | HIT_LASER_CANNON;
1428                         else if (t[0] == '0')
1429                                 sv_player->v->items = (int)sv_player->v->items | HIT_MJOLNIR;
1430                         else if (t[0] >= '2')
1431                                 sv_player->v->items = (int)sv_player->v->items | (IT_SHOTGUN << (t[0] - '2'));
1432                 }
1433                 else
1434                 {
1435                         if (t[0] >= '2')
1436                                 sv_player->v->items = (int)sv_player->v->items | (IT_SHOTGUN << (t[0] - '2'));
1437                 }
1438                 break;
1439
1440         case 's':
1441                 if (gamemode == GAME_ROGUE && (val = GETEDICTFIELDVALUE(sv_player, eval_ammo_shells1)))
1442                         val->_float = v;
1443
1444                 sv_player->v->ammo_shells = v;
1445                 break;
1446         case 'n':
1447                 if (gamemode == GAME_ROGUE)
1448                 {
1449                         if ((val = GETEDICTFIELDVALUE(sv_player, eval_ammo_nails1)))
1450                         {
1451                                 val->_float = v;
1452                                 if (sv_player->v->weapon <= IT_LIGHTNING)
1453                                         sv_player->v->ammo_nails = v;
1454                         }
1455                 }
1456                 else
1457                 {
1458                         sv_player->v->ammo_nails = v;
1459                 }
1460                 break;
1461         case 'l':
1462                 if (gamemode == GAME_ROGUE)
1463                 {
1464                         val = GETEDICTFIELDVALUE(sv_player, eval_ammo_lava_nails);
1465                         if (val)
1466                         {
1467                                 val->_float = v;
1468                                 if (sv_player->v->weapon > IT_LIGHTNING)
1469                                         sv_player->v->ammo_nails = v;
1470                         }
1471                 }
1472                 break;
1473         case 'r':
1474                 if (gamemode == GAME_ROGUE)
1475                 {
1476                         val = GETEDICTFIELDVALUE(sv_player, eval_ammo_rockets1);
1477                         if (val)
1478                         {
1479                                 val->_float = v;
1480                                 if (sv_player->v->weapon <= IT_LIGHTNING)
1481                                         sv_player->v->ammo_rockets = v;
1482                         }
1483                 }
1484                 else
1485                 {
1486                         sv_player->v->ammo_rockets = v;
1487                 }
1488                 break;
1489         case 'm':
1490                 if (gamemode == GAME_ROGUE)
1491                 {
1492                         val = GETEDICTFIELDVALUE(sv_player, eval_ammo_multi_rockets);
1493                         if (val)
1494                         {
1495                                 val->_float = v;
1496                                 if (sv_player->v->weapon > IT_LIGHTNING)
1497                                         sv_player->v->ammo_rockets = v;
1498                         }
1499                 }
1500                 break;
1501         case 'h':
1502                 sv_player->v->health = v;
1503                 break;
1504         case 'c':
1505                 if (gamemode == GAME_ROGUE)
1506                 {
1507                         val = GETEDICTFIELDVALUE(sv_player, eval_ammo_cells1);
1508                         if (val)
1509                         {
1510                                 val->_float = v;
1511                                 if (sv_player->v->weapon <= IT_LIGHTNING)
1512                                         sv_player->v->ammo_cells = v;
1513                         }
1514                 }
1515                 else
1516                 {
1517                         sv_player->v->ammo_cells = v;
1518                 }
1519                 break;
1520         case 'p':
1521                 if (gamemode == GAME_ROGUE)
1522                 {
1523                         val = GETEDICTFIELDVALUE(sv_player, eval_ammo_plasma);
1524                         if (val)
1525                         {
1526                                 val->_float = v;
1527                                 if (sv_player->v->weapon > IT_LIGHTNING)
1528                                         sv_player->v->ammo_cells = v;
1529                         }
1530                 }
1531                 break;
1532         }
1533 }
1534
1535 edict_t *FindViewthing (void)
1536 {
1537         int             i;
1538         edict_t *e;
1539
1540         for (i=0 ; i<sv.num_edicts ; i++)
1541         {
1542                 e = EDICT_NUM(i);
1543                 if (!strcmp (PR_GetString(e->v->classname), "viewthing"))
1544                         return e;
1545         }
1546         Con_Print("No viewthing on map\n");
1547         return NULL;
1548 }
1549
1550 /*
1551 ==================
1552 Host_Viewmodel_f
1553 ==================
1554 */
1555 void Host_Viewmodel_f (void)
1556 {
1557         edict_t *e;
1558         model_t *m;
1559
1560         e = FindViewthing ();
1561         if (!e)
1562                 return;
1563
1564         m = Mod_ForName (Cmd_Argv(1), false, true, false);
1565         if (!m)
1566         {
1567                 Con_Printf("Can't load %s\n", Cmd_Argv(1));
1568                 return;
1569         }
1570
1571         e->v->frame = 0;
1572         cl.model_precache[(int)e->v->modelindex] = m;
1573 }
1574
1575 /*
1576 ==================
1577 Host_Viewframe_f
1578 ==================
1579 */
1580 void Host_Viewframe_f (void)
1581 {
1582         edict_t *e;
1583         int             f;
1584         model_t *m;
1585
1586         e = FindViewthing ();
1587         if (!e)
1588                 return;
1589         m = cl.model_precache[(int)e->v->modelindex];
1590
1591         f = atoi(Cmd_Argv(1));
1592         if (f >= m->numframes)
1593                 f = m->numframes-1;
1594
1595         e->v->frame = f;
1596 }
1597
1598
1599 void PrintFrameName (model_t *m, int frame)
1600 {
1601         if (m->animscenes)
1602                 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1603         else
1604                 Con_Printf("frame %i\n", frame);
1605 }
1606
1607 /*
1608 ==================
1609 Host_Viewnext_f
1610 ==================
1611 */
1612 void Host_Viewnext_f (void)
1613 {
1614         edict_t *e;
1615         model_t *m;
1616
1617         e = FindViewthing ();
1618         if (!e)
1619                 return;
1620         m = cl.model_precache[(int)e->v->modelindex];
1621
1622         e->v->frame = e->v->frame + 1;
1623         if (e->v->frame >= m->numframes)
1624                 e->v->frame = m->numframes - 1;
1625
1626         PrintFrameName (m, e->v->frame);
1627 }
1628
1629 /*
1630 ==================
1631 Host_Viewprev_f
1632 ==================
1633 */
1634 void Host_Viewprev_f (void)
1635 {
1636         edict_t *e;
1637         model_t *m;
1638
1639         e = FindViewthing ();
1640         if (!e)
1641                 return;
1642
1643         m = cl.model_precache[(int)e->v->modelindex];
1644
1645         e->v->frame = e->v->frame - 1;
1646         if (e->v->frame < 0)
1647                 e->v->frame = 0;
1648
1649         PrintFrameName (m, e->v->frame);
1650 }
1651
1652 /*
1653 ===============================================================================
1654
1655 DEMO LOOP CONTROL
1656
1657 ===============================================================================
1658 */
1659
1660
1661 /*
1662 ==================
1663 Host_Startdemos_f
1664 ==================
1665 */
1666 void Host_Startdemos_f (void)
1667 {
1668         int             i, c;
1669
1670         if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
1671         {
1672                 if (!sv.active)
1673                 {
1674                         if (gamemode == GAME_TRANSFUSION)
1675                                 Cbuf_AddText ("map bb1\n");
1676                         else
1677                                 Cbuf_AddText ("map start\n");
1678                 }
1679                 return;
1680         }
1681
1682         c = Cmd_Argc() - 1;
1683         if (c > MAX_DEMOS)
1684         {
1685                 Con_Printf("Max %i demos in demoloop\n", MAX_DEMOS);
1686                 c = MAX_DEMOS;
1687         }
1688         Con_DPrintf("%i demo(s) in loop\n", c);
1689
1690         for (i=1 ; i<c+1 ; i++)
1691                 strlcpy (cls.demos[i-1], Cmd_Argv(i), sizeof (cls.demos[i-1]));
1692
1693         // LordHavoc: clear the remaining slots
1694         for (;i <= MAX_DEMOS;i++)
1695                 cls.demos[i-1][0] = 0;
1696
1697         if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
1698         {
1699                 cls.demonum = 0;
1700                 CL_NextDemo ();
1701         }
1702         else
1703                 cls.demonum = -1;
1704 }
1705
1706
1707 /*
1708 ==================
1709 Host_Demos_f
1710
1711 Return to looping demos
1712 ==================
1713 */
1714 void Host_Demos_f (void)
1715 {
1716         if (cls.state == ca_dedicated)
1717                 return;
1718         if (cls.demonum == -1)
1719                 cls.demonum = 1;
1720         CL_Disconnect_f ();
1721         CL_NextDemo ();
1722 }
1723
1724 /*
1725 ==================
1726 Host_Stopdemo_f
1727
1728 Return to looping demos
1729 ==================
1730 */
1731 void Host_Stopdemo_f (void)
1732 {
1733         if (!cls.demoplayback)
1734                 return;
1735         CL_Disconnect ();
1736         Host_ShutdownServer (false);
1737 }
1738
1739 static void MaxPlayers_f(void)
1740 {
1741         int n;
1742
1743         if (Cmd_Argc() != 2)
1744         {
1745                 Con_Printf("\"maxplayers\" is \"%u\"\n", svs.maxclients);
1746                 return;
1747         }
1748
1749         if (sv.active)
1750         {
1751                 Con_Print("maxplayers can not be changed while a server is running.\n");
1752                 return;
1753         }
1754
1755         n = atoi(Cmd_Argv(1));
1756         n = bound(1, n, MAX_SCOREBOARD);
1757         Con_Printf("\"maxplayers\" set to \"%u\"\n", n);
1758
1759         if (svs.clients)
1760                 Mem_Free(svs.clients);
1761         svs.maxclients = n;
1762         svs.clients = Mem_Alloc(sv_clients_mempool, sizeof(client_t) * svs.maxclients);
1763         if (n == 1)
1764                 Cvar_Set ("deathmatch", "0");
1765         else
1766                 Cvar_Set ("deathmatch", "1");
1767 }
1768
1769 //=============================================================================
1770
1771 /*
1772 ==================
1773 Host_InitCommands
1774 ==================
1775 */
1776 void Host_InitCommands (void)
1777 {
1778         Cmd_AddCommand ("status", Host_Status_f);
1779         Cmd_AddCommand ("quit", Host_Quit_f);
1780         if (gamemode == GAME_NEHAHRA)
1781         {
1782                 Cmd_AddCommand ("max", Host_God_f);
1783                 Cmd_AddCommand ("monster", Host_Notarget_f);
1784                 Cmd_AddCommand ("scrag", Host_Fly_f);
1785                 Cmd_AddCommand ("wraith", Host_Noclip_f);
1786                 Cmd_AddCommand ("gimme", Host_Give_f);
1787         }
1788         else
1789         {
1790                 Cmd_AddCommand ("god", Host_God_f);
1791                 Cmd_AddCommand ("notarget", Host_Notarget_f);
1792                 Cmd_AddCommand ("fly", Host_Fly_f);
1793                 Cmd_AddCommand ("noclip", Host_Noclip_f);
1794                 Cmd_AddCommand ("give", Host_Give_f);
1795         }
1796         Cmd_AddCommand ("map", Host_Map_f);
1797         Cmd_AddCommand ("restart", Host_Restart_f);
1798         Cmd_AddCommand ("changelevel", Host_Changelevel_f);
1799         Cmd_AddCommand ("connect", Host_Connect_f);
1800         Cmd_AddCommand ("reconnect", Host_Reconnect_f);
1801         Cmd_AddCommand ("version", Host_Version_f);
1802         Cmd_AddCommand ("say", Host_Say_f);
1803         Cmd_AddCommand ("say_team", Host_Say_Team_f);
1804         Cmd_AddCommand ("tell", Host_Tell_f);
1805         Cmd_AddCommand ("kill", Host_Kill_f);
1806         Cmd_AddCommand ("pause", Host_Pause_f);
1807         Cmd_AddCommand ("kick", Host_Kick_f);
1808         Cmd_AddCommand ("ping", Host_Ping_f);
1809         Cmd_AddCommand ("load", Host_Loadgame_f);
1810         Cmd_AddCommand ("save", Host_Savegame_f);
1811
1812         Cmd_AddCommand ("startdemos", Host_Startdemos_f);
1813         Cmd_AddCommand ("demos", Host_Demos_f);
1814         Cmd_AddCommand ("stopdemo", Host_Stopdemo_f);
1815
1816         Cmd_AddCommand ("viewmodel", Host_Viewmodel_f);
1817         Cmd_AddCommand ("viewframe", Host_Viewframe_f);
1818         Cmd_AddCommand ("viewnext", Host_Viewnext_f);
1819         Cmd_AddCommand ("viewprev", Host_Viewprev_f);
1820
1821         Cvar_RegisterVariable (&cl_name);
1822         Cmd_AddCommand ("name", Host_Name_f);
1823         Cvar_RegisterVariable (&cl_color);
1824         Cmd_AddCommand ("color", Host_Color_f);
1825         Cvar_RegisterVariable (&cl_rate);
1826         Cmd_AddCommand ("rate", Host_Rate_f);
1827         if (gamemode == GAME_NEHAHRA)
1828         {
1829                 Cvar_RegisterVariable (&cl_pmodel);
1830                 Cmd_AddCommand ("pmodel", Host_PModel_f);
1831         }
1832         Cmd_AddCommand ("prespawn", Host_PreSpawn_f);
1833         Cmd_AddCommand ("spawn", Host_Spawn_f);
1834         Cmd_AddCommand ("begin", Host_Begin_f);
1835         Cmd_AddCommand ("maxplayers", MaxPlayers_f);
1836
1837         Cvar_RegisterVariable(&sv_cheats);
1838 }
1839