1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 #include "commands/cmd_whois.h"
16 #include "commands/cmd_stats.h"
20 #include "transport.h"
21 #include "socketengine.h"
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"
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 */
33 bool TreeSocket::HandleSetTime(const std::string &prefix, std::deque<std::string> ¶ms)
35 if (!params.size() || !Utils->EnableTimeSync)
40 if ((params.size() == 2) && (params[1] == "FORCE"))
43 time_t them = atoi(params[0].c_str());
44 time_t us = Instance->Time(false);
46 time_t diff = them - us;
48 Utils->DoOneToAllButSender(prefix, "TIMESET", params, prefix);
50 if (force || (them != us))
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);
59 bool TreeSocket::Time(const std::string &prefix, std::deque<std::string> ¶ms)
61 // :source.server TIME remote.server sendernick
62 // :remote.server TIME source.server sendernick TS
63 if (params.size() == 2)
65 // someone querying our time?
66 if (this->Instance->Config->ServerName == params[0] || this->Instance->Config->GetSID() == params[0])
68 User* u = this->Instance->FindNick(params[1]);
71 params.push_back(ConvToStr(Instance->Time(false)));
73 Utils->DoOneToOne(this->Instance->Config->GetSID(),"TIME",params,params[0]);
79 User* u = this->Instance->FindNick(params[1]);
81 Utils->DoOneToOne(prefix,"TIME",params,params[0]);
84 else if (params.size() == 3)
86 // a response to a previous TIME
87 User* u = this->Instance->FindNick(params[1]);
88 if ((u) && (IS_LOCAL(u)))
90 time_t rawtime = atol(params[2].c_str());
92 timeinfo = localtime(&rawtime);
94 snprintf(tms,26,"%s",asctime(timeinfo));
96 u->WriteServ("391 %s %s :%s",u->nick,prefix.c_str(),tms);
101 Utils->DoOneToOne(prefix,"TIME",params,u->server);