]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_alltime.cpp
Added <oper:swhois> to m_swhois, which will override <type:swhois> if specified
[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                 // I'm too lazy to add a function to fetch the delta, so lets just cheat..
28                 int delta = time(NULL) - now;
29                 
30                 string msg = ":" + string(ServerInstance->Config->ServerName) + " NOTICE " + user->nick + " :Time for " +
31                         ServerInstance->Config->ServerName + " is: " + fmtdate + " (delta " + ConvToStr(delta) + " seconds)";
32                 
33                 if (IS_LOCAL(user))
34                 {
35                         user->Write(msg);
36                 }
37                 else
38                 {
39                         deque<string> params;
40                         params.push_back(user->nick);
41                         params.push_back(msg);
42                         Event ev((char *) &params, NULL, "send_push");
43                         ev.Send(ServerInstance);
44                 }
45                 
46                 return CMD_SUCCESS;
47         }
48 };
49
50 class Modulealltime : public Module
51 {
52         cmd_alltime *mycommand;
53  public:
54         Modulealltime(InspIRCd *Me)
55                 : Module::Module(Me)
56         {
57                 mycommand = new cmd_alltime(ServerInstance);
58                 ServerInstance->AddCommand(mycommand);
59         }
60         
61         virtual ~Modulealltime()
62         {
63         }
64         
65         virtual Version GetVersion()
66         {
67                 return Version(1, 0, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
68         }
69         
70 };
71
72 class ModulealltimeFactory : public ModuleFactory
73 {
74  public:
75         ModulealltimeFactory()
76         {
77         }
78         
79         ~ModulealltimeFactory()
80         {
81         }
82         
83         virtual Module *CreateModule(InspIRCd *Me)
84         {
85                 return new Modulealltime(Me);
86         }
87 };
88
89
90 extern "C" void *init_module(void)
91 {
92         return new ModulealltimeFactory;
93 }