]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_testcommand.cpp
Note: FOR THE MOMENT, this is BROKEN. It wont run right until im done.
[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 #include "inspircd.h"
26
27 /* $ModDesc: Povides a proof-of-concept test /WOOT command */
28
29 extern InspIRCd* ServerInstance;
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                 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                 log(DEBUG,"*** RESOLVER GOT ERROR: %d: %s",e,errormessage.c_str());
48         }
49 };
50
51 static Server *Srv;
52          
53 class cmd_woot : public command_t
54 {
55  public:
56         cmd_woot () : command_t("WOOT", 0, 0)
57         {
58                 this->source = "m_testcommand.so";
59         }
60
61         void 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                         Srv->AddResolver(r);
70                         r = new MyV6Resolver("2001:6b0:1:ea:202:a5ff:fecd:13a6", false);
71                         Srv->AddResolver(r);
72                 }
73                 catch (ModuleException& e)
74                 {
75                         log(DEBUG,"Danger, will robinson! There was an exception: %s",e.GetReason());
76                 }
77         }
78 };
79
80 class ModuleTestCommand : public Module
81 {
82         cmd_woot* newcommand;
83  public:
84         ModuleTestCommand(InspIRCd* Me)
85                 : Module::Module(Me)
86         {
87                 
88                 // Create a new command:
89                 // command will be called /WOOT, and will
90                 // call handle_woot when triggered, the
91                 // 0 in the modes parameter signifies that
92                 // anyone can issue the command, and the
93                 // command takes only one parameter.
94                 newcommand = new cmd_woot();
95                 Srv->AddCommand(newcommand);
96         }
97
98         void Implements(char* List)
99         {
100                 List[I_OnUserJoin] = 1;
101         }
102
103         virtual void OnUserJoin(userrec* user, chanrec* channel)
104         {
105         }
106         
107         virtual ~ModuleTestCommand()
108         {
109         }
110         
111         virtual Version GetVersion()
112         {
113                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
114         }
115 };
116
117
118 class ModuleTestCommandFactory : public ModuleFactory
119 {
120  public:
121         ModuleTestCommandFactory()
122         {
123         }
124         
125         ~ModuleTestCommandFactory()
126         {
127         }
128         
129         virtual Module * CreateModule(InspIRCd* Me)
130         {
131                 return new ModuleTestCommand(Me);
132         }
133         
134 };
135
136
137 extern "C" void * init_module( void )
138 {
139         return new ModuleTestCommandFactory;
140 }
141