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
86 * No need to include handlers.h here the signatures must match
87 * and we don't need to force a rebuild of all the handlers everytime
88 * we add a new one to the list. --Bleep
95 #include "ircd_features.h"
96 #include "ircd_reply.h"
97 #include "ircd_snprintf.h"
98 #include "ircd_string.h"
102 #include "numnicks.h"
111 * ms_settime - server message handler
113 * parv[0] = sender prefix
115 * parv[2] = servername (Only used when sptr is an Oper).
117 int ms_settime(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
121 static char tbuf[11];
124 if (!IsPrivileged(sptr))
128 return need_more_params(sptr, "SETTIME");
130 if (parc == 2 && MyUser(sptr))
131 parv[parc++] = cli_name(&me);
136 if (t < OLDEST_TS || dt < -9000000)
138 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :SETTIME: Bad value", sptr);
142 if (IsServer(sptr)) /* send to unlagged servers */
144 if (feature_bool(FEAT_RELIABLE_CLOCK)) {
145 ircd_snprintf(0, tbuf, sizeof(tbuf), "%Tu", TStime());
149 for (lp = cli_serv(&me)->down; lp; lp = lp->next)
150 if (cptr != lp->value.cptr && MsgQLength(&(cli_sendQ(lp->value.cptr))) < 8000)
151 sendcmdto_one(sptr, CMD_NOTICE, lp->value.cptr, "%s", parv[1]);
155 ircd_snprintf(0, tbuf, sizeof(tbuf), "%Tu", TStime());
157 if (hunt_server_prio_cmd(sptr, CMD_SETTIME, cptr, 1, "%s %C", 2, parc,
158 parv) != HUNTED_ISME)
162 if (feature_bool(FEAT_RELIABLE_CLOCK)) {
163 if ((dt > 600) || (dt < -600))
164 sendcmdto_serv_butone(&me, CMD_WALLOPS, 0, ":Bad SETTIME from %s: %Tu",
167 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is not set %ld "
168 "seconds %s : RELIABLE_CLOCK is defined", sptr,
169 (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
172 sendto_opmask_butone(0, SNO_OLDSNO, "SETTIME from %s, clock is set %ld "
173 "seconds %s", cli_name(sptr), (dt < 0) ? -dt : dt,
174 (dt < 0) ? "forwards" : "backwards");
177 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is set %ld seconds %s",
178 sptr, (dt < 0) ? -dt : dt,
179 (dt < 0) ? "forwards" : "backwards");
187 * mo_settime - oper message handler
189 * parv[0] = sender prefix
191 * parv[2] = servername (Only used when sptr is an Oper).
193 int mo_settime(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
197 static char tbuf[11];
200 if (!IsPrivileged(sptr))
204 return need_more_params(sptr, "SETTIME");
206 if (parc == 2 && MyUser(sptr))
207 parv[parc++] = cli_name(&me);
212 if (t < OLDEST_TS || dt < -9000000)
214 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :SETTIME: Bad value", sptr);
218 if (IsServer(sptr)) /* send to unlagged servers */
220 if (feature_bool(FEAT_RELIABLE_CLOCK)) {
221 ircd_snprintf(0, tbuf, sizeof(tbuf), "%Tu", TStime());
225 for (lp = cli_serv(&me)->down; lp; lp = lp->next)
226 if (cptr != lp->value.cptr && MsgQLength(&(cli_sendQ(lp->value.cptr))) < 8000)
227 sendcmdto_prio_one(sptr, CMD_SETTIME, lp->value.cptr, "%s", parv[1]);
231 ircd_snprintf(0, tbuf, sizeof(tbuf), "%Tu", TStime());
233 if (hunt_server_prio_cmd(sptr, CMD_SETTIME, cptr, 1, "%s %C", 2, parc,
234 parv) != HUNTED_ISME)
238 if (feature_bool(FEAT_RELIABLE_CLOCK)) {
239 if ((dt > 600) || (dt < -600))
240 sendcmdto_serv_butone(&me, CMD_WALLOPS, 0, ":Bad SETTIME from %s: %Tu",
243 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is not set %ld "
244 "seconds %s : RELIABLE_CLOCK is defined", sptr,
245 (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
248 sendto_opmask_butone(0, SNO_OLDSNO, "SETTIME from %s, clock is set %ld "
249 "seconds %s", cli_name(sptr), (dt < 0) ? -dt : dt,
250 (dt < 0) ? "forwards" : "backwards");
253 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is set %ld seconds %s",
254 sptr, (dt < 0) ? -dt : dt,
255 (dt < 0) ? "forwards" : "backwards");
267 * parv[0] = sender prefix
269 * parv[2] = servername (Only used when sptr is an Oper).
271 int m_settime(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
275 static char tbuf[11];
278 if (!IsPrivileged(sptr))
282 return need_more_params(sptr, "SETTIME");
284 if (parc == 2 && MyUser(sptr))
285 parv[parc++] = me.name;
290 if (t < OLDEST_TS || dt < -9000000)
292 sendto_one(sptr, ":%s NOTICE %s :SETTIME: Bad value", me.name, parv[0]); /* XXX DEAD */
296 if (IsServer(sptr)) /* send to unlagged servers */
298 #ifdef RELIABLE_CLOCK
299 sprintf_irc(tbuf, TIME_T_FMT, TStime());
302 for (lp = me.serv->down; lp; lp = lp->next)
303 if (cptr != lp->value.cptr && DBufLength(&lp->value.cptr->sendQ) < 8000) /* XXX DEAD */
304 sendto_one(lp->value.cptr, ":%s SETTIME %s", parv[0], parv[1]); /* XXX DEAD */
308 sprintf_irc(tbuf, TIME_T_FMT, TStime());
310 if (hunt_server(1, cptr, sptr, "%s%s " TOK_SETTIME " %s %s", 2, parc, parv) != /* XXX DEAD */
315 #ifdef RELIABLE_CLOCK
316 if ((dt > 600) || (dt < -600))
317 sendto_serv_butone(0, ":%s " TOK_WALLOPS " :Bad SETTIME from %s: " TIME_T_FMT, /* XXX DEAD */
318 me.name, sptr->name, t);
321 if (MyUser(sptr) || Protocol(cptr) < 10)
322 sendto_one(sptr, ":%s NOTICE %s :clock is not set %ld seconds %s : " /* XXX DEAD */
323 "RELIABLE_CLOCK is defined", me.name, parv[0],
324 (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
326 sendto_one(sptr, "%s NOTICE %s%s :clock is not set %ld seconds %s : " /* XXX DEAD */
327 "RELIABLE_CLOCK is defined", NumServ(&me), NumNick(sptr),
328 (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
331 sendto_ops("SETTIME from %s, clock is set %ld seconds %s", /* XXX DEAD */
332 sptr->name, (dt < 0) ? -dt : dt,
333 (dt < 0) ? "forwards" : "backwards");
337 if (MyUser(sptr) || Protocol(cptr) < 10)
338 sendto_one(sptr, ":%s NOTICE %s :clock is set %ld seconds %s", me.name, /* XXX DEAD */
339 parv[0], (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
341 sendto_one(sptr, "%s NOTICE %s%s :clock is set %ld seconds %s", /* XXX DEAD */
342 NumServ(&me), NumNick(sptr),
343 (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");