Beispiel #1
0
/**
 * @brief Call after the script initialized the node
 */
static void UI_ConFuncNodeLoaded (uiNode_t *node)
{
	/* register confunc non inherited */
	if (node->super == NULL) {
		/* don't add a callback twice */
		if (!Cmd_Exists(node->name)) {
			Cmd_AddCommand(node->name, UI_ConfuncCommand_f, "Confunc callback");
			Cmd_AddUserdata(node->name, node);
		} else {
			Com_Printf("UI_ParseNodeBody: Command name for confunc '%s' already registered\n", UI_GetPath(node));
		}
	} else {
		uiNode_t *dummy;

		/* convert a confunc to an "inherited" confunc if it is possible */
		if (Cmd_Exists(node->name)) {
			if (UI_ConFuncIsVirtual(node))
				return;
		}

		dummy = UI_AllocNode(node->name, "confunc", qfalse);
		Cmd_AddCommand(node->name, UI_ConfuncCommand_f, "Inherited confunc callback");
		Cmd_AddUserdata(dummy->name, dummy);
	}
}
Beispiel #2
0
/*
============
Cvar_RegisterVariable

Adds a freestanding variable to the variable list.
============
*/
void Cvar_RegisterVariable (cvar_t *variable)
{
	char	*oldstr;
	
// first check to see if it has allready been defined
	if (Cvar_FindVar (variable->name))
	{
		Con_Printf ("Can't register variable %s, allready defined\n", variable->name);
		return;
	}
	
// check for overlap with a command
	if (Cmd_Exists (variable->name))
	{
		Con_Printf ("Cvar_RegisterVariable: %s is a command\n", variable->name);
		return;
	}
		
// copy the value off, because future sets will Z_Free it
	oldstr = variable->string;
	variable->string = (char*) Z_Malloc (Q_strlen(variable->string)+1);	
	Q_strcpy (variable->string, oldstr);
	variable->value = Q_atof (variable->string);
	
// link the variable in
	variable->next = cvar_vars;
	cvar_vars = variable;
}
Beispiel #3
0
void Cvar_Set_f (void)
{
	cvar_t *var;
	const char *name;

	if (Cmd_Argc() != 3)
	{
		Com_Printf ("usage: set <cvar> <value>\n");
		return;
	}

	name = Cmd_Argv (1);
	var = Cvar_Find (name);

	if (var)
	{
		Cvar_Set (var, Cmd_Argv(2));
	}
	else
	{
		if (Cmd_Exists(name))
		{
			Com_Printf ("\"%s\" is a command\n", name);
			return;
		}

		var = Cvar_Get (name, Cmd_Argv(2), 0);
	}

	if (cvar_seta)
		var->flags |= CVAR_USER_ARCHIVE;
}
Beispiel #4
0
/*
============
Cmd_AddClientCommand
============
*/
void Cmd_AddClientCommand( const char *cmd_name, xcommand_t function )
{
	cmd_t	*cmd;

	// fail if the command is a variable name
	if( Cvar_FindVar( cmd_name ))
	{
		MsgDev( D_INFO, "Cmd_AddCommand: %s already defined as a var\n", cmd_name );
		return;
	}
	
	// fail if the command already exists
	if( Cmd_Exists( cmd_name ))
	{
		MsgDev(D_INFO, "Cmd_AddCommand: %s already defined\n", cmd_name);
		return;
	}

	// use a small malloc to avoid zone fragmentation
	cmd = Z_Malloc( sizeof( cmd_t ));
	cmd->name = copystring( cmd_name );
	cmd->desc = copystring( "client command" );
	cmd->function = function;
	cmd->flags = CMD_CLIENTDLL;
	cmd->next = cmd_functions;
	cmd_functions = cmd;
}
Beispiel #5
0
// Use this for engine inside call only, not from user code, because it doesn't alloc string for the name.
void Cmd_AddCommand(char *cmd_name, xcommand_t function)
{
	cmd_function_t *cmd;

	if (host_initialized)
	{
		Sys_Error(__FUNCTION__ " after host_initialized");
	}

	// Check in variables list
	if (Cvar_FindVar(cmd_name) != NULL)
	{
		Con_Printf(__FUNCTION__ ": \"%s\" already defined as a var\n", cmd_name);
		return;
	}

	// Check if this command is already defined
	if (Cmd_Exists(cmd_name))
	{
		Con_Printf(__FUNCTION__ ": \"%s\" already defined\n", cmd_name);
		return;
	}

	// Create cmd_function
	cmd = (cmd_function_t *)Hunk_Alloc(sizeof(cmd_function_t));
	cmd->name = cmd_name;
	cmd->function = function ? function : Cmd_ForwardToServer;
	cmd->flags = 0;

	Cmd_InsertCommand(cmd);
}
Beispiel #6
0
/*
============
Cvar_RegisterVariable

Adds a freestanding variable to the variable list.
============
*/
void Cvar_RegisterVariable (cvar_t *variable)
{
	char	value[512];
	qboolean	set_rom;

// first check to see if it has already been defined
	if (Cvar_FindVar (variable->name))
	{
		Con_Printf ("Can't register variable %s, already defined\n", variable->name);
		return;
	}

// check for overlap with a command
	if (Cmd_Exists (variable->name))
	{
		Con_Printf ("%s: %s is a command\n", __thisfunc__, variable->name);
		return;
	}

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

// copy the value off, because future sets will Z_Free it
	q_strlcpy (value, variable->string, sizeof(value));
	variable->string = NULL;

// set it through the function to be consistant
	set_rom = (variable->flags & CVAR_ROM);
	variable->flags &= ~CVAR_ROM;
	Cvar_Set (variable->name, value);
	if (set_rom)
		variable->flags |= CVAR_ROM;
}
Beispiel #7
0
// Use this for call from user code, because it alloc string for the name.
void Cmd_AddMallocCommand(char *cmd_name, xcommand_t function, int flag)
{
	cmd_function_t *cmd;

	// Check in variables list
	if (Cvar_FindVar(cmd_name) != NULL)
	{
		Con_Printf(__FUNCTION__ ": \"%s\" already defined as a var\n", cmd_name);
		return;
	}

	// Check if this command is already defined
	if (Cmd_Exists(cmd_name))
	{
		Con_Printf(__FUNCTION__ ": \"%s\" already defined\n", cmd_name);
		return;
	}

	// Create cmd_function
	cmd = (cmd_function_t *)Mem_Malloc(sizeof(cmd_function_t));
	cmd->name = CopyString(cmd_name);	// alloc string, so it will not dissapear on side modules unloading and to maintain the same name during run
	cmd->function = function ? function : Cmd_ForwardToServer;
	cmd->flags = flag;

	Cmd_InsertCommand(cmd);
}
Beispiel #8
0
/*
============
Cmd_AddCommand
============
*/
void Cmd_AddCommand(const char *cmd_name, xcommand_t function, const char *cmd_desc)
{
	cmd_function_t *cmd;

	// fail if the command is a variable name
	if( Cvar_FindVar( cmd_name ))
	{
		Com_Printf( "Cmd_AddCommand: %s already defined as a var\n", cmd_name );
		return;
	}
	
	// fail if the command already exists
	if( Cmd_Exists( cmd_name ))
	{
		Com_Printf( "Cmd_AddCommand: %s already defined\n", cmd_name );
		// ALARM! HACKED FOR NOW
		Cmd_RemoveCommand(cmd_name);
		return;
	}

	// use a small malloc to avoid zone fragmentation
	cmd = (cmd_function_t*)S_Malloc(sizeof(cmd_function_t));
	cmd->name = CopyString(cmd_name);
	cmd->desc = CopyString(cmd_desc);
	cmd->function = function;
	cmd->next = cmd_functions;
	cmd->complete = NULL;
	cmd_functions = cmd;
}
Beispiel #9
0
void Cvar_Set_tp_f (void)
{
	cvar_t *var;
	char *var_name;

	if (Cmd_Argc() != 3) {
		Com_Printf ("Usage: %s <cvar> <value>\n", Cmd_Argv(0));
		return;
	}

	var_name = Cmd_Argv (1);
	var = Cvar_Find (var_name);

	if (var) {
        if (!var->teamplay) {
            Com_Printf("\"%s\" is not a teamplay variable\n", var->name);
            return;
        } else {
		    Cvar_Set (var, Cmd_Argv(2));
        }
	} else {
		if (Cmd_Exists(var_name)) {
			Com_Printf ("\"%s\" is a command\n", var_name);
			return;
		}
		var = Cvar_Create (var_name, Cmd_Argv(2), 0);
        var->teamplay = true;
	}
}
Beispiel #10
0
void Cvar_Set_ex_f (void)
{
	cvar_t	*var;
	char	*var_name;
	char	*st = NULL;
	char	text_exp[1024];

	if (Cmd_Argc() != 3) {
		Com_Printf ("usage: set_ex <cvar> <value>\n");
		return;
	}

	var_name = Cmd_Argv (1);
	var = Cvar_Find (var_name);


	if ( !var ) {
		if (Cmd_Exists(var_name)) {
			Com_Printf ("\"%s\" is a command\n", var_name);
			return;
		}
		var = Cvar_Create(var_name, "", 0);
	}

	Cmd_ExpandString( Cmd_Argv(2), text_exp);
	st = TP_ParseMacroString( text_exp );
	st = TP_ParseFunChars(st, false);

	Cvar_Set (var, st );
}
Beispiel #11
0
/*
============
Cvar_RegisterVariable

Adds a freestanding variable to the variable list.
============
*/
void Cvar_RegisterVariable (cvar_t *variable)
{
	char	value[512];

// first check to see if it has allready been defined
	if (Cvar_FindVar (variable->name))
	{
		Con_Printf ("Can't register variable %s, allready defined\n", variable->name);
		return;
	}
	
// check for overlap with a command
	if (Cmd_Exists (variable->name))
	{
		Con_Printf ("Cvar_RegisterVariable: %s is a command\n", variable->name);
		return;
	}
		
// link the variable in
	variable->next = cvar_vars;
	cvar_vars = variable;

// copy the value off, because future sets will Z_Free it
	strcpy (value, variable->string);
	variable->string = Z_Malloc (1);	
	
// set it through the function to be consistant
	Cvar_Set (variable->name, value);
}
Beispiel #12
0
/*
============
Cvar_Register

Adds a freestanding variable to the variable list.

If the variable already exists, the value will not be set
The flags will be or'ed in if the variable exists.
============
*/
EXTERNC void Cvar_Register (cvar_t *var)
{
	char	string[512];
	int		key;
	cvar_t	*old;

	// first check to see if it has already been defined
	old = Cvar_Find (var->name);

	if (old && !(old->flags & CVAR_DYNAMIC)) {
		if (old == var)
			return;
		Com_Printf ("Can't register variable %s, already defined\n", var->name);
		return;
	}

#if 0
	// check for overlap with a command
	if (Cmd_Exists (var->name)) {
		Com_Printf ("Cvar_Register: %s is a command\n", var->name);
		return;
	}
#endif

	if (old)
	{
		var->flags |= old->flags & ~(CVAR_DYNAMIC|CVAR_TEMP);
		strlcpy (string, old->string, sizeof(string));
		Cvar_Delete (old->name);
		if (!(var->flags & CVAR_ROM))
			var->string = Q_strdup (string);
		else
			var->string = Q_strdup (var->string);
	}
	else
	{
		// allocate the string on heap because future sets will Q_free it
		var->string = Q_strdup (var->string);
	}
	
	var->value = Q_atof (var->string);

	// link the variable in
	key = Com_HashKey (var->name);
	var->hash_next = cvar_hash[key];
	cvar_hash[key] = var;
	var->next = cvar_vars;
	cvar_vars = var;

#ifndef CLIENTONLY
	if (var->flags & CVAR_SERVERINFO)
		SV_ServerinfoChanged (var->name, var->string);
#endif

#ifndef SERVERONLY
	if (var->flags & CVAR_USERINFO)
		CL_UserinfoChanged (var->name, var->string);
#endif
}
Beispiel #13
0
/**
 * @brief Reset and free the UI data hunk
 * @note Even called in case of an error when CL_Shutdown was called - maybe even
 * before CL_InitLocal (and thus UI_Init) was called
 * @sa CL_Shutdown
 * @sa UI_Init
 */
