diff options
Diffstat (limited to 'modules/protocol/inspircd20.cpp')
-rw-r--r-- | modules/protocol/inspircd20.cpp | 1930 |
1 files changed, 1202 insertions, 728 deletions
diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp index ab7649b69..14040d98e 100644 --- a/modules/protocol/inspircd20.cpp +++ b/modules/protocol/inspircd20.cpp @@ -1,105 +1,466 @@ -/* Inspircd 2.0 functions +/* + * Anope IRC Services * - * (C) 2003-2017 Anope Team - * Contact us at team@anope.org + * Copyright (C) 2005-2017 Anope Team <team@anope.org> * - * Please read COPYING and README for further details. + * This file is part of Anope. Anope 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. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. + * 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 see <http://www.gnu.org/licenses/>. */ +/* Dependencies: anope_protocol.rfc1459,anope_protocol.ts6 */ + #include "module.h" -#include "modules/cs_mode.h" +#include "modules/sasl.h" +#include "modules/chanserv/mode.h" +#include "modules/chanserv/set.h" +#include "modules/protocol/rfc1459.h" +#include "modules/protocol/inspircd20.h" +struct SASLUser +{ + Anope::string uid; + Anope::string acc; + time_t created; +}; + +static std::list<SASLUser> saslusers; +static Anope::string rsquit_server, rsquit_id; static unsigned int spanningtree_proto_ver = 0; -static ServiceReference<IRCDProto> insp12("IRCDProto", "inspircd12"); +void inspircd20::senders::Akill::Send(User* u, XLine* x) +{ + // Calculate the time left before this would expire, capping it at 2 days + time_t timeleft = x->GetExpires() - Anope::CurTime; + if (timeleft > 172800 || !x->GetExpires()) + timeleft = 172800; + + /* InspIRCd may support regex bans, if they do we can send this and forget about it */ + if (x->IsRegex() && Servers::Capab.count("RLINE")) + { + Anope::string mask = x->GetMask(); + size_t h = mask.find('#'); + if (h != Anope::string::npos) + mask = mask.replace(h, 1, ' '); + proto->SendAddLine("R", mask, timeleft, x->GetBy(), x->GetReason()); + return; + } + else if (x->IsRegex() || x->HasNickOrReal()) + { + if (!u) + { + /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */ + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + if (x->GetManager()->Check(it->second, x)) + this->Send(it->second, x); + return; + } + + XLine *old = x; + + if (old->GetManager()->HasEntry("*@" + u->host)) + return; + + /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */ + x = Serialize::New<XLine *>(); + x->SetMask("*@" + u->host); + x->SetBy(old->GetBy()); + x->SetExpires(old->GetExpires()); + x->SetReason(old->GetReason()); + old->GetManager()->AddXLine(x); -class InspIRCd20Proto : public IRCDProto + Anope::Logger.Bot("OperServ").Category("akill").Log(_("AKILL: Added an akill for {0} because {1}#{2} matches {3}"), + x->GetMask(), u->GetMask(), u->realname, old->GetMask()); + } + + /* ZLine if we can instead */ + if (x->GetUser() == "*") + { + cidr addr(x->GetHost()); + if (addr.valid()) + { + IRCD->Send<messages::SZLine>(u, x); + return; + } + } + + proto->SendAddLine("G", x->GetUser() + "@" + x->GetHost(), timeleft, x->GetBy(), x->GetReason()); +} + +void inspircd20::senders::AkillDel::Send(XLine* x) { - public: - InspIRCd20Proto(Module *creator) : IRCDProto(creator, "InspIRCd 2.0") + /* InspIRCd may support regex bans */ + if (x->IsRegex() && Servers::Capab.count("RLINE")) { - DefaultPseudoclientModes = "+I"; - CanSVSNick = true; - CanSVSJoin = true; - CanSetVHost = true; - CanSetVIdent = true; - CanSQLine = true; - CanSZLine = true; - CanSVSHold = true; - CanCertFP = true; - RequiresID = true; - MaxModes = 20; + Anope::string mask = x->GetMask(); + size_t h = mask.find('#'); + if (h != Anope::string::npos) + mask = mask.replace(h, 1, ' '); + proto->SendDelLine("R", mask); + return; } + else if (x->IsRegex() || x->HasNickOrReal()) + return; - void SendConnect() anope_override + /* ZLine if we can instead */ + if (x->GetUser() == "*") { - UplinkSocket::Message() << "CAPAB START 1202"; - UplinkSocket::Message() << "CAPAB CAPABILITIES :PROTOCOL=1202"; - UplinkSocket::Message() << "CAPAB END"; - insp12->SendConnect(); + cidr addr(x->GetHost()); + if (addr.valid()) + { + IRCD->Send<messages::SZLineDel>(x); + return; + } } - void SendSASLMechanisms(std::vector<Anope::string> &mechanisms) anope_override + proto->SendDelLine("G", x->GetUser() + "@" + x->GetHost()); +} + +void inspircd20::senders::MessageChannel::Send(Channel* c) +{ + Uplink::Send(Me, "FJOIN", c->name, c->creation_time, "+" + c->GetModes(true, true), ""); +} + +void inspircd20::senders::Join::Send(User* user, Channel* c, const ChannelStatus* status) +{ + Uplink::Send(Me, "FJOIN", c->name, c->creation_time, "+" + c->GetModes(true, true), "," + user->GetUID()); + + /* Note that we can send this with the FJOIN but choose not to + * because the mode stacker will handle this and probably will + * merge these modes with +nrt and other mlocked modes + */ + if (status) { - Anope::string mechlist; - for (unsigned i = 0; i < mechanisms.size(); ++i) - mechlist += "," + mechanisms[i]; + /* First save the channel status incase uc->Status == status */ + ChannelStatus cs = *status; + /* If the user is internally on the channel with flags, kill them so that + * the stacker will allow this. + */ + ChanUserContainer *uc = c->FindUser(user); + if (uc != NULL) + uc->status.Clear(); + + ServiceBot *setter = ServiceBot::Find(user->nick); + for (size_t i = 0; i < cs.Modes().length(); ++i) + c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); + + if (uc != NULL) + uc->status = cs; + } +} + +void inspircd20::senders::Login::Send(User *u, NickServ::Nick *na) +{ + /* InspIRCd uses an account to bypass chmode +R, not umode +r, so we can't send this here */ + if (na->GetAccount()->IsUnconfirmed()) + return; + + Uplink::Send(Me, "METADATA", u->GetUID(), "accountname", na->GetAccount()->GetDisplay()); +} + +void inspircd20::senders::Logout::Send(User *u) +{ + Uplink::Send(Me, "METADATA", u->GetUID(), "accountname", ""); +} + +void inspircd20::senders::ModeChannel::Send(const MessageSource &source, Channel *channel, const Anope::string &modes) +{ + IRCMessage message(source, "FMODE", channel->name, channel->creation_time); + message.TokenizeAndPush(modes); + Uplink::SendMessage(message); +} - UplinkSocket::Message(Me) << "METADATA * saslmechlist :" << (mechanisms.empty() ? "" : mechlist.substr(1)); +void inspircd20::senders::NickIntroduction::Send(User *user) +{ + Anope::string modes = "+" + user->GetModes(); + Uplink::Send(Me, "UID", user->GetUID(), user->timestamp, user->nick, user->host, user->host, user->GetIdent(), "0.0.0.0", user->timestamp, modes, user->realname); + if (modes.find('o') != Anope::string::npos) + Uplink::Send(user, "OPERTYPE", "services"); +} + + +void inspircd20::senders::SASL::Send(const ::SASL::Message& message) +{ + if (!message.ext.empty()) + Uplink::Send(Me, "ENCAP", message.target.substr(0, 3), "SASL", + message.source, message.target, + message.type, message.data, message.ext); + else + Uplink::Send(Me, "ENCAP", message.target.substr(0, 3), "SASL", + message.source, message.target, + message.type, message.data); +} + +void inspircd20::senders::SASLMechanisms::Send(const std::vector<Anope::string>& mechanisms) +{ + Anope::string mechlist; + for (unsigned int i = 0; i < mechanisms.size(); ++i) + mechlist += "," + mechanisms[i]; + + Uplink::Send(Me, "METADATA", "*", "saslmechlist", mechlist.empty() ? "" : mechlist.substr(1)); +} + +void inspircd20::senders::MessageServer::Send(Server* server) +{ + /* if rsquit is set then we are waiting on a squit */ + if (rsquit_id.empty() && rsquit_server.empty()) + Uplink::Send("SERVER", server->GetName(), Config->Uplinks[Anope::CurrentUplink].password, server->GetHops(), server->GetSID(), server->GetDescription()); +} + +void inspircd20::senders::SQLine::Send(User*, XLine* x) +{ + // Calculate the time left before this would expire, capping it at 2 days + time_t timeleft = x->GetExpires() - Anope::CurTime; + if (timeleft > 172800 || !x->GetExpires()) + timeleft = 172800; + proto->SendAddLine("Q", x->GetMask(), timeleft, x->GetBy(), x->GetReason()); +} + +void inspircd20::senders::SQLineDel::Send(XLine* x) +{ + proto->SendDelLine("Q", x->GetMask()); +} + +void inspircd20::senders::SQuit::Send(Server *s, const Anope::string &message) +{ + if (s != Me) + { + rsquit_id = s->GetSID(); + rsquit_server = s->GetName(); + + Uplink::Send("RSQUIT", s->GetName(), message); } + else + { + Uplink::Send("SQUIT", s->GetName(), message); + } +} - void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override { insp12->SendSVSKillInternal(source, user, buf); } - void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { insp12->SendGlobalNotice(bi, dest, msg); } - void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { insp12->SendGlobalPrivmsg(bi, dest, msg); } - void SendAkillDel(const XLine *x) anope_override { insp12->SendAkillDel(x); } - void SendTopic(const MessageSource &whosets, Channel *c) anope_override { insp12->SendTopic(whosets, c); }; - void SendVhostDel(User *u) anope_override { insp12->SendVhostDel(u); } - void SendAkill(User *u, XLine *x) anope_override { insp12->SendAkill(u, x); } - void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf) anope_override { insp12->SendNumericInternal(numeric, dest, buf); } - void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) anope_override { insp12->SendModeInternal(source, dest, buf); } - void SendClientIntroduction(User *u) anope_override { insp12->SendClientIntroduction(u); } - void SendServer(const Server *server) anope_override { insp12->SendServer(server); } - void SendSquit(Server *s, const Anope::string &message) anope_override { insp12->SendSquit(s, message); } - void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override { insp12->SendJoin(user, c, status); } - void SendSQLineDel(const XLine *x) anope_override { insp12->SendSQLineDel(x); } - void SendSQLine(User *u, const XLine *x) anope_override { insp12->SendSQLine(u, x); } - void SendVhost(User *u, const Anope::string &vident, const Anope::string &vhost) anope_override { insp12->SendVhost(u, vident, vhost); } - void SendSVSHold(const Anope::string &nick, time_t t) anope_override { insp12->SendSVSHold(nick, t); } - void SendSVSHoldDel(const Anope::string &nick) anope_override { insp12->SendSVSHoldDel(nick); } - void SendSZLineDel(const XLine *x) anope_override { insp12->SendSZLineDel(x); } - void SendSZLine(User *u, const XLine *x) anope_override { insp12->SendSZLine(u, x); } - void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &other) anope_override { insp12->SendSVSJoin(source, u, chan, other); } - void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string ¶m) anope_override { insp12->SendSVSPart(source, u, chan, param); } - void SendSWhois(const MessageSource &bi, const Anope::string &who, const Anope::string &mask) anope_override { insp12->SendSWhois(bi, who, mask); } - void SendBOB() anope_override { insp12->SendBOB(); } - void SendEOB() anope_override { insp12->SendEOB(); } - void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) { insp12->SendGlobopsInternal(source, buf); } - void SendLogin(User *u, NickAlias *na) anope_override { insp12->SendLogin(u, na); } - void SendLogout(User *u) anope_override { insp12->SendLogout(u); } - void SendChannel(Channel *c) anope_override { insp12->SendChannel(c); } - void SendSASLMessage(const SASL::Message &message) anope_override { insp12->SendSASLMessage(message); } - void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) anope_override { insp12->SendSVSLogin(uid, acc, vident, vhost); } - bool IsExtbanValid(const Anope::string &mask) anope_override { return insp12->IsExtbanValid(mask); } - bool IsIdentValid(const Anope::string &ident) anope_override { return insp12->IsIdentValid(ident); } -}; +void inspircd20::senders::SZLine::Send(User*, XLine* x) +{ + // Calculate the time left before this would expire, capping it at 2 days + time_t timeleft = x->GetExpires() - Anope::CurTime; + if (timeleft > 172800 || !x->GetExpires()) + timeleft = 172800; + proto->SendAddLine("Z", x->GetHost(), timeleft, x->GetBy(), x->GetReason()); +} -class InspIRCdAutoOpMode : public ChannelModeList +void inspircd20::senders::SZLineDel::Send(XLine* x) { - public: - InspIRCdAutoOpMode(char mode) : ChannelModeList("AUTOOP", mode) + proto->SendDelLine("Z", x->GetHost()); +} + +void inspircd20::senders::SVSHold::Send(const Anope::string& nick, time_t t) +{ + Uplink::Send(Config->GetClient("NickServ"), "SVSHOLD", nick, t, "Being held for registered user"); +} + +void inspircd20::senders::SVSHoldDel::Send(const Anope::string& nick) +{ + Uplink::Send(Config->GetClient("NickServ"), "SVSHOLD", nick); +} + +void inspircd20::senders::SVSJoin::Send(const MessageSource& source, User* u, const Anope::string& chan, const Anope::string& key) +{ + Uplink::Send(source, "SVSJOIN", u->GetUID(), chan); +} + +void inspircd20::senders::SVSLogin::Send(const Anope::string& uid, const Anope::string& acc, const Anope::string& vident, const Anope::string& vhost) +{ + Uplink::Send(Me, "METADATA", uid, "accountname", acc); + + SASLUser su; + su.uid = uid; + su.acc = acc; + su.created = Anope::CurTime; + + for (std::list<SASLUser>::iterator it = saslusers.begin(); it != saslusers.end();) { + SASLUser &u = *it; + + if (u.created + 30 < Anope::CurTime || u.uid == uid) + it = saslusers.erase(it); + else + ++it; } - bool IsValid(Anope::string &mask) const anope_override + saslusers.push_back(su); +} + +void inspircd20::senders::SVSNick::Send(User* u, const Anope::string& newnick, time_t ts) +{ + Uplink::Send("SVSNICK", u->GetUID(), newnick, ts); +} + +void inspircd20::senders::SVSPart::Send(const MessageSource& source, User* u, const Anope::string& chan, const Anope::string& reason) +{ + if (!reason.empty()) + Uplink::Send(source, "SVSPART", u->GetUID(), chan, reason); + else + Uplink::Send(source, "SVSPART", u->GetUID(), chan); +} + +void inspircd20::senders::SWhois::Send(const MessageSource&, User *user, const Anope::string& swhois) +{ + Uplink::Send(Me, "METADATA", user->GetUID(), "swhois", swhois); +} + +void inspircd20::senders::Topic::Send(const MessageSource &source, Channel *channel, const Anope::string &topic, time_t topic_ts, const Anope::string &topic_setter) +{ + if (Servers::Capab.count("SVSTOPIC")) + { + Uplink::Send(source, "SVSTOPIC", channel->name, topic_ts, topic_setter, topic); + } + else + { + /* If the last time a topic was set is after the TS we want for this topic we must bump this topic's timestamp to now */ + time_t ts = topic_ts; + if (channel->topic_time > ts) + ts = Anope::CurTime; + /* But don't modify c->topic_ts, it should remain set to the real TS we want as ci->last_topic_time pulls from it */ + Uplink::Send(source, "FTOPIC", channel->name, ts, topic_setter, topic); + } +} + +void inspircd20::senders::VhostDel::Send(User* u) +{ + if (u->HasMode("CLOAK")) + proto->SendChgHostInternal(u->nick, u->chost); + else + proto->SendChgHostInternal(u->nick, u->host); + + if (Servers::Capab.count("CHGIDENT") && u->GetIdent() != u->GetVIdent()) + proto->SendChgIdentInternal(u->nick, u->GetIdent()); +} + +void inspircd20::senders::VhostSet::Send(User* u, const Anope::string& vident, const Anope::string& vhost) +{ + if (!vident.empty()) + proto->SendChgIdentInternal(u->nick, vident); + if (!vhost.empty()) + proto->SendChgHostInternal(u->nick, vhost); +} + +void inspircd20::senders::Wallops::Send(const MessageSource &source, const Anope::string &msg) +{ + if (Servers::Capab.count("GLOBOPS")) + Uplink::Send(source, "SNONOTICE", "g", msg); + else + Uplink::Send(source, "SNONOTICE", "A", msg); +} + +void inspircd20::Proto::SendChgIdentInternal(const Anope::string &nick, const Anope::string &vIdent) +{ + if (!Servers::Capab.count("CHGIDENT")) + Anope::Logger.Log("CHGIDENT not loaded!"); + else + Uplink::Send(Me, "CHGIDENT", nick, vIdent); +} + +void inspircd20::Proto::SendChgHostInternal(const Anope::string &nick, const Anope::string &vhost) +{ + if (!Servers::Capab.count("CHGHOST")) + Anope::Logger.Log("CHGHOST not loaded!"); + else + Uplink::Send(Me, "CHGHOST", nick, vhost); +} + +void inspircd20::Proto::SendAddLine(const Anope::string &xtype, const Anope::string &mask, time_t duration, const Anope::string &addedby, const Anope::string &reason) +{ + Uplink::Send(Me, "ADDLINE", xtype, mask, addedby, Anope::CurTime, duration, reason); +} + +void inspircd20::Proto::SendDelLine(const Anope::string &xtype, const Anope::string &mask) +{ + Uplink::Send(Me, "DELLINE", xtype, mask); +} + +inspircd20::Proto::Proto(Module *creator) : ts6::Proto(creator, "InspIRCd 2.0") +{ + DefaultPseudoclientModes = "+I"; + CanSVSNick = true; + CanSVSJoin = true; + CanSetVHost = true; + CanSetVIdent = true; + CanSQLine = true; + CanSZLine = true; + CanSVSHold = true; + CanCertFP = true; + RequiresID = true; + MaxModes = 20; +} + +void inspircd20::Proto::Handshake() +{ + Uplink::Send("CAPAB START 1202"); + Uplink::Send("CAPAB CAPABILITIES :PROTOCOL=1202"); + Uplink::Send("CAPAB END"); + IRCD->Send<messages::MessageServer>(Me); +} + +void inspircd20::Proto::SendNumeric(int numeric, User *dest, IRCMessage &message) +{ + std::vector<Anope::string> params = message.GetParameters(); + if (params.empty()) + return; + + /* First parameter is the UID, change it to nick because it is pushed */ + params[0] = dest->nick; + + IRCMessage m(message.GetSource(), message.GetCommand()); + for (const Anope::string &s : params) + m.Push(s); + + Uplink::Send("PUSH", dest->GetUID(), Format(m)); +} + +void inspircd20::Proto::SendBOB() +{ + Uplink::Send(Me, "BURST", Anope::CurTime); + Module *enc = ModuleManager::FindFirstOf(ENCRYPTION); + Uplink::Send(Me, "VERSION", Anope::Format("Anope-{0} {1} {2} - {3} - Built: {4} - Flags: {5}", + Anope::Version(), Me->GetName(), IRCD->GetProtocolName(), enc ? enc->name : "(none)", Anope::VersionBuildTime(), Anope::VersionFlags())); +} + +void inspircd20::Proto::SendEOB() +{ + Uplink::Send(Me, "ENDBURST"); +} + +bool inspircd20::Proto::IsExtbanValid(const Anope::string &mask) +{ + return mask.length() >= 3 && mask[1] == ':'; +} + +bool inspircd20::Proto::IsIdentValid(const Anope::string &ident) +{ + if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned int>("userlen")) + return false; + + for (unsigned i = 0; i < ident.length(); ++i) { - // We can not validate this because we don't know about the - // privileges of the setter so just reject attempts to set it. + const char &c = ident[i]; + + if (c >= 'A' && c <= '}') + continue; + + if ((c >= '0' && c <= '9') || c == '-' || c == '.') + continue; + return false; } -}; + + return true; +} class InspIRCdExtBan : public ChannelModeVirtual<ChannelModeList> { @@ -111,13 +472,13 @@ class InspIRCdExtBan : public ChannelModeVirtual<ChannelModeList> { } - ChannelMode *Wrap(Anope::string ¶m) anope_override + ChannelMode *Wrap(Anope::string ¶m) override { param = Anope::string(ext) + ":" + param; return ChannelModeVirtual<ChannelModeList>::Wrap(param); } - ChannelMode *Unwrap(ChannelMode *cm, Anope::string ¶m) anope_override + ChannelMode *Unwrap(ChannelMode *cm, Anope::string ¶m) override { if (cm->type != MODE_LIST || param.length() < 3 || param[0] != ext || param[1] != ':') return cm; @@ -136,7 +497,7 @@ namespace InspIRCdExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string real_mask = mask.substr(3); @@ -152,7 +513,7 @@ namespace InspIRCdExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); @@ -188,12 +549,12 @@ namespace InspIRCdExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string real_mask = mask.substr(2); - return u->IsIdentified() && real_mask.equals_ci(u->Account()->display); + return u->IsIdentified() && real_mask.equals_ci(u->Account()->GetDisplay()); } }; @@ -204,7 +565,7 @@ namespace InspIRCdExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string real_mask = mask.substr(2); @@ -219,7 +580,7 @@ namespace InspIRCdExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string real_mask = mask.substr(2); @@ -227,14 +588,14 @@ namespace InspIRCdExtban } }; - class FinerprintMatcher : public InspIRCdExtBan + class FingerprintMatcher : public InspIRCdExtBan { public: - FinerprintMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c) + FingerprintMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c) { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string real_mask = mask.substr(2); @@ -249,7 +610,7 @@ namespace InspIRCdExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string real_mask = mask.substr(2); @@ -258,785 +619,900 @@ namespace InspIRCdExtban }; } -class ColonDelimitedParamMode : public ChannelModeParam +void inspircd20::Capab::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - public: - ColonDelimitedParamMode(const Anope::string &modename, char modeChar) : ChannelModeParam(modename, modeChar, true) { } - - bool IsValid(Anope::string &value) const anope_override + if (params[0].equals_cs("START")) { - return IsValid(value, false); - } + if (params.size() >= 2) + spanningtree_proto_ver = (Anope::string(params[1]).is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0); - bool IsValid(const Anope::string &value, bool historymode) const - { - if (value.empty()) - return false; // empty param is never valid + if (spanningtree_proto_ver < 1202) + { + Uplink::Send("ERROR", "Protocol mismatch, no or invalid protocol version given in CAPAB START"); + Anope::QuitReason = "Protocol mismatch, no or invalid protocol version given in CAPAB START"; + Anope::Quitting = true; + return; + } - Anope::string::size_type pos = value.find(':'); - if ((pos == Anope::string::npos) || (pos == 0)) - return false; // no ':' or it's the first char, both are invalid + /* reset CAPAB */ + Servers::Capab.insert("SERVERS"); + Servers::Capab.insert("CHGHOST"); + Servers::Capab.insert("CHGIDENT"); + Servers::Capab.insert("TOPICLOCK"); + IRCD->CanSVSHold = false; + } + else if (params[0].equals_cs("CHANMODES") && params.size() > 1) + { + spacesepstream ssep(params[1]); + Anope::string capab; - Anope::string rest; - try + while (ssep.GetToken(capab)) { - if (convertTo<int>(value, rest, false) <= 0) - return false; // negative numbers and zero are invalid + if (capab.find('=') == Anope::string::npos) + continue; - rest = rest.substr(1); - int n; - if (historymode) + Anope::string modename = capab.substr(0, capab.find('=')); + Anope::string modechar = capab.substr(capab.find('=') + 1); + char symbol = 0; + + if (modechar.empty()) + continue; + + if (modechar.length() == 2) { - // For the history mode, the part after the ':' is a duration and it - // can be in the user friendly "1d3h20m" format, make sure we accept that - n = Anope::DoTime(rest); + symbol = modechar[0]; + modechar = modechar.substr(1); } - else - n = convertTo<int>(rest); - if (n <= 0) - return false; + ChannelMode *cm = ModeManager::FindChannelModeByChar(modechar[0]); + if (cm == nullptr) + { + this->GetOwner()->logger.Log("Warning: Uplink has unknown channel mode {0}={1}", + modename, modechar); + continue; + } + + char modesymbol = cm->type == MODE_STATUS ? (anope_dynamic_static_cast<ChannelModeStatus *>(cm))->symbol : 0; + if (symbol != modesymbol) + { + this->GetOwner()->logger.Log("Warning: Channel mode {0} has a misconfigured status character", + modename); + continue; + } } - catch (const ConvertException &e) + } + if (params[0].equals_cs("USERMODES") && params.size() > 1) + { + spacesepstream ssep(params[1]); + Anope::string capab; + + while (ssep.GetToken(capab)) { - // conversion error, invalid - return false; - } + if (capab.find('=') == Anope::string::npos) + continue; - return true; - } -}; + Anope::string modename = capab.substr(0, capab.find('=')); + Anope::string modechar = capab.substr(capab.find('=') + 1); -class SimpleNumberParamMode : public ChannelModeParam -{ - public: - SimpleNumberParamMode(const Anope::string &modename, char modeChar) : ChannelModeParam(modename, modeChar, true) { } + if (modechar.empty()) + continue; - bool IsValid(Anope::string &value) const anope_override + UserMode *um = ModeManager::FindUserModeByChar(modechar[0]); + if (um == nullptr) + { + this->GetOwner()->logger.Log("Warning: Uplink has unknown user mode {0}={1}", + modename, modechar); + continue; + } + } + } + else if (params[0].equals_cs("MODULES") && params.size() > 1) { - if (value.empty()) - return false; // empty param is never valid + spacesepstream ssep(params[1]); + Anope::string module; - try + while (ssep.GetToken(module)) { - if (convertTo<int>(value) <= 0) - return false; + if (module.equals_cs("m_svshold.so")) + IRCD->CanSVSHold = true; + else if (module.find("m_rline.so") == 0) + { + Servers::Capab.insert("RLINE"); + const Anope::string ®exengine = Config->GetBlock("options")->Get<Anope::string>("regexengine"); + if (!regexengine.empty() && module.length() > 11 && regexengine != module.substr(11)) + this->GetOwner()->logger.Log("Warning: InspIRCd is using regex engine {0}, but we have {1}. " + "This may cause inconsistencies.", + module.substr(11), regexengine); + } + else if (module.equals_cs("m_topiclock.so")) + Servers::Capab.insert("TOPICLOCK"); } - catch (const ConvertException &e) + } + else if (params[0].equals_cs("MODSUPPORT") && params.size() > 1) + { + spacesepstream ssep(params[1]); + Anope::string module; + + while (ssep.GetToken(module)) { - // conversion error, invalid - return false; + if (module.equals_cs("m_services_account.so")) + Servers::Capab.insert("SERVICES"); + else if (module.equals_cs("m_chghost.so")) + Servers::Capab.insert("CHGHOST"); + else if (module.equals_cs("m_chgident.so")) + Servers::Capab.insert("CHGIDENT"); } - - return true; } -}; + else if (params[0].equals_cs("CAPABILITIES") && params.size() > 1) + { + spacesepstream ssep(params[1]); + Anope::string capab; + while (ssep.GetToken(capab)) + { + if (capab.find("MAXMODES=") != Anope::string::npos) + { + Anope::string maxmodes(capab.begin() + 9, capab.end()); + IRCD->MaxModes = maxmodes.is_pos_number_only() ? convertTo<unsigned>(maxmodes) : 3; + } + else if (capab == "GLOBOPS=1") + Servers::Capab.insert("GLOBOPS"); + } + } + else if (params[0].equals_cs("END")) + { + if (!Servers::Capab.count("SERVICES")) + { + Uplink::Send("ERROR", "m_services_account.so is not loaded. This is required by Anope"); + Anope::QuitReason = "ERROR: Remote server does not have the m_services_account module loaded, and this is required."; + Anope::Quitting = true; + return; + } + if (!ModeManager::FindUserModeByName("PRIV")) + { + Uplink::Send("ERROR", "m_hidechans.so is not loaded. This is required by Anope"); + Anope::QuitReason = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required."; + Anope::Quitting = true; + return; + } + if (!IRCD->CanSVSHold) + this->GetOwner()->logger.Log("SVSHOLD missing, Usage disabled until module is loaded."); + if (!Servers::Capab.count("CHGHOST")) + this->GetOwner()->logger.Log("CHGHOST missing, Usage disabled until module is loaded."); + if (!Servers::Capab.count("CHGIDENT")) + this->GetOwner()->logger.Log("CHGIDENT missing, Usage disabled until module is loaded."); + } -class ChannelModeFlood : public ColonDelimitedParamMode + rfc1459::Capab::Run(source, params); +} + +void inspircd20::ChgHost::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - public: - ChannelModeFlood(char modeChar) : ColonDelimitedParamMode("FLOOD", modeChar) { } + User *u = User::Find(params[0]); + if (!u || u->server != Me) + return; - bool IsValid(Anope::string &value) const anope_override - { - // The parameter of this mode is a bit different, it may begin with a '*', - // ignore it if that's the case - Anope::string v = value[0] == '*' ? value.substr(1) : value; - return ((!value.empty()) && (ColonDelimitedParamMode::IsValid(v))); - } -}; + u->SetDisplayedHost(params[1]); + Uplink::Send(u, "FHOST", params[1]); +} -class ChannelModeHistory : public ColonDelimitedParamMode +void inspircd20::ChgIdent::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - public: - ChannelModeHistory(char modeChar) : ColonDelimitedParamMode("HISTORY", modeChar) { } + User *u = User::Find(params[0]); + if (!u || u->server != Me) + return; + + u->SetIdent(params[1]); + Uplink::Send(u, "FIDENT", params[1]); +} + +void inspircd20::ChgName::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + User *u = User::Find(params[0]); + if (!u || u->server != Me) + return; + + u->SetRealname(params[1]); + Uplink::Send(u, "FNAME", params[1]); +} + +void inspircd20::Encap::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + if (!Anope::Match(Me->GetSID(), params[0]) && !Anope::Match(Me->GetName(), params[0])) + return; + + const Anope::string &command = params[1]; + std::vector<Anope::string> encap_params(params.begin() + 2, params.end()); + + Anope::ProcessCommand(source, command, encap_params); +} - bool IsValid(Anope::string &value) const anope_override +void inspircd20::Endburst::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + Server *s = source.GetServer(); + + s->logger.Debug("Processed ENDBURST for {0}", s->GetName()); + + s->Sync(true); +} + +void inspircd20::FHost::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + User *u = source.GetUser(); + if (u->HasMode("CLOAK")) + u->RemoveModeInternal(source, ModeManager::FindUserModeByName("CLOAK")); + u->SetDisplayedHost(params[0]); +} + +void inspircd20::FIdent::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + source.GetUser()->SetIdent(params[0]); +} + +void inspircd20::FJoin::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + Anope::string modes; + if (params.size() >= 3) { - return (ColonDelimitedParamMode::IsValid(value, true)); + for (unsigned i = 2; i < params.size() - 1; ++i) + modes += " " + params[i]; + if (!modes.empty()) + modes.erase(modes.begin()); } -}; -class ChannelModeRedirect : public ChannelModeParam -{ - public: - ChannelModeRedirect(char modeChar) : ChannelModeParam("REDIRECT", modeChar, true) { } + std::list<rfc1459::Join::SJoinUser> users; - bool IsValid(Anope::string &value) const anope_override + spacesepstream sep(params[params.size() - 1]); + Anope::string buf; + while (sep.GetToken(buf)) { - // The parameter of this mode is a channel, and channel names start with '#' - return ((!value.empty()) && (value[0] == '#')); + rfc1459::Join::SJoinUser sju; + + /* Loop through prefixes and find modes for them */ + for (char c; !buf.empty() && (c = buf[0]) != ',';) + { + buf.erase(buf.begin()); + sju.first.AddMode(c); + } + /* Erase the , */ + if (!buf.empty()) + buf.erase(buf.begin()); + + sju.second = User::Find(buf); + if (!sju.second) + { + this->GetOwner()->logger.Debug("FJOIN for non-existent user {0} on {1}", buf, params[0]); + continue; + } + + users.push_back(sju); } -}; -struct IRCDMessageCapab : Message::Capab + time_t ts = Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime; + rfc1459::Join::SJoin(source, params[0], ts, modes, users); +} + +void inspircd20::FMode::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - std::map<char, Anope::string> chmodes, umodes; + /* :source FMODE #test 12345678 +nto foo */ - IRCDMessageCapab(Module *creator) : Message::Capab(creator, "CAPAB") { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + Anope::string modes = params[2]; + for (unsigned n = 3; n < params.size(); ++n) + modes += " " + params[n]; - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + Channel *c = Channel::Find(params[0]); + time_t ts; + + try { - if (params[0].equals_cs("START")) - { - if (params.size() >= 2) - spanningtree_proto_ver = (Anope::string(params[1]).is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0); + ts = convertTo<time_t>(params[1]); + } + catch (const ConvertException &) + { + ts = 0; + } - if (spanningtree_proto_ver < 1202) - { - UplinkSocket::Message() << "ERROR :Protocol mismatch, no or invalid protocol version given in CAPAB START"; - Anope::QuitReason = "Protocol mismatch, no or invalid protocol version given in CAPAB START"; - Anope::Quitting = true; - return; - } + if (c) + c->SetModesInternal(source, modes, ts); +} - /* reset CAPAB */ - chmodes.clear(); - umodes.clear(); - Servers::Capab.insert("SERVERS"); - Servers::Capab.insert("TOPICLOCK"); - IRCD->CanSVSHold = false; - } - else if (params[0].equals_cs("CHANMODES") && params.size() > 1) - { - spacesepstream ssep(params[1]); - Anope::string capab; +void inspircd20::FTopic::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + /* :source FTOPIC channel topicts setby :topic */ - while (ssep.GetToken(capab)) - { - Anope::string modename = capab.substr(0, capab.find('=')); - Anope::string modechar = capab.substr(capab.find('=') + 1); - ChannelMode *cm = NULL; - - if (modename.equals_cs("admin")) - cm = new ChannelModeStatus("PROTECT", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 3); - else if (modename.equals_cs("allowinvite")) - { - cm = new ChannelMode("ALLINVITE", modechar[0]); - ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("INVITEBAN", "BAN", 'A')); - } - else if (modename.equals_cs("auditorium")) - cm = new ChannelMode("AUDITORIUM", modechar[0]); - else if (modename.equals_cs("autoop")) - cm = new InspIRCdAutoOpMode(modechar[0]); - else if (modename.equals_cs("ban")) - cm = new ChannelModeList("BAN", modechar[0]); - else if (modename.equals_cs("banexception")) - cm = new ChannelModeList("EXCEPT", modechar[0]); - else if (modename.equals_cs("blockcaps")) - { - cm = new ChannelMode("BLOCKCAPS", modechar[0]); - ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("BLOCKCAPSBAN", "BAN", 'B')); - } - else if (modename.equals_cs("blockcolor")) - { - cm = new ChannelMode("BLOCKCOLOR", modechar[0]); - ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("BLOCKCOLORBAN", "BAN", 'c')); - } - else if (modename.equals_cs("c_registered")) - cm = new ChannelModeNoone("REGISTERED", modechar[0]); - else if (modename.equals_cs("censor")) - cm = new ChannelMode("CENSOR", modechar[0]); - else if (modename.equals_cs("delayjoin")) - cm = new ChannelMode("DELAYEDJOIN", modechar[0]); - else if (modename.equals_cs("delaymsg")) - cm = new SimpleNumberParamMode("DELAYMSG", modechar[0]); - else if (modename.equals_cs("filter")) - cm = new ChannelModeList("FILTER", modechar[0]); - else if (modename.equals_cs("flood")) - cm = new ChannelModeFlood(modechar[0]); - else if (modename.equals_cs("founder")) - cm = new ChannelModeStatus("OWNER", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 4); - else if (modename.equals_cs("halfop")) - cm = new ChannelModeStatus("HALFOP", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 1); - else if (modename.equals_cs("history")) - cm = new ChannelModeHistory(modechar[0]); - else if (modename.equals_cs("invex")) - cm = new ChannelModeList("INVITEOVERRIDE", modechar[0]); - else if (modename.equals_cs("inviteonly")) - cm = new ChannelMode("INVITE", modechar[0]); - else if (modename.equals_cs("joinflood")) - cm = new ColonDelimitedParamMode("JOINFLOOD", modechar[0]); - else if (modename.equals_cs("key")) - cm = new ChannelModeKey(modechar[0]); - else if (modename.equals_cs("kicknorejoin")) - cm = new SimpleNumberParamMode("NOREJOIN", modechar[0]); - else if (modename.equals_cs("limit")) - cm = new ChannelModeParam("LIMIT", modechar[0], true); - else if (modename.equals_cs("moderated")) - cm = new ChannelMode("MODERATED", modechar[0]); - else if (modename.equals_cs("nickflood")) - cm = new ColonDelimitedParamMode("NICKFLOOD", modechar[0]); - else if (modename.equals_cs("noctcp")) - { - cm = new ChannelMode("NOCTCP", modechar[0]); - ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("NOCTCPBAN", "BAN", 'C')); - } - else if (modename.equals_cs("noextmsg")) - cm = new ChannelMode("NOEXTERNAL", modechar[0]); - else if (modename.equals_cs("nokick")) - { - cm = new ChannelMode("NOKICK", modechar[0]); - ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("NOKICKBAN", "BAN", 'Q')); - } - else if (modename.equals_cs("noknock")) - cm = new ChannelMode("NOKNOCK", modechar[0]); - else if (modename.equals_cs("nonick")) - { - cm = new ChannelMode("NONICK", modechar[0]); - ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("NONICKBAN", "BAN", 'N')); - } - else if (modename.equals_cs("nonotice")) - { - cm = new ChannelMode("NONOTICE", modechar[0]); - ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("NONOTICEBAN", "BAN", 'T')); - } - else if (modename.equals_cs("official-join")) - cm = new ChannelModeStatus("OFFICIALJOIN", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 2); - else if (modename.equals_cs("op")) - cm = new ChannelModeStatus("OP", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 2); - else if (modename.equals_cs("operonly")) - cm = new ChannelModeOperOnly("OPERONLY", modechar[0]); - else if (modename.equals_cs("operprefix")) - cm = new ChannelModeStatus("OPERPREFIX", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 2); - else if (modename.equals_cs("permanent")) - cm = new ChannelMode("PERM", modechar[0]); - else if (modename.equals_cs("private")) - cm = new ChannelMode("PRIVATE", modechar[0]); - else if (modename.equals_cs("redirect")) - cm = new ChannelModeRedirect(modechar[0]); - else if (modename.equals_cs("reginvite")) - cm = new ChannelMode("REGISTEREDONLY", modechar[0]); - else if (modename.equals_cs("regmoderated")) - cm = new ChannelMode("REGMODERATED", modechar[0]); - else if (modename.equals_cs("secret")) - cm = new ChannelMode("SECRET", modechar[0]); - else if (modename.equals_cs("sslonly")) - { - cm = new ChannelMode("SSL", modechar[0]); - ModeManager::AddChannelMode(new InspIRCdExtban::FinerprintMatcher("SSLBAN", "BAN", 'z')); - } - else if (modename.equals_cs("stripcolor")) - { - cm = new ChannelMode("STRIPCOLOR", modechar[0]); - ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("STRIPCOLORBAN", "BAN", 'S')); - } - else if (modename.equals_cs("topiclock")) - cm = new ChannelMode("TOPIC", modechar[0]); - else if (modename.equals_cs("voice")) - cm = new ChannelModeStatus("VOICE", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 0); - /* Unknown status mode, (customprefix) - add it */ - else if (modechar.length() == 2) - cm = new ChannelModeStatus(modename.upper(), modechar[1], modechar[0], -1); - /* Unknown non status mode, add it to our list for later */ - else - chmodes[modechar[0]] = modename.upper(); + Channel *c = Channel::Find(params[0]); + time_t ts = Anope::CurTime; - if (cm) - ModeManager::AddChannelMode(cm); - } - } - if (params[0].equals_cs("USERMODES") && params.size() > 1) - { - spacesepstream ssep(params[1]); - Anope::string capab; + try + { + ts = convertTo<time_t>(params[1]); + } + catch (const ConvertException &) { } - while (ssep.GetToken(capab)) - { - Anope::string modename = capab.substr(0, capab.find('=')); - Anope::string modechar = capab.substr(capab.find('=') + 1); - UserMode *um = NULL; - - if (modename.equals_cs("bot")) - um = new UserMode("BOT", modechar[0]); - else if (modename.equals_cs("callerid")) - um = new UserMode("CALLERID", modechar[0]); - else if (modename.equals_cs("cloak")) - um = new UserMode("CLOAK", modechar[0]); - else if (modename.equals_cs("deaf")) - um = new UserMode("DEAF", modechar[0]); - else if (modename.equals_cs("deaf_commonchan")) - um = new UserMode("COMMONCHANS", modechar[0]); - else if (modename.equals_cs("helpop")) - um = new UserModeOperOnly("HELPOP", modechar[0]); - else if (modename.equals_cs("hidechans")) - um = new UserMode("PRIV", modechar[0]); - else if (modename.equals_cs("hideoper")) - um = new UserModeOperOnly("HIDEOPER", modechar[0]); - else if (modename.equals_cs("invisible")) - um = new UserMode("INVIS", modechar[0]); - else if (modename.equals_cs("invis-oper")) - um = new UserModeOperOnly("INVISIBLE_OPER", modechar[0]); - else if (modename.equals_cs("oper")) - um = new UserModeOperOnly("OPER", modechar[0]); - else if (modename.equals_cs("regdeaf")) - um = new UserMode("REGPRIV", modechar[0]); - else if (modename.equals_cs("servprotect")) - { - um = new UserModeNoone("PROTECTED", modechar[0]); - IRCD->DefaultPseudoclientModes += modechar; - } - else if (modename.equals_cs("showwhois")) - um = new UserMode("WHOIS", modechar[0]); - else if (modename.equals_cs("u_censor")) - um = new UserMode("CENSOR", modechar[0]); - else if (modename.equals_cs("u_registered")) - um = new UserModeNoone("REGISTERED", modechar[0]); - else if (modename.equals_cs("u_stripcolor")) - um = new UserMode("STRIPCOLOR", modechar[0]); - else if (modename.equals_cs("wallops")) - um = new UserMode("WALLOPS", modechar[0]); - else - umodes[modechar[0]] = modename.upper(); + if (c) + c->ChangeTopicInternal(NULL, params[2], params[3], ts); +} - if (um) - ModeManager::AddUserMode(um); - } - } - else if (params[0].equals_cs("MODULES") && params.size() > 1) - { - spacesepstream ssep(params[1]); - Anope::string module; +void inspircd20::Idle::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + ServiceBot *bi = ServiceBot::Find(params[0]); + if (bi) + { + Uplink::Send(bi, "IDLE", source.GetSource(), Anope::StartTime, Anope::CurTime - bi->lastmsg); + } + else + { + User *u = User::Find(params[0]); + if (u && u->server == Me) + Uplink::Send(u, "IDLE", source.GetSource(), Anope::StartTime, 0); + } +} - while (ssep.GetToken(module)) - { - if (module.equals_cs("m_svshold.so")) - IRCD->CanSVSHold = true; - else if (module.find("m_rline.so") == 0) - { - Servers::Capab.insert("RLINE"); - const Anope::string ®exengine = Config->GetBlock("options")->Get<const Anope::string>("regexengine"); - if (!regexengine.empty() && module.length() > 11 && regexengine != module.substr(11)) - Log() << "Warning: InspIRCd is using regex engine " << module.substr(11) << ", but we have " << regexengine << ". This may cause inconsistencies."; - } - else if (module.equals_cs("m_topiclock.so")) - Servers::Capab.insert("TOPICLOCK"); - } - } - else if (params[0].equals_cs("MODSUPPORT") && params.size() > 1) +/* + * source = numeric of the sending server + * params[0] = uuid + * params[1] = metadata name + * params[2] = data + */ +void inspircd20::Metadata::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + if (isdigit(params[0][0])) + { + if (params[1].equals_cs("accountname")) { - spacesepstream ssep(params[1]); - Anope::string module; - - while (ssep.GetToken(module)) - { - if (module.equals_cs("m_services_account.so")) - { - Servers::Capab.insert("SERVICES"); - ModeManager::AddChannelMode(new InspIRCdExtban::AccountMatcher("ACCOUNTBAN", "BAN", 'R')); - ModeManager::AddChannelMode(new InspIRCdExtban::UnidentifiedMatcher("UNREGISTEREDBAN", "BAN", 'U')); - } - else if (module.equals_cs("m_chghost.so")) - Servers::Capab.insert("CHGHOST"); - else if (module.equals_cs("m_chgident.so")) - Servers::Capab.insert("CHGIDENT"); - else if (module == "m_channelban.so") - ModeManager::AddChannelMode(new InspIRCdExtban::ChannelMatcher("CHANNELBAN", "BAN", 'j')); - else if (module == "m_gecosban.so") - ModeManager::AddChannelMode(new InspIRCdExtban::RealnameMatcher("REALNAMEBAN", "BAN", 'r')); - else if (module == "m_nopartmessage.so") - ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("PARTMESSAGEBAN", "BAN", 'p')); - else if (module == "m_serverban.so") - ModeManager::AddChannelMode(new InspIRCdExtban::ServerMatcher("SERVERBAN", "BAN", 's')); - else if (module == "m_muteban.so") - ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("QUIET", "BAN", 'm')); - } + User *u = User::Find(params[0]); + NickServ::Account *nc = NickServ::FindAccount(params[2]); + if (u && nc) + u->Login(nc); } - else if (params[0].equals_cs("CAPABILITIES") && params.size() > 1) + + /* + * possible incoming ssl_cert messages: + * Received: :409 METADATA 409AAAAAA ssl_cert :vTrSe c38070ce96e41cc144ed6590a68d45a6 <...> <...> + * Received: :409 METADATA 409AAAAAC ssl_cert :vTrSE Could not get peer certificate: error:00000000:lib(0):func(0):reason(0) + */ + else if (params[1].equals_cs("ssl_cert")) { - spacesepstream ssep(params[1]); - Anope::string capab; - while (ssep.GetToken(capab)) + User *u = User::Find(params[0]); + if (!u) + return; + u->Extend<bool>("ssl", true); + Anope::string data = params[2].c_str(); + size_t pos1 = data.find(' ') + 1; + size_t pos2 = data.find(' ', pos1); + if ((pos2 - pos1) >= 32) // inspircd supports md5 and sha1 fingerprint hashes -> size 32 or 40 bytes. { - if (capab.find("CHANMODES") != Anope::string::npos) - { - Anope::string modes(capab.begin() + 10, capab.end()); - commasepstream sep(modes); - Anope::string modebuf; - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - if (ModeManager::FindChannelModeByChar(modebuf[t])) - continue; - ModeManager::AddChannelMode(new ChannelModeList(chmodes[modebuf[t]], modebuf[t])); - } - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - if (ModeManager::FindChannelModeByChar(modebuf[t])) - continue; - ModeManager::AddChannelMode(new ChannelModeParam(chmodes[modebuf[t]], modebuf[t])); - } - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - if (ModeManager::FindChannelModeByChar(modebuf[t])) - continue; - ModeManager::AddChannelMode(new ChannelModeParam(chmodes[modebuf[t]], modebuf[t], true)); - } - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - if (ModeManager::FindChannelModeByChar(modebuf[t])) - continue; - ModeManager::AddChannelMode(new ChannelMode(chmodes[modebuf[t]], modebuf[t])); - } - } - else if (capab.find("USERMODES") != Anope::string::npos) - { - Anope::string modes(capab.begin() + 10, capab.end()); - commasepstream sep(modes); - Anope::string modebuf; - - sep.GetToken(modebuf); - sep.GetToken(modebuf); - - if (sep.GetToken(modebuf)) - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - ModeManager::AddUserMode(new UserModeParam(umodes[modebuf[t]], modebuf[t])); - - if (sep.GetToken(modebuf)) - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - ModeManager::AddUserMode(new UserMode(umodes[modebuf[t]], modebuf[t])); - } - else if (capab.find("MAXMODES=") != Anope::string::npos) - { - Anope::string maxmodes(capab.begin() + 9, capab.end()); - IRCD->MaxModes = maxmodes.is_pos_number_only() ? convertTo<unsigned>(maxmodes) : 3; - } - else if (capab.find("PREFIX=") != Anope::string::npos) - { - Anope::string modes(capab.begin() + 8, capab.begin() + capab.find(')')); - Anope::string chars(capab.begin() + capab.find(')') + 1, capab.end()); - short level = modes.length() - 1; - - for (size_t t = 0, end = modes.length(); t < end; ++t) - { - ChannelMode *cm = ModeManager::FindChannelModeByChar(modes[t]); - if (cm == NULL || cm->type != MODE_STATUS) - { - Log() << "CAPAB PREFIX gave unknown channel status mode " << modes[t]; - continue; - } - - ChannelModeStatus *cms = anope_dynamic_static_cast<ChannelModeStatus *>(cm); - cms->level = level--; - - Log(LOG_DEBUG) << cms->name << " is now level " << cms->level; - } - - ModeManager::RebuildStatusModes(); - } - else if (capab == "GLOBOPS=1") - Servers::Capab.insert("GLOBOPS"); + u->fingerprint = data.substr(pos1, pos2 - pos1); } + EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u); } - else if (params[0].equals_cs("END")) + } + // We deliberately ignore non-bursting servers to avoid pseudoserver fights + else if ((params[0][0] == '#') && (!source.GetServer()->IsSynced())) + { + Channel *c = Channel::Find(params[0]); + if (c && c->ci) { - if (!Servers::Capab.count("SERVICES")) + if ((do_mlock) && (params[1] == "mlock")) { - UplinkSocket::Message() << "ERROR :m_services_account.so is not loaded. This is required by Anope"; - Anope::QuitReason = "ERROR: Remote server does not have the m_services_account module loaded, and this is required."; - Anope::Quitting = true; - return; + ModeLocks *modelocks = c->ci->GetExt<ModeLocks>("modelocks"); + Anope::string modes; + if (modelocks) + modes = modelocks->GetMLockAsString(c->ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); + + // Mode lock string is not what we say it is? + if (modes != params[2]) + Uplink::Send(Me, "METADATA", c->name, "mlock", modes); } - if (!ModeManager::FindUserModeByName("PRIV")) + else if ((do_topiclock) && (params[1] == "topiclock")) { - UplinkSocket::Message() << "ERROR :m_hidechans.so is not loaded. This is required by Anope"; - Anope::QuitReason = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required."; - Anope::Quitting = true; - return; + bool mystate = c->ci->IsTopicLock(); + bool serverstate = (params[2] == "1"); + if (mystate != serverstate) + Uplink::Send(Me, "METADATA", c->name, "topiclock", mystate ? "1" : ""); } - if (!IRCD->CanSVSHold) - Log() << "SVSHOLD missing, Usage disabled until module is loaded."; - if (!Servers::Capab.count("CHGHOST")) - Log() << "CHGHOST missing, Usage disabled until module is loaded."; - if (!Servers::Capab.count("CHGIDENT")) - Log() << "CHGIDENT missing, Usage disabled until module is loaded."; - - chmodes.clear(); - umodes.clear(); } - - Message::Capab::Run(source, params); } -}; - -struct IRCDMessageEncap : IRCDMessage -{ - ServiceReference<IRCDMessage> insp12_encap; - - IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4), insp12_encap("IRCDMessage", "inspircd12/encap") { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + else if (params[0] == "*") { - if (!Anope::Match(Me->GetSID(), params[0]) && !Anope::Match(Me->GetName(), params[0])) - return; + // Wed Oct 3 15:40:27 2012: S[14] O :20D METADATA * modules :-m_svstopic.so - if (params[1] == "CHGIDENT") + if (params[1].equals_cs("modules") && !params[2].empty()) { - User *u = User::Find(params[2]); - if (!u || u->server != Me) + // only interested when it comes from our uplink + Server* server = source.GetServer(); + if (!server || server->GetUplink() != Me) return; - u->SetIdent(params[3]); - UplinkSocket::Message(u) << "FIDENT " << params[3]; - } - else if (params[1] == "CHGHOST") - { - User *u = User::Find(params[2]); - if (!u || u->server != Me) + bool plus = (params[2][0] == '+'); + if (!plus && params[2][0] != '-') return; - u->SetDisplayedHost(params[3]); - UplinkSocket::Message(u) << "FHOST " << params[3]; - } - else if (params[1] == "CHGNAME") - { - User *u = User::Find(params[2]); - if (!u || u->server != Me) + bool required = false; + Anope::string capab, module = params[2].substr(1); + + if (module.equals_cs("m_services_account.so")) + required = true; + else if (module.equals_cs("m_hidechans.so")) + required = true; + else if (module.equals_cs("m_chghost.so")) + capab = "CHGHOST"; + else if (module.equals_cs("m_chgident.so")) + capab = "CHGIDENT"; + else if (module.equals_cs("m_svshold.so")) + capab = "SVSHOLD"; + else if (module.equals_cs("m_rline.so")) + capab = "RLINE"; + else if (module.equals_cs("m_topiclock.so")) + capab = "TOPICLOCK"; + else return; - u->SetRealname(params[3]); - UplinkSocket::Message(u) << "FNAME " << params[3]; - } + if (required) + { + if (!plus) + this->GetOwner()->logger.Log("Warning: InspIRCd unloaded module {0}, Anope won't function correctly without it"); + } + else + { + if (plus) + Servers::Capab.insert(capab); + else + Servers::Capab.erase(capab); + + this->GetOwner()->logger.Log("InspIRCd {0} module {1}, adjusted functionality", plus ? "loaded" : "unloaded", module); + } - if (insp12_encap) - insp12_encap->Run(source, params); + } } -}; +} -struct IRCDMessageFHost : IRCDMessage +void inspircd20::Mode::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageFHost(Module *creator) : IRCDMessage(creator, "FHOST", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + if (IRCD->IsChannelValid(params[0])) + { + Channel *c = Channel::Find(params[0]); + + Anope::string modes = params[1]; + for (unsigned int n = 2; n < params.size(); ++n) + modes += " " + params[n]; - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + if (c) + c->SetModesInternal(source, modes); + } + else { - User *u = source.GetUser(); - if (u->HasMode("CLOAK")) - u->RemoveModeInternal(source, ModeManager::FindUserModeByName("CLOAK")); - u->SetDisplayedHost(params[0]); + /* InspIRCd lets opers change another + users modes, we have to kludge this + as it slightly breaks RFC1459 + */ + User *u = User::Find(params[0]); + if (u != nullptr) + u->SetModesInternal(source, "%s", params[1].c_str()); } -}; +} -struct IRCDMessageFIdent : IRCDMessage +void inspircd20::Nick::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageFIdent(Module *creator) : IRCDMessage(creator, "FIDENT", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + source.GetUser()->ChangeNick(params[0]); +} - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - source.GetUser()->SetIdent(params[0]); - } -}; +void inspircd20::OperType::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + /* opertype is equivalent to mode +o because servers + dont do this directly */ + User *u = source.GetUser(); + if (!u->HasMode("OPER")) + u->SetModesInternal(source, "+o"); +} -struct IRCDMessageSave : IRCDMessage +void inspircd20::RSQuit::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - time_t last_collide; + Server *s = Server::Find(params[0]); + const Anope::string &reason = params.size() > 1 ? params[1] : ""; + if (!s) + return; + + Uplink::Send(Me, "SQUIT", s->GetSID(), reason); + s->Delete(s->GetName() + " " + s->GetUplink()->GetName()); +} - IRCDMessageSave(Module *creator) : IRCDMessage(creator, "SAVE", 2), last_collide(0) { } +void inspircd20::Save::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + User *targ = User::Find(params[0]); + time_t ts; - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + try + { + ts = convertTo<time_t>(params[1]); + } + catch (const ConvertException &) { - User *targ = User::Find(params[0]); - time_t ts; + return; + } - try - { - ts = convertTo<time_t>(params[1]); - } - catch (const ConvertException &) + if (!targ || targ->timestamp != ts) + return; + + BotInfo *bi; + if (targ->server == Me && (bi = dynamic_cast<BotInfo *>(targ))) + { + if (last_collide == Anope::CurTime) { + Anope::QuitReason = "Nick collision fight on " + targ->nick; + Anope::Quitting = true; return; } - if (!targ || targ->timestamp != ts) - return; + IRCD->Send<messages::Kill>(Me, targ->nick, "Nick collision"); + IRCD->Send<messages::NickChange>(targ, targ->nick, Anope::CurTime); + targ->timestamp = Anope::CurTime; + last_collide = Anope::CurTime; + } + else + targ->ChangeNick(targ->GetUID()); +} - BotInfo *bi; - if (targ->server == Me && (bi = dynamic_cast<BotInfo *>(targ))) - { - if (last_collide == Anope::CurTime) - { - Anope::QuitReason = "Nick collision fight on " + targ->nick; - Anope::Quitting = true; - return; - } +/* + * [Nov 04 00:08:46.308435 2009] debug: Received: SERVER irc.inspircd.com pass 0 964 :Testnet Central! + * 0: name + * 1: pass + * 2: hops + * 3: numeric + * 4: desc + */ +void inspircd20::ServerMessage::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + unsigned int hops = 0; - IRCD->SendKill(Me, targ->nick, "Nick collision"); - IRCD->SendNickChange(targ, targ->nick); - last_collide = Anope::CurTime; - } - else - targ->ChangeNick(targ->GetUID()); + try + { + hops = convertTo<unsigned int>(params[2]); } -}; + catch (const ConvertException &) { } + + new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, params[4], params[3]); +} -class IRCDMessageMetadata : IRCDMessage +void inspircd20::SQuit::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - ServiceReference<IRCDMessage> insp12_metadata; - const bool &do_topiclock; - const bool &do_mlock; + if (params[0] == rsquit_id || params[0] == rsquit_server) + { + /* squit for a recently squit server, introduce the juped server now */ + Server *s = Server::Find(rsquit_server); - public: - IRCDMessageMetadata(Module *creator, const bool &handle_topiclock, const bool &handle_mlock) : IRCDMessage(creator, "METADATA", 3), insp12_metadata("IRCDMessage", "inspircd12/metadata"), do_topiclock(handle_topiclock), do_mlock(handle_mlock) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + rsquit_id.clear(); + rsquit_server.clear(); - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - // We deliberately ignore non-bursting servers to avoid pseudoserver fights - if ((params[0][0] == '#') && (!source.GetServer()->IsSynced())) + if (s && s->IsJuped()) + IRCD->Send<messages::MessageServer>(s); + } + else + rfc1459::SQuit::Run(source, params); +} + +void inspircd20::Time::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + Uplink::Send(Me, "TIME", source.GetSource(), params[1], Anope::CurTime); +} + +/* + * [Nov 03 22:09:58.176252 2009] debug: Received: :964 UID 964AAAAAC 1225746297 w00t2 localhost testnet.user w00t 127.0.0.1 1225746302 +iosw +ACGJKLNOQcdfgjklnoqtx :Robin Burchell <w00t@inspircd.org> + * 0: uid + * 1: ts + * 2: nick + * 3: host + * 4: dhost + * 5: ident + * 6: ip + * 7: signon + * 8+: modes and params -- IMPORTANT, some modes (e.g. +s) may have parameters. So don't assume a fixed position of realname! + * last: realname + */ +void inspircd20::UID::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + time_t ts = convertTo<time_t>(params[1]); + + Anope::string modes = params[8]; + for (unsigned i = 9; i < params.size() - 1; ++i) + modes += " " + params[i]; + + NickServ::Nick *na = NULL; + if (sasl) + for (std::list<SASLUser>::iterator it = saslusers.begin(); it != saslusers.end();) { - Channel *c = Channel::Find(params[0]); - if (c && c->ci) + SASLUser &u = *it; + + if (u.created + 30 < Anope::CurTime) + it = saslusers.erase(it); + else if (u.uid == params[0]) { - if ((do_mlock) && (params[1] == "mlock")) - { - ModeLocks *modelocks = c->ci->GetExt<ModeLocks>("modelocks"); - Anope::string modes; - if (modelocks) - modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", ""); - - // Mode lock string is not what we say it is? - if (modes != params[2]) - UplinkSocket::Message(Me) << "METADATA " << c->name << " mlock :" << modes; - } - else if ((do_topiclock) && (params[1] == "topiclock")) - { - bool mystate = c->ci->GetExt<bool>("TOPICLOCK"); - bool serverstate = (params[2] == "1"); - if (mystate != serverstate) - UplinkSocket::Message(Me) << "METADATA " << c->name << " topiclock :" << (mystate ? "1" : ""); - } + na = NickServ::FindNick(u.acc); + it = saslusers.erase(it); } + else + ++it; } - if (insp12_metadata) - insp12_metadata->Run(source, params); + User *u = User::OnIntroduce(params[2], params[5], params[3], params[4], params[6], source.GetServer(), params[params.size() - 1], ts, modes, params[0], na ? na->GetAccount() : NULL); + if (u) + { + time_t signon = Anope::CurTime; + + try + { + signon = convertTo<time_t>(params[7]); + } + catch (const ConvertException &) { } + + u->signon = signon; } -}; +} class ProtoInspIRCd20 : public Module + , public EventHook<Event::UserNickChange> + , public EventHook<Event::ChannelSync> + , public EventHook<Event::ChanRegistered> + , public EventHook<Event::DelChan> + , public EventHook<Event::MLockEvents> + , public EventHook<Event::SetChannelOption> { - Module *m_insp12; - - InspIRCd20Proto ircd_proto; + inspircd20::Proto ircd_proto; + ExtensibleItem<bool> ssl; + ServiceReference<ModeLocks> mlocks; /* Core message handlers */ - Message::Away message_away; - Message::Error message_error; - Message::Invite message_invite; - Message::Join message_join; - Message::Kick message_kick; - Message::Kill message_kill; - Message::MOTD message_motd; - Message::Notice message_notice; - Message::Part message_part; - Message::Ping message_ping; - Message::Privmsg message_privmsg; - Message::Quit message_quit; - Message::Stats message_stats; - Message::Topic message_topic; - - /* InspIRCd 1.2 message handlers */ - ServiceAlias message_endburst, message_fjoin, message_fmode, - message_ftopic, message_idle, message_mode, - message_nick, message_opertype, message_rsquit, message_server, - message_squit, message_time, message_uid; + rfc1459::Away message_away; + rfc1459::Error message_error; + rfc1459::Invite message_invite; + rfc1459::Join message_join; + rfc1459::Kick message_kick; + rfc1459::Kill message_kill; + rfc1459::MOTD message_motd; + rfc1459::Notice message_notice; + rfc1459::Part message_part; + rfc1459::Ping message_ping; + rfc1459::Privmsg message_privmsg; + rfc1459::Quit message_quit; + rfc1459::Stats message_stats; + rfc1459::Topic message_topic; /* Our message handlers */ - IRCDMessageCapab message_capab; - IRCDMessageEncap message_encap; - IRCDMessageFHost message_fhost; - IRCDMessageFIdent message_fident; - IRCDMessageMetadata message_metadata; - IRCDMessageSave message_save; + inspircd20::Capab message_capab; + inspircd20::ChgHost message_chghost; + inspircd20::ChgIdent message_chgident; + inspircd20::ChgName message_chgname; + inspircd20::Encap message_encap; + inspircd20::Endburst message_endburst; + inspircd20::FHost message_fhost; + inspircd20::FIdent message_fident; + inspircd20::FJoin message_fjoin; + inspircd20::FMode message_fmode; + inspircd20::FTopic message_ftopic; + inspircd20::Idle message_idle; + inspircd20::Metadata message_metadata; + inspircd20::Mode message_mode; + inspircd20::Nick message_nick; + inspircd20::OperType message_opertype; + inspircd20::RSQuit message_rsquit; + inspircd20::Save message_save; + inspircd20::ServerMessage message_server; + inspircd20::SQuit message_squit; + inspircd20::Time message_time; + inspircd20::UID message_uid; + + rfc1459::senders::GlobalNotice sender_global_notice; + rfc1459::senders::GlobalPrivmsg sender_global_privmsg; + rfc1459::senders::Invite sender_invite; + rfc1459::senders::Kick sender_kick; + rfc1459::senders::Kill sender_svskill; + rfc1459::senders::ModeChannel sender_mode_chan; + rfc1459::senders::ModeUser sender_mode_user; + rfc1459::senders::NickChange sender_nickchange; + rfc1459::senders::Notice sender_notice; + rfc1459::senders::Part sender_part; + rfc1459::senders::Ping sender_ping; + rfc1459::senders::Pong sender_pong; + rfc1459::senders::Privmsg sender_privmsg; + rfc1459::senders::Quit sender_quit; + + inspircd20::senders::Akill sender_akill; + inspircd20::senders::AkillDel sender_akill_del; + inspircd20::senders::MessageChannel sender_channel; + inspircd20::senders::Login sender_login; + inspircd20::senders::Logout sender_logout; + inspircd20::senders::NickIntroduction sender_nickintroduction; + inspircd20::senders::MessageServer sender_server; + inspircd20::senders::SASL sender_sasl; + inspircd20::senders::SASLMechanisms sender_sasl_mechs; + inspircd20::senders::SQLine sender_sqline; + inspircd20::senders::SQLineDel sender_sqline_del; + inspircd20::senders::SQuit sender_squit; + inspircd20::senders::SZLine sender_szline; + inspircd20::senders::SZLineDel sender_szline_del; + inspircd20::senders::SVSHold sender_svshold; + inspircd20::senders::SVSHoldDel sender_svsholddel; + inspircd20::senders::SVSJoin sender_svsjoin; + inspircd20::senders::SVSLogin sender_svslogin; + inspircd20::senders::SVSNick sender_svsnick; + inspircd20::senders::SVSPart sender_svspart; + inspircd20::senders::SWhois sender_swhois; + inspircd20::senders::Topic sender_topic; + inspircd20::senders::VhostDel sender_vhost_del; + inspircd20::senders::VhostSet sender_vhost_set; + inspircd20::senders::Wallops sender_wallops; bool use_server_side_topiclock, use_server_side_mlock; void SendChannelMetadata(Channel *c, const Anope::string &metadataname, const Anope::string &value) { - UplinkSocket::Message(Me) << "METADATA " << c->name << " " << metadataname << " :" << value; + Uplink::Send(Me, "METADATA", c->name, metadataname, value); } public: - ProtoInspIRCd20(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR), - ircd_proto(this), - message_away(this), message_error(this), message_invite(this), message_join(this), message_kick(this), - message_kill(this), message_motd(this), message_notice(this), message_part(this), message_ping(this), - message_privmsg(this), message_quit(this), message_stats(this), message_topic(this), - - message_endburst("IRCDMessage", "inspircd20/endburst", "inspircd12/endburst"), - message_fjoin("IRCDMessage", "inspircd20/fjoin", "inspircd12/fjoin"), - message_fmode("IRCDMessage", "inspircd20/fmode", "inspircd12/fmode"), - message_ftopic("IRCDMessage", "inspircd20/ftopic", "inspircd12/ftopic"), - message_idle("IRCDMessage", "inspircd20/idle", "inspircd12/idle"), - message_mode("IRCDMessage", "inspircd20/mode", "inspircd12/mode"), - message_nick("IRCDMessage", "inspircd20/nick", "inspircd12/nick"), - message_opertype("IRCDMessage", "inspircd20/opertype", "inspircd12/opertype"), - message_rsquit("IRCDMessage", "inspircd20/rsquit", "inspircd12/rsquit"), - message_server("IRCDMessage", "inspircd20/server", "inspircd12/server"), - message_squit("IRCDMessage", "inspircd20/squit", "inspircd12/squit"), - message_time("IRCDMessage", "inspircd20/time", "inspircd12/time"), - message_uid("IRCDMessage", "inspircd20/uid", "inspircd12/uid"), - - message_capab(this), message_encap(this), message_fhost(this), message_fident(this), message_metadata(this, use_server_side_topiclock, use_server_side_mlock), - message_save(this) + ProtoInspIRCd20(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , EventHook<Event::UserNickChange>(this) + , EventHook<Event::ChannelSync>(this) + , EventHook<Event::ChanRegistered>(this) + , EventHook<Event::DelChan>(this) + , EventHook<Event::MLockEvents>(this) + , EventHook<Event::SetChannelOption>(this) + + , ircd_proto(this) + , ssl(this, "ssl") + + , message_away(this) + , message_error(this) + , message_invite(this) + , message_join(this) + , message_kick(this) + , message_kill(this) + , message_motd(this) + , message_notice(this) + , message_part(this) + , message_ping(this) + , message_privmsg(this) + , message_quit(this) + , message_stats(this) + , message_topic(this) + + , message_capab(this) + , message_chghost(this) + , message_chgident(this) + , message_chgname(this) + , message_encap(this) + , message_endburst(this) + , message_fhost(this) + , message_fident(this) + , message_fjoin(this) + , message_fmode(this) + , message_ftopic(this) + , message_idle(this) + , message_metadata(this, use_server_side_topiclock, use_server_side_mlock) + , message_mode(this) + , message_nick(this) + , message_opertype(this) + , message_rsquit(this) + , message_save(this) + , message_server(this) + , message_squit(this) + , message_time(this) + , message_uid(this) + + , sender_akill(this, &ircd_proto) + , sender_akill_del(this, &ircd_proto) + , sender_channel(this) + , sender_global_notice(this) + , sender_global_privmsg(this) + , sender_invite(this) + , sender_kick(this) + , sender_svskill(this) + , sender_login(this) + , sender_logout(this) + , sender_mode_chan(this) + , sender_mode_user(this) + , sender_nickchange(this) + , sender_nickintroduction(this) + , sender_notice(this) + , sender_part(this) + , sender_ping(this) + , sender_pong(this) + , sender_privmsg(this) + , sender_quit(this) + , sender_server(this) + , sender_sasl(this) + , sender_sasl_mechs(this) + , sender_sqline(this, &ircd_proto) + , sender_sqline_del(this, &ircd_proto) + , sender_squit(this) + , sender_szline(this, &ircd_proto) + , sender_szline_del(this, &ircd_proto) + , sender_svshold(this) + , sender_svsholddel(this) + , sender_svsjoin(this) + , sender_svslogin(this) + , sender_svsnick(this) + , sender_svspart(this) + , sender_swhois(this) + , sender_topic(this) + , sender_vhost_del(this, &ircd_proto) + , sender_vhost_set(this, &ircd_proto) + , sender_wallops(this) { - - if (ModuleManager::LoadModule("inspircd12", User::Find(creator)) != MOD_ERR_OK) - throw ModuleException("Unable to load inspircd12"); - m_insp12 = ModuleManager::FindModule("inspircd12"); - if (!m_insp12) - throw ModuleException("Unable to find inspircd12"); - if (!insp12) - throw ModuleException("No protocol interface for insp12"); - ModuleManager::DetachAll(m_insp12); - + IRCD = &ircd_proto; } ~ProtoInspIRCd20() { - m_insp12 = ModuleManager::FindModule("inspircd12"); - ModuleManager::UnloadModule(m_insp12, NULL); + IRCD = nullptr; } - void OnReload(Configuration::Conf *conf) anope_override + void OnReload(Configuration::Conf *conf) override { use_server_side_topiclock = conf->GetModule(this)->Get<bool>("use_server_side_topiclock"); use_server_side_mlock = conf->GetModule(this)->Get<bool>("use_server_side_mlock"); + + for (int i = 0; i < conf->CountBlock("extban"); ++i) + { + Configuration::Block *extban = conf->GetBlock("extban", i); + Anope::string name = extban->Get<Anope::string>("name"), + type = extban->Get<Anope::string>("type"), + base = extban->Get<Anope::string>("base"), + character = extban->Get<Anope::string>("character"); + + ChannelMode *cm; + + if (character.empty()) + continue; + + if (type == "channel") + cm = new InspIRCdExtban::ChannelMatcher(name, base, character[0]); + else if (type == "entry") + cm = new InspIRCdExtban::EntryMatcher(name, base, character[0]); + else if (type == "realname") + cm = new InspIRCdExtban::RealnameMatcher(name, base, character[0]); + else if (type == "account") + cm = new InspIRCdExtban::AccountMatcher(name, base, character[0]); + else if (type == "fingerprint") + cm = new InspIRCdExtban::FingerprintMatcher(name, base, character[0]); + else if (type == "unidentified") + cm = new InspIRCdExtban::UnidentifiedMatcher(name, base, character[0]); + else if (type == "server") + cm = new InspIRCdExtban::ServerMatcher(name, base, character[0]); + else + continue; + + if (!ModeManager::AddChannelMode(cm)) + delete cm; + } } - void OnUserNickChange(User *u, const Anope::string &) anope_override + void OnUserNickChange(User *u, const Anope::string &) override { u->RemoveModeInternal(Me, ModeManager::FindUserModeByName("REGISTERED")); } - void OnChannelSync(Channel *c) anope_override + void OnChannelSync(Channel *c) override { if (c->ci) this->OnChanRegistered(c->ci); } - void OnChanRegistered(ChannelInfo *ci) anope_override + void OnChanRegistered(ChanServ::Channel *ci) override { - ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); - if (use_server_side_mlock && ci->c && modelocks && !modelocks->GetMLockAsString(false).empty()) + if (use_server_side_mlock && ci->c && mlocks && !mlocks->GetMLockAsString(ci, false).empty()) { - Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", ""); + Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); SendChannelMetadata(ci->c, "mlock", modes); } if (use_server_side_topiclock && Servers::Capab.count("TOPICLOCK") && ci->c) { - if (ci->HasExt("TOPICLOCK")) + if (ci->IsTopicLock()) SendChannelMetadata(ci->c, "topiclock", "1"); } } - void OnDelChan(ChannelInfo *ci) anope_override + void OnDelChan(ChanServ::Channel *ci) override { if (use_server_side_mlock && ci->c) SendChannelMetadata(ci->c, "mlock", ""); @@ -1045,35 +1521,33 @@ class ProtoInspIRCd20 : public Module SendChannelMetadata(ci->c, "topiclock", ""); } - EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) anope_override + EventReturn OnMLock(ChanServ::Channel *ci, ModeLock *lock) override { - ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); - ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); - if (use_server_side_mlock && cm && ci->c && modelocks && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM)) + ChannelMode *cm = ModeManager::FindChannelModeByName(lock->GetName()); + if (use_server_side_mlock && cm && ci->c && mlocks && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM)) { - Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar; + Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar; SendChannelMetadata(ci->c, "mlock", modes); } return EVENT_CONTINUE; } - EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) anope_override + EventReturn OnUnMLock(ChanServ::Channel *ci, ModeLock *lock) override { - ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); - ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); - if (use_server_side_mlock && cm && ci->c && modelocks && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM)) + ChannelMode *cm = ModeManager::FindChannelModeByName(lock->GetName()); + if (use_server_side_mlock && cm && ci->c && mlocks && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM)) { - Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, ""); + Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, ""); SendChannelMetadata(ci->c, "mlock", modes); } return EVENT_CONTINUE; } - EventReturn OnSetChannelOption(CommandSource &source, Command *cmd, ChannelInfo *ci, const Anope::string &setting) anope_override + EventReturn OnSetChannelOption(CommandSource &source, Command *cmd, ChanServ::Channel *ci, const Anope::string &setting) override { - if (cmd->name == "chanserv/topic" && ci->c) + if (cmd->GetName() == "chanserv/topic" && ci->c) { if (setting == "topiclock on") SendChannelMetadata(ci->c, "topiclock", "1"); |