]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_alltime.cpp
Header rearrangement, move inspircd.h to top, remove stdio, stdlib, stdblahblah that...
[user/henk/code/inspircd.git] / src / modules / m_alltime.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 "modules.h"
16
17 /* $ModDesc: Display timestamps from all servers connected to the network */
18
19 class cmd_alltime : public command_t
20 {
21  public:
22         cmd_alltime(InspIRCd *Instance) : command_t(Instance, "ALLTIME", 'o', 0)
23         {
24                 this->source = "m_alltime.so";
25                 syntax = "";
26         }
27
28         CmdResult Handle(const char **parameters, int pcnt, userrec *user)
29         {
30                 char fmtdate[64];
31                 char fmtdate2[64];
32                 time_t now = ServerInstance->Time(false);
33                 strftime(fmtdate, sizeof(fmtdate), "%F %T", gmtime(&now));
34                 now = ServerInstance->Time(true);
35                 strftime(fmtdate2, sizeof(fmtdate2), "%F %T", gmtime(&now));
36                 
37                 int delta = ServerInstance->GetTimeDelta();
38                 
39                 string msg = ":" + string(ServerInstance->Config->ServerName) + " NOTICE " + user->nick + " :System time for " +
40                         ServerInstance->Config->ServerName + " is: " + fmtdate + " (delta " + ConvToStr(delta) + " seconds): Time with delta: "+ fmtdate2;
41                 
42                 if (IS_LOCAL(user))
43                 {
44                         user->Write(msg);
45                 }
46                 else
47                 {
48                         deque<string> params;
49                         params.push_back(user->nick);
50                         params.push_back(msg);
51                         Event ev((char *) &params, NULL, "send_push");
52                         ev.Send(ServerInstance);
53                 }
54
55                 /* we want this routed out! */
56                 return CMD_SUCCESS;
57         }
58 };
59
60 class Modulealltime : public Module
61 {
62         cmd_alltime *mycommand;
63  public:
64         Modulealltime(InspIRCd *Me)
65                 : Module(Me)
66         {
67                 mycommand = new cmd_alltime(ServerInstance);
68                 ServerInstance->AddCommand(mycommand);
69         }
70         
71         virtual ~Modulealltime()
72         {
73         }
74         
75         virtual Version GetVersion()
76         {
77                 return Version(1, 0, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
78         }
79         
80 };
81
82 class ModulealltimeFactory : public ModuleFactory
83 {
84  public:
85         ModulealltimeFactory()
86         {
87         }
88         
89         ~ModulealltimeFactory()
90         {
91         }
92         
93         virtual Module *CreateModule(InspIRCd *Me)
94         {
95                 return new Modulealltime(Me);
96         }
97 };
98
99
100 extern "C" DllExport void *init_module(void)
101 {
102         return new ModulealltimeFactory;
103 }