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