]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/coremods/core_channel/core_channel.cpp
Merge branch 'insp20' into master.
[user/henk/code/inspircd.git] / src / coremods / core_channel / core_channel.cpp
index 045d94a1c93f301a7e66a421077542ee54540594..ccf4d1a6e1c64695b1ecf1a632054066036bbed5 100644 (file)
@@ -30,6 +30,19 @@ class CoreModChannel : public Module, public CheckExemption::EventListener
        CommandKick cmdkick;
        CommandNames cmdnames;
        CommandTopic cmdtopic;
+
+       ModeChannelBan banmode;
+       SimpleChannelModeHandler inviteonlymode;
+       ModeChannelKey keymode;
+       ModeChannelLimit limitmode;
+       SimpleChannelModeHandler moderatedmode;
+       SimpleChannelModeHandler noextmsgmode;
+       ModeChannelOp opmode;
+       SimpleChannelModeHandler privatemode;
+       SimpleChannelModeHandler secretmode;
+       SimpleChannelModeHandler topiclockmode;
+       ModeChannelVoice voicemode;
+
        insp::flat_map<std::string, char> exemptions;
 
        ModResult IsInvited(User* user, Channel* chan)
@@ -49,6 +62,17 @@ class CoreModChannel : public Module, public CheckExemption::EventListener
                , cmdkick(this)
                , cmdnames(this)
                , cmdtopic(this)
+               , banmode(this)
+               , inviteonlymode(this, "inviteonly", 'i')
+               , keymode(this)
+               , limitmode(this)
+               , moderatedmode(this, "moderated", 'm')
+               , noextmsgmode(this, "noextmsg", 'n')
+               , opmode(this)
+               , privatemode(this, "private", 'p')
+               , secretmode(this, "secret", 's')
+               , topiclockmode(this, "topiclock", 't')
+               , voicemode(this)
        {
        }
 
@@ -80,10 +104,31 @@ class CoreModChannel : public Module, public CheckExemption::EventListener
                        exempts[restriction] = prefix;
                }
                exemptions.swap(exempts);
+
+               ConfigTag* securitytag = ServerInstance->Config->ConfValue("security");
+               const std::string announceinvites = securitytag->getString("announceinvites", "dynamic");
+               if (stdalgo::string::equalsci(announceinvites, "none"))
+                       cmdinvite.announceinvites = Invite::ANNOUNCE_NONE;
+               else if (stdalgo::string::equalsci(announceinvites, "all"))
+                       cmdinvite.announceinvites = Invite::ANNOUNCE_ALL;
+               else if (stdalgo::string::equalsci(announceinvites, "ops"))
+                       cmdinvite.announceinvites = Invite::ANNOUNCE_OPS;
+               else if (stdalgo::string::equalsci(announceinvites, "dynamic"))
+                       cmdinvite.announceinvites = Invite::ANNOUNCE_DYNAMIC;
+               else
+                       throw ModuleException(announceinvites + " is an invalid <security:announceinvites> value, at " + securitytag->getTagLocation());
+
+               // In 2.0 we allowed limits of 0 to be set. This is non-standard behaviour
+               // and will be removed in the next major release.
+               limitmode.minlimit = optionstag->getBool("allowzerolimit", true) ? 0 : 1;
+
+               banmode.DoRehash();
        }
 
        void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
+               tokens["KEYLEN"] = ConvToStr(ModeChannelKey::maxkeylen);
+
                // Build a map of limits to their mode character.
                insp::flat_map<int, std::string> limits;
                const ModeParser::ListModeList& listmodes = ServerInstance->Modes->GetListModes();
@@ -94,7 +139,7 @@ class CoreModChannel : public Module, public CheckExemption::EventListener
                }
 
                // Generate the MAXLIST token from the limits map.
-               std::string& buffer = tokens["MAX       LIST"];
+               std::string& buffer = tokens["MAXLIST"];
                for (insp::flat_map<int, std::string>::const_iterator iter = limits.begin(); iter != limits.end(); ++iter)
                {
                        if (!buffer.empty())
@@ -106,6 +151,53 @@ class CoreModChannel : public Module, public CheckExemption::EventListener
                }
        }
 
+       ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string&, std::string&, const std::string& keygiven) CXX11_OVERRIDE
+       {
+               if (!chan)
+                       return MOD_RES_PASSTHRU;
+
+               // Check whether the channel key is correct.
+               const std::string ckey = chan->GetModeParameter(&keymode);
+               if (!ckey.empty())
+               {
+                       ModResult MOD_RESULT;
+                       FIRST_MOD_RESULT(OnCheckKey, MOD_RESULT, (user, chan, keygiven));
+                       if (!MOD_RESULT.check(InspIRCd::TimingSafeCompare(ckey, keygiven)))
+                       {
+                               // If no key provided, or key is not the right one, and can't bypass +k (not invited or option not enabled)
+                               user->WriteNumeric(ERR_BADCHANNELKEY, chan->name, "Cannot join channel (Incorrect channel key)");
+                               return MOD_RES_DENY;
+                       }
+               }
+
+               // Check whether the invite only mode is set.
+               if (chan->IsModeSet(inviteonlymode))
+               {
+                       ModResult MOD_RESULT;
+                       FIRST_MOD_RESULT(OnCheckInvite, MOD_RESULT, (user, chan));
+                       if (MOD_RESULT != MOD_RES_ALLOW)
+                       {
+                               user->WriteNumeric(ERR_INVITEONLYCHAN, chan->name, "Cannot join channel (Invite only)");
+                               return MOD_RES_DENY;
+                       }
+               }
+
+               // Check whether the limit would be exceeded by this user joining.
+               if (chan->IsModeSet(limitmode))
+               {
+                       ModResult MOD_RESULT;
+                       FIRST_MOD_RESULT(OnCheckLimit, MOD_RESULT, (user, chan));
+                       if (!MOD_RESULT.check(chan->GetUserCounter() < static_cast<size_t>(limitmode.ext.get(chan))))
+                       {
+                               user->WriteNumeric(ERR_CHANNELISFULL, chan->name, "Cannot join channel (Channel is full)");
+                               return MOD_RES_DENY;
+                       }
+               }
+
+               // Everything looks okay.
+               return MOD_RES_PASSTHRU;
+       }
+
        void OnPostJoin(Membership* memb) CXX11_OVERRIDE
        {
                Channel* const chan = memb->chan;
@@ -115,7 +207,7 @@ class CoreModChannel : public Module, public CheckExemption::EventListener
                        // Remove existing invite, if any
                        invapi.Remove(localuser, chan);
 
-                       if (chan->topicset)
+                       if (chan->topic.length())
                                Topic::ShowTopic(localuser, chan);
 
                        // Show all members of the channel, including invisible (+i) users
@@ -177,6 +269,7 @@ class CoreModChannel : public Module, public CheckExemption::EventListener
        void Prioritize() CXX11_OVERRIDE
        {
                ServerInstance->Modules.SetPriority(this, I_OnPostJoin, PRIORITY_FIRST);
+               ServerInstance->Modules.SetPriority(this, I_OnUserPreJoin, PRIORITY_LAST);
        }
 
        Version GetVersion() CXX11_OVERRIDE