]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_alltime.cpp
Record compression ratio stats for a /stats char (this isnt finished yet)
[user/henk/code/inspircd.git] / src / modules / m_alltime.cpp
1 /* Written by Special (john@yarbbles.com) */
2
3 using namespace std;
4
5 #include <stdio.h>
6 #include <string>
7 #include "inspircd.h"
8 #include "modules.h"
9
10 /* $ModDesc: Display timestamps from all servers connected to the network */
11
12 class cmd_alltime : public command_t
13 {
14  public:
15         cmd_alltime(InspIRCd *Instance) : command_t(Instance, "ALLTIME", 'o', 0)
16         {
17                 this->source = "m_alltime.so";
18                 syntax = "";
19         }
20
21         CmdResult Handle(const char **parameters, int pcnt, userrec *user)
22         {
23                 char fmtdate[64];
24                 time_t now = ServerInstance->Time();
25                 strftime(fmtdate, sizeof(fmtdate), "%F %T", gmtime(&now));
26                 
27                 int delta = ServerInstance->GetTimeDelta();
28                 
29                 string msg = ":" + string(ServerInstance->Config->ServerName) + " NOTICE " + user->nick + " :Time for " +
30                         ServerInstance->Config->ServerName + " is: " + fmtdate + " (delta " + ConvToStr(delta) + " seconds)";
31                 
32                 if (IS_LOCAL(user))
33                 {
34                         user->Write(msg);
35                 }
36                 else
37                 {
38                         deque<string> params;
39                         params.push_back(user->nick);
40                         params.push_back(msg);
41                         Event ev((char *) &params, NULL, "send_push");
42                         ev.Send(ServerInstance);
43                 }
44                 
45                 return CMD_SUCCESS;
46         }
47 };
48
49 class Modulealltime : public Module
50 {
51         cmd_alltime *mycommand;
52  public:
53         Modulealltime(InspIRCd *Me)
54                 : Module::Module(Me)
55         {
56                 mycommand = new cmd_alltime(ServerInstance);
57                 ServerInstance->AddCommand(mycommand);
58         }
59         
60         virtual ~Modulealltime()
61         {
62         }
63         
64         virtual Version GetVersion()
65         {
66                 return Version(1, 0, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
67         }
68         
69 };
70
71 class ModulealltimeFactory : public ModuleFactory
72 {
73  public:
74         ModulealltimeFactory()
75         {
76         }
77         
78         ~ModulealltimeFactory()
79         {
80         }
81         
82         virtual Module *CreateModule(InspIRCd *Me)
83         {
84                 return new Modulealltime(Me);
85         }
86 };
87
88
89 extern "C" void *init_module(void)
90 {
91         return new ModulealltimeFactory;
92 }