All pastes #19425 Raw Edit

wegstar

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

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

extern std::string StringToUpper(std::string strtoconv);
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(4,"BZFSBot plugin loaded. Party Time!");
	bz_registerEvent(bz_eChatMessageEvent,BZ_ALL_USERS,&bot);
	return 0;
	
}

BZF_PLUGIN_CALL int bz_Unload ( void )
{
	bz_debugMessage(4,"BZFSBot plugin unloaded");
	bz_removeEvent(bz_eChatMessageEvent,BZ_ALL_USERS,&bot);
	return 0;
}

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


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

	case bz_eChatMessageEvent:
		{
			bz_ChatEventData *chat = (bz_ChatEventData*)eventData;
			
			int sender = chat->from;
			std::string message = chat->message.c_str();//convert bzAPI string to std::string for substr
			bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, chat->message.c_str());
			if(StringToUpper(message.substr(1))== std::string("~"))
			{
				if(StringToUpper(message) == "~HI")
				{
					bz_sendTextMessage(BZ_SERVER, BZ_ALL_USERS, "Hello");
				}

				
			}
			
		}
		break;
	}
}