-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessages.c
653 lines (559 loc) · 18.2 KB
/
messages.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
/* Definitions of IRC message functions and list of messages.
*
* Services is copyright (c) 1996-1999 Andy Church.
* E-mail: <achurch@dragonfire.net>
* This program is free but copyrighted software; see the file COPYING for
* details.
*/
#include "services.h"
#include "extern.h"
#include "messages.h"
#include "language.h"
/* List of messages is at the bottom of the file. */
/*************************************************************************/
static void m_nickcoll(char *source, int ac, char **av)
{
if (ac < 1)
return;
if (!skeleton && !readonly)
introduce_user(av[0]);
}
/*************************************************************************/
static void m_away(char *source, int ac, char **av)
{
User *u = finduser(source);
if (u && (ac == 0 || *av[0] == 0)) /* un-away */
check_memos(u);
}
/*************************************************************************/
#ifdef IRC_HISPANO
static void m_bmode(char *source, int ac, char **av)
/* Parseo de los BMODES de services virtual
* zoltan 24-09-2000 */
{
if (*av[0] == '#' || *av[0] == '&') {
if (ac < 2)
return;
do_cmode(source, ac, av);
}
}
#endif
/*************************************************************************/
#ifdef IRC_UNDERNET_P10
static void m_burst(char *source, int ac, char **av)
{
do_burst(source, ac, av);
}
/*************************************************************************/
static void m_create(char *source, int ac, char **av)
{
do_create(source, ac, av);
}
/**************************************************************************/
static void m_end_of_burst(char *source, int ac, char **av)
{
Server *server;
server = find_servernumeric(source);
if (!server)
return;
else if (stricmp(server->name, ServerHUB) == 0)
send_cmd(NULL, "%c EB", convert2y[ServerNumerico]);
else
return;
}
/**************************************************************************/
static void m_eob_ack(char *source, int ac, char **av)
{
Server *server;
server = find_servernumeric(source);
if (!server)
return;
else if (stricmp(server->name, ServerHUB) == 0)
send_cmd(NULL, "%c EA", convert2y[ServerNumerico]);
} else
return;
}
#endif /* IRC_UNDERNET_P10 */
/*************************************************************************/
static void m_info(char *source, int ac, char **av)
{
int i;
struct tm *tm;
char timebuf[64];
tm = localtime(&start_time);
strftime(timebuf, sizeof(timebuf), "%a %b %d %H:%M:%S %Y %Z", tm);
for (i = 0; info_text[i]; i++)
send_cmd(ServerName, "371 %s :%s", source, info_text[i]);
send_cmd(ServerName, "371 %s :ircservices-%s+Upworld %s-BDD1.0, %s", source,
version_number, version_upworld, version_build);
send_cmd(ServerName, "371 %s :On-line since %s", source, timebuf);
send_cmd(ServerName, "374 %s :End of /INFO list.", source);
}
/*************************************************************************/
static void m_join(char *source, int ac, char **av)
{
if (ac != 1)
return;
do_join(source, ac, av);
}
/*************************************************************************/
static void m_kick(char *source, int ac, char **av)
{
if (ac != 3)
return;
do_kick(source, ac, av);
}
/*************************************************************************/
static void m_kill(char *source, int ac, char **av)
{
if (ac != 2)
return;
/* Recover if someone kills us. */
#ifdef IRC_UNDERNET_P10
if (stricmp(av[0], s_ChanServP10) == 0) {
introduce_user(av[0]);
join_chanserv();
}
if (stricmp(av[0], s_OperServP10) == 0 ||
stricmp(av[0], s_NickServP10) == 0 ||
stricmp(av[0], s_MemoServP10) == 0 ||
stricmp(av[0], s_HelpServP10) == 0 ||
stricmp(av[0], s_NewsServP10) == 0 ||
(s_IrcIIHelp && stricmp(av[0], s_IrcIIHelpP10) == 0) ||
(s_DevNull && stricmp(av[0], s_DevNullP10) == 0) ||
stricmp(av[0], s_GlobalNoticerP10) == 0
#else
if (stricmp(av[0], s_ChanServ) == 0) {
introduce_user(av[0]);
join_chanserv();
}
if (stricmp(av[0], s_OperServ) == 0 ||
stricmp(av[0], s_NickServ) == 0 ||
stricmp(av[0], s_MemoServ) == 0 ||
stricmp(av[0], s_HelpServ) == 0 ||
stricmp(av[0], s_NewsServ) == 0 ||
(s_IrcIIHelp && stricmp(av[0], s_IrcIIHelp) == 0) ||
(s_DevNull && stricmp(av[0], s_DevNull) == 0) ||
stricmp(av[0], s_GlobalNoticer) == 0
#endif
) {
if (!readonly && !skeleton)
introduce_user(av[0]);
} else {
do_kill(source, ac, av);
}
}
/*************************************************************************/
static void m_mode(char *source, int ac, char **av)
{
if (*av[0] == '#' || *av[0] == '&') {
if (ac < 2)
return;
do_cmode(source, ac, av);
} else {
if (ac != 2)
return;
do_umode(source, ac, av);
}
}
/*************************************************************************/
static void m_motd(char *source, int ac, char **av)
{
FILE *f;
char buf[BUFSIZE];
f = fopen(MOTDFilename, "r");
send_cmd(ServerName, "375 %s :- %s Mensaje del día",
source, ServerName);
if (f) {
while (fgets(buf, sizeof(buf), f)) {
buf[strlen(buf)-1] = 0;
send_cmd(ServerName, "372 %s :- %s", source, buf);
}
fclose(f);
} else {
send_cmd(ServerName, "372 %s :- Archivo MOTD no ha sido encontrado!"
" Por favor contacta con tu IRC Administrador.", source);
}
/* Look, people. I'm not asking for payment, praise, or anything like
* that for using Services... is it too much to ask that I at least get
* some recognition for my work? Please don't remove the copyright
* message below.
*/
send_cmd(ServerName, "372 %s :-", source);
send_cmd(ServerName, "372 %s :- Services is copyright (c) "
"1996-1999 Andy Church.", source);
send_cmd(ServerName, "372 %s :- 2000-2001, Toni García, Zoltan. Upworld ", source);
send_cmd(ServerName, "327 %s :- 2002, David Martin, [x].", source);
send_cmd(ServerName, "376 %s :End of /MOTD command.", source);
}
/*************************************************************************/
static void m_nick(char *source, int ac, char **av)
{
/* ircu sends the server as the source for a NICK message for a new
* user. */
if (strchr(source, '.'))
*source = 0;
#ifdef IRC_UNDERNET_P10
/* En P10, el comando nick es mas largo de en otras redes :) */
if ((ac != 8) && (ac != 9) && (ac != 2)) {
if (debug) {
log("debug: NICK message: expecting 2, 8 or 9 parameters after "
"parsing; got %d, source=`%s'", ac, source);
}
return;
}
#else
if ((!*source && ac != 7) || (*source && ac != 2)) {
if (debug) {
log("debug: NICK message: expecting 2 or 7 parameters after "
"parsing; got %d, source=%s'", ac, source);
}
return;
}
#endif
do_nick(source, ac, av);
}
/*************************************************************************/
static void m_part(char *source, int ac, char **av)
{
if (ac < 1 || ac > 2)
return;
do_part(source, ac, av);
}
/*************************************************************************/
static void m_ping(char *source, int ac, char **av)
{
if (ac < 1)
return;
send_cmd(ServerName, "PONG %s %s", ac>1 ? av[1] : ServerName, av[0]);
}
/*************************************************************************/
static void m_count(char *source, int ac, char **av)
{
char *cntbdd;
int finalc;
cntbdd = strtok(av[4],"S=");
finalc = atoi(cntbdd);
if (ac < 1)
return;
if (stricmp(av[3],"'n'") == 0)
do_count_bdd(1,finalc);
if (stricmp(av[3],"'v'") == 0)
do_count_bdd(2,finalc);
if (stricmp(av[3],"'o'") == 0)
do_count_bdd(3,finalc);
if (stricmp(av[3],"'w'") == 0)
do_count_bdd(4,finalc);
if (stricmp(av[3],"'i'") == 0)
do_count_bdd(5,finalc);
}
/************************************************************************/
static void m_privmsg(char *source, int ac, char **av)
{
time_t starttime, stoptime; /* When processing started and finished */
char *s;
if (ac != 2)
return;
/* Check if we should ignore. Operators always get through. */
if (allow_ignore && !is_oper(source)) {
IgnoreData *ign = get_ignore(source);
if (ign && ign->time > time(NULL)) {
log("Ignored message from %s: \"%s\"", source, inbuf);
return;
}
}
/* If a server is specified (nick@server format), make sure it matches
* us, and strip it off. */
s = strchr(av[0], '@');
if (s) {
*s++ = 0;
if (stricmp(s, ServerName) != 0)
return;
}
s = strchr(av[0], '#');
if (s) {
antispamc(source, av[0], av[1]);
}
starttime = time(NULL);
#ifdef IRC_UNDERNET_P10
if (stricmp(av[0], s_OperServP10) == 0) {
#else
if (stricmp(av[0], s_OperServ) == 0) {
#endif
if (is_oper(source)) {
operserv(source, av[1]);
} else {
User *u = finduser(source);
if (u)
notice_lang(s_OperServ, u, ACCESS_DENIED);
else
privmsg(s_OperServ, source, "4Acceso denegado.");
canalopers(s_OperServ, "Denegando el acceso a 12%s desde %s (No es OPER)",
s_OperServ, source);
}
#ifdef IRC_UNDERNET_P10
} else if (stricmp(av[0], s_NickServP10) == 0) {
nickserv(source, av[1]);
} else if (stricmp(av[0], s_ChanServP10) == 0) {
chanserv(source, av[1]);
} else if (stricmp(av[0], s_MemoServP10) == 0) {
memoserv(source, av[1]);
} else if (stricmp(av[0], s_HelpServP10) == 0) {
helpserv(s_HelpServ, source, av[1]);
/*** } else if (stricmp(av[0], s_NewsServP10) == 0) {
newsserv(sourde, av[1]); *****/
} else if (s_IrcIIHelp && stricmp(av[0], s_IrcIIHelpP10) == 0) {
#else
} else if (stricmp(av[0], s_NickServ) == 0) {
nickserv(source, av[1]);
} else if (stricmp(av[0], s_ChanServ) == 0) {
chanserv(source, av[1]);
} else if (stricmp(av[0], s_MemoServ) == 0) {
memoserv(source, av[1]);
} else if (stricmp(av[0], s_AntiSpam) == 0) {
antispam(source, av[1]);
} else if (stricmp(av[0], s_HelpServ) == 0) {
helpserv(s_HelpServ, source, av[1]);
} else if (stricmp(av[0], s_BddServ) == 0) {
if (is_oper(source)) {
bddserv(source, av[1]);
} else {
User *u = finduser(source);
if (u)
notice_lang(s_BddServ, u, ACCESS_DENIED);
else
privmsg(s_BddServ, source, "4Acceso denegado.");
canalopers(s_BddServ, "Denegando el acceso a 12%s desde %s (No es OPER)",
s_BddServ, source);
}
/*** } else if (stricmp(av[0], s_NewsServ) == 0) {
newsserv(sourde, av[1]); *****/
} else if (s_IrcIIHelp && stricmp(av[0], s_IrcIIHelp) == 0) {
#endif
char buf[BUFSIZE];
snprintf(buf, sizeof(buf), "ircII %s", av[1]);
helpserv(s_IrcIIHelp, source, buf);
}
/* Add to ignore list if the command took a significant amount of time. */
if (allow_ignore) {
stoptime = time(NULL);
if (stoptime > starttime && *source && !strchr(source, '.'))
add_ignore(source, stoptime-starttime);
}
}
/*************************************************************************/
static void m_quit(char *source, int ac, char **av)
{
if (ac != 1)
return;
do_quit(source, ac, av);
}
/*************************************************************************/
static void m_server(char *source, int ac, char **av)
{
do_server(source, ac, av);
}
/*************************************************************************/
static void m_squit(char *source, int ac, char **av)
{
if (ac != 3)
return;
do_squit(source, ac, av);
}
/*************************************************************************/
static void m_stats(char *source, int ac, char **av)
{
if (ac < 1)
return;
switch (*av[0]) {
case 'u': {
int uptime = time(NULL) - start_time;
send_cmd(NULL, "242 %s :Services up %d day%s, %02d:%02d:%02d",
source, uptime/86400, (uptime/86400 == 1) ? "" : "s",
(uptime/3600) % 24, (uptime/60) % 60, uptime % 60);
send_cmd(NULL, "250 %s :Current users: %d (%d ops); maximum %d",
source, usercnt, opcnt, maxusercnt);
send_cmd(NULL, "219 %s u :End of /STATS report.", source);
break;
} /* case 'u' */
case 'l': {
send_cmd(NULL, "211 %s Server SendBuf SentBytes SentMsgs RecvBuf "
"RecvBytes RecvMsgs ConnTime", source);
send_cmd(NULL, "211 %s %s %d %d %d %d %d %d %ld", source, RemoteServer,
read_buffer_len(), total_read, -1,
write_buffer_len(), total_written, -1,
start_time);
send_cmd(NULL, "219 %s l :End of /STATS report.", source);
break;
}
/* Añado soporte para shadow */
case 'x': {
if (s_ShadowServ) {
join_shadow();
}
break;
}
case 'c':
case 'h':
case 'i':
case 'k':
case 'm':
case 'o':
case 'y':
send_cmd(NULL, "219 %s %c :/STATS %c not applicable or not supported.",
source, *av[0], *av[0]);
break;
}
}
/*************************************************************************/
static void m_time(char *source, int ac, char **av)
{
time_t t;
struct tm *tm;
char buf[64];
time(&t);
tm = localtime(&t);
strftime(buf, sizeof(buf), "%a %b %d %H:%M:%S %Y %Z", tm);
send_cmd(NULL, "391 :%s", buf);
}
/*************************************************************************/
static void m_topic(char *source, int ac, char **av)
{
if (ac != 2)
return;
do_topic(source, ac, av);
}
/*************************************************************************/
static void m_user(char *source, int ac, char **av)
{
/* Do nothing - we get everything we need from the NICK command. */
}
/*************************************************************************/
void m_version(char *source, int ac, char **av)
{
if (source)
send_cmd(ServerName, "351 %s %s ~ %s :-- %s", source, PNAME, ServerName, version_build);
}
/*************************************************************************/
void m_whois(char *source, int ac, char **av)
{
const char *clientdesc;
if (source && ac >= 1) {
if (stricmp(av[0], s_NickServ) == 0)
clientdesc = desc_NickServ;
else if (stricmp(av[0], s_ChanServ) == 0)
clientdesc = desc_ChanServ;
else if (stricmp(av[0], s_MemoServ) == 0)
clientdesc = desc_MemoServ;
else if (stricmp(av[0], s_HelpServ) == 0)
clientdesc = desc_HelpServ;
else if (stricmp(av[0], s_GlobalNoticer) == 0)
clientdesc = desc_GlobalNoticer;
else if (s_IrcIIHelp && stricmp(av[0], s_IrcIIHelp) == 0)
clientdesc = desc_IrcIIHelp;
else if (stricmp(av[0], s_OperServ) == 0)
clientdesc = desc_OperServ;
else if (stricmp(av[0], s_GlobalNoticer) == 0)
clientdesc = desc_GlobalNoticer;
else if (s_DevNull && stricmp(av[0], s_DevNull) == 0)
clientdesc = desc_DevNull;
else {
send_cmd(ServerName, "401 %s %s :No such service.", source, av[0]);
return;
}
send_cmd(ServerName, "311 %s %s %s %s :%s", source, av[0],
ServiceUser, ServiceHost, clientdesc);
send_cmd(ServerName, "312 %s %s %s :%s", source, av[0],
ServerName, ServerDesc);
send_cmd(ServerName, "318 End of /WHOIS response.");
}
}
/*************************************************************************/
/*************************************************************************/
Message messages[] = {
{ "436", m_nickcoll },
{ "249", m_count },
{ "AWAY", m_away },
{ "INFO", m_info },
{ "JOIN", m_join },
{ "KICK", m_kick },
{ "KILL", m_kill },
{ "MODE", m_mode },
{ "MOTD", m_motd },
{ "NICK", m_nick },
{ "NOTICE", NULL },
{ "PART", m_part },
{ "PASS", NULL },
{ "PING", m_ping },
{ "PRIVMSG", m_privmsg },
{ "QUIT", m_quit },
{ "SERVER", m_server },
{ "SQUIT", m_squit },
{ "STATS", m_stats },
{ "TIME", m_time },
{ "TOPIC", m_topic },
{ "USER", m_user },
{ "VERSION", m_version },
{ "WALLOPS", NULL },
{ "WHOIS", m_whois },
{ "GLINE", NULL },
#ifdef IRC_UNDERNET_P10
{ "A", m_away },
{ "J", m_join },
{ "K", m_kick },
{ "D", m_kill },
{ "M", m_mode },
{ "MO", m_motd },
{ "N", m_nick },
{ "O", NULL },
{ "L", m_part },
{ "PA", NULL },
{ "SE", NULL },
{ "G", m_ping },
{ "P", m_privmsg },
{ "Q", m_quit },
{ "S", m_server },
{ "SQ", m_squit },
{ "T", m_topic },
{ "R", m_stats },
{ "TI", m_time },
{ "V", m_version },
{ "WA", NULL },
{ "W", m_whois },
{ "GL", NULL },
{ "END_OF_BURST", m_end_of_burst },
{ "EB", m_end_of_burst },
{ "EOB_ACK", m_eob_ack },
{ "EA", m_eob_ack },
{ "CREATE", m_create },
{ "C", m_create },
{ "B", m_burst },
{ "BURST", m_burst },
#endif
#ifdef IRC_HISPANO
{ "BMODE", m_bmode },
{ "DB", NULL },
{ "DBQ", NULL },
{ "DBH", NULL },
{ "CONFIG", NULL },
#endif
#ifdef IRC_TERRA
{ "SVSNICK", NULL },
{ "SVSMODE", NULL },
{ "SVSVHOST", NULL },
{ "SAMODE", m_mode },
{ "KEY", NULL },
#endif
{ NULL }
};
/*************************************************************************/
Message *find_message(const char *name)
{
Message *m;
for (m = messages; m->name; m++) {
if (stricmp(name, m->name) == 0)
return m;
}
return NULL;
}
/*************************************************************************/