当前位置: 首页>>代码示例>>C++>>正文


C++ Cvar_ValidateString函数代码示例

本文整理汇总了C++中Cvar_ValidateString函数的典型用法代码示例。如果您正苦于以下问题:C++ Cvar_ValidateString函数的具体用法?C++ Cvar_ValidateString怎么用?C++ Cvar_ValidateString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Cvar_ValidateString函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GScr_SetCvar

void GScr_SetCvar()
{
  const char *newstringval;
  const char *var_name;
  char buffer[1024];
  mvabuf;


  var_name = Scr_GetString(0);
  if ( Scr_GetType(1) == 3 )
  {
    Scr_ConstructMessageString(1, Scr_GetNumParam() - 1, "Dvar Value", buffer, 0x400u);
    newstringval = buffer;
  }
  else
  {
    newstringval = Scr_GetString(1);
  }
  if (Cvar_ValidateString(var_name) )
  {
    Cvar_SetAllowCheatOnly(var_name, newstringval);
    if ( Scr_GetNumParam() > 2 && Scr_GetInt(2) )
    {
      Cvar_AddFlagsByName(var_name, 0x400u);
    }
  }
  else
  {
    Scr_Error(va("Cvar %s has an invalid cvar name", var_name));
  }
}
开发者ID:crazy28,项目名称:CoD4X17a_testing,代码行数:31,代码来源:scr_vm_functions.c

示例2: CopyString

/*
============
Cvar_SetDefault

Change default value of a cvar, or create if it doesn't exist
============
*/
cvar_t *Cvar_SetDefault( const char *var_name, const char *var_value ) {
	cvar_t *var;

	if ( !Cvar_ValidateString( var_name ) ) {
		Com_Printf("invalid cvar name string: %s\n", var_name );
		var_name = "BADNAME";
	}

	var = Cvar_FindVar (var_name);

	if(var)
	{
		var_value = Cvar_Validate(var, var_value, qfalse);

		// if not explicitly set, change value
		if(!var->explicitSet)
		{
			Cvar_SetSafe( var_name, var_value );
			var->explicitSet = qfalse;
		}

		if (!strcmp(var->resetString,var_value))
			return var;

		var->overriddenResetString = var->resetString;
		var->resetString = CopyString( var_value );

		var->flags |= CVAR_CUSTOM_RESET;
	}
	else
	{
		var = Cvar_Get( var_name, var_value, CVAR_CUSTOM_RESET );
	}

	return var;
}
开发者ID:DaneTheory,项目名称:spearmint,代码行数:43,代码来源:cvar.c

示例3: Cvar_SetIFlag

/*
============
Cvar_SetIFlag

Sets the cvar by the name that begins with a backslash to "1".  This creates a
cvar that can be set by the engine but not by the sure, and can be read by
interpreted modules.
============
*/
void Cvar_SetIFlag( const char *var_name )
{
    cvar_t *var;
    long hash;
    int index;

    if ( !var_name ) {
        Com_Error( ERR_FATAL, "Cvar_SetIFlag: NULL parameter" );
    }

    if ( *var_name != '\\' ) {
        Com_Error( ERR_FATAL, "Cvar_SetIFlag: var_name must begin with a '\\'" );
    }

    /*
    if ( Cvar_FindVar( var_name ) ) {
    	Com_Error( ERR_FATAL, "Cvar_SetIFlag: %s already exists.", var_name );
    }
    */

    if ( !Cvar_ValidateString( var_name + 1 ) ) {
        Com_Printf( "invalid cvar name string: %s\n", var_name );
        var_name = "BADNAME";
    }

    // find a free cvar
    for(index = 0; index < MAX_CVARS; index++)
    {
        if(!cvar_indexes[index].name)
            break;
    }

    if(index >= MAX_CVARS)
    {
        if(!com_errorEntered)
            Com_Error(ERR_FATAL, "Error: Too many cvars, cannot create a new one!");

        return;
    }

    var = &cvar_indexes[index];

    if(index >= cvar_numIndexes)
        cvar_numIndexes = index + 1;

    var->name = CopyString (var_name);
    var->string = CopyString ("1");
    var->modified = qtrue;
    var->modificationCount = 1;
    var->value = atof (var->string);
    var->integer = atoi(var->string);
    var->resetString = CopyString( "1" );
    var->validate = qfalse;

    // link the variable in
    var->next = cvar_vars;

    cvar_vars = var;

    var->flags = CVAR_INIT;
    // note what types of cvars have been modified (userinfo, archive, serverinfo, systeminfo)
    cvar_modifiedFlags |= var->flags;

    hash = generateHashValue(var_name);

    var->hashNext = hashTable[hash];

    hashTable[hash] = var;
}
开发者ID:AlienHoboken,项目名称:Unvanquished,代码行数:78,代码来源:cvar.c

