]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_testcommand.cpp
8f49277cda14b15de3647b72f9764f59236ba7a8
[user/henk/code/inspircd.git] / src / modules / m_testcommand.cpp
1 #include <stdio.h>
2
3 #include "users.h"
4 #include "channels.h"
5 #include "modules.h"
6
7 /* $ModDesc: Povides a proof-of-concept test /WOOT command */
8
9 Server *Srv;
10          
11
12 void handle_woot(char **parameters, int pcnt, userrec *user)
13 {
14         // this test command just accepts:
15         // /woot :<text>
16         // and sends <text> to all opers with +s mode.
17         // NB: The ':' is *REQUIRED* otherwise the parser will
18         // split the line into multiple parameters[]!
19         //
20         // If you want to process all the line with no leading colon, you must 
21         // implement a parser here that assembles parameters[] to match the
22         // syntax of your command - the way it is done in the core is to meet
23         // rfc-compatibility.
24         Srv->SendOpers(parameters[0]);
25         
26
27         // Here is a sample of how to send servermodes. Note that unless remote
28         // servers in your net are u:lined, they may reverse this, but its a
29         // quick and effective modehack.
30         
31         // NOTE: DO NOT CODE LIKE THIS!!! This has no checks and can send
32         // invalid or plain confusing mode changes, code some checking!
33         char* modes[3];
34         modes[0] = "#chatspike";
35         modes[1] = "+o";
36         modes[2] = user->nick;
37         
38         // run the mode change, send numerics (such as "no such channel") back
39         // to "user".
40         Srv->SendMode(modes,3,user);
41 }
42
43 class ModuleTestCommand : public Module
44 {
45  public:
46         ModuleTestCommand()
47         {
48                 Srv = new Server;
49                 // Create a new command:
50                 // command will be called /WOOT, and will
51                 // call handle_woot when triggered, the
52                 // 0 in the modes parameter signifies that
53                 // anyone can issue the command, and the
54                 // command takes only one parameter.
55                 Srv->AddCommand("WOOT",handle_woot,0,1);
56
57                 // Add a mode +Z for channels with no parameters                
58                 Srv->AddExtendedMode('Z',MT_CHANNEL,false,1,0);
59         }
60         
61         virtual bool OnExtendedMode(userrec* user, chanrec* chan, char modechar, int type, bool mode_on, string_list &params)
62         {
63                 if ((modechar != 'Z') || (type != MT_CHANNEL)) {
64                         // this mode isn't ours, we have to bail and return 0 to not handle it.
65                         Srv->Log(DEBUG,"Extended mode event triggered, but this is not a mode i've claimed!");
66                         return 0;
67                 }
68                 
69                 
70                 if (mode_on) {
71                         Srv->Log(DEBUG,"Custom mode is being added to channel");
72                 }
73                 else {
74                         Srv->Log(DEBUG,"Custom mode is being taken from a channel");
75                 }
76                 Srv->Log(DEBUG,chan->name);
77                 
78                 // must return 1 to handle the mode!
79                 return 1;
80         }
81         
82         virtual void OnUserJoin(userrec* user, chanrec* channel)
83         {
84                 Srv->Log(DEBUG,"OnUserJoin triggered");
85                 if (channel->IsCustomModeSet('Z'))
86                 {
87                         std::string param = channel->GetModeParameter('Z');
88                         Srv->Log(DEBUG,"Custom mode is set on this channel! Parameter="+param);
89                 }
90         }
91         
92         virtual ~ModuleTestCommand()
93         {
94                 delete Srv;
95         }
96         
97         virtual Version GetVersion()
98         {
99                 return Version(1,0,0,0);
100         }
101         
102         virtual void OnUserConnect(userrec* user)
103         {
104         }
105
106 };
107
108
109 class ModuleTestCommandFactory : public ModuleFactory
110 {
111  public:
112         ModuleTestCommandFactory()
113         {
114         }
115         
116         ~ModuleTestCommandFactory()
117         {
118         }
119         
120         virtual Module * CreateModule()
121         {
122                 return new ModuleTestCommand;
123         }
124         
125 };
126
127
128 extern "C" void * init_module( void )
129 {
130         return new ModuleTestCommandFactory;
131 }
132