]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_testcommand.cpp
ad7afbc9768cbeb4bf99de542b006d0e527bcda6
[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         // this test command just accepts:
15         // /woot :<text>
16         // and sends <text> to all opers with +s mode.
17         // NB: The ':' is *REQUIRED* otherwise the parser will
18         // split the line into multiple parameters[]!
19         //
20         // If you want to process all the line with no leading colon, you must 
21         // implement a parser here that assembles parameters[] to match the
22         // syntax of your command - the way it is done in the core is to meet
23         // rfc-compatibility.
24         Srv->SendOpers(parameters[0]);
25         
26
27         // Here is a sample of how to send servermodes. Note that unless remote
28         // servers in your net are u:lined, they may reverse this, but its a
29         // quick and effective modehack.
30         
31         // NOTE: DO NOT CODE LIKE THIS!!! This has no checks and can send
32         // invalid or plain confusing mode changes, code some checking!
33         char* modes[3];
34         modes[0] = "#chatspike";
35         modes[1] = "+o";
36         modes[2] = user->nick;
37         
38         // run the mode change, send numerics (such as "no such channel") back
39         // to "user".
40         Srv->SendMode(modes,3,user);
41 }
42
43 class ModuleTestCommand : public Module
44 {
45  public:
46         ModuleTestCommand()
47         {
48                 Srv = new Server;
49                 // Create a new command:
50                 // command will be called /WOOT, and will
51                 // call handle_woot when triggered, the
52                 // 0 in the modes parameter signifies that
53                 // anyone can issue the command, and the
54                 // command takes only one parameter.
55                 Srv->AddCommand("WOOT",handle_woot,0,1);
56         }
57         
58         virtual ~ModuleTestCommand()
59         {
60                 delete Srv;
61         }
62         
63         virtual Version GetVersion()
64         {
65                 return Version(1,0,0,0);
66         }
67         
68         virtual void OnUserConnect(userrec* user)
69         {
70         }
71
72 };
73
74
75 class ModuleTestCommandFactory : public ModuleFactory
76 {
77  public:
78         ModuleTestCommandFactory()
79         {
80         }
81         
82         ~ModuleTestCommandFactory()
83         {
84         }
85         
86         virtual Module * CreateModule()
87         {
88                 return new ModuleTestCommand;
89         }
90         
91 };
92
93
94 extern "C" void * init_module( void )
95 {
96         return new ModuleTestCommandFactory;
97 }
98