]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/time.cpp
Fix m_chanlog crashing.
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / time.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 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 "commands/cmd_whois.h"
16 #include "commands/cmd_stats.h"
17 #include "socket.h"
18 #include "wildcard.h"
19 #include "xline.h"
20 #include "transport.h"
21 #include "socketengine.h"
22
23 #include "m_spanningtree/main.h"
24 #include "m_spanningtree/utils.h"
25 #include "m_spanningtree/treeserver.h"
26 #include "m_spanningtree/link.h"
27 #include "m_spanningtree/treesocket.h"
28 #include "m_spanningtree/resolvers.h"
29 #include "m_spanningtree/handshaketimer.h"
30
31 /* $ModDep: m_spanningtree/timesynctimer.h m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h */
32
33 bool TreeSocket::HandleSetTime(const std::string &prefix, std::deque<std::string> &params)
34 {
35         if (!params.size() || !Utils->EnableTimeSync)
36                 return true;
37
38         bool force = false;
39
40         if ((params.size() == 2) && (params[1] == "FORCE"))
41                 force = true;
42
43         time_t them = atoi(params[0].c_str());
44         time_t us = Instance->Time(false);
45
46         time_t diff = them - us;
47
48         Utils->DoOneToAllButSender(prefix, "TIMESET", params, prefix);
49
50         if (force || (them != us))
51         {
52                 time_t old = Instance->SetTimeDelta(diff);
53                 Instance->Log(DEBUG, "TS (diff %d) from %s applied (old delta was %d)", diff, prefix.c_str(), old);
54         }
55
56         return true;
57 }
58
59 bool TreeSocket::Time(const std::string &prefix, std::deque<std::string> &params)
60 {
61         // :source.server TIME remote.server sendernick
62         // :remote.server TIME source.server sendernick TS
63         if (params.size() == 2)
64         {
65                 // someone querying our time?
66                 if (this->Instance->Config->ServerName == params[0] || this->Instance->Config->GetSID() == params[0])
67                 {
68                         User* u = this->Instance->FindNick(params[1]);
69                         if (u)
70                         {
71                                 params.push_back(ConvToStr(Instance->Time(false)));
72                                 params[0] = prefix;
73                                 Utils->DoOneToOne(this->Instance->Config->GetSID(),"TIME",params,params[0]);
74                         }
75                 }
76                 else
77                 {
78                         // not us, pass it on
79                         User* u = this->Instance->FindNick(params[1]);
80                         if (u)
81                                 Utils->DoOneToOne(prefix,"TIME",params,params[0]);
82                 }
83         }
84         else if (params.size() == 3)
85         {
86                 // a response to a previous TIME
87                 User* u = this->Instance->FindNick(params[1]);
88                 if ((u) && (IS_LOCAL(u)))
89                 {
90                         time_t rawtime = atol(params[2].c_str());
91                         struct tm * timeinfo;
92                         timeinfo = localtime(&rawtime);
93                         char tms[26];
94                         snprintf(tms,26,"%s",asctime(timeinfo));
95                         tms[24] = 0;
96                         u->WriteServ("391 %s %s :%s",u->nick,prefix.c_str(),tms);
97                 }
98                 else
99                 {
100                         if (u)
101                                 Utils->DoOneToOne(prefix,"TIME",params,u->server);
102                 }
103         }
104         return true;
105 }
106