]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_info/core_info.cpp
Don't update the idle timer when a user replies to a CTCP.
[user/henk/code/inspircd.git] / src / coremods / core_info / core_info.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
5  *
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.
9  *
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
13  * details.
14  *
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/>.
17  */
18
19
20 #include "inspircd.h"
21 #include "core_info.h"
22
23 enum
24 {
25         // From RFC 2812.
26         RPL_WELCOME = 1,
27         RPL_YOURHOST = 2,
28         RPL_CREATED = 3,
29         RPL_MYINFO = 4
30 };
31
32 RouteDescriptor ServerTargetCommand::GetRouting(User* user, const Params& parameters)
33 {
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;
38 }
39
40 class CoreModInfo : public Module
41 {
42         CommandAdmin cmdadmin;
43         CommandCommands cmdcommands;
44         CommandInfo cmdinfo;
45         CommandModules cmdmodules;
46         CommandMotd cmdmotd;
47         CommandTime cmdtime;
48         CommandVersion cmdversion;
49         Numeric::Numeric numeric004;
50
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
56         */
57         static std::string CreateModeList(ModeType mt, bool needparam = false)
58         {
59                 std::string modestr;
60                 for (unsigned char mode = 'A'; mode <= 'z'; mode++)
61                 {
62                         ModeHandler* mh = ServerInstance->Modes.FindMode(mode, mt);
63                         if ((mh) && ((!needparam) || (mh->NeedsParam(true))))
64                                 modestr.push_back(mode);
65                 }
66                 return modestr;
67         }
68
69         void OnServiceChange(const ServiceProvider& prov)
70         {
71                 if (prov.service != SERVICE_MODE)
72                         return;
73
74                 std::vector<std::string>& params = numeric004.GetParams();
75                 params.erase(params.begin()+2, params.end());
76
77                 // Create lists of modes
78                 // 1. User modes
79                 // 2. Channel 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));
84         }
85  public:
86         CoreModInfo()
87                 : cmdadmin(this)
88                 , cmdcommands(this)
89                 , cmdinfo(this)
90                 , cmdmodules(this)
91                 , cmdmotd(this)
92                 , cmdtime(this)
93                 , cmdversion(this)
94                 , numeric004(RPL_MYINFO)
95         {
96                 numeric004.push(ServerInstance->Config->ServerName);
97                 numeric004.push(INSPIRCD_BRANCH);
98         }
99
100         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
101         {
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");
106         }
107
108         void OnUserConnect(LocalUser* user) CXX11_OVERRIDE
109         {
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);
114
115                 ServerInstance->ISupport.SendTo(user);
116
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));
122                 if (!MOD_RESULT)
123                         ServerInstance->Parser.CallHandler(command, parameters, user);
124
125                 MOD_RESULT = MOD_RES_PASSTHRU;
126                 command = "MOTD";
127                 FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, user, true));
128                 if (!MOD_RESULT)
129                         ServerInstance->Parser.CallHandler(command, parameters, user);
130
131                 if (ServerInstance->Config->RawLog)
132                 {
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);
135                 }
136         }
137
138         void OnServiceAdd(ServiceProvider& service) CXX11_OVERRIDE
139         {
140                 OnServiceChange(service);
141         }
142
143         void OnServiceDel(ServiceProvider& service) CXX11_OVERRIDE
144         {
145                 OnServiceChange(service);
146         }
147
148         void Prioritize() CXX11_OVERRIDE
149         {
150                 ServerInstance->Modules.SetPriority(this, I_OnUserConnect, PRIORITY_FIRST);
151         }
152
153         Version GetVersion() CXX11_OVERRIDE
154         {
155                 return Version("Provides the ADMIN, COMMANDS, INFO, MODULES, MOTD, TIME and VERSION commands", VF_VENDOR|VF_CORE);
156         }
157 };
158
159 MODULE_INIT(CoreModInfo)