summaryrefslogtreecommitdiff
path: root/src/qcommon/cvar.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/qcommon/cvar.c')
-rw-r--r--src/qcommon/cvar.c53
1 files changed, 51 insertions, 2 deletions
diff --git a/src/qcommon/cvar.c b/src/qcommon/cvar.c
index b0a21506..8db30e6a 100644
--- a/src/qcommon/cvar.c
+++ b/src/qcommon/cvar.c
@@ -364,6 +364,18 @@ cvar_t *Cvar_Get( const char *var_name, const char *var_value, int flags ) {
flags &= ~CVAR_VM_CREATED;
}
+ // Make sure servers cannot mark engine-added variables as SERVER_CREATED
+ if(var->flags & CVAR_SERVER_CREATED)
+ {
+ if(!(flags & CVAR_SERVER_CREATED))
+ var->flags &= ~CVAR_SERVER_CREATED;
+ }
+ else
+ {
+ if(flags & CVAR_SERVER_CREATED)
+ flags &= ~CVAR_SERVER_CREATED;
+ }
+
var->flags |= flags;
// only allow one non-empty reset string without a warning
@@ -613,6 +625,28 @@ void Cvar_Set( const char *var_name, const char *value) {
/*
============
+Cvar_SetSafe
+============
+*/
+void Cvar_SetSafe( const char *var_name, const char *value )
+{
+ int flags = Cvar_Flags( var_name );
+
+ if( flags != CVAR_NONEXISTENT && flags & CVAR_PROTECTED )
+ {
+ if( value )
+ Com_Error( ERR_DROP, "Restricted source tried to set "
+ "\"%s\" to \"%s\"\n", var_name, value );
+ else
+ Com_Error( ERR_DROP, "Restricted source tried to "
+ "modify \"%s\"\n", var_name );
+ return;
+ }
+ Cvar_Set( var_name, value );
+}
+
+/*
+============
Cvar_SetLatched
============
*/
@@ -636,6 +670,21 @@ void Cvar_SetValue( const char *var_name, float value) {
Cvar_Set (var_name, val);
}
+/*
+============
+Cvar_SetValueSafe
+============
+*/
+void Cvar_SetValueSafe( const char *var_name, float value )
+{
+ char val[32];
+
+ if( Q_isintegral( value ) )
+ Com_sprintf( val, sizeof(val), "%i", (int)value );
+ else
+ Com_sprintf( val, sizeof(val), "%f", value );
+ Cvar_SetSafe( var_name, val );
+}
/*
============
@@ -1211,9 +1260,9 @@ void Cvar_Update( vmCvar_t *vmCvar ) {
}
vmCvar->modificationCount = cv->modificationCount;
if ( strlen(cv->string)+1 > MAX_CVAR_VALUE_STRING )
- Com_Error( ERR_DROP, "Cvar_Update: src %s length %zd exceeds MAX_CVAR_VALUE_STRING",
+ Com_Error( ERR_DROP, "Cvar_Update: src %s length %u exceeds MAX_CVAR_VALUE_STRING",
cv->string,
- strlen(cv->string));
+ (unsigned int) strlen(cv->string));
Q_strncpyz( vmCvar->string, cv->string, MAX_CVAR_VALUE_STRING );
vmCvar->value = cv->value;