]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_testcommand.cpp
a32559c68521a44b0bf22627fa3626ed37d28010
[user/henk/code/inspircd.git] / src / modules / m_testcommand.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "users.h"
16 #include "channels.h"
17 #include "modules.h"
18 #include "dns.h"
19
20 /* $ModDesc: Povides a proof-of-concept test /WOOT command */
21
22 /** A test resolver class for IPV6
23  */
24 class MyV6Resolver : public Resolver
25 {
26         bool fw;
27  public:
28         MyV6Resolver(InspIRCd* Instance, Module* me, const std::string &source, bool forward, bool &cached) : Resolver(Instance, source, forward ? DNS_QUERY_AAAA : DNS_QUERY_PTR6, cached, me)
29         {
30                 fw = forward;
31         }
32
33         virtual void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
34         {
35                 ServerInstance->Log(DEBUG,"*** RESOLVER COMPLETED %s LOOKUP, IP IS: '%s' TTL=%lu CACHED=%d",fw ? "FORWARD" : "REVERSE", result.c_str(), ttl, cached);
36         }
37
38         virtual void OnError(ResolverError e, const std::string &errormessage)
39         {
40                 ServerInstance->Log(DEBUG,"*** RESOLVER GOT ERROR: %d: %s",e,errormessage.c_str());
41         }
42 };
43
44 /** Handle /WOOT
45  */
46 class cmd_woot : public command_t
47 {
48         Module* Creator;
49  public:
50         /* Command 'woot', takes no parameters and needs no special modes */
51         cmd_woot (InspIRCd* Instance, Module* maker) : command_t(Instance,"WOOT", 0, 0), Creator(maker)
52         {
53                 this->source = "m_testcommand.so";
54         }
55
56         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
57         {
58                 /* We dont have to worry about deleting 'r', the core will
59                  * do it for us as required.*/
60                 try
61                 {
62                         bool cached;
63                         MyV6Resolver* r = new MyV6Resolver(ServerInstance, Creator, "shake.stacken.kth.se", true, cached);
64                         ServerInstance->AddResolver(r, cached);
65                         r = new MyV6Resolver(ServerInstance, Creator, "2001:6b0:1:ea:202:a5ff:fecd:13a6", false, cached);
66                         ServerInstance->AddResolver(r, cached);
67                 }
68                 catch (ModuleException& e)
69                 {
70                         ServerInstance->Log(DEBUG,"Danger, will robinson! There was an exception: %s",e.GetReason());
71                 }
72
73                 return CMD_FAILURE;
74         }
75 };
76
77 class ModuleTestCommand : public Module
78 {
79         cmd_woot* newcommand;
80  public:
81         ModuleTestCommand(InspIRCd* Me)
82                 : Module(Me)
83         {
84                 
85                 // Create a new command
86                 newcommand = new cmd_woot(ServerInstance, this);
87                 ServerInstance->AddCommand(newcommand);
88         }
89
90         void Implements(char* List)
91         {
92         }
93
94         virtual ~ModuleTestCommand()
95         {
96                 delete newcommand;
97         }
98
99         virtual Version GetVersion()
100         {
101                 return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
102         }
103 };
104
105
106 class ModuleTestCommandFactory : public ModuleFactory
107 {
108  public:
109         ModuleTestCommandFactory()
110         {
111         }
112         
113         ~ModuleTestCommandFactory()
114         {
115         }
116         
117         virtual Module * CreateModule(InspIRCd* Me)
118         {
119                 return new ModuleTestCommand(Me);
120         }
121         
122 };
123
124
125 extern "C" DllExport void * init_module( void )
126 {
127         return new ModuleTestCommandFactory;
128 }
129