]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_samode.cpp
34278101eb1b3749f5b895a2b17a9669ed9bf4f2
[user/henk/code/inspircd.git] / src / modules / m_samode.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18
19 /*
20  * SAMODE module for InspIRCd
21  *  Co authored by Brain and w00t
22  *
23  *  Syntax: /SAMODE <#chan/nick> +/-<modes> [parameters for modes]
24  * 
25  */
26
27 /* $ModDesc: Provides more advanced UnrealIRCd SAMODE command */
28
29 /*
30  * ToDo:
31  *   Err... not a lot really.
32  */ 
33
34 #include <stdio.h>
35 #include "users.h"
36 #include "channels.h"
37 #include "modules.h"
38 #include "inspircd.h"
39
40 /** Handle /SAMODE
41  */
42 class cmd_samode : public command_t
43 {
44  public:
45         cmd_samode (InspIRCd* Instance) : command_t(Instance,"SAMODE", 'o', 2)
46         {
47                 this->source = "m_samode.so";
48                 syntax = "<target> <modes> {<mode-parameters>}";
49         }
50
51         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
52         {
53                 /*
54                  * Handles an SAMODE request. Notifies all +s users.
55                  */
56
57                 userrec* n = new userrec(ServerInstance);
58                 n->SetFd(FD_MAGIC_NUMBER);
59                 ServerInstance->SendMode(parameters,pcnt,n);
60                 delete n;
61
62                 if (ServerInstance->Modes->GetLastParse().length())
63                 {
64                         ServerInstance->WriteOpers(std::string(user->nick)+" used SAMODE: "+ServerInstance->Modes->GetLastParse());
65
66                         std::deque<std::string> n;
67                         irc::spacesepstream spaced(ServerInstance->Modes->GetLastParse());
68                         std::string one = "*";
69                         while ((one = spaced.GetToken()) != "")
70                                 n.push_back(one);
71
72                         Event rmode((char *)&n, NULL, "send_mode_explicit");
73                         rmode.Send(ServerInstance);
74
75                         /* XXX: Yes, this is right. We dont want to propogate the
76                          * actual SAMODE command, just the MODE command generated
77                          * by the send_mode_explicit
78                          */
79                         return CMD_FAILURE;
80                 }
81
82                 return CMD_FAILURE;
83         }
84 };
85
86 class ModuleSaMode : public Module
87 {
88         cmd_samode*     mycommand;
89  public:
90         ModuleSaMode(InspIRCd* Me)
91                 : Module::Module(Me)
92         {
93                 
94                 mycommand = new cmd_samode(ServerInstance);
95                 ServerInstance->AddCommand(mycommand);
96         }
97         
98         virtual ~ModuleSaMode()
99         {
100         }
101         
102         virtual Version GetVersion()
103         {
104                 return Version(1,1,2,2,VF_VENDOR,API_VERSION);
105         }
106 };
107
108
109 class ModuleSaModeFactory : public ModuleFactory
110 {
111  public:
112         ModuleSaModeFactory()
113         {
114         }
115         
116         ~ModuleSaModeFactory()
117         {
118         }
119         
120         virtual Module * CreateModule(InspIRCd* Me)
121         {
122                 return new ModuleSaMode(Me);
123         }
124         
125 };
126
127
128 extern "C" void * init_module( void )
129 {
130         return new ModuleSaModeFactory;
131 }