Пример #1
0
//-----------------------------------------------------------------------------
// Returns a CServerCommandManager instance.
//-----------------------------------------------------------------------------
CServerCommandManager* CServerCommandManager::CreateCommand(const char* szName,
	const char* szHelpText, int iFlags)
{
	// Copy the name and store a help text copier value
	char* szNameCopy = strdup(szName);
	char* szHelpTextCopy = NULL;

	// FInd if the command already exists
	ConCommand* pConCommand = g_pCVar->FindCommand(szName);
	if( pConCommand )
	{
		// Store the current command's help text and flags
		szHelpTextCopy = strdup(pConCommand->GetHelpText());
		iFlags = pConCommand->m_nFlags;

		// Unregister the old command
		g_pCVar->UnregisterConCommand(pConCommand);
	}
	else if( szHelpText != NULL )
	{
		// Store the given help text
		szHelpTextCopy = strdup(szHelpText);
	}

	// Return a new instance of ConCommand
	return new CServerCommandManager(pConCommand, szNameCopy, szHelpTextCopy, iFlags);
}
// Syntax: cssm_help [command name]
void cssmatch::cssm_help(const CCommand & args)
{
    ServerPlugin * plugin = ServerPlugin::getInstance();

    const map<string, ConCommand *> * pluginConCommands = plugin->getPluginConCommands();
    map<string, ConCommand *>::const_iterator lastConCommand = pluginConCommands->end();

    if (args.ArgC() == 1)
    {
        map<string, ConCommand *>::const_iterator itConCommand = pluginConCommands->begin();
        while (itConCommand != lastConCommand)
        {
            ConCommand * command = itConCommand->second;

            const char * helpText = command->GetHelpText();
            Msg("%s\n", helpText);
            delete [] helpText;

            itConCommand++;
        }
    }
    else
    {
        string commandName = args.Arg(1);
        map<string, ConCommand *>::const_iterator itConCommand = pluginConCommands->find(
            commandName);
        if (itConCommand != lastConCommand)
        {
            const char * helpText = itConCommand->second->GetHelpText();
            Msg("%s\n", helpText);
            delete [] helpText;
        }
        else
        {
            I18nManager * i18n = plugin->getI18nManager();

            map<string, string> parameters;
            parameters["$command"] = commandName;
            i18n->i18nMsg("error_command_not_found", parameters);
        }
    }
}