1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
25 #include "helperfuncs.h"
28 FileReader *quotes = NULL;
30 std::string q_file = "";
31 std::string prefix = "";
32 std::string suffix = "";
34 /* $ModDesc: Provides random Quotes on Connect. */
36 void handle_randquote(char** parameters, int pcntl, userrec *user)
41 if (q_file == "" || quotes->Exists())
43 fsize = quotes->FileSize();
44 str = quotes->GetLine(rand() % fsize);
45 sprintf(buf,"NOTICE %s :%s%s%s",user->nick,prefix.c_str(),str.c_str(),suffix.c_str());
46 Srv->SendServ(user->fd, buf);
50 sprintf(buf, "NOTICE %s :Your administrator specified an invalid quotes file, please bug them about this.", user->nick);
51 Srv->SendServ(user->fd, buf);
59 class ModuleRandQuote : public Module
65 ModuleRandQuote(Server* Me)
69 conf = new ConfigReader;
70 // Sort the Randomizer thingie..
73 q_file = conf->ReadValue("randquote","file",0);
74 prefix = conf->ReadValue("randquote","prefix",0);
75 suffix = conf->ReadValue("randquote","suffix",0);
79 log(DEFAULT,"m_randquote: Quotefile not specified - Please check your config.");
83 quotes = new FileReader(q_file);
86 log(DEFAULT,"m_randquote: QuoteFile not Found!! Please check your config - module will not function.");
89 /* Hidden Command -- Mode clients assume /quote sends raw data to an IRCd >:D */
90 else Srv->AddCommand("QUOTE",handle_randquote,0,0,"m_randquote.so");
93 virtual ~ModuleRandQuote()
99 virtual Version GetVersion()
101 return Version(1,0,0,1,VF_VENDOR);
104 virtual void OnUserConnect(userrec* user)
106 // Make a fake pointer to be passed to handle_randquote()
107 // Dont try this at home kiddies :D
108 /* Or do things a slightly nicer way, and pass NULL */
110 handle_randquote(NULL, 0, user);
115 class ModuleRandQuoteFactory : public ModuleFactory
118 ModuleRandQuoteFactory()
122 ~ModuleRandQuoteFactory()
126 virtual Module * CreateModule(Server* Me)
128 return new ModuleRandQuote(Me);
134 extern "C" void * init_module( void )
136 return new ModuleRandQuoteFactory;