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