]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Send the 001-004 numerics and MOTD/LUSERS from core_info.
authorPeter Powell <petpow@saberuk.com>
Wed, 22 Aug 2018 12:43:46 +0000 (13:43 +0100)
committerPeter Powell <petpow@saberuk.com>
Wed, 22 Aug 2018 20:25:55 +0000 (21:25 +0100)
Co-authored-by: Attila Molnar <attilamolnar@hush.com>
include/mode.h
include/numerics.h
src/coremods/core_info/core_info.cpp
src/mode.cpp
src/users.cpp

index ac23adc330b1303175fdfff2d88cca6c0ae209f9..fe02838b2fc80aef7b47d98deab905818e718cef 100644 (file)
@@ -594,30 +594,12 @@ class CoreExport ModeParser : public fakederef<ModeParser>
         */
        ModeAction TryMode(User* user, User* targu, Channel* targc, Modes::Change& mcitem, bool SkipACL);
 
-       /** Returns a list of user or channel mode characters.
-        * Used for constructing the parts of the mode list in the 004 numeric.
-        * @param mt Controls whether to list user modes or channel modes
-        * @param needparam Return modes only if they require a parameter to be set
-        * @return The available mode letters that satisfy the given conditions
-        */
-       std::string CreateModeList(ModeType mt, bool needparam = false);
-
-       /** Recreate the cached mode list that is displayed in the 004 numeric
-        * in Cached004ModeList.
-        * Called when a mode handler is added or removed.
-        */
-       void RecreateModeListFor004Numeric();
-
        /** Allocates an unused id for the given mode type, throws a ModuleException if out of ids.
         * @param mt The type of the mode to allocate the id for
         * @return The id
         */
        ModeHandler::Id AllocateModeId(ModeType mt);
 
-       /** Cached mode list for use in 004 numeric
-        */
-       TR1NS::array<std::string, 3> Cached004ModeList;
-
  public:
        typedef std::vector<ListModeBase*> ListModeList;
        typedef std::vector<PrefixMode*> PrefixModeList;
@@ -778,14 +760,6 @@ class CoreExport ModeParser : public fakederef<ModeParser>
         */
        PrefixMode* FindPrefix(unsigned const char pfxletter);
 
