Exemplo n.º 1
0
        /**
         * @param var_name
         * @param var_value
         * @param flags
         * @return
         */
        public static cvar_t Get(string var_name, string var_value, int flags)
        {
            cvar_t var;

            if ((flags & (Defines.CVAR_USERINFO | Defines.CVAR_SERVERINFO)) != 0)
            {
                if (!Cvar.InfoValidate(var_name))
                {
                    Com.Printf("invalid info cvar name\n");

                    return(null);
                }
            }

            var = Cvar.FindVar(var_name);

            if (var != null)
            {
                var.flags |= flags;

                return(var);
            }

            if (var_value == null)
            {
                return(null);
            }

            if ((flags & (Defines.CVAR_USERINFO | Defines.CVAR_SERVERINFO)) != 0)
            {
                if (!Cvar.InfoValidate(var_value))
                {
                    Com.Printf("invalid info cvar value\n");

                    return(null);
                }
            }

            var          = new();
            var.name     = new(var_name);
            var.@string  = new(var_value);
            var.modified = true;
            var.value    = Lib.atof(var.@string);

            // link the variable in
            var.next          = Globals.cvar_vars;
            Globals.cvar_vars = var;

            var.flags = flags;

            return(var);
        }
Exemplo n.º 2
0
        /**
         * Gereric set function, sets the value of the variable, with forcing its even possible to
         * override the variables write protection.
         */
        private static cvar_t Set2(string var_name, string value, bool force)
        {
            var var = Cvar.FindVar(var_name);

            if (var == null)
            {
                // create it
                return(Cvar.Get(var_name, value, 0));
            }

            if ((var.flags & (Defines.CVAR_USERINFO | Defines.CVAR_SERVERINFO)) != 0)
            {
                if (!Cvar.InfoValidate(value))
                {
                    Com.Printf("invalid info cvar value\n");

                    return(var);
                }
            }

            if (!force)
            {
                if ((var.flags & Defines.CVAR_NOSET) != 0)
                {
                    Com.Printf(var_name + " is write protected.\n");

                    return(var);
                }

                if ((var.flags & Defines.CVAR_LATCH) != 0)
                {
                    if (var.latched_string != null)
                    {
                        if (value.Equals(var.latched_string))
                        {
                            return(var);
                        }

                        var.latched_string = null;
                    }
                    else
                    {
                        if (value.Equals(var.@string))
                        {
                            return(var);
                        }
                    }

                    if (Globals.server_state != 0)
                    {
                        Com.Printf(var_name + " will be changed for next game.\n");
                        var.latched_string = value;
                    }
                    else
                    {
                        var.@string = value;
                        var.value   = Lib.atof(var.@string);

                        if (var.name.Equals("game"))
                        {
                            FS.SetGamedir(var.@string);
                            FS.ExecAutoexec();
                        }
                    }

                    return(var);
                }
            }
            else
            {
                if (var.latched_string != null)
                {
                    var.latched_string = null;
                }
            }

            if (value.Equals(var.@string))
            {
                return(var);                // not changed
            }
            var.modified = true;

            if ((var.flags & Defines.CVAR_USERINFO) != 0)
            {
                Globals.userinfo_modified = true;                 // transmit at next oportunity
            }
            var.@string = value;

            try
            {
                var.value = float.Parse(var.@string, CultureInfo.InvariantCulture);
            }
            catch (Exception)
            {
                var.value = 0.0f;
            }

            return(var);
        }