]> jfr.im git - irc/rqf/shadowircd.git/blob - modules/m_time.c
irc_string.h -> match.h, irc_string.h; includes changed
[irc/rqf/shadowircd.git] / modules / m_time.c
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 *
24 * $Id: m_time.c 254 2005-09-21 23:35:12Z nenolod $
25 */
26
27 #include "stdinc.h"
28 #include "client.h"
29 #include "ircd.h"
30 #include "numeric.h"
31 #include "s_conf.h"
32 #include "s_serv.h"
33 #include "send.h"
34 #include "msg.h"
35 #include "parse.h"
36 #include "modules.h"
37 #include "packet.h"
38
39 static int m_time(struct Client *, struct Client *, int, const char **);
40 static char *date(void);
41
42 struct Message time_msgtab = {
43 "TIME", 0, 0, 0, MFLG_SLOW,
44 {mg_unreg, {m_time, 0}, {m_time, 2}, mg_ignore, mg_ignore, {m_time, 0}}
45 };
46
47 mapi_clist_av1 time_clist[] = { &time_msgtab, NULL };
48 DECLARE_MODULE_AV1(time, NULL, NULL, time_clist, NULL, NULL, "$Revision: 254 $");
49
50 static const char *months[] = {
51 "January", "February", "March", "April",
52 "May", "June", "July", "August",
53 "September", "October", "November", "December"
54 };
55
56 static const char *weekdays[] = {
57 "Sunday", "Monday", "Tuesday", "Wednesday",
58 "Thursday", "Friday", "Saturday"
59 };
60
61 /*
62 * m_time
63 * parv[0] = sender prefix
64 * parv[1] = servername
65 */
66 static int
67 m_time(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
68 {
69 /* this is not rate limited, so end the grace period */
70 if(MyClient(source_p) && !IsFloodDone(source_p))
71 flood_endgrace(source_p);
72
73 if(hunt_server(client_p, source_p, ":%s TIME :%s", 1, parc, parv) == HUNTED_ISME)
74 sendto_one_numeric(source_p, RPL_TIME, form_str(RPL_TIME),
75 me.name, date());
76
77 return 0;
78 }
79
80 /* date()
81 *
82 * returns date in human readable form
83 */
84 static char *
85 date(void)
86 {
87 static char buf[80];
88 char plus;
89 struct tm *lt;
90 struct tm *gm;
91 struct tm gmbuf;
92 time_t lclock;
93 int minswest;
94
95 lclock = rb_current_time();
96 gm = gmtime(&lclock);
97 memcpy((void *) &gmbuf, (void *) gm, sizeof(gmbuf));
98 gm = &gmbuf;
99 lt = localtime(&lclock);
100
101 if(lt->tm_yday == gm->tm_yday)
102 minswest = (gm->tm_hour - lt->tm_hour) * 60 + (gm->tm_min - lt->tm_min);
103 else if(lt->tm_yday > gm->tm_yday && lt->tm_year == gm->tm_year)
104 minswest = (gm->tm_hour - (lt->tm_hour + 24)) * 60;
105 else
106 minswest = ((gm->tm_hour + 24) - lt->tm_hour) * 60;
107
108 plus = (minswest > 0) ? '-' : '+';
109
110 if(minswest < 0)
111 minswest = -minswest;
112
113 rb_sprintf(buf, "%s %s %d %d -- %02u:%02u:%02u %c%02u:%02u",
114 weekdays[lt->tm_wday], months[lt->tm_mon], lt->tm_mday,
115 lt->tm_year + 1900, lt->tm_hour, lt->tm_min, lt->tm_sec,
116 plus, minswest / 60, minswest % 60);
117
118 return buf;
119 }