diff options
Diffstat (limited to 'modules/protocol/ngircd.cpp')
-rw-r--r-- | modules/protocol/ngircd.cpp | 239 |
1 files changed, 113 insertions, 126 deletions
diff --git a/modules/protocol/ngircd.cpp b/modules/protocol/ngircd.cpp index 4ea9a15ec..aa2c23a80 100644 --- a/modules/protocol/ngircd.cpp +++ b/modules/protocol/ngircd.cpp @@ -1,21 +1,28 @@ /* - * ngIRCd Protocol module for Anope IRC Services + * Anope IRC Services * - * (C) 2012 Anope Team <team@anope.org> - * (C) 2011-2012, 2014 Alexander Barton <alex@barton.de> - * (C) 2011 Anope Team <team@anope.org> + * Copyright (C) 2011-2016 Anope Team <team@anope.org> + * Copyright (C) 2011-2012, 2014 Alexander Barton <alex@barton.de> * - * 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/>. */ #include "module.h" class ngIRCdProto : public IRCDProto { - void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override + void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) override { IRCDProto::SendSVSKillInternal(source, user, buf); user->KillInternal(source, buf); @@ -32,64 +39,64 @@ class ngIRCdProto : public IRCDProto MaxModes = 5; } - void SendAkill(User *u, XLine *x) anope_override + void SendAkill(User *u, 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) + time_t timeleft = x->GetExpires() - Anope::CurTime; + if (timeleft > 172800 || !x->GetExpires()) timeleft = 172800; - UplinkSocket::Message(Me) << "GLINE " << x->mask << " " << timeleft << " :" << x->GetReason() << " (" << x->by << ")"; + Uplink::Send(Me, "GLINE", x->GetMask(), timeleft, x->GetReason() + " (" + x->GetBy() + ")"); } - void SendAkillDel(const XLine *x) anope_override + void SendAkillDel(XLine *x) override { - UplinkSocket::Message(Me) << "GLINE " << x->mask; + Uplink::Send(Me, "GLINE", x->GetMask()); } - void SendChannel(Channel *c) anope_override + void SendChannel(Channel *c) override { - UplinkSocket::Message(Me) << "CHANINFO " << c->name << " +" << c->GetModes(true, true); + Uplink::Send(Me, "CHANINFO", c->name, "+" + c->GetModes(true, true)); } // Received: :dev.anope.de NICK DukeP 1 ~DukePyro p57ABF9C9.dip.t-dialin.net 1 +i :DukePyrolator - void SendClientIntroduction(User *u) anope_override + void SendClientIntroduction(User *u) override { Anope::string modes = "+" + u->GetModes(); - UplinkSocket::Message(Me) << "NICK " << u->nick << " 1 " << u->GetIdent() << " " << u->host << " 1 " << modes << " :" << u->realname; + Uplink::Send(Me, "NICK", u->nick, 1, u->GetIdent(), u->host, 1, modes, u->realname); } - void SendConnect() anope_override + void SendConnect() override { - UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password << " 0210-IRC+ Anope|" << Anope::VersionShort() << ":CLHMSo P"; + Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password, "0210-IRC+", "Anope|" + Anope::VersionShort(), "CLHMSo P"); /* Make myself known to myself in the serverlist */ SendServer(Me); /* finish the enhanced server handshake and register the connection */ this->SendNumeric(376, "*", ":End of MOTD command"); } - 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->nick << " " << newnick; + Uplink::Send(Me, "SVSNICK", u->nick, newnick); } - void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override + void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { - UplinkSocket::Message(bi) << "NOTICE $" << dest->GetName() << " :" << msg; + Uplink::Send(bi, "NOTICE", "$" + dest->GetName(), msg); } - void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override + void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { - UplinkSocket::Message(bi) << "PRIVMSG $" << dest->GetName() << " :" << msg; + Uplink::Send(bi, "PRIVMSG", "$" + dest->GetName(), msg); } - void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) anope_override + void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) override { - UplinkSocket::Message(source) << "WALLOPS :" << buf; + Uplink::Send(source, "WALLOPS", buf); } - void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override + void SendJoin(User *user, Channel *c, const ChannelStatus *status) override { - UplinkSocket::Message(user) << "JOIN " << c->name; + Uplink::Send(user, "JOIN", c->name); if (status) { /* First save the channel status incase uc->Status == status */ @@ -101,7 +108,7 @@ class ngIRCdProto : public IRCDProto if (uc != NULL) uc->status.Clear(); - BotInfo *setter = BotInfo::Find(user->GetUID()); + 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); @@ -110,54 +117,56 @@ class ngIRCdProto : public IRCDProto } } - void SendKickInternal(const MessageSource &source, const Channel *chan, User *user, const Anope::string &buf) anope_override + void SendKickInternal(const MessageSource &source, const Channel *chan, User *user, const Anope::string &buf) override { if (!buf.empty()) - UplinkSocket::Message(source) << "KICK " << chan->name << " " << user->nick << " :" << buf; + Uplink::Send(source, "KICK", chan->name, user->nick, buf); else - UplinkSocket::Message(source) << "KICK " << chan->name << " " << user->nick; + Uplink::Send(source, "KICK", chan->name, user->nick); } - void SendLogin(User *u, NickAlias *na) anope_override + void SendLogin(User *u, NickServ::Nick *na) override { - UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :" << na->nc->display; + Uplink::Send(Me, "METADATA", u->GetUID(), "accountname", na->GetAccount()->GetDisplay()); } - void SendLogout(User *u) anope_override + void SendLogout(User *u) override { - UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :"; - } + Uplink::Send(Me, "METADATA", u->GetUID(), "accountname", ""); + } - void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) anope_override + void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) override { - UplinkSocket::Message(source) << "MODE " << dest->name << " " << buf; + IRCMessage message(source, "MODE", dest->name); + message.TokenizeAndPush(buf); + Uplink::SendMessage(message); } - void SendPartInternal(User *u, const Channel *chan, const Anope::string &buf) anope_override + void SendPartInternal(User *u, const Channel *chan, const Anope::string &buf) override { if (!buf.empty()) - UplinkSocket::Message(u) << "PART " << chan->name << " :" << buf; + Uplink::Send(u, "PART", chan->name, buf); else - UplinkSocket::Message(u) << "PART " << chan->name; + Uplink::Send(u, "PART", chan->name); } /* SERVER name hop descript */ - void SendServer(const Server *server) anope_override + void SendServer(const Server *server) override { - UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() << " :" << server->GetDescription(); + Uplink::Send("SERVER", server->GetName(), server->GetHops(), server->GetDescription()); } - void SendTopic(const MessageSource &source, Channel *c) anope_override + void SendTopic(const MessageSource &source, Channel *c) override { - UplinkSocket::Message(source) << "TOPIC " << c->name << " :" << c->topic; + Uplink::Send(source, "TOPIC", c->name, c->topic); } - void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) anope_override + void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) override { if (!vIdent.empty()) - UplinkSocket::Message(Me) << "METADATA " << u->nick << " user :" << vIdent; + Uplink::Send(Me, "METADATA", u->nick, "user", vIdent); - UplinkSocket::Message(Me) << "METADATA " << u->nick << " cloakhost :" << vhost; + Uplink::Send(Me, "METADATA", u->nick, "cloakhost", vhost); if (!u->HasMode("CLOAK")) { u->SetMode(Config->GetClient("HostServ"), "CLOAK"); @@ -165,14 +174,16 @@ class ngIRCdProto : public IRCDProto } } - void SendVhostDel(User *u) anope_override + void SendVhostDel(User *u) override { this->SendVhost(u, u->GetIdent(), ""); } - Anope::string Format(const Anope::string &source, const Anope::string &message) anope_override + Anope::string Format(IRCMessage &message) { - return IRCDProto::Format(source.empty() ? Me->GetSID() : source, message); + if (message.GetSource().GetSource().empty()) + message.SetSource(Me); + return IRCDProto::Format(message); } }; @@ -181,7 +192,7 @@ struct IRCDMessage005 : IRCDMessage IRCDMessage005(Module *creator) : IRCDMessage(creator, "005", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } // Please see <http://www.irc.org/tech_docs/005.html> for details. - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { size_t pos; Anope::string parameter, data; @@ -222,7 +233,7 @@ struct IRCDMessage376 : IRCDMessage * */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { } }; @@ -248,7 +259,7 @@ struct IRCDMessageChaninfo : IRCDMessage * a channel has no user limit (the parameter <modes> doesn't list the "l" * channel mode). In this case <limit> should be "0". */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { bool created; Channel *c = Channel::FindOrCreate(params[0], created); @@ -290,7 +301,7 @@ struct IRCDMessageJoin : Message::Join * * if a user joins a new channel, the ircd sends <channelname>\7<umode> */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { User *user = source.GetUser(); size_t pos = params[0].find('\7'); @@ -340,7 +351,7 @@ struct IRCDMessageMetadata : IRCDMessage * - "user": the user name (ident) of a client (can't be empty) */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { User *u = User::Find(params[0]); if (!u) @@ -350,14 +361,14 @@ struct IRCDMessageMetadata : IRCDMessage } if (params[1].equals_cs("accountname")) { - NickCore *nc = NickCore::Find(params[2]); + NickServ::Account *nc = NickServ::FindAccount(params[2]); if (nc) u->Login(nc); } else if (params[1].equals_cs("certfp")) { u->fingerprint = params[2]; - FOREACH_MOD(OnFingerprint, (u)); + EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u); } else if (params[1].equals_cs("cloakhost")) { @@ -391,7 +402,7 @@ struct IRCDMessageMode : IRCDMessage * params[n] = parameters */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { Anope::string modes = params[1]; @@ -438,7 +449,7 @@ struct IRCDMessageNick : IRCDMessage * params[0] = newnick * */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { if (params.size() == 1) { @@ -479,7 +490,7 @@ struct IRCDMessageNJoin : IRCDMessage * * Received: :dev.anope.de NJOIN #test :DukeP2,@DukeP,%test,+test2 */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { std::list<Message::Join::SJoinUser> users; @@ -504,7 +515,7 @@ struct IRCDMessageNJoin : IRCDMessage continue; } users.push_back(sju); - } + } Message::Join::SJoin(source, params[0], 0, "", users); } @@ -519,7 +530,7 @@ struct IRCDMessagePong : IRCDMessage * when receiving a new server and then finish sync once we * get a pong back from that server. */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { if (!source.GetServer()->IsSynced()) source.GetServer()->Sync(false); @@ -555,7 +566,7 @@ struct IRCDMessageServer : IRCDMessage * params[3] = server description */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { if (params.size() == 3) { @@ -582,7 +593,7 @@ struct IRCDMessageTopic : IRCDMessage IRCDMessageTopic(Module *creator) : IRCDMessage(creator, "TOPIC", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } // Received: :DukeP TOPIC #anope :test - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { Channel *c = Channel::Find(params[0]); if (!c) @@ -597,6 +608,7 @@ struct IRCDMessageTopic : IRCDMessage class ProtongIRCd : public Module + , public EventHook<Event::UserNickChange> { ngIRCdProto ircd_proto; @@ -631,71 +643,46 @@ class ProtongIRCd : public Module IRCDMessageServer message_server; IRCDMessageTopic message_topic; - void AddModes() - { - /* Add user modes */ - ModeManager::AddUserMode(new UserMode("NOCTCP", 'b')); - ModeManager::AddUserMode(new UserMode("BOT", 'B')); - ModeManager::AddUserMode(new UserMode("COMMONCHANS", 'C')); - ModeManager::AddUserMode(new UserMode("INVIS", 'i')); - ModeManager::AddUserMode(new UserModeOperOnly("OPER", 'o')); - ModeManager::AddUserMode(new UserModeOperOnly("PROTECTED", 'q')); - ModeManager::AddUserMode(new UserModeOperOnly("RESTRICTED", 'r')); - ModeManager::AddUserMode(new UserModeNoone("REGISTERED", 'R')); - ModeManager::AddUserMode(new UserModeOperOnly("SNOMASK", 's')); - ModeManager::AddUserMode(new UserMode("WALLOPS", 'w')); - ModeManager::AddUserMode(new UserMode("CLOAK", 'x')); - - /* Add modes for ban, exception, and invite lists */ - ModeManager::AddChannelMode(new ChannelModeList("BAN", 'b')); - ModeManager::AddChannelMode(new ChannelModeList("EXCEPT", 'e')); - ModeManager::AddChannelMode(new ChannelModeList("INVITEOVERRIDE", 'I')); - - /* Add channel user modes */ - ModeManager::AddChannelMode(new ChannelModeStatus("VOICE", 'v', '+', 0)); - ModeManager::AddChannelMode(new ChannelModeStatus("HALFOP", 'h', '%', 1)); - ModeManager::AddChannelMode(new ChannelModeStatus("OP", 'o', '@', 2)); - ModeManager::AddChannelMode(new ChannelModeStatus("PROTECT", 'a', '&', 3)); - ModeManager::AddChannelMode(new ChannelModeStatus("OWNER", 'q', '~', 4)); - - /* Add channel modes */ - ModeManager::AddChannelMode(new ChannelMode("INVITE", 'i')); - ModeManager::AddChannelMode(new ChannelModeKey('k')); - ModeManager::AddChannelMode(new ChannelModeParam("LIMIT", 'l', true)); - ModeManager::AddChannelMode(new ChannelMode("MODERATED", 'm')); - ModeManager::AddChannelMode(new ChannelMode("REGMODERATED", 'M')); - ModeManager::AddChannelMode(new ChannelMode("NOEXTERNAL", 'n')); - ModeManager::AddChannelMode(new ChannelMode("OPERONLY", 'O')); - ModeManager::AddChannelMode(new ChannelMode("PERM", 'P')); - ModeManager::AddChannelMode(new ChannelMode("NOKICK", 'Q')); - ModeManager::AddChannelMode(new ChannelModeNoone("REGISTERED", 'r')); - ModeManager::AddChannelMode(new ChannelMode("REGISTEREDONLY", 'R')); - ModeManager::AddChannelMode(new ChannelMode("SECRET", 's')); - ModeManager::AddChannelMode(new ChannelMode("TOPIC", 't')); - ModeManager::AddChannelMode(new ChannelMode("NOINVITE", 'V')); - ModeManager::AddChannelMode(new ChannelMode("SSL", 'z')); - } - public: - ProtongIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR), - ircd_proto(this), - message_capab(this), message_error(this), message_invite(this), message_kick(this), message_kill(this), - message_motd(this), message_notice(this), message_part(this), message_ping(this), message_privmsg(this), - message_squery(this, "SQUERY"), message_quit(this), message_squit(this), message_stats(this), message_time(this), - message_version(this), message_whois(this), - - message_005(this), message_376(this), message_chaninfo(this), message_join(this), message_metadata(this), - message_mode(this), message_nick(this), message_njoin(this), message_pong(this), message_server(this), - message_topic(this) + ProtongIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , EventHook<Event::UserNickChange>(this) + , ircd_proto(this) + , message_capab(this) + , message_error(this) + , message_invite(this) + , message_kick(this) + , message_kill(this) + , message_motd(this) + , message_notice(this) + , message_part(this) + , message_ping(this) + , message_privmsg(this) + , message_squery(this, "SQUERY") + , message_quit(this) + , message_squit(this) + , message_stats(this) + , message_time(this) + , message_version(this) + , message_whois(this) + + , message_005(this) + , message_376(this) + , message_chaninfo(this) + , message_join(this) + , message_metadata(this) + , message_mode(this) + , message_nick(this) + , message_njoin(this) + , message_pong(this) + , message_server(this) + , message_topic(this) { Servers::Capab.insert("QS"); - this->AddModes(); - } - void OnUserNickChange(User *u, const Anope::string &) anope_override + void OnUserNickChange(User *u, const Anope::string &) override { u->RemoveMode(Config->GetClient("NickServ"), "REGISTERED"); } |