示例#1
0
文件: Game.cs 项目: maesse/CubeHags
 public Game()
 {
     spawns  = new spawn_t[] {
         new spawn_t{Name = "info_player_start", Spawn = new SpawnDelegate(SP_info_player_start)},
         new spawn_t{Name = "info_ladder", Spawn = new SpawnDelegate(SP_info_ladder)}
     };
     sv_gravity = CVars.Instance.Get("sv_gravity", "800", CVarFlags.SERVER_INFO);
     sv_speed = CVars.Instance.Get("sv_speed", "320", CVarFlags.SERVER_INFO);
     g_synchrounousClients = CVars.Instance.Get("g_synchrounousClients", "0", CVarFlags.SERVER_INFO);
     g_forcerespawn = CVars.Instance.Get("g_forcerespawn", "20", CVarFlags.NONE);
     g_smoothClients = CVars.Instance.Get("g_smoothClients", "0", CVarFlags.SERVER_INFO);
     g_gametype = CVars.Instance.Get("g_gametype", "0", CVarFlags.SERVER_INFO | CVarFlags.LATCH | CVarFlags.USER_INFO);
     g_teamAutoJoin = CVars.Instance.Get("g_teamAutoJoin", "0", CVarFlags.ARCHIVE);
     g_maxGameClients = CVars.Instance.Get("g_maxGameClients", "0", CVarFlags.SERVER_INFO | CVarFlags.ARCHIVE | CVarFlags.LATCH);
     g_edgefriction = CVars.Instance.Get("g_edgefriction", "2", CVarFlags.SERVER_CREATED);
 }
示例#2
0
文件: CVars.cs 项目: maesse/CubeHags
        public static string Validate(CVar var, string value, bool warn)
        {
            if (!var.Validate)
                return value;

            if (value.Equals("") || value == null)
                return value;

            float valuef;
            bool changed = false;
            if(float.TryParse(value, out valuef))
            {
                if (var.Integral)
                {
                    if (valuef != (int)valuef)
                    {
                        if (warn)
                            System.Console.Write("WARNING: cvar '{0}' must be integral", var.Name);

                        valuef = (int)valuef;
                        changed = true;
                    }
                }
            }
            else
            {
                if (warn)
                    System.Console.Write("WARNING: cvar '{0}' must be numeric", var.Name);

                valuef = float.Parse(var.ResetString);
                changed = true;
            }

            if (valuef < var.min)
            {
                if (warn)
                {
                    if (changed)
                        System.Console.Write(" and is");
                    else
                        System.Console.Write("WARNING: cvar '{0}'", var.Name);

                    System.Console.Write(" out of range (min {0})", var.min);
                }
                valuef = var.min;
                changed = true;
            }
            else if (valuef > var.max)
            {
                if (warn)
                {
                    if (changed)
                        System.Console.Write(" and is");
                    else
                        System.Console.Write("WARNING: cvar '{0}'", var.Name);

                    System.Console.Write(" out of range (max {0})", var.max);
                }
                valuef = var.max;
                changed = true;
            }

            if (changed)
            {
                if (warn)
                    System.Console.WriteLine(", setting to {0}", value);

                return "" + valuef;
            }

            return value;
        }
示例#3
0
文件: CVars.cs 项目: maesse/CubeHags
 public void Unset(CVar var)
 {
     // remove from dictionary
     if (vars.ContainsKey(var.Name))
         vars.Remove(var.Name);
 }
示例#4
0
文件: CVars.cs 项目: maesse/CubeHags
        /*
        ============
        Cvar_Print

        Prints the value, default, and latched string of the given variable
        ============
        */
        public void Print(CVar var)
        {
            Common.Instance.Write("\"{0}\" is \"{1}\"^7", var.Name, var.String);
            if ((var.Flags & CVarFlags.ROM) != CVarFlags.ROM)
            {
                if (var.String.Equals(var.ResetString))
                    Common.Instance.Write(", the default");
                else
                    Common.Instance.Write(" default: \"{0}\"^7", var.ResetString);
            }

            Common.Instance.Write("\n");
            if (var.LatchedString != null)
                Common.Instance.WriteLine("latched: \"{0}\"^7", var.LatchedString);
        }
