diff options
author | Peter Powell <petpow@saberuk.com> | 2018-08-22 13:43:46 +0100 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2018-08-22 21:25:55 +0100 |
commit | b5bc17fba34044097844263641c0f612db75d466 (patch) | |
tree | 342ae94f13a302963003fd4821bff2afccd21c42 /src/coremods | |
parent | bc4751a3279b3c058b2f0c5af5fdebbab10474d3 (diff) |
Send the 001-004 numerics and MOTD/LUSERS from core_info.
Co-authored-by: Attila Molnar <attilamolnar@hush.com>
Diffstat (limited to 'src/coremods')
-rw-r--r-- | src/coremods/core_info/core_info.cpp | 100 |
1 files changed, 99 insertions, 1 deletions
diff --git a/src/coremods/core_info/core_info.cpp b/src/coremods/core_info/core_info.cpp index f1a17d089..2d7a89475 100644 --- a/src/coremods/core_info/core_info.cpp +++ b/src/coremods/core_info/core_info.cpp @@ -20,6 +20,15 @@ #include "inspircd.h" #include "core_info.h" +enum +{ + // From RFC 2812. + RPL_WELCOME = 1, + RPL_YOURHOST = 2, + RPL_CREATED = 3, + RPL_MYINFO = 4 +}; + RouteDescriptor ServerTargetCommand::GetRouting(User* user, const Params& parameters) { // Parameter must be a server name, not a nickname or uuid @@ -37,11 +46,55 @@ class CoreModInfo : public Module CommandMotd cmdmotd; CommandTime cmdtime; CommandVersion cmdversion; + Numeric::Numeric numeric004; + /** Returns a list of user or channel mode characters. + * Used for constructing the parts of the mode list in the 004 numeric. + * @param mt Controls whether to list user modes or channel modes + * @param needparam Return modes only if they require a parameter to be set + * @return The available mode letters that satisfy the given conditions + */ + static std::string CreateModeList(ModeType mt, bool needparam = false) + { + std::string modestr; + for (unsigned char mode = 'A'; mode <= 'z'; mode++) + { + ModeHandler* mh = ServerInstance->Modes.FindMode(mode, mt); + if ((mh) && ((!needparam) || (mh->NeedsParam(true)))) + modestr.push_back(mode); + } + return modestr; + } + + void OnServiceChange(const ServiceProvider& prov) + { + if (prov.service != SERVICE_MODE) + return; + + std::vector<std::string>& params = numeric004.GetParams(); + params.erase(params.begin()+2, params.end()); + + // Create lists of modes + // 1. User modes + // 2. Channel modes + // 3. Channel modes that require a parameter when set + numeric004.push(CreateModeList(MODETYPE_USER)); + numeric004.push(CreateModeList(MODETYPE_CHANNEL)); + numeric004.push(CreateModeList(MODETYPE_CHANNEL, true)); + } public: CoreModInfo() - : cmdadmin(this), cmdcommands(this), cmdinfo(this), cmdmodules(this), cmdmotd(this), cmdtime(this), cmdversion(this) + : cmdadmin(this) + , cmdcommands(this) + , cmdinfo(this) + , cmdmodules(this) + , cmdmotd(this) + , cmdtime(this) + , cmdversion(this) + , numeric004(RPL_MYINFO) { + numeric004.push(ServerInstance->Config->ServerName); + numeric004.push(INSPIRCD_BRANCH); } void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE @@ -52,6 +105,51 @@ class CoreModInfo : public Module cmdadmin.AdminNick = tag->getString("nick", "admin"); } + void OnUserConnect(LocalUser* user) CXX11_OVERRIDE + { + user->WriteNumeric(RPL_WELCOME, InspIRCd::Format("Welcome to the %s IRC Network %s", ServerInstance->Config->Network.c_str(), user->GetFullRealHost().c_str())); + user->WriteNumeric(RPL_YOURHOST, InspIRCd::Format("Your host is %s, running version %s", ServerInstance->Config->ServerName.c_str(), INSPIRCD_BRANCH)); + user->WriteNumeric(RPL_CREATED, InspIRCd::TimeString(ServerInstance->startup_time, "This server was created %H:%M:%S %b %d %Y")); + user->WriteNumeric(numeric004); + + ServerInstance->ISupport.SendTo(user); + + /* Trigger MOTD and LUSERS output, give modules a chance too */ + ModResult MOD_RESULT; + std::string command("LUSERS"); + CommandBase::Params parameters; + FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, user, true)); + if (!MOD_RESULT) + ServerInstance->Parser.CallHandler(command, parameters, user); + + MOD_RESULT = MOD_RES_PASSTHRU; + command = "MOTD"; + FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, user, true)); + if (!MOD_RESULT) + ServerInstance->Parser.CallHandler(command, parameters, user); + + if (ServerInstance->Config->RawLog) + { + ClientProtocol::Messages::Privmsg rawlogmsg(ServerInstance->FakeClient, user, "*** Raw I/O logging is enabled on user server. All messages, passwords, and commands are being recorded."); + user->Send(ServerInstance->GetRFCEvents().privmsg, rawlogmsg); + } + } + + void OnServiceAdd(ServiceProvider& service) CXX11_OVERRIDE + { + OnServiceChange(service); + } + + void OnServiceDel(ServiceProvider& service) CXX11_OVERRIDE + { + OnServiceChange(service); + } + + void Prioritize() CXX11_OVERRIDE + { + ServerInstance->Modules.SetPriority(this, I_OnUserConnect, PRIORITY_FIRST); + } + Version GetVersion() CXX11_OVERRIDE { return Version("Provides the ADMIN, COMMANDS, INFO, MODULES, MOTD, TIME and VERSION commands", VF_VENDOR|VF_CORE); |