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