]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/time.cpp
006260a8951d5adb7b9984d95882f3842f67ed3a
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / time.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 "commands/cmd_whois.h"
16 #include "commands/cmd_stats.h"
17 #include "socket.h"
18 #include "xline.h"
19 #include "../transport.h"
20 #include "socketengine.h"
21
22 #include "main.h"
23 #include "utils.h"
24 #include "treeserver.h"
25 #include "treesocket.h"
26
27 /* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
28
29 bool TreeSocket::Time(const std::string &prefix, std::deque<std::string> &params)
30 {
31         // :source.server TIME remote.server sendernick
32         // :remote.server TIME source.server sendernick TS
33         if (params.size() == 2)
34         {
35                 // someone querying our time?
36                 if (this->ServerInstance->Config->ServerName == params[0] || this->ServerInstance->Config->GetSID() == params[0])
37                 {
38                         User* u = this->ServerInstance->FindNick(params[1]);
39                         if (u)
40                         {
41                                 params.push_back(ConvToStr(ServerInstance->Time()));
42                                 params[0] = prefix;
43                                 Utils->DoOneToOne(this->ServerInstance->Config->GetSID(),"TIME",params,params[0]);
44                         }
45                 }
46                 else
47                 {
48                         // not us, pass it on
49                         User* u = this->ServerInstance->FindNick(params[1]);
50                         if (u)
51                                 Utils->DoOneToOne(prefix,"TIME",params,params[0]);
52                 }
53         }
54         else if (params.size() == 3)
55         {
56                 // a response to a previous TIME
57                 User* u = this->ServerInstance->FindNick(params[1]);
58                 if ((u) && (IS_LOCAL(u)))
59                 {
60                         std::string sourceserv = Utils->FindServer(prefix)->GetName();
61                         time_t rawtime = atol(params[2].c_str());
62                         struct tm * timeinfo;
63                         timeinfo = localtime(&rawtime);
64                         char tms[26];
65                         snprintf(tms,26,"%s",asctime(timeinfo));
66                         tms[24] = 0;
67                         u->WriteNumeric(RPL_TIME, "%s %s :%s",u->nick.c_str(),sourceserv.c_str(),tms);
68                 }
69                 else
70                 {
71                         if (u)
72                                 Utils->DoOneToOne(prefix,"TIME",params,u->server);
73                 }
74         }
75         return true;
76 }
77