示例#1
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);
        }
示例#2
0
        public static void SV_SpawnServer(String server, String spawnpoint, Int32 serverstate, Boolean attractloop, Boolean loadgame)
        {
            Int32 i;
            var   checksum = 0;

            if (attractloop)
            {
                Cvar.Set("paused", "0");
            }
            Com.Printf("------- Server Initialization -------\\n");
            Com.DPrintf("SpawnServer: " + server + "\\n");
            if (sv.demofile != null)
            {
                try
                {
                    sv.demofile.Close();
                }
                catch (Exception e)
                {
                }
            }

            svs.spawncount++;
            sv.state             = Defines.ss_dead;
            Globals.server_state = sv.state;
            sv             = new server_t();
            svs.realtime   = 0;
            sv.loadgame    = loadgame;
            sv.attractloop = attractloop;
            sv.configstrings[Defines.CS_NAME] = server;
            if (Cvar.VariableValue("deathmatch") != 0)
            {
                sv.configstrings[Defines.CS_AIRACCEL] = "" + SV_MAIN.sv_airaccelerate.value;
                PMove.pm_airaccelerate = SV_MAIN.sv_airaccelerate.value;
            }
            else
            {
                sv.configstrings[Defines.CS_AIRACCEL] = "0";
                PMove.pm_airaccelerate = 0;
            }

            SZ.Init(sv.multicast, sv.multicast_buf, sv.multicast_buf.Length);
            sv.name = server;
            for (i = 0; i < SV_MAIN.maxclients.value; i++)
            {
                if (svs.clients[i].state > Defines.cs_connected)
                {
                    svs.clients[i].state = Defines.cs_connected;
                }
                svs.clients[i].lastframe = -1;
            }

            sv.time = 1000;
            sv.name = server;
            sv.configstrings[Defines.CS_NAME] = server;
            Int32[] iw = new[] { checksum };
            if (serverstate != Defines.ss_game)
            {
                sv.models[1] = CM.CM_LoadMap("", false, iw);
            }
            else
            {
                sv.configstrings[Defines.CS_MODELS + 1] = "maps/" + server + ".bsp";
                sv.models[1] = CM.CM_LoadMap(sv.configstrings[Defines.CS_MODELS + 1], false, iw);
            }

            checksum = iw[0];
            sv.configstrings[Defines.CS_MAPCHECKSUM] = "" + checksum;
            SV_WORLD.SV_ClearWorld();
            for (i = 1; i < CM.CM_NumInlineModels(); i++)
            {
                sv.configstrings[Defines.CS_MODELS + 1 + i] = "*" + i;
                sv.models[i + 1] = CM.InlineModel(sv.configstrings[Defines.CS_MODELS + 1 + i]);
            }

            sv.state             = Defines.ss_loading;
            Globals.server_state = sv.state;
            GameSpawn.SpawnEntities(sv.name, CM.CM_EntityString(), spawnpoint);
            GameBase.G_RunFrame();
            GameBase.G_RunFrame();
            sv.state             = serverstate;
            Globals.server_state = sv.state;
            SV_CreateBaseline();
            SV_CheckForSavegame();
            Cvar.FullSet("mapname", sv.name, Defines.CVAR_SERVERINFO | Defines.CVAR_NOSET);
        }