]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_samode.cpp
82055dad3a611a869c26691ffb027d5d9d925f4d
[user/henk/code/inspircd.git] / src / modules / m_samode.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 /* $ModDesc: Provides more advanced UnrealIRCd SAMODE command */
15
16 #include "inspircd.h"
17
18 /** Handle /SAMODE
19  */
20 class CommandSamode : public Command
21 {
22  public:
23         CommandSamode (InspIRCd* Instance) : Command(Instance,"SAMODE", "o", 2, false, 0)
24         {
25                 this->source = "m_samode.so";
26                 syntax = "<target> <modes> {<mode-parameters>}";
27         }
28
29         CmdResult Handle (const std::vector<std::string>& parameters, User *user)
30         {
31                 /*
32                  * Handles an SAMODE request. Notifies all +s users.
33                  */
34                 ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
35
36                 if (ServerInstance->Modes->GetLastParse().length())
37                 {
38                         ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick) + " used SAMODE: " + ServerInstance->Modes->GetLastParse());
39
40                         std::deque<std::string> n;
41                         irc::spacesepstream spaced(ServerInstance->Modes->GetLastParse());
42                         std::string one;
43                         while (spaced.GetToken(one))
44                                 n.push_back(one);
45
46                         std::string channel = n[0];
47                         n.pop_front();
48                         ServerInstance->PI->SendMode(channel, n);
49
50                         /* XXX: Yes, this is right. We dont want to propagate the
51                          * actual SAMODE command, just the MODE command generated
52                          * by the Protocol Interface
53                          */
54                         return CMD_LOCALONLY;
55                 }
56                 else
57                 {
58                         user->WriteServ("NOTICE %s :*** Invalid SAMODE sequence.", user->nick.c_str());
59                 }
60
61                 return CMD_FAILURE;
62         }
63 };
64
65 class ModuleSaMode : public Module
66 {
67         CommandSamode*  mycommand;
68  public:
69         ModuleSaMode(InspIRCd* Me)
70                 : Module(Me)
71         {
72
73                 mycommand = new CommandSamode(ServerInstance);
74                 ServerInstance->AddCommand(mycommand);
75
76         }
77
78         virtual ~ModuleSaMode()
79         {
80         }
81
82         virtual Version GetVersion()
83         {
84                 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
85         }
86 };
87
88 MODULE_INIT(ModuleSaMode)