1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
// customPollTypeSample.cpp : Defines the entry point for the DLL application.
//
#include "bzfsAPI.h"
#include "plugin_utils.h"
class customPollTypeSample : public bz_Plugin, public bz_CustomPollTypeHandler
{
public:
virtual const char* Name ()
{
return "Custom Poll Type";
}
virtual void Init ( const char* config );
virtual void Cleanup ( void );
virtual void Event ( bz_EventData * /* eventData */ )
{
return;
}
virtual bool PollOpen (bz_BasePlayerRecord *player, const char* action, const char* parameters);
virtual void PollClose (const char* action, const char* parameters, bool success);
};
BZ_PLUGIN(customPollTypeSample)
void customPollTypeSample::Init ( const char* /*commandLine*/ )
{
// This will introduce a '/poll mute callsign' option
bz_registerCustomPollType("mute", "callsign", this);
}
void customPollTypeSample::Cleanup ()
{
Flush();
// Remove the poll option when this plugin is loaded or else what other plugin would handle it?
bz_removeCustomPollType("mute");
}
// This function is called before a `/poll mute <callsign>` poll is started. If this function returns false, then the poll will not
// start. This is useful for checking permissions or other conditions.
bool customPollTypeSample::PollOpen(bz_BasePlayerRecord *player, const char* action, const char* /*parameters*/)
{
int playerID = player->playerID;
std::string _action = action;
// If a player doesn't have the 'poll' permission, they will not be able to start a poll. Be sure to send the playerID a message
// or else it'll appear as if the /poll command did not work.
if (!bz_hasPerm(playerID, "pollMute"))
{
bz_sendTextMessage(BZ_SERVER, playerID, "You can't start a poll!");
return false;
}
// The 'action' variable will be set whichever poll option is being called
if (_action == "mute")
{
// Return true in order to let BZFS start the poll
return true;
}
// This should never be reached but it'll take care of compiler warnings
return false;
}
void customPollTypeSample::PollClose(const char* action, const char* parameters, bool success)
{
std::string _action = action;
std::string _parameters = parameters;
if (_action == "mute" && success)
{
bz_BasePlayerRecord *pr = bz_getPlayerBySlotOrCallsign(_parameters.c_str());
if (!pr)
{
bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "player %s not found", _parameters.c_str());
return;
}
// Poll succeeded, so mute the player
bz_revokePerm(pr->playerID, "talk");
bz_freePlayerRecord(pr);
}
}
// Local Variables: ***
// mode: C++ ***
// tab-width: 4 ***
// c-basic-offset: 4 ***
// indent-tabs-mode: nil ***
// End: ***
// ex: shiftwidth=4 tabstop=4
|