]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_testcommand.cpp
Fixed bug #85
[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(Server* Me)
52                 : Module::Module(Me)
53         {
54                 Srv = Me;
55                 // Create a new command:
56                 // command will be called /WOOT, and will
57                 // call handle_woot when triggered, the
58                 // 0 in the modes parameter signifies that
59                 // anyone can issue the command, and the
60                 // command takes only one parameter.
61                 Srv->AddCommand("WOOT",handle_woot,0,0,"m_testcommand.so");
62
63                 // Add a mode +Z for channels with no parameters                
64                 Srv->AddExtendedMode('Z',MT_CHANNEL,false,1,0);
65         }
66         
67         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
68         {
69                 
70                 if ((modechar != 'Z') || (type != MT_CHANNEL))
71                 {
72                         // this mode isn't ours, we have to bail and return 0 to not handle it.
73                         Srv->Log(DEBUG,"Extended mode event triggered, but this is not a mode i've claimed!");
74                         return 0;
75                 }
76                 
77                 chanrec* chan = (chanrec*)target;
78                 
79                 if (mode_on)
80                 {
81                         Srv->Log(DEBUG,"Custom mode is being added to channel");
82                         Srv->Log(DEBUG,chan->name);
83                 }
84                 else
85                 {
86                         Srv->Log(DEBUG,"Custom mode is being taken from a channel");
87                         Srv->Log(DEBUG,chan->name);
88                 }
89
90                 // must return 1 to handle the mode!
91                 return 1;
92         }
93         
94         virtual void OnUserJoin(userrec* user, chanrec* channel)
95         {
96                 Srv->Log(DEBUG,"OnUserJoin triggered");
97                 if (channel->IsCustomModeSet('Z'))
98                 {
99                         std::string param = channel->GetModeParameter('Z');
100                         Srv->Log(DEBUG,"Custom mode is set on this channel! Parameter="+param);
101                 }
102         }
103         
104         virtual ~ModuleTestCommand()
105         {
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(Server* Me)
132         {
133                 return new ModuleTestCommand(Me);
134         }
135         
136 };
137
138
139 extern "C" void * init_module( void )
140 {
141         return new ModuleTestCommandFactory;
142 }
143