Example #1
0
        public static void Error(int code, string fmt, params object[] vargs)
        {
            // va_list argptr;
            // static char msg[MAXPRINTMSG];

            if (Com.recursive)
            {
                Sys.Error("recursive error after: " + Com.msg);
            }

            Com.recursive = true;

            Com.msg = Com.sprintf(fmt, vargs);

            if (code == Defines.ERR_DISCONNECT)
            {
                Cl.Drop();
                Com.recursive = false;

                return;
            }

            if (code == Defines.ERR_DROP)
            {
                Com.Printf("********************\nERROR: " + Com.msg + "\n********************\n");
                SV_MAIN.SV_Shutdown("Server crashed: " + Com.msg + "\n", false);
                Cl.Drop();
                Com.recursive = false;

                return;
            }

            SV_MAIN.SV_Shutdown("Server fatal crashed: %s" + Com.msg + "\n", false);
            Cl.Shutdown();

            Sys.Error(Com.msg);
        }
Example #2
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();
            }
        }