]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_testcommand.cpp
6d8b7a2f69f8d9174960f2424c1b65699bb1f6a2
[user/henk/code/inspircd.git] / src / modules / m_testcommand.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 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 #include "dns.h"
24
25 /* $ModDesc: Povides a proof-of-concept test /WOOT command */
26
27 class MyResolver : public Resolver
28 {
29  public:
30         MyResolver(const std::string &source, bool forward, const std::string &dnsserver = "") : Resolver(source, forward, dnsserver) { }
31
32         virtual void OnLookupComplete(const std::string &result)
33         {
34                 log(DEBUG,"*** RESOLVER COMPLETED LOOKUP, IP IS: '%s'",result.c_str());
35         }
36
37         virtual void OnError(ResolverError e)
38         {
39                 log(DEBUG,"*** RESOLVER GOT ERROR: %d",e);
40         }
41 };
42
43 static Server *Srv;
44          
45 class cmd_woot : public command_t
46 {
47  public:
48         cmd_woot () : command_t("WOOT", 0, 0)
49         {
50                 this->source = "m_testcommand.so";
51         }
52
53         void Handle (char **parameters, int pcnt, userrec *user)
54         {
55                 /* We dont have to worry about deleting 'r', the core will
56                  * do it for us as required.*/
57                 MyResolver* r = new MyResolver("brainbox.ath.cx", true);
58                 Srv->AddResolver(r);
59         }
60 };
61
62 class ModuleTestCommand : public Module
63 {
64         cmd_woot* newcommand;
65  public:
66         ModuleTestCommand(Server* Me)
67                 : Module::Module(Me)
68         {
69                 Srv = Me;
70                 // Create a new command:
71                 // command will be called /WOOT, and will
72                 // call handle_woot when triggered, the
73                 // 0 in the modes parameter signifies that
74                 // anyone can issue the command, and the
75                 // command takes only one parameter.
76                 newcommand = new cmd_woot();
77                 Srv->AddCommand(newcommand);
78         }
79
80         void Implements(char* List)
81         {
82                 List[I_OnUserJoin] = 1;
83         }
84
85         virtual void OnUserJoin(userrec* user, chanrec* channel)
86         {
87         }
88         
89         virtual ~ModuleTestCommand()
90         {
91         }
92         
93         virtual Version GetVersion()
94         {
95                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
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(Server* Me)
112         {
113                 return new ModuleTestCommand(Me);
114         }
115         
116 };
117
118
119 extern "C" void * init_module( void )
120 {
121         return new ModuleTestCommandFactory;
122 }
123