X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_randquote.cpp;h=7d4ad042f502dc5d47498c06887b6ebc12063f39;hb=cbd32e195f5f574653550a3ed4954168ace30c55;hp=5be40bc6c5508d86050f6e4ce60838a2b2521815;hpb=61b45c935dbb50c280970c9f431fd1c7ef4eb680;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_randquote.cpp b/src/modules/m_randquote.cpp index 5be40bc6c..7d4ad042f 100644 --- a/src/modules/m_randquote.cpp +++ b/src/modules/m_randquote.cpp @@ -1,89 +1,90 @@ -#include -#include -#include +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * InspIRCd: (C) 2002-2010 InspIRCd Development Team + * See: http://wiki.inspircd.org/Credits + * + * This program is free but copyrighted software; see + * the file COPYING for details. + * + * --------------------------------------------------- + */ -#include "users.h" -#include "channels.h" -#include "modules.h" +#include "inspircd.h" +static FileReader *quotes = NULL; + +std::string prefix; +std::string suffix; /* $ModDesc: Provides random Quotes on Connect. */ -class ModuleRandQuote : public Module +/** Handle /RANDQUOTE + */ +class CommandRandquote : public Command { - private: - - Server *Srv; - ConfigReader *conf; - FileReader *quotes; - - std::string q_file; - std::string prefix; - std::string suffix; - public: - ModuleRandQuote() + CommandRandquote(Module* Creator) : Command(Creator,"RANDQUOTE", 0) { - Srv = new Server; - conf = new ConfigReader; - - q_file = conf->ReadValue("randquote","file",0); - prefix = conf->ReadValue("randquote","prefix",0); - suffix = conf->ReadValue("randquote","suffix",0); - - quotes = new FileReader(q_file); } - - virtual ~ModuleRandQuote() - { - delete Srv; - delete conf; - delete quotes; - } - - virtual Version GetVersion() - { - return Version(1,0,0,0); - } - - virtual void OnUserConnect(userrec* user) + + CmdResult Handle (const std::vector& parameters, User *user) { std::string str; int fsize; - char buf[MAXBUF]; fsize = quotes->FileSize(); - srand(time(NULL)); - str = quotes->GetLine(rand() % fsize); - - sprintf(buf,"NOTICE %s :%s%s%s",user->nick,prefix.c_str(),str.c_str(),suffix.c_str()); - Srv->SendServ(user->fd, buf); - return; + str = quotes->GetLine(ServerInstance->GenRandomInt(fsize)); + user->WriteServ("NOTICE %s :%s%s%s",user->nick.c_str(),prefix.c_str(),str.c_str(),suffix.c_str()); + + return CMD_SUCCESS; } }; - -class ModuleRandQuoteFactory : public ModuleFactory +class ModuleRandQuote : public Module { + private: + CommandRandquote cmd; public: - ModuleRandQuoteFactory() + ModuleRandQuote() + : cmd(this) { } - - ~ModuleRandQuoteFactory() + + void init() { + ConfigTag* conf = ServerInstance->Config->ConfValue("randquote"); + + std::string q_file = conf->getString("file","quotes"); + prefix = conf->getString("prefix"); + suffix = conf->getString("suffix"); + + quotes = new FileReader(q_file); + if (!quotes->Exists()) + { + throw ModuleException("m_randquote: QuoteFile not Found!! Please check your config - module will not function."); + } + ServerInstance->AddCommand(&cmd); + Implementation eventlist[] = { I_OnUserConnect }; + ServerInstance->Modules->Attach(eventlist, this, 1); } - - virtual Module * CreateModule() + + + virtual ~ModuleRandQuote() { - return new ModuleRandQuote; + delete quotes; } - -}; + virtual Version GetVersion() + { + return Version("Provides random Quotes on Connect.",VF_VENDOR); + } -extern "C" void * init_module( void ) -{ - return new ModuleRandQuoteFactory; -} + virtual void OnUserConnect(LocalUser* user) + { + cmd.Handle(std::vector(), user); + } +}; +MODULE_INIT(ModuleRandQuote)