コード例 #1
0
//
//	Name: CC_BalanceMacroReport( const CCommand& args )
//	Author: Hekar Khani
//	Description: ConCommand to display a simple report of the current balance macros
//	Notes:
//
void CC_BalanceMacroReport( const CCommand& args )
{
	ConCommandBase *Command = cvar->GetCommands();
	for ( ; Command != NULL; Command = Command->GetNext())
	{
		ConVar *convar = dynamic_cast< ConVar * > ( Command );
		if ( !convar )
		{
			continue;
		}

		const char *convarname = convar->GetName();
		if ( Q_strstr( convarname, "lfm" ) )
		{
			Msg( "Name: %s\t\tValue: %s\t\tDesc: %s\n", convar->GetName(), convar->GetString(), convar->GetHelpText() );
		}
	}
}
コード例 #2
0
//
//	Name: CC_BalanceMacroReport( const CCommand& args )
//	Author: Hekar Khani
//	Description: ConCommand to display a report of the current balance macros in CSV format
//	Notes:
//
void CC_BalanceMacroReportCSV( const CCommand& args )
{
	// HODO: add ability to write to file
	ConCommandBase *Command = cvar->GetCommands();
	for ( ; Command != NULL; Command = Command->GetNext())
	{
		ConVar *convar = dynamic_cast< ConVar * > ( Command );
		if ( !convar )
		{
			continue;
		}

		Msg( "Convar, Value, Description\n" );
		const char *convarname = convar->GetName();
		if ( Q_strstr( convarname, "lfm" ) )
		{
			Msg( "%s, %s, %s\n", convar->GetName(), convar->GetString(), convar->GetHelpText() );
		}
	}
}
コード例 #3
0
ファイル: smn_console.cpp プロジェクト: pmrowla/sourcemod-1.5
static cell_t sm_GetConVarName(IPluginContext *pContext, const cell_t *params)
{
	Handle_t hndl = static_cast<Handle_t>(params[1]);
	HandleError err;
	ConVar *pConVar;

	if ((err=g_ConVarManager.ReadConVarHandle(hndl, &pConVar))
		!= HandleError_None)
	{
		return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
	}

	pContext->StringToLocalUTF8(params[2], params[3], pConVar->GetName(), NULL);

	return 1;
}
コード例 #4
0
ファイル: convar.cpp プロジェクト: xxauroraxx/Source.Python
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void ConVar_PrintDescription( const ConCommandBase *pVar )
{
	bool bMin, bMax;
	float fMin, fMax;
	const char *pStr;

	assert( pVar );

	Color clr;
	clr.SetColor( 255, 100, 100, 255 );

	if ( !pVar->IsCommand() )
	{
		ConVar *var = ( ConVar * )pVar;
		const ConVar_ServerBounded *pBounded = dynamic_cast<const ConVar_ServerBounded*>( var );

		bMin = var->GetMin( fMin );
		bMax = var->GetMax( fMax );

		const char *value = NULL;
		char tempVal[ 32 ];

		if ( pBounded || var->IsFlagSet( FCVAR_NEVER_AS_STRING ) )
		{
			value = tempVal;
			
			int intVal = pBounded ? pBounded->GetInt() : var->GetInt();
			float floatVal = pBounded ? pBounded->GetFloat() : var->GetFloat();

			if ( fabs( (float)intVal - floatVal ) < 0.000001 )
			{
				Q_snprintf( tempVal, sizeof( tempVal ), "%d", intVal );
			}
			else
			{
				Q_snprintf( tempVal, sizeof( tempVal ), "%f", floatVal );
			}
		}
		else
		{
			value = var->GetString();
		}

		if ( value )
		{
			ConColorMsg( clr, "\"%s\" = \"%s\"", var->GetName(), value );

			if ( stricmp( value, var->GetDefault() ) )
			{
				ConMsg( " ( def. \"%s\" )", var->GetDefault() );
			}
		}

		if ( bMin )
		{
			ConMsg( " min. %f", fMin );
		}
		if ( bMax )
		{
			ConMsg( " max. %f", fMax );
		}

		ConMsg( "\n" );

		// Handled virtualized cvars.
		if ( pBounded && fabs( pBounded->GetFloat() - var->GetFloat() ) > 0.0001f )
		{
			ConColorMsg( clr, "** NOTE: The real value is %.3f but the server has temporarily restricted it to %.3f **\n",
				var->GetFloat(), pBounded->GetFloat() );
		}
	}
	else
	{
		ConCommand *var = ( ConCommand * )pVar;

		ConColorMsg( clr, "\"%s\"\n", var->GetName() );
	}

	ConVar_PrintFlags( pVar );

	pStr = pVar->GetHelpText();
	if ( pStr && pStr[0] )
	{
		ConMsg( " - %s\n", pStr );
	}
}
コード例 #5
0
//-----------------------------------------------------------------------------
// Purpose: rebuilds the list of possible completions from the current entered text
//-----------------------------------------------------------------------------
void CConsolePanel::RebuildCompletionList(const char *text)
{
	ClearCompletionList();

	// we need the length of the text for the partial string compares
	int len = Q_strlen(text);
	if ( len < 1 )
	{
		// Fill the completion list with history instead
		for ( int i = 0 ; i < m_CommandHistory.Count(); i++ )
		{
			CHistoryItem *item = &m_CommandHistory[ i ];
			CompletionItem *comp = new CompletionItem();
			m_CompletionList.AddToTail( comp );
			comp->m_bIsCommand = false;
			comp->m_pCommand = NULL;
			comp->m_pText = new CHistoryItem( *item );
		}
		return;
	}

	bool bNormalBuild = true;

	// if there is a space in the text, and the command isn't of the type to know how to autocomplet, then command completion is over
	const char *space = strstr( text, " " );
	if ( space )
	{
		ConCommand *pCommand = FindAutoCompleteCommmandFromPartial( text );
		if ( !pCommand )
			return;

		bNormalBuild = false;

		CUtlVector< CUtlString > commands;
		int count = pCommand->AutoCompleteSuggest( text, commands );
		Assert( count <= COMMAND_COMPLETION_MAXITEMS );
		int i;

		for ( i = 0; i < count; i++ )
		{
			// match found, add to list
			CompletionItem *item = new CompletionItem();
			m_CompletionList.AddToTail( item );
			item->m_bIsCommand = false;
			item->m_pCommand = NULL;
			item->m_pText = new CHistoryItem( commands[ i ].String() );
		}
	}
				 
	if ( bNormalBuild )
	{
		// look through the command list for all matches
		ConCommandBase const *cmd = (ConCommandBase const *)cvar->GetCommands();
		while (cmd)
		{
			if ( cmd->IsFlagSet( FCVAR_DEVELOPMENTONLY ) || cmd->IsFlagSet( FCVAR_HIDDEN ) )
			{
				cmd = cmd->GetNext();
				continue;
			}

			if ( !strnicmp(text, cmd->GetName(), len))
			{
				// match found, add to list
				CompletionItem *item = new CompletionItem();
				m_CompletionList.AddToTail( item );
				item->m_pCommand = (ConCommandBase *)cmd;
				const char *tst = cmd->GetName();
				if ( !cmd->IsCommand() )
				{
					item->m_bIsCommand = false;
					ConVar *var = ( ConVar * )cmd;
					ConVar_ServerBounded *pBounded = dynamic_cast<ConVar_ServerBounded*>( var );
					if ( pBounded || var->IsFlagSet( FCVAR_NEVER_AS_STRING ) )
					{
						char strValue[512];
						
						int intVal = pBounded ? pBounded->GetInt() : var->GetInt();
						float floatVal = pBounded ? pBounded->GetFloat() : var->GetFloat();
						
						if ( floatVal == intVal )
							Q_snprintf( strValue, sizeof( strValue ), "%d", intVal );
						else
							Q_snprintf( strValue, sizeof( strValue ), "%f", floatVal );

						item->m_pText = new CHistoryItem( var->GetName(), strValue );
					}
					else
					{
						item->m_pText = new CHistoryItem( var->GetName(), var->GetString() );
					}
				}
				else
				{
					item->m_bIsCommand = true;
					item->m_pText = new CHistoryItem( tst );
				}
			}

			cmd = cmd->GetNext();
		}

		// Now sort the list by command name
		if ( m_CompletionList.Count() >= 2 )
		{
			for ( int i = 0 ; i < m_CompletionList.Count(); i++ )
			{
				for ( int j = i + 1; j < m_CompletionList.Count(); j++ )
				{
					const CompletionItem *i1, *i2;
					i1 = m_CompletionList[ i ];
					i2 = m_CompletionList[ j ];

					if ( Q_stricmp( i1->GetName(), i2->GetName() ) > 0 )
					{
						CompletionItem *temp = m_CompletionList[ i ];
						m_CompletionList[ i ] = m_CompletionList[ j ];
						m_CompletionList[ j ] = temp;
					}
				}
			}
		}
	}

}
コード例 #6
0
void ConVarManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command)
{
	int argcount = command->ArgC();
	if (argcount >= 3)
	{
		bool wantReset = false;
		
		/* Get plugin index that was passed */
		const char *arg = command->Arg(2);
		if (argcount >= 4 && strcmp(arg, "reset") == 0)
		{
			wantReset = true;
			arg = command->Arg(3);
		}
		
		/* Get plugin object */
		IPlugin *plugin = scripts->FindPluginByConsoleArg(arg);

		if (!plugin)
		{
			UTIL_ConsolePrint("[SM] Plugin \"%s\" was not found.", arg);
			return;
		}

		/* Get plugin name */
		const sm_plugininfo_t *plinfo = plugin->GetPublicInfo();
		const char *plname = IS_STR_FILLED(plinfo->name) ? plinfo->name : plugin->GetFilename();

		ConVarList *pConVarList;
		ConVarList::iterator iter;

		/* If no convar list... */
		if (!plugin->GetProperty("ConVarList", (void **)&pConVarList))
		{
			UTIL_ConsolePrint("[SM] No convars found for: %s", plname);
			return;
		}

		if (!wantReset)
		{
			UTIL_ConsolePrint("[SM] Listing %d convars for: %s", pConVarList->size(), plname);
			UTIL_ConsolePrint("  %-32.31s %s", "[Name]", "[Value]");
		}
		
		/* Iterate convar list and display/reset each one */
		for (iter = pConVarList->begin(); iter != pConVarList->end(); iter++)
		{
			/*const */ConVar *pConVar = const_cast<ConVar *>(*iter);
			if (!wantReset)
			{
				UTIL_ConsolePrint("  %-32.31s %s", pConVar->GetName(), pConVar->GetString()); 
			} else {
				pConVar->Revert();
			}
		}
		
		if (wantReset)
		{
			UTIL_ConsolePrint("[SM] Reset %d convars for: %s", pConVarList->size(), plname);
		}

		return;
	}

	/* Display usage of subcommand */
	UTIL_ConsolePrint("[SM] Usage: sm cvars [reset] <plugin #>");
}