]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_samode.cpp
7f3e9f428757ec79d7129d2411a085c126b1660f
[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 #include "users.h"
18 #include "channels.h"
19 #include "modules.h"
20
21 /** Handle /SAMODE
22  */
23 class cmd_samode : public command_t
24 {
25  public:
26         cmd_samode (InspIRCd* Instance) : command_t(Instance,"SAMODE", 'o', 2)
27         {
28                 this->source = "m_samode.so";
29                 syntax = "<target> <modes> {<mode-parameters>}";
30         }
31
32         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
33         {
34                 /*
35                  * Handles an SAMODE request. Notifies all +s users.
36                  */
37
38                 userrec* n = new userrec(ServerInstance);
39                 n->SetFd(FD_MAGIC_NUMBER);
40                 ServerInstance->SendMode(parameters,pcnt,n);
41                 delete n;
42
43                 if (ServerInstance->Modes->GetLastParse().length())
44                 {
45                         ServerInstance->WriteOpers("*** " + std::string(user->nick) + " used SAMODE: " + ServerInstance->Modes->GetLastParse());
46
47                         std::deque<std::string> n;
48                         irc::spacesepstream spaced(ServerInstance->Modes->GetLastParse());
49                         std::string one = "*";
50                         while (spaced.GetToken(one))
51                                 n.push_back(one);
52
53                         Event rmode((char *)&n, NULL, "send_mode");
54                         rmode.Send(ServerInstance);
55
56                         n.clear();
57                         n.push_back(std::string(user->nick) + " used SAMODE: " + ServerInstance->Modes->GetLastParse());
58                         Event rmode2((char *)&n, NULL, "send_opers");
59                         rmode2.Send(ServerInstance);
60
61                         /* XXX: Yes, this is right. We dont want to propogate the
62                          * actual SAMODE command, just the MODE command generated
63                          * by the send_mode
64                          */
65                         return CMD_LOCALONLY;
66                 }
67                 else
68                 {
69                         user->WriteServ("NOTICE %s :*** Invalid SAMODE sequence.", user->nick);
70                 }
71
72                 return CMD_FAILURE;
73         }
74 };
75
76 class ModuleSaMode : public Module
77 {
78         cmd_samode*     mycommand;
79  public:
80         ModuleSaMode(InspIRCd* Me)
81                 : Module(Me)
82         {
83                 
84                 mycommand = new cmd_samode(ServerInstance);
85                 ServerInstance->AddCommand(mycommand);
86         }
87         
88         virtual ~ModuleSaMode()
89         {
90         }
91         
92         virtual Version GetVersion()
93         {
94                 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
95         }
96 };
97
98 MODULE_INIT(ModuleSaMode)