2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "core_info.h"
32 RouteDescriptor ServerTargetCommand::GetRouting(User* user, const Params& parameters)
34 // Parameter must be a server name, not a nickname or uuid
35 if ((!parameters.empty()) && (parameters[0].find('.') != std::string::npos))
36 return ROUTE_UNICAST(parameters[0]);
37 return ROUTE_LOCALONLY;
40 class CoreModInfo : public Module
42 CommandAdmin cmdadmin;
43 CommandCommands cmdcommands;
45 CommandModules cmdmodules;
48 CommandVersion cmdversion;
49 Numeric::Numeric numeric004;
51 /** Returns a list of user or channel mode characters.
52 * Used for constructing the parts of the mode list in the 004 numeric.
53 * @param mt Controls whether to list user modes or channel modes
54 * @param needparam Return modes only if they require a parameter to be set
55 * @return The available mode letters that satisfy the given conditions
57 static std::string CreateModeList(ModeType mt, bool needparam = false)
60 for (unsigned char mode = 'A'; mode <= 'z'; mode++)
62 ModeHandler* mh = ServerInstance->Modes.FindMode(mode, mt);
63 if ((mh) && ((!needparam) || (mh->NeedsParam(true))))
64 modestr.push_back(mode);
69 void OnServiceChange(const ServiceProvider& prov)
71 if (prov.service != SERVICE_MODE)
74 std::vector<std::string>& params = numeric004.GetParams();
75 params.erase(params.begin()+2, params.end());
77 // Create lists of modes
80 // 3. Channel modes that require a parameter when set
81 numeric004.push(CreateModeList(MODETYPE_USER));
82 numeric004.push(CreateModeList(MODETYPE_CHANNEL));
83 numeric004.push(CreateModeList(MODETYPE_CHANNEL, true));
94 , numeric004(RPL_MYINFO)
96 numeric004.push(ServerInstance->Config->ServerName);
97 numeric004.push(INSPIRCD_BRANCH);
100 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
102 // Process the escape codes in the MOTDs.
103 ConfigFileCache newmotds;
104 for (ServerConfig::ClassVector::const_iterator iter = ServerInstance->Config->Classes.begin(); iter != ServerInstance->Config->Classes.end(); ++iter)
106 ConfigTag* tag = (*iter)->config;
107 // Don't process the file if it has already been processed.
108 const std::string motd = tag->getString("motd", "motd");
109 if (newmotds.find(motd) != newmotds.end())
112 // We can't process the file if it doesn't exist.
113 ConfigFileCache::iterator file = ServerInstance->Config->Files.find(motd);
114 if (file == ServerInstance->Config->Files.end())
117 // Process escape codes.
118 newmotds[file->first] = file->second;
119 InspIRCd::ProcessColors(newmotds[file->first]);
122 cmdmotd.motds.swap(newmotds);
124 ConfigTag* tag = ServerInstance->Config->ConfValue("admin");
125 cmdadmin.AdminName = tag->getString("name");
126 cmdadmin.AdminEmail = tag->getString("email", "null@example.com");
127 cmdadmin.AdminNick = tag->getString("nick", "admin");
130 void OnUserConnect(LocalUser* user) CXX11_OVERRIDE
132 user->WriteNumeric(RPL_WELCOME, InspIRCd::Format("Welcome to the %s IRC Network %s", ServerInstance->Config->Network.c_str(), user->GetFullRealHost().c_str()));
133 user->WriteNumeric(RPL_YOURHOST, InspIRCd::Format("Your host is %s, running version %s", ServerInstance->Config->ServerName.c_str(), INSPIRCD_BRANCH));
134 user->WriteNumeric(RPL_CREATED, InspIRCd::TimeString(ServerInstance->startup_time, "This server was created %H:%M:%S %b %d %Y"));
135 user->WriteNumeric(numeric004);
137 ServerInstance->ISupport.SendTo(user);
139 /* Trigger MOTD and LUSERS output, give modules a chance too */
140 ModResult MOD_RESULT;
141 std::string command("LUSERS");
142 CommandBase::Params parameters;
143 FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, user, true));
145 ServerInstance->Parser.CallHandler(command, parameters, user);
147 MOD_RESULT = MOD_RES_PASSTHRU;
149 FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, user, true));
151 ServerInstance->Parser.CallHandler(command, parameters, user);
153 if (ServerInstance->Config->RawLog)
155 ClientProtocol::Messages::Privmsg rawlogmsg(ServerInstance->FakeClient, user, "*** Raw I/O logging is enabled on this server. All messages, passwords, and commands are being recorded.");
156 user->Send(ServerInstance->GetRFCEvents().privmsg, rawlogmsg);
160 void OnServiceAdd(ServiceProvider& service) CXX11_OVERRIDE
162 OnServiceChange(service);
165 void OnServiceDel(ServiceProvider& service) CXX11_OVERRIDE
167 OnServiceChange(service);
170 void Prioritize() CXX11_OVERRIDE
172 ServerInstance->Modules.SetPriority(this, I_OnUserConnect, PRIORITY_FIRST);
175 Version GetVersion() CXX11_OVERRIDE
177 return Version("Provides the ADMIN, COMMANDS, INFO, MODULES, MOTD, TIME, and VERSION commands", VF_VENDOR|VF_CORE);
181 MODULE_INIT(CoreModInfo)