Esempio n. 1
0
        /**
         * SV_CheckForSavegame.
         */
        public static void SV_CheckForSavegame()
        {
            string name;

            int i;

            if (SV_MAIN.sv_noreload.value != 0)
            {
                return;
            }

            if (Cvar.VariableValue("deathmatch") != 0)
            {
                return;
            }

            name = FS.Gamedir() + "/save/current/" + SV_INIT.sv.name + ".sav";

            if (!File.Exists(name))
            {
                return;
            }

            SV_WORLD.SV_ClearWorld();

            // get configstrings and areaportals
            SV_CCMDS.SV_ReadLevelFile();

            if (!SV_INIT.sv.loadgame)
            {
                // coming back to a level after being in a different
                // level, so run it for ten seconds

                // rlava2 was sending too many lightstyles, and overflowing the
                // reliable data. temporarily changing the server state to loading
                // prevents these from being passed down.
                int previousState;                     // PGM

                previousState    = SV_INIT.sv.state;   // PGM
                SV_INIT.sv.state = Defines.ss_loading; // PGM

                for (i = 0; i < 100; i++)
                {
                    GameBase.G_RunFrame();
                }

                SV_INIT.sv.state = previousState;                 // PGM
            }
        }
Esempio n. 2
0
        /**
         * SV_SpawnServer.
         *
         * Change the server to a new map, taking all connected clients along with
         * it.
         */
        public static void SV_SpawnServer(string server, string spawnpoint, int serverstate, bool attractloop, bool loadgame)
        {
            int i;
            var checksum = 0;

            if (attractloop)
            {
                Cvar.Set("paused", "0");
            }

            Com.Printf("------- Server Initialization -------\n");

            Com.DPrintf("SpawnServer: " + server + "\n");

            if (SV_INIT.sv.demofile != null)
            {
                try
                {
                    SV_INIT.sv.demofile.Close();
                }
                catch (Exception)
                {
                }
            }

            // any partially connected client will be restarted
            SV_INIT.svs.spawncount++;

            SV_INIT.sv.state = Defines.ss_dead;

            Globals.server_state = SV_INIT.sv.state;

            // wipe the entire per-level structure
            SV_INIT.sv = new();

            SV_INIT.svs.realtime   = 0;
            SV_INIT.sv.loadgame    = loadgame;
            SV_INIT.sv.attractloop = attractloop;

            // save name for levels that don't set message
            SV_INIT.sv.configstrings[Defines.CS_NAME] = server;

            if (Cvar.VariableValue("deathmatch") != 0)
            {
                SV_INIT.sv.configstrings[Defines.CS_AIRACCEL] = "" + SV_MAIN.sv_airaccelerate.value;
                PMove.pm_airaccelerate = SV_MAIN.sv_airaccelerate.value;
            }
            else
            {
                SV_INIT.sv.configstrings[Defines.CS_AIRACCEL] = "0";
                PMove.pm_airaccelerate = 0;
            }

            SZ.Init(SV_INIT.sv.multicast, SV_INIT.sv.multicast_buf, SV_INIT.sv.multicast_buf.Length);

            SV_INIT.sv.name = server;

            // leave slots at start for clients only
            for (i = 0; i < SV_MAIN.maxclients.value; i++)
            {
                // needs to reconnect
                if (SV_INIT.svs.clients[i].state > Defines.cs_connected)
                {
                    SV_INIT.svs.clients[i].state = Defines.cs_connected;
                }

                SV_INIT.svs.clients[i].lastframe = -1;
            }

            SV_INIT.sv.time = 1000;

            SV_INIT.sv.name = server;
            SV_INIT.sv.configstrings[Defines.CS_NAME] = server;

            int[] iw = { checksum };

            if (serverstate != Defines.ss_game)
            {
                SV_INIT.sv.models[1] = CM.CM_LoadMap("", false, iw);                 // no real map
            }
            else
            {
                SV_INIT.sv.configstrings[Defines.CS_MODELS + 1] = "maps/" + server + ".bsp";
                SV_INIT.sv.models[1] = CM.CM_LoadMap(SV_INIT.sv.configstrings[Defines.CS_MODELS + 1], false, iw);
            }

            checksum = iw[0];
            SV_INIT.sv.configstrings[Defines.CS_MAPCHECKSUM] = "" + checksum;

            // clear physics interaction links

            SV_WORLD.SV_ClearWorld();

            for (i = 1; i < CM.CM_NumInlineModels(); i++)
            {
                SV_INIT.sv.configstrings[Defines.CS_MODELS + 1 + i] = "*" + i;

                // copy references
                SV_INIT.sv.models[i + 1] = CM.InlineModel(SV_INIT.sv.configstrings[Defines.CS_MODELS + 1 + i]);
            }

            // spawn the rest of the entities on the map

            // precache and static commands can be issued during
            // map initialization

            SV_INIT.sv.state     = Defines.ss_loading;
            Globals.server_state = SV_INIT.sv.state;

            // load and spawn all other entities
            GameSpawn.SpawnEntities(SV_INIT.sv.name, CM.CM_EntityString(), spawnpoint);

            // run two frames to allow everything to settle
            GameBase.G_RunFrame();
            GameBase.G_RunFrame();

            // all precaches are complete
            SV_INIT.sv.state     = serverstate;
            Globals.server_state = SV_INIT.sv.state;

            // create a baseline for more efficient communications
            SV_INIT.SV_CreateBaseline();

            // check for a savegame
            SV_INIT.SV_CheckForSavegame();

            // set serverinfo variable
            Cvar.FullSet("mapname", SV_INIT.sv.name, Defines.CVAR_SERVERINFO | Defines.CVAR_NOSET);
        }