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