]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_samode.cpp
84540b1178d6d325f1355048e189b5ca84b5b673
[user/henk/code/inspircd.git] / src / modules / m_samode.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 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 char* const* parameters, int pcnt, User *user)
30         {
31                 /*
32                  * Handles an SAMODE request. Notifies all +s users.
33                  */
34                 ServerInstance->SendMode(parameters, pcnt, 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                         ServerInstance->PI->SendOperNotice(std::string(user->nick) + " used SAMODE: " + ServerInstance->Modes->GetLastParse());
51
52                         /* XXX: Yes, this is right. We dont want to propagate the
53                          * actual SAMODE command, just the MODE command generated
54                          * by the Protocol Interface
55                          */
56                         return CMD_LOCALONLY;
57                 }
58                 else
59                 {
60                         user->WriteServ("NOTICE %s :*** Invalid SAMODE sequence.", user->nick);
61                 }
62
63                 return CMD_FAILURE;
64         }
65 };
66
67 class ModuleSaMode : public Module
68 {
69         CommandSamode*  mycommand;
70  public:
71         ModuleSaMode(InspIRCd* Me)
72                 : Module(Me)
73         {
74                 
75                 mycommand = new CommandSamode(ServerInstance);
76                 ServerInstance->AddCommand(mycommand);
77
78         }
79         
80         virtual ~ModuleSaMode()
81         {
82         }
83         
84         virtual Version GetVersion()
85         {
86                 return Version(1, 2, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
87         }
88 };
89
90 MODULE_INIT(ModuleSaMode)