All pastes #19445 Raw Edit

wegstar

public text v1 · immutable
#19445 ·published 2005-08-06 16:35 UTC
rendered paste body
// SAMPLE_PLUGIN.cpp : Defines the entry point for the DLL application.
//

#include "bzfsAPI.h"
#include <string>
#include <cstdlib>
#include <ctime>

extern std::string strtoupper(std::string strtoconv);
bool yesBot = true;
BZ_GET_PLUGIN_VERSION


class BZFSBotHandler : public bz_EventHandler
{
public:
	BZFSBotHandler();
	virtual ~BZFSBotHandler();

	virtual void process ( bz_EventData *eventData );

	virtual bool autoDelete ( void ) { return false;} // this will be used for more then one event

};
BZFSBotHandler bot;

BZF_PLUGIN_CALL int bz_Load ( const char* commandLine )
{
	bz_debugMessage(1,"BZFSBot plugin loaded. Party Time!");
	bz_registerEvent(bz_eChatMessageEvent,BZ_ALL_USERS,&bot);
	return 0;
	
}

BZF_PLUGIN_CALL int bz_Unload ( void )
{
	bz_debugMessage(1,"BZFSBot plugin unloaded. Load me next time ;)");
	bz_removeEvent(bz_eChatMessageEvent,BZ_ALL_USERS,&bot);
	return 0;
}

BZFSBotHandler::BZFSBotHandler()
{
}
BZFSBotHandler::~BZFSBotHandler()
{
}


