]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_samode.cpp
Merge pull request #514 from SaberUK/master+virtual-cleanup
[user/henk/code/inspircd.git] / src / modules / m_samode.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
6  *   Copyright (C) 2006-2007 Robin Burchell <robin+git@viroteck.net>
7  *   Copyright (C) 2004-2005 Craig Edwards <craigedwards@brainbox.cc>
8  *
9  * This file is part of InspIRCd.  InspIRCd is free software: you can
10  * redistribute it and/or modify it under the terms of the GNU General Public
11  * License as published by the Free Software Foundation, version 2.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22
23 /* $ModDesc: Provides command SAMODE to allow opers to change modes on channels and users */
24
25 #include "inspircd.h"
26
27 /** Handle /SAMODE
28  */
29 class CommandSamode : public Command
30 {
31  public:
32         bool active;
33         CommandSamode(Module* Creator) : Command(Creator,"SAMODE", 2)
34         {
35                 allow_empty_last_param = false;
36                 flags_needed = 'o'; Penalty = 0; syntax = "<target> <modes> {<mode-parameters>}";
37                 active = false;
38         }
39
40         CmdResult Handle (const std::vector<std::string>& parameters, User *user)
41         {
42                 User* target = ServerInstance->FindNick(parameters[0]);
43                 if ((target) && (target != user))
44                 {
45                         if (!user->HasPrivPermission("users/samode-usermodes", true))
46                                 return CMD_FAILURE;
47                 }
48                 this->active = true;
49                 ServerInstance->Parser->CallHandler("MODE", parameters, user);
50                 if (ServerInstance->Modes->GetLastParse().length())
51                         ServerInstance->SNO->WriteGlobalSno('a', user->nick + " used SAMODE: " +ServerInstance->Modes->GetLastParse());
52                 this->active = false;
53                 return CMD_SUCCESS;
54         }
55 };
56
57 class ModuleSaMode : public Module
58 {
59         CommandSamode cmd;
60  public:
61         ModuleSaMode()
62                 : cmd(this)
63         {
64         }
65
66         void init() CXX11_OVERRIDE
67         {
68                 ServerInstance->Modules->AddService(cmd);
69                 ServerInstance->Modules->Attach(I_OnPreMode, this);
70         }
71
72         Version GetVersion() CXX11_OVERRIDE
73         {
74                 return Version("Provides command SAMODE to allow opers to change modes on channels and users", VF_VENDOR);
75         }
76
77         ModResult OnPreMode(User* source,User* dest,Channel* channel, const std::vector<std::string>& parameters) CXX11_OVERRIDE
78         {
79                 if (cmd.active)
80                         return MOD_RES_ALLOW;
81                 return MOD_RES_PASSTHRU;
82         }
83
84         void Prioritize()
85         {
86                 Module *override = ServerInstance->Modules->Find("m_override.so");
87                 ServerInstance->Modules->SetPriority(this, I_OnPreMode, PRIORITY_BEFORE, &override);
88         }
89 };
90
91 MODULE_INIT(ModuleSaMode)