-       /** Returns an array of modes:
-        * 1. User modes
-        * 2. Channel modes
-        * 3. Channel modes that require a parameter when set
-        * This is sent to users as the last part of the 004 numeric
-        */
-       const TR1NS::array<std::string, 3>& GetModeListFor004Numeric();
-
        /** Generates a list of modes, comma seperated by type:
         *  1; Listmodes EXCEPT those with a prefix
         *  2; Modes that take a param when adding or removing
@@ -823,11 +797,6 @@ class CoreExport ModeParser : public fakederef<ModeParser>
        void ShowListModeList(User* user, Channel* chan, ModeHandler* mh);
 };
 
-inline const TR1NS::array<std::string, 3>& ModeParser::GetModeListFor004Numeric()
-{
-       return Cached004ModeList;
-}
-
 inline PrefixMode* ModeHandler::IsPrefixMode()
 {
        return (this->type_id == MC_PREFIX ? static_cast<PrefixMode*>(this) : NULL);
index d1899b7570b6ea824b866430f7ce19e2cf6b2457..343f882527007117524d5341e32b274b78153121 100644 (file)
  */
 enum
 {
-       /*
-        * Reply range of numerics.
-        */
-       RPL_WELCOME                     = 1, // 2812, not 1459
-       RPL_YOURHOSTIS                  = 2, // 2812, not 1459
-       RPL_SERVERCREATED               = 3, // 2812, not 1459
-       RPL_SERVERVERSION               = 4, // 2812, not 1459
        RPL_ISUPPORT                    = 5, // not RFC, extremely common though (defined as RPL_BOUNCE in 2812, widely ignored)
 
        RPL_SNOMASKIS                   = 8, // unrealircd
index f1a17d0898dafd182d3f8afb01083cc62d2599fa..2d7a89475e6976a6e0763b686d9586623fba1272 100644 (file)
 #include "inspircd.h"
 #include "core_info.h"
 
+enum
+{
+       // From RFC 2812.
+       RPL_WELCOME = 1,
+       RPL_YOURHOST = 2,
+       RPL_CREATED = 3,
+       RPL_MYINFO = 4
+};
+
 RouteDescriptor ServerTargetCommand::GetRouting(User* user, const Params& parameters)
 {
        // Parameter must be a server name, not a nickname or uuid
@@ -37,11 +46,55 @@ class CoreModInfo : public Module
        CommandMotd cmdmotd;
        CommandTime cmdtime;
        CommandVersion cmdversion;
+       Numeric::Numeric numeric004;
 
+       /** Returns a list of user or channel mode characters.
+        * Used for constructing the parts of the mode list in the 004 numeric.
+        * @param mt Controls whether to list user modes or channel modes
+        * @param needparam Return modes only if they require a parameter to be set
+        * @return The available mode letters that satisfy the given conditions
+       */
+       static std::string CreateModeList(ModeType mt, bool needparam = false)
+       {
+               std::string modestr;
+               for (unsigned char mode = 'A'; mode <= 'z'; mode++)
+               {
+                       ModeHandler* mh = ServerInstance->Modes.FindMode(mode, mt);
+                       if ((mh) && ((!needparam) || (mh->NeedsParam(true))))
+                               modestr.push_back(mode);
+               }
+               return modestr;
+       }
+
+       void OnServiceChange(const ServiceProvider& prov)
+       {
+               if (prov.service != SERVICE_MODE)
+                       return;
+
+               std::vector<std::string>& params = numeric004.GetParams();
+               params.erase(params.begin()+2, params.end());
+
+               // Create lists of modes
+               // 1. User modes
+               // 2. Channel modes
+               // 3. Channel modes that require a parameter when set
+               numeric004.push(CreateModeList(MODETYPE_USER));
+               numeric004.push(CreateModeList(MODETYPE_CHANNEL));
+               numeric004.push(CreateModeList(MODETYPE_CHANNEL, true));
+       }
  public:
        CoreModInfo()
-               : cmdadmin(this), cmdcommands(this), cmdinfo(this), cmdmodules(this), cmdmotd(this), cmdtime(this), cmdversion(this)
+               : cmdadmin(this)
+               , cmdcommands(this)
+               , cmdinfo(this)
+               , cmdmodules(this)
+               , cmdmotd(this)
+               , cmdtime(this)
+               , cmdversion(this)
+               , numeric004(RPL_MYINFO)
        {
+               numeric004.push(ServerInstance->Config->ServerName);
+               numeric004.push(INSPIRCD_BRANCH);
        }
 
        void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
@@ -52,6 +105,51 @@ class CoreModInfo : public Module
                cmdadmin.AdminNick = tag->getString("nick", "admin");
        }
 
+       void OnUserConnect(LocalUser* user) CXX11_OVERRIDE
+       {
+               user->WriteNumeric(RPL_WELCOME, InspIRCd::Format("Welcome to the %s IRC Network %s", ServerInstance->Config->Network.c_str(), user->GetFullRealHost().c_str()));
+               user->WriteNumeric(RPL_YOURHOST, InspIRCd::Format("Your host is %s, running version %s", ServerInstance->Config->ServerName.c_str(), INSPIRCD_BRANCH));
+               user->WriteNumeric(RPL_CREATED, InspIRCd::TimeString(ServerInstance->startup_time, "This server was created %H:%M:%S %b %d %Y"));
+               user->WriteNumeric(numeric004);
+
+               ServerInstance->ISupport.SendTo(user);
+
+               /* Trigger MOTD and LUSERS output, give modules a chance too */
+               ModResult MOD_RESULT;
+               std::string command("LUSERS");
+               CommandBase::Params parameters;
+               FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, user, true));
+               if (!MOD_RESULT)
+                       ServerInstance->Parser.CallHandler(command, parameters, user);
+
+               MOD_RESULT = MOD_RES_PASSTHRU;
+               command = "MOTD";
+               FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, user, true));
+               if (!MOD_RESULT)
+                       ServerInstance->Parser.CallHandler(command, parameters, user);
+
+               if (ServerInstance->Config->RawLog)
+               {
+                       ClientProtocol::Messages::Privmsg rawlogmsg(ServerInstance->FakeClient, user, "*** Raw I/O logging is enabled on user server. All messages, passwords, and commands are being recorded.");
+                       user->Send(ServerInstance->GetRFCEvents().privmsg, rawlogmsg);
+               }
+       }
+
+       void OnServiceAdd(ServiceProvider& service) CXX11_OVERRIDE
+       {
+               OnServiceChange(service);
+       }
+
+       void OnServiceDel(ServiceProvider& service) CXX11_OVERRIDE
+       {
+               OnServiceChange(service);
+       }
+
+       void Prioritize() CXX11_OVERRIDE
+       {
+               ServerInstance->Modules.SetPriority(this, I_OnUserConnect, PRIORITY_FIRST);
+       }
+
        Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides the ADMIN, COMMANDS, INFO, MODULES, MOTD, TIME and VERSION commands", VF_VENDOR|VF_CORE);
