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


C++ Cvar_FindVar函数代码示例

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


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

示例1: Cvar_FindVar

/*
============
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* name, const char* value, int flags) {
    Cvar::Register(nullptr, name, "--", flags, value);
    return Cvar_FindVar(name);
}
开发者ID:Gireen,项目名称:Unvanquished,代码行数:12,代码来源:cvar.cpp

示例2: Cvar_VariableValue

/*
============
Cvar_VariableValue
============
*/
float Cvar_VariableValue(const char* name) {
    cvar_t* var = Cvar_FindVar(name);
    return var ? var->value : 0.0f;
}
开发者ID:Gireen,项目名称:Unvanquished,代码行数:9,代码来源:cvar.cpp

示例3: SZ_Clear


//.........这里部分代码省略.........
				if (activeNumber == playerNumber)
					break;
			}
		}
		if (clientNumber == svs.maxclients)
			return NULL;

		SZ_Clear(&net_message);
		// save space for the header, filled in later
		MSG_WriteLong(&net_message, 0);
		MSG_WriteByte(&net_message, CCREP_PLAYER_INFO);
		MSG_WriteByte(&net_message, playerNumber);
		MSG_WriteString(&net_message, client->name);
		MSG_WriteLong(&net_message, client->colors);
		MSG_WriteLong(&net_message, (int)client->edict->v.frags);
		MSG_WriteLong(&net_message, (int)(net_time - client->netconnection->connecttime));
		MSG_WriteString(&net_message, client->netconnection->address);
		*((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
		dfunc.Write (acceptsock, net_message.data, net_message.cursize, &clientaddr);
		SZ_Clear(&net_message);

		return NULL;
	}

	if (command == CCREQ_RULE_INFO)
	{
		char	*prevCvarName;
		cvar_t	*var;

		// find the search start location
		prevCvarName = MSG_ReadString();
		if (*prevCvarName)
		{
			var = Cvar_FindVar (prevCvarName);
			if (!var)
				return NULL;
			var = var->next;
		}
		else
			var = cvar_vars;

		// search for the next server cvar
		while (var)
		{
			if (var->server)
				break;
			var = var->next;
		}

		// send the response

		SZ_Clear(&net_message);
		// save space for the header, filled in later
		MSG_WriteLong(&net_message, 0);
		MSG_WriteByte(&net_message, CCREP_RULE_INFO);
		if (var)
		{
			MSG_WriteString(&net_message, var->name);
			MSG_WriteString(&net_message, var->string);
		}
		*((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
		dfunc.Write (acceptsock, net_message.data, net_message.cursize, &clientaddr);
		SZ_Clear(&net_message);

		return NULL;
	}
开发者ID:st1x51,项目名称:QuartalEngine,代码行数:67,代码来源:net_dgrm.c

示例4: Cmd_ExecuteString

/*
============
Cmd_ExecuteString

A complete command line has been parsed, so try to execute it

FIXME: this function is getting really messy...
============
*/
void Cmd_ExecuteString (char *text)
{	
	cmd_function_t	*cmd;
	cmd_alias_t		*a;
	int				key;
	static char		buf[1024];
	cbuf_t			*inserttarget;
#ifndef SERVERONLY
	char			**s;
#endif

	Cmd_ExpandString (text, buf);
	Cmd_TokenizeString (buf);

// execute the command line
	if (!Cmd_Argc())
		return;		// no tokens

	inserttarget = &cbuf_main;

#ifndef SERVERONLY
	if (cbuf_current == &cbuf_safe)
		inserttarget = &cbuf_safe;

	if (cbuf_current == &cbuf_svc) {
		if (CL_CheckServerCommand())
			return;
	}
#endif

	key = Com_HashKey (cmd_argv[0]);

// check functions
	for (cmd=cmd_hash_array[key] ; cmd ; cmd=cmd->hash_next)
	{
		if (!Q_stricmp (cmd_argv[0], cmd->name))
		{
#ifndef SERVERONLY
			// special check for msg_trigger commands
			if (cbuf_current == &cbuf_safe) {
				for (s = safe_commands; *s; s++) {
					if (!Q_stricmp(cmd_argv[0], *s))
						break;
				}
				if (!*s) {
					if (cl_warncmd.value || developer.value)
						Com_Printf ("\"%s\" cannot be used in message triggers\n", cmd_argv[0]);
					return;
				}
			}
#endif
			if (cmd->function)
				cmd->function ();
			else
				Cmd_ForwardToServer ();
			return;
		}
	}

// some bright guy decided to use "skill" as a mod command in Custom TF, sigh
	if (!strcmp(Cmd_Argv(0), "skill") && Cmd_Argc() == 1 && Cmd_FindAlias("skill"))
		goto checkaliases;

// check cvars
	if (Cvar_Command())
		return;

// check alias
checkaliases:
	for (a=cmd_alias_hash[key] ; a ; a=a->hash_next)
	{
		if (!Q_stricmp (cmd_argv[0], a->name))
		{
#ifndef SERVERONLY
			if (cbuf_current == &cbuf_svc) {
				Cbuf_AddText (a->value);
				Cbuf_AddText ("\n");
			}
			else
#endif
			{
				Cbuf_InsertTextEx (inserttarget, "\n");

				// if the alias value is a command or cvar and
				// the alias is called with parameters, add them
				if (Cmd_Argc() > 1 && !strchr(a->value, ' ') && !strchr(a->value, '\t')
					&& (Cvar_FindVar(a->value) || (Cmd_FindCommand(a->value)
					&& a->value[0] != '+' && a->value[0] != '-')))
				{
					Cbuf_InsertTextEx (inserttarget, Cmd_Args());
					Cbuf_InsertTextEx (inserttarget, " ");
//.........这里部分代码省略.........
开发者ID:matatk,项目名称:agrip,代码行数:101,代码来源:cmd.c

示例5: Com_Printf

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 ((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)
	{
		// 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_LATCH)
		{
			if (var->latchedString)
			{
				if (strcmp(value, var->latchedString) == 0)
				{
					return var;
//.........这里部分代码省略.........
开发者ID:Ponce,项目名称:etlegacy,代码行数: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:kingtiger01,项目名称:OpenMOHAA,代码行数:101,代码来源:cvar.c

示例7: CSCR_WriteGameCVars

/*
======================
CSCR_WriteGameCVars

Print all cvars declared in script to gamesettings.cfg file
======================
*/
int CSCR_WriteGameCVars( file_t *cfg, const char *scriptfilename )
{
	int count = 0;
	fs_offset_t length = 0;
	char *start;
	parserstate_t state = {0};
	qboolean success = false;

	state.filename = scriptfilename;

	state.buf = (char*)FS_LoadFile( scriptfilename, &length, true );

	start = state.buf;

	if( state.buf == 0 || length == 0 )
	{
		if( start )
			Mem_Free( start );
		return 0;
	}
	MsgDev( D_INFO, "Reading config script file %s\n", scriptfilename );

	if( !CSCR_ParseHeader( &state ) )
	{
		MsgDev( D_ERROR, "Failed to	parse header!\n" );
		goto finish;
	}

	FS_Printf( cfg, "// declared in %s:\n", scriptfilename );

	while( !CSCR_ExpectString( &state, "}", false, false ) )
	{
		scrvardef_t var = { 0 };

		if( CSCR_ParseSingleCvar( &state, &var ) )
		{
			convar_t *cvar = Cvar_FindVar( var.name );
			if( cvar && !( cvar->flags & ( CVAR_SERVERNOTIFY | CVAR_ARCHIVE ) ) )
			{
				// cvars will be placed in gamesettings.cfg and restored on map start
				if( var.flags & CVAR_USERINFO )
					FS_Printf( cfg, "// %s ( %s )\nsetu %s \"%s\"\n", var.desc, var.value, var.name, cvar->string );
				else
					FS_Printf( cfg, "// %s ( %s )\nset %s \"%s\"\n", var.desc, var.value, var.name, cvar->string );
			}
			count++;
		}
		else
			break;

		if( count > 1024 )
			break;
	}

	if( COM_ParseFile( state.buf, state.token ) )
		MsgDev( D_ERROR, "Got extra tokens!\n" );
	else
		success = true;

finish:
	if( !success )
	{
		state.token[ sizeof( state.token ) - 1 ] = 0;
		if( start && state.buf )
			MsgDev( D_ERROR, "Parse error in %s, byte %d, token %s\n", scriptfilename, (int)( state.buf - start ), state.token );
		else
			MsgDev( D_ERROR, "Parse error in %s, token %s\n", scriptfilename, state.token );
	}
	if( start )
		Mem_Free( start );

	return count;
}
开发者ID:jeefo,项目名称:xash3d,代码行数:80,代码来源:cfgscript.c

示例8: demoCut

qboolean demoCut(const char *oldName, int startTime, int endTime) {
	fileHandle_t	oldHandle = 0;
	fileHandle_t	newHandle = 0;
	msg_t			oldMsg;
	byte			oldData[MAX_MSGLEN];
	int				oldSize;
	char			newName[MAX_OSPATH];
	int				buf;
	int				readGamestate = 0;
	int				i;
	demoPlay_t		*play = demo.play.handle;
	qboolean		ret = qfalse;
	int				framesSaved = 0;
	char			newGameDir[MAX_QPATH];
	char			next;
	char			*ext;
	if (!play) {
		Com_Printf("Demo cutting is allowed in mme mode only.\n");
		return qfalse;
	}
	startTime += play->startTime;
	endTime += play->startTime;
	ext = Cvar_FindVar("mme_demoExt")->string;
	if (!*ext)
		ext = ".dm_26";
	oldSize = FS_FOpenFileRead(va("demos/%s%s", oldName, ext), &oldHandle, qtrue);
	if (!oldHandle) {
		Com_Printf("Failed to open %s for cutting.\n", oldName);
		return qfalse;
	}
	memset(&demo.cut.Clc, 0, sizeof(demo.cut.Clc));
	Com_SetLoadingMsg("Cutting the demo...");
	while (oldSize > 0) {
cutcontinue:
		MSG_Init(&oldMsg, oldData, sizeof(oldData));
		/* Read the sequence number */
		if (FS_Read(&demo.cut.Clc.serverMessageSequence, 4, oldHandle) != 4)
			goto cuterror;
		demo.cut.Clc.serverMessageSequence = LittleLong(demo.cut.Clc.serverMessageSequence);
		oldSize -= 4;
		/* Read the message size */
		if (FS_Read(&oldMsg.cursize,4, oldHandle) != 4)
			goto cuterror;
		oldMsg.cursize = LittleLong(oldMsg.cursize);
		oldSize -= 4;
		/* Negative size signals end of demo */
		if (oldMsg.cursize < 0)
			break;
		if (oldMsg.cursize > oldMsg.maxsize) 
			goto cuterror;
		/* Read the actual message */
		if (FS_Read(oldMsg.data, oldMsg.cursize, oldHandle) != oldMsg.cursize)
			goto cuterror;
		oldSize -= oldMsg.cursize;
		// init the bitstream
		MSG_BeginReading(&oldMsg);
		// Skip the reliable sequence acknowledge number
		MSG_ReadLong(&oldMsg);
		//
		// parse the message
		//
		while (1) {
			byte cmd;
			if (oldMsg.readcount > oldMsg.cursize) {
				Com_Printf("Demo cutter, read past end of server message.\n");
				goto cuterror;
			}
            cmd = MSG_ReadByte(&oldMsg);
			if (cmd == svc_EOF) {
                break;
			}
			// skip all the gamestates until we reach needed
			if (readGamestate < demo.currentNum) {
				if (cmd == svc_gamestate) {
					readGamestate++;
				}
				goto cutcontinue;
			}
			// other commands
			switch (cmd) {
			default:
				Com_Printf(S_COLOR_RED"ERROR: CL_ParseServerMessage: Illegible server message\n");
				goto cuterror;		
			case svc_nop:
				break;
			case svc_serverCommand:
				demoCutParseCommandString(&oldMsg, &demo.cut.Clc);
				break;
			case svc_gamestate:
				if (readGamestate > demo.currentNum) {
					Com_Printf("Warning: unexpected new gamestate, finishing cutting.\n");
					goto cutcomplete;
				}
				if (!demoCutParseGamestate(&oldMsg, &demo.cut.Clc, &demo.cut.Cl)) {
					goto cuterror;
				}
				Com_sprintf(newName, sizeof(newName), "demos/%s_cut%s", oldName, ext);
				newHandle = FS_FOpenFileWrite(newName);
				if (!newHandle) {
					Com_Printf("Failed to open %s for target cutting.\n", newName);
//.........这里部分代码省略.........
开发者ID:deathsythe47,项目名称:jaMME,代码行数:101,代码来源:cl_demos_cut.cpp

示例9: Cvar_Set

/*
============
Cvar_Set
============
*/
void Cvar_Set (const char *var_name, const char *value)
{
	cvar_t		*var;
	size_t		varlen;

	var = Cvar_FindVar (var_name);
	if (!var)
	{	// there is an error in C code if this happens
		Con_Printf ("%s: variable %s not found\n", __thisfunc__, var_name);
		return;
	}

	if ( var->flags & (CVAR_ROM|CVAR_LOCKED) )
		return;	// cvar is marked read-only or locked temporarily

	if (var->flags & CVAR_REGISTERED)
	{
		if ( !strcmp(var->string, value) )
			return;	// no change
	}
	else
	{
		var->flags |= CVAR_REGISTERED;
	}

	varlen = strlen(value);
	if (var->string == NULL)
	{
		var->string = (char *) Z_Malloc (varlen + 1, Z_MAINZONE);
	}
	else if (strlen(var->string) != varlen)
	{
		Z_Free ((void *)var->string);	// free the old value string
		var->string = (char *) Z_Malloc (varlen + 1, Z_MAINZONE);
	}

	memcpy ((char *)var->string, value, varlen + 1);
	var->value = atof (var->string);
	var->integer = (int) var->value;

// handle notifications
#if defined (H2W)
#   if defined(SERVERONLY)
	if (var->flags & CVAR_SERVERINFO)
	{
		Info_SetValueForKey (svs.info, var_name, value, MAX_SERVERINFO_STRING);
		SV_BroadcastCommand ("fullserverinfo \"%s\"\n", svs.info);
	}
#   else /* HWCL */
	if (var->flags & CVAR_USERINFO)
	{
		Info_SetValueForKey (cls.userinfo, var_name, value, MAX_INFO_STRING);
		if (cls.state >= ca_connected)
		{
			MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
			SZ_Print (&cls.netchan.message, va("setinfo \"%s\" \"%s\"\n", var_name, value));
		}
	}
#   endif
#else	/* ! H2W */
	if (var->flags & CVAR_NOTIFY)
	{
		if (sv.active)
			SV_BroadcastPrintf ("\"%s\" changed to \"%s\"\n", var_name, value);
	}
#endif	/* H2W	*/

// don't allow deathmatch and coop at the same time
#if !defined(H2W) || defined(SERVERONLY)
	if ( !strcmp(var->name, deathmatch.name) )
	{
		if (var->integer != 0)
			Cvar_Set("coop", "0");
	}
	else if ( !strcmp(var->name, coop.name) )
	{
		if (var->integer != 0)
			Cvar_Set("deathmatch", "0");
	}
#endif	/* coop && deathmatch */
}
开发者ID:crutchwalkfactory,项目名称:motocakerteam,代码行数:86,代码来源:cvar.c

示例10: Cvar_UnlockVar

void Cvar_UnlockVar (const char *var_name)
{
	cvar_t	*var = Cvar_FindVar (var_name);
	if (var)
		var->flags &= ~CVAR_LOCKED;
}
开发者ID:crutchwalkfactory,项目名称:motocakerteam,代码行数:6,代码来源:cvar.c

示例11: 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\n");
	}

	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);
		}

		// if CVAR_USERINFO was toggled on for an existing cvar, check wether the value needs to be cleaned from foreigh 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)
		{
			char *cleaned = Cvar_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
			}
		}

// 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, "Cvar_Get: MAX_CVARS (%d) hit -- too many cvars!\n", MAX_CVARS);
//.........这里部分代码省略.........
开发者ID:BulldogDrummond,项目名称:etlegacy-mysql,代码行数:101,代码来源:cvar.c

示例12: Cmd_Alias_f

/* <4c63> ../engine/cmd.c:521 */
void Cmd_Alias_f(void)
{
	cmdalias_t *a;
	const char *s;
	char cmd[MAX_CMD_LINE];
	int i, c;

	if (Cmd_Argc() == 1)
	{
		// Output all aliases
		Con_Printf("Current alias commands:\n");

		for (a = cmd_alias; a; a = a->next)
		{
			Con_Printf("%s : %s", a->name, a->value);	// Don't need \n here, because each alias value is appended with it
		}

		return;
	}

	s = Cmd_Argv(1);

	if (Q_strlen(s) >= MAX_ALIAS_NAME)
	{
		Con_Printf("Alias name is too long\n");
		return;
	}

	if (Cvar_FindVar(s))
	{
		Con_Printf("Alias name is invalid\n");
		return;
	}

	SetCStrikeFlags();	// TODO: Do this once somewhere at the server start

	if ((g_bIsCStrike || g_bIsCZero) &&
		(!Q_stricmp(s, "cl_autobuy")
		|| !Q_stricmp(s, "cl_rebuy")
		|| !Q_stricmp(s, "gl_ztrick")
		|| !Q_stricmp(s, "gl_ztrick_old")
		|| !Q_stricmp(s, "gl_d3dflip")))
	{
		Con_Printf("Alias name is invalid\n");
		return;
	}

	// Say hello to my little friend! (c)
	if (g_bIsTFC && (!Q_stricmp(s, "_special") || !Q_stricmp(s, "special")))
	{
		Con_Printf("Alias name is invalid\n");
		return;
	}

	// Gather arguments into one string
	cmd[0] = 0;
	c = Cmd_Argc();
	for (i = 2; i <= c; i++)
	{
		Q_strncat(cmd, Cmd_Argv(i), MAX_CMD_LINE - 2 - Q_strlen(cmd));	// always have a space for \n or ' ' and \0

		if (i != c)
		{
			Q_strcat(cmd, " ");
		}
	}
	Q_strcat(cmd, "\n");

	// Search for existing alias
	for (a = cmd_alias; a; a = a->next)
	{
		if (!Q_stricmp(a->name, s))
		{
			if (!Q_strcmp(a->value, cmd))
			{
				// Same value on the alias, return
				return;
			}
			// Release value, will realloc
			Z_Free(a->value);
			break;
		}
	}

	if (!a)
	{
		// Alloc new alias
		a = (cmdalias_t *)Z_Malloc(sizeof(cmdalias_t));
		a->next = cmd_alias;
		cmd_alias = a;

		Q_strncpy(a->name, s, ARRAYSIZE(a->name) - 1);
		a->name[ARRAYSIZE(a->name) - 1] = 0;
	}

	a->value = CopyString(cmd);
}
开发者ID:coolmans,项目名称:rehlds,代码行数:98,代码来源:cmd.cpp

示例13: Cvar_FindVar

/**
 * @brief Sets a cvar values
 * Handles write protection and latched cvars as expected
 * @param[in] varName Which cvar
 * @param[in] value Set the cvar to the value specified by 'value'
 * @param[in] force Force the update of the cvar
 */
static cvar_t *Cvar_Set2 (const char *varName, const char *value, bool force)
{
	cvar_t *var;

	if (!value)
		return NULL;

	var = Cvar_FindVar(varName);
	/* create it */
	if (!var)
		return Cvar_Get(varName, value);

	if (var->flags & (CVAR_USERINFO | CVAR_SERVERINFO)) {
		if (!Cvar_InfoValidate(value)) {
			Com_Printf("invalid info cvar value '%s' of cvar '%s'\n", value, varName);
			return var;
		}
	}

	if (!force) {
		if (var->flags & CVAR_NOSET) {
			Com_Printf("%s is write protected.\n", varName);
			return var;
		}
#ifndef DEBUG
		if (var->flags & CVAR_DEVELOPER) {
			Com_Printf("%s is a developer cvar.\n", varName);
			return var;
		}
#endif

		if (var->flags & CVAR_LATCH) {
			if (var->latchedString) {
				if (Q_streq(value, var->latchedString))
					return var;
				Mem_Free(var->latchedString);
				var->latchedString = NULL;
			} else {
				if (Q_streq(value, var->string))
					return var;
			}

			/* if we are running a server */
			if (Com_ServerState()) {
				Com_Printf("%s will be changed for next game.\n", varName);
				var->latchedString = Mem_PoolStrDup(value, com_cvarSysPool, 0);
			} else {
				Mem_Free(var->oldString);
				var->oldString = var->string;
				var->string = Mem_PoolStrDup(value, com_cvarSysPool, 0);
				var->value = atof(var->string);
				var->integer = atoi(var->string);
			}

			if (var->check && var->check(var))
				Com_Printf("Invalid value for cvar %s\n", varName);

			return var;
		}
	} else {
		Mem_Free(var->latchedString);
		var->latchedString = NULL;
	}

	if (Q_streq(value, var->string))
		return var;				/* not changed */

	if (var->flags & CVAR_R_MASK)
		Com_SetRenderModified(true);

	Mem_Free(var->oldString);		/* free the old value string */
	var->oldString = var->string;
	var->modified = true;

	if (var->flags & CVAR_USERINFO)
		Com_SetUserinfoModified(true);	/* transmit at next opportunity */

	var->string = Mem_PoolStrDup(value, com_cvarSysPool, 0);
	var->value = atof(var->string);
	var->integer = atoi(var->string);

	if (var->check && var->check(var)) {
		Com_Printf("Invalid value for cvar %s\n", varName);
		return var;
	}

	Cvar_ExecuteChangeListener(var);

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

示例14: Cvar_VariableIntegerValue

/*
============
Cvar_VariableIntegerValue
============
*/
int Cvar_VariableIntegerValue( const char* name ) {
    cvar_t* var = Cvar_FindVar(name);
    return var ? var->integer : 0;
}
开发者ID:Gireen,项目名称:Unvanquished,代码行数:9,代码来源:cvar.cpp

示例15: Com_Printf

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

	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
		return Cvar_Get( var_name, value, defaultFlags );
	}

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

	value = Cvar_Validate(var, value, qtrue);

	if((var->flags & CVAR_LATCH) && var->latchedString)
	{
		if(!strcmp(value, var->string))
		{
			Cvar_FreeString(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)) && com_sv_running && !com_sv_running->integer && CL_ConnectedToServer() )
		{
			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;
				Cvar_FreeString (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;
		}
	}
//.........这里部分代码省略.........
开发者ID:LuisMars,项目名称:OpenJK,代码行数:101,代码来源:cvar.cpp


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