2 * IRC - Internet Relay Chat, ircd/m_settime.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
6 * See file AUTHORS in IRC package for additional names of
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 1, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * m_functions execute protocol messages on this server:
29 * cptr is always NON-NULL, pointing to a *LOCAL* client
30 * structure (with an open socket connected!). This
31 * identifies the physical socket where the message
32 * originated (or which caused the m_function to be
33 * executed--some m_functions may call others...).
35 * sptr is the source of the message, defined by the
36 * prefix part of the message if present. If not
37 * or prefix not found, then sptr==cptr.
39 * (!IsServer(cptr)) => (cptr == sptr), because
40 * prefixes are taken *only* from servers...
43 * (sptr == cptr) => the message didn't
46 * (sptr != cptr && IsServer(sptr) means
47 * the prefix specified servername. (?)
49 * (sptr != cptr && !IsServer(sptr) means
50 * that message originated from a remote
55 * (!IsServer(sptr)) means that, sptr can safely
56 * taken as defining the target structure of the
57 * message in this server.
59 * *Always* true (if 'parse' and others are working correct):
61 * 1) sptr->from == cptr (note: cptr->from == cptr)
63 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
64 * *cannot* be a local connection, unless it's
65 * actually cptr!). [MyConnect(x) should probably
66 * be defined as (x == x->from) --msa ]
68 * parc number of variable parameter strings (if zero,
69 * parv is allowed to be NULL)
71 * parv a NULL terminated list of parameter pointers,
73 * parv[0], sender (prefix string), if not present
74 * this points to an empty string.
75 * parv[1]...parv[parc-1]
76 * pointers to additional parameters
77 * parv[parc] == NULL, *always*
79 * note: it is guaranteed that parv[0]..parv[parc-1] are all
87 #include "ircd_features.h"
88 #include "ircd_reply.h"
89 #include "ircd_snprintf.h"
90 #include "ircd_string.h"
103 * ms_settime - server message handler
105 * parv[0] = sender prefix
107 * parv[2] = server name (Only used when sptr is an Oper).
109 int ms_settime(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
113 static char tbuf[11];
116 if (parc < 2) /* verify argument count */
117 return need_more_params(sptr, "SETTIME");
119 t = atoi(parv[1]); /* convert time and compute delta */
123 if (t < OLDEST_TS || dt < -9000000)
125 if (IsServer(sptr)) /* protocol violation if it's from a server */
126 protocol_violation(sptr, "SETTIME: Bad value (%Tu, delta %ld)", t, dt);
128 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :SETTIME: Bad value (%Tu, "
129 "delta %d)", sptr, t, dt);
130 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :SETTIME: Bad value", sptr);
135 if (feature_bool(FEAT_RELIABLE_CLOCK))
137 ircd_snprintf(0, tbuf, sizeof(tbuf), "%Tu", TStime());
141 if (BadPtr(parv[2])) /* spam the network */
143 for (lp = cli_serv(&me)->down; lp; lp = lp->next)
144 if (cptr != lp->value.cptr)
145 sendcmdto_prio_one(sptr, CMD_SETTIME, lp->value.cptr, "%s", parv[1]);
149 if (hunt_server_prio_cmd(sptr, CMD_SETTIME, cptr, 1, "%s %C", 2, parc,
150 parv) != HUNTED_ISME)
152 /* If the destination was *not* me, but I'm RELIABLE_CLOCK and the
153 * delta is more than 30 seconds off, bounce back a corrected
156 if (feature_bool(FEAT_RELIABLE_CLOCK) && (dt > 30 || dt < -30))
157 sendcmdto_prio_one(&me, CMD_SETTIME, cptr, "%s %C", parv[1], cptr);
162 if (feature_bool(FEAT_RELIABLE_CLOCK))
164 /* don't apply settime--reliable */
165 if ((dt > 600) || (dt < -600))
166 sendcmdto_serv_butone(&me, CMD_DESYNCH, 0, ":Bad SETTIME from %s: %Tu "
167 "(delta %d)", cli_name(sptr), t, dt);
168 /* Let user know we're ignoring him */
171 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is not set %ld "
172 "seconds %s : RELIABLE_CLOCK is defined", sptr,
173 (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
176 else /* tell opers about time change */
178 sendto_opmask_butone(0, SNO_OLDSNO, "SETTIME from %s, clock is set %ld "
179 "seconds %s", cli_name(sptr), (dt < 0) ? -dt : dt,
180 (dt < 0) ? "forwards" : "backwards");
181 /* Apply time change... */
183 /* Let the issuing user know what we did... */
186 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is set %ld seconds %s",
187 sptr, (dt < 0) ? -dt : dt,
188 (dt < 0) ? "forwards" : "backwards");
196 * mo_settime - oper message handler
198 * parv[0] = sender prefix
200 * parv[2] = servername (Only used when sptr is an Oper).
202 int mo_settime(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
206 static char tbuf[11];
208 /* Must be a global oper */
210 return send_reply(sptr, ERR_NOPRIVILEGES);
212 if (parc < 2) /* verify argument count */
213 return need_more_params(sptr, "SETTIME");
215 if (parc == 2 && MyUser(sptr)) /* default to me */
216 parv[parc++] = cli_name(&me);
218 t = atoi(parv[1]); /* convert the time */
220 /* If we're reliable_clock or if the oper specified a 0 time, use current */
221 if (!t || feature_bool(FEAT_RELIABLE_CLOCK))
224 ircd_snprintf(0, tbuf, sizeof(tbuf), "%Tu", TStime());
228 dt = TStime() - t; /* calculate the delta */
230 if (t < OLDEST_TS || dt < -9000000) /* verify value */
232 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :SETTIME: Bad value", sptr);
236 /* OK, send the message off to its destination */
237 if (hunt_server_prio_cmd(sptr, CMD_SETTIME, cptr, 1, "%s %C", 2, parc,
238 parv) != HUNTED_ISME)
241 if (feature_bool(FEAT_RELIABLE_CLOCK)) /* don't apply settime--reliable */
243 if ((dt > 600) || (dt < -600))
244 sendcmdto_serv_butone(&me, CMD_DESYNCH, 0, ":Bad SETTIME from %s: %Tu "
245 "(delta %ld)", cli_name(sptr), t, dt);
246 if (IsUser(sptr)) /* Let user know we're ignoring him */
247 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is not set %ld seconds "
248 "%s: RELIABLE_CLOCK is defined", sptr, (dt < 0) ? -dt : dt,
249 (dt < 0) ? "forward" : "backward");
251 else /* tell opers about time change */
253 sendto_opmask_butone(0, SNO_OLDSNO, "SETTIME from %s, clock is set %ld "
254 "seconds %s", cli_name(sptr), (dt < 0) ? -dt : dt,
255 (dt < 0) ? "forwards" : "backwards");
256 TSoffset -= dt; /* apply time change */
257 if (IsUser(sptr)) /* let user know what we did */
258 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is set %ld seconds %s",
259 sptr, (dt < 0) ? -dt : dt,
260 (dt < 0) ? "forwards" : "backwards");