Exemplo n.º 1
0
        /**
         * SV_InitGame.
         *
         * A brand new game has been started.
         */
        public static void SV_InitGame()
        {
            int     i;
            edict_t ent;

            //char idmaster[32];
            string idmaster;

            if (SV_INIT.svs.initialized)
            {
                // cause any connected clients to reconnect
                SV_MAIN.SV_Shutdown("Server restarted\n", true);
            }
            else
            {
                // make sure the client is down
                Cl.Drop();
                SCR.BeginLoadingPlaque();
            }

            // get any latched variable changes (maxclients, etc)
            Cvar.GetLatchedVars();

            SV_INIT.svs.initialized = true;

            if (Cvar.VariableValue("coop") != 0 && Cvar.VariableValue("deathmatch") != 0)
            {
                Com.Printf("Deathmatch and Coop both set, disabling Coop\n");
                Cvar.FullSet("coop", "0", Defines.CVAR_SERVERINFO | Defines.CVAR_LATCH);
            }

            // dedicated servers are can't be single player and are usually DM
            // so unless they explicity set coop, force it to deathmatch
            if (Globals.dedicated.value != 0)
            {
                if (0 == Cvar.VariableValue("coop"))
                {
                    Cvar.FullSet("deathmatch", "1", Defines.CVAR_SERVERINFO | Defines.CVAR_LATCH);
                }
            }

            // init clients
            if (Cvar.VariableValue("deathmatch") != 0)
            {
                if (SV_MAIN.maxclients.value <= 1)
                {
                    Cvar.FullSet("maxclients", "8", Defines.CVAR_SERVERINFO | Defines.CVAR_LATCH);
                }
                else if (SV_MAIN.maxclients.value > Defines.MAX_CLIENTS)
                {
                    Cvar.FullSet("maxclients", "" + Defines.MAX_CLIENTS, Defines.CVAR_SERVERINFO | Defines.CVAR_LATCH);
                }
            }
            else if (Cvar.VariableValue("coop") != 0)
            {
                if (SV_MAIN.maxclients.value <= 1 || SV_MAIN.maxclients.value > 4)
                {
                    Cvar.FullSet("maxclients", "4", Defines.CVAR_SERVERINFO | Defines.CVAR_LATCH);
                }
            }
            else             // non-deathmatch, non-coop is one player
            {
                Cvar.FullSet("maxclients", "1", Defines.CVAR_SERVERINFO | Defines.CVAR_LATCH);
            }

            SV_INIT.svs.spawncount = Lib.rand();
            SV_INIT.svs.clients    = new client_t[(int)SV_MAIN.maxclients.value];

            for (var n = 0; n < SV_INIT.svs.clients.Length; n++)
            {
                SV_INIT.svs.clients[n]             = new();
                SV_INIT.svs.clients[n].serverindex = n;
            }

            SV_INIT.svs.num_client_entities = (int)SV_MAIN.maxclients.value * Defines.UPDATE_BACKUP * 64;             //ok.

            SV_INIT.svs.client_entities = new entity_state_t[SV_INIT.svs.num_client_entities];

            for (var n = 0; n < SV_INIT.svs.client_entities.Length; n++)
            {
                SV_INIT.svs.client_entities[n] = new(null);
            }

            // init network stuff
            NET.ConfigServer(SV_MAIN.maxclients.value > 1);

            // heartbeats will always be sent to the id master
            SV_INIT.svs.last_heartbeat = -99999;             // send immediately
            idmaster = "192.246.40.37:" + Defines.PORT_MASTER;
            NET.StringToAdr(idmaster, SV_MAIN.master_adr[0]);

            // init game
            SV_GAME.SV_InitGameProgs();

            for (i = 0; i < SV_MAIN.maxclients.value; i++)
            {
                ent = GameBase.g_edicts[i + 1];
                SV_INIT.svs.clients[i].edict   = ent;
                SV_INIT.svs.clients[i].lastcmd = new();
            }
        }