]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_callerid.cpp
Merge pull request #215 from attilamolnar/insp20+modfixes
[user/henk/code/inspircd.git] / src / modules / m_callerid.cpp
index 16b883f632862c5cacb1285841fd3c60fc6a6057..416ede9a1ba8f05cb6381b9c5f975cb4aa29f439 100644 (file)
@@ -1,16 +1,25 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
  *
- *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2008-2009 Robin Burchell <robin+git@viroteck.net>
+ *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
+ *   Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
  *
- * This program is free but copyrighted software; see
- *            the file COPYING for details.
+ * 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"
 #include <set>
 #include <sstream>
@@ -18,7 +27,7 @@
 
 /* $ModDesc: Implementation of callerid (umode +g & /accept, ala hybrid etc) */
 
-class callerid_data : public classbase
+class callerid_data
 {
  public:
        time_t lastnotify;
@@ -32,7 +41,7 @@ class callerid_data : public classbase
        std::list<callerid_data *> wholistsme;
 
        callerid_data() : lastnotify(0) { }
-       callerid_data(const std::string& str, InspIRCd* ServerInstance)
+       callerid_data(const std::string& str)
        {
                irc::commasepstream s(str);
                std::string tok;
@@ -56,16 +65,16 @@ class callerid_data : public classbase
                }
        }
 
-       std::string ToString(Module* proto) const
+       std::string ToString(SerializeFormat format) const
        {
                std::ostringstream oss;
                oss << lastnotify;
                for (std::set<User*>::const_iterator i = accepting.begin(); i != accepting.end(); ++i)
                {
+                       User* u = *i;
                        // Encode UIDs.
-                       oss << "," << proto->ProtoTranslate(*i);
+                       oss << "," << (format == FORMAT_USER ? u->nick : u->uuid);
                }
-               oss << std::ends;
                return oss.str();
        }
 };
@@ -77,22 +86,22 @@ struct CallerIDExtInfo : public ExtensionItem
        {
        }
 
-       std::string serialize(Module* requestor, const Extensible* container, void* item)
+       std::string serialize(SerializeFormat format, const Extensible* container, void* item) const
        {
                callerid_data* dat = static_cast<callerid_data*>(item);
-               return dat->ToString(requestor);
+               return dat->ToString(format);
        }
 
-       void unserialize(Module* requestor, Extensible* container, const std::string& value)
+       void unserialize(SerializeFormat format, Extensible* container, const std::string& value)
        {
-               callerid_data* dat = new callerid_data(value, requestor->ServerInstance);
+               callerid_data* dat = new callerid_data(value);
                set_raw(container, dat);
        }
 
        callerid_data* get(User* user, bool create)
        {
                callerid_data* dat = static_cast<callerid_data*>(get_raw(user));
-               if (!dat)
+               if (create && !dat)
                {
                        dat = new callerid_data;
                        set_raw(user, dat);
@@ -127,7 +136,7 @@ struct CallerIDExtInfo : public ExtensionItem
 class User_g : public SimpleUserModeHandler
 {
 public:
-       User_g(InspIRCd* Instance, Module* Creator) : SimpleUserModeHandler(Creator, 'g') { }
+       User_g(Module* Creator) : SimpleUserModeHandler(Creator, "callerid", 'g') { }
 };
 
 class CommandAccept : public Command
@@ -135,7 +144,7 @@ class CommandAccept : public Command
 public:
        CallerIDExtInfo extInfo;
        unsigned int maxaccepts;
-       CommandAccept(InspIRCd* Instance, Module* Creator) : Command(Instance, Creator, "ACCEPT", 0, 1),
+       CommandAccept(Module* Creator) : Command(Creator, "ACCEPT", 1),
                extInfo(Creator)
        {
                syntax = "{[+|-]<nicks>}|*}";
@@ -221,6 +230,11 @@ public:
                }
        }
 
+       RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
+       {
+               return ROUTE_BROADCAST;
+       }
+
        void ListAccept(User* user)
        {
                callerid_data* dat = extInfo.get(user, false);
@@ -341,15 +355,17 @@ private:
        }
 
 public:
-       ModuleCallerID(InspIRCd* Me) : Module(Me), cmd(Me, this), myumode(Me, this)
+       ModuleCallerID() : cmd(this), myumode(this)
        {
-               OnRehash(NULL);
+       }
 
-               if (!ServerInstance->Modes->AddMode(&myumode))
-                       throw ModuleException("Could not add usermode +g");
+       void init()
+       {
+               OnRehash(NULL);
 
-               ServerInstance->AddCommand(&cmd);
-               Extensible::Register(&cmd.extInfo);
+               ServerInstance->Modules->AddService(myumode);
+               ServerInstance->Modules->AddService(cmd);
+               ServerInstance->Modules->AddService(cmd.extInfo);
 
                Implementation eventlist[] = { I_OnRehash, I_OnUserPreNick, I_OnUserQuit, I_On005Numeric, I_OnUserPreNotice, I_OnUserPreMessage };
                ServerInstance->Modules->Attach(eventlist, this, 6);
@@ -357,12 +373,11 @@ public:
 
        virtual ~ModuleCallerID()
        {
-               ServerInstance->Modes->DelMode(&myumode);
        }
 
        virtual Version GetVersion()
        {
-               return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
+               return Version("Implementation of callerid (umode +g & /accept, ala hybrid etc)", VF_COMMON | VF_VENDOR);
        }
 
        virtual void On005Numeric(std::string& output)
@@ -389,8 +404,8 @@ public:
                        if (now > (dat->lastnotify + (time_t)notify_cooldown))
                        {
                                user->WriteNumeric(717, "%s %s :has been informed that you messaged them.", user->nick.c_str(), dest->nick.c_str());
-                               ServerInstance->DumpText(dest, ":%s 718 %s %s %s@%s :is messaging you, and you have umode +g. Use /ACCEPT +%s to allow.",
-                                       ServerInstance->Config->ServerName, dest->nick.c_str(), user->nick.c_str(), user->ident.c_str(), user->dhost.c_str(), user->nick.c_str());
+                               dest->SendText(":%s 718 %s %s %s@%s :is messaging you, and you have umode +g. Use /ACCEPT +%s to allow.",
+                                       ServerInstance->Config->ServerName.c_str(), dest->nick.c_str(), user->nick.c_str(), user->ident.c_str(), user->dhost.c_str(), user->nick.c_str());
                                dat->lastnotify = now;
                        }
                        return MOD_RES_DENY;
@@ -428,7 +443,7 @@ public:
 
        virtual void OnRehash(User* user)
        {
-               ConfigReader Conf(ServerInstance);
+               ConfigReader Conf;
                cmd.maxaccepts = Conf.ReadInteger("callerid", "maxaccepts", "16", 0, true);
                operoverride = Conf.ReadFlag("callerid", "operoverride", "0", 0);
                tracknick = Conf.ReadFlag("callerid", "tracknick", "0", 0);