]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_testcommand.cpp
Made SANICK not collide the user (theres no need to in the new 1.1 now we have return...
[user/henk/code/inspircd.git] / src / modules / m_testcommand.cpp
index 53414424d5b7c2102d30476f1d17a8f962fdae86..bc268c34b86307bf965552ba4d138ac72d0fc9dd 100644 (file)
@@ -20,43 +20,62 @@ using namespace std;
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
-#include "helperfuncs.h"
+
 #include "dns.h"
+#include "inspircd.h"
 
 /* $ModDesc: Povides a proof-of-concept test /WOOT command */
 
-class MyResolver : public Resolver
+
+
+class MyV6Resolver : public Resolver
 {
+       bool fw;
  public:
-       MyResolver(const std::string &source, bool forward, const std::string &dnsserver = "") : Resolver(source, forward, dnsserver) { }
+       MyV6Resolver(const std::string &source, bool forward) : Resolver(ServerInstance, source, forward ? DNS_QUERY_AAAA : DNS_QUERY_PTR6)
+       {
+               fw = forward;
+       }
 
        virtual void OnLookupComplete(const std::string &result)
        {
-               log(DEBUG,"*** RESOLVER COMPLETED LOOKUP, IP IS: '%s'",result.c_str());
+               ServerInstance->Log(DEBUG,"*** RESOLVER COMPLETED %s LOOKUP, IP IS: '%s'",fw ? "FORWARD" : "REVERSE", result.c_str());
        }
 
-       virtual void OnError(ResolverError e)
+       virtual void OnError(ResolverError e, const std::string &errormessage)
        {
-               log(DEBUG,"*** RESOLVER GOT ERROR: %d",e);
+               ServerInstance->Log(DEBUG,"*** RESOLVER GOT ERROR: %d: %s",e,errormessage.c_str());
        }
 };
 
-static Server *Srv;
+
         
 class cmd_woot : public command_t
 {
  public:
-       cmd_woot () : command_t("WOOT", 0, 0)
+       cmd_woot (InspIRCd* Instance) : command_t(Instance,"WOOT", 0, 0)
        {
                this->source = "m_testcommand.so";
        }
 
-       void Handle (char **parameters, int pcnt, userrec *user)
+       CmdResult Handle (const char** parameters, int pcnt, userrec *user)
        {
                /* We dont have to worry about deleting 'r', the core will
                 * do it for us as required.*/
-               MyResolver* r = new MyResolver("brainbox.ath.cx", true);
-               Srv->AddResolver(r);
+
+               try
+               {
+                       MyV6Resolver* r = new MyV6Resolver("shake.stacken.kth.se", true);
+                       ServerInstance->AddResolver(r);
+                       r = new MyV6Resolver("2001:6b0:1:ea:202:a5ff:fecd:13a6", false);
+                       ServerInstance->AddResolver(r);
+               }
+               catch (ModuleException& e)
+               {
+                       ServerInstance->Log(DEBUG,"Danger, will robinson! There was an exception: %s",e.GetReason());
+               }
+
+               return CMD_FAILURE;
        }
 };
 
@@ -64,18 +83,18 @@ class ModuleTestCommand : public Module
 {
        cmd_woot* newcommand;
  public:
-       ModuleTestCommand(Server* Me)
+       ModuleTestCommand(InspIRCd* Me)
                : Module::Module(Me)
        {
-               Srv = Me;
+               
                // Create a new command:
                // command will be called /WOOT, and will
                // call handle_woot when triggered, the
                // 0 in the modes parameter signifies that
                // anyone can issue the command, and the
                // command takes only one parameter.
-               newcommand = new cmd_woot();
-               Srv->AddCommand(newcommand);
+               newcommand = new cmd_woot(ServerInstance);
+               ServerInstance->AddCommand(newcommand);
        }
 
        void Implements(char* List)
@@ -93,7 +112,7 @@ class ModuleTestCommand : public Module
        
        virtual Version GetVersion()
        {
-               return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
+               return Version(1, 0, 0, 0, VF_VENDOR);
        }
 };
 
@@ -109,7 +128,7 @@ class ModuleTestCommandFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule(Server* Me)
+       virtual Module * CreateModule(InspIRCd* Me)
        {
                return new ModuleTestCommand(Me);
        }