]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_testcommand.cpp
Inherit m_filter.cpp and m_filter_pcre.cpp from a base set of classes, so that change...
[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         /* Command 'woot', takes no parameters and needs no special modes */
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                 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                 newcommand = new cmd_woot(ServerInstance);
91                 ServerInstance->AddCommand(newcommand);
92         }
93
94         void Implements(char* List)
95         {
96                 List[I_OnUserJoin] = 1;
97         }
98
99         virtual void OnUserJoin(userrec* user, chanrec* channel)
100         {
101                 /* This is an example, we do nothing here */
102         }
103         
104         virtual ~ModuleTestCommand()
105         {
106                 delete newcommand;
107         }
108
109         virtual Version GetVersion()
110         {
111                 return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
112         }
113 };
114
115
116 class ModuleTestCommandFactory : public ModuleFactory
117 {
118  public:
119         ModuleTestCommandFactory()
120         {
121         }
122         
123         ~ModuleTestCommandFactory()
124         {
125         }
126         
127         virtual Module * CreateModule(InspIRCd* Me)
128         {
129                 return new ModuleTestCommand(Me);
130         }
131         
132 };
133
134
135 extern "C" void * init_module( void )
136 {
137         return new ModuleTestCommandFactory;
138 }
139