示例#5
0
文件: CVars.cs 项目: maesse/CubeHags
        // Gets a cvar. If it doesn't exist, it will be created
        public CVar Get(string name, string value, CVarFlags flags)
        {
            if (name == null || value == null || name.Equals(""))
            {
                System.Console.WriteLine("FATAL: CVar Get w/ null arguments");
                return null;
            }

            if (!ValidateString(name))
            {
                System.Console.WriteLine("Invalid cvar name string: {0}", name);
                name = "BADNAME";
            }

            CVar nvar = FindVar(name);

            if (nvar != null)
            {
                CVar var = nvar;
                value = Validate(var, value, false);

                // if the C code is now specifying a variable that the user already
                // set a value for, take the new value as the reset value
                if((var.Flags & CVarFlags.USER_CREATED) == CVarFlags.USER_CREATED)
                {
                    var.Flags &= ~CVarFlags.USER_CREATED;
                    var.ResetString = value;

                    if ((flags & CVarFlags.ROM) == CVarFlags.ROM)
                    {
                        // this variable was set by the user,
                        // so force it to value given by the engine.

                        var.LatchedString = value;
                    }
                }

                var.Flags = flags;

                // only allow one non-empty reset string without a warning
                if (var.ResetString == null || var.ResetString.Equals(""))
                    var.ResetString = value;
                else if (!value.Equals("") && value.Equals(var.ResetString))
                {

                }

                // if we have a latched string, take that value now
                if (var.LatchedString != null)
                {
                    string s = var.LatchedString;
                    var.LatchedString = null;
                    Set(name, s);
                }

                // ZOID--needs to be set so that cvars the game sets as
                // SERVERINFO get sent to clients
                modifiedFlags |= flags;

                return var;
            }

            //
            // allocate a new cvar
            //

            CVar cvar = new CVar();
            cvar.Name = name;
            cvar.String = value;
            cvar.Modified = true;
            cvar.ModificationCount = 1;
            float val;
            int val2;
            if(float.TryParse(value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out val))
                cvar.Value = val;
            if (int.TryParse(value, out val2))
            {
                cvar.Integer = val2;
                cvar.Integral = true;
            }
            cvar.ResetString = value;
            cvar.Validate = false;
            cvar.Flags = flags;
            // note what types of cvars have been modified (userinfo, archive, serverinfo, systeminfo)
            modifiedFlags |= cvar.Flags;

            vars.Add(name, cvar);

            return cvar;
        }
示例#6
0
文件: CVars.cs 项目: maesse/CubeHags
        // Applies a (permanent until changed) range-check on a cvar.
        public void CheckRange(CVar var, float min, float max, bool integral)
        {
            var.Validate = true;
            var.min = min;
            var.max = max;
            var.Integral = integral;

            // Force initial range check
            Set(var.Name, var.String);
        }
示例#7
0
文件: Net.cs 项目: maesse/CubeHags
        bool GetCvars()
        {
            bool modified = false;
            net_enabled = CVars.Instance.Get("net_enabled", "1", CVarFlags.ARCHIVE | CVarFlags.LATCH);
            modified = net_enabled.Modified;
            net_enabled.Modified = false;

            net_ip = CVars.Instance.Get("net_ip", "127.0.0.1", CVarFlags.LATCH);
            if (net_ip.Modified)
            {
                modified = true;
                net_ip.Modified = false;
            }

            net_port = CVars.Instance.Get("net_port", "27960", CVarFlags.LATCH);
            if (net_port.Modified)
            {
                modified = true;
                net_port.Modified = false;
            }

            return modified;
        }
示例#8
0
文件: Game.cs 项目: maesse/CubeHags
        public void Init(float levelTime, int randSeed, int restart)
        {
            LogPrintf("----- Game Initialization -----");

            g_cheats = CVars.Instance.Get("g_cheats", "", CVarFlags.NONE);

            level.time = levelTime;
            level.startTime = levelTime;
            level.newSession = true;

            // initialize all entities for this game
            g_entities = new gentity_t[1024];
            level.sentities = new sharedEntity[1024];
            for (int i = 0; i < 1024; i++)
            {
                g_entities[i] = (new gentity_t());
                level.sentities[i] = g_entities[i].shEnt;
            }
            level.gentities = g_entities;

            // initialize all clients for this game
            level.maxclients = 32;
            g_clients = new gclient_t[64];
            for (int i = 0; i < level.maxclients; i++)
            {
                g_clients[i] = (new gclient_t());
            }
            level.clients = g_clients;

            // set client fields on player ents
            for (int i = 0; i < level.maxclients; i++)
            {
                gentity_t ent = g_entities[i];
                ent.s.number = i;
                ent.s.clientNum = i;
                ent.client = level.clients[i];
            }

            // always leave room for the max number of clients,
            // even if they aren't all used, so numbers inside that
            // range are NEVER anything but clients
            level.num_entities = 64;

            Server.Instance.LocateGameData(level.sentities, level.num_entities, level.clients);

            SpawnEntitiesFromString();

            FindTeams();
        }
