]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - host_cmd.c
cl_capturevideo_raw* modes now use O_NONBLOCKING file access for more performance
[xonotic/darkplaces.git] / host_cmd.c
index 1e67a8db3c237eb11225cd1198826b3d3a4dfd0f..86668a20a267a3c2dae6c6fb67621d8bbed28102 100644 (file)
@@ -65,8 +65,8 @@ void Host_Status_f (void)
        for (players = 0, j = 0;j < svs.maxclients;j++)
                if (svs.clients[j].active)
                        players++;
-       print ("host:    %s\n", Cvar_VariableString ("hostname"));
-       print ("version: %s build %s\n", gamename, buildstring);
+       print ("host:     %s\n", Cvar_VariableString ("hostname"));
+       print ("version:  %s build %s\n", gamename, buildstring);
        switch(sv.protocol)
        {
                case PROTOCOL_QUAKE: protocolname = sv.netquakecompatible ? "QUAKE" : "QUAKEDP";break;
@@ -79,8 +79,8 @@ void Host_Status_f (void)
                default: protocolname = "PROTOCOL_UNKNOWN";break;
        }
        print ("protocol: %i (%s)\n", sv.protocol, protocolname);
-       print ("map:     %s\n", sv.name);
-       print ("players: %i active (%i max)\n\n", players, svs.maxclients);
+       print ("map:      %s\n", sv.name);
+       print ("players:  %i active (%i max)\n\n", players, svs.maxclients);
        for (j = 0, client = svs.clients;j < svs.maxclients;j++, client++)
        {
                if (!client->active)
@@ -276,7 +276,6 @@ void Host_Map_f (void)
        if (cmd_source != src_command)
                return;
 
-       SCR_BeginLoadingPlaque ();
        cls.demonum = -1;               // stop demo loop in case this fails
 
        CL_Disconnect ();
@@ -304,7 +303,7 @@ Goes to a new map, taking all clients along
 void Host_Changelevel_f (void)
 {
        char level[MAX_QPATH];
-       
+
        if (Cmd_Argc() != 2)
        {
                Con_Print("changelevel <levelname> : continue game on a new level\n");
@@ -323,7 +322,6 @@ void Host_Changelevel_f (void)
        key_consoleactive = 0;
 
        SV_SaveSpawnparms ();
-       SCR_BeginLoadingPlaque();
        allowcheats = sv_cheats.integer != 0;
        strcpy(level, Cmd_Argv(1));
        SV_SpawnServer(level);
@@ -341,7 +339,7 @@ Restarts the current server for a dead player
 void Host_Restart_f (void)
 {
        char mapname[MAX_QPATH];
-       
+
        if (Cmd_Argc() != 1)
        {
                Con_Print("restart : restart current level\n");
@@ -359,7 +357,6 @@ void Host_Restart_f (void)
        key_dest = key_game;
        key_consoleactive = 0;
 
-       SCR_BeginLoadingPlaque();
        allowcheats = sv_cheats.integer != 0;
        strcpy(mapname, sv.name);
        SV_SpawnServer(mapname);
@@ -387,7 +384,6 @@ void Host_Reconnect_f (void)
                //Con_Print("reconnect: no signon, ignoring reconnect\n");
                return;
        }
-       SCR_BeginLoadingPlaque();
        cls.signon = 0;         // need new connection messages
 }
 
@@ -504,7 +500,7 @@ void Host_Savegame_f (void)
        FS_DefaultExtension (name, ".sav", sizeof (name));
 
        Con_Printf("Saving game to %s...\n", name);
-       f = FS_Open (name, "w", false);
+       f = FS_Open (name, "wb", false, false);
        if (!f)
        {
                Con_Print("ERROR: couldn't open.\n");
@@ -520,8 +516,7 @@ void Host_Savegame_f (void)
        FS_Printf(f, "%s\n", sv.name);
        FS_Printf(f, "%f\n",sv.time);
 
-// write the light styles
-
+       // write the light styles
        for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
        {
                if (sv.lightstyles[i])
@@ -530,13 +525,9 @@ void Host_Savegame_f (void)
                        FS_Print(f,"m\n");
        }
 
-
        ED_WriteGlobals (f);
        for (i=0 ; i<sv.num_edicts ; i++)
-       {
                ED_Write (f, EDICT_NUM(i));
-               FS_Flush (f);
-       }
        FS_Close (f);
        Con_Print("done.\n");
 }
@@ -551,15 +542,14 @@ Host_Loadgame_f
 */
 void Host_Loadgame_f (void)
 {
-       qfile_t *f;
        char filename[MAX_QPATH];
        char mapname[MAX_QPATH];
-       float time, tfloat;
-       char buf[32768];
+       float time;
        const char *start;
-       char *str;
-       int i, r;
+       const char *t;
+       char *text;
        edict_t *ent;
+       int i;
        int entnum;
        int version;
        float spawn_parms[NUM_SPAWN_PARMS];
@@ -580,45 +570,53 @@ void Host_Loadgame_f (void)
 
        cls.demonum = -1;               // stop demo loop in case this fails
 
-       f = FS_Open (filename, "r", false);
-       if (!f)
+       t = text = FS_LoadFile (filename, tempmempool, false);
+       if (!text)
        {
                Con_Print("ERROR: couldn't open.\n");
                return;
        }
 
-       str = FS_Getline (f);
-       sscanf (str, "%i\n", &version);
+       // version
+       COM_ParseToken(&t, false);
+       version = atoi(com_token);
        if (version != SAVEGAME_VERSION)
        {
-               FS_Close (f);
+               Mem_Free(text);
                Con_Printf("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
                return;
        }
 
-       SCR_BeginLoadingPlaque ();
+       // description
+       // this is a little hard to parse, as : is a separator in COM_ParseToken,
+       // so use the console parser instead
+       COM_ParseTokenConsole(&t);
 
-       str = FS_Getline (f);
        for (i = 0;i < NUM_SPAWN_PARMS;i++)
        {
-               str = FS_Getline (f);
-               sscanf (str, "%f\n", &spawn_parms[i]);
+               COM_ParseToken(&t, false);
+               spawn_parms[i] = atof(com_token);
        }
+       // skill
+       COM_ParseToken(&t, false);
 // this silliness is so we can load 1.06 save files, which have float skill values
-       str = FS_Getline (f);
-       sscanf (str, "%f\n", &tfloat);
-       current_skill = (int)(tfloat + 0.1);
+       current_skill = (int)(atof(com_token) + 0.5);
        Cvar_SetValue ("skill", (float)current_skill);
 
-       strcpy (mapname, FS_Getline (f));
+       // mapname
+       COM_ParseToken(&t, false);
+       strcpy (mapname, com_token);
 
-       str = FS_Getline (f);
-       sscanf (str, "%f\n",&time);
+       // time
+       COM_ParseToken(&t, false);
+       time = atof(com_token);
 
        allowcheats = sv_cheats.integer != 0;
+
        SV_SpawnServer (mapname);
        if (!sv.active)
        {
+               Mem_Free(text);
                Con_Print("Couldn't load map\n");
                return;
        }
@@ -629,9 +627,10 @@ void Host_Loadgame_f (void)
 
        for (i = 0;i < MAX_LIGHTSTYLES;i++)
        {
-               str = FS_Getline (f);
-               sv.lightstyles[i] = Mem_Alloc(edictstring_mempool, strlen(str)+1);
-               strcpy (sv.lightstyles[i], str);
+               // light style
+               COM_ParseToken(&t, false);
+               sv.lightstyles[i] = Mem_Alloc(edictstring_mempool, strlen(com_token)+1);
+               strcpy (sv.lightstyles[i], com_token);
        }
 
 // load the edicts out of the savegame file
@@ -639,32 +638,20 @@ void Host_Loadgame_f (void)
        entnum = -1;
        for (;;)
        {
-               r = EOF;
-               for (i = 0;i < (int)sizeof(buf) - 1;i++)
-               {
-                       r = FS_Getc (f);
-                       if (r == EOF || !r)
-                               break;
-                       buf[i] = r;
-                       if (r == '}')
-                       {
-                               i++;
+               start = t;
+               while (COM_ParseToken(&t, false))
+                       if (!strcmp(com_token, "}"))
                                break;
-                       }
-               }
-               if (r == EOF)
-                       break;
-               if (i == sizeof(buf)-1)
-                       Host_Error ("Loadgame buffer overflow");
-               buf[i] = 0;
-               start = buf;
                if (!COM_ParseToken(&start, false))
                {
                        // end of file
                        break;
                }
                if (strcmp(com_token,"{"))
+               {
+                       Mem_Free(text);
                        Host_Error ("First token isn't a brace");
+               }
 
                if (entnum == -1)
                {
@@ -675,7 +662,10 @@ void Host_Loadgame_f (void)
                {
                        // parse an edict
                        if (entnum >= MAX_EDICTS)
+                       {
+                               Mem_Free(text);
                                Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)\n", MAX_EDICTS);
+                       }
                        while (entnum >= sv.max_edicts)
                                SV_IncreaseEdicts();
                        ent = EDICT_NUM(entnum);
@@ -694,8 +684,6 @@ void Host_Loadgame_f (void)
        sv.num_edicts = entnum;
        sv.time = time;
 
-       FS_Close (f);
-
        for (i = 0;i < NUM_SPAWN_PARMS;i++)
                svs.clients[0].spawn_parms[i] = spawn_parms[i];
 
@@ -746,7 +734,7 @@ void Host_Name_f (void)
                SV_ClientPrintf("You can't change name more than once every 5 seconds!\n");
                return;
        }
-       
+
        host_client->nametime = sv.time + 5;
 
        // point the string back at updateclient->name to keep it safe
@@ -769,7 +757,7 @@ void Host_Name_f (void)
 Host_Playermodel_f
 ======================
 */
-cvar_t cl_playermodel = {CVAR_SAVE, "_cl_playermodel", ""}; 
+cvar_t cl_playermodel = {CVAR_SAVE, "_cl_playermodel", ""};
 // the old cl_playermodel in cl_main has been renamed to __cl_playermodel
 void Host_Playermodel_f (void)
 {
@@ -806,7 +794,7 @@ void Host_Playermodel_f (void)
                SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
                return;
        }
-       
+
        host_client->nametime = sv.time + 5;
        */
 
@@ -867,7 +855,7 @@ void Host_Playerskin_f (void)
                SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
                return;
        }
-       
+
        host_client->nametime = sv.time + 5;
        */
 
@@ -931,9 +919,9 @@ void Host_Say(qboolean teamonly)
                p1++;
        }
        if (!fromServer)
-               snprintf (text, sizeof(text), "%c%s: %s", 1, host_client->name, p1);
+               dpsnprintf (text, sizeof(text), "%c%s: %s", 1, host_client->name, p1);
        else
-               snprintf (text, sizeof(text), "%c<%s> %s", 1, hostname.string, p1);
+               dpsnprintf (text, sizeof(text), "%c<%s> %s", 1, hostname.string, p1);
        p2 = text + strlen(text);
        while ((const char *)p2 > (const char *)text && (p2[-1] == '\r' || p2[-1] == '\n' || (p2[-1] == '\"' && quoted)))
        {