]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_randquote.cpp
Change allocation of commands/modes
[user/henk/code/inspircd.git] / src / modules / m_randquote.cpp
index e4cb70a76502592b52d1f260b15e2a99ddaa2cdc..21cb2257dc8358ba0bfbe2b11dfeb383bd3e6703 100644 (file)
@@ -2,8 +2,8 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2007 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.
@@ -31,7 +31,7 @@ class CommandRandquote : public Command
                this->source = "m_randquote.so";
        }
 
-       CmdResult Handle (const char** parameters, int pcntl, User *user)
+       CmdResult Handle (const std::vector<std::string>& parameters, User *user)
        {
                std::string str;
                int fsize;
@@ -40,11 +40,11 @@ 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;
                }
 
@@ -52,83 +52,58 @@ class CommandRandquote : public Command
        }
 };
 
-/** 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:
-       CommandRandquote* mycommand;
+       CommandRandquote cmd;
        ConfigReader *conf;
  public:
        ModuleRandQuote(InspIRCd* Me)
-               : Module(Me)
+               : Module(Me), cmd(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);
                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);
                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);
        }
 
-       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(User* user)
        {
-               if (mycommand)
-                       mycommand->Handle(NULL, 0, user);
+               cmd.Handle(std::vector<std::string>(), user);
        }
 };