X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_randquote.cpp;h=e2910e7cd96e003dc3f3f33479dde98a629a912a;hb=de25d946733f774e3a5b53a58438a9c92af0acbe;hp=7dd3303a844de6cba7f2054052636337787e913c;hpb=e4acbc95b8b6cd5b28d38a2242c02e8ff4991e4a;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_randquote.cpp b/src/modules/m_randquote.cpp index 7dd3303a8..e2910e7cd 100644 --- a/src/modules/m_randquote.cpp +++ b/src/modules/m_randquote.cpp @@ -2,8 +2,8 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd: (C) 2002-2008 InspIRCd Development Team - * See: http://www.inspircd.org/wiki/index.php/Credits + * InspIRCd: (C) 2002-2009 InspIRCd Development Team + * See: http://wiki.inspircd.org/Credits * * This program is free but copyrighted software; see * the file COPYING for details. @@ -26,12 +26,11 @@ std::string suffix; class CommandRandquote : public Command { public: - CommandRandquote (InspIRCd* Instance) : Command(Instance,"RANDQUOTE", 0, 0) + CommandRandquote(Module* Creator) : Command(Creator,"RANDQUOTE", 0) { - this->source = "m_randquote.so"; } - CmdResult Handle (const char** parameters, int pcntl, User *user) + CmdResult Handle (const std::vector& parameters, User *user) { std::string str; int fsize; @@ -40,93 +39,70 @@ class CommandRandquote : public Command { 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; } - return CMD_LOCALONLY; - } -}; - -/** 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(); + return CMD_SUCCESS; } }; class ModuleRandQuote : public Module { private: - CommandRandquote* mycommand; + CommandRandquote cmd; ConfigReader *conf; public: - ModuleRandQuote(InspIRCd* Me) - : Module(Me) + ModuleRandQuote() + : cmd(this) { - - conf = new ConfigReader(ServerInstance); + + conf = new ConfigReader; // Sort the Randomizer thingie.. - srand(time(NULL)); + srand(ServerInstance->Time()); q_file = conf->ReadValue("randquote","file",0); prefix = conf->ReadValue("randquote","prefix",0); suffix = conf->ReadValue("randquote","suffix",0); - mycommand = NULL; - 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); + quotes = new FileReader(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 CommandRandquote(ServerInstance); - ServerInstance->AddCommand(mycommand); + ServerInstance->AddCommand(&cmd); } Implementation eventlist[] = { I_OnUserConnect }; ServerInstance->Modules->Attach(eventlist, this, 1); } - + virtual ~ModuleRandQuote() { delete conf; delete quotes; } - + virtual Version GetVersion() { - return Version(1,1,0,1,VF_VENDOR,API_VERSION); + return Version("Provides random Quotes on Connect.",VF_VENDOR,API_VERSION); } - + virtual void OnUserConnect(User* user) { - if (mycommand) - mycommand->Handle(NULL, 0, user); + cmd.Handle(std::vector(), user); } };