X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_randquote.cpp;h=b3bd82995722fef9cd17d14ca03a38fe31e9a053;hb=f14271bdb80dd6af67cde4fb97df9716613a7177;hp=9a467833f21a1bef5c4e93352585cb06f75755de;hpb=cd9610cb975fe219f4bf9ce2e80bff7fef91a6d9;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_randquote.cpp b/src/modules/m_randquote.cpp index 9a467833f..b3bd82995 100644 --- a/src/modules/m_randquote.cpp +++ b/src/modules/m_randquote.cpp @@ -2,7 +2,7 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd: (C) 2002-2007 InspIRCd Development Team + * InspIRCd: (C) 2002-2009 InspIRCd Development Team * See: http://www.inspircd.org/wiki/index.php/Credits * * This program is free but copyrighted software; see @@ -12,9 +12,6 @@ */ #include "inspircd.h" -#include "users.h" -#include "channels.h" -#include "modules.h" static FileReader *quotes = NULL; @@ -26,15 +23,15 @@ std::string suffix; /** Handle /RANDQUOTE */ -class cmd_randquote : public command_t +class CommandRandquote : public Command { public: - cmd_randquote (InspIRCd* Instance) : command_t(Instance,"RANDQUOTE", 0, 0) + CommandRandquote (InspIRCd* Instance) : Command(Instance,"RANDQUOTE", 0, 0) { this->source = "m_randquote.so"; } - CmdResult Handle (const char** parameters, int pcntl, userrec *user) + CmdResult Handle (const std::vector& parameters, User *user) { std::string str; int fsize; @@ -43,11 +40,11 @@ class cmd_randquote : public command_t { fsize = quotes->FileSize(); str = quotes->GetLine(rand() % fsize); - user->WriteServ("NOTICE %s :%s%s%s",user->nick,prefix.c_str(),str.c_str(),suffix.c_str()); + user->WriteServ("NOTICE %s :%s%s%s",user->nick.c_str(),prefix.c_str(),str.c_str(),suffix.c_str()); } else { - user->WriteServ("NOTICE %s :Your administrator specified an invalid quotes file, please bug them about this.", user->nick); + user->WriteServ("NOTICE %s :Your administrator specified an invalid quotes file, please bug them about this.", user->nick.c_str()); return CMD_FAILURE; } @@ -55,36 +52,19 @@ class cmd_randquote : public command_t } }; -/** Thrown by m_randquote - */ -class RandquoteException : public ModuleException -{ - private: - const std::string err; - public: - RandquoteException(const std::string &message) : err(message) { } - - ~RandquoteException() throw () { } - - virtual const char* GetReason() - { - return err.c_str(); - } -}; - class ModuleRandQuote : public Module { private: - cmd_randquote* mycommand; + CommandRandquote* mycommand; ConfigReader *conf; public: ModuleRandQuote(InspIRCd* Me) : Module(Me) { - + conf = new ConfigReader(ServerInstance); // Sort the Randomizer thingie.. - srand(time(NULL)); + srand(ServerInstance->Time()); q_file = conf->ReadValue("randquote","file",0); prefix = conf->ReadValue("randquote","prefix",0); @@ -94,45 +74,41 @@ class ModuleRandQuote : public Module if (q_file.empty()) { - RandquoteException e("m_randquote: Quotefile not specified - Please check your config."); - throw(e); + throw ModuleException("m_randquote: Quotefile not specified - Please check your config."); } quotes = new FileReader(ServerInstance, q_file); if(!quotes->Exists()) { - RandquoteException e("m_randquote: QuoteFile not Found!! Please check your config - module will not function."); - throw(e); + throw ModuleException("m_randquote: QuoteFile not Found!! Please check your config - module will not function."); } else { /* Hidden Command -- Mode clients assume /quote sends raw data to an IRCd >:D */ - mycommand = new cmd_randquote(ServerInstance); + mycommand = new CommandRandquote(ServerInstance); ServerInstance->AddCommand(mycommand); } + Implementation eventlist[] = { I_OnUserConnect }; + ServerInstance->Modules->Attach(eventlist, this, 1); } - void Implements(char* List) - { - List[I_OnUserConnect] = 1; - } - + virtual ~ModuleRandQuote() { - DELETE(conf); - DELETE(quotes); + delete conf; + delete quotes; } - + virtual Version GetVersion() { - return Version(1,1,0,1,VF_VENDOR,API_VERSION); + return Version("$Id$",VF_VENDOR,API_VERSION); } - - virtual void OnUserConnect(userrec* user) + + virtual void OnUserConnect(User* user) { if (mycommand) - mycommand->Handle(NULL, 0, user); + mycommand->Handle(std::vector(), user); } }; -MODULE_INIT(ModuleRandQuote); +MODULE_INIT(ModuleRandQuote)