]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_testcommand.cpp
9644209574f55d08ccfc28d7ab118863137ef3b0
[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                         // this mode isn't ours, we have to bail and return 0 to not handle it.
71                         Srv->Log(DEBUG,"Extended mode event triggered, but this is not a mode i've claimed!");
72                         return 0;
73                 }
74                 
75                 chanrec* chan = (chanrec*)target;
76                 
77                 if (mode_on) {
78                         Srv->Log(DEBUG,"Custom mode is being added to channel");
79                         Srv->Log(DEBUG,chan->name);
80                 }
81                 else {
82                         Srv->Log(DEBUG,"Custom mode is being taken from a channel");
83                         Srv->Log(DEBUG,chan->name);
84                 }
85
86                 // must return 1 to handle the mode!
87                 return 1;
88         }
89         
90         virtual void OnUserJoin(userrec* user, chanrec* channel)
91         {
92                 Srv->Log(DEBUG,"OnUserJoin triggered");
93                 if (channel->IsCustomModeSet('Z'))
94                 {
95                         std::string param = channel->GetModeParameter('Z');
96                         Srv->Log(DEBUG,"Custom mode is set on this channel! Parameter="+param);
97                 }
98         }
99         
100         virtual ~ModuleTestCommand()
101         {
102                 delete Srv;
103         }
104         
105         virtual Version GetVersion()
106         {
107                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
108         }
109         
110         virtual void OnUserConnect(userrec* user)
111         {
112         }
113
114 };
115
116
117 class ModuleTestCommandFactory : public ModuleFactory
118 {
119  public:
120         ModuleTestCommandFactory()
121         {
122         }
123         
124         ~ModuleTestCommandFactory()
125         {
126         }
127         
128         virtual Module * CreateModule()
129         {
130                 return new ModuleTestCommand;
131         }
132         
133 };
134
135
136 extern "C" void * init_module( void )
137 {
138         return new ModuleTestCommandFactory;
139 }
140