index 71fce24d82658e3935d58c77e7758f9a382ed7b3..0bb97cc9ead29633407cce38333e0c7335fc77ed 100644 (file)
@@ -630,8 +630,6 @@ void ModeParser::AddMode(ModeHandler* mh)
                mhlist.prefix.push_back(pm);
        else if (mh->IsListModeBase())
                mhlist.list.push_back(mh->IsListModeBase());
-
-       RecreateModeListFor004Numeric();
 }
 
 bool ModeParser::DelMode(ModeHandler* mh)
@@ -689,8 +687,6 @@ bool ModeParser::DelMode(ModeHandler* mh)
                mhlist.prefix.erase(std::find(mhlist.prefix.begin(), mhlist.prefix.end(), mh->IsPrefixMode()));
        else if (mh->IsListModeBase())
                mhlist.list.erase(std::find(mhlist.list.begin(), mhlist.list.end(), mh->IsListModeBase()));
-
-       RecreateModeListFor004Numeric();
        return true;
 }
 
@@ -720,27 +716,6 @@ PrefixMode* ModeParser::FindPrefixMode(unsigned char modeletter)
        return mh->IsPrefixMode();
 }
 
-std::string ModeParser::CreateModeList(ModeType mt, bool needparam)
-{
-       std::string modestr;
-
-       for (unsigned char mode = 'A'; mode <= 'z'; mode++)
-       {
-               ModeHandler* mh = modehandlers[mt][mode-65];
-               if ((mh) && ((!needparam) || (mh->NeedsParam(true))))
-                       modestr.push_back(mode);
-       }
-
-       return modestr;
-}
-
-void ModeParser::RecreateModeListFor004Numeric()
-{
-       Cached004ModeList[0] = CreateModeList(MODETYPE_USER);
-       Cached004ModeList[1] = CreateModeList(MODETYPE_CHANNEL);
-       Cached004ModeList[2] = CreateModeList(MODETYPE_CHANNEL, true);
-}
-
 PrefixMode* ModeParser::FindPrefix(unsigned const char pfxletter)
 {
        const PrefixModeList& list = GetPrefixModes();
index e17c8cd79417764df5bc883231aa2b811c64e229..1ddd3ca0ef99864d0c1da9a87b8ede2654be3c96 100644 (file)
@@ -557,45 +557,15 @@ void LocalUser::FullConnect()
        if (quitting)
                return;
 
-       this->WriteNumeric(RPL_WELCOME, InspIRCd::Format("Welcome to the %s IRC Network %s", ServerInstance->Config->Network.c_str(), GetFullRealHost().c_str()));
-       this->WriteNumeric(RPL_YOURHOSTIS, InspIRCd::Format("Your host is %s, running version %s", ServerInstance->Config->ServerName.c_str(), INSPIRCD_BRANCH));
-       this->WriteNumeric(RPL_SERVERCREATED, InspIRCd::TimeString(ServerInstance->startup_time, "This server was created %H:%M:%S %b %d %Y"));
-
-       const TR1NS::array<std::string, 3>& modelist = ServerInstance->Modes->GetModeListFor004Numeric();
-       this->WriteNumeric(RPL_SERVERVERSION, ServerInstance->Config->ServerName, INSPIRCD_BRANCH, modelist[0], modelist[1], modelist[2]);
-
-       ServerInstance->ISupport.SendTo(this);
-
-       /* Now registered */
-       if (ServerInstance->Users->unregistered_count)
-               ServerInstance->Users->unregistered_count--;
-
-       /* Trigger MOTD and LUSERS output, give modules a chance too */
-       ModResult MOD_RESULT;
-       std::string command("LUSERS");
-       CommandBase::Params parameters;
-       FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, this, true));
-       if (!MOD_RESULT)
-               ServerInstance->Parser.CallHandler(command, parameters, this);
-
-       MOD_RESULT = MOD_RES_PASSTHRU;
-       command = "MOTD";
-       FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, this, true));
-       if (!MOD_RESULT)
-               ServerInstance->Parser.CallHandler(command, parameters, this);
-
-       if (ServerInstance->Config->RawLog)
-       {
-               ClientProtocol::Messages::Privmsg rawlogmsg(ServerInstance->FakeClient, this, "*** Raw I/O logging is enabled on this server. All messages, passwords, and commands are being recorded.");
-               this->Send(ServerInstance->GetRFCEvents().privmsg, rawlogmsg);
-       }
-
        /*
         * We don't set REG_ALL until triggering OnUserConnect, so some module events don't spew out stuff
         * for a user that doesn't exist yet.
         */
        FOREACH_MOD(OnUserConnect, (this));
 
+       /* Now registered */
+       if (ServerInstance->Users->unregistered_count)
+               ServerInstance->Users->unregistered_count--;
        this->registered = REG_ALL;
 
        FOREACH_MOD(OnPostConnect, (this));