X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fnumericbuilder.h;h=a077c666deaa9ff67e1d1261281a487d2b492d1e;hb=b0f16081ccaef527ed4b5434a7264508cf455f39;hp=cd418ea11be6d84968090575633f74717930b229;hpb=3aa92b8d13f57b228d565df23cdad4c720d5cff0;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/numericbuilder.h b/include/numericbuilder.h index cd418ea11..a077c666d 100644 --- a/include/numericbuilder.h +++ b/include/numericbuilder.h @@ -1,6 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * + * Copyright (C) 2018-2020 Sadie Powell * Copyright (C) 2015-2016 Attila Molnar * * This file is part of InspIRCd. InspIRCd is free software: you can @@ -22,6 +23,7 @@ namespace Numeric { class WriteNumericSink; + class WriteRemoteNumericSink; template class GenericBuilder; @@ -52,6 +54,22 @@ class Numeric::WriteNumericSink } }; +class Numeric::WriteRemoteNumericSink +{ + User* const user; + + public: + WriteRemoteNumericSink(User* u) + : user(u) + { + } + + void operator()(Numeric& numeric) const + { + user->WriteRemoteNumeric(numeric); + } +}; + template class Numeric::GenericBuilder { @@ -68,7 +86,7 @@ class Numeric::GenericBuilder GenericBuilder(Sink s, unsigned int num, bool addparam = true, size_t additionalsize = 0) : sink(s) , numeric(num) - , max(ServerInstance->Config->Limits.MaxLine - ServerInstance->Config->ServerName.size() - additionalsize - 10) + , max(ServerInstance->Config->Limits.MaxLine - ServerInstance->Config->GetServerName().size() - additionalsize - 10) { if (addparam) numeric.push(std::string()); @@ -138,7 +156,7 @@ class Numeric::GenericParamBuilder : sink(s) , numeric(num) , currlen(0) - , max(ServerInstance->Config->Limits.MaxLine - ServerInstance->Config->ServerName.size() - additionalsize - 10) + , max(ServerInstance->Config->Limits.MaxLine - ServerInstance->Config->GetServerName().size() - additionalsize - 10) { } @@ -179,3 +197,124 @@ class Numeric::ParamBuilder : public GenericParamBuildername); + push(message); + } + + CannotSendTo(Channel* chan, const std::string& what, ModeHandler* mh) + : Numeric(ERR_CANNOTSENDTOCHAN) + { + push(chan->name); + push(InspIRCd::Format("You cannot send %s to this channel whilst the +%c (%s) mode is set.", + what.c_str(), mh->GetModeChar(), mh->name.c_str())); + } + + CannotSendTo(Channel* chan, const std::string& what, char extban, const std::string& extbandesc) + : Numeric(ERR_CANNOTSENDTOCHAN) + { + push(chan->name); + push(InspIRCd::Format("You cannot send %s to this channel whilst %s %c: (%s) extban is set matching you.", + what.c_str(), strchr("AEIOUaeiou", extban) ? "an" : "a", extban, extbandesc.c_str())); + } + + CannotSendTo(User* user, const std::string& message) + : Numeric(ERR_CANTSENDTOUSER) + { + push(user->registered & REG_NICK ? user->nick : "*"); + push(message); + } + + CannotSendTo(User* user, const std::string& what, ModeHandler* mh, bool self = false) + : Numeric(ERR_CANTSENDTOUSER) + { + push(user->registered & REG_NICK ? user->nick : "*"); + push(InspIRCd::Format("You cannot send %s to this user whilst %s have the +%c (%s) mode set.", + what.c_str(), self ? "you" : "they", mh->GetModeChar(), mh->name.c_str())); + } +}; + +/* Builder for the ERR_INVALIDMODEPARAM numeric. */ +class Numerics::InvalidModeParameter : public Numeric::Numeric +{ + private: + void push_message(ModeHandler* mode, const std::string& message) + { + if (!message.empty()) + { + // The caller has specified their own message. + push(message); + return; + } + + const std::string& syntax = mode->GetSyntax(); + if (!syntax.empty()) + { + // If the mode has a syntax hint we include it in the message. + push(InspIRCd::Format("Invalid %s mode parameter. Syntax: %s.", mode->name.c_str(), syntax.c_str())); + } + else + { + // Otherwise, send it without. + push(InspIRCd::Format("Invalid %s mode parameter.", mode->name.c_str())); + } + } + + public: + InvalidModeParameter(Channel* chan, ModeHandler* mode, const std::string& parameter, const std::string& message = "") + : Numeric(ERR_INVALIDMODEPARAM) + { + push(chan->name); + push(mode->GetModeChar()); + push(parameter); + push_message(mode, message); + } + + InvalidModeParameter(User* user, ModeHandler* mode, const std::string& parameter, const std::string& message = "") + : Numeric(ERR_INVALIDMODEPARAM) + { + push(user->registered & REG_NICK ? user->nick : "*"); + push(mode->GetModeChar()); + push(parameter); + push_message(mode, message); + } +}; + +/** Builder for the ERR_NOSUCHCHANNEL numeric. */ +class Numerics::NoSuchChannel : public Numeric::Numeric +{ + public: + NoSuchChannel(const std::string& chan) + : Numeric(ERR_NOSUCHCHANNEL) + { + push(chan.empty() ? "*" : chan); + push("No such channel"); + } +}; + +/** Builder for the ERR_NOSUCHNICK numeric. */ +class Numerics::NoSuchNick : public Numeric::Numeric +{ + public: + NoSuchNick(const std::string& nick) + : Numeric(ERR_NOSUCHNICK) + { + push(nick.empty() ? "*" : nick); + push("No such nick"); + } +};