All pastes #608174 Raw Edit

Something

public text v1 · immutable
·published 2007-07-08 03:14 UTC
rendered paste body
#include <iostream>
#include "bzfsAPI.h"

BZ_GET_PLUGIN_VERSION

class spooferHandler : public bz_CustomSlashCommandHandler {
public: virtual bool handle(int playerID, bzApiString command, bzApiString message, bzAPIStringList *params);
};

spooferHandler spoof;

BZF_PLUGIN_CALL int bz_Load ( const char* /*commandLine*/ ) {
	bz_debugMessage(4,"spoof plugin loaded");
	bz_registerCustomSlashCommand("spoof", &spoof);
	bz_registerCustomSlashCommand("aspoof", &spoof);

	return 0;
}

BZF_PLUGIN_CALL int bz_Unload ( void ) {
	bz_debugMessage(4,"spoof plugin unloaded");
	bz_removeCustomSlashCommand("spoof");
	bz_removeCustomSlashCommand("aspoof");

	return 0;
}

bool spooferHandler::handle(int playerID, bzApiString command, bzApiString message, bzAPIStringList *params) {
	int paramSize = params->size();

	if (bz_hasPerm(playerID, "spoof") || bz_hasPerm(playerID, "aspoof")) {
		if (paramSize == 0 || paramSize == 1) {
			bz_sendTextMessage(BZ_SERVER, playerID, "Spoofer Usage: <player slot> <message>");
			return true;
		}
	} else {
		bz_sendTextMessagef(BZ_SERVER, playerID, "Spoofer: You do not have permission to use the %s command.", command.c_str());
		return true;
	}

	int slot = atoi(params->get(0).c_str());

	std::string spoofedMessage;
	for (unsigned int i = 1; i < params->size(); i++) {
		spoofedMessage += params->get(i).c_str();
		if (!(i == params->size() - 1)) // so we don't stick a whitespace on the end
			spoofedMessage += " "; // add a whitespace between each chat text parameter
	}

	bzAPIIntList *playerList = bz_newIntList();
	bz_getPlayerIndexList(playerList);
	bz_PlayerRecord *data = bz_getPlayerByIndex(playerList->get(playerID));

	std::string playerName = data->callsign.c_str();

	bz_freePlayerRecord(data);

	if (slot == 0 && params->get(0) == "0") { // Fix for int check and for slot # itself (slot 0)

		if (command == "spoof" && bz_hasPerm(playerID, "spoof")) { // Normal spoof or aspoof?
			bz_sendTextMessagef(BZ_SERVER, eAdministrators, "Spoofer: %s spoofed slot %d.", playerName.c_str(), slot);
		}

		bz_sendTextMessage(slot, BZ_ALLUSERS, spoofedMessage.c_str());
	} else if (slot != 0) { // All other slot numbers

		if (command == "spoof" && bz_hasPerm(playerID, "spoof")) { // Normal spoof or aspoof?
			bz_sendTextMessagef(BZ_SERVER, eAdministrators, "Spoofer: %s spoofed slot %d.", playerName.c_str(), slot);
		}

		bz_sendTextMessage(slot, BZ_ALLUSERS, spoofedMessage.c_str());
	} else {
		bz_sendTextMessage(BZ_SERVER, playerID, "Spoofer Usage: <player slot> <message>");
		return true;
	}

	return true;

}