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 sendto_one(sptr, ":%s NOTICE %s :SETTIME: Bad value", me.name, parv[0]);
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 sendto_one(lp->value.cptr, ":%s SETTIME %s", parv[0], parv[1]);
150 sprintf_irc(tbuf, TIME_T_FMT, TStime());
152 if (hunt_server(1, cptr, sptr, "%s%s " TOK_SETTIME " %s %s", 2, parc, parv) !=
157 #ifdef RELIABLE_CLOCK
158 if ((dt > 600) || (dt < -600))
159 sendto_serv_butone(0, ":%s " TOK_WALLOPS " :Bad SETTIME from %s: " TIME_T_FMT,
160 me.name, sptr->name, t);
163 if (MyUser(sptr) || Protocol(cptr) < 10)
164 sendto_one(sptr, ":%s NOTICE %s :clock is not set %ld seconds %s : "
165 "RELIABLE_CLOCK is defined", me.name, parv[0],
166 (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
168 sendto_one(sptr, "%s NOTICE %s%s :clock is not set %ld seconds %s : "
169 "RELIABLE_CLOCK is defined", NumServ(&me), NumNick(sptr),
170 (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
173 sendto_ops("SETTIME from %s, clock is set %ld seconds %s",
174 sptr->name, (dt < 0) ? -dt : dt,
175 (dt < 0) ? "forwards" : "backwards");
179 if (MyUser(sptr) || Protocol(cptr) < 10)
180 sendto_one(sptr, ":%s NOTICE %s :clock is set %ld seconds %s", me.name,
181 parv[0], (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
183 sendto_one(sptr, "%s NOTICE %s%s :clock is set %ld seconds %s",
184 NumServ(&me), NumNick(sptr),
185 (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
192 * mo_settime - oper message handler
194 * parv[0] = sender prefix
196 * parv[2] = servername (Only used when sptr is an Oper).
198 int mo_settime(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
202 static char tbuf[11];
205 if (!IsPrivileged(sptr))
209 return need_more_params(sptr, "SETTIME");
211 if (parc == 2 && MyUser(sptr))
212 parv[parc++] = me.name;
217 if (t < OLDEST_TS || dt < -9000000)
219 sendto_one(sptr, ":%s NOTICE %s :SETTIME: Bad value", me.name, parv[0]);
223 if (IsServer(sptr)) /* send to unlagged servers */
225 #ifdef RELIABLE_CLOCK
226 sprintf_irc(tbuf, TIME_T_FMT, TStime());
229 for (lp = me.serv->down; lp; lp = lp->next)
230 if (cptr != lp->value.cptr && DBufLength(&lp->value.cptr->sendQ) < 8000)
231 sendto_one(lp->value.cptr, ":%s SETTIME %s", parv[0], parv[1]);
235 sprintf_irc(tbuf, TIME_T_FMT, TStime());
237 if (hunt_server(1, cptr, sptr, "%s%s " TOK_SETTIME " %s %s", 2, parc, parv) !=
242 #ifdef RELIABLE_CLOCK
243 if ((dt > 600) || (dt < -600))
244 sendto_serv_butone(0, ":%s " TOK_WALLOPS " :Bad SETTIME from %s: " TIME_T_FMT,
245 me.name, sptr->name, t);
248 if (MyUser(sptr) || Protocol(cptr) < 10)
249 sendto_one(sptr, ":%s NOTICE %s :clock is not set %ld seconds %s : "
250 "RELIABLE_CLOCK is defined", me.name, parv[0],
251 (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
253 sendto_one(sptr, "%s NOTICE %s%s :clock is not set %ld seconds %s : "
254 "RELIABLE_CLOCK is defined", NumServ(&me), NumNick(sptr),
255 (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
258 sendto_ops("SETTIME from %s, clock is set %ld seconds %s",
259 sptr->name, (dt < 0) ? -dt : dt,
260 (dt < 0) ? "forwards" : "backwards");
264 if (MyUser(sptr) || Protocol(cptr) < 10)
265 sendto_one(sptr, ":%s NOTICE %s :clock is set %ld seconds %s", me.name,
266 parv[0], (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
268 sendto_one(sptr, "%s NOTICE %s%s :clock is set %ld seconds %s",
269 NumServ(&me), NumNick(sptr),
270 (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
281 * parv[0] = sender prefix
283 * parv[2] = servername (Only used when sptr is an Oper).
285 int m_settime(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
289 static char tbuf[11];
292 if (!IsPrivileged(sptr))
296 return need_more_params(sptr, "SETTIME");
298 if (parc == 2 && MyUser(sptr))
299 parv[parc++] = me.name;
304 if (t < OLDEST_TS || dt < -9000000)
306 sendto_one(sptr, ":%s NOTICE %s :SETTIME: Bad value", me.name, parv[0]);
310 if (IsServer(sptr)) /* send to unlagged servers */
312 #ifdef RELIABLE_CLOCK
313 sprintf_irc(tbuf, TIME_T_FMT, TStime());
316 for (lp = me.serv->down; lp; lp = lp->next)
317 if (cptr != lp->value.cptr && DBufLength(&lp->value.cptr->sendQ) < 8000)
318 sendto_one(lp->value.cptr, ":%s SETTIME %s", parv[0], parv[1]);
322 sprintf_irc(tbuf, TIME_T_FMT, TStime());
324 if (hunt_server(1, cptr, sptr, "%s%s " TOK_SETTIME " %s %s", 2, parc, parv) !=
329 #ifdef RELIABLE_CLOCK
330 if ((dt > 600) || (dt < -600))
331 sendto_serv_butone(0, ":%s " TOK_WALLOPS " :Bad SETTIME from %s: " TIME_T_FMT,
332 me.name, sptr->name, t);
335 if (MyUser(sptr) || Protocol(cptr) < 10)
336 sendto_one(sptr, ":%s NOTICE %s :clock is not set %ld seconds %s : "
337 "RELIABLE_CLOCK is defined", me.name, parv[0],
338 (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
340 sendto_one(sptr, "%s NOTICE %s%s :clock is not set %ld seconds %s : "
341 "RELIABLE_CLOCK is defined", NumServ(&me), NumNick(sptr),
342 (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
345 sendto_ops("SETTIME from %s, clock is set %ld seconds %s",
346 sptr->name, (dt < 0) ? -dt : dt,
347 (dt < 0) ? "forwards" : "backwards");
351 if (MyUser(sptr) || Protocol(cptr) < 10)
352 sendto_one(sptr, ":%s NOTICE %s :clock is set %ld seconds %s", me.name,
353 parv[0], (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
355 sendto_one(sptr, "%s NOTICE %s%s :clock is set %ld seconds %s",
356 NumServ(&me), NumNick(sptr),
357 (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");