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