void BZFSBotHandler::process ( bz_EventData *eventData )
{
	switch (eventData->eventType)
	{
	default:
		break;

	case bz_eChatMessageEvent:
		{
			bz_ChatEventData *chat = (bz_ChatEventData*)eventData;
			
			/*Do stuff here, ie.e set vars up*/
			int sender = chat->from;
			std::string message = chat->message.c_str();//convert bzAPI string to std::string for substr
			srand ( (unsigned)time(NULL) );
			bz_PlayerRecord* speaker = bz_getPlayerByIndex ( chat->from );


			// activate things... and vice versa
			if(strtoupper(message.substr(0,7)) == "@YESBOT")
				{
					if(speaker->admin == true){
					
					yesBot = true;
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, "Bot activated");
					}
					else{
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, "You aren't an admin");
					}
				}
			if(strtoupper(message.substr(0,6)) == "@NOBOT")
				{
					if(speaker->admin == true){
					
					yesBot = false;
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, "Bot deactivated");
					}
					else{
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, "You aren't an admin");
					}
				}


			
			if(yesBot == true){// get a way to turn off the bot when not needed :)
			
			// "non-symbol" commands
			if(strtoupper(message.substr(0,2)) == "HI")
				{
					std::string user = speaker->callsign.c_str();//the former is a std::string while the latter is bzAPI string, so "convert" it 
					std::string hello = "Hi ";
					std::string result = hello + user; 
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, result.c_str());
				}

			if(strtoupper(message.substr(0,5)) == "HELLO")
				{
					std::string user = speaker->callsign.c_str();
					std::string hello = "Hello ";
					std::string result = hello + user; 
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, result.c_str());
				}

			if(strtoupper(message).find("SERVER",0) != std::string::npos)// find the occurrence of the string "server", and if it is found, um.. yeah
				{
					
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, "What about me?");
				}
			if(strtoupper(message).find("MAGIC",0) != std::string::npos)// find the occurrence of the string "server", and if it is found, um.. yeah
				{
					
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, "");
				}
			if(strtoupper(message).find("BLAST007",0) != std::string::npos)// find the occurrence of the string "server", and if it is found, um.. yeah
				{
					
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, "He is occasionally wacky, but very cool :)");
				}
			if(strtoupper(message).find("WEGSTAR",0) != std::string::npos)// find the occurrence of the string "server", and if it is found, um.. yeah
				{
					
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, "The stater of the obvious, tries to learn the world, but ends up wasting time instead.");
				}
			if(strtoupper(message).find("LOL",0) != std::string::npos)// find the occurrence of the string "server", and if it is found, um.. yeah
				{
					std::string user = speaker->callsign.c_str();
					std::string part = "lol.. that's so funny, ";
					std::string part2 = ". hehehe";
					std::string result = part + user + part2;

					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, result.c_str() );
				}

			if(strtoupper(message.substr(0,1))== std::string("~"))
			{

				/* Hi */
				if(strtoupper(message.substr(0,3)) == "~HI")
				{
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, "Hello");
				}


				if(strtoupper(message.substr(0,5)) == "~LART"){
					std::string arg = message.substr(6);// from the six character to the end
					
					// for some reason, switch and case doesn't work here :(
					int num = rand()%10;
					if(num == 1)
							{
					std::string lart = "The SERVER beats ";
					std::string lart2 = " head off with a louisville slugger, and makes a home run";
					std::string result = lart + arg + lart2;
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, result.c_str());
							}
						else if(num == 2)
							{
					std::string lart = "The SERVER forces ";
					std::string lart2 = " to browse the web with IE";
					std::string result = lart + arg + lart2;
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, result.c_str());
							}
						else if(num == 3)
							{
					std::string lart = "The SERVER rm -rf's ";
					std::string result = lart + arg;
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, result.c_str());
							}
						else if(num == 4)
							{
					std::string lart = "The SERVER cuts off ";
					std::string lart2 = "'s head with a halberd that could have been sharper";
					std::string result = lart + arg + lart2;
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, result.c_str());
							}
						else if(num == 5)
							{
					std::string lart = "The SERVER blasts ";
					std::string lart2 = " to oblivion with a kamehameha wave";
					std::string result = lart + arg + lart2;
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, result.c_str());
							}
						else if(num == 6)
							{
					std::string lart = "The SERVER cuts ";
					std::string lart2 = " in half with a free AOL CD";
					std::string result = lart + arg + lart2;
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, result.c_str());
							}
						else if(num == 7)
							{
					std::string lart = "The SERVER jabs a hot car lighter into ";
					std::string lart2 = "'s eye sockets";
					std::string result = lart + arg + lart2 ;
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, result.c_str());

							}
						else if(num == 8)
							{
					std::string lart = "The SERVER removes debian from ";
					std::string lart2 = "'s system";
					std::string result = lart + arg + lart2 ;
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, result.c_str());
							}
						else if(num == 9)
							{
					std::string lart = "The SERVER sends a legion of lawyers after ";
					std::string lart2 = "'s head";
					std::string result = lart + arg + lart2 ;
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, result.c_str());
							}
						else if(num == 10)
							{
					std::string lart = "The SERVER beats ";
					std::string lart2 = " senseless with a 50lb Unix manual";
					std::string result = lart + arg + lart2 ;
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, result.c_str());
							}
						else
							{
					std::string lart = "The SERVER decides to spare ";
					std::string lart2 = "'s life :P";
					std::string result = lart + arg + lart2 ;
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, result.c_str());
					
							}

					
					}/*if ~lart*/

				/* FISHSLAP */
				if(strtoupper(message.substr(0,10)) == "~WHALESLAP")
				{
					std::string arg = message.substr(11);
					std::string slap = "The SERVER slaps ";
					std::string slap2 = " upside and over the head with one freakishly huge killer whale named Hugh";
					std::string result = slap + arg + slap2;
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, result.c_str());
				}

			   /* Magic Eight Ball*/
			   if(strtoupper(message.substr(0,15)) == "~MAGICEIGHTBALL")
			   {
				   std::string opt1 = "Yes...";
				   std::string opt2 = "No...";
				   std::string opt3 = "Maybe So...";
				   std::string opt4 = "Dunno";
				   std::string opt5 = "umm... probably";
				   std::string opt6 = "Never";
				   std::string opt7 = "Not in a million years :-)...";
				   std::string opt = "Ask again later";

				   int num = rand()%7;
				   if(num==1){
						bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, opt1.c_str());
				   }
				   else if(num==2){
					   bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, opt2.c_str());
				   }
				   else if(num == 3){
					   bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, opt3.c_str());
				   }
				   else if (num == 4){
					   bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, opt4.c_str());
				   }
				   else if (num == 5){
					   bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, opt5.c_str());
				   }
				   else if (num == 6){
					   bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, opt6.c_str());
				   }
				   else if (num == 7){
					   bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, opt7.c_str());
				   }
				   else{
					   bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, opt.c_str());
				   }
			   }


				/* Commands */
			   if(strtoupper(message.substr(0,10)) == "~TOGGLEANNOUNCE")
				{
					std::string arg = message.substr(11);
					std::string slap = "The SERVER slaps ";
					std::string slap2 = " upside and over the head with one freakishly huge killer whale named Hugh";
					std::string result = slap + arg + slap2;
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, result.c_str());
				}


				

			} /*if "~" one*/
			}			

		} /*switch*/
		break;
	case bz_ePlayerSpawnEvent:
		{
		   bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, "Welcome");
		}
		break;
	case bz_ePlayerJoinEvent:
		{
			
			bz_PlayerJoinPartEventData *join = (bz_PlayerJoinPartEventData*)eventData;
			bz_PlayerRecord* joiner = bz_getPlayerByIndex ( join->playerID );

			if(join->callsign == "wegstar" && (joiner->globalUser == true)){
				bz_sendTextMessage(BZ_SERVER,BZ_ALL_USERS, "WEGSTAR HAS ARRIVED!!");
			}
			else if (join->callsign == "gnurdux" && (joiner->globalUser == true)){
				bz_sendTextMessage(BZ_SERVER,BZ_ALL_USERS, "GNURDUX HAS ARRIVED!!");
			}
		}
		break;
		
	

	}
}