]>
jfr.im git - irc/thales.git/blob - src/messages.c
1 /* GNU Thales - IRC to Relational Database Gateway
2 * Copyright (C) 2002 Lucas Nussbaum <lucas@lucas-nussbaum.net>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 extern char *ServerName
;
30 extern char *RemoteServer
;
31 extern time_t start_time
;
33 extern unsigned int nbusers
;
34 extern unsigned int nbusers_max
;
35 extern unsigned int nbchans
;
36 extern unsigned int nbchans_max
;
38 /* List of messages is at the bottom of the file. */
41 static void m_ping(char *source
, int ac
, char **av
)
45 send_cmd(ServerName
, "PONG %s %s", ac
> 1 ? av
[1] : ServerName
, av
[0]);
48 /* SERVER - forwarded */
49 static void m_server(char *source
, int ac
, char **av
)
53 do_server(av
[0], av
[2], source
);
58 do_server(av
[0], strchr(av
[2], ' ') + 1, ServerName
);
60 do_server(av
[0], av
[2], ServerName
);
65 /* SQUIT - forwarded */
66 static void m_squit(char *source
, int ac
, char **av
)
71 /* NICK - forwarded */
72 static void m_nick(char *source
, int ac
, char **av
)
75 do_nick_chg(av
[0], source
);
80 /* KICK - forwarded */
81 static void m_kick(char *source
, int ac
, char **av
)
83 do_part(av
[0], av
[1]); /* kicks are handled like parts */
86 /* PART - forwarded */
87 static void m_part(char *source
, int ac
, char **av
)
89 do_part(av
[0], source
);
94 static void m_error(char *source
, int ac
, char **av
)
96 fatal(av
[0][0] == ':' ? av
[0] + 1 : av
[0]);
99 /* JOIN - forwarded */
100 static void m_join(char *source
, int ac
, char **av
)
104 /* LAME ultimate 2.8 with multiple channels in the same JOIN ... */
106 while ((pos
= strchr(oldpos
, ',')) != NULL
)
109 do_join(oldpos
, source
);
112 do_join(oldpos
, source
);
114 if (!strcmp(av
[0], "0"))
117 do_join(av
[0], source
);
121 /* QUIT - forwarded */
122 static void m_quit(char *source
, int ac
, char **av
)
127 /* SJOIN - forwarded */
128 static void m_sjoin(char *source
, int ac
, char **av
)
131 #if defined(IRCD_BAHAMUT)||defined(IRCD_ULTIMATE)||defined(IRCD_IRCDRU)
133 do_join(av
[1], source
); /* like a join */
136 do_sjoin(av
[1], av
[ac
- 1], &av
[2], (ac
> 3) ? ac
- 3 : 0);
139 /* SVSMODE - forwarded */
140 static void m_svsmode(char *source
, int ac
, char **av
)
143 #if defined(IRCD_BAHAMUT)||defined(IRCD_ULTIMATE)||defined(IRCD_IRCDRU)||defined(IRCD_HYBRID)
144 do_umode(av
[0], av
[2]);
145 #elif defined(IRCD_UNREAL)||defined(IRCD_ULTI28)
146 do_umode(av
[0], av
[1]);
149 do_cmode(av
[0], &av
[1], ac
- 2);
152 /* MODE - forwarded */
153 static void m_mode(char *source
, int ac
, char **av
)
156 do_umode(av
[0], av
[1]);
158 do_cmode(av
[0], &av
[1], ac
- 1);
161 /* TOPIC - forwarded */
162 static void m_topic(char *source
, int ac
, char **av
)
165 do_topic(source
, av
[0], av
[1]);
167 do_topic(av
[0], av
[1], av
[2], av
[3]);
168 #endif /* IRCD_HYBRID */
171 /* TBURST - forwarded -iwes */
173 static void m_tburst(char *source
, int ac
, char **av
)
175 do_tburst(av
[1], av
[2], av
[3], av
[4]);
177 #endif /* IRCD_HYBRID */
179 /* KILL - forwarded */
180 static void m_kill(char *source
, int ac
, char **av
)
185 /* AWAY - forwarded */
186 static void m_away(char *source
, int ac
, char **av
)
189 do_away_unset(source
);
191 do_away_set(source
, av
[0]);
194 /* VERSION - handled */
195 static void m_version(char *source
, int ac
, char **av
)
198 send_cmd(ServerName
, "351 %s GNU Thales %s %s",
199 source
, VERSION
, ServerName
);
202 /* STATS - handled */
203 static void m_stats(char *source
, int ac
, char **av
)
211 "211 %s Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime",
213 send_cmd(NULL
, "211 %s %s %d %d %d %d %d %d %ld", source
,
214 RemoteServer
, write_buffer_len(), total_written
, -1,
215 read_buffer_len(), total_read
, -1, time(NULL
) - start_time
);
216 send_cmd(NULL
, "219 %s l :End of /STATS report.", source
);
221 uptime
= time(NULL
) - start_time
;
222 send_cmd(NULL
, "242 %s :GNU Thales up %d day%s, %02d:%02d:%02d",
223 source
, uptime
/ 86400, (uptime
/ 86400 == 1) ? "" : "s",
224 (uptime
/ 3600) % 24, (uptime
/ 60) % 60, uptime
% 60);
225 send_cmd(NULL
, "219 %s u :End of /STATS report.", source
);
229 send_cmd(NULL
, "219 %s %c :End of /STATS report.", source
, *av
[0]);
234 /* LUSERS - forwarded */
235 static void m_lusers(char *source
, int ac
, char **av
)
241 static void m_motd(char *source
, int ac
, char **av
)
243 send_cmd(ServerName
, "375 %s :- %s Message of the Day", source
,
245 send_cmd(ServerName
, "372 %s :- _____ _ _", source
);
246 send_cmd(ServerName
, "372 %s :-|_ _| |__ __ _| | ___ ___", source
);
247 send_cmd(ServerName
, "372 %s :- | | | '_ \\ / _` | |/ _ \\/ __|",
249 send_cmd(ServerName
, "372 %s :- | | | | | | (_| | | __/\\__ \\",
251 send_cmd(ServerName
, "372 %s :- |_| |_| |_|\\__,_|_|\\___||___/",
253 send_cmd(ServerName
, "372 %s :- v. %s", source
, VERSION
);
254 send_cmd(ServerName
, "372 %s :- (c)2002-2004 Lucas Nussbaum", source
);
255 send_cmd(ServerName
, "372 %s :-", source
);
256 send_cmd(ServerName
, "372 %s :-GNU Thales is an IRC to MySQL gateway.",
258 send_cmd(ServerName
, "372 %s :- More info is available on", source
);
259 send_cmd(ServerName
, "372 %s :- http://www.gnu.org/software/thales/",
261 send_cmd(ServerName
, "376 %s :End of /MOTD command.", source
);
264 /* ADMIN - handled */
265 static void m_admin(char *source
, int ac
, char **av
)
267 send_cmd(ServerName
, "256 %s :Administrative info about %s", source
,
269 send_cmd(ServerName
, "257 %s :thales-%s : IRC to MySQL Gateway", source
,
272 "258 %s :Written by Lucas Nussbaum <lucas@lucas-nussbaum.net>",
275 "259 %s :See http://www.gnu.org/software/thales/ for more info.",
280 static char *months
[] = {
281 "January", "February", "March", "April",
282 "May", "June", "July", "August",
283 "September", "October", "November", "December"
286 static char *weekdays
[] = {
287 "Sunday", "Monday", "Tuesday", "Wednesday",
288 "Thursday", "Friday", "Saturday"
291 static void m_time(char *source
, int ac
, char **av
)
293 static char buf
[80], plus
;
301 memcpy((char *) &gmbuf
, (char *) gm
, sizeof(gmbuf
));
303 lt
= localtime(&clock
);
305 if (lt
->tm_yday
== gm
->tm_yday
)
307 (gm
->tm_hour
- lt
->tm_hour
) * 60 + (gm
->tm_min
- lt
->tm_min
);
308 else if (lt
->tm_yday
> gm
->tm_yday
)
309 minswest
= (gm
->tm_hour
- (lt
->tm_hour
+ 24)) * 60;
311 minswest
= ((gm
->tm_hour
+ 24) - lt
->tm_hour
) * 60;
313 plus
= (minswest
> 0) ? '-' : '+';
315 minswest
= -minswest
;
317 (void) snprintf(buf
, sizeof(buf
),
318 "%s %s %d %04d -- %02d:%02d %c%02d:%02d",
319 weekdays
[lt
->tm_wday
], months
[lt
->tm_mon
], lt
->tm_mday
,
320 lt
->tm_year
+ 1900, lt
->tm_hour
, lt
->tm_min
, plus
,
321 minswest
/ 60, minswest
% 60);
323 send_cmd(ServerName
, "391 %s %s :%s", source
, ServerName
, buf
);
328 * IRCD specific commands
331 #if defined(IRCD_UNREAL)||defined(IRCD_ULTI28)
333 /* CHGHOST - forwarded */
334 static void m_chghost(char *source
, int ac
, char **av
)
336 do_defhost(av
[0], av
[1]);
339 /* CHGNAME - forwarded */
340 static void m_chgname(char *source
, int ac
, char **av
)
342 do_defname(av
[0], av
[1]);
345 /* CHGIDENT - forwarded */
346 static void m_chgident(char *source
, int ac
, char **av
)
348 do_defname(av
[0], av
[1]);
351 /* SETNAME - forwarded */
352 static void m_setname(char *source
, int ac
, char **av
)
354 do_defname(source
, av
[0]);
357 /* SETIDENT - forwarded */
358 static void m_setident(char *source
, int ac
, char **av
)
360 do_defident(source
, av
[0]);
367 /* SDESC - forwarded */
368 static void m_sdesc(char *source
, int ac
, char **av
)
370 do_sdesc(source
, av
[0]);
373 /* SWHOIS - forwarded */
374 static void m_swhois(char *source
, int ac
, char **av
)
376 do_swhois(source
, av
[0]);
382 #if defined(IRCD_UNREAL)||defined(IRCD_ULTI28)
383 /* SETHOST - forwarded */
384 static void m_sethost(char *source
, int ac
, char **av
)
386 do_defhost(source
, av
[0]);
390 #if defined(IRCD_ULTIMATE)
392 /* SETHOST - forwarded */
393 static void m_sethost(char *source
, int ac
, char **av
)
395 do_defhost(av
[0], av
[1]);
402 /* REALHOST - forwarded */
403 static void m_realhost(char *source
, int ac
, char **av
)
405 mylog("NBPARAMS : %d", ac
);
407 do_realhost(av
[0], av
[1]);
409 do_realhost(av
[0], "");
413 /*************************************************************************/
414 Message messages
[] = {
422 {"VERSION", m_version
}
434 {"SVSMODE", m_svsmode
}
445 #endif /* IRCD_HYBRID */
502 {"CHGHOST", m_chghost
}
504 {"CHGIDENT", m_chgident
}
506 {"CHGNAME", m_chgname
}
508 {"SETHOST", m_sethost
}
510 {"SETIDENT", m_setident
}
512 {"SETNAME", m_setname
}
560 {"SETHOST", m_sethost
}
576 {"SVS2MODE", m_svsmode
}
582 {"CHGHOST", m_chghost
}
584 {"CHGIDENT", m_chgident
}
586 {"CHGNAME", m_chgname
}
588 {"SETHOST", m_sethost
}
590 {"SETIDENT", m_setident
}
592 {"SETNAME", m_setname
}
600 {"REALHOST", m_realhost
}
606 /*************************************************************************/
608 Message
*find_message(const char *name
)
611 for (m
= messages
; m
->name
; m
++)
612 if (stricmp(name
, m
->name
) == 0)
617 /*************************************************************************/