diff options
Diffstat (limited to 'modules/protocol/unreal.cpp')
-rw-r--r-- | modules/protocol/unreal.cpp | 1895 |
1 files changed, 965 insertions, 930 deletions
diff --git a/modules/protocol/unreal.cpp b/modules/protocol/unreal.cpp index d43f04fc4..053e41deb 100644 --- a/modules/protocol/unreal.cpp +++ b/modules/protocol/unreal.cpp @@ -1,420 +1,402 @@ -/* Unreal IRCD 3.2.x functions +/* + * Anope IRC Services * - * (C) 2003-2017 Anope Team - * Contact us at team@anope.org + * Copyright (C) 2003-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.bahamut */ + #include "module.h" -#include "modules/cs_mode.h" +#include "modules/chanserv/mode.h" #include "modules/sasl.h" +#include "modules/operserv/stats.h" +#include "modules/protocol/rfc1459.h" +#include "modules/protocol/unreal.h" +#include "modules/protocol/bahamut.h" -class UnrealIRCdProto : public IRCDProto -{ - public: - UnrealIRCdProto(Module *creator) : IRCDProto(creator, "UnrealIRCd 3.2.x") - { - DefaultPseudoclientModes = "+Soiq"; - CanSVSNick = true; - CanSVSJoin = true; - CanSetVHost = true; - CanSetVIdent = true; - CanSNLine = true; - CanSQLine = true; - CanSZLine = true; - CanSVSHold = true; - CanSVSO = true; - MaxModes = 12; - } - - private: - /* SVSNOOP */ - void SendSVSNOOP(const Server *server, bool set) anope_override - { - UplinkSocket::Message() << "SVSNOOP " << server->GetName() << " " << (set ? "+" : "-"); - } +static Anope::string UplinkSID; - void SendAkillDel(const XLine *x) anope_override +void unreal::senders::Akill::Send(User* u, XLine* x) +{ + if (x->IsRegex() || x->HasNickOrReal()) { - if (x->IsRegex() || x->HasNickOrReal()) - return; - - /* ZLine if we can instead */ - if (x->GetUser() == "*") + if (!u) { - cidr a(x->GetHost()); - if (a.valid()) - { - IRCD->SendSZLineDel(x); - return; - } + /* 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; } - UplinkSocket::Message() << "TKL - G " << x->GetUser() << " " << x->GetHost() << " " << x->by; - } + XLine *old = x; - void SendTopic(const MessageSource &source, Channel *c) anope_override - { - UplinkSocket::Message(source) << "TOPIC " << c->name << " " << c->topic_setter << " " << c->topic_ts << " :" << c->topic; - } + if (old->GetManager()->HasEntry("*@" + u->host)) + return; - void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override - { - UplinkSocket::Message(bi) << "NOTICE $" << dest->GetName() << " :" << msg; - } + /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */ + XLine *xl = Serialize::New<XLine *>(); + xl->SetMask("*@" + u->host); + xl->SetBy(old->GetBy()); + xl->SetExpires(old->GetExpires()); + xl->SetReason(old->GetReason()); + xl->SetID(old->GetID()); - void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override - { - UplinkSocket::Message(bi) << "PRIVMSG $" << dest->GetName() << " :" << msg; - } + old->GetManager()->AddXLine(xl); + x = xl; - void SendVhostDel(User *u) anope_override - { - BotInfo *HostServ = Config->GetClient("HostServ"); - u->RemoveMode(HostServ, "CLOAK"); - u->RemoveMode(HostServ, "VHOST"); - ModeManager::ProcessModes(); - u->SetMode(HostServ, "CLOAK"); + 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()); } - void SendAkill(User *u, XLine *x) anope_override + /* ZLine if we can instead */ + if (x->GetUser() == "*") { - if (x->IsRegex() || x->HasNickOrReal()) + cidr a(x->GetHost()); + if (a.valid()) { - 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->manager->Check(it->second, x)) - this->SendAkill(it->second, x); - return; - } - - const XLine *old = x; - - if (old->manager->HasEntry("*@" + u->host)) - return; + IRCD->Send<messages::SZLine>(u, x); + return; + } + } - /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */ - XLine *xline = new XLine("*@" + u->host, old->by, old->expires, old->reason, old->id); - old->manager->AddXLine(xline); - x = xline; + // 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; + Uplink::Send("TKL", "+", "G", x->GetUser(), x->GetHost(), x->GetBy(), Anope::CurTime + timeleft, x->GetCreated(), x->GetReason()); +} - Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->mask; - } +void unreal::senders::AkillDel::Send(XLine* x) +{ + if (x->IsRegex() || x->HasNickOrReal()) + return; - /* ZLine if we can instead */ - if (x->GetUser() == "*") + /* ZLine if we can instead */ + if (x->GetUser() == "*") + { + cidr a(x->GetHost()); + if (a.valid()) { - cidr a(x->GetHost()); - if (a.valid()) - { - IRCD->SendSZLine(u, x); - return; - } + IRCD->Send<messages::SZLineDel>(x); + return; } - - // Calculate the time left before this would expire, capping it at 2 days - time_t timeleft = x->expires - Anope::CurTime; - if (timeleft > 172800 || !x->expires) - timeleft = 172800; - UplinkSocket::Message() << "TKL + G " << x->GetUser() << " " << x->GetHost() << " " << x->by << " " << Anope::CurTime + timeleft << " " << x->created << " :" << x->GetReason(); } - void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override - { - UplinkSocket::Message(source) << "SVSKILL " << user->nick << " :" << buf; - user->KillInternal(source, buf); - } + Uplink::Send("TKL", "-", "G", x->GetUser(), x->GetHost(), x->GetBy()); +} - void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) anope_override - { - UplinkSocket::Message(source) << "SVS2MODE " << u->nick <<" " << buf; - } +void unreal::senders::MessageChannel::Send(Channel* c) +{ + /* Unreal does not support updating a channels TS without actually joining a user, + * so we will join and part us now + */ + ServiceBot *bi; + if (c->ci) + bi = c->ci->WhoSends(); + else + bi = Config->GetClient("ChanServ"); - void SendClientIntroduction(User *u) anope_override - { - Anope::string modes = "+" + u->GetModes(); - UplinkSocket::Message() << "NICK " << u->nick << " 1 " << u->timestamp << " " << u->GetIdent() << " " << u->host << " " << u->server->GetName() << " 0 " << modes << " " << u->host << " * :" << u->realname; - } + if (!bi) + return; - /* SERVER name hop descript */ - /* Unreal 3.2 actually sends some info about itself in the descript area */ - void SendServer(const Server *server) anope_override + if (c->FindUser(bi) == NULL) { - if (!server->GetSID().empty() && server == Me) - UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() << " :U0-*-" << server->GetSID() << " " << server->GetDescription(); - else - UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() << " :" << server->GetDescription(); + bi->Join(c); + bi->Part(c); } - - /* JOIN */ - void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override + else { - UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name << " :" << user->nick; - if (status) - { - /* 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(); - - BotInfo *setter = BotInfo::Find(user->GetUID()); - 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; - } + bi->Part(c); + bi->Join(c); } +} - /* unsqline - */ - void SendSQLineDel(const XLine *x) anope_override +void unreal::senders::Join::Send(User* user, Channel* c, const ChannelStatus* status) +{ + Uplink::Send(Me, "SJOIN", c->creation_time, c->name, user->GetUID()); + if (status) { - UplinkSocket::Message() << "UNSQLINE " << x->mask; - } + /* 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(); - /* SQLINE */ - /* - ** - Unreal will translate this to TKL for us - ** - */ - void SendSQLine(User *, const XLine *x) anope_override - { - UplinkSocket::Message() << "SQLINE " << x->mask << " :" << x->GetReason(); - } + ServiceBot *setter = ServiceBot::Find(user->GetUID()); + for (size_t i = 0; i < cs.Modes().length(); ++i) + c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); - /* - ** svso - ** parv[0] = sender prefix - ** parv[1] = nick - ** parv[2] = options - */ - void SendSVSO(BotInfo *source, const Anope::string &nick, const Anope::string &flag) anope_override - { - UplinkSocket::Message(source) << "SVSO " << nick << " " << flag; + if (uc != NULL) + uc->status = cs; } +} - /* Functions that use serval cmd functions */ +void unreal::senders::Kill::Send(const MessageSource &source, const Anope::string &target, const Anope::string &reason) +{ + Uplink::Send(source, "SVSKILL", target, reason); +} - void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) anope_override - { - if (!vIdent.empty()) - UplinkSocket::Message(Me) << "CHGIDENT " << u->nick << " " << vIdent; - if (!vhost.empty()) - UplinkSocket::Message(Me) << "CHGHOST " << u->nick << " " << vhost; - } +void unreal::senders::Kill::Send(const MessageSource &source, User *user, const Anope::string &reason) +{ + Uplink::Send(source, "SVSKILL", user->GetUID(), reason); + user->KillInternal(source, reason); +} - void SendConnect() anope_override - { - /* - NICKv2 = Nick Version 2 - VHP = Sends hidden host - UMODE2 = sends UMODE2 on user modes - NICKIP = Sends IP on NICK - TOKEN = Use tokens to talk - SJ3 = Supports SJOIN - NOQUIT = No Quit - TKLEXT = Extended TKL we don't use it but best to have it - SJB64 = Base64 encoded time stamps - ESVID = Allows storing account names as services stamp - MLOCK = Supports the MLOCK server command - VL = Version Info - NS = Config->Numeric Server - */ - Anope::string protoctl = "NICKv2 VHP UMODE2 NICKIP SJOIN SJOIN2 SJ3 NOQUIT TKLEXT ESVID MLOCK VL"; - if (!Me->GetSID().empty()) - protoctl += " VL"; - UplinkSocket::Message() << "PROTOCTL " << protoctl; - UplinkSocket::Message() << "PASS :" << Config->Uplinks[Anope::CurrentUplink].password; - SendServer(Me); - } +void unreal::senders::Login::Send(User *u, NickServ::Nick *na) +{ + /* 3.2.10.4+ treats users logged in with accounts as fully registered, even if -r, so we can not set this here. Just use the timestamp. */ + if (Servers::Capab.count("ESVID") > 0 && !na->GetAccount()->IsUnconfirmed()) + IRCD->SendMode(Config->GetClient("NickServ"), u, "+d {0}", na->GetAccount()->GetDisplay()); + else + IRCD->SendMode(Config->GetClient("NickServ"), u, "+d {0}", u->signon); +} - /* SVSHOLD - set */ - void SendSVSHold(const Anope::string &nick, time_t t) anope_override - { - UplinkSocket::Message() << "TKL + Q H " << nick << " " << Me->GetName() << " " << Anope::CurTime + t << " " << Anope::CurTime << " :Being held for registered user"; - } +void unreal::senders::Logout::Send(User *u) +{ + IRCD->SendMode(Config->GetClient("NickServ"), u, "+d 0"); +} - /* SVSHOLD - release */ - void SendSVSHoldDel(const Anope::string &nick) anope_override - { - UplinkSocket::Message() << "TKL - Q * " << nick << " " << Me->GetName(); - } +void unreal::senders::ModeUser::Send(const MessageSource &source, User *user, const Anope::string &modes) +{ + IRCMessage message(source, "SVS2MODE", user->GetUID()); + message.TokenizeAndPush(modes); + Uplink::SendMessage(message); +} - /* UNSGLINE */ - /* - * SVSNLINE - :realname mask - */ - void SendSGLineDel(const XLine *x) anope_override - { - UplinkSocket::Message() << "SVSNLINE - :" << x->mask; - } +void unreal::senders::NickIntroduction::Send(User *user) +{ + Anope::string modes = "+" + user->GetModes(); + Uplink::Send("UID", user->nick, 1, user->timestamp, user->GetIdent(), user->host, user->GetUID(), "*", modes, !user->vhost.empty() ? user->vhost : "*", !user->chost.empty() ? user->chost : "*", "*", user->realname); +} - /* UNSZLINE */ - void SendSZLineDel(const XLine *x) anope_override - { - UplinkSocket::Message() << "TKL - Z * " << x->GetHost() << " " << x->by; - } +void unreal::senders::SASL::Send(const ::SASL::Message& message) +{ + size_t p = message.target.find('!'); + if (p == Anope::string::npos) + return; + + if (!message.ext.empty()) + Uplink::Send(ServiceBot::Find(message.source), "SASL", message.target.substr(0, p), message.target, message.type, message.data, message.ext); + else + Uplink::Send(ServiceBot::Find(message.source), "SASL", message.target.substr(0, p), message.target, message.type, message.data); +} - /* SZLINE */ - void SendSZLine(User *, const XLine *x) anope_override - { - // Calculate the time left before this would expire, capping it at 2 days - time_t timeleft = x->expires - Anope::CurTime; - if (timeleft > 172800 || !x->expires) - timeleft = 172800; - UplinkSocket::Message() << "TKL + Z * " << x->GetHost() << " " << x->by << " " << Anope::CurTime + timeleft << " " << x->created << " :" << x->GetReason(); - } +void unreal::senders::MessageServer::Send(Server* server) +{ + Uplink::Send(Me, "SID", server->GetName(), server->GetHops() + 1, server->GetSID(), server->GetDescription()); +} - /* SGLINE */ +void unreal::senders::SGLine::Send(User*, XLine* x) +{ /* * SVSNLINE + reason_where_is_space :realname mask with spaces - */ - void SendSGLine(User *, const XLine *x) anope_override - { - Anope::string edited_reason = x->GetReason(); - edited_reason = edited_reason.replace_all_cs(" ", "_"); - UplinkSocket::Message() << "SVSNLINE + " << edited_reason << " :" << x->mask; - } + */ + Anope::string edited_reason = x->GetReason(); + edited_reason = edited_reason.replace_all_cs(" ", "_"); + Uplink::Send("SVSNLINE", "+", edited_reason, x->GetMask()); +} - /* svsjoin - parv[0] - sender - parv[1] - nick to make join - parv[2] - channel to join - parv[3] - (optional) channel key(s) - */ - /* In older Unreal SVSJOIN and SVSNLINE tokens were mixed so SVSJOIN and SVSNLINE are broken - when coming from a none TOKEN'd server - */ - void SendSVSJoin(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string ¶m) anope_override - { - if (!param.empty()) - UplinkSocket::Message(source) << "SVSJOIN " << user->GetUID() << " " << chan << " :" << param; - else - UplinkSocket::Message(source) << "SVSJOIN " << user->GetUID() << " " << chan; - } +void unreal::senders::SGLineDel::Send(XLine* x) +{ + Uplink::Send("SVSNLINE", "-", x->GetMask()); +} - void SendSVSPart(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string ¶m) anope_override - { - if (!param.empty()) - UplinkSocket::Message(source) << "SVSPART " << user->GetUID() << " " << chan << " :" << param; - else - UplinkSocket::Message(source) << "SVSPART " << user->GetUID() << " " << chan; - } +void unreal::senders::SQLine::Send(User*, XLine* x) +{ + Uplink::Send("SQLINE", x->GetMask(), x->GetReason()); +} - void SendSWhois(const MessageSource &source, const Anope::string &who, const Anope::string &mask) anope_override - { - UplinkSocket::Message(source) << "SWHOIS " << who << " :" << mask; - } +void unreal::senders::SQLineDel::Send(XLine* x) +{ + Uplink::Send("UNSQLINE", x->GetMask()); +} - void SendEOB() anope_override - { - UplinkSocket::Message(Me) << "EOS"; - } +void unreal::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; + Uplink::Send("TKL", "+", "Z", "*", x->GetHost(), x->GetBy(), Anope::CurTime + timeleft, x->GetCreated(), x->GetReason()); +} - bool IsNickValid(const Anope::string &nick) anope_override - { - if (nick.equals_ci("ircd") || nick.equals_ci("irc")) - return false; +void unreal::senders::SZLineDel::Send(XLine* x) +{ + Uplink::Send("TKL", "-", "Z", "*", x->GetHost(), x->GetBy()); +} - return IRCDProto::IsNickValid(nick); - } +void unreal::senders::SVSHold::Send(const Anope::string& nick, time_t t) +{ + Uplink::Send("TKL", "+", "Q", "H", nick, Me->GetName(), Anope::CurTime + t, Anope::CurTime, "Being held for registered user"); +} - bool IsChannelValid(const Anope::string &chan) anope_override - { - if (chan.find(':') != Anope::string::npos) - return false; +void unreal::senders::SVSHoldDel::Send(const Anope::string& nick) +{ + Uplink::Send("TKL", "-", "Q", "*", nick, Me->GetName()); +} - return IRCDProto::IsChannelValid(chan); - } +/* svsjoin + parv[0] - sender + parv[1] - nick to make join + parv[2] - channel to join + parv[3] - (optional) channel key(s) +*/ +void unreal::senders::SVSJoin::Send(const MessageSource& source, User* user, const Anope::string& chan, const Anope::string& key) +{ + if (!key.empty()) + Uplink::Send(source, "SVSJOIN", user->GetUID(), chan, key); + else + Uplink::Send(source, "SVSJOIN", user->GetUID(), chan); +} - bool IsExtbanValid(const Anope::string &mask) anope_override - { - return mask.length() >= 4 && mask[0] == '~' && mask[2] == ':'; - } +void unreal::senders::SVSLogin::Send(const Anope::string& uid, const Anope::string& acc, const Anope::string& vident, const Anope::string& vhost) +{ + size_t p = uid.find('!'); + if (p == Anope::string::npos) + return; + Uplink::Send(Me, "SVSLOGIN", uid.substr(0, p), uid, acc); +} - void SendLogin(User *u, NickAlias *na) anope_override - { - /* 3.2.10.4+ treats users logged in with accounts as fully registered, even if -r, so we can not set this here. Just use the timestamp. */ - if (Servers::Capab.count("ESVID") > 0 && !na->nc->HasExt("UNCONFIRMED")) - IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %s", na->nc->display.c_str()); - else - IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %d", u->signon); - } +void unreal::senders::SVSPart::Send(const MessageSource& source, User* user, const Anope::string& chan, const Anope::string& reason) +{ + if (!reason.empty()) + Uplink::Send(source, "SVSPART", user->GetUID(), chan, reason); + else + Uplink::Send(source, "SVSPART", user->GetUID(), chan); +} - void SendLogout(User *u) anope_override - { - IRCD->SendMode(Config->GetClient("NickServ"), u, "+d 0"); - } +void unreal::senders::SWhois::Send(const MessageSource& source, User *user, const Anope::string& swhois) +{ + Uplink::Send(source, "SWHOIS", user->GetUID(), swhois); +} - void SendChannel(Channel *c) anope_override - { - /* Unreal does not support updating a channels TS without actually joining a user, - * so we will join and part us now - */ - BotInfo *bi = c->ci->WhoSends(); - if (!bi) - ; - else if (c->FindUser(bi) == NULL) - { - bi->Join(c); - bi->Part(c); - } - else - { - bi->Part(c); - bi->Join(c); - } - } +void unreal::senders::Topic::Send(const MessageSource &source, Channel *channel, const Anope::string &topic, time_t topic_ts, const Anope::string &topic_setter) +{ + Uplink::Send(source, "TOPIC", channel->name, topic_setter, topic_ts, topic); +} - void SendSASLMessage(const SASL::Message &message) anope_override - { - size_t p = message.target.find('!'); - if (p == Anope::string::npos) - return; +void unreal::senders::VhostDel::Send(User* u) +{ + ServiceBot *HostServ = Config->GetClient("HostServ"); + u->RemoveMode(HostServ, "CLOAK"); + u->RemoveMode(HostServ, "VHOST"); + ModeManager::ProcessModes(); + u->SetMode(HostServ, "CLOAK"); +} - UplinkSocket::Message(BotInfo::Find(message.source)) << "SASL " << message.target.substr(0, p) << " " << message.target << " " << message.type << " " << message.data << (message.ext.empty() ? "" : " " + message.ext); - } +void unreal::senders::VhostSet::Send(User* u, const Anope::string& vident, const Anope::string& vhost) +{ + if (!vident.empty()) + Uplink::Send(Me, "CHGIDENT", u->GetUID(), vident); + if (!vhost.empty()) + Uplink::Send(Me, "CHGHOST", u->GetUID(), vhost); +} - void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) anope_override - { - size_t p = uid.find('!'); - if (p == Anope::string::npos) - return; - UplinkSocket::Message(Me) << "SVSLOGIN " << uid.substr(0, p) << " " << uid << " " << acc; - } +void unreal::senders::Wallops::Send(const MessageSource &source, const Anope::string &msg) +{ + Uplink::Send(Me, "SENDUMODE", "o", "from " + source.GetName() + ": " + msg); +} - bool IsIdentValid(const Anope::string &ident) anope_override - { - if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen")) - return false; +unreal::Proto::Proto(Module *creator) : IRCDProto(creator, "UnrealIRCd 4") +{ + DefaultPseudoclientModes = "+Soiq"; + CanSVSNick = true; + CanSVSJoin = true; + CanSetVHost = true; + CanSetVIdent = true; + CanSNLine = true; + CanSQLine = true; + CanSZLine = true; + CanSVSHold = true; + CanCertFP = true; + RequiresID = true; + MaxModes = 12; +} - for (unsigned i = 0; i < ident.length(); ++i) - { - const char &c = ident[i]; +void unreal::Proto::Handshake() +{ + /* + NICKv2 = Nick Version 2 + VHP = Sends hidden host + UMODE2 = sends UMODE2 on user modes + NICKIP = Sends IP on NICK + SJ3 = Supports SJOIN + NOQUIT = No Quit + TKLEXT = Extended TKL we don't use it but best to have it + MLOCK = Supports the MLOCK server command + VL = Version Info + SID = SID/UID mode + */ + Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password); + Uplink::Send("PROTOCTL", "NICKv2", "VHP", "UMODE2", "NICKIP", "SJOIN", "SJOIN2", "SJ3", "NOQUIT", "TKLEXT", "MLOCK", "SID"); + Uplink::Send("PROTOCTL", "EAUTH=" + Me->GetName() + ",,,Anope-" + Anope::VersionShort()); + Uplink::Send("PROTOCTL", "SID=" + Me->GetSID()); + Uplink::Send("SERVER", Me->GetName(), Me->GetHops() + 1, Me->GetDescription()); +} - if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-') - continue; +void unreal::Proto::SendEOB() +{ + Uplink::Send(Me, "EOS"); +} - if (c == '-' || c == '.' || c == '_') - continue; +bool unreal::Proto::IsNickValid(const Anope::string &nick) +{ + if (nick.equals_ci("ircd") || nick.equals_ci("irc")) + return false; - return false; - } + return IRCDProto::IsNickValid(nick); +} - return true; +bool unreal::Proto::IsChannelValid(const Anope::string &chan) +{ + if (chan.find(':') != Anope::string::npos) + return false; + + return IRCDProto::IsChannelValid(chan); +} + +bool unreal::Proto:: IsExtbanValid(const Anope::string &mask) +{ + return mask.length() >= 4 && mask[0] == '~' && mask[2] == ':'; +} + +bool unreal::Proto::IsIdentValid(const Anope::string &ident) +{ + if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen")) + return false; + + for (unsigned i = 0; i < ident.length(); ++i) + { + const char &c = ident[i]; + + if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-') + continue; + + if (c == '-' || c == '.' || c == '_') + continue; + + return false; } -}; + + return true; +} class UnrealExtBan : public ChannelModeVirtual<ChannelModeList> { @@ -426,13 +408,13 @@ class UnrealExtBan : 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() < 4 || param[0] != '~' || param[1] != ext || param[2] != ':') return cm; @@ -451,7 +433,7 @@ namespace UnrealExtban { } - 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 channel = mask.substr(3); @@ -486,7 +468,7 @@ namespace UnrealExtban { } - 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); @@ -502,7 +484,7 @@ namespace UnrealExtban { } - 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); @@ -518,7 +500,7 @@ namespace UnrealExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); return u->HasMode("REGISTERED") && mask.equals_ci(u->nick); @@ -532,14 +514,29 @@ namespace UnrealExtban { } - 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); - return u->Account() && Anope::Match(u->Account()->display, real_mask); + return u->Account() && Anope::Match(u->Account()->GetDisplay(), real_mask); } }; + + class FingerprintMatcher : public UnrealExtBan + { + public: + FingerprintMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c) + { + } + + bool Matches(User *u, const Entry *e) override + { + const Anope::string &mask = e->GetMask(); + Anope::string real_mask = mask.substr(3); + return !u->fingerprint.empty() && Anope::Match(u->fingerprint, real_mask); + } + }; } class ChannelModeFlood : public ChannelModeParam @@ -548,18 +545,18 @@ class ChannelModeFlood : public ChannelModeParam ChannelModeFlood(char modeChar, bool minusNoArg) : ChannelModeParam("FLOOD", modeChar, minusNoArg) { } /* Borrowed part of this check from UnrealIRCd */ - bool IsValid(Anope::string &value) const anope_override + bool IsValid(Anope::string &value) const override { if (value.empty()) return false; try { Anope::string rest; - if (value[0] != ':' && convertTo<unsigned>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<unsigned>(rest.substr(1), rest, false) > 0 && rest.empty()) + if (value[0] != ':' && convertTo<unsigned int>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<unsigned int>(rest.substr(1), rest, false) > 0 && rest.empty()) return true; } catch (const ConvertException &) { } - + /* '['<number><1 letter>[optional: '#'+1 letter],[next..]']'':'<number> */ size_t end_bracket = value.find(']', 1); if (end_bracket == Anope::string::npos) @@ -600,245 +597,85 @@ class ChannelModeUnrealSSL : public ChannelMode { } - bool CanSet(User *u) const anope_override + bool CanSet(User *u) const override { return false; } }; -struct IRCDMessageCapab : Message::Capab +void unreal::ChgHost::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageCapab(Module *creator) : Message::Capab(creator, "PROTOCTL") { } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - for (unsigned i = 0; i < params.size(); ++i) - { - Anope::string capab = params[i]; - - 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) - { - switch (modebuf[t]) - { - case 'b': - ModeManager::AddChannelMode(new ChannelModeList("BAN", 'b')); - - ModeManager::AddChannelMode(new UnrealExtban::ChannelMatcher("CHANNELBAN", "BAN", 'c')); - ModeManager::AddChannelMode(new UnrealExtban::EntryMatcher("JOINBAN", "BAN", 'j')); - ModeManager::AddChannelMode(new UnrealExtban::EntryMatcher("NONICKBAN", "BAN", 'n')); - ModeManager::AddChannelMode(new UnrealExtban::EntryMatcher("QUIET", "BAN", 'q')); - ModeManager::AddChannelMode(new UnrealExtban::RealnameMatcher("REALNAMEBAN", "BAN", 'r')); - ModeManager::AddChannelMode(new UnrealExtban::RegisteredMatcher("REGISTEREDBAN", "BAN", 'R')); - ModeManager::AddChannelMode(new UnrealExtban::AccountMatcher("ACCOUNTBAN", "BAN", 'a')); - continue; - case 'e': - ModeManager::AddChannelMode(new ChannelModeList("EXCEPT", 'e')); - continue; - case 'I': - ModeManager::AddChannelMode(new ChannelModeList("INVITEOVERRIDE", 'I')); - continue; - default: - ModeManager::AddChannelMode(new ChannelModeList("", modebuf[t])); - } - } - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - switch (modebuf[t]) - { - case 'k': - ModeManager::AddChannelMode(new ChannelModeKey('k')); - continue; - case 'f': - ModeManager::AddChannelMode(new ChannelModeFlood('f', false)); - continue; - case 'L': - ModeManager::AddChannelMode(new ChannelModeParam("REDIRECT", 'L')); - continue; - default: - ModeManager::AddChannelMode(new ChannelModeParam("", modebuf[t])); - } - } - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - switch (modebuf[t]) - { - case 'l': - ModeManager::AddChannelMode(new ChannelModeParam("LIMIT", 'l', true)); - continue; - case 'j': - ModeManager::AddChannelMode(new ChannelModeParam("JOINFLOOD", 'j', true)); - continue; - default: - ModeManager::AddChannelMode(new ChannelModeParam("", modebuf[t], true)); - } - } - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - switch (modebuf[t]) - { - case 'p': - ModeManager::AddChannelMode(new ChannelMode("PRIVATE", 'p')); - continue; - case 's': - ModeManager::AddChannelMode(new ChannelMode("SECRET", 's')); - continue; - case 'm': - ModeManager::AddChannelMode(new ChannelMode("MODERATED", 'm')); - continue; - case 'n': - ModeManager::AddChannelMode(new ChannelMode("NOEXTERNAL", 'n')); - continue; - case 't': - ModeManager::AddChannelMode(new ChannelMode("TOPIC", 't')); - continue; - case 'i': - ModeManager::AddChannelMode(new ChannelMode("INVITE", 'i')); - continue; - case 'r': - ModeManager::AddChannelMode(new ChannelModeNoone("REGISTERED", 'r')); - continue; - case 'R': - ModeManager::AddChannelMode(new ChannelMode("REGISTEREDONLY", 'R')); - continue; - case 'c': - ModeManager::AddChannelMode(new ChannelMode("BLOCKCOLOR", 'c')); - continue; - case 'O': - ModeManager::AddChannelMode(new ChannelModeOperOnly("OPERONLY", 'O')); - continue; - case 'A': - ModeManager::AddChannelMode(new ChannelModeOperOnly("ADMINONLY", 'A')); - continue; - case 'Q': - ModeManager::AddChannelMode(new ChannelMode("NOKICK", 'Q')); - continue; - case 'K': - ModeManager::AddChannelMode(new ChannelMode("NOKNOCK", 'K')); - continue; - case 'V': - ModeManager::AddChannelMode(new ChannelMode("NOINVITE", 'V')); - continue; - case 'C': - ModeManager::AddChannelMode(new ChannelMode("NOCTCP", 'C')); - continue; - case 'u': - ModeManager::AddChannelMode(new ChannelMode("AUDITORIUM", 'u')); - continue; - case 'z': - ModeManager::AddChannelMode(new ChannelMode("SSL", 'z')); - continue; - case 'N': - ModeManager::AddChannelMode(new ChannelMode("NONICK", 'N')); - continue; - case 'S': - ModeManager::AddChannelMode(new ChannelMode("STRIPCOLOR", 'S')); - continue; - case 'M': - ModeManager::AddChannelMode(new ChannelMode("REGMODERATED", 'M')); - continue; - case 'T': - ModeManager::AddChannelMode(new ChannelMode("NONOTICE", 'T')); - continue; - case 'G': - ModeManager::AddChannelMode(new ChannelMode("CENSOR", 'G')); - continue; - case 'Z': - ModeManager::AddChannelMode(new ChannelModeUnrealSSL("", 'Z')); - continue; - default: - ModeManager::AddChannelMode(new ChannelMode("", modebuf[t])); - } - } - } - } - - Message::Capab::Run(source, params); - } -}; + User *u = User::Find(params[0]); + if (u) + u->SetDisplayedHost(params[1]); +} -struct IRCDMessageChgHost : IRCDMessage +void unreal::ChgIdent::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageChgHost(Module *creator) : IRCDMessage(creator, "CHGHOST", 2) { } + User *u = User::Find(params[0]); + if (u) + u->SetVIdent(params[1]); +} - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - User *u = User::Find(params[0]); - if (u) - u->SetDisplayedHost(params[1]); - } -}; +void unreal::ChgName::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + User *u = User::Find(params[0]); + if (u) + u->SetRealname(params[1]); +} -struct IRCDMessageChgIdent : IRCDMessage +void unreal::MD::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageChgIdent(Module *creator) : IRCDMessage(creator, "CHGIDENT", 2) { } + const Anope::string &mdtype = params[0], + &obj = params[1], + &var = params[2], + &value = params.size() > 3 ? params[3] : ""; - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + if (mdtype == "client") { - User *u = User::Find(params[0]); - if (u) - u->SetVIdent(params[1]); - } -}; + User *u = User::Find(obj); -struct IRCDMessageChgName : IRCDMessage -{ - IRCDMessageChgName(Module *creator) : IRCDMessage(creator, "CHGNAME", 2) { } + if (u == nullptr) + return; - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - User *u = User::Find(params[0]); - if (u) - u->SetRealname(params[1]); + if (var == "certfp" && !value.empty()) + { + u->Extend<bool>("ssl", true); + u->fingerprint = value; + EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u); + } } -}; +} -struct IRCDMessageMode : IRCDMessage +void unreal::Mode::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageMode(Module *creator, const Anope::string &mname) : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + bool server_source = source.GetServer() != NULL; + Anope::string modes = params[1]; + for (unsigned i = 2; i < params.size() - (server_source ? 1 : 0); ++i) + modes += " " + params[i]; - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + if (IRCD->IsChannelValid(params[0])) { - bool server_source = source.GetServer() != NULL; - Anope::string modes = params[1]; - for (unsigned i = 2; i < params.size() - (server_source ? 1 : 0); ++i) - modes += " " + params[i]; - - if (IRCD->IsChannelValid(params[0])) - { - Channel *c = Channel::Find(params[0]); - time_t ts = 0; - - try - { - if (server_source) - ts = convertTo<time_t>(params[params.size() - 1]); - } - catch (const ConvertException &) { } + Channel *c = Channel::Find(params[0]); + time_t ts = 0; - if (c) - c->SetModesInternal(source, modes, ts); - } - else + try { - User *u = User::Find(params[0]); - if (u) - u->SetModesInternal(source, "%s", params[1].c_str()); + if (server_source) + ts = convertTo<time_t>(params[params.size() - 1]); } + catch (const ConvertException &) { } + + if (c) + c->SetModesInternal(source, modes, ts); } -}; + else + { + User *u = User::Find(params[0]); + if (u) + u->SetModesInternal(source, "%s", params[1].c_str()); + } +} /* netinfo * argv[0] = max global count @@ -850,487 +687,685 @@ struct IRCDMessageMode : IRCDMessage * argv[6] = free(**) * argv[7] = ircnet */ -struct IRCDMessageNetInfo : IRCDMessage +void unreal::NetInfo::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageNetInfo(Module *creator) : IRCDMessage(creator, "NETINFO", 8) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - UplinkSocket::Message() << "NETINFO " << MaxUserCount << " " << Anope::CurTime << " " << convertTo<int>(params[2]) << " " << params[3] << " 0 0 0 :" << params[7]; - } -}; + Stats *stats = Serialize::GetObject<Stats *>(); + Uplink::Send("NETINFO", stats ? stats->GetMaxUserCount() : 0, Anope::CurTime, params[2], params[3], "0", "0", "0", params[7]); +} -struct IRCDMessageNick : IRCDMessage +/* +** NICK - new +** source = NULL +** parv[0] = nickname +** parv[1] = hopcount +** parv[2] = timestamp +** parv[3] = username +** parv[4] = hostname +** parv[5] = servername +** parv[6] = servicestamp +** parv[7] = umodes +** parv[8] = virthost, * if none +** parv[9] = ip +** parv[10] = info +** +** NICK - change +** source = oldnick +** parv[0] = new nickname +** parv[1] = hopcount +*/ +void unreal::Nick::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - /* - ** NICK - new - ** source = NULL - ** parv[0] = nickname - ** parv[1] = hopcount - ** parv[2] = timestamp - ** parv[3] = username - ** parv[4] = hostname - ** parv[5] = servername - ** parv[6] = servicestamp - ** parv[7] = umodes - ** parv[8] = virthost, * if none - ** parv[9] = ip - ** parv[10] = info - ** - ** NICK - change - ** source = oldnick - ** parv[0] = new nickname - ** parv[1] = hopcount - */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + if (params.size() == 11) { - if (params.size() == 11) + Anope::string ip; + if (params[9] != "*") { - Anope::string ip; - if (params[9] != "*") - { - Anope::string decoded_ip; - Anope::B64Decode(params[9], decoded_ip); + Anope::string decoded_ip; + Anope::B64Decode(params[9], decoded_ip); - sockaddrs ip_addr; - ip_addr.ntop(params[9].length() == 8 ? AF_INET : AF_INET6, decoded_ip.c_str()); - ip = ip_addr.addr(); - } + sockaddrs ip_addr; + ip_addr.ntop(params[9].length() == 8 ? AF_INET : AF_INET6, decoded_ip.c_str()); + ip = ip_addr.addr(); + } - Anope::string vhost = params[8]; - if (vhost.equals_cs("*")) - vhost.clear(); + Anope::string vhost = params[8]; + if (vhost.equals_cs("*")) + vhost.clear(); - time_t user_ts = params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime; + time_t user_ts = Anope::CurTime; - Server *s = Server::Find(params[5]); - if (s == NULL) - { - Log(LOG_DEBUG) << "User " << params[0] << " introduced from non-existent server " << params[5] << "?"; - return; - } - - NickAlias *na = NULL; + try + { + user_ts = convertTo<time_t>(params[2]); + } + catch (const ConvertException &) { } + + Server *s = Server::Find(params[5]); + if (s == NULL) + { + Anope::Logger.Debug("User {0} introduced from non-existent server {1}", params[0], params[5]); + return; + } + + NickServ::Nick *na = NULL; - if (params[6] == "0") - ; - else if (params[6].is_pos_number_only()) + if (params[6] == "0") + ; + else if (params[6].is_pos_number_only()) + { + try { if (convertTo<time_t>(params[6]) == user_ts) - na = NickAlias::Find(params[0]); + na = NickServ::FindNick(params[0]); } - else - { - na = NickAlias::Find(params[6]); - } - - User::OnIntroduce(params[0], params[3], params[4], vhost, ip, s, params[10], user_ts, params[7], "", na ? *na->nc : NULL); + catch (const ConvertException &) { } } else { - User *u = source.GetUser(); - if (u) - u->ChangeNick(params[0]); + na = NickServ::FindNick(params[6]); } + + User::OnIntroduce(params[0], params[3], params[4], vhost, ip, s, params[10], user_ts, params[7], "", na ? na->GetAccount() : NULL); } -}; + else + { + User *u = source.GetUser(); -/** This is here because: - * - * If we had three servers, A, B & C linked like so: A<->B<->C - * If Anope is linked to A and B splits from A and then reconnects - * B introduces itself, introduces C, sends EOS for C, introduces Bs clients - * introduces Cs clients, sends EOS for B. This causes all of Cs clients to be introduced - * with their server "not syncing". We now send a PING immediately when receiving a new server - * and then finish sync once we get a pong back from that server. + if (u) + u->ChangeNick(params[0]); + } +} + +/* We ping servers to detect EOB instead of handling the EOS message + * because Unreal sends EOS for servers on link prior to the majority + * of the burst. */ -struct IRCDMessagePong : IRCDMessage +void unreal::Pong::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessagePong(Module *creator) : IRCDMessage(creator, "PONG", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + if (!source.GetServer()->IsSynced()) + source.GetServer()->Sync(false); +} - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override +void unreal::Protoctl::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + for (unsigned int i = 0; i < params.size(); ++i) { - if (!source.GetServer()->IsSynced()) - source.GetServer()->Sync(false); + Anope::string capab = params[i]; + + if (!capab.find("SID=")) + { + UplinkSID = capab.substr(4); + } } -}; -struct IRCDMessageSASL : IRCDMessage + rfc1459::Capab::Run(source, params); +} + +void unreal::SASL::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageSASL(Module *creator) : IRCDMessage(creator, "SASL", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + size_t p = params[1].find('!'); + if (!sasl || p == Anope::string::npos) + return; + + ::SASL::Message m; + m.source = params[1]; + m.target = params[0]; + m.type = params[2]; + m.data = params[3]; + m.ext = params.size() > 4 ? params[4] : ""; + + sasl->ProcessMessage(m); +} - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - size_t p = params[1].find('!'); - if (!SASL::sasl || p == Anope::string::npos) - return; +void unreal::SDesc::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + source.GetServer()->SetDescription(params[0]); +} - SASL::Message m; - m.source = params[1]; - m.target = params[0]; - m.type = params[2]; - m.data = params[3]; - m.ext = params.size() > 4 ? params[4] : ""; +void unreal::SetHost::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + User *u = source.GetUser(); - SASL::sasl->ProcessMessage(m); - } -}; + /* When a user sets +x we receive the new host and then the mode change */ + if (u->HasMode("CLOAK")) + u->SetDisplayedHost(params[0]); + else + u->SetCloakedHost(params[0]); +} -struct IRCDMessageSDesc : IRCDMessage +void unreal::SetIdent::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageSDesc(Module *creator) : IRCDMessage(creator, "SDESC", 1) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + User *u = source.GetUser(); + u->SetVIdent(params[0]); +} - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - source.GetServer()->SetDescription(params[0]); - } -}; +void unreal::SetName::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + User *u = source.GetUser(); + u->SetRealname(params[0]); +} -struct IRCDMessageSetHost : IRCDMessage +void unreal::ServerMessage::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageSetHost(Module *creator) : IRCDMessage(creator, "SETHOST", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + unsigned int hops = 0; - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + try { - User *u = source.GetUser(); - - /* When a user sets +x we receive the new host and then the mode change */ - if (u->HasMode("CLOAK")) - u->SetDisplayedHost(params[0]); - else - u->SetCloakedHost(params[0]); + hops = convertTo<unsigned>(params[1]); } -}; + catch (const ConvertException &) { } -struct IRCDMessageSetIdent : IRCDMessage -{ - IRCDMessageSetIdent(Module *creator) : IRCDMessage(creator, "SETIDENT", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + if (params[1].equals_cs("1")) + { + Anope::string desc; + spacesepstream(params[2]).GetTokenRemainder(desc, 1); - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, desc, UplinkSID); + } + else { - User *u = source.GetUser(); - u->SetVIdent(params[0]); + new Server(source.GetServer(), params[0], hops, params[2]); } -}; -struct IRCDMessageSetName : IRCDMessage + IRCD->Send<messages::Ping>(Me->GetName(), params[0]); +} + +void unreal::SID::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageSetName(Module *creator) : IRCDMessage(creator, "SETNAME", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + unsigned int hops = 0; - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + try { - User *u = source.GetUser(); - u->SetRealname(params[0]); + hops = convertTo<unsigned>(params[1]); } -}; + catch (const ConvertException &) { } -struct IRCDMessageServer : IRCDMessage + new Server(source.GetServer(), params[0], hops, params[3], params[2]); + + IRCD->Send<messages::Ping>(Me->GetName(), params[0]); +} + +void unreal::SJoin::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + Anope::string modes; + if (params.size() >= 4) + for (unsigned i = 2; i < params.size() - 1; ++i) + modes += " " + params[i]; + if (!modes.empty()) + modes.erase(modes.begin()); - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - unsigned int hops = Anope::string(params[1]).is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0; + std::list<Anope::string> bans, excepts, invites; + std::list<rfc1459::Join::SJoinUser> users; - if (params[1].equals_cs("1")) + spacesepstream sep(params[params.size() - 1]); + Anope::string buf; + while (sep.GetToken(buf)) + { + /* Ban */ + if (buf[0] == '&') { - Anope::string desc; - spacesepstream(params[2]).GetTokenRemainder(desc, 1); - - new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, desc); + buf.erase(buf.begin()); + bans.push_back(buf); + } + /* Except */ + else if (buf[0] == '"') + { + buf.erase(buf.begin()); + excepts.push_back(buf); + } + /* Invex */ + else if (buf[0] == '\'') + { + buf.erase(buf.begin()); + invites.push_back(buf); } else - new Server(source.GetServer(), params[0], hops, params[2]); - - IRCD->SendPing(Me->GetName(), params[0]); - } -}; - -struct IRCDMessageSJoin : IRCDMessage -{ - IRCDMessageSJoin(Module *creator) : IRCDMessage(creator, "SJOIN", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - Anope::string modes; - if (params.size() >= 4) - for (unsigned i = 2; i < params.size() - 1; ++i) - modes += " " + params[i]; - if (!modes.empty()) - modes.erase(modes.begin()); - - std::list<Anope::string> bans, excepts, invites; - std::list<Message::Join::SJoinUser> users; - - spacesepstream sep(params[params.size() - 1]); - Anope::string buf; - while (sep.GetToken(buf)) { - /* Ban */ - if (buf[0] == '&') - { - buf.erase(buf.begin()); - bans.push_back(buf); - } - /* Except */ - else if (buf[0] == '"') - { - buf.erase(buf.begin()); - excepts.push_back(buf); - } - /* Invex */ - else if (buf[0] == '\'') + rfc1459::Join::SJoinUser sju; + + /* Get prefixes from the nick */ + for (char ch; !buf.empty() && (ch = ModeManager::GetStatusChar(buf[0]));) { + sju.first.AddMode(ch); buf.erase(buf.begin()); - invites.push_back(buf); } - else + + sju.second = User::Find(buf); + if (!sju.second) { - Message::Join::SJoinUser sju; - - /* Get prefixes from the nick */ - for (char ch; (ch = ModeManager::GetStatusChar(buf[0]));) - { - sju.first.AddMode(ch); - buf.erase(buf.begin()); - } - - sju.second = User::Find(buf); - if (!sju.second) - { - Log(LOG_DEBUG) << "SJOIN for non-existent user " << buf << " on " << params[1]; - continue; - } - - users.push_back(sju); + Anope::Logger.Debug("SJOIN for non-existent user {0} on {1}", buf, params[1]); + continue; } - } - - time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : Anope::CurTime; - Message::Join::SJoin(source, params[1], ts, modes, users); - if (!bans.empty() || !excepts.empty() || !invites.empty()) - { - Channel *c = Channel::Find(params[1]); - - if (!c || c->creation_time != ts) - return; - - ChannelMode *ban = ModeManager::FindChannelModeByName("BAN"), - *except = ModeManager::FindChannelModeByName("EXCEPT"), - *invex = ModeManager::FindChannelModeByName("INVITEOVERRIDE"); - - if (ban) - for (std::list<Anope::string>::iterator it = bans.begin(), it_end = bans.end(); it != it_end; ++it) - c->SetModeInternal(source, ban, *it); - if (except) - for (std::list<Anope::string>::iterator it = excepts.begin(), it_end = excepts.end(); it != it_end; ++it) - c->SetModeInternal(source, except, *it); - if (invex) - for (std::list<Anope::string>::iterator it = invites.begin(), it_end = invites.end(); it != it_end; ++it) - c->SetModeInternal(source, invex, *it); + users.push_back(sju); } } -}; -struct IRCDMessageTopic : IRCDMessage -{ - IRCDMessageTopic(Module *creator) : IRCDMessage(creator, "TOPIC", 4) { } + time_t ts = Anope::CurTime; - /* - ** source = sender prefix - ** parv[0] = channel name - ** parv[1] = topic nickname - ** parv[2] = topic time - ** parv[3] = topic text - */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + try { - Channel *c = Channel::Find(params[0]); - if (c) - c->ChangeTopicInternal(source.GetUser(), params[1], params[3], Anope::string(params[2]).is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime); + ts = convertTo<time_t>(params[0]); } -}; + catch (const ConvertException &) { } + + rfc1459::Join::SJoin(source, params[1], ts, modes, users); + + if (!bans.empty() || !excepts.empty() || !invites.empty()) + { + Channel *c = Channel::Find(params[1]); + + if (!c || c->creation_time != ts) + return; + ChannelMode *ban = ModeManager::FindChannelModeByName("BAN"), + *except = ModeManager::FindChannelModeByName("EXCEPT"), + *invex = ModeManager::FindChannelModeByName("INVITEOVERRIDE"); -struct IRCDMessageUmode2 : IRCDMessage + if (ban) + for (std::list<Anope::string>::iterator it = bans.begin(), it_end = bans.end(); it != it_end; ++it) + c->SetModeInternal(source, ban, *it); + if (except) + for (std::list<Anope::string>::iterator it = excepts.begin(), it_end = excepts.end(); it != it_end; ++it) + c->SetModeInternal(source, except, *it); + if (invex) + for (std::list<Anope::string>::iterator it = invites.begin(), it_end = invites.end(); it != it_end; ++it) + c->SetModeInternal(source, invex, *it); + } +} + +/* +** source = sender prefix +** parv[0] = channel name +** parv[1] = topic nickname +** parv[2] = topic time +** parv[3] = topic text +*/ +void unreal::Topic::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageUmode2(Module *creator) : IRCDMessage(creator, "UMODE2", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + Channel *c = Channel::Find(params[0]); + time_t ts = Anope::CurTime; - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + try { - source.GetUser()->SetModesInternal(source, "%s", params[0].c_str()); + ts = convertTo<time_t>(params[2]); } -}; + catch (const ConvertException &) { } -class ProtoUnreal : public Module + if (c) + c->ChangeTopicInternal(source.GetUser(), params[1], params[3], ts); +} + +/* + * parv[0] = nickname + * parv[1] = hopcount + * parv[2] = timestamp + * parv[3] = username + * parv[4] = hostname + * parv[5] = UID + * parv[6] = servicestamp + * parv[7] = umodes + * parv[8] = virthost, * if none + * parv[9] = cloaked host, * if none + * parv[10] = ip + * parv[11] = info + */ +void unreal::UID::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - UnrealIRCdProto ircd_proto; + Anope::string + nickname = params[0], + hopcount = params[1], + timestamp = params[2], + username = params[3], + hostname = params[4], + uid = params[5], + account = params[6], + umodes = params[7], + vhost = params[8], + chost = params[9], + ip = params[10], + info = params[11]; - /* 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_svskill; - 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::SQuit message_squit; - Message::Stats message_stats; - Message::Time message_time; - Message::Version message_version; - Message::Whois message_whois; + if (ip != "*") + { + Anope::string decoded_ip; + Anope::B64Decode(ip, decoded_ip); - /* Our message handlers */ - IRCDMessageCapab message_capab; - IRCDMessageChgHost message_chghost; - IRCDMessageChgIdent message_chgident; - IRCDMessageChgName message_chgname; - IRCDMessageMode message_mode, message_svsmode, message_svs2mode; - IRCDMessageNetInfo message_netinfo; - IRCDMessageNick message_nick; - IRCDMessagePong message_pong; - IRCDMessageSASL message_sasl; - IRCDMessageSDesc message_sdesc; - IRCDMessageSetHost message_sethost; - IRCDMessageSetIdent message_setident; - IRCDMessageSetName message_setname; - IRCDMessageServer message_server; - IRCDMessageSJoin message_sjoin; - IRCDMessageTopic message_topic; - IRCDMessageUmode2 message_umode2; + sockaddrs ip_addr; + ip_addr.ntop(ip.length() == 8 ? AF_INET : AF_INET6, decoded_ip.c_str()); + ip = ip_addr.addr(); + } - bool use_server_side_mlock; + if (vhost == "*") + vhost.clear(); - void AddModes() + if (chost == "*") + chost.clear(); + + time_t user_ts; + try { - ModeManager::AddChannelMode(new ChannelModeStatus("VOICE", 'v', '+', 0)); - ModeManager::AddChannelMode(new ChannelModeStatus("HALFOP", 'h', '%', 1)); - ModeManager::AddChannelMode(new ChannelModeStatus("OP", 'o', '@', 2)); - /* Unreal sends +q as * and +a as ~ */ - ModeManager::AddChannelMode(new ChannelModeStatus("PROTECT", 'a', '~', 3)); - ModeManager::AddChannelMode(new ChannelModeStatus("OWNER", 'q', '*', 4)); - - /* Add user modes */ - ModeManager::AddUserMode(new UserModeOperOnly("SERV_ADMIN", 'A')); - ModeManager::AddUserMode(new UserMode("BOT", 'B')); - ModeManager::AddUserMode(new UserModeOperOnly("CO_ADMIN", 'C')); - ModeManager::AddUserMode(new UserMode("CENSOR", 'G')); - ModeManager::AddUserMode(new UserModeOperOnly("HIDEOPER", 'H')); - ModeManager::AddUserMode(new UserModeOperOnly("HIDEIDLE", 'I')); - ModeManager::AddUserMode(new UserModeOperOnly("NETADMIN", 'N')); - ModeManager::AddUserMode(new UserMode("REGPRIV", 'R')); - ModeManager::AddUserMode(new UserModeOperOnly("PROTECTED", 'S')); - ModeManager::AddUserMode(new UserMode("NOCTCP", 'T')); - ModeManager::AddUserMode(new UserMode("WEBTV", 'V')); - ModeManager::AddUserMode(new UserModeOperOnly("WHOIS", 'W')); - ModeManager::AddUserMode(new UserModeOperOnly("ADMIN", 'a')); - ModeManager::AddUserMode(new UserMode("DEAF", 'd')); - ModeManager::AddUserMode(new UserModeOperOnly("GLOBOPS", 'g')); - ModeManager::AddUserMode(new UserModeOperOnly("HELPOP", 'h')); - ModeManager::AddUserMode(new UserMode("INVIS", 'i')); - ModeManager::AddUserMode(new UserModeOperOnly("OPER", 'o')); - ModeManager::AddUserMode(new UserMode("PRIV", 'p')); - ModeManager::AddUserMode(new UserModeOperOnly("GOD", 'q')); - ModeManager::AddUserMode(new UserModeNoone("REGISTERED", 'r')); - ModeManager::AddUserMode(new UserModeOperOnly("SNOMASK", 's')); - ModeManager::AddUserMode(new UserModeNoone("VHOST", 't')); - ModeManager::AddUserMode(new UserMode("WALLOPS", 'w')); - ModeManager::AddUserMode(new UserMode("CLOAK", 'x')); - ModeManager::AddUserMode(new UserModeNoone("SSL", 'z')); + user_ts = convertTo<time_t>(timestamp); } - - public: - ProtoUnreal(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_svskill(this, "SVSKILL"), message_motd(this), message_notice(this), message_part(this), message_ping(this), - message_privmsg(this), message_quit(this), message_squit(this), message_stats(this), message_time(this), - message_version(this), message_whois(this), - - message_capab(this), message_chghost(this), message_chgident(this), message_chgname(this), message_mode(this, "MODE"), - message_svsmode(this, "SVSMODE"), message_svs2mode(this, "SVS2MODE"), message_netinfo(this), message_nick(this), message_pong(this), - message_sasl(this), message_sdesc(this), message_sethost(this), message_setident(this), message_setname(this), message_server(this), - message_sjoin(this), message_topic(this), message_umode2(this) + catch (const ConvertException &) { - - this->AddModes(); + user_ts = Anope::CurTime; } - void Prioritize() anope_override + NickServ::Nick *na = NULL; + + if (account == "0") { - ModuleManager::SetPriority(this, PRIORITY_FIRST); + /* nothing */ } + else if (account.is_pos_number_only()) + { + try + { + if (convertTo<time_t>(account) == user_ts) + na = NickServ::FindNick(nickname); + } + catch (const ConvertException &) { } + } + else + { + na = NickServ::FindNick(account); + } + + User *u = User::OnIntroduce(nickname, username, hostname, vhost, ip, source.GetServer(), info, user_ts, umodes, uid, na ? na->GetAccount() : NULL); + + if (u && !chost.empty() && chost != u->GetCloakedHost()) + u->SetCloakedHost(chost); +} + +void unreal::Umode2::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + source.GetUser()->SetModesInternal(source, "%s", params[0].c_str()); +} + +class ProtoUnreal : public Module + , public EventHook<Event::UserNickChange> + , public EventHook<Event::ChannelSync> + , public EventHook<Event::ChanRegistered> + , public EventHook<Event::DelChan> + , public EventHook<Event::MLockEvents> +{ + unreal::Proto ircd_proto; + ServiceReference<ModeLocks> mlocks; + + /* Core message handlers */ + rfc1459::Away message_away; + rfc1459::Error message_error; + rfc1459::Invite message_invite; + rfc1459::Join message_join; + rfc1459::Kick message_kick; + rfc1459::Kill message_kill, message_svskill; + 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::SQuit message_squit; + rfc1459::Stats message_stats; + rfc1459::Time message_time; + rfc1459::Version message_version; + rfc1459::Whois message_whois; + + /* Our message handlers */ + unreal::ChgHost message_chghost; + unreal::ChgIdent message_chgident; + unreal::ChgName message_chgname; + unreal::MD message_md; + unreal::Mode message_mode, message_svsmode, message_svs2mode; + unreal::NetInfo message_netinfo; + unreal::Nick message_nick; + unreal::Pong message_pong; + unreal::Protoctl message_protoctl; + unreal::SASL message_sasl; + unreal::SDesc message_sdesc; + unreal::SetHost message_sethost; + unreal::SetIdent message_setident; + unreal::SetName message_setname; + unreal::ServerMessage message_server; + unreal::SID message_sid; + unreal::SJoin message_sjoin; + unreal::Topic message_topic; + unreal::UID message_uid; + unreal::Umode2 message_umode2; + + rfc1459::senders::GlobalNotice sender_global_notice; + rfc1459::senders::GlobalPrivmsg sender_global_privmsg; + rfc1459::senders::Invite sender_invite; + rfc1459::senders::Kick sender_kick; + rfc1459::senders::ModeChannel sender_mode_chan; + 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; + rfc1459::senders::SQuit sender_squit; + + bahamut::senders::NOOP sender_noop; + bahamut::senders::SVSNick sender_svsnick; + + unreal::senders::Akill sender_akill; + unreal::senders::AkillDel sender_akill_del; + unreal::senders::MessageChannel sender_channel; + unreal::senders::Join sender_join; + unreal::senders::Kill sender_svskill; + unreal::senders::Login sender_login; + unreal::senders::Logout sender_logout; + unreal::senders::ModeUser sender_mode_user; + unreal::senders::NickIntroduction sender_nickintroduction; + unreal::senders::MessageServer sender_server; + unreal::senders::SASL sender_sasl; + unreal::senders::SGLine sender_sgline; + unreal::senders::SGLineDel sender_sgline_del; + unreal::senders::SQLine sender_sqline; + unreal::senders::SQLineDel sender_sqline_del; + unreal::senders::SVSHold sender_svshold; + unreal::senders::SVSHoldDel sender_svsholddel; + unreal::senders::SVSJoin sender_svsjoin; + unreal::senders::SVSPart sender_svspart; + unreal::senders::SWhois sender_swhois; + unreal::senders::Topic sender_topic; + unreal::senders::VhostDel sender_vhost_del; + unreal::senders::VhostSet sender_vhost_set; + unreal::senders::Wallops sender_wallops; - void OnReload(Configuration::Conf *conf) anope_override + bool use_server_side_mlock; + + public: + ProtoUnreal(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , EventHook<Event::UserNickChange>(this, EventHook<Event::UserNickChange>::Priority::FIRST) + , EventHook<Event::ChannelSync>(this, EventHook<Event::ChannelSync>::Priority::FIRST) + , EventHook<Event::ChanRegistered>(this, EventHook<Event::ChanRegistered>::Priority::FIRST) + , EventHook<Event::DelChan>(this, EventHook<Event::DelChan>::Priority::FIRST) + , EventHook<Event::MLockEvents>(this, EventHook<Event::MLockEvents>::Priority::FIRST) + , ircd_proto(this) + , message_away(this) + , message_error(this) + , message_invite(this) + , message_join(this) + , message_kick(this) + , message_kill(this) + , message_svskill(this, "SVSKILL") + , message_motd(this) + , message_notice(this) + , message_part(this) + , message_ping(this) + , message_privmsg(this) + , message_quit(this) + , message_squit(this) + , message_stats(this) + , message_time(this) + , message_version(this) + , message_whois(this) + + , message_chghost(this) + , message_chgident(this) + , message_chgname(this) + , message_md(this) + , message_mode(this, "MODE") + , message_svsmode(this, "SVSMODE") + , message_svs2mode(this, "SVS2MODE") + , message_netinfo(this) + , message_nick(this) + , message_pong(this) + , message_protoctl(this) + , message_sasl(this) + , message_sdesc(this) + , message_sethost(this) + , message_setident(this) + , message_setname(this) + , message_server(this) + , message_sid(this) + , message_sjoin(this) + , message_topic(this) + , message_uid(this) + , message_umode2(this) + + , sender_akill(this) + , sender_akill_del(this) + , sender_channel(this) + , sender_global_notice(this) + , sender_global_privmsg(this) + , sender_invite(this) + , sender_join(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_noop(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_sgline(this) + , sender_sgline_del(this) + , sender_sqline(this) + , sender_sqline_del(this) + , sender_squit(this) + , sender_svshold(this) + , sender_svsholddel(this) + , sender_svsjoin(this) + , sender_svsnick(this) + , sender_svspart(this) + , sender_swhois(this) + , sender_topic(this) + , sender_vhost_del(this) + , sender_vhost_set(this) + , sender_wallops(this) + { + IRCD = &ircd_proto; + } + + ~ProtoUnreal() + { + IRCD = nullptr; + } + + void OnReload(Configuration::Conf *conf) override { 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 UnrealExtban::ChannelMatcher(name, base, character[0]); + else if (type == "entry") + cm = new UnrealExtban::EntryMatcher(name, base, character[0]); + else if (type == "realname") + cm = new UnrealExtban::RealnameMatcher(name, base, character[0]); + else if (type == "registered") + cm = new UnrealExtban::RegisteredMatcher(name, base, character[0]); + else if (type == "account") + cm = new UnrealExtban::AccountMatcher(name, base, character[0]); + else if (type == "fingerprint") + cm = new UnrealExtban::FingerprintMatcher(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")); if (Servers::Capab.count("ESVID") == 0) - IRCD->SendLogout(u); + sender_logout.Send(u); } - void OnChannelSync(Channel *c) anope_override + void OnChannelSync(Channel *c) override { if (!c->ci) return; - ModeLocks *modelocks = c->ci->GetExt<ModeLocks>("modelocks"); - if (use_server_side_mlock && Servers::Capab.count("MLOCK") > 0 && modelocks) + if (use_server_side_mlock && Servers::Capab.count("MLOCK") > 0 && mlocks) { - Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", ""); - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(c->creation_time) << " " << c->ci->name << " " << modes; + Anope::string modes = mlocks->GetMLockAsString(c->ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); + Uplink::Send(Me, "MLOCK", c->creation_time, c->ci->GetName(), modes); } } - void OnChanRegistered(ChannelInfo *ci) anope_override + void OnChanRegistered(ChanServ::Channel *ci) override { - ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); - if (!ci->c || !use_server_side_mlock || !modelocks || !Servers::Capab.count("MLOCK")) + if (!ci->c || !use_server_side_mlock || !mlocks || !Servers::Capab.count("MLOCK")) return; - Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", ""); - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes; + Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); + Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), modes); } - void OnDelChan(ChannelInfo *ci) anope_override + void OnDelChan(ChanServ::Channel *ci) override { if (!ci->c || !use_server_side_mlock || !Servers::Capab.count("MLOCK")) return; - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " :"; + Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), ""); } - 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 && modelocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) + ChannelMode *cm = ModeManager::FindChannelModeByName(lock->GetName()); + if (use_server_side_mlock && cm && mlocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) { - Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar; - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes; + Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar; + Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), 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 && modelocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) + ChannelMode *cm = ModeManager::FindChannelModeByName(lock->GetName()); + if (use_server_side_mlock && cm && mlocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) { - Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, ""); - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes; + Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, ""); + Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), modes); } return EVENT_CONTINUE; |