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