]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_rpctest.cpp
146eabacf54a073b573a2392b04a5947298cb6cb
[user/henk/code/inspircd.git] / src / modules / m_rpctest.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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 "rpc.h"
16
17 /* $ModDesc: A test of the RPC API */
18 /* $ModDep: rpc.h */
19
20 class ModuleRPCTest : public Module
21 {
22  private:
23
24  public:
25         ModuleRPCTest(InspIRCd *Me) : Module(Me)
26         {
27                 Implementation eventlist[] = { I_OnEvent };
28                 ServerInstance->Modules->Attach(eventlist, this, 1);
29         }
30
31         virtual ~ModuleRPCTest()
32         {
33         }
34
35         virtual Version GetVersion()
36         {
37                 return Version("A test of the RPC API", VF_VENDOR, API_VERSION);
38         }
39
40
41         virtual void OnEvent(Event *ev)
42         {
43                 if (ev->GetEventID() == "RPCMethod")
44                 {
45                         RPCRequest *req = (RPCRequest*) ev->GetData();
46
47                         if (req->method == "test.echo")
48                         {
49                                 req->claimed = true;
50                                 if (req->parameters->ArraySize() < 1)
51                                 {
52                                         req->error = "Insufficient parameters";
53                                         return;
54                                 }
55
56                                 req->result->SetString(req->parameters->GetArray(0)->GetString());
57                         }
58                 }
59         }
60 };
61
62 MODULE_INIT(ModuleRPCTest)
63