2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2018, 2020 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2018 linuxdaemon <linuxdaemon.irc@gmail.com>
6 * Copyright (C) 2014, 2016, 2018 Attila Molnar <attilamolnar@hush.com>
8 * This file is part of InspIRCd. InspIRCd is free software: you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation, version 2.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "core_info.h"
34 RouteDescriptor ServerTargetCommand::GetRouting(User* user, const Params& parameters)
36 // Parameter must be a server name, not a nickname or uuid
37 if ((!parameters.empty()) && (parameters[0].find('.') != std::string::npos))
38 return ROUTE_UNICAST(parameters[0]);
39 return ROUTE_LOCALONLY;
42 class CoreModInfo : public Module
44 CommandAdmin cmdadmin;
45 CommandCommands cmdcommands;
47 CommandModules cmdmodules;
49 CommandServList cmdservlist;
51 CommandVersion cmdversion;
52 Numeric::Numeric numeric004;
54 /** Returns a list of user or channel mode characters.
55 * Used for constructing the parts of the mode list in the 004 numeric.
56 * @param mt Controls whether to list user modes or channel modes
57 * @param needparam Return modes only if they require a parameter to be set
58 * @return The available mode letters that satisfy the given conditions
60 static std::string CreateModeList(ModeType mt, bool needparam = false)
63 for (unsigned char mode = 'A'; mode <= 'z'; mode++)
65 ModeHandler* mh = ServerInstance->Modes.FindMode(mode, mt);
66 if ((mh) && ((!needparam) || (mh->NeedsParam(true))))
67 modestr.push_back(mode);
72 void OnServiceChange(const ServiceProvider& prov)
74 if (prov.service != SERVICE_MODE)
77 std::vector<std::string>& params = numeric004.GetParams();
78 params.erase(params.begin()+2, params.end());
80 // Create lists of modes
83 // 3. Channel modes that require a parameter when set
84 numeric004.push(CreateModeList(MODETYPE_USER));
85 numeric004.push(CreateModeList(MODETYPE_CHANNEL));
86 numeric004.push(CreateModeList(MODETYPE_CHANNEL, true));
98 , numeric004(RPL_MYINFO)
100 numeric004.push(ServerInstance->Config->ServerName);
101 numeric004.push(INSPIRCD_BRANCH);
104 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
106 // Process the escape codes in the MOTDs.
107 ConfigFileCache newmotds;
108 for (ServerConfig::ClassVector::const_iterator iter = ServerInstance->Config->Classes.begin(); iter != ServerInstance->Config->Classes.end(); ++iter)
110 ConfigTag* tag = (*iter)->config;
111 // Don't process the file if it has already been processed.
112 const std::string motd = tag->getString("motd", "motd");
113 if (newmotds.find(motd) != newmotds.end())
116 // We can't process the file if it doesn't exist.
117 ConfigFileCache::iterator file = ServerInstance->Config->Files.find(motd);
118 if (file == ServerInstance->Config->Files.end())
121 // Process escape codes.
122 newmotds[file->first] = file->second;
123 InspIRCd::ProcessColors(newmotds[file->first]);
126 cmdmotd.motds.swap(newmotds);
128 ConfigTag* tag = ServerInstance->Config->ConfValue("admin");
129 cmdadmin.AdminName = tag->getString("name");
130 cmdadmin.AdminEmail = tag->getString("email", "null@example.com");
131 cmdadmin.AdminNick = tag->getString("nick", "admin");
134 void OnUserConnect(LocalUser* user) CXX11_OVERRIDE
136 user->WriteNumeric(RPL_WELCOME, InspIRCd::Format("Welcome to the %s IRC Network %s", ServerInstance->Config->Network.c_str(), user->GetFullRealHost().c_str()));
137 user->WriteNumeric(RPL_YOURHOST, InspIRCd::Format("Your host is %s, running version %s", ServerInstance->Config->GetServerName().c_str(), INSPIRCD_BRANCH));
138 user->WriteNumeric(RPL_CREATED, InspIRCd::TimeString(ServerInstance->startup_time, "This server was created %H:%M:%S %b %d %Y"));
139 user->WriteNumeric(numeric004);
141 ServerInstance->ISupport.SendTo(user);
143 /* Trigger MOTD and LUSERS output, give modules a chance too */
144 ModResult MOD_RESULT;
145 std::string command("LUSERS");
146 CommandBase::Params parameters;
147 FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, user, true));
149 ServerInstance->Parser.CallHandler(command, parameters, user);
151 MOD_RESULT = MOD_RES_PASSTHRU;
153 FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, user, true));
155 ServerInstance->Parser.CallHandler(command, parameters, user);
157 if (ServerInstance->Config->RawLog)
159 ClientProtocol::Messages::Privmsg rawlogmsg(ServerInstance->FakeClient, user, "*** Raw I/O logging is enabled on this server. All messages, passwords, and commands are being recorded.");
160 user->Send(ServerInstance->GetRFCEvents().privmsg, rawlogmsg);
164 void OnServiceAdd(ServiceProvider& service) CXX11_OVERRIDE
166 OnServiceChange(service);
169 void OnServiceDel(ServiceProvider& service) CXX11_OVERRIDE
171 OnServiceChange(service);
174 void Prioritize() CXX11_OVERRIDE
176 ServerInstance->Modules.SetPriority(this, I_OnUserConnect, PRIORITY_FIRST);
179 Version GetVersion() CXX11_OVERRIDE
181 return Version("Provides the ADMIN, COMMANDS, INFO, MODULES, MOTD, TIME, SERVLIST, and VERSION commands", VF_VENDOR|VF_CORE);
185 MODULE_INIT(CoreModInfo)