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