All pastes #281658 Raw Edit

onePlayerPerm source

public text v1 · immutable
#281658 ·published 2006-12-16 23:26 UTC
rendered paste body
// oneUserPerm.cpp : Defines the entry point for the DLL application.
//

#include "bzfsAPI.h"
#include <fstream>
#include <string>
#include <list>

BZ_GET_PLUGIN_VERSION

std::string perm;
int assigned = -1;

class Assigner : public bz_EventHandler
{
public:
  virtual void process ( bz_EventData *eventData )
  {
    bzAPIIntList *playerList = bz_newIntList();
    bz_getPlayerIndexList (playerList);

    if (playerList->size() == 1 && assigned == -1) {
      if (!bz_hasPerm(playerList->get(0), perm.c_str()) && bz_hasPerm(playerList->get(0), bz_perm_say)) {
        assigned = playerList->get(0);
        bz_grantPerm(assigned, perm.c_str());
      }
      else assigned = -2;
    }
    else if (playerList->size() != 1 && assigned != -1) {
      if (assigned != -2) bz_revokePerm(assigned, perm.c_str());
      assigned = -1;
    }

    bz_deleteIntList(playerList);
  }
};

Assigner oneUserPermer;

BZF_PLUGIN_CALL int bz_Load ( const char* commandLine )
{
  bz_debugMessage(4,"oneUserPerm plugin loaded");
  perm = commandLine;
  bz_registerEvent(bz_eTickEvent,&oneUserPermer);
  return 0;
}

BZF_PLUGIN_CALL int bz_Unload ( void )
{
  bz_removeEvent(bz_eTickEvent,&oneUserPermer);
  bz_debugMessage(4,"oneUserPerm plugin unloaded");
  return 0;
}

// Local Variables: ***
// mode:C++ ***
// tab-width: 8 ***
// c-basic-offset: 2 ***
// indent-tabs-mode: t ***
// End: ***
// ex: shiftwidth=2 tabstop=8