示例4: Com_DPrintf

cvar_t         *Cvar_Set2( const char *var_name, const char *value, qboolean force )
{
    cvar_t *var;

#if 0

    if ( strcmp( "com_hunkused", var_name ) != 0 )
    {
        Com_DPrintf( "Cvar_Set2: %s %s\n", var_name, value );
    }

#endif

    if ( !Cvar_ValidateString( var_name ) )
    {
        Com_Printf( "invalid cvar name string: %s\n", var_name );
        var_name = "BADNAME";
    }

    var = Cvar_FindVar( var_name );

    if ( !var )
    {
        if ( !value )
        {
            return NULL;
        }

        // create it
        if ( !force )
        {
            var = Cvar_Get( var_name, value, CVAR_USER_CREATED );
        }
        else
        {
            var = Cvar_Get( var_name, value, 0 );
        }
        var->modificationCount++;
        var->transient = qfalse;
        return var;
    }

    var->transient = qfalse;

    if ( !value )
    {
        value = var->resetString;

        /* make sure we remove ARCHIVE cvars from the autogen if reset */
        if( var->flags & CVAR_ARCHIVE )
        {
            var->transient = qtrue;
            cvar_modifiedFlags |= CVAR_ARCHIVE;
        }
    }

    if ( var->flags & CVAR_USERINFO )
    {
        const char *cleaned = Com_ClearForeignCharacters( value );

        if ( strcmp( value, cleaned ) )
        {
            Com_Printf( FOREIGN_MSG );
            Com_Printf(_( "Using %s instead of %s\n"), cleaned, value );
            return Cvar_Set2( var_name, cleaned, force );
        }
    }

    if ( !strcmp( value, var->string ) )
    {
        if ( ( var->flags & CVAR_LATCH ) && var->latchedString )
        {
            if ( !strcmp( value, var->latchedString ) )
            {
                return var;
            }
        }
        else
        {
            return var;
        }
    }

    // note what types of cvars have been modified (userinfo, archive, serverinfo, systeminfo)
    cvar_modifiedFlags |= var->flags;

    if ( !force )
    {
        // ydnar: don't set unsafe variables when com_crashed is set
        if ( ( var->flags & CVAR_UNSAFE ) && com_crashed != NULL && com_crashed->integer )
        {
            Com_Printf( _("%s is unsafe. Check com_crashed.\n"), var_name );
            return var;
        }

        if ( var->flags & CVAR_ROM )
        {
            Com_Printf( _("%s is read only.\n"), var_name );
            return var;
        }
//.........这里部分代码省略.........
开发者ID:AlienHoboken,项目名称:Unvanquished,代码行数:101,代码来源:cvar.c

示例5: Com_Error

/*
============
Cvar_Get

If the variable already exists, the value will not be set unless CVAR_ROM
The flags will be or'ed in if the variable exists.
============
*/
cvar_t         *Cvar_Get( const char *var_name, const char *var_value, int flags )
{
    cvar_t *var;
    long   hash;

    if ( !var_name || !var_value )
    {
        Com_Error( ERR_FATAL, "Cvar_Get: NULL parameter" );
    }

    if ( !Cvar_ValidateString( var_name ) )
    {
        Com_Printf( "invalid cvar name string: %s\n", var_name );
        var_name = "BADNAME";
    }

#if 0 // FIXME: values with backslash happen

    if ( !Cvar_ValidateString( var_value ) )
    {
        Com_Printf( "invalid cvar value string: %s\n", var_value );
        var_value = "BADVALUE";
    }

#endif

    var = Cvar_FindVar( var_name );

    if ( var )
    {
        // 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 & CVAR_USER_CREATED ) && !( flags & CVAR_USER_CREATED ) && var_value[ 0 ] )
        {
            var->flags &= ~CVAR_USER_CREATED;
            Z_Free( var->resetString );
            var->resetString = CopyString( var_value );

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

                if ( var->latchedString )
                {
                    Z_Free( var->latchedString );
                }

                var->latchedString = CopyString( var_value );
            }

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

        var->flags |= flags;

        // only allow one non-empty reset string without a warning
        if ( !var->resetString[ 0 ] )
        {
            // we don't have a reset string yet
            Z_Free( var->resetString );
            var->resetString = CopyString( var_value );
        }
        else if ( var_value[ 0 ] && strcmp( var->resetString, var_value ) )
        {
            Com_DPrintf( "Warning: cvar \"%s\" given initial values: \"%s\" and \"%s\"\n", var_name, var->resetString, var_value );
        }

        // if we have a latched string, take that value now
        if ( var->latchedString )
        {
            char *s;

            s = var->latchedString;
            var->latchedString = NULL; // otherwise cvar_set2 would free it
            Cvar_Set2( var_name, s, qtrue );
            Z_Free( s );
        }

        // TTimo
        // if CVAR_USERINFO was toggled on for an existing cvar, check whether the value needs to be cleaned from foreign characters
        // (for instance, seta name "name-with-foreign-chars" in the config file, and toggle to CVAR_USERINFO happens later in CL_Init)
        if ( flags & CVAR_USERINFO )
        {
            const char *cleaned = Com_ClearForeignCharacters( var->string );  // NOTE: it is probably harmless to call Cvar_Set2 in all cases, but I don't want to risk it

            if ( strcmp( var->string, cleaned ) )
            {
                Cvar_Set2( var->name, var->string, qfalse );  // call Cvar_Set2 with the value to be cleaned up for verbosity
            }
//.........这里部分代码省略.........
开发者ID:AlienHoboken,项目名称:Unvanquished,代码行数:101,代码来源:cvar.c

示例6: Com_Printf

/*
============
Cvar_Set2
============
*/
cvar_t *Cvar_Set2( const char *var_name, const char *value, qboolean force ) {
	cvar_t	*var;

//	Com_DPrintf( "Cvar_Set2: %s %s\n", var_name, value );

	if ( !Cvar_ValidateString( var_name ) ) {
		Com_Printf("invalid cvar name string: %s\n", var_name );
		var_name = "BADNAME";
	}

#if 0	// FIXME
	if ( value && !Cvar_ValidateString( value ) ) {
		Com_Printf("invalid cvar value string: %s\n", value );
		var_value = "BADVALUE";
	}
#endif

	var = Cvar_FindVar (var_name);
	if (!var) {
		if ( !value ) {
			return NULL;
		}
		// create it
		if ( !force ) {
			return Cvar_Get( var_name, value, CVAR_USER_CREATED );
		} else {
			return Cvar_Get (var_name, value, 0);
		}
	}

	if (!value ) {
		value = var->resetString;
	}

	if((var->flags & CVAR_LATCH) && var->latchedString) {
		if(!strcmp(value,var->latchedString))
			return var;
	}
	else if (!strcmp(value,var->string)) {
		return var;
	}
	// note what types of cvars have been modified (userinfo, archive, serverinfo, systeminfo)
	cvar_modifiedFlags |= var->flags;

	if (!force)
	{
		if (var->flags & CVAR_ROM)
		{
			Com_Printf ("%s is read only.\n", var_name);
			return var;
		}

		if (var->flags & CVAR_INIT)
		{
			Com_Printf ("%s is write protected.\n", var_name);
			return var;
		}

		if (var->flags & CVAR_LATCH)
		{
			if (var->latchedString)
			{
				if (strcmp(value, var->latchedString) == 0)
					return var;
				Z_Free (var->latchedString);
			}
			else
			{
				if (strcmp(value, var->string) == 0)
					return var;
			}

			Com_Printf ("%s will be changed upon restarting.\n", var_name);
			var->latchedString = CopyString(value);
			var->modified = qtrue;
			var->modificationCount++;
			return var;
		}

		if ( (var->flags & CVAR_CHEAT) && !cvar_cheats->integer )
		{
			Com_Printf ("%s is cheat protected.\n", var_name);
			return var;
		}

	}
	else
	{
		if (var->latchedString)
		{
			Z_Free (var->latchedString);
			var->latchedString = NULL;
		}
	}

//.........这里部分代码省略.........
开发者ID:ZdrytchX,项目名称:Lolards,代码行数:101,代码来源:cvar.c

示例7: Com_Error

/*
============
Cvar_Get

If the variable already exists, the value will not be set unless CVAR_ROM
The flags will be or'ed in if the variable exists.
============
*/
cvar_t *Cvar_Get( const char *var_name, const char *var_value, int flags ) {
	cvar_t	*var;
	long	hash;

  if ( !var_name || ! var_value ) {
		Com_Error( ERR_FATAL, "Cvar_Get: NULL parameter" );
  }

	if ( !Cvar_ValidateString( var_name ) ) {
		Com_Printf("invalid cvar name string: %s\n", var_name );
		var_name = "BADNAME";
	}

#if 0		// FIXME: values with backslash happen
	if ( !Cvar_ValidateString( var_value ) ) {
		Com_Printf("invalid cvar value string: %s\n", var_value );
		var_value = "BADVALUE";
	}
#endif

	var = Cvar_FindVar (var_name);
	if ( var ) {
		// 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 & CVAR_USER_CREATED ) && !( flags & CVAR_USER_CREATED )
			&& var_value[0] ) {
			var->flags &= ~CVAR_USER_CREATED;
			Z_Free( var->resetString );
			var->resetString = CopyString( var_value );

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

		var->flags |= flags;
		// only allow one non-empty reset string without a warning
		if ( !var->resetString[0] ) {
			// we don't have a reset string yet
			Z_Free( var->resetString );
			var->resetString = CopyString( var_value );
		} else if ( var_value[0] && strcmp( var->resetString, var_value ) ) {
			Com_DPrintf( "Warning: cvar \"%s\" given initial values: \"%s\" and \"%s\"\n",
				var_name, var->resetString, var_value );
		}
		// if we have a latched string, take that value now
		if ( var->latchedString ) {
			char *s;

			s = var->latchedString;
			var->latchedString = NULL;	// otherwise cvar_set2 would free it
			Cvar_Set2( var_name, s, qtrue );
			Z_Free( s );
		}

// use a CVAR_SET for rom sets, get won't override
#if 0
		// CVAR_ROM always overrides
		if ( flags & CVAR_ROM ) {
			Cvar_Set2( var_name, var_value, qtrue );
		}
#endif
		return var;
	}

	//
	// allocate a new cvar
	//
	if ( cvar_numIndexes >= MAX_CVARS ) {
		Com_Error( ERR_FATAL, "MAX_CVARS" );
	}
	var = &cvar_indexes[cvar_numIndexes];
	cvar_numIndexes++;
	var->name = CopyString (var_name);
	var->string = CopyString (var_value);
	var->modified = qtrue;
	var->modificationCount = 1;
	var->value = atof (var->string);
	var->integer = atoi(var->string);
	var->resetString = CopyString( var_value );

	// link the variable in
	var->next = cvar_vars;
	cvar_vars = var;

	var->flags = flags;

	hash = generateHashValue(var_name);
	var->hashNext = hashTable[hash];
	hashTable[hash] = var;

	return var;
//.........这里部分代码省略.........
开发者ID:ZdrytchX,项目名称:Lolards,代码行数:101,代码来源:cvar.c

示例8: Com_Error

/*
============
Cvar_Get

If the variable already exists, the value will not be set unless CVAR_ROM
The flags will be or'ed in if the variable exists.
============
*/
cvar_t *Cvar_Get( const char *var_name, const char *var_value, int flags ) {
	cvar_t	*var;
	long	hash;
	int	index;

	if ( !var_name || ! var_value ) {
		Com_Error( ERR_FATAL, "Cvar_Get: NULL parameter" );
	}

	if ( !Cvar_ValidateString( var_name ) ) {
		Com_Printf("invalid cvar name string: %s\n", var_name );
		var_name = "BADNAME";
	}

#if 0		// FIXME: values with backslash happen
	if ( !Cvar_ValidateString( var_value ) ) {
		Com_Printf("invalid cvar value string: %s\n", var_value );
		var_value = "BADVALUE";
	}
#endif

	var = Cvar_FindVar (var_name);
	
	if(var)
	{
		var_value = Cvar_Validate(var, var_value, qfalse);

		// Make sure the game code cannot mark engine-added variables as gamecode vars
		if(var->flags & CVAR_VM_CREATED)
		{
			if(!(flags & CVAR_VM_CREATED))
				var->flags &= ~CVAR_VM_CREATED;
		}
		else if (!(var->flags & CVAR_USER_CREATED))
		{
			if(flags & CVAR_VM_CREATED)
				flags &= ~CVAR_VM_CREATED;
		}

		// 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 & CVAR_USER_CREATED)
		{
			var->flags &= ~CVAR_USER_CREATED;
			Z_Free( var->resetString );
			var->resetString = CopyString( var_value );

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

				if(var->latchedString)
					Z_Free(var->latchedString);
				
				var->latchedString = CopyString(var_value);
			}
		}
		
		// 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
		if ( !var->resetString[0] ) {
			// we don't have a reset string yet
			Z_Free( var->resetString );
			var->resetString = CopyString( var_value );
		} else if ( var_value[0] && strcmp( var->resetString, var_value ) ) {
			Com_DPrintf( "Warning: cvar \"%s\" given initial values: \"%s\" and \"%s\"\n",
				var_name, var->resetString, var_value );
		}
		// if we have a latched string, take that value now
		if ( var->latchedString ) {
			char *s;

			s = var->latchedString;
			var->latchedString = NULL;	// otherwise cvar_set2 would free it
			Cvar_Set2( var_name, s, qtrue );
			Z_Free( s );
		}

//.........这里部分代码省略.........
开发者ID:chrisballinger,项目名称:tremulous,代码行数:101,代码来源:cvar.c

示例9: Com_DPrintf

cvar_t *Cvar_Set2(const char *var_name, const char *value, qboolean force)
{
	cvar_t *var;

	Com_DPrintf("Cvar_Set2: %s %s\n", var_name, value);

	if (!Cvar_ValidateString(var_name))
	{
		Com_Printf("invalid cvar name string: %s\n", var_name);
		var_name = "BADNAME";
	}

	var = Cvar_FindVar(var_name);
	if (!var)
	{
		if (!value)
		{
			return NULL;
		}
		// create it
		if (!force)
		{
			return Cvar_Get(var_name, value, CVAR_USER_CREATED);
		}
		else
		{
			return Cvar_Get(var_name, value, 0);
		}
	}

	if (!value)
	{
		value = var->resetString;
	}

	if (var->flags & CVAR_USERINFO)
	{
		char *cleaned = Cvar_ClearForeignCharacters(value);
		if (strcmp(value, cleaned))
		{
#ifdef DEDICATED
			Com_Printf(FOREIGN_MSG);
#else
			Com_Printf("%s", CL_TranslateStringBuf(FOREIGN_MSG));
#endif
			Com_Printf("Using %s instead of %s\n", cleaned, value);
			return Cvar_Set2(var_name, cleaned, force);
		}
	}

	if (!strcmp(value, var->string))
	{
		if ((var->flags & CVAR_LATCH) && var->latchedString)
		{
			if (!strcmp(value, var->latchedString))
			{
				return var;
			}
		}
		else
		{
			return var;
		}
	}
	// note what types of cvars have been modified (userinfo, archive, serverinfo, systeminfo)
	cvar_modifiedFlags |= var->flags;

	if (!force)
	{
		// don't set unsafe variables when com_crashed is set
		if ((var->flags & CVAR_UNSAFE) && com_crashed != NULL && com_crashed->integer)
		{
			Com_Printf("%s is unsafe. Check com_crashed.\n", var_name);
			return var;
		}

		if (var->flags & CVAR_ROM)
		{
			Com_Printf("%s is read only.\n", var_name);
			return var;
		}

		if (var->flags & CVAR_INIT)
		{
			Com_Printf("%s is write protected.\n", var_name);
			return var;
		}

		if ((var->flags & CVAR_CHEAT) && !cvar_cheats->integer)
		{
			Com_Printf("%s is cheat protected.\n", var_name);
			return var;
		}

		if (var->flags & CVAR_LATCH)
		{
			if (var->latchedString)
			{
				if (strcmp(value, var->latchedString) == 0)
				{
//.........这里部分代码省略.........
开发者ID:vishen,项目名称:etlegacy,代码行数:101,代码来源:cvar.c

示例10: Com_Printf

/*
============
Cvar_Set2
============
*/
cvar_t *Cvar_Set2( const char *var_name, const char *value, int defaultFlags, qboolean force ) {
	cvar_t	*var;

//	Com_DPrintf( "Cvar_Set2: %s %s\n", var_name, value );

	if ( !Cvar_ValidateString( var_name ) ) {
		Com_Printf("invalid cvar name string: %s\n", var_name );
		var_name = "BADNAME";
	}

#if 0	// FIXME
	if ( value && !Cvar_ValidateString( value ) ) {
		Com_Printf("invalid cvar value string: %s\n", value );
		var_value = "BADVALUE";
	}
#endif

	var = Cvar_FindVar (var_name);
	if (!var) {
		if ( !value ) {
			return NULL;
		}
		// create it
		var = Cvar_Get( var_name, value, defaultFlags );
		var->explicitSet = qtrue;
		return var;
	}

	// explicit set state change
	if ( var->explicitSet != ( value != NULL ) ) {
		var->explicitSet = ( value != NULL );

		// update config file even if value hasn't changed
		if ( var->flags & CVAR_ARCHIVE ) {
			cvar_modifiedFlags |= CVAR_ARCHIVE;
		}
	}

	if (!value ) {
		value = var->resetString;
	}

	value = Cvar_Validate(var, value, qtrue);

	if((var->flags & CVAR_LATCH) && var->latchedString)
	{
		if(!strcmp(value, var->string))
		{
			Z_Free(var->latchedString);
			var->latchedString = NULL;
			return var;
		}

		if(!strcmp(value, var->latchedString))
			return var;
	}
	else if(!strcmp(value, var->string))
		return var;

	// note what types of cvars have been modified (userinfo, archive, serverinfo, systeminfo)
	cvar_modifiedFlags |= var->flags;

	if (!force)
	{
		if ( (var->flags & (CVAR_SYSTEMINFO|CVAR_SERVER_CREATED)) && CL_ConnectedToRemoteServer() )
		{
			Com_Printf ("%s can only be set by server.\n", var_name);
			return var;
		}

		if (var->flags & CVAR_ROM)
		{
			Com_Printf ("%s is read only.\n", var_name);
			return var;
		}

		if (var->flags & CVAR_INIT)
		{
			Com_Printf ("%s is write protected.\n", var_name);
			return var;
		}

		if (var->flags & CVAR_LATCH)
		{
			if (var->latchedString)
			{
				if (strcmp(value, var->latchedString) == 0)
					return var;
				Z_Free (var->latchedString);
			}
			else
			{
				if (strcmp(value, var->string) == 0)
					return var;
			}
//.........这里部分代码省略.........
开发者ID:DaneTheory,项目名称:spearmint,代码行数:101,代码来源:cvar.c

示例11: Cvar_Get

/*
============
Cvar_Get

If the variable already exists, the value will not be set unless CVAR_ROM
The flags will be or'ed in if the variable exists.
============
*/
cvar_t* Cvar_Get( const char *var_name, const char *var_value, int flags )
{
	if ( !var_name || !var_value ) {
		Com_Error( ERR_FATAL, "Cvar_Get: NULL parameter" );
	}

	if ( !Cvar_ValidateString( var_name ) ) {
		Com_Printf("invalid cvar name string: %s\n", var_name );
		var_name = "BADNAME";
	}

	cvar_t* var = Cvar_FindVar( var_name );
	if ( var ) {
		// 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 & CVAR_USER_CREATED ) && !( flags & CVAR_USER_CREATED )
			&& var_value[0] ) {
			var->flags &= ~CVAR_USER_CREATED;
			Z_Free( var->resetString );
			var->resetString = CopyString( var_value );
			// needs to be set so that cvars the game tags as SERVERINFO get sent to clients
			cvar_modifiedFlags |= flags;
		}

		var->flags |= flags;
		// only allow one non-empty reset string without a warning
		// KHB 071110  no, that's wrong for several reasons, notably vm changes caused by pure
		if ((flags & CVAR_ROM) || !var->resetString[0]) {
			Z_Free( var->resetString );
			var->resetString = CopyString( var_value );
		} else if ( var_value[0] && strcmp( var->resetString, var_value ) ) {
			Com_DPrintf( "Warning: cvar \"%s\" given initial values: \"%s\" and \"%s\"\n",
				var_name, var->resetString, var_value );
		}

		// if we have a latched string, take that value now
		if ( var->latchedString ) {
			char* s = var->latchedString;
			var->latchedString = NULL;	// otherwise cvar_set2 would free it
			Cvar_Set2( var_name, s, qtrue );
			Z_Free( s );
		}

/* KHB  note that this is #if 0'd in the 132 code, but is actually REQUIRED for correctness
	consider a cgame that sets a CVAR_ROM client version:
	you connect to a v1 server, load the v1 cgame, and set the ROM version to v1
	you then connect to a v2 server and correctly load the v2 cgame, but
	when that registers its GENUINELY "NEW" version var, the value is ignored
	so now you have a CVAR_ROM with the wrong value in it. gg.
i'm preserving this incorrect behavior FOR NOW for compatability, because
game\ai_main.c(1352): trap_Cvar_Register( &mapname, "mapname", "", CVAR_SERVERINFO | CVAR_ROM );
breaks every single mod except CPMA otherwise, but it IS wrong, and critically so
		// CVAR_ROM always overrides
		if (flags & CVAR_ROM) {
			Cvar_Set2( var_name, var_value, qtrue );
		}
*/
		return var;
	}

	//
	// allocate a new cvar
	//
	if ( cvar_numIndexes >= MAX_CVARS ) {
		Com_Error( ERR_FATAL, "MAX_CVARS" );
	}
	var = &cvar_indexes[cvar_numIndexes];
	cvar_numIndexes++;
	var->name = CopyString( var_name );
	var->string = CopyString( var_value );
	var->modified = qtrue;
	var->modificationCount = 1;
	var->value = atof(var->string);
	var->integer = atoi(var->string);
	var->resetString = CopyString( var_value );

	// link the variable in
	var->next = cvar_vars;
	cvar_vars = var;

	var->flags = flags;
	cvar_modifiedFlags |= flags; // needed so USERINFO cvars created by cgame actually get sent

	long hash = Cvar_Hash(var_name);
	var->hashNext = hashTable[hash];
	hashTable[hash] = var;

	return var;
}
开发者ID:DaTa-,项目名称:cnq3x,代码行数:97,代码来源:cvar.cpp


注:本文中的Cvar_ValidateString函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。