X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_randquote.cpp;h=73bf9b3b195b052d94c2a0b8409cef61adb38060;hb=ea7aa89d61f5090ee7e7ecbe9eb633e1189ce40a;hp=5cd8a8572f6f82ac6d72d316f08320175773e4ca;hpb=eb4229deed0281ae566ef7e55a144e5d3183a4b2;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_randquote.cpp b/src/modules/m_randquote.cpp index 5cd8a8572..73bf9b3b1 100644 --- a/src/modules/m_randquote.cpp +++ b/src/modules/m_randquote.cpp @@ -14,6 +14,8 @@ * --------------------------------------------------- */ +using namespace std; + #include #include #include @@ -22,7 +24,7 @@ #include "modules.h" #include "helperfuncs.h" -Server *Srv = NULL; +Server *Srv; FileReader *quotes = NULL; std::string q_file = ""; @@ -31,33 +33,46 @@ std::string suffix = ""; /* $ModDesc: Provides random Quotes on Connect. */ -void handle_randquote(char** parameters, int pcntl, userrec *user) +class cmd_randquote : public command_t { - std::string str; - int fsize; - char buf[MAXBUF]; - if (quotes) + public: + cmd_randquote () : command_t("RANDQUOTE", 0, 0) { - fsize = quotes->FileSize(); - 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); + this->source = "m_randquote.so"; } - return; -} - + void Handle (char** parameters, int pcntl, userrec *user) + { + std::string str; + int fsize; + char buf[MAXBUF]; + if (q_file == "" || quotes->Exists()) + { + fsize = quotes->FileSize(); + 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); + } + else + { + sprintf(buf, "NOTICE %s :Your administrator specified an invalid quotes file, please bug them about this.", user->nick); + Srv->SendServ(user->fd, buf); + } + return; + } +}; class ModuleRandQuote : public Module { private: - + cmd_randquote* mycommand; ConfigReader *conf; public: - ModuleRandQuote() + ModuleRandQuote(Server* Me) + : Module::Module(Me) { - Srv = new Server; + Srv = Me; conf = new ConfigReader; // Sort the Randomizer thingie.. srand(time(NULL)); @@ -66,7 +81,10 @@ class ModuleRandQuote : public Module prefix = conf->ReadValue("randquote","prefix",0); suffix = conf->ReadValue("randquote","suffix",0); - if (q_file == "") { + mycommand = NULL; + + if (q_file == "") + { log(DEFAULT,"m_randquote: Quotefile not specified - Please check your config."); return; } @@ -77,13 +95,16 @@ class ModuleRandQuote : public Module log(DEFAULT,"m_randquote: QuoteFile not Found!! Please check your config - module will not function."); return; } - /* Hidden Command -- Mode clients assume /quote sends raw data to an IRCd >:D */ - else Srv->AddCommand("QUOTE",handle_randquote,0,0,"m_randquote.so"); + else + { + /* Hidden Command -- Mode clients assume /quote sends raw data to an IRCd >:D */ + mycommand = new cmd_randquote(); + Srv->AddCommand(mycommand); + } } virtual ~ModuleRandQuote() { - delete Srv; delete conf; delete quotes; } @@ -95,10 +116,8 @@ class ModuleRandQuote : public Module virtual void OnUserConnect(userrec* user) { - // Make a fake pointer to be passed to handle_randquote() - // Dont try this at home kiddies :D - char *rar = "RAR"; - handle_randquote(&rar, 0, user); + if (mycommand) + mycommand->Handle(NULL, 0, user); } }; @@ -114,9 +133,9 @@ class ModuleRandQuoteFactory : public ModuleFactory { } - virtual Module * CreateModule() + virtual Module * CreateModule(Server* Me) { - return new ModuleRandQuote; + return new ModuleRandQuote(Me); } };