]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_samode.cpp
Convert all to new Attach() system. The Implements() method needs removing from all...
[user/henk/code/inspircd.git] / src / modules / m_samode.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 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** 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->WriteOpers("*** " + 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                         Event rmode((char *)&n, NULL, "send_mode");
47                         rmode.Send(ServerInstance);
48
49                         n.clear();
50                         n.push_back(std::string(user->nick) + " used SAMODE: " + ServerInstance->Modes->GetLastParse());
51                         Event rmode2((char *)&n, NULL, "send_opers");
52                         rmode2.Send(ServerInstance);
53
54                         /* XXX: Yes, this is right. We dont want to propagate the
55                          * actual SAMODE command, just the MODE command generated
56                          * by the send_mode
57                          */
58                         return CMD_LOCALONLY;
59                 }
60                 else
61                 {
62                         user->WriteServ("NOTICE %s :*** Invalid SAMODE sequence.", user->nick);
63                 }
64
65                 return CMD_FAILURE;
66         }
67 };
68
69 class ModuleSaMode : public Module
70 {
71         CommandSamode*  mycommand;
72  public:
73         ModuleSaMode(InspIRCd* Me)
74                 : Module(Me)
75         {
76                 
77                 mycommand = new CommandSamode(ServerInstance);
78                 ServerInstance->AddCommand(mycommand);
79
80         }
81         
82         virtual ~ModuleSaMode()
83         {
84         }
85         
86         virtual Version GetVersion()
87         {
88                 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
89         }
90 };
91
92 MODULE_INIT(ModuleSaMode)