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