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