+ void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
+ {
+ ConfigTag* optionstag = ServerInstance->Config->ConfValue("options");
+
+ std::string current;
+ irc::spacesepstream defaultstream(optionstag->getString("exemptchanops"));
+ insp::flat_map<std::string, char> exempts;
+ while (defaultstream.GetToken(current))
+ {
+ std::string::size_type pos = current.find(':');
+ if (pos == std::string::npos || (pos + 2) > current.size())
+ throw ModuleException("Invalid exemptchanops value '" + current + "' at " + optionstag->getTagLocation());
+
+ const std::string restriction = current.substr(0, pos);
+ const char prefix = current[pos + 1];
+
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Exempting prefix %c from %s", prefix, restriction.c_str());
+ exempts[restriction] = prefix;
+ }
+
+ ConfigTag* securitytag = ServerInstance->Config->ConfValue("security");
+ const std::string announceinvites = securitytag->getString("announceinvites", "dynamic");
+ Invite::AnnounceState newannouncestate;
+ if (stdalgo::string::equalsci(announceinvites, "none"))
+ newannouncestate = Invite::ANNOUNCE_NONE;
+ else if (stdalgo::string::equalsci(announceinvites, "all"))
+ newannouncestate = Invite::ANNOUNCE_ALL;
+ else if (stdalgo::string::equalsci(announceinvites, "ops"))
+ newannouncestate = Invite::ANNOUNCE_OPS;
+ else if (stdalgo::string::equalsci(announceinvites, "dynamic"))
+ newannouncestate = Invite::ANNOUNCE_DYNAMIC;
+ else
+ throw ModuleException(announceinvites + " is an invalid <security:announceinvites> value, at " + securitytag->getTagLocation());
+
+ // Config is valid, apply it
+
+ // Validates and applies <maxlist> tags, so do it first
+ banmode.DoRehash();
+
+ exemptions.swap(exempts);
+ // 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;;
+ cmdinvite.announceinvites = newannouncestate;
+ joinhook.modefromuser = optionstag->getBool("cyclehostsfromuser");
+
+ Implementation events[] = { I_OnCheckKey, I_OnCheckLimit, I_OnCheckChannelBan };
+ if (optionstag->getBool("invitebypassmodes", true))
+ ServerInstance->Modules.Attach(events, this, sizeof(events)/sizeof(Implementation));
+ else
+ {
+ for (unsigned int i = 0; i < sizeof(events)/sizeof(Implementation); i++)
+ ServerInstance->Modules.Detach(events[i], this);
+ }
+ }
+
+ 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();
+ for (ModeParser::ListModeList::const_iterator iter = listmodes.begin(); iter != listmodes.end(); ++iter)
+ {
+ const unsigned int limit = (*iter)->GetLowerLimit();
+ limits[limit].push_back((*iter)->GetModeChar());
+ }
+
+ // Generate the MAXLIST token from the limits map.
+ std::string& buffer = tokens["MAXLIST"];
+ for (insp::flat_map<int, std::string>::const_iterator iter = limits.begin(); iter != limits.end(); ++iter)
+ {
+ if (!buffer.empty())
+ buffer.push_back(',');
+
+ std::string modes(iter->second);
+ std::sort(modes.begin(), modes.end());
+
+ buffer.append(modes);
+ buffer.push_back(':');
+ buffer.append(ConvToStr(iter->first));
+ }
+ }
+
+ 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;
+ }
+