void UI_Shutdown (void)
{
	/* MN is not yet initialized */
	if (ui_global.adata == nullptr)
		return;

	const uiBehaviour_t* confunc = UI_GetNodeBehaviour("confunc");

	/* remove all confunc commands */
	uiNode_t** nodes[] = {ui_global.windows, ui_global.components};
	for (int nodeType = 0; nodeType < 2; ++nodeType) {
		for (int i = 0; i < ui_global.numWindows; i++) {
			uiNode_t* node = nodes[nodeType][i];
			while (node) {
				/* remove the command */
				if (node->behaviour == confunc) {
					/* many nodes to one command is allowed */
					if (Cmd_Exists(node->name)) {
						Cmd_RemoveCommand(node->name);
					}
				}

				/* recursive next */
				if (node->firstChild != nullptr) {
					node = node->firstChild;
					continue;
				}
				while (node) {
					if (node->next != nullptr) {
						node = node->next;
						break;
					}
					node = node->parent;
				}
			}
		}
	}
	UI_ShutdownLua();
	UI_FontShutdown();
	UI_ResetInput();
	UI_ResetTimers();

#ifdef DEBUG
	Cmd_RemoveCommand("debug_uimemory");
#endif
	Cmd_RemoveCommand("ui_restart");

	Mem_Free(ui_global.adata);
	OBJZERO(ui_global);

	/* release pools */
	Mem_FreePool(ui_sysPool);
	Mem_FreePool(ui_dynStringPool);
	Mem_FreePool(ui_dynPool);
	ui_sysPool = nullptr;
	ui_dynStringPool = nullptr;
	ui_dynPool = nullptr;
}
Beispiel #14
0
/**
 * @brief Cleanup tasks on removing a console function
 * @param node The node to delete.
 */
