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
}