]> jfr.im git - irc/thales.git/blob - src/messages.c
Sequana support removed
[irc/thales.git] / src / messages.c
1 /* GNU Thales - IRC to Relational Database Gateway
2 * Copyright (C) 2002 Lucas Nussbaum <lucas@lucas-nussbaum.net>
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #include "thales.h"
20 #include "messages.h"
21 #include "send.h"
22 #include "misc.h"
23 #include "compat.h"
24 #include "memory.h"
25 #include "log.h"
26 #include "actions.h"
27 #include "sockutil.h"
28
29 extern char *ServerName;
30 extern char *RemoteServer;
31 extern time_t start_time;
32
33 extern unsigned int nbusers;
34 extern unsigned int nbusers_max;
35 extern unsigned int nbchans;
36 extern unsigned int nbchans_max;
37
38 /* List of messages is at the bottom of the file. */
39
40 /* PING - handled */
41 static void m_ping(char *source, int ac, char **av)
42 {
43 if (ac < 1)
44 return;
45 send_cmd(ServerName, "PONG %s %s", ac > 1 ? av[1] : ServerName, av[0]);
46 }
47
48 /* SERVER - forwarded */
49 static void m_server(char *source, int ac, char **av)
50 {
51 if (*source)
52 {
53 do_server(av[0], av[2], source);
54 }
55 else
56 {
57 #ifdef IRCD_UNREAL
58 do_server(av[0], strchr(av[2], ' ') + 1, ServerName);
59 #else
60 do_server(av[0], av[2], ServerName);
61 #endif
62 }
63 }
64
65 /* SQUIT - forwarded */
66 static void m_squit(char *source, int ac, char **av)
67 {
68 do_squit(av[0]);
69 }
70
71 /* NICK - forwarded */
72 static void m_nick(char *source, int ac, char **av)
73 {
74 if (*source)
75 do_nick_chg(av[0], source);
76 else
77 do_nick_new(ac, av);
78 }
79
80 /* KICK - forwarded */
81 static void m_kick(char *source, int ac, char **av)
82 {
83 do_part(av[0], av[1]); /* kicks are handled like parts */
84 }
85
86 /* PART - forwarded */
87 static void m_part(char *source, int ac, char **av)
88 {
89 do_part(av[0], source);
90
91 }
92
93 /* ERROR - handled */
94 static void m_error(char *source, int ac, char **av)
95 {
96 fatal(av[0][0] == ':' ? av[0] + 1 : av[0]);
97 }
98
99 /* JOIN - forwarded */
100 static void m_join(char *source, int ac, char **av)
101 {
102 #ifdef IRCD_ULTI28
103 char *pos, *oldpos;
104 /* LAME ultimate 2.8 with multiple channels in the same JOIN ... */
105 oldpos = av[0];
106 while ((pos = strchr(oldpos, ',')) != NULL)
107 {
108 *pos = '\0';
109 do_join(oldpos, source);
110 oldpos = pos + 1;
111 }
112 do_join(oldpos, source);
113 #else
114 if (!strcmp(av[0], "0"))
115 do_partall(source);
116 else
117 do_join(av[0], source);
118 #endif
119 }
120
121 /* QUIT - forwarded */
122 static void m_quit(char *source, int ac, char **av)
123 {
124 do_quit(source);
125 }
126
127 /* SJOIN - forwarded */
128 static void m_sjoin(char *source, int ac, char **av)
129 {
130
131 #if defined(IRCD_BAHAMUT)||defined(IRCD_ULTIMATE)||defined(IRCD_IRCDRU)
132 if (ac == 2)
133 do_join(av[1], source); /* like a join */
134 else
135 #endif
136 do_sjoin(av[1], av[ac - 1], &av[2], (ac > 3) ? ac - 3 : 0);
137 }
138
139 /* SVSMODE - forwarded */
140 static void m_svsmode(char *source, int ac, char **av)
141 {
142 if (*av[0] != '#')
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]);
147 #endif
148 else
149 do_cmode(av[0], &av[1], ac - 2);
150 }
151
152 /* MODE - forwarded */
153 static void m_mode(char *source, int ac, char **av)
154 {
155 if (*av[0] != '#')
156 do_umode(av[0], av[1]);
157 else
158 do_cmode(av[0], &av[1], ac - 1);
159 }
160
161 /* TOPIC - forwarded */
162 static void m_topic(char *source, int ac, char **av)
163 {
164 #ifdef IRCD_HYBRID
165 do_topic(source, av[0], av[1]);
166 #else
167 do_topic(av[0], av[1], av[2], av[3]);
168 #endif /* IRCD_HYBRID */
169 }
170
171 /* TBURST - forwarded -iwes */
172 #ifdef IRCD_HYBRID
173 static void m_tburst(char *source, int ac, char **av)
174 {
175 do_tburst(av[1], av[2], av[3], av[4]);
176 }
177 #endif /* IRCD_HYBRID */
178
179 /* KILL - forwarded */
180 static void m_kill(char *source, int ac, char **av)
181 {
182 do_quit(av[0]);
183 }
184
185 /* AWAY - forwarded */
186 static void m_away(char *source, int ac, char **av)
187 {
188 if (!ac)
189 do_away_unset(source);
190 else
191 do_away_set(source, av[0]);
192 }
193
194 /* VERSION - handled */
195 static void m_version(char *source, int ac, char **av)
196 {
197 if (source)
198 send_cmd(ServerName, "351 %s GNU Thales %s %s",
199 source, VERSION, ServerName);
200 }
201
202 /* STATS - handled */
203 static void m_stats(char *source, int ac, char **av)
204 {
205 if (ac < 1)
206 return;
207 switch (*av[0])
208 {
209 case 'l':
210 send_cmd(NULL,
211 "211 %s Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime",
212 source);
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);
217 break;
218 case 'u':
219 {
220 int uptime;
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);
226 break;
227 }
228 default:
229 send_cmd(NULL, "219 %s %c :End of /STATS report.", source, *av[0]);
230 break;
231 }
232 }
233
234 /* LUSERS - forwarded */
235 static void m_lusers(char *source, int ac, char **av)
236 {
237 do_lusers(source);
238 }
239
240 /* MOTD - handled */
241 static void m_motd(char *source, int ac, char **av)
242 {
243 send_cmd(ServerName, "375 %s :- %s Message of the Day", source,
244 ServerName);
245 send_cmd(ServerName, "372 %s :- _____ _ _", source);
246 send_cmd(ServerName, "372 %s :-|_ _| |__ __ _| | ___ ___", source);
247 send_cmd(ServerName, "372 %s :- | | | '_ \\ / _` | |/ _ \\/ __|",
248 source);
249 send_cmd(ServerName, "372 %s :- | | | | | | (_| | | __/\\__ \\",
250 source);
251 send_cmd(ServerName, "372 %s :- |_| |_| |_|\\__,_|_|\\___||___/",
252 source);
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.",
257 source);
258 send_cmd(ServerName, "372 %s :- More info is available on", source);
259 send_cmd(ServerName, "372 %s :- http://www.gnu.org/software/thales/",
260 source);
261 send_cmd(ServerName, "376 %s :End of /MOTD command.", source);
262 }
263
264 /* ADMIN - handled */
265 static void m_admin(char *source, int ac, char **av)
266 {
267 send_cmd(ServerName, "256 %s :Administrative info about %s", source,
268 ServerName);
269 send_cmd(ServerName, "257 %s :thales-%s : IRC to MySQL Gateway", source,
270 VERSION);
271 send_cmd(ServerName,
272 "258 %s :Written by Lucas Nussbaum <lucas@lucas-nussbaum.net>",
273 source);
274 send_cmd(ServerName,
275 "259 %s :See http://www.gnu.org/software/thales/ for more info.",
276 source);
277 }
278
279 /* TIME - handled */
280 static char *months[] = {
281 "January", "February", "March", "April",
282 "May", "June", "July", "August",
283 "September", "October", "November", "December"
284 };
285
286 static char *weekdays[] = {
287 "Sunday", "Monday", "Tuesday", "Wednesday",
288 "Thursday", "Friday", "Saturday"
289 };
290
291 static void m_time(char *source, int ac, char **av)
292 {
293 static char buf[80], plus;
294 struct tm *lt, *gm;
295 struct tm gmbuf;
296 int minswest;
297 time_t clock;
298
299 time(&clock);
300 gm = gmtime(&clock);
301 memcpy((char *) &gmbuf, (char *) gm, sizeof(gmbuf));
302 gm = &gmbuf;
303 lt = localtime(&clock);
304
305 if (lt->tm_yday == gm->tm_yday)
306 minswest =
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;
310 else
311 minswest = ((gm->tm_hour + 24) - lt->tm_hour) * 60;
312
313 plus = (minswest > 0) ? '-' : '+';
314 if (minswest < 0)
315 minswest = -minswest;
316
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);
322
323 send_cmd(ServerName, "391 %s %s :%s", source, ServerName, buf);
324 }
325
326
327 /*
328 * IRCD specific commands
329 */
330
331 #if defined(IRCD_UNREAL)||defined(IRCD_ULTI28)
332
333 /* CHGHOST - forwarded */
334 static void m_chghost(char *source, int ac, char **av)
335 {
336 do_defhost(av[0], av[1]);
337 }
338
339 /* CHGNAME - forwarded */
340 static void m_chgname(char *source, int ac, char **av)
341 {
342 do_defname(av[0], av[1]);
343 }
344
345 /* CHGIDENT - forwarded */
346 static void m_chgident(char *source, int ac, char **av)
347 {
348 do_defname(av[0], av[1]);
349 }
350
351 /* SETNAME - forwarded */
352 static void m_setname(char *source, int ac, char **av)
353 {
354 do_defname(source, av[0]);
355 }
356
357 /* SETIDENT - forwarded */
358 static void m_setident(char *source, int ac, char **av)
359 {
360 do_defident(source, av[0]);
361 }
362
363 #endif
364
365 #ifdef IRCD_UNREAL
366
367 /* SDESC - forwarded */
368 static void m_sdesc(char *source, int ac, char **av)
369 {
370 do_sdesc(source, av[0]);
371 }
372
373 /* SWHOIS - forwarded */
374 static void m_swhois(char *source, int ac, char **av)
375 {
376 do_swhois(source, av[0]);
377 }
378
379
380 #endif
381
382 #if defined(IRCD_UNREAL)||defined(IRCD_ULTI28)
383 /* SETHOST - forwarded */
384 static void m_sethost(char *source, int ac, char **av)
385 {
386 do_defhost(source, av[0]);
387 }
388 #endif
389
390 #if defined(IRCD_ULTIMATE)
391
392 /* SETHOST - forwarded */
393 static void m_sethost(char *source, int ac, char **av)
394 {
395 do_defhost(av[0], av[1]);
396 }
397
398 #endif
399
400 #ifdef IRCD_HYBRID
401
402 /* REALHOST - forwarded */
403 static void m_realhost(char *source, int ac, char **av)
404 {
405 mylog("NBPARAMS : %d", ac);
406 if (ac > 1)
407 do_realhost(av[0], av[1]);
408 else
409 do_realhost(av[0], "");
410 }
411 #endif
412
413 /*************************************************************************/
414 Message messages[] = {
415
416 {"PASS", NULL}
417 ,
418 {"PING", m_ping}
419 ,
420 {"SERVER", m_server}
421 ,
422 {"VERSION", m_version}
423 ,
424 {"SQUIT", m_squit}
425 ,
426 {"NICK", m_nick}
427 ,
428 {"KILL", m_kill}
429 ,
430 {"SJOIN", m_sjoin}
431 ,
432 {"KICK", m_kick}
433 ,
434 {"SVSMODE", m_svsmode}
435 ,
436 {"PART", m_part}
437 ,
438 {"MODE", m_mode}
439 ,
440 {"TOPIC", m_topic}
441 ,
442 #ifdef IRCD_HYBRID
443 {"TBURST", m_tburst}
444 ,
445 #endif /* IRCD_HYBRID */
446 {"QUIT", m_quit}
447 ,
448 {"STATS", m_stats}
449 ,
450 {"JOIN", m_join}
451 ,
452 {"AWAY", m_away}
453 ,
454 {"ERROR", m_error}
455 ,
456 {"SQLINE", NULL}
457 ,
458 {"NOTICE", NULL}
459 ,
460 {"GNOTICE", NULL}
461 ,
462 {"SZLINE", NULL}
463 ,
464 {"CAPAB", NULL}
465 ,
466 {"SVINFO", NULL}
467 ,
468 {"SGLINE", NULL}
469 ,
470 {"UNSGLINE", NULL}
471 ,
472 {"UNSZLINE", NULL}
473 ,
474 {"AKILL", NULL}
475 ,
476 {"GLOBOPS", NULL}
477 ,
478 {"WALLOPS", NULL}
479 ,
480 {"SVSKILL", NULL}
481 ,
482 {"RAKILL", NULL}
483 ,
484 {"CHATOPS", NULL}
485 ,
486 {"LUSERS", m_lusers}
487 ,
488 {"ADMIN", m_admin}
489 ,
490 {"MOTD", m_motd}
491 ,
492 {"TIME", m_time}
493 ,
494
495 #ifdef IRCD_ULTI28
496 {"VCTRL", NULL}
497 ,
498 {"PROTOCTL", NULL}
499 ,
500 {"SNETINFO", NULL}
501 ,
502 {"CHGHOST", m_chghost}
503 ,
504 {"CHGIDENT", m_chgident}
505 ,
506 {"CHGNAME", m_chgname}
507 ,
508 {"SETHOST", m_sethost}
509 ,
510 {"SETIDENT", m_setident}
511 ,
512 {"SETNAME", m_setname}
513 ,
514 {"FAILOPS", NULL}
515 ,
516 {"GCONNECT", NULL}
517 ,
518 {"NETINFO", NULL}
519 ,
520 {"ADG", NULL}
521 ,
522 {"NETG", NULL}
523 ,
524 {"NETGLOBAL", NULL}
525 ,
526 {"GNOTICE", NULL}
527 ,
528 {"GLINE", NULL}
529 ,
530 {"GOPER", NULL}
531 ,
532 {"GNOTICE", NULL}
533 ,
534 {"GOPER", NULL}
535 ,
536 {"GCLIENT", NULL}
537 ,
538 #endif
539 #ifdef IRCD_ULTIMATE
540 {"VCTRL", NULL}
541 ,
542 {"GCONNECT", NULL}
543 ,
544 {"NETGLOBAL", NULL}
545 ,
546 {"GNOTICE", NULL}
547 ,
548 {"GOPER", NULL}
549 ,
550 {"GNOTICE", NULL}
551 ,
552 {"GOPER", NULL}
553 ,
554 {"NETCTRL", NULL}
555 ,
556 {"EOBURST", NULL}
557 ,
558 {"NETINFO", NULL}
559 ,
560 {"SETHOST", m_sethost}
561 ,
562 {"SMODE", m_mode}
563 ,
564 #endif
565 #ifdef IRCD_UNREAL
566 {"HELP", NULL}
567 ,
568 {"PROTOCTL", NULL}
569 ,
570 {"TKL", NULL}
571 ,
572 {"SMO", NULL}
573 ,
574 {"SDESC", m_sdesc}
575 ,
576 {"SVS2MODE", m_svsmode}
577 ,
578 {"GOPER", NULL}
579 ,
580 {"NETINFO", NULL}
581 ,
582 {"CHGHOST", m_chghost}
583 ,
584 {"CHGIDENT", m_chgident}
585 ,
586 {"CHGNAME", m_chgname}
587 ,
588 {"SETHOST", m_sethost}
589 ,
590 {"SETIDENT", m_setident}
591 ,
592 {"SETNAME", m_setname}
593 ,
594 {"SWHOIS", m_swhois}
595 ,
596 {"EOS", NULL}
597 ,
598 #endif
599 #ifdef IRCD_HYBRID
600 {"REALHOST", m_realhost}
601 ,
602 #endif
603 {NULL}
604 };
605
606 /*************************************************************************/
607
608 Message *find_message(const char *name)
609 {
610 Message *m;
611 for (m = messages; m->name; m++)
612 if (stricmp(name, m->name) == 0)
613 return m;
614 return NULL;
615 }
616
617 /*************************************************************************/