void uiConFuncNode::deleteNode (uiNode_t* node)
{
	onWindowClosed(node);
	if (Cmd_Exists(node->name)) {
		uiNode_t* userData = (uiNode_t*)Cmd_GetUserdata(node->name);
		if (userData && userData == node)
			Cmd_RemoveCommand(node->name);
	}
	uiNode::deleteNode(node);
}
/*	Adds a freestanding variable to the variable list.
*/
void Cvar_RegisterVariable (ConsoleVariable_t *variable,void (*Function)(void))
{
	char	*oldstr;
	ConsoleVariable_t	*cursor,*prev; //johnfitz -- sorted list insert

	// First check to see if it has allready been defined
	if (Cvar_FindVar (variable->name))
	{
		Con_Printf ("Can't register variable %s, allready defined\n", variable->name);
		return;
	}

	// Check for overlap with a command
	if (Cmd_Exists (variable->name))
	{
		Con_Printf ("Cvar_RegisterVariable: %s is a command\n", variable->name);
		return;
	}

// copy the value off, because future sets will free it
	oldstr = variable->string;
	variable->string = (char*)malloc_or_die(strlen(variable->string) + 1);
	strcpy(variable->string, oldstr);

	Cvar_UpdateValues(variable);

	//johnfitz -- save initial value for "reset" command
	variable->default_string = (char*)malloc_or_die(strlen(variable->string) + 1);
	strcpy(variable->default_string, oldstr);
	//johnfitz

// link the variable in

	//johnfitz -- insert each entry in alphabetical order
	if(!cConsoleVariables || strcmp(variable->name, cConsoleVariables->name) < 0) //insert at front
	{
		variable->next = cConsoleVariables;
		cConsoleVariables = variable;
	}
	else //insert later
	{
		prev = cConsoleVariables;
		cursor = cConsoleVariables->next;
		while (cursor && (strcmp(variable->name, cursor->name) > 0))
		{
			prev = cursor;
			cursor = cursor->next;
		}
		variable->next = prev->next;
		prev->next = variable;
	}
	//johnfitz

	variable->callback = Function; //johnfitz
}
Beispiel #16
0
void MP3_XMMS2_Init(void) {
	XMMS2_LoadLibrary();

	if (!MP3_XMMS2_IsActive())
		return;

	XMMS2_Connect();

	if (!Cmd_Exists("mp3_startxmms2"))
			Cmd_AddCommand("mp3_startxmms2", MP3_Execute_f);
}
Beispiel #17
0
static void
Cmd_Alias_f (void)
{
	cmdalias_t *alias;
	dstring_t  *cmd;
	int         i, c;
	const char *s;

	if (Cmd_Argc () == 1) {
		Sys_Printf ("Current alias commands:\n");
		for (alias = cmd_alias; alias; alias = alias->next)
			Sys_Printf ("alias %s \"%s\"\n", alias->name, alias->value);
		return;
	}

	s = Cmd_Argv (1);
	// if the alias already exists, reuse it
	alias = (cmdalias_t *) Hash_Find (cmd_alias_hash, s);
	if (Cmd_Argc () == 2) {
		if (alias)
			Sys_Printf ("alias %s \"%s\"\n", alias->name, alias->value);
		return;
	}
	if (alias)
		free ((char *) alias->value);
	else if (!Cmd_Exists (s)) {
		cmdalias_t **a;

		alias = calloc (1, sizeof (cmdalias_t));
		SYS_CHECKMEM (alias);
		alias->name = strdup (s);
		Hash_Add (cmd_alias_hash, alias);
		for (a = &cmd_alias; *a; a = &(*a)->next)
			if (strcmp ((*a)->name, alias->name) >= 0)
				break;
		alias->next = *a;
		*a = alias;
		Cmd_AddCommand (alias->name, Cmd_Runalias_f, "Alias command.");
	} else {
		Sys_Printf ("alias: a command with the name \"%s\" already exists.\n", s);
		return;
	}
	// copy the rest of the command line
	cmd = dstring_newstr ();
	c = Cmd_Argc ();
	for (i = 2; i < c; i++) {
		dstring_appendstr (cmd, Cmd_Argv (i));
		if (i != c - 1)
			dstring_appendstr (cmd, " ");
	}

	alias->value = dstring_freeze (cmd);
}
Beispiel #18
0
/*
============
Cvar_RegisterVariable

Adds a freestanding variable to the variable list.
============
*/
void Cvar_RegisterVariable (cvar_t *variable, void *function)
{
	char	*oldstr;
	cvar_t	*cursor,*prev; //johnfitz -- sorted list insert

// first check to see if it has already been defined
	if (Cvar_FindVar (variable->name))
	{
		Con_Printf ("Can't register variable %s, already defined\n", variable->name);
		return;
	}
	
// check for overlap with a command
	if (Cmd_Exists (variable->name))
	{
		Con_Printf ("   %s is a command\n", variable->name);
		return;
	}
		
// copy the value off, because future sets will Z_Free it
	oldstr = variable->string;
	variable->string = Z_Malloc (strlen(variable->string)+1);	
	strcpy (variable->string, oldstr);
	variable->value = atof (variable->string);

	//johnfitz -- save initial value for "reset" command
	variable->default_string = Z_Malloc (strlen(variable->string)+1);
	strcpy (variable->default_string, oldstr);
	//johnfitz

// link the variable in
	//johnfitz -- insert each entry in alphabetical order
	if (cvar_vars == NULL || strcmp(variable->name, cvar_vars->name) < 0) // insert at front
	{
		variable->next = cvar_vars;
		cvar_vars = variable;
	}
	else //insert later
	{
		prev = cvar_vars;
		cursor = cvar_vars->next;
		while (cursor && (strcmp(variable->name, cursor->name) > 0))
		{
			prev = cursor;
			cursor = cursor->next;
		}
		variable->next = prev->next;
		prev->next = variable;
	}
	//johnfitz

	variable->callback = function; //johnfitz
}
Beispiel #19
0
void M_Init (void)
{
	if (Cmd_Exists("music_change"))
		Cmd_RemoveCommand("music_change");
	Cmd_TableAddList(musicCmds);
	Cmd_AddParamCompleteFunction("music_play", M_CompleteMusic);
	snd_music = Cvar_Get("snd_music", "PsymongN3", 0, "Background music track");
	snd_music_volume = Cvar_Get("snd_music_volume", "128", CVAR_ARCHIVE, "Music volume - default is 128.");
	snd_music_volume->modified = true;
	snd_music_play = Cvar_Get ("snd_music_play", "1", CVAR_ARCHIVE, "Enable background music.");
	music.playing = snd_music_play->integer != 0;
}
Beispiel #20
0
/**
 * @brief Reset and free the UI data hunk
 * @note Even called in case of an error when CL_Shutdown was called - maybe even
 * before CL_InitLocal (and thus UI_Init) was called
 * @sa CL_Shutdown
 * @sa UI_Init
 */
