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
84 * No need to include handlers.h here the signatures must match
85 * and we don't need to force a rebuild of all the handlers everytime
86 * we add a new one to the list. --Bleep
93 #include "ircd_reply.h"
94 #include "ircd_string.h"
107 * ms_settime - server message handler
109 * parv[0] = sender prefix
111 * parv[2] = servername (Only used when sptr is an Oper).
113 int ms_settime(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
117 static char tbuf[11];
120 if (!IsPrivileged(sptr))
124 return need_more_params(sptr, "SETTIME");
126 if (parc == 2 && MyUser(sptr))
127 parv[parc++] = me.name;
132 if (t < OLDEST_TS || dt < -9000000)
134 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :SETTIME: Bad value", sptr);
138 if (IsServer(sptr)) /* send to unlagged servers */
140 #ifdef RELIABLE_CLOCK
141 sprintf_irc(tbuf, TIME_T_FMT, TStime());
144 for (lp = me.serv->down; lp; lp = lp->next)
145 if (cptr != lp->value.cptr && DBufLength(&lp->value.cptr->sendQ) < 8000)
146 sendcmdto_one(sptr, CMD_NOTICE, lp->value.cptr, "%s", parv[1]);
150 sprintf_irc(tbuf, TIME_T_FMT, TStime());
152 if (hunt_server_cmd(sptr, CMD_SETTIME, cptr, 1, "%s %C", 2, parc, parv) !=
157 #ifdef RELIABLE_CLOCK
158 if ((dt > 600) || (dt < -600))
159 sendcmdto_serv_butone(&me, CMD_WALLOPS, 0, ":Bad SETTIME from %s: %Tu",
163 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is not set %ld seconds %s "
164 ": RELIABLE_CLOCK is defined", sptr, (dt < 0) ? -dt : dt,
165 (dt < 0) ? "forwards" : "backwards");
168 sendto_opmask_butone(0, SNO_OLDSNO, "SETTIME from %s, clock is set %ld "
169 "seconds %s", sptr->name, (dt < 0) ? -dt : dt,
170 (dt < 0) ? "forwards" : "backwards");
174 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is set %ld seconds %s",
175 sptr, (dt < 0) ? -dt : dt,
176 (dt < 0) ? "forwards" : "backwards");
183 * mo_settime - oper message handler
185 * parv[0] = sender prefix
187 * parv[2] = servername (Only used when sptr is an Oper).
189 int mo_settime(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
193 static char tbuf[11];
196 if (!IsPrivileged(sptr))
200 return need_more_params(sptr, "SETTIME");
202 if (parc == 2 && MyUser(sptr))
203 parv[parc++] = me.name;
208 if (t < OLDEST_TS || dt < -9000000)
210 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :SETTIME: Bad value", sptr);
214 if (IsServer(sptr)) /* send to unlagged servers */
216 #ifdef RELIABLE_CLOCK
217 sprintf_irc(tbuf, TIME_T_FMT, TStime());
220 for (lp = me.serv->down; lp; lp = lp->next)
221 if (cptr != lp->value.cptr && DBufLength(&lp->value.cptr->sendQ) < 8000)
222 sendcmdto_one(sptr, CMD_SETTIME, lp->value.cptr, "%s", parv[1]);
226 sprintf_irc(tbuf, TIME_T_FMT, TStime());
228 if (hunt_server_cmd(sptr, CMD_SETTIME, cptr, 1, "%s %C", 2, parc, parv) !=
233 #ifdef RELIABLE_CLOCK
234 if ((dt > 600) || (dt < -600))
235 sendcmdto_serv_butone(&me, CMD_WALLOPS, 0, ":Bad SETTIME from %s: %Tu",
239 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is not set %ld seconds %s "
240 ": RELIABLE_CLOCK is defined", sptr, (dt < 0) ? -dt : dt,
241 (dt < 0) ? "forwards" : "backwards");
244 sendto_opmask_butone(0, SNO_OLDSNO, "SETTIME from %s, clock is set %ld "
245 "seconds %s", sptr->name, (dt < 0) ? -dt : dt,
246 (dt < 0) ? "forwards" : "backwards");
250 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is set %ld seconds %s",
251 sptr, (dt < 0) ? -dt : dt,
252 (dt < 0) ? "forwards" : "backwards");
263 * parv[0] = sender prefix
265 * parv[2] = servername (Only used when sptr is an Oper).
267 int m_settime(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
271 static char tbuf[11];
274 if (!IsPrivileged(sptr))
278 return need_more_params(sptr, "SETTIME");
280 if (parc == 2 && MyUser(sptr))
281 parv[parc++] = me.name;
286 if (t < OLDEST_TS || dt < -9000000)
288 sendto_one(sptr, ":%s NOTICE %s :SETTIME: Bad value", me.name, parv[0]); /* XXX DEAD */
292 if (IsServer(sptr)) /* send to unlagged servers */
294 #ifdef RELIABLE_CLOCK
295 sprintf_irc(tbuf, TIME_T_FMT, TStime());
298 for (lp = me.serv->down; lp; lp = lp->next)
299 if (cptr != lp->value.cptr && DBufLength(&lp->value.cptr->sendQ) < 8000)
300 sendto_one(lp->value.cptr, ":%s SETTIME %s", parv[0], parv[1]); /* XXX DEAD */
304 sprintf_irc(tbuf, TIME_T_FMT, TStime());
306 if (hunt_server(1, cptr, sptr, "%s%s " TOK_SETTIME " %s %s", 2, parc, parv) != /* XXX DEAD */
311 #ifdef RELIABLE_CLOCK
312 if ((dt > 600) || (dt < -600))
313 sendto_serv_butone(0, ":%s " TOK_WALLOPS " :Bad SETTIME from %s: " TIME_T_FMT, /* XXX DEAD */
314 me.name, sptr->name, t);
317 if (MyUser(sptr) || Protocol(cptr) < 10)
318 sendto_one(sptr, ":%s NOTICE %s :clock is not set %ld seconds %s : " /* XXX DEAD */
319 "RELIABLE_CLOCK is defined", me.name, parv[0],
320 (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
322 sendto_one(sptr, "%s NOTICE %s%s :clock is not set %ld seconds %s : " /* XXX DEAD */
323 "RELIABLE_CLOCK is defined", NumServ(&me), NumNick(sptr),
324 (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
327 sendto_ops("SETTIME from %s, clock is set %ld seconds %s", /* XXX DEAD */
328 sptr->name, (dt < 0) ? -dt : dt,
329 (dt < 0) ? "forwards" : "backwards");
333 if (MyUser(sptr) || Protocol(cptr) < 10)
334 sendto_one(sptr, ":%s NOTICE %s :clock is set %ld seconds %s", me.name, /* XXX DEAD */
335 parv[0], (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
337 sendto_one(sptr, "%s NOTICE %s%s :clock is set %ld seconds %s", /* XXX DEAD */
338 NumServ(&me), NumNick(sptr),
339 (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");