]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_wallops.cpp
Add support for blocking tag messages with the deaf mode.
[user/henk/code/inspircd.git] / src / coremods / core_wallops.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2018-2019 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2013-2014, 2018 Attila Molnar <attilamolnar@hush.com>
6  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
7  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
8  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
9  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
10  *   Copyright (C) 2006, 2010 Craig Edwards <brain@inspircd.org>
11  *
12  * This file is part of InspIRCd.  InspIRCd is free software: you can
13  * redistribute it and/or modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation, version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19  * details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24
25
26 #include "inspircd.h"
27
28 /** Handle /WALLOPS.
29  */
30 class CommandWallops : public Command
31 {
32         SimpleUserModeHandler wallopsmode;
33         ClientProtocol::EventProvider protoevprov;
34
35  public:
36         /** Constructor for wallops.
37          */
38         CommandWallops(Module* parent)
39                 : Command(parent, "WALLOPS", 1, 1)
40                 , wallopsmode(parent, "wallops", 'w')
41                 , protoevprov(parent, name)
42         {
43                 flags_needed = 'o';
44                 syntax = ":<message>";
45         }
46
47         /** Handle command.
48          * @param parameters The parameters to the command
49          * @param user The user issuing the command
50          * @return A value from CmdResult to indicate command success or failure.
51          */
52         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
53
54         RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
55         {
56                 return ROUTE_BROADCAST;
57         }
58 };
59
60 CmdResult CommandWallops::Handle(User* user, const Params& parameters)
61 {
62         if (parameters[0].empty())
63         {
64                 user->WriteNumeric(ERR_NOTEXTTOSEND, "No text to send");
65                 return CMD_FAILURE;
66         }
67
68         ClientProtocol::Message msg("WALLOPS", user);
69         msg.PushParamRef(parameters[0]);
70         ClientProtocol::Event wallopsevent(protoevprov, msg);
71
72         const UserManager::LocalList& list = ServerInstance->Users.GetLocalUsers();
73         for (UserManager::LocalList::const_iterator i = list.begin(); i != list.end(); ++i)
74         {
75                 LocalUser* curr = *i;
76                 if (curr->IsModeSet(wallopsmode))
77                         curr->Send(wallopsevent);
78         }
79
80         return CMD_SUCCESS;
81 }
82
83 class CoreModWallops : public Module
84 {
85  private:
86         CommandWallops cmd;
87
88  public:
89         CoreModWallops()
90                 : cmd(this)
91         {
92         }
93
94         Version GetVersion() CXX11_OVERRIDE
95         {
96                 return Version("Provides the WALLOPS command", VF_CORE | VF_VENDOR);
97         }
98 };
99
100 MODULE_INIT(CoreModWallops)