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