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