]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_randquote.cpp
Implement support for saving filters.
[user/henk/code/inspircd.git] / src / modules / m_randquote.cpp
index aebf7c0ad9a426247ea9c61be1587f4bfbc1964a..0148e48d6c0e780c9c1d0bf76e46f964bba5faae 100644 (file)
@@ -1,89 +1,59 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <fstream>
-
-#include "users.h"
-#include "channels.h"
-#include "modules.h"
-
-
-/* $ModDesc: Provides random Quotes on Connect. */
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2013, 2020 Sadie Powell <sadie@witchery.services>
+ *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
+ *   Copyright (C) 2010 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
+ *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2003, 2006-2008, 2010 Craig Edwards <brain@inspircd.org>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "inspircd.h"
 
 class ModuleRandQuote : public Module
 {
  private:
+       std::string prefix;
+       std::string suffix;
+       std::vector<std::string> quotes;
 
-        Server *Srv;
-        ConfigReader *conf;
-        FileReader *quotes;
-
-        string q_file;
-        string prefix;
-        string suffix;
-        
  public:
-       ModuleRandQuote()
-       {
-               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()
+       void init() CXX11_OVERRIDE
        {
-               return Version(1,0,0,0);
+               ConfigTag* conf = ServerInstance->Config->ConfValue("randquote");
+               prefix = conf->getString("prefix");
+               suffix = conf->getString("suffix");
+               FileReader reader(conf->getString("file", "quotes", 1));
+               quotes = reader.GetVector();
        }
-       
-       virtual void OnUserConnect(userrec* user)
-       {
-               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;
-       }
-};
-
-
-class ModuleRandQuoteFactory : public ModuleFactory
-{
- public:
-       ModuleRandQuoteFactory()
+       void OnUserConnect(LocalUser* user) CXX11_OVERRIDE
        {
+               if (!quotes.empty())
+               {
+                       unsigned long random = ServerInstance->GenRandomInt(quotes.size());
+                       user->WriteNotice(prefix + quotes[random] + suffix);
+               }
        }
-       
-       ~ModuleRandQuoteFactory()
-       {
-       }
-       
-       virtual Module * CreateModule()
+
+       Version GetVersion() CXX11_OVERRIDE
        {
-               return new ModuleRandQuote;
+               return Version("Allows random quotes to be sent to users when they connect to the server.", VF_VENDOR);
        }
-       
 };
 
-
-extern "C" void * init_module( void )
-{
-       return new ModuleRandQuoteFactory;
-}
-
+MODULE_INIT(ModuleRandQuote)