]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_time.c
strip_colour(): strip ASCII 29 (mIRC 7 italics).
[irc/rqf/shadowircd.git] / modules / m_time.c
CommitLineData
212380e3 1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_time.c: Sends the current time on the server.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
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 2 of the License, or
12 * (at your option) any later version.
13 *
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.
18 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 *
212380e3 24 */
25
26#include "stdinc.h"
27#include "client.h"
28#include "ircd.h"
29#include "numeric.h"
30#include "s_conf.h"
31#include "s_serv.h"
32#include "send.h"
33#include "msg.h"
34#include "parse.h"
35#include "modules.h"
36#include "packet.h"
212380e3 37
38static int m_time(struct Client *, struct Client *, int, const char **);
39static char *date(void);
40
41struct Message time_msgtab = {
42 "TIME", 0, 0, 0, MFLG_SLOW,
43 {mg_unreg, {m_time, 0}, {m_time, 2}, mg_ignore, mg_ignore, {m_time, 0}}
44};
45
46mapi_clist_av1 time_clist[] = { &time_msgtab, NULL };
47DECLARE_MODULE_AV1(time, NULL, NULL, time_clist, NULL, NULL, "$Revision: 254 $");
48
49static const char *months[] = {
50 "January", "February", "March", "April",
51 "May", "June", "July", "August",
52 "September", "October", "November", "December"
53};
54
55static const char *weekdays[] = {
56 "Sunday", "Monday", "Tuesday", "Wednesday",
57 "Thursday", "Friday", "Saturday"
58};
59
60/*
61 * m_time
212380e3 62 * parv[1] = servername
63 */
64static int
65m_time(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
66{
67 /* this is not rate limited, so end the grace period */
68 if(MyClient(source_p) && !IsFloodDone(source_p))
69 flood_endgrace(source_p);
70
71 if(hunt_server(client_p, source_p, ":%s TIME :%s", 1, parc, parv) == HUNTED_ISME)
72 sendto_one_numeric(source_p, RPL_TIME, form_str(RPL_TIME),
73 me.name, date());
74
75 return 0;
76}
77
78/* date()
79 *
80 * returns date in human readable form
81 */
82static char *
83date(void)
84{
85 static char buf[80];
86 char plus;
87 struct tm *lt;
88 struct tm *gm;
89 struct tm gmbuf;
90 time_t lclock;
91 int minswest;
92
9f6bbe3c 93 lclock = rb_current_time();
212380e3 94 gm = gmtime(&lclock);
95 memcpy((void *) &gmbuf, (void *) gm, sizeof(gmbuf));
96 gm = &gmbuf;
97 lt = localtime(&lclock);
98
99 if(lt->tm_yday == gm->tm_yday)
100 minswest = (gm->tm_hour - lt->tm_hour) * 60 + (gm->tm_min - lt->tm_min);
101 else if(lt->tm_yday > gm->tm_yday && lt->tm_year == gm->tm_year)
102 minswest = (gm->tm_hour - (lt->tm_hour + 24)) * 60;
103 else
104 minswest = ((gm->tm_hour + 24) - lt->tm_hour) * 60;
105
106 plus = (minswest > 0) ? '-' : '+';
107
108 if(minswest < 0)
109 minswest = -minswest;
110
581fa5c4 111 rb_sprintf(buf, "%s %s %d %d -- %02u:%02u:%02u %c%02u:%02u",
212380e3 112 weekdays[lt->tm_wday], months[lt->tm_mon], lt->tm_mday,
113 lt->tm_year + 1900, lt->tm_hour, lt->tm_min, lt->tm_sec,
114 plus, minswest / 60, minswest % 60);
115
116 return buf;
117}