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