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