void UI_Shutdown (void)
{
	int i;
	const uiBehaviour_t *confunc;

	/* MN is not yet initialized */
	if (ui_global.adata == NULL)
		return;

	confunc = UI_GetNodeBehaviour("confunc");

	/* remove all confunc commands */
	for (i = 0; i < ui_global.numWindows; i++) {
		uiNode_t *node = ui_global.windows[i];
		while (node) {

			/* remove the command */
			if (node->behaviour == confunc) {
				/* many nodes to one command is allowed */
				if (Cmd_Exists(node->name))
					Cmd_RemoveCommand(node->name);
			}

			/* recursive next */
			if (node->firstChild != NULL)
				node = node->firstChild;
			else {
				while (node) {
					if (node->next != NULL) {
						node = node->next;
						break;
					}
					node = node->parent;
				}
			}
		}
	}

	if (ui_global.adataize)
		Mem_Free(ui_global.adata);
	ui_global.adata = NULL;
	ui_global.adataize = 0;

	/* release pools */
	Mem_FreePool(ui_sysPool);
	Mem_FreePool(ui_dynStringPool);
	Mem_FreePool(ui_dynPool);
	ui_sysPool = NULL;
	ui_dynStringPool = NULL;
	ui_dynPool = NULL;
}
Beispiel #21
0
void Cvar_Set_Bind_Str_f (void)
{
	cvar_t		*var;
	int			keynum;
	char		*var_name;
	char		*key_name;
	//char		str[1024];
	//char		*v,*s;

	if (Cmd_Argc() != 3) {
		Com_Printf ("usage: set_bind_str <cvar> <key>\n");
		return;
	}

	var_name = Cmd_Argv (1);
	key_name = Cmd_Argv (2);
	var = Cvar_Find (var_name);
	keynum = Key_StringToKeynum( key_name );

	if ( !var) {
		if (Cmd_Exists(var_name)) {
			Com_Printf ("\"%s\" is a command\n", var_name);
			return;
		}
		var = Cvar_Create(var_name, "", 0);
	}

	if (!var) {
		Com_Printf ("Unknown variable \"%s\"\n", var_name);
		return;
	} else if (keynum == -1) {
		Com_Printf ("Unknown key \"%s\"\n", key_name);
		return;
	} else {
		if (keybindings[keynum]) {
			/*		s = str; v = keybindings[keynum];
						while (*v) {
							if (*v == '\"') // " should be escaped
								*s++ = '\\';
							*s++ = *v++;
						}
						*s = '\0';
						Cvar_Set (var, str);*/
			Cvar_Set (var, keybindings[keynum]);
		} else
			Cvar_Set (var, "");
	}
}
Beispiel #22
0
/* <189df> ../engine/cvar.c:391 */
void EXT_FUNC Cvar_RegisterVariable(cvar_t *variable)
{
	char *oldstr;
	cvar_t *v, *c;
	cvar_t dummyvar;

	if (Cvar_FindVar(variable->name))
	{
		Con_Printf("Can't register variable \"%s\", already defined\n", variable->name);
		return;
	}

	if (Cmd_Exists(variable->name))
	{
		Con_Printf(__FUNCTION__ ": \"%s\" is a command\n", variable->name);
		return;
	}

	oldstr = variable->string;

	// Alloc string, so it will not dissapear on side modules unloading and to maintain the same name during run
	variable->string = (char *)Z_Malloc(Q_strlen(variable->string) + 1);
	Q_strcpy(variable->string, oldstr);
	variable->value = (float)Q_atof(oldstr);

	dummyvar.name = " ";
	dummyvar.next = cvar_vars;

	v = cvar_vars;
	c = &dummyvar;

	// Insert with alphabetic order
	while (v)
	{
		if (Q_stricmp(v->name, variable->name) > 0)
		{
			break;
		}

		c = v;
		v = v->next;
	}

	c->next = variable;
	variable->next = v;
	cvar_vars = dummyvar.next;
}
Beispiel #23
0
void Cvar_Set_Alias_Str_f (void)
{
	cvar_t		*var;
	char		*var_name;
	char		*alias_name;
	//char		str[1024];
	char		*v /*,*s*/;
	if (Cmd_Argc() != 3) {
		Com_Printf ("usage: set_alias_str <cvar> <alias>\n");
		return;
	}

	var_name = Cmd_Argv (1);
	alias_name = Cmd_Argv (2);
	var = Cvar_Find (var_name);
	v = Cmd_AliasString( alias_name );

	if ( !var) {
		if (Cmd_Exists(var_name)) {
			Com_Printf ("\"%s\" is a command\n", var_name);
			return;
		}
		var = Cvar_Create(var_name, "", 0);
	}

	if (!var) {
		Com_Printf ("Unknown variable \"%s\"\n", var_name);
		return;
	} else if (!v) {
		Com_Printf ("Unknown alias \"%s\"\n", alias_name);
		return;
	} else {
		/*		s = str;
				while (*v) {
					if (*v == '\"') // " should be escaped
						*s++ = '\\';
					*s++ = *v++;
				}
				*s = '\0';
				Cvar_Set (var, str);*/
		Cvar_Set (var, v);
	}
}
Beispiel #24
0
/*
============
Cmd_AddCommand
============
*/
void Cmd_AddCommand( const char *cmd_name, xcommand_t function, const char *cmd_desc )
{
	cmd_function_t	*cmd;
	
	// fail if the command already exists
	if(Cmd_Exists( cmd_name ))
	{
		MsgDev(D_INFO, "Cmd_AddCommand: %s already defined\n", cmd_name);
		return;
	}

	// use a small malloc to avoid zone fragmentation
	cmd = Malloc(sizeof(cmd_function_t));
	cmd->name = copystring( cmd_name );
	cmd->desc = copystring( cmd_desc );
	cmd->function = function;
	cmd->next = cmd_functions;
	cmd_functions = cmd;
}
Beispiel #25
0
/*
=====================================
Cmd_GetGameList

Prints or complete gamedir name
=====================================
*/
qboolean Cmd_GetGamesList( const char *s, char *completedname, int length )
{
	int	i, numgamedirs;
	string	gamedirs[MAX_MODS];
	string	matchbuf;

	// stand-alone games doesn't have cmd "game"
	if( !Cmd_Exists( "game" ))
		return false;

	// compare gamelist with current keyword
	for( i = 0, numgamedirs = 0; i < SI.numgames; i++ )
	{
		if(( *s == '*' ) || !Q_strnicmp( SI.games[i]->gamefolder, s, Q_strlen( s )))
			Q_strcpy( gamedirs[numgamedirs++], SI.games[i]->gamefolder ); 
	}

	if( !numgamedirs ) return false;
	Q_strncpy( matchbuf, gamedirs[0], MAX_STRING ); 
	if( completedname && length ) Q_strncpy( completedname, matchbuf, length );
	if( numgamedirs == 1 ) return true;

	for( i = 0; i < numgamedirs; i++ )
	{
		Q_strncpy( matchbuf, gamedirs[i], MAX_STRING ); 
		Msg( "%16s\n", matchbuf );
	}

	Msg( "\n^3 %i games found.\n", numgamedirs );

	// cut shortestMatch to the amount common with s
	if( completedname && length )
	{
		for( i = 0; matchbuf[i]; i++ )
		{
			if( Q_tolower( completedname[i] ) != Q_tolower( matchbuf[i] ))
				completedname[i] = 0;
		}
	}
	return true;
}
Beispiel #26
0
/*
============
Cvar_Get

Adds a newly allocated variable to the variable list or sets its value.
============
*/
cvar_t *Cvar_Get (char *name, char *value, int flags)
{
	cvar_t *cvar;

	if (developer.value)
		Con_Printf("Cvar_Get(\"%s\", \"%s\", %i);\n", name, value, flags);
	
// first check to see if it has already been defined
	cvar = Cvar_FindVar (name);
	if (cvar)
	{
//		cvar->flags |= flags;
//		Cvar_SetQuick_Internal (cvar, value);
		Cvar_Set(cvar->name, value);
		return cvar;
	}

// check for overlap with a command
	if (Cmd_Exists (name))
	{
		Con_Printf("Cvar_Get: %s is a command\n", name);
		return NULL;
	}

// allocate a new cvar, cvar name, and cvar string
// FIXME: these never get Z_Free'd
	cvar = Z_Malloc(sizeof(cvar_t));
//	cvar->flags = flags | CVAR_ALLOCATED;
	cvar->name = Z_Malloc(strlen(name)+1);
	strcpy(cvar->name, name);
	cvar->string = Z_Malloc(strlen(value)+1);
	strcpy(cvar->string, value);
	cvar->value = atof (cvar->string);
//	cvar->integer = (int) cvar->value;

// link the variable in
	cvar->next = cvar_vars;
	cvar_vars = cvar;
	return cvar;
}
Beispiel #27
0
/*
* Con_MessageMode2_f
*/
static void Con_MessageMode2_f( void )
{
    chat_team = Cmd_Exists( "say_team" ); // if not, make it a normal "say: "
    if( cls.state == CA_ACTIVE )
        CL_SetKeyDest( key_message );
}