Plug-in API Custom Slash Commands Change

Questions, comments, and news on the server side plug-ins and it's API
Post Reply
User avatar
allejo
Breaker of Builds
Breaker of Builds
Posts: 648
Joined: Sun Feb 17, 2008 10:01 pm
Location: /dev/null
Contact:

Plug-in API Custom Slash Commands Change

Post by allejo » Fri Apr 03, 2015 4:23 am

As of commit 159b068c, the plug-in API now allows you overload built-in slash commands meaning you can disable built-in slash commands completely or give them custom functionality.

Here's a quick and dirty example of how to take advantage of this functionality by allowing hidden admins to kick without revealing their callsigns to the player who was kicked. SlashCommand() should return false if you want BZFS to handle the command and it should return true if the plug-in will be handling it. All custom slash commands that don't overload built-in commands should always return true to prevent BZFS from sending the "Unknown command" messages should bz_eUnknownSlashCommand not handle the unknown slash command.

Code: Select all

void SAMPLE_PLUGIN::Init (const char* commandLine)
{
    // Register our slash commands, especially the ones we're overloading
    bz_registerCustomSlashCommand("foo", this);
    bz_registerCustomSlashCommand("kick", this);
    bz_registerCustomSlashCommand("gameover", this);
}

void SAMPLE_PLUGIN::Cleanup (void)
{
    Flush(); // Clean up all the events

    // Unregister our slash commands. Yes, even the ones we overloaded because
    // they are still registered as being custom
    bz_removeCustomSlashCommand("foo");
    bz_removeCustomSlashCommand("kick");
    bz_removeCustomSlashCommand("gameover");
}

bool SAMPLE_PLUGIN::SlashCommand(int playerID, bz_ApiString command, bz_ApiString /*message*/, bz_APIStringList *params)
{
    if (command == "foo")
    {
        bz_sendTextMessage(BZ_SERVER, playerID, "A custom slash command still works as usual.");

        return true;
    }
    else if (command == "kick")
    {
        // A hidden admin wants to kick a player without revealing their identity
        if (bz_hasPerm(playerID, "hideadmin")
        {
            bz_kickUser(atoi(std::string(params->get(0)).erase(0,1)), params->get(1).c_str(), 1);
            bz_sendTextMessage(BZ_SERVER, playerID, "You are a hidden admin, so I've kicked the player without revealing your callsign.");

            return true; // Handle the kicking so BZFS doesn't reveal the admin's identity
        }

        bz_sendTextMessage(BZ_SERVER, playerID, "You are not a hidden admin so BZFS will handle the kicking.");

        return false; // We don't want to handle the functionality, so returning false tells BZFS to handle it
    }
    else if (command == "gameover")
    {
        bz_sendTextMessage(BZ_SERVER, playerID, "We have disabled /gameover on this server completely.");

        return true; // We want to disable /gameover so by returning true, we get complete control of the slash command
    }

    return false; // Will never be reached, but just in case, return false to have BZFS as the fallback
}
* Please note, this isn't meant to be a complete solution as this method will not accept callsigns in the /kick command; this is merely an example.
Here's my personal website and my open source projects are available on GitHub; I work on a lot of cool things.

Image

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests