diff options
Diffstat (limited to 'modules/protocol/hybrid.cpp')
-rw-r--r-- | modules/protocol/hybrid.cpp | 140 |
1 files changed, 66 insertions, 74 deletions
diff --git a/modules/protocol/hybrid.cpp b/modules/protocol/hybrid.cpp index fc248338e..465f3fd25 100644 --- a/modules/protocol/hybrid.cpp +++ b/modules/protocol/hybrid.cpp @@ -17,7 +17,7 @@ static bool UseSVSAccount = false; // Temporary backwards compatibility hack un class HybridProto : public IRCDProto { - void SendSVSKillInternal(const MessageSource &source, User *u, const Anope::string &buf) anope_override + void SendSVSKillInternal(const MessageSource &source, User *u, const Anope::string &buf) override { IRCDProto::SendSVSKillInternal(source, u, buf); u->KillInternal(source, buf); @@ -40,53 +40,50 @@ class HybridProto : public IRCDProto MaxModes = 6; } - void SendInvite(const MessageSource &source, const Channel *c, User *u) anope_override + void SendInvite(const MessageSource &source, const Channel *c, User *u) override { UplinkSocket::Message(source) << "INVITE " << u->GetUID() << " " << c->name << " " << c->creation_time; } - void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override + void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) override { UplinkSocket::Message(bi) << "NOTICE $$" << dest->GetName() << " :" << msg; } - void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override + void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) override { UplinkSocket::Message(bi) << "PRIVMSG $$" << dest->GetName() << " :" << msg; } - void SendSQLine(User *, const XLine *x) anope_override + void SendSQLine(User *, const XLine *x) override { UplinkSocket::Message(Me) << "RESV * " << (x->expires ? x->expires - Anope::CurTime : 0) << " " << x->mask << " :" << x->reason; } - void SendSGLineDel(const XLine *x) anope_override + void SendSGLineDel(const XLine *x) override { UplinkSocket::Message(Me) << "UNXLINE * " << x->mask; } - void SendSGLine(User *, const XLine *x) anope_override + void SendSGLine(User *, const XLine *x) override { UplinkSocket::Message(Me) << "XLINE * " << x->mask << " " << (x->expires ? x->expires - Anope::CurTime : 0) << " :" << x->GetReason(); } - void SendSZLineDel(const XLine *x) anope_override + void SendSZLineDel(const XLine *x) override { UplinkSocket::Message(Me) << "UNDLINE * " << x->GetHost(); } - void SendSZLine(User *, const XLine *x) anope_override + void SendSZLine(User *, const XLine *x) 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; + /* Calculate the time left before this would expire */ + time_t timeleft = x->expires ? x->expires - Anope::CurTime : x->expires; UplinkSocket::Message(Me) << "DLINE * " << timeleft << " " << x->GetHost() << " :" << x->GetReason(); } - void SendAkillDel(const XLine *x) anope_override + void SendAkillDel(const XLine *x) override { if (x->IsRegex() || x->HasNickOrReal()) return; @@ -94,12 +91,12 @@ class HybridProto : public IRCDProto UplinkSocket::Message(Me) << "UNKLINE * " << x->GetUser() << " " << x->GetHost(); } - void SendSQLineDel(const XLine *x) anope_override + void SendSQLineDel(const XLine *x) override { UplinkSocket::Message(Me) << "UNRESV * " << x->mask; } - void SendJoin(User *u, Channel *c, const ChannelStatus *status) anope_override + void SendJoin(User *u, Channel *c, const ChannelStatus *status) override { UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name << " +" << c->GetModes(true, true) << " :" << u->GetUID(); @@ -122,15 +119,15 @@ class HybridProto : public IRCDProto uc->status.Clear(); BotInfo *setter = BotInfo::Find(u->GetUID()); - for (size_t i = 0; i < cs.Modes().length(); ++i) - c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), u->GetUID(), false); + for (auto mode : cs.Modes()) + c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), u->GetUID(), false); if (uc) uc->status = cs; } } - void SendAkill(User *u, XLine *x) anope_override + void SendAkill(User *u, XLine *x) override { if (x->IsRegex() || x->HasNickOrReal()) { @@ -140,9 +137,9 @@ class HybridProto : public IRCDProto * 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); + for (const auto &[_, user] : UserListByNick) + if (x->manager->Check(user, x)) + this->SendAkill(user, x); return; } @@ -162,16 +159,13 @@ class HybridProto : public IRCDProto << u->realname << " matches " << old->mask; } - /* 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; + /* Calculate the time left before this would expire */ + time_t timeleft = x->expires ? x->expires - Anope::CurTime : x->expires; UplinkSocket::Message(Me) << "KLINE * " << timeleft << " " << x->GetUser() << " " << x->GetHost() << " :" << x->GetReason(); } - void SendServer(const Server *server) anope_override + void SendServer(const Server *server) override { if (server == Me) UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() + 1 << " " << server->GetSID() << " +" << " :" << server->GetDescription(); @@ -179,7 +173,7 @@ class HybridProto : public IRCDProto UplinkSocket::Message(Me) << "SID " << server->GetName() << " " << server->GetHops() + 1 << " " << server->GetSID() << " +" << " :" << server->GetDescription(); } - void SendConnect() anope_override + void SendConnect() override { UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password; @@ -197,7 +191,7 @@ class HybridProto : public IRCDProto UplinkSocket::Message(Me) << "SVINFO 6 6 0 :" << Anope::CurTime; } - void SendClientIntroduction(User *u) anope_override + void SendClientIntroduction(User *u) override { Anope::string modes = "+" + u->GetModes(); @@ -205,17 +199,17 @@ class HybridProto : public IRCDProto << u->host << " " << u->host << " 0.0.0.0 " << u->GetUID() << " * :" << u->realname; } - void SendEOB() anope_override + void SendEOB() override { UplinkSocket::Message(Me) << "EOB"; } - void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) anope_override + void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) override { UplinkSocket::Message(source) << "SVSMODE " << u->GetUID() << " " << u->timestamp << " " << buf; } - void SendLogin(User *u, NickAlias *na) anope_override + void SendLogin(User *u, NickAlias *na) override { if (UseSVSAccount == false) IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %s", na->nc->display.c_str()); @@ -223,7 +217,7 @@ class HybridProto : public IRCDProto UplinkSocket::Message(Me) << "SVSACCOUNT " << u->GetUID() << " " << u->timestamp << " " << na->nc->display; } - void SendLogout(User *u) anope_override + void SendLogout(User *u) override { if (UseSVSAccount == false) IRCD->SendMode(Config->GetClient("NickServ"), u, "+d *"); @@ -231,28 +225,28 @@ class HybridProto : public IRCDProto UplinkSocket::Message(Me) << "SVSACCOUNT " << u->GetUID() << " " << u->timestamp << " *"; } - void SendChannel(Channel *c) anope_override + void SendChannel(Channel *c) override { Anope::string modes = "+" + c->GetModes(true, true); UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name << " " << modes << " :"; } - void SendTopic(const MessageSource &source, Channel *c) anope_override + void SendTopic(const MessageSource &source, Channel *c) override { UplinkSocket::Message(source) << "TBURST " << c->creation_time << " " << c->name << " " << c->topic_ts << " " << c->topic_setter << " :" << c->topic; } - void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) anope_override + void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) override { UplinkSocket::Message(Me) << "SVSNICK " << u->GetUID() << " " << u->timestamp << " " << newnick << " " << when; } - void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &) anope_override + void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &) override { UplinkSocket::Message(source) << "SVSJOIN " << u->GetUID() << " " << chan; } - void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string ¶m) anope_override + void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string ¶m) override { if (!param.empty()) UplinkSocket::Message(source) << "SVSPART " << u->GetUID() << " " << chan << " :" << param; @@ -260,34 +254,34 @@ class HybridProto : public IRCDProto UplinkSocket::Message(source) << "SVSPART " << u->GetUID() << " " << chan; } - void SendSVSHold(const Anope::string &nick, time_t t) anope_override + void SendSVSHold(const Anope::string &nick, time_t t) override { XLine x(nick, Me->GetName(), Anope::CurTime + t, "Being held for registered user"); this->SendSQLine(NULL, &x); } - void SendSVSHoldDel(const Anope::string &nick) anope_override + void SendSVSHoldDel(const Anope::string &nick) override { XLine x(nick); this->SendSQLineDel(&x); } - void SendVhost(User *u, const Anope::string &ident, const Anope::string &host) anope_override + void SendVhost(User *u, const Anope::string &ident, const Anope::string &host) override { UplinkSocket::Message(Me) << "SVSHOST " << u->GetUID() << " " << u->timestamp << " " << host; } - void SendVhostDel(User *u) anope_override + void SendVhostDel(User *u) override { UplinkSocket::Message(Me) << "SVSHOST " << u->GetUID() << " " << u->timestamp << " " << u->host; } - bool IsExtbanValid(const Anope::string &mask) anope_override + bool IsExtbanValid(const Anope::string &mask) override { return mask.length() >= 4 && mask[0] == '$' && mask[2] == ':'; } - bool IsIdentValid(const Anope::string &ident) anope_override + bool IsIdentValid(const Anope::string &ident) override { if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen")) return false; @@ -305,10 +299,8 @@ class HybridProto : public IRCDProto if (a == '-' || a == '_' || a == '.') return false; - for (i = 0; i < ident.length(); ++i) + for (const auto c : ident) { - const char &c = ident[i]; - /* A tilde can only be used as the first character of a user name. */ if (c == '~' && i == 0) continue; @@ -331,7 +323,7 @@ struct IRCDMessageBMask : IRCDMessage /* 0 1 2 3 */ /* :0MC BMASK 1350157102 #channel b :*!*@*.test.com */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { Channel *c = Channel::Find(params[1]); ChannelMode *mode = ModeManager::FindChannelModeByChar(params[2][0]); @@ -353,7 +345,7 @@ struct IRCDMessageCapab : Message::Capab /* 0 */ /* CAPAB :TBURST EOB MLOCK */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { spacesepstream sep(params[0]); Anope::string capab; @@ -368,7 +360,7 @@ struct IRCDMessageCapab : Message::Capab ModeManager::AddChannelMode(new ChannelModeStatus("OWNER", 'q', '~', 4)); } - Message::Capab::Run(source, params); + Message::Capab::Run(source, params, tags); } }; @@ -378,7 +370,7 @@ struct IRCDMessageCertFP: IRCDMessage /* 0 */ /* :0MCAAAAAB CERTFP 4C62287BA6776A89CD4F8FF10A62FFB35E79319F51AF6C62C674984974FCCB1D */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { User *u = source.GetUser(); @@ -391,7 +383,7 @@ struct IRCDMessageEOB : IRCDMessage { IRCDMessageEOB(Module *creator) : IRCDMessage(creator, "EOB", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { source.GetServer()->Sync(true); } @@ -401,7 +393,7 @@ struct IRCDMessageJoin : Message::Join { IRCDMessageJoin(Module *creator) : Message::Join(creator, "JOIN") { } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { if (params.size() < 2) return; @@ -409,7 +401,7 @@ struct IRCDMessageJoin : Message::Join std::vector<Anope::string> p = params; p.erase(p.begin()); - Message::Join::Run(source, p); + Message::Join::Run(source, p, tags); } }; @@ -419,7 +411,7 @@ struct IRCDMessageMetadata : IRCDMessage /* 0 1 2 3 */ /* :0MC METADATA client 0MCAAAAAB certfp :4C62287BA6776A89CD4F8FF10A62FFB35E79319F51AF6C62C674984974FCCB1D */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { if (params[0].equals_cs("client")) { @@ -445,7 +437,7 @@ struct IRCDMessageMLock : IRCDMessage /* 0 1 2 3 */ /* :0MC MLOCK 1350157102 #channel 1350158923 :nt */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { Channel *c = Channel::Find(params[1]); @@ -470,7 +462,7 @@ struct IRCDMessageNick : IRCDMessage /* 0 1 */ /* :0MCAAAAAB NICK newnick 1350157102 */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { source.GetUser()->ChangeNick(params[0], convertTo<time_t>(params[1])); } @@ -482,7 +474,7 @@ struct IRCDMessagePass : IRCDMessage /* 0 */ /* PASS password */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { if (params.size() == 4) UplinkSID = params[3]; @@ -493,7 +485,7 @@ struct IRCDMessagePong : IRCDMessage { IRCDMessagePong(Module *creator) : IRCDMessage(creator, "PONG", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { source.GetServer()->Sync(false); } @@ -505,7 +497,7 @@ struct IRCDMessageServer : IRCDMessage /* 0 1 2 3 4 */ /* SERVER hades.arpa 1 4XY + :ircd-hybrid test server */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { /* Servers other than our immediate uplink are introduced via SID */ if (params[1] != "1") @@ -529,7 +521,7 @@ struct IRCDMessageSID : IRCDMessage /* 0 1 2 3 4 */ /* :0MC SID hades.arpa 2 4XY + :ircd-hybrid test server */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { unsigned int hops = params[1].is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0; new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, params.back(), params[2]); @@ -544,7 +536,7 @@ struct IRCDMessageSJoin : IRCDMessage /* 0 1 2 3 */ /* :0MC SJOIN 1654877335 #nether +nt :@0MCAAAAAB +0MCAAAAAC */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { Anope::string modes; @@ -591,7 +583,7 @@ struct IRCDMessageSVSMode : IRCDMessage /* 0 1 2 */ /* :0MC SVSMODE 0MCAAAAAB 1350157102 +r */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { User *u = User::Find(params[0]); @@ -611,7 +603,7 @@ struct IRCDMessageTBurst : IRCDMessage /* 0 1 2 3 4 */ /* :0MC TBURST 1654867975 #nether 1654877335 Steve!~steve@the.mines :Join the ghast nation */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { Anope::string setter; sepstream(params[3], '!').GetToken(setter, 0); @@ -629,7 +621,7 @@ struct IRCDMessageTMode : IRCDMessage /* 0 1 2 */ /* :0MC TMODE 1654867975 #nether +ntR */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { time_t ts = 0; @@ -656,7 +648,7 @@ struct IRCDMessageUID : IRCDMessage /* 0 1 2 3 4 5 6 7 8 9 10 */ /* :0MC UID Steve 1 1350157102 +oi ~steve virtual.host real.host 10.0.0.1 0MCAAAAAB Steve :Mining all the time */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { NickAlias *na = NULL; @@ -816,17 +808,17 @@ class ProtoHybrid : public Module this->AddModes(); } - void OnUserNickChange(User *u, const Anope::string &) anope_override + void OnUserNickChange(User *u, const Anope::string &) override { u->RemoveModeInternal(Me, ModeManager::FindUserModeByName("REGISTERED")); } - void OnReload(Configuration::Conf *conf) anope_override + void OnReload(Configuration::Conf *conf) override { use_server_side_mlock = conf->GetModule(this)->Get<bool>("use_server_side_mlock"); } - void OnChannelSync(Channel *c) anope_override + void OnChannelSync(Channel *c) override { if (!c->ci) return; @@ -839,13 +831,13 @@ class ProtoHybrid : public Module } } - void OnDelChan(ChannelInfo *ci) anope_override + void OnDelChan(ChannelInfo *ci) override { if (use_server_side_mlock && ci->c && Servers::Capab.count("MLOCK")) UplinkSocket::Message(Me) << "MLOCK " << ci->c->creation_time << " " << ci->name << " " << Anope::CurTime << " :"; } - EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) anope_override + EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) override { ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); @@ -858,7 +850,7 @@ class ProtoHybrid : public Module return EVENT_CONTINUE; } - EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) anope_override + EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) override { ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); |