示例#1
0
bool MConsole::InvokePluginsCommand(const CCommand &command){
	int len = command.ArgC();
	const char **argArray = (const char **) alloca(sizeof(char*) * len);
	for(int i=0; i<len; ++i){
		argArray[i] = command.Arg(i);
	}

	return InvokePluginsCommand(g_MConsole->cmdClient, command.ArgC(), argArray, command.ArgS());
}
bool SizzlingProtect::IsChatExploit( const CCommand &args, int ClientCommandIndex )
{
	const char *pChar = V_strstr( args.ArgS(), "%" );
	while ( pChar )
	{
		if ( !IsValidString(&pChar) )
		{
			return true;
		}
		pChar = V_strstr( pChar, "%" );
	}
	return false;
}
示例#3
0
void ccommand_lua(const CCommand &arg)
{
	if (!g_pLuaInterface)
	{
		Warning("Warning: g_pLuaInterface was a NULL pointer.\n");
		g_pLuaInterface = source_lua::SetupLuaInterface();

		if (!g_pLuaInterface)
		{
			Warning("Fatal Error: g_pLuaInterface was STILL a NULL pointer after recreation.\n");

			return;
		}
	}

	char* cConcencatedArg = (char*)arg.ArgS();

	source_lua::RunString(g_pLuaInterface, cConcencatedArg);
}
// Syntax: cssm_grant steamid
void cssmatch::cssm_grant(const CCommand & args)
{
    ServerPlugin * plugin = ServerPlugin::getInstance();

    if (args.ArgC() > 1)
    {
        I18nManager * i18n = plugin->getI18nManager();
        list<string> * adminlist = plugin->getAdminlist();

        string steamid = args.ArgS();

        // Remove the spaces added between each ":" by the console
        size_t iRemove;
        while((iRemove = steamid.find(' ')) != string::npos)
            steamid.replace(iRemove, 1, "", 0, 0);

        // Remove the quotes
        while((iRemove = steamid.find('"')) != string::npos)
            steamid.replace(iRemove, 1, "", 0, 0);

        // Remove the tab
        while((iRemove = steamid.find('\t')) != string::npos)
            steamid.replace(iRemove, 1, "", 0, 0);

        // Notify the user
        map<string, string> parameters;
        parameters["$steamid"] = steamid;

        list<string>::iterator invalidSteamid = adminlist->end();
        if (find(adminlist->begin(), invalidSteamid, steamid) == invalidSteamid)
        {
            adminlist->push_back(steamid);
            i18n->i18nMsg("admin_new_admin", parameters);

            // Update the player rights if he's connected
            ClanMember * player = NULL;
            CSSMATCH_VALID_PLAYER(PlayerHavingSteamid, steamid, player)
            {
                player->setReferee(true);
            }
示例#5
0
void ChatTriggers::OnSayCommand_Pre(const CCommandContext &context, const CCommand &command)
{
#elif SOURCE_ENGINE >= SE_ORANGEBOX
void ChatTriggers::OnSayCommand_Pre(const CCommand &command)
{
#else
void ChatTriggers::OnSayCommand_Pre()
{
	CCommand command;
#endif
	int client = g_ConCmds.GetCommandClient();
	m_bIsChatTrigger = false;
	m_bWasFloodedMessage = false;
	m_bPluginIgnored = true;

	const char *args = command.ArgS();

	if (!args)
	{
		RETURN_META(MRES_IGNORED);
	}

	/* Save these off for post hook as the command data returned from the engine in older engine versions 
	 * can be NULL, despite the data still being there and valid. */
	m_Arg0Backup = command.Arg(0);
	size_t len = strlen(args);

#if SOURCE_ENGINE == SE_EPISODEONE
	if (m_bIsINS)
	{
		if (strcmp(m_Arg0Backup, "say2") == 0 && len >= 4)
		{
			args += 4;
			len -= 4;
		}

		if (len == 0)
		{
			RETURN_META(MRES_SUPERCEDE);
		}
	}
#endif

	/* The first pair of quotes are stripped from client say commands, but not console ones.
	 * We do not want the forwards to differ from what is displayed.
	 * So only strip the first pair of quotes from client say commands. */
	bool is_quoted = false;

	if (
#if SOURCE_ENGINE == SE_EPISODEONE
		!m_bIsINS && 
#endif
		client != 0 && args[0] == '"' && args[len-1] == '"')
	{
		/* The server normally won't display empty say commands, but in this case it does.
		 * I don't think it's desired so let's block it. */
		if (len <= 2)
		{
			RETURN_META(MRES_SUPERCEDE);
		}

		args++;
		len--;
		is_quoted = true;
	}

	/* Some? engines strip the last quote when printing the string to chat.
	 * This results in having a double-quoted message passed to the OnClientSayCommand ("message") forward,
	 * but losing the last quote in the OnClientSayCommand_Post ("message) forward.
	 * To compensate this, we copy the args into our own buffer where the engine won't mess with
	 * and strip the quotes. */
	delete [] m_ArgSBackup;
	m_ArgSBackup = new char[CCommand::MaxCommandLength()+1];
	memcpy(m_ArgSBackup, args, len+1);

	/* Strip the quotes from the argument */
	if (is_quoted)
	{
		if (m_ArgSBackup[len-1] == '"')
		{
			m_ArgSBackup[--len] = '\0';
		}
	}

	/* The server console cannot do this */
	if (client == 0)
	{
		if (CallOnClientSayCommand(client) >= Pl_Handled)
		{
			RETURN_META(MRES_SUPERCEDE);
		}

		RETURN_META(MRES_IGNORED);
	}

	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);

	/* We guarantee the client is connected */
	if (!pPlayer || !pPlayer->IsConnected())
	{
		RETURN_META(MRES_IGNORED);
	}

	/* Check if we need to block this message from being sent */
	if (ClientIsFlooding(client))
	{
		char buffer[128];

		if (!logicore.CoreTranslate(buffer, sizeof(buffer), "%T", 2, NULL, "Flooding the server", &client))
			UTIL_Format(buffer, sizeof(buffer), "You are flooding the server!");

		/* :TODO: we should probably kick people who spam too much. */

		char fullbuffer[192];
		UTIL_Format(fullbuffer, sizeof(fullbuffer), "[SM] %s", buffer);
		g_HL2.TextMsg(client, HUD_PRINTTALK, fullbuffer);

		m_bWasFloodedMessage = true;

		RETURN_META(MRES_SUPERCEDE);
	}

	bool is_trigger = false;
	bool is_silent = false;

	/* Check for either trigger */
	if (m_PubTriggerSize && strncmp(m_ArgSBackup, m_PubTrigger, m_PubTriggerSize) == 0)
	{
		is_trigger = true;
		args = &m_ArgSBackup[m_PubTriggerSize];
	} 
	else if (m_PrivTriggerSize && strncmp(m_ArgSBackup, m_PrivTrigger, m_PrivTriggerSize) == 0) 
	{
		is_trigger = true;
		is_silent = true;
		args = &m_ArgSBackup[m_PrivTriggerSize];
	}

	/**
	 * Test if this is actually a command!
	 */
	if (is_trigger && PreProcessTrigger(PEntityOfEntIndex(client), args))
	{
		m_bIsChatTrigger = true;

		/**
		 * We'll execute it in post.
		 */
		m_bWillProcessInPost = true;
	}

	if (is_silent && (m_bIsChatTrigger || (g_bSupressSilentFails && pPlayer->GetAdminId() != INVALID_ADMIN_ID)))
	{
		RETURN_META(MRES_SUPERCEDE);
	}

	if (CallOnClientSayCommand(client) >= Pl_Handled)
	{
		RETURN_META(MRES_SUPERCEDE);
	}

	/* Otherwise, let the command continue */
	RETURN_META(MRES_IGNORED);
}
示例#6
0
//// HOST_SAY
// String comes in as
// say blah blah blah
// or as
// blah blah blah
//
void Host_Say( edict_t *pEdict, const CCommand &args, bool teamonly )
{
	CBasePlayer *client;
	int		j;
	char	*p;
	char	text[256];
	char    szTemp[256];
	const char *cpSay = "say";
	const char *cpSayTeam = "say_team";
	const char *pcmd = args[0];
	bool bSenderDead = false;

	// We can get a raw string now, without the "say " prepended
	if ( args.ArgC() == 0 )
		return;

	if ( !stricmp( pcmd, cpSay) || !stricmp( pcmd, cpSayTeam ) )
	{
		if ( args.ArgC() >= 2 )
		{
			p = (char *)args.ArgS();
		}
		else
		{
			// say with a blank message, nothing to do
			return;
		}
	}
	else  // Raw text, need to prepend argv[0]
	{
		if ( args.ArgC() >= 2 )
		{
			Q_snprintf( szTemp,sizeof(szTemp), "%s %s", ( char * )pcmd, (char *)args.ArgS() );
		}
		else
		{
			// Just a one word command, use the first word...sigh
			Q_snprintf( szTemp,sizeof(szTemp), "%s", ( char * )pcmd );
		}
		p = szTemp;
	}

	CBasePlayer *pPlayer = NULL;
	if ( pEdict )
	{
		pPlayer = ((CBasePlayer *)CBaseEntity::Instance( pEdict ));
		Assert( pPlayer );

		// make sure the text has valid content
		p = CheckChatText( pPlayer, p );
	}

	if ( !p )
		return;

	if ( pEdict )
	{
		if ( !pPlayer->CanSpeak() )
			return;

		// See if the player wants to modify of check the text
		pPlayer->CheckChatText( p, 127 );	// though the buffer szTemp that p points to is 256, 
											// chat text is capped to 127 in CheckChatText above

		Assert( strlen( pPlayer->GetPlayerName() ) > 0 );

		bSenderDead = ( pPlayer->m_lifeState != LIFE_ALIVE );
	}
	else
	{
		bSenderDead = false;
	}

	const char *pszFormat = NULL;
	const char *pszPrefix = NULL;
	const char *pszLocation = NULL;
	if ( g_pGameRules )
	{
		pszFormat = g_pGameRules->GetChatFormat( teamonly, pPlayer );
		pszPrefix = g_pGameRules->GetChatPrefix( teamonly, pPlayer );	
		pszLocation = g_pGameRules->GetChatLocation( teamonly, pPlayer );
	}

	const char *pszPlayerName = pPlayer ? pPlayer->GetPlayerName():"Console";

	if ( pszPrefix && strlen( pszPrefix ) > 0 )
	{
		if ( pszLocation && strlen( pszLocation ) )
		{
			Q_snprintf( text, sizeof(text), "%s %s @ %s: ", pszPrefix, pszPlayerName, pszLocation );
		}
		else
		{
			Q_snprintf( text, sizeof(text), "%s %s: ", pszPrefix, pszPlayerName );
		}
	}
	else
	{
		Q_snprintf( text, sizeof(text), "%s: ", pszPlayerName );
	}

	j = sizeof(text) - 2 - strlen(text);  // -2 for /n and null terminator
	if ( (int)strlen(p) > j )
		p[j] = 0;

	Q_strncat( text, p, sizeof( text ), COPY_ALL_CHARACTERS );
	Q_strncat( text, "\n", sizeof( text ), COPY_ALL_CHARACTERS );
 
	// loop through all players
	// Start with the first player.
	// This may return the world in single player if the client types something between levels or during spawn
	// so check it, or it will infinite loop

	client = NULL;
	for ( int i = 1; i <= gpGlobals->maxClients; i++ )
	{
		client = ToBaseMultiplayerPlayer( UTIL_PlayerByIndex( i ) );
		if ( !client || !client->edict() )
			continue;
		
		if ( client->edict() == pEdict )
			continue;

		if ( !(client->IsNetClient()) )	// Not a client ? (should never be true)
			continue;

		if ( teamonly && g_pGameRules->PlayerCanHearChat( client, pPlayer ) != GR_TEAMMATE )
			continue;

		if ( pPlayer && !client->CanHearAndReadChatFrom( pPlayer ) )
			continue;

		if ( pPlayer && GetVoiceGameMgr() && GetVoiceGameMgr()->IsPlayerIgnoringPlayer( pPlayer->entindex(), i ) )
			continue;

		CSingleUserRecipientFilter user( client );
		user.MakeReliable();

		if ( pszFormat )
		{
			UTIL_SayText2Filter( user, pPlayer, true, pszFormat, pszPlayerName, p, pszLocation );
		}
		else
		{
			UTIL_SayTextFilter( user, text, pPlayer, true );
		}
	}

	if ( pPlayer )
	{
		// print to the sending client
		CSingleUserRecipientFilter user( pPlayer );
		user.MakeReliable();

		if ( pszFormat )
		{
			UTIL_SayText2Filter( user, pPlayer, true, pszFormat, pszPlayerName, p, pszLocation );
		}
		else
		{
			UTIL_SayTextFilter( user, text, pPlayer, true );
		}
	}

	// echo to server console
	// Adrian: Only do this if we're running a dedicated server since we already print to console on the client.
	if ( engine->IsDedicatedServer() )
		 Msg( "%s", text );

	Assert( p );

	int userid = 0;
	const char *networkID = "Console";
	const char *playerName = "Console";
	const char *playerTeam = "Console";
	if ( pPlayer )
	{
		userid = pPlayer->GetUserID();
		networkID = pPlayer->GetNetworkIDString();
		playerName = pPlayer->GetPlayerName();
		CTeam *team = pPlayer->GetTeam();
		if ( team )
		{
			playerTeam = team->GetName();
		}
	}
		
	if ( teamonly )
		UTIL_LogPrintf( "\"%s<%i><%s><%s>\" say_team \"%s\"\n", playerName, userid, networkID, playerTeam, p );
	else
		UTIL_LogPrintf( "\"%s<%i><%s><%s>\" say \"%s\"\n", playerName, userid, networkID, playerTeam, p );

	IGameEvent * event = gameeventmanager->CreateEvent( "player_say" );

	if ( event )	// will be null if there are no listeners!
	{
		event->SetInt("userid", userid );
		event->SetString("text", p );
		event->SetInt("priority", 1 );	// HLTV event priority, not transmitted
		gameeventmanager->FireEvent( event );
	}
}
示例#7
0
void MConsole::OnSayCommand_Pre(void *pUnknown, const CCommand &command){
	if(strcmp(command.Arg(0), "say") != 0 && strcmp(command.Arg(0), "say_team")){
		return;
	}

	int client = g_MConsole->cmdClient;
	auto player = playerhelpers->GetGamePlayer(client);


	if(client == 0 || player == NULL) RETURN_META(MRES_IGNORED);
	if(!player->IsConnected()) RETURN_META(MRES_IGNORED);


	const char *argsTmp = command.ArgS();
	if(argsTmp == NULL) RETURN_META(MRES_IGNORED);

	char *args = (char*) alloca(strlen(argsTmp) + 1);
	strcpy(args, argsTmp);

	// Remove quotes
	if(args[0] == '"' && strlen(args) > 2){
		args = &args[1];
		int len = strlen(args);
		if(args[len - 1] == '"') args[len - 1] = '\0';
	}

	

	bool isTrigger = false;
	bool isSilent = false;

	if(args[0] == '-'){
		isTrigger = true;
	}else if(args[0] == '/'){
		isTrigger = true;
		isSilent = true;
	}

	// Args: ["say" "-command" "arg1" "arg2"]

	if(isTrigger){
		args = &args[1]; // Skip the - or /

		int MAX_ARGS = 16;
		char **argArray = new char*[MAX_ARGS];
		int numArgs = 1;
		int curArgPos = 0;

		argArray[0] = new char[256];
		argArray[0][0] = '\0';
		int len = strlen(args);
		bool inQuotes = false;
		bool quotesType = -1;
		for(int i = 0; i < len; ++i){
			if(quotesType == 0 && args[i] == '"'){
				inQuotes = false;
			}else if(quotesType == 1 && args[i] == '\''){
				inQuotes = false;
			}else if(args[i] == '"'){
				inQuotes = true;
				quotesType = 0;
			}else if(args[i] == '\''){
				inQuotes = true;
				quotesType = 1;
			}else if(args[i] == ' ' && !inQuotes && numArgs < MAX_ARGS){
				argArray[numArgs - 1][curArgPos] = '\0';
				++numArgs;

				argArray[numArgs - 1] = new char[256];
				argArray[numArgs - 1][curArgPos] = '\0';
				curArgPos = 0;
			}else{
				argArray[numArgs - 1][curArgPos++] = args[i];
			}
		}

		argArray[numArgs - 1][curArgPos] = '\0';

		if(g_MConsole->InvokePluginsCommand(client, curArgPos == 0 ? numArgs - 1 : numArgs, (const char **) argArray, args) && isSilent){
			for(int i = 0; i < numArgs; ++i) delete[] argArray[i];
			delete[] argArray;
			RETURN_META(MRES_SUPERCEDE);
		}

		for(int i = 0; i < numArgs; ++i) delete[] argArray[i];
		delete[] argArray;
	}
}
// Syntax: cssm_start [configuration file from cstrike/cfg/cssmatch/configurations [-cutround]
// [-warmup]]
void cssmatch::cssm_start(const CCommand & args)
{
    ServerPlugin * plugin = ServerPlugin::getInstance();
    I18nManager * i18n = plugin->getI18nManager();
    MatchManager * match = plugin->getMatch();

    bool kniferound = true;
    bool warmup = true;
    string configurationFile = DEFAULT_CONFIGURATION_FILE;

    switch(args.ArgC())
    {
    case 4:
    case 3:
        kniferound = string(args.ArgS()).find("-kniferound") == string::npos;
        warmup = string(args.ArgS()).find("-warmup") == string::npos;
    // break;
    case 2:
        configurationFile = args.Arg(1);
    // break;
    case 1:
        try
        {
            RunnableConfigurationFile configuration(
                CFG_FOLDER_PATH MATCH_CONFIGURATIONS_PATH + configurationFile);

            // Determine the initial match state
            BaseMatchState * initialState = NULL;
            if (plugin->getConVar("cssmatch_kniferound")->GetBool() && kniferound)
            {
                initialState = KnifeRoundMatchState::getInstance();
            }
            else if ((plugin->getConVar("cssmatch_warmup_time")->GetInt() > 0) && warmup)
            {
                initialState = WarmupMatchState::getInstance();
            }
            else if (plugin->getConVar("cssmatch_sets")->GetInt() > 0)
            {
                initialState = HalfMatchState::getInstance();
            }
            else // Error case
            {
                RecipientFilter recipients;
                recipients.addAllPlayers();
                i18n->i18nChatWarning(recipients, "match_config_error");
            }
            match->start(configuration, warmup, initialState);

            /*RecipientFilter recipients;
            recipients.addAllPlayers();
            i18n->i18nChatSay(recipients,"match_started");*/
        }
        catch(const ConfigurationFileException & e)
        {
            map<string, string> parameters;
            parameters["$file"] = configurationFile;

            i18n->i18nMsg("error_file_not_found", parameters);
        }
        catch(const MatchManagerException & e)
        {
            i18n->i18nMsg("match_in_progress");
        }
        break;
    default:
        Msg(
            "cssm_start [configuration file from cstrike/cfg/cssmatch/configurations [-cutround] [-warmup]]\n");
    }
}
示例#9
0
	const char *ArgS() const
	{
		return cmd->ArgS();
	}
void ChatTriggers::OnSayCommand_Pre(const CCommand &command)
{
#else
void ChatTriggers::OnSayCommand_Pre()
{
	CCommand command;
#endif
	int client;
	CPlayer *pPlayer;
	
	client = g_ConCmds.GetCommandClient();
	m_bIsChatTrigger = false;
	m_bWasFloodedMessage = false;

	/* The server console cannot do this */
	if (client == 0 || (pPlayer = g_Players.GetPlayerByIndex(client)) == NULL)
	{
		RETURN_META(MRES_IGNORED);
	}

	/* We guarantee the client is connected */
	if (!pPlayer->IsConnected())
	{
		RETURN_META(MRES_IGNORED);
	}

	const char *args = command.ArgS();
	
	if (!args)
	{
		RETURN_META(MRES_IGNORED);
	}

	/* Check if we need to block this message from being sent */
	if (ClientIsFlooding(client))
	{
		char buffer[128];

		/* :TODO: log an error? */
		if (g_Translator.CoreTransEx(g_pFloodPhrases, 
			client, 
			buffer, 
			sizeof(buffer),
			"Flooding the server",
			NULL,
			NULL)
			!= Trans_Okay)
		{
			UTIL_Format(buffer, sizeof(buffer), "You are flooding the server!");
		}

		/* :TODO: we should probably kick people who spam too much. */

		char fullbuffer[192];
		UTIL_Format(fullbuffer, sizeof(fullbuffer), "[SM] %s", buffer);
		g_HL2.TextMsg(client, HUD_PRINTTALK, fullbuffer);

		m_bWasFloodedMessage = true;

		RETURN_META(MRES_SUPERCEDE);
	}

	/* Handle quoted string sets */
	bool is_quoted = false;
	if (args[0] == '"')
	{
		args++;
		is_quoted = true;
	}

	bool is_trigger = false;
	bool is_silent = false;

	/* Check for either trigger */
	if (m_PubTriggerSize && strncmp(args, m_PubTrigger, m_PubTriggerSize) == 0)
	{
		is_trigger = true;
		args = &args[m_PubTriggerSize];
	} 
	else if (m_PrivTriggerSize && strncmp(args, m_PrivTrigger, m_PrivTriggerSize) == 0) 
	{
		is_trigger = true;
		is_silent = true;
		args = &args[m_PrivTriggerSize];
	}

	if (!is_trigger)
	{
		RETURN_META(MRES_IGNORED);
	}

	/**
	 * Test if this is actually a command!
	 */
	if (!PreProcessTrigger(engine->PEntityOfEntIndex(client), args, is_quoted))
	{
		CPlayer *pPlayer;
		if (is_silent 
			&& g_bSupressSilentFails 
			&& client != 0
			&& (pPlayer = g_Players.GetPlayerByIndex(client)) != NULL
			&& pPlayer->GetAdminId() != INVALID_ADMIN_ID)
		{
			RETURN_META(MRES_SUPERCEDE);
		}
		RETURN_META(MRES_IGNORED);
	}

	m_bIsChatTrigger = true;

	/**
	 * We'll execute it in post.
	 */
	m_bWillProcessInPost = true;
	m_bTriggerWasSilent = is_silent;

	/* If we're silent, block */
	if (is_silent)
	{
		RETURN_META(MRES_SUPERCEDE);
	}

	/* Otherwise, let the command continue */
	RETURN_META(MRES_IGNORED);
}