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 ConfigTag* tag = ServerInstance->Config->ConfValue("admin");
103 cmdadmin.AdminName = tag->getString("name");
104 cmdadmin.AdminEmail = tag->getString("email", "null@example.com");
105 cmdadmin.AdminNick = tag->getString("nick", "admin");
108 void OnUserConnect(LocalUser* user) CXX11_OVERRIDE
110 user->WriteNumeric(RPL_WELCOME, InspIRCd::Format("Welcome to the %s IRC Network %s", ServerInstance->Config->Network.c_str(), user->GetFullRealHost().c_str()));
111 user->WriteNumeric(RPL_YOURHOST, InspIRCd::Format("Your host is %s, running version %s", ServerInstance->Config->ServerName.c_str(), INSPIRCD_BRANCH));
112 user->WriteNumeric(RPL_CREATED, InspIRCd::TimeString(ServerInstance->startup_time, "This server was created %H:%M:%S %b %d %Y"));
113 user->WriteNumeric(numeric004);
115 ServerInstance->ISupport.SendTo(user);
117 /* Trigger MOTD and LUSERS output, give modules a chance too */
118 ModResult MOD_RESULT;
119 std::string command("LUSERS");
120 CommandBase::Params parameters;
121 FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, user, true));
123 ServerInstance->Parser.CallHandler(command, parameters, user);
125 MOD_RESULT = MOD_RES_PASSTHRU;
127 FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, user, true));
129 ServerInstance->Parser.CallHandler(command, parameters, user);
131 if (ServerInstance->Config->RawLog)
133 ClientProtocol::Messages::Privmsg rawlogmsg(ServerInstance->FakeClient, user, "*** Raw I/O logging is enabled on user server. All messages, passwords, and commands are being recorded.");
134 user->Send(ServerInstance->GetRFCEvents().privmsg, rawlogmsg);
138 void OnServiceAdd(ServiceProvider& service) CXX11_OVERRIDE
140 OnServiceChange(service);
143 void OnServiceDel(ServiceProvider& service) CXX11_OVERRIDE
145 OnServiceChange(service);
148 void Prioritize() CXX11_OVERRIDE
150 ServerInstance->Modules.SetPriority(this, I_OnUserConnect, PRIORITY_FIRST);
153 Version GetVersion() CXX11_OVERRIDE
155 return Version("Provides the ADMIN, COMMANDS, INFO, MODULES, MOTD, TIME and VERSION commands", VF_VENDOR|VF_CORE);
159 MODULE_INIT(CoreModInfo)