summaryrefslogtreecommitdiff
path: root/modules/protocol/ngircd.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2016-12-17 21:44:22 -0500
committerAdam <Adam@anope.org>2016-12-17 21:44:22 -0500
commit4fcbbbe4fbc137841b47c8e2372477b85649270a (patch)
treef2a5fd3b5a77ef0384df6e2712fdd74f832d7dfe /modules/protocol/ngircd.cpp
parented08d1a31119adb379f8bec46d7ad47ee35c4c92 (diff)
Split ircdproto send functions out into separate services
This makes it easier to see which send functions a protocol module implements as they are all explicitly registered by the module, and avoids the problem of subtly breaking other protocol modules when using inheritance. Also split the old "core" send implementations out into a module, and the TS6 ID generator
Diffstat (limited to 'modules/protocol/ngircd.cpp')
-rw-r--r--modules/protocol/ngircd.cpp188
1 files changed, 98 insertions, 90 deletions
diff --git a/modules/protocol/ngircd.cpp b/modules/protocol/ngircd.cpp
index 1818c1021..7712aec8f 100644
--- a/modules/protocol/ngircd.cpp
+++ b/modules/protocol/ngircd.cpp
@@ -24,23 +24,7 @@
#include "modules/protocol/rfc1459.h"
#include "modules/protocol/ngircd.h"
-void ngircd::Proto::SendSVSKill(const MessageSource &source, User *user, const Anope::string &buf)
-{
- IRCDProto::SendSVSKill(source, user, buf);
- user->KillInternal(source, buf);
-}
-
-ngircd::Proto::Proto(Module *creator) : IRCDProto(creator, "ngIRCd")
-{
- DefaultPseudoclientModes = "+oi";
- CanCertFP = true;
- CanSVSNick = true;
- CanSetVHost = true;
- CanSetVIdent = true;
- MaxModes = 5;
-}
-
-void ngircd::Proto::SendAkill(User *u, XLine *x)
+void ngircd::senders::Akill::Send(User* u, XLine* x)
{
// Calculate the time left before this would expire, capping it at 2 days
time_t timeleft = x->GetExpires() - Anope::CurTime;
@@ -49,100 +33,47 @@ void ngircd::Proto::SendAkill(User *u, XLine *x)
Uplink::Send(Me, "GLINE", x->GetMask(), timeleft, x->GetReason() + " (" + x->GetBy() + ")");
}
-void ngircd::Proto::SendAkillDel(XLine *x)
+void ngircd::senders::AkillDel::Send(XLine* x)
{
Uplink::Send(Me, "GLINE", x->GetMask());
}
-void ngircd::Proto::SendChannel(Channel *c)
+void ngircd::senders::MessageChannel::Send(Channel* c)
{
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 ngircd::Proto::SendClientIntroduction(User *u)
+void ngircd::senders::Login::Send(User *u, NickServ::Nick *na)
{
- Anope::string modes = "+" + u->GetModes();
- Uplink::Send(Me, "NICK", u->nick, 1, u->GetIdent(), u->host, 1, modes, u->realname);
+ Uplink::Send(Me, "METADATA", u->GetUID(), "accountname", na->GetAccount()->GetDisplay());
}
-void ngircd::Proto::SendConnect()
+void ngircd::senders::Logout::Send(User *u)
{
- 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 */
- Uplink::Send("376", "*", "End of MOTD command");
+ Uplink::Send(Me, "METADATA", u->GetUID(), "accountname", "");
}
-void ngircd::Proto::SendForceNickChange(User *u, const Anope::string &newnick, time_t when)
+void ngircd::senders::SVSNick::Send(User* u, const Anope::string& newnick, time_t ts)
{
Uplink::Send(Me, "SVSNICK", u->nick, newnick);
}
-void ngircd::Proto::SendGlobalNotice(ServiceBot *bi, Server *dest, const Anope::string &msg)
-{
- Uplink::Send(bi, "NOTICE", "$" + dest->GetName(), msg);
-}
-
-void ngircd::Proto::SendGlobalPrivmsg(ServiceBot *bi, Server *dest, const Anope::string &msg)
-{
- Uplink::Send(bi, "PRIVMSG", "$" + dest->GetName(), msg);
-}
-
-void ngircd::Proto::SendGlobops(const MessageSource &source, const Anope::string &buf)
-{
- Uplink::Send(source, "WALLOPS", buf);
-}
-
-void ngircd::Proto::SendJoin(User *user, Channel *c, const ChannelStatus *status)
-{
- Uplink::Send(user, "JOIN", c->name);
- 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();
-
- 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);
-
- if (uc != NULL)
- uc->status = cs;
- }
-}
-
-void ngircd::Proto::SendLogin(User *u, NickServ::Nick *na)
-{
- Uplink::Send(Me, "METADATA", u->GetUID(), "accountname", na->GetAccount()->GetDisplay());
-}
-
-void ngircd::Proto::SendLogout(User *u)
-{
- Uplink::Send(Me, "METADATA", u->GetUID(), "accountname", "");
-}
-
-/* SERVER name hop descript */
-void ngircd::Proto::SendServer(Server *server)
+// Received: :dev.anope.de NICK DukeP 1 ~DukePyro p57ABF9C9.dip.t-dialin.net 1 +i :DukePyrolator
+void ngircd::senders::NickIntroduction::Send(User *user)
{
- Uplink::Send("SERVER", server->GetName(), server->GetHops(), server->GetDescription());
+ Anope::string modes = "+" + user->GetModes();
+ Uplink::Send(Me, "NICK", user->nick, 1, user->GetIdent(), user->host, 1, modes, user->realname);
}
-void ngircd::Proto::SendTopic(const MessageSource &source, Channel *c)
+void ngircd::senders::VhostDel::Send(User* u)
{
- Uplink::Send(source, "TOPIC", c->name, c->topic);
+ IRCD->Send<messages::VhostSet>(u, u->GetIdent(), "");
}
-void ngircd::Proto::SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost)
+void ngircd::senders::VhostSet::Send(User* u, const Anope::string& vident, const Anope::string& vhost)
{
- if (!vIdent.empty())
- Uplink::Send(Me, "METADATA", u->nick, "user", vIdent);
+ if (!vident.empty())
+ Uplink::Send(Me, "METADATA", u->nick, "user", vident);
Uplink::Send(Me, "METADATA", u->nick, "cloakhost", vhost);
if (!u->HasMode("CLOAK"))
@@ -152,9 +83,23 @@ void ngircd::Proto::SendVhost(User *u, const Anope::string &vIdent, const Anope:
}
}
-void ngircd::Proto::SendVhostDel(User *u)
+ngircd::Proto::Proto(Module *creator) : IRCDProto(creator, "ngIRCd")
{
- this->SendVhost(u, u->GetIdent(), "");
+ DefaultPseudoclientModes = "+oi";
+ CanCertFP = true;
+ CanSVSNick = true;
+ CanSetVHost = true;
+ CanSetVIdent = true;
+ MaxModes = 5;
+}
+
+void ngircd::Proto::Handshake()
+{
+ Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password, "0210-IRC+", "Anope|" + Anope::VersionShort(), "CLHMSo P");
+ /* Make myself known to myself in the serverlist */
+ IRCD->Send<messages::MessageServer>(Me);
+ /* finish the enhanced server handshake and register the connection */
+ Uplink::Send("376", "*", "End of MOTD command");
}
Anope::string ngircd::Proto::Format(IRCMessage &message)
@@ -508,7 +453,7 @@ void ngircd::ServerMessage::Run(MessageSource &source, const std::vector<Anope::
* when receiving a new server and then finish sync once we
* get a pong back from that server.
*/
- IRCD->SendPing(Me->GetName(), params[0]);
+ IRCD->Send<messages::Ping>(Me->GetName(), params[0]);
}
class ProtongIRCd : public Module
@@ -546,6 +491,36 @@ class ProtongIRCd : public Module
ngircd::Pong message_pong;
ngircd::ServerMessage message_server;
+ /* Core message senders */
+ rfc1459::senders::GlobalNotice sender_global_notice;
+ rfc1459::senders::GlobalPrivmsg sender_global_privmsg;
+ rfc1459::senders::Invite sender_invite;
+ rfc1459::senders::Join sender_join;
+ rfc1459::senders::Kick sender_kick;
+ rfc1459::senders::Kill sender_svskill;
+ rfc1459::senders::ModeChannel sender_mode_chan;
+ rfc1459::senders::ModeUser sender_mode_user;
+ rfc1459::senders::NickChange sender_nickchange;
+ rfc1459::senders::Notice sender_notice;
+ rfc1459::senders::Part sender_part;
+ rfc1459::senders::Ping sender_ping;
+ rfc1459::senders::Pong sender_pong;
+ rfc1459::senders::Privmsg sender_privmsg;
+ rfc1459::senders::Quit sender_quit;
+ rfc1459::senders::MessageServer sender_server;
+ rfc1459::senders::SQuit sender_squit;
+ rfc1459::senders::Topic sender_topic;
+ rfc1459::senders::Wallops sender_wallops;
+
+ ngircd::senders::Akill sender_akill;
+ ngircd::senders::AkillDel sender_akill_del;
+ ngircd::senders::MessageChannel sender_channel;
+ ngircd::senders::Login sender_login;
+ ngircd::senders::Logout sender_logout;
+ ngircd::senders::SVSNick sender_svsnick;
+ ngircd::senders::VhostDel sender_vhost_del;
+ ngircd::senders::VhostSet sender_vhost_set;
+
public:
ProtongIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR)
, EventHook<Event::UserNickChange>(this)
@@ -578,10 +553,43 @@ class ProtongIRCd : public Module
, message_pong(this)
, message_server(this)
, message_topic(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_notice(this)
+ , sender_part(this)
+ , sender_ping(this)
+ , sender_pong(this)
+ , sender_privmsg(this)
+ , sender_quit(this)
+ , sender_server(this)
+ , sender_squit(this)
+ , sender_svsnick(this)
+ , sender_topic(this)
+ , sender_vhost_del(this)
+ , sender_vhost_set(this)
+ , sender_wallops(this)
+ {
Servers::Capab.insert("QS");
+ IRCD = &ircd_proto;
+ }
+
+ ~ProtongIRCd()
+ {
+ IRCD = nullptr;
}
void OnUserNickChange(User *u, const Anope::string &) override