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