]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_testclient.cpp
A few more I missed.
[user/henk/code/inspircd.git] / src / modules / extra / m_testclient.cpp
index a867dad203947c1a351618fccce1f821f5f63bfb..f4e58b7b5969cbee5810b759585c3c129d47ac95 100644 (file)
@@ -1 +1,110 @@
-/*       +------------------------------------+\r *       | Inspire Internet Relay Chat Daemon |\r *       +------------------------------------+\r *\r *  InspIRCd: (C) 2002-2007 InspIRCd Development Team\r * See: http://www.inspircd.org/wiki/index.php/Credits\r *\r * This program is free but copyrighted software; see\r *            the file COPYING for details.\r *\r * ---------------------------------------------------\r */\r\r#include "inspircd.h"\r#include "users.h"\r#include "channels.h"\r#include "modules.h"\r#include "configreader.h"\r#include "m_sqlv2.h"\r\rclass ModuleTestClient : public Module\r{\rprivate:\r     \r\rpublic:\r      ModuleTestClient(InspIRCd* Me)\r         : Module::Module(Me)\r   {\r      }\r\r     void Implements(char* List)\r    {\r              List[I_OnRequest] = List[I_OnBackgroundTimer] = 1;\r     }\r              \r       virtual Version GetVersion()\r   {\r              return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);\r    }\r      \r       virtual void OnBackgroundTimer(time_t foo)\r     {\r              Module* target = ServerInstance->FindFeature("SQL");\r           \r               if(target)\r             {\r                      SQLrequest foo = SQLreq(this, target, "foo", "UPDATE rawr SET foo = '?' WHERE bar = 42", ConvToStr(time(NULL)));\r                       \r                       if(foo.Send())\r                 {\r                              ServerInstance->Log(DEBUG, "Sent query, got given ID %lu", foo.id);\r                    }\r                      else\r                   {\r                              ServerInstance->Log(DEBUG, "SQLrequest failed: %s", foo.error.Str());\r                  }\r              }\r      }\r      \r       virtual char* OnRequest(Request* request)\r      {\r              if(strcmp(SQLRESID, request->GetId()) == 0)\r            {\r                      ServerInstance->Log(DEBUG, "Got SQL result (%s)", request->GetId());\r           \r                       SQLresult* res = (SQLresult*)request;\r\r                 if (res->error.Id() == NO_ERROR)\r                       {\r                              if(res->Cols())\r                                {\r                                      ServerInstance->Log(DEBUG, "Got result with %d rows and %d columns", res->Rows(), res->Cols());\r\r                                       for (int r = 0; r < res->Rows(); r++)\r                                  {\r                                              ServerInstance->Log(DEBUG, "Row %d:", r);\r                                              \r                                               for(int i = 0; i < res->Cols(); i++)\r                                           {\r                                                      ServerInstance->Log(DEBUG, "\t[%s]: %s", res->ColName(i).c_str(), res->GetValue(r, i).d.c_str());\r                                              }\r                                      }\r                              }\r                              else\r                           {\r                                      ServerInstance->Log(DEBUG, "%d rows affected in query", res->Rows());\r                          }\r                      }\r                      else\r                   {\r                              ServerInstance->Log(DEBUG, "SQLrequest failed: %s", res->error.Str());\r                         \r                       }\r              \r                       return SQLSUCCESS;\r             }\r              \r               ServerInstance->Log(DEBUG, "Got unsupported API version string: %s", request->GetId());\r                \r               return NULL;\r   }\r      \r       virtual ~ModuleTestClient()\r    {\r      }       \r};\r\rMODULE_INIT(ModuleTestClient);\r\r
\ No newline at end of file
+/*       +------------------------------------+
+ *       | Inspire Internet Relay Chat Daemon |
+ *       +------------------------------------+
+ *
+ *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
+ * This program is free but copyrighted software; see
+ *            the file COPYING for details.
+ *
+ * ---------------------------------------------------
+ */
+
+#include "inspircd.h"
+#include "users.h"
+#include "channels.h"
+#include "modules.h"
+#include "configreader.h"
+#include "m_sqlv2.h"
+
+class ModuleTestClient : public Module
+{
+private:
+       
+
+public:
+       ModuleTestClient(InspIRCd* Me)
+               : Module::Module(Me)
+       {
+       }
+
+       void Implements(char* List)
+       {
+               List[I_OnRequest] = List[I_OnBackgroundTimer] = 1;
+       }
+               
+       virtual Version GetVersion()
+       {
+               return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
+       }
+       
+       virtual void OnBackgroundTimer(time_t foo)
+       {
+               Module* target = ServerInstance->FindFeature("SQL");
+               
+               if(target)
+               {
+                       SQLrequest foo = SQLreq(this, target, "foo", "UPDATE rawr SET foo = '?' WHERE bar = 42", ConvToStr(time(NULL)));
+                       
+                       if(foo.Send())
+                       {
+                               ServerInstance->Log(DEBUG, "Sent query, got given ID %lu", foo.id);
+                       }
+                       else
+                       {
+                               ServerInstance->Log(DEBUG, "SQLrequest failed: %s", foo.error.Str());
+                       }
+               }
+       }
+       
+       virtual char* OnRequest(Request* request)
+       {
+               if(strcmp(SQLRESID, request->GetId()) == 0)
+               {
+                       ServerInstance->Log(DEBUG, "Got SQL result (%s)", request->GetId());
+               
+                       SQLresult* res = (SQLresult*)request;
+
+                       if (res->error.Id() == NO_ERROR)
+                       {
+                               if(res->Cols())
+                               {
+                                       ServerInstance->Log(DEBUG, "Got result with %d rows and %d columns", res->Rows(), res->Cols());
+
+                                       for (int r = 0; r < res->Rows(); r++)
+                                       {
+                                               ServerInstance->Log(DEBUG, "Row %d:", r);
+                                               
+                                               for(int i = 0; i < res->Cols(); i++)
+                                               {
+                                                       ServerInstance->Log(DEBUG, "\t[%s]: %s", res->ColName(i).c_str(), res->GetValue(r, i).d.c_str());
+                                               }
+                                       }
+                               }
+                               else
+                               {
+                                       ServerInstance->Log(DEBUG, "%d rows affected in query", res->Rows());
+                               }
+                       }
+                       else
+                       {
+                               ServerInstance->Log(DEBUG, "SQLrequest failed: %s", res->error.Str());
+                               
+                       }
+               
+                       return SQLSUCCESS;
+               }
+               
+               ServerInstance->Log(DEBUG, "Got unsupported API version string: %s", request->GetId());
+               
+               return NULL;
+       }
+       
+       virtual ~ModuleTestClient()
+       {
+       }       
+};
+
+MODULE_INIT(ModuleTestClient);
+