]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - host_cmd.c
make dedicated work again
[xonotic/darkplaces.git] / host_cmd.c
index c08e92125405bcbb31a682cc5b70a47858a8d28f..a97af9f6ff0b5f2267ed47a391c986a67c8f6613 100644 (file)
@@ -20,12 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include "quakedef.h"
 
-extern cvar_t  pausable;
-
 int    current_skill;
 
-void Mod_Print (void);
-
 dfunction_t *ED_FindFunction (char *name);
 
 /*
@@ -37,6 +33,7 @@ Host_Quit_f
 // LordHavoc: didn't like it asking me if I wanted to quit
 //extern void M_Menu_Quit_f (void);
 
+extern qboolean host_shuttingdown;
 void Host_Quit_f (void)
 {
        /*
@@ -46,8 +43,9 @@ void Host_Quit_f (void)
                return;
        }
        */
+       host_shuttingdown = true;
        CL_Disconnect ();
-       Host_ShutdownServer(false);             
+       Host_ShutdownServer(false);
 
        Sys_Quit ();
 }
@@ -66,7 +64,7 @@ void Host_Status_f (void)
        int                     hours = 0;
        int                     j;
        void            (*print) (char *fmt, ...);
-       
+
        if (cmd_source == src_command)
        {
                if (!sv.active)
@@ -80,7 +78,7 @@ void Host_Status_f (void)
                print = SV_ClientPrintf;
 
        print ("host:    %s\n", Cvar_VariableString ("hostname"));
-       print ("version: %4.2f\n", VERSION);
+       print ("version: %s build %i\n", gamename, buildnumber);
        if (tcpipAvailable)
                print ("tcp/ip:  %s\n", my_tcpip_address);
        if (ipxAvailable)
@@ -268,11 +266,12 @@ void Host_Map_f (void)
 
        cls.demonum = -1;               // stop demo loop in case this fails
 
+//     SCR_BeginLoadingPlaque ();
+
        CL_Disconnect ();
        Host_ShutdownServer(false);             
 
        key_dest = key_game;                    // remove console or menu
-       SCR_BeginLoadingPlaque ();
 
        cls.mapstring[0] = 0;
        for (i=0 ; i<Cmd_Argc() ; i++)
@@ -359,7 +358,7 @@ This is sent just before a server changes levels
 */
 void Host_Reconnect_f (void)
 {
-       SCR_BeginLoadingPlaque ();
+//     SCR_BeginLoadingPlaque ();
        cls.signon = 0;         // need new connection messages
 }
 
@@ -376,10 +375,7 @@ void Host_Connect_f (void)
        
        cls.demonum = -1;               // stop demo loop in case this fails
        if (cls.demoplayback)
-       {
-               CL_StopPlayback ();
                CL_Disconnect ();
-       }
        strcpy (name, Cmd_Argv(1));
        CL_EstablishConnection (name);
        Host_Reconnect_f ();
@@ -429,7 +425,7 @@ Host_Savegame_f
 void Host_Savegame_f (void)
 {
        char    name[256];
-       FILE    *f;
+       QFile   *f;
        int             i;
        char    comment[SAVEGAME_COMMENT_LENGTH+1];
 
@@ -479,30 +475,30 @@ void Host_Savegame_f (void)
        COM_DefaultExtension (name, ".sav");
        
        Con_Printf ("Saving game to %s...\n", name);
-       f = fopen (name, "w");
+       f = Qopen (name, "w");
        if (!f)
        {
                Con_Printf ("ERROR: couldn't open.\n");
                return;
        }
        
-       fprintf (f, "%i\n", SAVEGAME_VERSION);
+       Qprintf (f, "%i\n", SAVEGAME_VERSION);
        Host_SavegameComment (comment);
-       fprintf (f, "%s\n", comment);
+       Qprintf (f, "%s\n", comment);
        for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
-               fprintf (f, "%f\n", svs.clients->spawn_parms[i]);
-       fprintf (f, "%d\n", current_skill);
-       fprintf (f, "%s\n", sv.name);
-       fprintf (f, "%f\n",sv.time);
+               Qprintf (f, "%f\n", svs.clients->spawn_parms[i]);
+       Qprintf (f, "%d\n", current_skill);
+       Qprintf (f, "%s\n", sv.name);
+       Qprintf (f, "%f\n",sv.time);
 
 // write the light styles
 
        for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
        {
                if (sv.lightstyles[i])
-                       fprintf (f, "%s\n", sv.lightstyles[i]);
+                       Qprintf (f, "%s\n", sv.lightstyles[i]);
                else
-                       fprintf (f,"m\n");
+                       Qprintf (f,"m\n");
        }
 
 
@@ -510,13 +506,15 @@ void Host_Savegame_f (void)
        for (i=0 ; i<sv.num_edicts ; i++)
        {
                ED_Write (f, EDICT_NUM(i));
-               fflush (f);
+               Qflush (f);
        }
-       fclose (f);
+       Qclose (f);
        Con_Printf ("done.\n");
 }
 
 
+extern mempool_t *edictstring_mempool;
+
 /*
 ===============
 Host_Loadgame_f
@@ -525,15 +523,16 @@ Host_Loadgame_f
 void Host_Loadgame_f (void)
 {
        char    name[MAX_OSPATH];
-       FILE    *f;
+       QFile   *f;
        char    mapname[MAX_QPATH];
        float   time, tfloat;
-       char    str[32768], *start;
+       char    buf[32768], *start;
+       char    *str;
        int             i, r;
        edict_t *ent;
        int             entnum;
        int             version;
-       float                   spawn_parms[NUM_SPAWN_PARMS];
+       float   spawn_parms[NUM_SPAWN_PARMS];
 
        if (cmd_source != src_command)
                return;
@@ -548,36 +547,43 @@ void Host_Loadgame_f (void)
 
        sprintf (name, "%s/%s", com_gamedir, Cmd_Argv(1));
        COM_DefaultExtension (name, ".sav");
-       
-// we can't call SCR_BeginLoadingPlaque, because too much stack space has
-// been used.  The menu calls it before stuffing loadgame command
+
+       // LordHavoc: made SCR_UpdateScreen use a great deal less stack space, no longer an issue
+       //// we can't call SCR_BeginLoadingPlaque, because too much stack space has
+       //// been used.  The menu calls it before stuffing loadgame command
 //     SCR_BeginLoadingPlaque ();
 
        Con_Printf ("Loading game from %s...\n", name);
-       f = fopen (name, "r");
+       f = Qopen (name, "rz");
        if (!f)
        {
                Con_Printf ("ERROR: couldn't open.\n");
                return;
        }
 
-       fscanf (f, "%i\n", &version);
+       str = Qgetline (f);
+       sscanf (str, "%i\n", &version);
        if (version != SAVEGAME_VERSION)
        {
-               fclose (f);
+               Qclose (f);
                Con_Printf ("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
                return;
        }
-       fscanf (f, "%s\n", str);
-       for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
-               fscanf (f, "%f\n", &spawn_parms[i]);
+       str = Qgetline (f);
+       for (i=0 ; i<NUM_SPAWN_PARMS ; i++) {
+               str = Qgetline (f);
+               sscanf (str, "%f\n", &spawn_parms[i]);
+       }
 // this silliness is so we can load 1.06 save files, which have float skill values
-       fscanf (f, "%f\n", &tfloat);
+       str = Qgetline (f);
+       sscanf (str, "%f\n", &tfloat);
        current_skill = (int)(tfloat + 0.1);
        Cvar_SetValue ("skill", (float)current_skill);
 
-       fscanf (f, "%s\n",mapname);
-       fscanf (f, "%f\n",&time);
+       strcpy (mapname, Qgetline (f));
+
+       str = Qgetline (f);
+       sscanf (str, "%f\n",&time);
 
        CL_Disconnect_f ();
        
@@ -594,32 +600,32 @@ void Host_Loadgame_f (void)
 
        for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
        {
-               fscanf (f, "%s\n", str);
-               sv.lightstyles[i] = Hunk_Alloc (strlen(str)+1);
+               str = Qgetline (f);
+               sv.lightstyles[i] = Mem_Alloc(edictstring_mempool, strlen(str)+1);
                strcpy (sv.lightstyles[i], str);
        }
 
 // load the edicts out of the savegame file
        entnum = -1;            // -1 is the globals
-       while (!feof(f))
+       while (!Qeof(f))
        {
-               for (i=0 ; i<sizeof(str)-1 ; i++)
+               for (i=0 ; i<sizeof(buf)-1 ; i++)
                {
-                       r = fgetc (f);
+                       r = Qgetc (f);
                        if (r == EOF || !r)
                                break;
-                       str[i] = r;
+                       buf[i] = r;
                        if (r == '}')
                        {
                                i++;
                                break;
                        }
                }
-               if (i == sizeof(str)-1)
+               if (i == sizeof(buf)-1)
                        Sys_Error ("Loadgame buffer overflow");
-               str[i] = 0;
-               start = str;
-               start = COM_Parse(str);
+               buf[i] = 0;
+               start = buf;
+               start = COM_Parse(buf);
                if (!com_token[0])
                        break;          // end of file
                if (strcmp(com_token,"{"))
@@ -648,7 +654,7 @@ void Host_Loadgame_f (void)
        sv.num_edicts = entnum;
        sv.time = time;
 
-       fclose (f);
+       Qclose (f);
 
        for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
                svs.clients->spawn_parms[i] = spawn_parms[i];
@@ -669,17 +675,22 @@ Host_Name_f
 */
 void Host_Name_f (void)
 {
-       char    *newName;
+       char newName[64];
 
        if (Cmd_Argc () == 1)
        {
                Con_Printf ("\"name\" is \"%s\"\n", cl_name.string);
                return;
        }
+       //if (Cmd_Argc () == 2)
+       //      newName = Cmd_Argv(1);
+       //else
+       //      newName = Cmd_Args();
+       //newName[15] = 0;
        if (Cmd_Argc () == 2)
-               newName = Cmd_Argv(1);  
+               strncpy(newName, Cmd_Argv(1), 15);
        else
-               newName = Cmd_Args();
+               strncpy(newName, Cmd_Args(), 15);
        newName[15] = 0;
 
        if (cmd_source == src_command)
@@ -708,7 +719,7 @@ void Host_Name_f (void)
        
 void Host_Version_f (void)
 {
-       Con_Printf ("Version %4.2f\n", VERSION);
+       Con_Printf ("Version: %s build %i\n", gamename, buildnumber);
        Con_Printf ("Exe: "__TIME__" "__DATE__"\n");
 }
 
@@ -766,7 +777,7 @@ void Host_Say(qboolean teamonly)
        {
                if (!client || !client->active || !client->spawned)
                        continue;
-               if (teamplay.value && teamonly && client->edict->v.team != save->edict->v.team)
+               if (teamplay.integer && teamonly && client->edict->v.team != save->edict->v.team)
                        continue;
                host_client = client;
                SV_ClientPrintf("%s", text);
@@ -795,7 +806,7 @@ void Host_Tell_f(void)
        client_t *save;
        int             j;
        char    *p;
-       char    text[64];
+       char    text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
 
        if (cmd_source == src_command)
        {
@@ -855,7 +866,7 @@ void Host_Color_f(void)
        
        if (Cmd_Argc() == 1)
        {
-               Con_Printf ("\"color\" is \"%i %i\"\n", ((int)cl_color.value) >> 4, ((int)cl_color.value) & 0x0f);
+               Con_Printf ("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
                Con_Printf ("color <0-13> [0-13]\n");
                return;
        }
@@ -894,7 +905,7 @@ void Host_Color_f(void)
                pr_global_struct->time = sv.time;
                pr_globals[0] = playercolor;
                pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
-               PR_ExecuteProgram (SV_ChangeTeam);
+               PR_ExecuteProgram (SV_ChangeTeam, "");
        }
        else
        {
@@ -923,13 +934,13 @@ void Host_Kill_f (void)
 
        if (sv_player->v.health <= 0)
        {
-               SV_ClientPrintf ("Can't suicide -- allready dead!\n");
+               SV_ClientPrintf ("Can't suicide -- already dead!\n");
                return;
        }
        
        pr_global_struct->time = sv.time;
        pr_global_struct->self = EDICT_TO_PROG(sv_player);
-       PR_ExecuteProgram (pr_global_struct->ClientKill);
+       PR_ExecuteProgram (pr_global_struct->ClientKill, "QC function ClientKill is missing");
 }
 
 
@@ -946,7 +957,7 @@ void Host_Pause_f (void)
                Cmd_ForwardToServer ();
                return;
        }
-       if (!pausable.value)
+       if (!pausable.integer)
                SV_ClientPrintf ("Pause not allowed.\n");
        else
        {
@@ -985,7 +996,7 @@ void Host_PreSpawn_f (void)
 
        if (host_client->spawned)
        {
-               Con_Printf ("prespawn not valid -- allready spawned\n");
+               Con_Printf ("prespawn not valid -- already spawned\n");
                return;
        }
        
@@ -1016,7 +1027,7 @@ void Host_Spawn_f (void)
 
        if (host_client->spawned)
        {
-               Con_Printf ("Spawn not valid -- allready spawned\n");
+               Con_Printf ("Spawn not valid -- already spawned\n");
                return;
        }
 
@@ -1026,7 +1037,7 @@ void Host_Spawn_f (void)
 
 // run the entrance script
        if (sv.loadgame)
-       {       // loaded games are fully inited allready
+       {       // loaded games are fully inited already
                // if this is the last client to be connected, unpause
                sv.paused = false;
 
@@ -1036,7 +1047,7 @@ void Host_Spawn_f (void)
                        Con_DPrintf("Calling RestoreGame\n");
                        pr_global_struct->time = sv.time;
                        pr_global_struct->self = EDICT_TO_PROG(sv_player);
-                       PR_ExecuteProgram (RestoreGame);
+                       PR_ExecuteProgram (RestoreGame, "");
                }
        }
        else
@@ -1061,12 +1072,12 @@ void Host_Spawn_f (void)
 
                pr_global_struct->time = sv.time;
                pr_global_struct->self = EDICT_TO_PROG(sv_player);
-               PR_ExecuteProgram (pr_global_struct->ClientConnect);
+               PR_ExecuteProgram (pr_global_struct->ClientConnect, "QC function ClientConnect is missing");
 
-               if ((Sys_FloatTime() - host_client->netconnection->connecttime) <= sv.time)
+               if ((Sys_DoubleTime() - host_client->netconnection->connecttime) <= sv.time)
                        Sys_Printf ("%s entered the game\n", host_client->name);
 
-               PR_ExecuteProgram (pr_global_struct->PutClientInServer);        
+               PR_ExecuteProgram (pr_global_struct->PutClientInServer, "QC function PutClientInServer is missing");
        }
 
 
@@ -1268,58 +1279,58 @@ void Host_Give_f (void)
 
        t = Cmd_Argv(1);
        v = atoi (Cmd_Argv(2));
-       
+
        switch (t[0])
        {
-   case '0':
-   case '1':
-   case '2':
-   case '3':
-   case '4':
-   case '5':
-   case '6':
-   case '7':
-   case '8':
-   case '9':
-      // MED 01/04/97 added hipnotic give stuff
-      if (hipnotic)
-      {
-         if (t[0] == '6')
-         {
-            if (t[1] == 'a')
-               sv_player->v.items = (int)sv_player->v.items | HIT_PROXIMITY_GUN;
-            else
-               sv_player->v.items = (int)sv_player->v.items | IT_GRENADE_LAUNCHER;
-         }
-         else if (t[0] == '9')
-            sv_player->v.items = (int)sv_player->v.items | HIT_LASER_CANNON;
-         else if (t[0] == '0')
-            sv_player->v.items = (int)sv_player->v.items | HIT_MJOLNIR;
-         else if (t[0] >= '2')
-            sv_player->v.items = (int)sv_player->v.items | (IT_SHOTGUN << (t[0] - '2'));
-      }
-      else
-      {
-         if (t[0] >= '2')
-            sv_player->v.items = (int)sv_player->v.items | (IT_SHOTGUN << (t[0] - '2'));
-      }
+       case '0':
+       case '1':
+       case '2':
+       case '3':
+       case '4':
+       case '5':
+       case '6':
+       case '7':
+       case '8':
+       case '9':
+               // MED 01/04/97 added hipnotic give stuff
+               if (gamemode == GAME_HIPNOTIC)
+               {
+                       if (t[0] == '6')
+                       {
+                               if (t[1] == 'a')
+                               sv_player->v.items = (int)sv_player->v.items | HIT_PROXIMITY_GUN;
+                               else
+                               sv_player->v.items = (int)sv_player->v.items | IT_GRENADE_LAUNCHER;
+                       }
+                       else if (t[0] == '9')
+                               sv_player->v.items = (int)sv_player->v.items | HIT_LASER_CANNON;
+                       else if (t[0] == '0')
+                               sv_player->v.items = (int)sv_player->v.items | HIT_MJOLNIR;
+                       else if (t[0] >= '2')
+                               sv_player->v.items = (int)sv_player->v.items | (IT_SHOTGUN << (t[0] - '2'));
+               }
+               else
+               {
+                       if (t[0] >= '2')
+                               sv_player->v.items = (int)sv_player->v.items | (IT_SHOTGUN << (t[0] - '2'));
+               }
                break;
-       
-    case 's':
-               if (rogue)
+
+       case 's':
+               if (gamemode == GAME_ROGUE)
                {
-                   if ((val = GETEDICTFIELDVALUE(sv_player, eval_ammo_shells1)))
-                           val->_float = v;
+                       if ((val = GETEDICTFIELDVALUE(sv_player, eval_ammo_shells1)))
+                               val->_float = v;
                }
 
-        sv_player->v.ammo_shells = v;
-        break;         
-    case 'n':
-               if (rogue)
+               sv_player->v.ammo_shells = v;
+               break;
+       case 'n':
+               if (gamemode == GAME_ROGUE)
                {
-                   if ((val = GETEDICTFIELDVALUE(sv_player, eval_ammo_nails1)))
+                       if ((val = GETEDICTFIELDVALUE(sv_player, eval_ammo_nails1)))
                        {
-                           val->_float = v;
+                               val->_float = v;
                                if (sv_player->v.weapon <= IT_LIGHTNING)
                                        sv_player->v.ammo_nails = v;
                        }
@@ -1328,9 +1339,9 @@ void Host_Give_f (void)
                {
                        sv_player->v.ammo_nails = v;
                }
-        break;         
-    case 'l':
-               if (rogue)
+               break;
+       case 'l':
+               if (gamemode == GAME_ROGUE)
                {
                        val = GETEDICTFIELDVALUE(sv_player, eval_ammo_lava_nails);
                        if (val)
@@ -1340,9 +1351,9 @@ void Host_Give_f (void)
                                        sv_player->v.ammo_nails = v;
                        }
                }
-        break;
-    case 'r':
-               if (rogue)
+               break;
+       case 'r':
+               if (gamemode == GAME_ROGUE)
                {
                        val = GETEDICTFIELDVALUE(sv_player, eval_ammo_rockets1);
                        if (val)
@@ -1356,9 +1367,9 @@ void Host_Give_f (void)
                {
                        sv_player->v.ammo_rockets = v;
                }
-        break;         
-    case 'm':
-               if (rogue)
+               break;
+       case 'm':
+               if (gamemode == GAME_ROGUE)
                {
                        val = GETEDICTFIELDVALUE(sv_player, eval_ammo_multi_rockets);
                        if (val)
@@ -1368,12 +1379,12 @@ void Host_Give_f (void)
                                        sv_player->v.ammo_rockets = v;
                        }
                }
-        break;         
-    case 'h':
-        sv_player->v.health = v;
-        break;         
-    case 'c':
-               if (rogue)
+               break;
+       case 'h':
+               sv_player->v.health = v;
+               break;
+       case 'c':
+               if (gamemode == GAME_ROGUE)
                {
                        val = GETEDICTFIELDVALUE(sv_player, eval_ammo_cells1);
                        if (val)
@@ -1387,9 +1398,9 @@ void Host_Give_f (void)
                {
                        sv_player->v.ammo_cells = v;
                }
-        break;         
-    case 'p':
-               if (rogue)
+               break;
+       case 'p':
+               if (gamemode == GAME_ROGUE)
                {
                        val = GETEDICTFIELDVALUE(sv_player, eval_ammo_plasma);
                        if (val)
@@ -1399,15 +1410,15 @@ void Host_Give_f (void)
                                        sv_player->v.ammo_cells = v;
                        }
                }
-        break;         
-    }
+               break;
+       }
 }
 
 edict_t        *FindViewthing (void)
 {
        int             i;
        edict_t *e;
-       
+
        for (i=0 ; i<sv.num_edicts ; i++)
        {
                e = EDICT_NUM(i);
@@ -1432,7 +1443,7 @@ void Host_Viewmodel_f (void)
        if (!e)
                return;
 
-       m = Mod_ForName (Cmd_Argv(1), false);
+       m = Mod_ForName (Cmd_Argv(1), false, true, false);
        if (!m)
        {
                Con_Printf ("Can't load %s\n", Cmd_Argv(1));
@@ -1469,15 +1480,10 @@ void Host_Viewframe_f (void)
 
 void PrintFrameName (model_t *m, int frame)
 {
-       aliashdr_t                      *hdr;
-       maliasframedesc_t       *pframedesc;
-
-       hdr = (aliashdr_t *)Mod_Extradata (m);
-       if (!hdr)
-               return;
-       pframedesc = &hdr->frames[frame];
-       
-       Con_Printf ("frame %i: %s\n", frame, pframedesc->name);
+       if (m->animscenes)
+               Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
+       else
+               Con_Printf("frame %i\n", frame);
 }
 
 /*
@@ -1597,11 +1603,8 @@ Return to looping demos
 */
 void Host_Stopdemo_f (void)
 {
-       if (cls.state == ca_dedicated)
-               return;
        if (!cls.demoplayback)
                return;
-       CL_StopPlayback ();
        CL_Disconnect ();
 }
 
@@ -1616,7 +1619,7 @@ void Host_InitCommands (void)
 {
        Cmd_AddCommand ("status", Host_Status_f);
        Cmd_AddCommand ("quit", Host_Quit_f);
-       if (nehahra)
+       if (gamemode == GAME_NEHAHRA)
        {
                Cmd_AddCommand ("max", Host_God_f);
                Cmd_AddCommand ("monster", Host_Notarget_f);
@@ -1661,6 +1664,4 @@ void Host_InitCommands (void)
        Cmd_AddCommand ("viewframe", Host_Viewframe_f);
        Cmd_AddCommand ("viewnext", Host_Viewnext_f);
        Cmd_AddCommand ("viewprev", Host_Viewprev_f);
-
-       Cmd_AddCommand ("mcache", Mod_Print);
 }