示例#9
0
文件: Server.cs 项目: maesse/CubeHags
        public void Init()
        {
            AddOperatorCommands();

            sv_fps = CVars.Instance.Get("sv_fps", "100", CVarFlags.TEMP);
            sv_timeout = CVars.Instance.Get("sv_timeout", "200", CVarFlags.TEMP);
            sv_hostname = CVars.Instance.Get("sv_hostname", "noname", CVarFlags.SERVER_INFO | CVarFlags.ARCHIVE);
            sv_mapname = CVars.Instance.Get("mapname", "nomap", CVarFlags.SERVER_INFO | CVarFlags.ARCHIVE);
            CVars.Instance.Get("nextmap", "", CVarFlags.TEMP);
            sv_mapChecksum = CVars.Instance.Get("sv_mapChecksum", "", CVarFlags.ROM);
            sv_maxclients = CVars.Instance.Get("sv_maxclients", "32", CVarFlags.SERVER_INFO | CVarFlags.LATCH);
            sv_zombietime = CVars.Instance.Get("sv_zombietime", "2", CVarFlags.TEMP);
            sv_killserver = CVars.Instance.Get("sv_killserver", "0", CVarFlags.TEMP);
            sv_reconnectlimit = CVars.Instance.Get("sv_reconnectlimit", "3", CVarFlags.SERVER_INFO | CVarFlags.ARCHIVE);
            sv_minping = CVars.Instance.Get("sv_minping", "0", CVarFlags.ARCHIVE | CVarFlags.SERVER_INFO);
            sv_maxping = CVars.Instance.Get("sv_maxping", "0", CVarFlags.ARCHIVE | CVarFlags.SERVER_INFO);
            sv_minrate = CVars.Instance.Get("sv_minrate", "0", CVarFlags.ARCHIVE | CVarFlags.SERVER_INFO);
            sv_maxrate = CVars.Instance.Get("sv_maxrate", "0", CVarFlags.ARCHIVE | CVarFlags.SERVER_INFO);
            CVars.Instance.Get("sv_serverid", "0", CVarFlags.SERVER_INFO | CVarFlags.ROM);
        }
示例#10
0
文件: Common.cs 项目: maesse/CubeHags
        public void Init(string commandline)
        {
            System.Console.WriteLine("Cubehags os:{0} cpus:{1}", Environment.OSVersion, Environment.ProcessorCount);
            FileStream stream;
            try
            {
                Directory.CreateDirectory("log");
                stream = File.Create("log/cubehagslog.txt");
            }
            catch (Exception ex)
            {
                stream = File.Create("log/cubelog" + new Random().Next(99999) + ".txt");
            }
            logWriter = new StreamWriter(stream);
            CVars.Instance.Init();

            // prepare enough of the subsystems to handle
            // cvar and command buffer management
            ParseCommandLine(commandline);

            // done early so bind command exists
            KeyHags.Instance.Init();
            FileCache.Instance.Init();
            Commands.Instance.AddCommand("quit", new CommandDelegate(Quit_f));
            Commands.Instance.AddCommand("exit", new CommandDelegate(Quit_f));

            ExecuteCfg();

            // if any archived cvars are modified after this, we will trigger a writing
            // of the config file
            CVars.Instance.modifiedFlags &= ~CVarFlags.ARCHIVE;

            //
            // init commands and vars
            //
            maxfps = CVars.Instance.Get("maxfps", "300", CVarFlags.ARCHIVE);
            logfile = CVars.Instance.Get("logfile", "0", CVarFlags.TEMP);
            cl_running = CVars.Instance.Get("cl_running", "0", CVarFlags.ROM);
            sv_running = CVars.Instance.Get("sv_running", "0", CVarFlags.ROM);
            timescale = CVars.Instance.Get("timescale", "1", CVarFlags.TEMP);

            Server.Instance.Init();
            Client.Instance.Init();

            // set com_frameTime so that if a map is started on the
            // command line it will still be able to count on com_frameTime
            // being random enough for a serverid
            frameTime = (int)Milliseconds();

            // add + commands from command line
            Commands.Instance.AddText("toggleui;");
            Commands.Instance.Execute();
            if (!AddStartupCommands())
            {
                // if the user didn't give any commands, run default action -- nothing
            }
        }
示例#11
0
        /*
        =================
        Netchan_Process

        Returns qfalse if the message should not be processed due to being
        out of order or a fragment.

        Msg must be large enough to hold MAX_MSGLEN, because if this is the
        final fragment of a multi-part message, the entire thing will be
        copied out.
        =================
        */
        public bool NetChan_Process(netchan_t chan, Packet packet)
        {
            // get sequence numbers
            int sequence = packet.Buffer.ReadInt32();

            // check for fragment information
            bool fragmented = false;
            if ((sequence & (1 << 31)) == (1 << 31))
            {
                sequence &= ~(1 << 31);
                fragmented = true;
            }

            // read the qport if we are a server
            int qport;
            if (chan.sock == NetSource.SERVER)
            {
                qport = packet.Buffer.ReadInt16();
            }

            // read the fragment information
            int fragStart = 0, fragEnd = 0;
            if (fragmented)
            {
                fragStart = packet.Buffer.ReadInt16();
                fragEnd = packet.Buffer.ReadInt16();
            }

            //
            // discard out of order or duplicated packets
            //
            if (sequence <= sequence - (chan.incomingSequence + 1))
            {
                Common.Instance.WriteLine("[0}: out of order packetseq {1} at {2}", packet.Address.ToString(), sequence, chan.incomingSequence);
                return false;
            }

            //
            // dropped packets don't keep the message from being used
            //
            chan.dropped = sequence - (chan.incomingSequence + 1);
            if (chan.dropped > 0)
            {
                Common.Instance.WriteLine("{0}: dropped {1} packets at {2}", packet.Address.ToString(), chan.dropped, sequence);
            }

            //
            // if this is the final framgent of a reliable message,
            // bump incoming_reliable_sequence
            //
            if (fragmented)
            {
                Common.Instance.WriteLine("Implement fragmentation");
            }

            //
            // the message can now be read from the current message pointer
            //
            chan.incomingSequence = sequence;
            return true;
        }