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