예제 #1
0
        /**
         * Any variables with latched values will be updated.
         */
        public static void GetLatchedVars()
        {
            cvar_t var;

            for (var = Globals.cvar_vars; var != null; var = var.next)
            {
                if (var.latched_string == null || var.latched_string.Length == 0)
                {
                    continue;
                }

                var.@string        = var.latched_string;
                var.latched_string = null;
                var.value          = Lib.atof(var.@string);

                if (var.name.Equals("game"))
                {
                    FS.SetGamedir(var.@string);
                    FS.ExecAutoexec();
                }
            }
        }
예제 #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);
        }