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