]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/extra/m_testclient.cpp
Dont echo the JOIN to the user whos speaking
[user/henk/code/inspircd.git] / src / modules / extra / m_testclient.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 "inspircd.h"
15 #include "users.h"
16 #include "channels.h"
17 #include "modules.h"
18 #include "configreader.h"
19 #include "m_sqlv2.h"
20
21 class ModuleTestClient : public Module
22 {
23 private:
24         
25
26 public:
27         ModuleTestClient(InspIRCd* Me)
28                 : Module::Module(Me)
29         {
30         }
31
32         void Implements(char* List)
33         {
34                 List[I_OnRequest] = List[I_OnBackgroundTimer] = 1;
35         }
36                 
37         virtual Version GetVersion()
38         {
39                 return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
40         }
41         
42         virtual void OnBackgroundTimer(time_t foo)
43         {
44                 Module* target = ServerInstance->Modules->FindFeature("SQL");
45                 
46                 if(target)
47                 {
48                         SQLrequest foo = SQLrequest(this, target, "foo",
49                                         SQLquery("UPDATE rawr SET foo = '?' WHERE bar = 42") % time(NULL));
50                         
51                         if(foo.Send())
52                         {
53                                 ServerInstance->Log(DEBUG, "Sent query, got given ID %lu", foo.id);
54                         }
55                         else
56                         {
57                                 ServerInstance->Log(DEBUG, "SQLrequest failed: %s", foo.error.Str());
58                         }
59                 }
60         }
61         
62         virtual char* OnRequest(Request* request)
63         {
64                 if(strcmp(SQLRESID, request->GetId()) == 0)
65                 {
66                         ServerInstance->Log(DEBUG, "Got SQL result (%s)", request->GetId());
67                 
68                         SQLresult* res = (SQLresult*)request;
69
70                         if (res->error.Id() == NO_ERROR)
71                         {
72                                 if(res->Cols())
73                                 {
74                                         ServerInstance->Log(DEBUG, "Got result with %d rows and %d columns", res->Rows(), res->Cols());
75
76                                         for (int r = 0; r < res->Rows(); r++)
77                                         {
78                                                 ServerInstance->Log(DEBUG, "Row %d:", r);
79                                                 
80                                                 for(int i = 0; i < res->Cols(); i++)
81                                                 {
82                                                         ServerInstance->Log(DEBUG, "\t[%s]: %s", res->ColName(i).c_str(), res->GetValue(r, i).d.c_str());
83                                                 }
84                                         }
85                                 }
86                                 else
87                                 {
88                                         ServerInstance->Log(DEBUG, "%d rows affected in query", res->Rows());
89                                 }
90                         }
91                         else
92                         {
93                                 ServerInstance->Log(DEBUG, "SQLrequest failed: %s", res->error.Str());
94                                 
95                         }
96                 
97                         return SQLSUCCESS;
98                 }
99                 
100                 ServerInstance->Log(DEBUG, "Got unsupported API version string: %s", request->GetId());
101                 
102                 return NULL;
103         }
104         
105         virtual ~ModuleTestClient()
106         {
107         }       
108 };
109
110 MODULE_INIT(ModuleTestClient)
111