From b443df39386c77cf2d027e2b45c4d629261e0100 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Sat, 16 Nov 2019 22:04:08 +0000 Subject: Close connections when an I/O hook is configured but not loaded. --- include/dynref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/dynref.h b/include/dynref.h index 6e2e17423..44829164b 100644 --- a/include/dynref.h +++ b/include/dynref.h @@ -43,7 +43,7 @@ class CoreExport dynamic_reference_base : public interfacebase, public insp::int ModuleRef creator; dynamic_reference_base(Module* Creator, const std::string& Name); ~dynamic_reference_base(); - inline const std::string& GetProvider() { return name; } + inline const std::string& GetProvider() const { return name; } void SetProvider(const std::string& newname); /** Set handler to call when the target object becomes available -- cgit v1.3.1-10-gc9f91 From 687778b72e31322a73b2e2e17af6bd0f2a2561bc Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Sun, 17 Nov 2019 22:06:36 +0000 Subject: Allow Channel::WriteNotice send to other servers and status ranks. --- include/channels.h | 3 ++- src/channels.cpp | 5 +++-- src/modules/m_ojoin.cpp | 6 +----- src/modules/m_spanningtree/fjoin.cpp | 9 +++++++-- src/modules/m_timedbans.cpp | 8 ++------ src/modules/m_uninvite.cpp | 5 +---- 6 files changed, 16 insertions(+), 20 deletions(-) (limited to 'include') diff --git a/include/channels.h b/include/channels.h index d346db8ef..5957ae668 100644 --- a/include/channels.h +++ b/include/channels.h @@ -283,8 +283,9 @@ class CoreExport Channel : public Extensible /** Write a NOTICE to all local users on the channel * @param text Text to send + * @param status The minimum status rank to send this message to. */ - void WriteNotice(const std::string& text); + void WriteNotice(const std::string& text, char status = 0); }; inline bool Channel::HasUser(User* user) diff --git a/src/channels.cpp b/src/channels.cpp index 282199718..5baaf03ee 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -473,10 +473,11 @@ const char* Channel::ChanModes(bool showsecret) return scratch.c_str(); } -void Channel::WriteNotice(const std::string& text) +void Channel::WriteNotice(const std::string& text, char status) { - ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, ServerInstance->FakeClient, this, text, MSG_NOTICE); + ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, ServerInstance->FakeClient, this, text, MSG_NOTICE, status); Write(ServerInstance->GetRFCEvents().privmsg, privmsg); + ServerInstance->PI->SendMessage(this, status, text, MSG_NOTICE); } /* returns the status character for a given user on a channel, e.g. @ for op, diff --git a/src/modules/m_ojoin.cpp b/src/modules/m_ojoin.cpp index c0626ec69..e3366056d 100644 --- a/src/modules/m_ojoin.cpp +++ b/src/modules/m_ojoin.cpp @@ -57,11 +57,7 @@ class CommandOjoin : public SplitCommand ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used OJOIN to join "+channel->name); if (notice) - { - const std::string msg = user->nick + " joined on official network business."; - channel->WriteNotice(msg); - ServerInstance->PI->SendChannelNotice(channel, 0, msg); - } + channel->WriteNotice(user->nick + " joined on official network business."); } else { diff --git a/src/modules/m_spanningtree/fjoin.cpp b/src/modules/m_spanningtree/fjoin.cpp index 6305e5af8..02d985ef3 100644 --- a/src/modules/m_spanningtree/fjoin.cpp +++ b/src/modules/m_spanningtree/fjoin.cpp @@ -276,8 +276,13 @@ void CommandFJoin::RemoveStatus(Channel* c) void CommandFJoin::LowerTS(Channel* chan, time_t TS, const std::string& newname) { if (Utils->AnnounceTSChange) - chan->WriteNotice(InspIRCd::Format("Creation time of %s changed from %s to %s", newname.c_str(), - InspIRCd::TimeString(chan->age).c_str(), InspIRCd::TimeString(TS).c_str())); + { + // WriteNotice is not used here because the message only needs to go to the local server. + const std::string tsmessage = InspIRCd::Format("Creation time of %s changed from %s to %s", newname.c_str(), + InspIRCd::TimeString(chan->age).c_str(), InspIRCd::TimeString(TS).c_str()); + ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, ServerInstance->FakeClient, chan, tsmessage, MSG_NOTICE); + chan->Write(ServerInstance->GetRFCEvents().privmsg, privmsg); + } // While the name is equal in case-insensitive compare, it might differ in case; use the remote version chan->name = newname; diff --git a/src/modules/m_timedbans.cpp b/src/modules/m_timedbans.cpp index ef3382e4b..eb3c47527 100644 --- a/src/modules/m_timedbans.cpp +++ b/src/modules/m_timedbans.cpp @@ -128,9 +128,7 @@ class CommandTban : public Command PrefixMode* mh = ServerInstance->Modes->FindPrefixMode('h'); char pfxchar = (mh && mh->name == "halfop") ? mh->GetPrefix() : '@'; - ClientProtocol::Messages::Privmsg notice(ServerInstance->FakeClient, channel, message, MSG_NOTICE); - channel->Write(ServerInstance->GetRFCEvents().privmsg, notice, pfxchar); - ServerInstance->PI->SendChannelNotice(channel, pfxchar, message); + channel->WriteNotice(message, pfxchar); return CMD_SUCCESS; } @@ -221,9 +219,7 @@ class ModuleTimedBans : public Module PrefixMode* mh = ServerInstance->Modes->FindPrefixMode('h'); char pfxchar = (mh && mh->name == "halfop") ? mh->GetPrefix() : '@'; - ClientProtocol::Messages::Privmsg notice(ClientProtocol::Messages::Privmsg::nocopy, ServerInstance->FakeClient, cr, message, MSG_NOTICE); - cr->Write(ServerInstance->GetRFCEvents().privmsg, notice, pfxchar); - ServerInstance->PI->SendChannelNotice(cr, pfxchar, message); + cr->WriteNotice(message, pfxchar); Modes::ChangeList setban; setban.push_remove(ServerInstance->Modes->FindMode('b', MODETYPE_CHANNEL), mask); diff --git a/src/modules/m_uninvite.cpp b/src/modules/m_uninvite.cpp index ae1553a23..ec5653806 100644 --- a/src/modules/m_uninvite.cpp +++ b/src/modules/m_uninvite.cpp @@ -100,10 +100,7 @@ class CommandUninvite : public Command user->WriteRemoteNumeric(n); lu->WriteNumeric(RPL_UNINVITED, InspIRCd::Format("You were uninvited from %s by %s", c->name.c_str(), user->nick.c_str())); - - std::string msg = "*** " + user->nick + " uninvited " + u->nick + "."; - c->WriteNotice(msg); - ServerInstance->PI->SendChannelNotice(c, 0, msg); + c->WriteNotice(InspIRCd::Format("*** %s uninvited %s.", user->nick.c_str(), u->nick.c_str())); } return CMD_SUCCESS; -- cgit v1.3.1-10-gc9f91 From 2ec7654267f8ad127653839ba9aaf369705e3026 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Sun, 17 Nov 2019 22:37:24 +0000 Subject: Deprecate Send{Channel,User}Notice; use SendMessage instead. --- include/protocol.h | 4 ++-- src/users.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/protocol.h b/include/protocol.h index f98f6b37d..c95ea1706 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -122,7 +122,7 @@ class CoreExport ProtocolInterface * @param status The status character (e.g. %) required to receive. * @param text The message to send. */ - void SendChannelNotice(Channel* target, char status, const std::string &text) + DEPRECATED_METHOD(void SendChannelNotice(Channel* target, char status, const std::string& text)) { SendMessage(target, status, text, MSG_NOTICE); } @@ -131,7 +131,7 @@ class CoreExport ProtocolInterface * @param target The user to message. * @param text The message to send. */ - void SendUserNotice(User* target, const std::string &text) + DEPRECATED_METHOD(void SendUserNotice(User* target, const std::string& text)) { SendMessage(target, text, MSG_NOTICE); } diff --git a/src/users.cpp b/src/users.cpp index bca1c6a7c..6c58f0617 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -853,7 +853,7 @@ void User::WriteNumeric(const Numeric::Numeric& numeric) void User::WriteRemoteNotice(const std::string& text) { - ServerInstance->PI->SendUserNotice(this, text); + ServerInstance->PI->SendMessage(this, text, MSG_NOTICE); } void LocalUser::WriteRemoteNotice(const std::string& text) -- cgit v1.3.1-10-gc9f91 From bef13bcae31bd8111f7de093148319761cbb8c94 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Mon, 25 Nov 2019 14:10:42 +0000 Subject: Add some overloads of IRCv3::Replies::Reply#Send. --- include/modules/ircv3_replies.h | 86 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/modules/ircv3_replies.h b/include/modules/ircv3_replies.h index fc7a7dac9..6a490c4d1 100644 --- a/include/modules/ircv3_replies.h +++ b/include/modules/ircv3_replies.h @@ -45,6 +45,16 @@ class IRCv3::Replies::Reply /** The event provider for this reply. */ ClientProtocol::EventProvider evprov; + /** Wraps a message in an event and sends it to a user. + * @param user The user to send the message to. + * @param msg The message to send to the user. + */ + void SendInternal(LocalUser* user, ClientProtocol::Message& msg) + { + ClientProtocol::Event ev(evprov, msg); + user->Send(ev); + } + protected: /** Initializes a new instance of the Reply class. * @param Creator The module which created this instance. @@ -70,20 +80,88 @@ class IRCv3::Replies::Reply msg.PushParamRef(command->name); msg.PushParam(code); msg.PushParam(description); + SendInternal(user, msg); + } - ClientProtocol::Event ev(evprov, msg); - user->Send(ev); + template + void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const std::string& description) + { + ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName); + msg.PushParamRef(command->name); + msg.PushParam(code); + msg.PushParam(ConvToStr(p1)); + msg.PushParam(description); + SendInternal(user, msg); + } + + template + void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2, + const std::string& description) + { + ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName); + msg.PushParamRef(command->name); + msg.PushParam(code); + msg.PushParam(ConvToStr(p1)); + msg.PushParam(ConvToStr(p2)); + msg.PushParam(description); + SendInternal(user, msg); + } + + template + void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2, + const T3& p3, const std::string& description) + { + ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName); + msg.PushParamRef(command->name); + msg.PushParam(code); + msg.PushParam(ConvToStr(p1)); + msg.PushParam(ConvToStr(p2)); + msg.PushParam(ConvToStr(p3)); + msg.PushParam(description); + SendInternal(user, msg); + } + + template + void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2, + const T3& p3, const T4& p4, const std::string& description) + { + ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName); + msg.PushParamRef(command->name); + msg.PushParam(code); + msg.PushParam(ConvToStr(p1)); + msg.PushParam(ConvToStr(p2)); + msg.PushParam(ConvToStr(p3)); + msg.PushParam(ConvToStr(p4)); + msg.PushParam(description); + SendInternal(user, msg); + } + + template + void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2, + const T3& p3, const T4& p4, const T5& p5, const std::string& description) + { + ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName); + msg.PushParamRef(command->name); + msg.PushParam(code); + msg.PushParam(ConvToStr(p1)); + msg.PushParam(ConvToStr(p2)); + msg.PushParam(ConvToStr(p3)); + msg.PushParam(ConvToStr(p4)); + msg.PushParam(ConvToStr(p5)); + msg.PushParam(description); + SendInternal(user, msg); } /** * Sends a standard reply to the specified user if they have the specified cap - * or a notice if they do not.s + * or a notice if they do not. * @param user The user to send the reply to. * @param command The command that the reply relates to. * @param code A machine readable code for this reply. * @param description A human readable description of this reply. */ - void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code, const std::string& description) + void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code, + const std::string& description) { if (cap.get(user)) Send(user, command, code, description); -- cgit v1.3.1-10-gc9f91 From eaea34e987eba0e9cb839e63a9d0abf6c78ab1c4 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Tue, 3 Dec 2019 12:02:41 +0000 Subject: Send * for empty targets in the no such nick/channel message. --- include/numericbuilder.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/numericbuilder.h b/include/numericbuilder.h index 4431fbc52..dc95cdaf7 100644 --- a/include/numericbuilder.h +++ b/include/numericbuilder.h @@ -257,7 +257,7 @@ class Numerics::NoSuchChannel : public Numeric::Numeric NoSuchChannel(const std::string& chan) : Numeric(ERR_NOSUCHCHANNEL) { - push(chan); + push(chan.empty() ? "*" : chan); push("No such channel"); } }; @@ -269,7 +269,7 @@ class Numerics::NoSuchNick : public Numeric::Numeric NoSuchNick(const std::string& nick) : Numeric(ERR_NOSUCHNICK) { - push(nick); + push(nick.empty() ? "*" : nick); push("No such nick"); } }; -- cgit v1.3.1-10-gc9f91 From 7f36a337134102b46e4b1c80d989f38ee08ec194 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Tue, 3 Dec 2019 12:25:12 +0000 Subject: Bump the InspIRCd ABI version. --- include/modules.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/modules.h b/include/modules.h index d739f0cf1..8ec591024 100644 --- a/include/modules.h +++ b/include/modules.h @@ -107,7 +107,7 @@ struct ModResult { * and numerical comparisons in preprocessor macros if they wish to support * multiple versions of InspIRCd in one file. */ -#define INSPIRCD_VERSION_API 7 +#define INSPIRCD_VERSION_API 8 /** * This #define allows us to call a method in all -- cgit v1.3.1-10-gc9f91