]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_services_account.cpp
Convert WriteNumeric() calls to pass the parameters of the numeric as method parameters
[user/henk/code/inspircd.git] / src / modules / m_services_account.cpp
index 8ab9c9a3ba37a79e7933e7e5e4b235672013ad85..048e04a5a332ae7fbd8159b9017b3810e274acd2 100644 (file)
@@ -46,7 +46,7 @@ class Channel_r : public ModeHandler
                }
                else
                {
-                       source->WriteNumeric(500, ":Only a server may modify the +r channel mode");
+                       source->WriteNumeric(500, "Only a server may modify the +r channel mode");
                }
                return MODEACTION_DENY;
        }
@@ -72,7 +72,7 @@ class User_r : public ModeHandler
                }
                else
                {
-                       source->WriteNumeric(500, ":Only a server may modify the +r user mode");
+                       source->WriteNumeric(500, "Only a server may modify the +r user mode");
                }
                return MODEACTION_DENY;
        }
@@ -102,68 +102,42 @@ class AChannel_M : public SimpleChannelModeHandler
        AChannel_M(Module* Creator) : SimpleChannelModeHandler(Creator, "regmoderated", 'M') { }
 };
 
-static bool ReadCGIIRCExt(const char* extname, User* user, const std::string*& out)
-{
-       ExtensionItem* wiext = ServerInstance->Extensions.GetItem(extname);
-       if (!wiext)
-               return false;
-
-       if (wiext->creator->ModuleSourceFile != "m_cgiirc.so")
-               return false;
-
-       StringExtItem* stringext = static_cast<StringExtItem*>(wiext);
-       std::string* addr = stringext->get(user);
-       if (!addr)
-               return false;
-
-       out = addr;
-       return true;
-}
-
 class AccountExtItemImpl : public AccountExtItem
 {
+       Events::ModuleEventProvider eventprov;
+
  public:
        AccountExtItemImpl(Module* mod)
-               : AccountExtItem("accountname", mod)
+               : AccountExtItem("accountname", ExtensionItem::EXT_USER, mod)
+               , eventprov(mod, "event/account")
        {
        }
 
        void unserialize(SerializeFormat format, Extensible* container, const std::string& value)
        {
-               User* user = dynamic_cast<User*>(container);
-               if (!user)
-                       return;
+               User* user = static_cast<User*>(container);
 
                StringExtItem::unserialize(format, container, value);
+
+               // If we are being reloaded then don't send the numeric or run the event
+               if (format == FORMAT_INTERNAL)
+                       return;
+
                if (!value.empty())
                {
                        // Logged in
                        if (IS_LOCAL(user))
                        {
-                               const std::string* host = &user->dhost;
-                               if (user->registered != REG_ALL)
-                               {
-                                       if (!ReadCGIIRCExt("cgiirc_webirc_hostname", user, host))
-                                       {
-                                               ReadCGIIRCExt("cgiirc_webirc_ip", user, host);
-                                       }
-                               }
-
-                               user->WriteNumeric(900, "%s!%s@%s %s :You are now logged in as %s",
-                                       user->nick.c_str(), user->ident.c_str(), host->c_str(), value.c_str(), value.c_str());
+                               user->WriteNumeric(900, user->GetFullHost(), value, InspIRCd::Format("You are now logged in as %s", value.c_str()));
                        }
-
-                       AccountEvent(creator, user, value).Send();
-               }
-               else
-               {
-                       // Logged out
-                       AccountEvent(creator, user, "").Send();
                }
+               // If value is empty then logged out
+
+               FOREACH_MOD_CUSTOM(eventprov, AccountEventListener, OnAccountChange, (user, value));
        }
 };
 
-class ModuleServicesAccount : public Module
+class ModuleServicesAccount : public Module, public Whois::EventListener
 {
        AChannel_R m1;
        AChannel_M m2;
@@ -173,8 +147,11 @@ class ModuleServicesAccount : public Module
        AccountExtItemImpl accountname;
        bool checking_ban;
  public:
-       ModuleServicesAccount() : m1(this), m2(this), m3(this), m4(this), m5(this),
-               accountname(this)
+       ModuleServicesAccount()
+               : Whois::EventListener(this)
+               , m1(this), m2(this), m3(this), m4(this), m5(this)
+               , accountname(this)
+               , checking_ban(false)
        {
        }
 
@@ -185,19 +162,19 @@ class ModuleServicesAccount : public Module
        }
 
        /* <- :twisted.oscnet.org 330 w00t2 w00t2 w00t :is logged in as */
-       void OnWhois(User* source, User* dest) CXX11_OVERRIDE
+       void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
        {
-               std::string *account = accountname.get(dest);
+               std::string* account = accountname.get(whois.GetTarget());
 
                if (account)
                {
-                       ServerInstance->SendWhoisLine(source, dest, 330, "%s %s :is logged in as", dest->nick.c_str(), account->c_str());
+                       whois.SendLine(330, "%s :is logged in as", account->c_str());
                }
 
-               if (dest->IsModeSet(m5))
+               if (whois.GetTarget()->IsModeSet(m5))
                {
                        /* user is registered */
-                       ServerInstance->SendWhoisLine(source, dest, 307, "%s :is a registered nick", dest->nick.c_str());
+                       whois.SendLine(307, ":is a registered nick");
                }
        }
 
@@ -205,12 +182,7 @@ class ModuleServicesAccount : public Module
        {
                /* On nickchange, if they have +r, remove it */
                if (user->IsModeSet(m5) && assign(user->nick) != oldnick)
-               {
-                       std::vector<std::string> modechange;
-                       modechange.push_back(user->nick);
-                       modechange.push_back("-r");
-                       ServerInstance->Modes->Process(modechange, ServerInstance->FakeClient, ModeParser::MODE_LOCALONLY);
-               }
+                       m5.RemoveMode(user);
        }
 
        ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
@@ -229,7 +201,7 @@ class ModuleServicesAccount : public Module
                        if (c->IsModeSet(m2) && !is_registered && res != MOD_RES_ALLOW)
                        {
                                // user messaging a +M channel and is not registered
-                               user->WriteNumeric(477, c->name+" :You need to be identified to a registered account to message this channel");
+                               user->WriteNumeric(477, c->name, "You need to be identified to a registered account to message this channel");
                                return MOD_RES_DENY;
                        }
                }
@@ -240,7 +212,7 @@ class ModuleServicesAccount : public Module
                        if (u->IsModeSet(m3) && !is_registered)
                        {
                                // user messaging a +R user and is not registered
-                               user->WriteNumeric(477, u->nick +" :You need to be identified to a registered account to message this user");
+                               user->WriteNumeric(477, u->nick, "You need to be identified to a registered account to message this user");
                                return MOD_RES_DENY;
                        }
                }
@@ -295,7 +267,7 @@ class ModuleServicesAccount : public Module
                                if (!is_registered)
                                {
                                        // joining a +R channel and not identified
-                                       user->WriteNumeric(477, chan->name + " :You need to be identified to a registered account to join this channel");
+                                       user->WriteNumeric(477, chan->name, "You need to be identified to a registered account to join this channel");
                                        return MOD_RES_DENY;
                                }
                        }
@@ -317,4 +289,3 @@ class ModuleServicesAccount : public Module
 };
 
 MODULE_INIT(ModuleServicesAccount)
-