/[cvs]/eggdrop1.9/src/cmds.c
ViewVC logotype

Contents of /eggdrop1.9/src/cmds.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.43 - (show annotations) (download) (as text)
Wed Nov 8 19:43:46 2000 UTC (19 years, 1 month ago) by guppy
Branch: MAIN
Changes since 1.42: +15 -5 lines
File MIME type: text/x-chdr
guppy: Applied Sup's patch so you cannot unlink directly linked bots.

1 /*
2 * cmds.c -- handles:
3 * commands from a user via dcc
4 * (split in 2, this portion contains no-irc commands)
5 *
6 * $Id: cmds.c,v 1.42 2000/09/18 20:01:41 fabian Exp $
7 */
8 /*
9 * Copyright (C) 1997 Robey Pointer
10 * Copyright (C) 1999, 2000 Eggheads
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 */
26
27 #include "main.h"
28 #include "tandem.h"
29 #include "modules.h"
30 #include <ctype.h>
31
32 extern struct chanset_t *chanset;
33 extern struct dcc_t *dcc;
34 extern struct userrec *userlist;
35 extern tcl_timer_t *timer, *utimer;
36 extern int dcc_total, remote_boots, backgrd, make_userfile,
37 do_restart, conmask, require_p, must_be_owner,
38 strict_host;
39 extern unsigned long otraffic_irc, otraffic_irc_today,
40 itraffic_irc, itraffic_irc_today,
41 otraffic_bn, otraffic_bn_today,
42 itraffic_bn, itraffic_bn_today,
43 otraffic_dcc, otraffic_dcc_today,
44 itraffic_dcc, itraffic_dcc_today,
45 otraffic_trans, otraffic_trans_today,
46 itraffic_trans, itraffic_trans_today,
47 otraffic_unknown, otraffic_unknown_today,
48 itraffic_unknown, itraffic_unknown_today;
49 extern Tcl_Interp *interp;
50 extern char botnetnick[], origbotname[], ver[], network[],
51 owner[], spaces[];
52 extern time_t now, online_since;
53
54
55 static char *btos(int);
56
57
58 /* Add hostmask to a bot's record if possible.
59 */
60 static int add_bot_hostmask(int idx, char *nick)
61 {
62 struct chanset_t *chan;
63
64 for (chan = chanset; chan; chan = chan->next)
65 if (channel_active(chan)) {
66 memberlist *m = ismember(chan, nick);
67
68 if (m) {
69 char s[UHOSTLEN];
70 struct userrec *u;
71
72 egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
73 u = get_user_by_host(s);
74 if (u) {
75 dprintf(idx, "(Can't add hostmask for %s because it matches %s)\n",
76 nick, u->handle);
77 return 0;
78 }
79 if (strchr("~^+=-", m->userhost[0]))
80 egg_snprintf(s, sizeof s, "*!%s%s", strict_host ? "?" : "", m->userhost+1);
81 else
82 egg_snprintf(s, sizeof s, "*!%s", m->userhost);
83 dprintf(idx, "(Added hostmask for %s from %s)\n", nick, chan->dname);
84 addhost_by_handle(nick, s);
85 return 1;
86 }
87 }
88 return 0;
89 }
90
91 static void tell_who(struct userrec *u, int idx, int chan)
92 {
93 int i, k, ok = 0, atr = u ? u->flags : 0, len;
94 char s[1024]; /* temp fix - 1.4 has a better one */
95
96 if (chan == 0)
97 dprintf(idx, "Party line members: (* = owner, + = master, @ = op)\n");
98 else {
99 simple_sprintf(s, "assoc %d", chan);
100 if ((Tcl_Eval(interp, s) != TCL_OK) || !interp->result[0])
101 dprintf(idx,
102 "People on channel %s%d: (* = owner, + = master, @ = op)\n",
103 (chan < 100000) ? "" : "*", chan % 100000);
104 else
105 dprintf(idx,
106 "People on channel '%s' (%s%d): (* = owner, + = master, @ = op)\n",
107 interp->result, (chan < 100000) ? "" : "*", chan % 100000);
108 }
109 for (i = 0; i < dcc_total; i++)
110 if (dcc[i].type == &DCC_CHAT)
111 if (dcc[i].u.chat->channel == chan) {
112 spaces[len = HANDLEN - strlen(dcc[i].nick)] = 0;
113 if (atr & USER_OWNER) {
114 sprintf(s, " [%.2lu] %c%s%s %s",
115 dcc[i].sock, (geticon(i) == '-' ? ' ' : geticon(i)),
116 dcc[i].nick, spaces, dcc[i].host);
117 } else {
118 sprintf(s, " %c%s%s %s",
119 (geticon(i) == '-' ? ' ' : geticon(i)),
120 dcc[i].nick, spaces, dcc[i].host);
121 }
122 spaces[len] = ' ';
123 if (atr & USER_MASTER) {
124 if (dcc[i].u.chat->con_flags)
125 sprintf(&s[strlen(s)], " (con:%s)",
126 masktype(dcc[i].u.chat->con_flags));
127 }
128 if (now - dcc[i].timeval > 300) {
129 unsigned long days, hrs, mins;
130
131 days = (now - dcc[i].timeval) / 86400;
132 hrs = ((now - dcc[i].timeval) - (days * 86400)) / 3600;
133 mins = ((now - dcc[i].timeval) - (hrs * 3600)) / 60;
134 if (days > 0)
135 sprintf(&s[strlen(s)], " (idle %lud%luh)", days, hrs);
136 else if (hrs > 0)
137 sprintf(&s[strlen(s)], " (idle %luh%lum)", hrs, mins);
138 else
139 sprintf(&s[strlen(s)], " (idle %lum)", mins);
140 }
141 dprintf(idx, "%s\n", s);
142 if (dcc[i].u.chat->away != NULL)
143 dprintf(idx, " AWAY: %s\n", dcc[i].u.chat->away);
144 }
145 for (i = 0; i < dcc_total; i++)
146 if (dcc[i].type == &DCC_BOT) {
147 if (!ok) {
148 ok = 1;
149 dprintf(idx, "Bots connected:\n");
150 }
151 egg_strftime(s, 14, "%d %b %H:%M", localtime(&dcc[i].timeval));
152 spaces[len = HANDLEN - strlen(dcc[i].nick)] = 0;
153 if (atr & USER_OWNER) {
154 dprintf(idx, " [%.2lu] %s%c%s%s (%s) %s\n",
155 dcc[i].sock, dcc[i].status & STAT_CALLED ? "<-" : "->",
156 dcc[i].status & STAT_SHARE ? '+' : ' ',
157 dcc[i].nick, spaces, s, dcc[i].u.bot->version);
158 } else {
159 dprintf(idx, " %s%c%s%s (%s) %s\n",
160 dcc[i].status & STAT_CALLED ? "<-" : "->",
161 dcc[i].status & STAT_SHARE ? '+' : ' ',
162 dcc[i].nick, spaces, s, dcc[i].u.bot->version);
163 }
164 spaces[len] = ' ';
165 }
166 ok = 0;
167 for (i = 0; i < dcc_total; i++) {
168 if ((dcc[i].type == &DCC_CHAT) && (dcc[i].u.chat->channel != chan)) {
169 if (!ok) {
170 ok = 1;
171 dprintf(idx, "Other people on the bot:\n");
172 }
173 spaces[len = HANDLEN - strlen(dcc[i].nick)] = 0;
174 if (atr & USER_OWNER) {
175 sprintf(s, " [%.2lu] %c%s%s ",
176 dcc[i].sock,
177 (geticon(i) == '-' ? ' ' : geticon(i)), dcc[i].nick,
178 spaces);
179 } else {
180 sprintf(s, " %c%s%s ",
181 (geticon(i) == '-' ? ' ' : geticon(i)), dcc[i].nick,
182 spaces);
183 }
184 spaces[len] = ' ';
185 if (atr & USER_MASTER) {
186 if (dcc[i].u.chat->channel < 0)
187 strcat(s, "(-OFF-) ");
188 else if (dcc[i].u.chat->channel == 0)
189 strcat(s, "(party) ");
190 else
191 sprintf(&s[strlen(s)], "(%5d) ", dcc[i].u.chat->channel);
192 }
193 strcat(s, dcc[i].host);
194 if (atr & USER_MASTER) {
195 if (dcc[i].u.chat->con_flags)
196 sprintf(&s[strlen(s)], " (con:%s)",
197 masktype(dcc[i].u.chat->con_flags));
198 }
199 if (now - dcc[i].timeval > 300) {
200 k = (now - dcc[i].timeval) / 60;
201 if (k < 60)
202 sprintf(&s[strlen(s)], " (idle %dm)", k);
203 else
204 sprintf(&s[strlen(s)], " (idle %dh%dm)", k / 60, k % 60);
205 }
206 dprintf(idx, "%s\n", s);
207 if (dcc[i].u.chat->away != NULL)
208 dprintf(idx, " AWAY: %s\n", dcc[i].u.chat->away);
209 }
210 if ((atr & USER_MASTER) && (dcc[i].type->flags & DCT_SHOWWHO) &&
211 (dcc[i].type != &DCC_CHAT)) {
212 if (!ok) {
213 ok = 1;
214 dprintf(idx, "Other people on the bot:\n");
215 }
216 spaces[len = HANDLEN - strlen(dcc[i].nick)] = 0;
217 if (atr & USER_OWNER) {
218 sprintf(s, " [%.2lu] %c%s%s (files) %s",
219 dcc[i].sock, dcc[i].status & STAT_CHAT ? '+' : ' ',
220 dcc[i].nick, spaces, dcc[i].host);
221 } else {
222 sprintf(s, " %c%s%s (files) %s",
223 dcc[i].status & STAT_CHAT ? '+' : ' ',
224 dcc[i].nick, spaces, dcc[i].host);
225 }
226 spaces[len] = ' ';
227 dprintf(idx, "%s\n", s);
228 }
229 }
230 }
231
232 static void cmd_botinfo(struct userrec *u, int idx, char *par)
233 {
234 char s[512], s2[32];
235 struct chanset_t *chan;
236 time_t now2;
237 int hr, min;
238
239 Context;
240 chan = chanset;
241 now2 = now - online_since;
242 s2[0] = 0;
243 if (now2 > 86400) {
244 int days = now2 / 86400;
245
246 /* Days */
247 sprintf(s2, "%d day", days);
248 if (days >= 2)
249 strcat(s2, "s");
250 strcat(s2, ", ");
251 now2 -= days * 86400;
252 }
253 hr = (time_t) ((int) now2 / 3600);
254 now2 -= (hr * 3600);
255 min = (time_t) ((int) now2 / 60);
256 sprintf(&s2[strlen(s2)], "%02d:%02d", (int) hr, (int) min);
257 putlog(LOG_CMDS, "*", "#%s# botinfo", dcc[idx].nick);
258 simple_sprintf(s, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
259 botnet_send_infoq(-1, s);
260 s[0] = 0;
261 if (module_find("server", 0, 0)) {
262 while (chan != NULL) {
263 if (!channel_secret(chan)) {
264 if ((strlen(s) + strlen(chan->dname) + strlen(network)
265 + strlen(botnetnick) + strlen(ver) + 1) >= 490) {
266 strcat(s,"++ ");
267 break; /* yeesh! */
268 }
269 strcat(s, chan->dname);
270 strcat(s, ", ");
271 }
272 chan = chan->next;
273 }
274
275 if (s[0]) {
276 s[strlen(s) - 2] = 0;
277 dprintf(idx, "*** [%s] %s <%s> (%s) [UP %s]\n", botnetnick,
278 ver, network, s, s2);
279 } else
280 dprintf(idx, "*** [%s] %s <%s> (%s) [UP %s]\n", botnetnick,
281 ver, network, BOT_NOCHANNELS, s2);
282 } else
283 dprintf(idx, "*** [%s] %s <NO_IRC> [UP %s]\n", botnetnick, ver, s2);
284 }
285
286 static void cmd_whom(struct userrec *u, int idx, char *par)
287 {
288 if (par[0] == '*') {
289 putlog(LOG_CMDS, "*", "#%s# whom %s", dcc[idx].nick, par);
290 answer_local_whom(idx, -1);
291 return;
292 } else if (dcc[idx].u.chat->channel < 0) {
293 dprintf(idx, "You have chat turned off.\n");
294 return;
295 }
296 putlog(LOG_CMDS, "*", "#%s# whom %s", dcc[idx].nick, par);
297 if (!par[0]) {
298 answer_local_whom(idx, dcc[idx].u.chat->channel);
299 } else {
300 int chan = -1;
301
302 if ((par[0] < '0') || (par[0] > '9')) {
303 Tcl_SetVar(interp, "chan", par, 0);
304 if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
305 interp->result[0]) {
306 chan = atoi(interp->result);
307 }
308 if (chan <= 0) {
309 dprintf(idx, "No such channel.\n");
310 return;
311 }
312 } else
313 chan = atoi(par);
314 if ((chan < 0) || (chan > 99999)) {
315 dprintf(idx, "Channel # out of range: must be 0-99999\n");
316 return;
317 }
318 answer_local_whom(idx, chan);
319 }
320 }
321
322 static void cmd_me(struct userrec *u, int idx, char *par)
323 {
324 int i;
325
326 if (dcc[idx].u.chat->channel < 0) {
327 dprintf(idx, "You have chat turned off.\n");
328 return;
329 }
330 if (!par[0]) {
331 dprintf(idx, "Usage: me <action>\n");
332 return;
333 }
334 if (dcc[idx].u.chat->away != NULL)
335 not_away(idx);
336 for (i = 0; i < dcc_total; i++)
337 if ((dcc[i].type->flags & DCT_CHAT) &&
338 (dcc[i].u.chat->channel == dcc[idx].u.chat->channel) &&
339 ((i != idx) || (dcc[i].status & STAT_ECHO)))
340 dprintf(i, "* %s %s\n", dcc[idx].nick, par);
341 botnet_send_act(idx, botnetnick, dcc[idx].nick,
342 dcc[idx].u.chat->channel, par);
343 check_tcl_act(dcc[idx].nick, dcc[idx].u.chat->channel, par);
344 }
345
346 static void cmd_motd(struct userrec *u, int idx, char *par)
347 {
348 int i;
349
350 if (par[0]) {
351 putlog(LOG_CMDS, "*", "#%s# motd %s", dcc[idx].nick, par);
352 if (!egg_strcasecmp(par, botnetnick))
353 show_motd(idx);
354 else {
355 i = nextbot(par);
356 if (i < 0)
357 dprintf(idx, "That bot isn't connected.\n");
358 else {
359 char x[40];
360
361 simple_sprintf(x, "%s%d:%s@%s",
362 (u->flags & USER_HIGHLITE) ?
363 ((dcc[idx].status & STAT_TELNET) ? "#" : "!") : "",
364 dcc[idx].sock, dcc[idx].nick, botnetnick);
365 botnet_send_motd(i, x, par);
366 }
367 }
368 } else {
369 putlog(LOG_CMDS, "*", "#%s# motd", dcc[idx].nick);
370 show_motd(idx);
371 }
372 }
373
374 static void cmd_away(struct userrec *u, int idx, char *par)
375 {
376 if (strlen(par) > 60)
377 par[60] = 0;
378 set_away(idx, par);
379 }
380
381 static void cmd_back(struct userrec *u, int idx, char *par)
382 {
383 not_away(idx);
384 }
385
386 static void cmd_newpass(struct userrec *u, int idx, char *par)
387 {
388 char *new;
389
390 if (!par[0]) {
391 dprintf(idx, "Usage: newpass <newpassword>\n");
392 return;
393 }
394 new = newsplit(&par);
395 if (strlen(new) > 16)
396 new[16] = 0;
397 if (strlen(new) < 6) {
398 dprintf(idx, "Please use at least 6 characters.\n");
399 return;
400 }
401 set_user(&USERENTRY_PASS, u, new);
402 putlog(LOG_CMDS, "*", "#%s# newpass...", dcc[idx].nick);
403 dprintf(idx, "Changed password to '%s'\n", new);
404 }
405
406 static void cmd_bots(struct userrec *u, int idx, char *par)
407 {
408 putlog(LOG_CMDS, "*", "#%s# bots", dcc[idx].nick);
409 tell_bots(idx);
410 }
411
412 static void cmd_bottree(struct userrec *u, int idx, char *par)
413 {
414 putlog(LOG_CMDS, "*", "#%s# bottree", dcc[idx].nick);
415 tell_bottree(idx, 0);
416 }
417
418 static void cmd_vbottree(struct userrec *u, int idx, char *par)
419 {
420 putlog(LOG_CMDS, "*", "#%s# vbottree", dcc[idx].nick);
421 tell_bottree(idx, 1);
422 }
423
424 static void cmd_rehelp(struct userrec *u, int idx, char *par)
425 {
426 putlog(LOG_CMDS, "*", "#%s# rehelp", dcc[idx].nick);
427 dprintf(idx, "Reload help cache...\n");
428 reload_help_data();
429 }
430
431 static void cmd_help(struct userrec *u, int idx, char *par)
432 {
433 struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
434
435 get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
436 if (par[0]) {
437 putlog(LOG_CMDS, "*", "#%s# help %s", dcc[idx].nick, par);
438 if (!strcmp(par, "all"))
439 tellallhelp(idx, "all", &fr);
440 else if (strchr(par, '*') || strchr(par, '?')) {
441 char *p = par;
442
443 /* Check if the search pattern only consists of '*' and/or '?'
444 * If it does, show help for "all" instead of listing all help
445 * entries.
446 */
447 for (p = par; *p && ((*p == '*') || (*p == '?')); p++);
448 if (*p)
449 tellwildhelp(idx, par, &fr);
450 else
451 tellallhelp(idx, "all", &fr);
452 } else
453 tellhelp(idx, par, &fr, 0);
454 } else {
455 putlog(LOG_CMDS, "*", "#%s# help", dcc[idx].nick);
456 if (glob_op(fr) || glob_botmast(fr) || chan_op(fr))
457 tellhelp(idx, "help", &fr, 0);
458 else
459 tellhelp(idx, "helpparty", &fr, 0);
460 }
461 }
462
463 static void cmd_addlog(struct userrec *u, int idx, char *par)
464 {
465 if (!par[0]) {
466 dprintf(idx, "Usage: addlog <message>\n");
467 return;
468 }
469 dprintf(idx, "Placed entry in the log file.\n");
470 putlog(LOG_MISC, "*", "%s: %s", dcc[idx].nick, par);
471 }
472
473 static void cmd_who(struct userrec *u, int idx, char *par)
474 {
475 int i;
476
477 if (par[0]) {
478 if (dcc[idx].u.chat->channel < 0) {
479 dprintf(idx, "You have chat turned off.\n");
480 return;
481 }
482 putlog(LOG_CMDS, "*", "#%s# who %s", dcc[idx].nick, par);
483 if (!egg_strcasecmp(par, botnetnick))
484 tell_who(u, idx, dcc[idx].u.chat->channel);
485 else {
486 i = nextbot(par);
487 if (i < 0) {
488 dprintf(idx, "That bot isn't connected.\n");
489 } else if (dcc[idx].u.chat->channel > 99999)
490 dprintf(idx, "You are on a local channel\n");
491 else {
492 char s[40];
493
494 simple_sprintf(s, "%d:%s@%s", dcc[idx].sock,
495 dcc[idx].nick, botnetnick);
496 botnet_send_who(i, s, par, dcc[idx].u.chat->channel);
497 }
498 }
499 } else {
500 putlog(LOG_CMDS, "*", "#%s# who", dcc[idx].nick);
501 if (dcc[idx].u.chat->channel < 0)
502 tell_who(u, idx, 0);
503 else
504 tell_who(u, idx, dcc[idx].u.chat->channel);
505 }
506 }
507
508 static void cmd_whois(struct userrec *u, int idx, char *par)
509 {
510 if (!par[0]) {
511 dprintf(idx, "Usage: whois <handle>\n");
512 return;
513 }
514 putlog(LOG_CMDS, "*", "#%s# whois %s", dcc[idx].nick, par);
515 tell_user_ident(idx, par, u ? (u->flags & USER_MASTER) : 0);
516 }
517
518 static void cmd_match(struct userrec *u, int idx, char *par)
519 {
520 int start = 1, limit = 20;
521 char *s, *s1, *chname;
522
523 if (!par[0]) {
524 dprintf(idx, "Usage: match <nick/host> [[skip] count]\n");
525 return;
526 }
527 putlog(LOG_CMDS, "*", "#%s# match %s", dcc[idx].nick, par);
528 s = newsplit(&par);
529 if (strchr(CHANMETA, par[0]) != NULL)
530 chname = newsplit(&par);
531 else
532 chname = "";
533 if (atoi(par) > 0) {
534 s1 = newsplit(&par);
535 if (atoi(par) > 0) {
536 start = atoi(s1);
537 limit = atoi(par);
538 } else
539 limit = atoi(s1);
540 }
541 tell_users_match(idx, s, start, limit, u ? (u->flags & USER_MASTER) : 0,
542 chname);
543 }
544
545 static void cmd_uptime(struct userrec *u, int idx, char *par)
546 {
547 putlog(LOG_CMDS, "*", "#%s# uptime", dcc[idx].nick);
548 tell_verbose_uptime(idx);
549 }
550
551 static void cmd_status(struct userrec *u, int idx, char *par)
552 {
553 int atr = u ? u->flags : 0;
554
555 if (!egg_strcasecmp(par, "all")) {
556 if (!(atr & USER_MASTER)) {
557 dprintf(idx, "You do not have Bot Master privileges.\n");
558 return;
559 }
560 putlog(LOG_CMDS, "*", "#%s# status all", dcc[idx].nick);
561 tell_verbose_status(idx);
562 tell_mem_status_dcc(idx);
563 dprintf(idx, "\n");
564 tell_settings(idx);
565 do_module_report(idx, 1, NULL);
566 } else {
567 putlog(LOG_CMDS, "*", "#%s# status", dcc[idx].nick);
568 tell_verbose_status(idx);
569 tell_mem_status_dcc(idx);
570 do_module_report(idx, 0, NULL);
571 }
572 }
573
574 static void cmd_dccstat(struct userrec *u, int idx, char *par)
575 {
576 putlog(LOG_CMDS, "*", "#%s# dccstat", dcc[idx].nick);
577 tell_dcc(idx);
578 }
579
580 static void cmd_boot(struct userrec *u, int idx, char *par)
581 {
582 int i, files = 0, ok = 0;
583 char *who;
584 struct userrec *u2;
585
586 if (!par[0]) {
587 dprintf(idx, "Usage: boot nick[@bot]\n");
588 return;
589 }
590 who = newsplit(&par);
591 if (strchr(who, '@') != NULL) {
592 char whonick[HANDLEN + 1];
593
594 splitcn(whonick, who, '@', HANDLEN);
595 if (!egg_strcasecmp(who, botnetnick)) {
596 cmd_boot(u, idx, whonick);
597 return;
598 }
599 if (remote_boots > 0) {
600 i = nextbot(who);
601 if (i < 0) {
602 dprintf(idx, "No such bot connected.\n");
603 return;
604 }
605 botnet_send_reject(i, dcc[idx].nick, botnetnick, whonick,
606 who, par[0] ? par : dcc[idx].nick);
607 putlog(LOG_BOTS, "*", "#%s# boot %s@%s (%s)", dcc[idx].nick, whonick,
608 who, par[0] ? par : dcc[idx].nick);
609 } else
610 dprintf(idx, "Remote boots are disabled here.\n");
611 return;
612 }
613 for (i = 0; i < dcc_total; i++)
614 if (!egg_strcasecmp(dcc[i].nick, who)
615 && !ok && (dcc[i].type->flags & DCT_CANBOOT)) {
616 u2 = get_user_by_handle(userlist, dcc[i].nick);
617 if (u2 && (u2->flags & USER_OWNER)
618 && egg_strcasecmp(dcc[idx].nick, who)) {
619 dprintf(idx, "Can't boot the bot owner.\n");
620 return;
621 }
622 if (u2 && (u2->flags & USER_MASTER) && !(u && (u->flags & USER_MASTER))) {
623 dprintf(idx, "Can't boot a bot master.\n");
624 return;
625 }
626 files = (dcc[i].type->flags & DCT_FILES);
627 if (files)
628 dprintf(idx, "Booted %s from the file section.\n", dcc[i].nick);
629 else
630 dprintf(idx, "Booted %s from the bot.\n", dcc[i].nick);
631 putlog(LOG_CMDS, "*", "#%s# boot %s %s", dcc[idx].nick, who, par);
632 do_boot(i, dcc[idx].nick, par);
633 ok = 1;
634 }
635 if (!ok)
636 dprintf(idx, "Who? No such person on the party line.\n");
637 }
638
639 static void cmd_console(struct userrec *u, int idx, char *par)
640 {
641 char *nick, s[2], s1[512];
642 int dest = 0, i, ok = 0, pls, md;
643 struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
644 module_entry *me;
645
646 if (!par[0]) {
647 dprintf(idx, "Your console is %s: %s (%s)\n",
648 dcc[idx].u.chat->con_chan,
649 masktype(dcc[idx].u.chat->con_flags),
650 maskname(dcc[idx].u.chat->con_flags));
651 return;
652 }
653 get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
654 strcpy(s1, par);
655 nick = newsplit(&par);
656 /* Don't remove '+' as someone couldn't have '+' in CHANMETA cause
657 * he doesn't use IRCnet ++rtc.
658 */
659 if (nick[0] && !strchr(CHANMETA "+-*", nick[0]) && glob_master(fr)) {
660 for (i = 0; i < dcc_total; i++)
661 if (!egg_strcasecmp(nick, dcc[i].nick) &&
662 (dcc[i].type == &DCC_CHAT) && (!ok)) {
663 ok = 1;
664 dest = i;
665 }
666 if (!ok) {
667 dprintf(idx, "No such user on the party line!\n");
668 return;
669 }
670 nick[0] = 0;
671 } else
672 dest = idx;
673 if (!nick[0])
674 nick = newsplit(&par);
675 /* Consider modeless channels, starting with '+' */
676 if ((nick [0] == '+' && findchan_by_dname(nick)) ||
677 (nick [0] != '+' && strchr(CHANMETA "*", nick[0]))) {
678 if (strcmp(nick, "*") && !findchan_by_dname(nick)) {
679 dprintf(idx, "Invalid console channel: %s\n", nick);
680 return;
681 }
682 get_user_flagrec(u, &fr, nick);
683 if (!chan_op(fr) && !(glob_op(fr) && !chan_deop(fr))) {
684 dprintf(idx, "You don't have op or master access to channel %s\n",
685 nick);
686 return;
687 }
688 strncpy(dcc[dest].u.chat->con_chan, nick, 81);
689 dcc[dest].u.chat->con_chan[80] = 0;
690 nick[0] = 0;
691 if ((dest == idx) && !glob_master(fr) && !chan_master(fr))
692 /* Consoling to another channel for self */
693 dcc[dest].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_WALL);
694 }
695 if (!nick[0])
696 nick = newsplit(&par);
697 pls = 1;
698 if (nick[0]) {
699 if ((nick[0] != '+') && (nick[0] != '-'))
700 dcc[dest].u.chat->con_flags = 0;
701 for (; *nick; nick++) {
702 if (*nick == '+')
703 pls = 1;
704 else if (*nick == '-')
705 pls = 0;
706 else {
707 s[0] = *nick;
708 s[1] = 0;
709 md = logmodes(s);
710 if ((dest == idx) && !glob_master(fr) && pls) {
711 if (chan_master(fr))
712 md &= ~(LOG_FILES | LOG_LEV1 | LOG_LEV2 | LOG_LEV3 |
713 LOG_LEV4 | LOG_LEV5 | LOG_LEV6 | LOG_LEV7 |
714 LOG_LEV8 | LOG_DEBUG);
715 else
716 md &= ~(LOG_MISC | LOG_CMDS | LOG_FILES | LOG_LEV1 |
717 LOG_LEV2 | LOG_LEV3 | LOG_LEV4 | LOG_LEV5 |
718 LOG_LEV6 | LOG_LEV7 | LOG_LEV8 | LOG_WALL |
719 LOG_DEBUG);
720 }
721 if (!glob_owner(fr) && pls)
722 md &= ~(LOG_RAW | LOG_SRVOUT | LOG_BOTNET | LOG_BOTSHARE);
723 if (!glob_botmast(fr) && pls)
724 md &= ~LOG_BOTS;
725 if (pls)
726 dcc[dest].u.chat->con_flags |= md;
727 else
728 dcc[dest].u.chat->con_flags &= ~md;
729 }
730 }
731 }
732 putlog(LOG_CMDS, "*", "#%s# console %s", dcc[idx].nick, s1);
733 if (dest == idx) {
734 dprintf(idx, "Set your console to %s: %s (%s)\n",
735 dcc[idx].u.chat->con_chan,
736 masktype(dcc[idx].u.chat->con_flags),
737 maskname(dcc[idx].u.chat->con_flags));
738 } else {
739 dprintf(idx, "Set console of %s to %s: %s (%s)\n", dcc[dest].nick,
740 dcc[dest].u.chat->con_chan,
741 masktype(dcc[dest].u.chat->con_flags),
742 maskname(dcc[dest].u.chat->con_flags));
743 dprintf(dest, "%s set your console to %s: %s (%s)\n", dcc[idx].nick,
744 dcc[dest].u.chat->con_chan,
745 masktype(dcc[dest].u.chat->con_flags),
746 maskname(dcc[dest].u.chat->con_flags));
747 }
748 /* New style autosave -- drummer,07/25/1999*/
749 if ((me = module_find("console", 1, 1))) {
750 Function *func = me->funcs;
751 (func[CONSOLE_DOSTORE]) (dest);
752 }
753 }
754
755 static void cmd_pls_bot(struct userrec *u, int idx, char *par)
756 {
757 char *handle, *addr, *p, *q, *host;
758 struct userrec *u1;
759 struct bot_addr *bi;
760
761 if (!par[0])
762 dprintf(idx, "Usage: +bot <handle> <address[:telnet-port[/relay-port]]> [host]\n");
763 else {
764 handle = newsplit(&par);
765 addr = newsplit(&par);
766 if (strlen(handle) > HANDLEN)
767 handle[HANDLEN] = 0; /* max len = XX .. for the moment :) */
768 if (get_user_by_handle(userlist, handle))
769 dprintf(idx, "Someone already exists by that name.\n");
770 else if (strchr(BADHANDCHARS, handle[0]) != NULL)
771 dprintf(idx, "You can't start a botnick with '%c'.\n", handle[0]);
772 else {
773 if (strlen(addr) > 60)
774 addr[60] = 0;
775 putlog(LOG_CMDS, "*", "#%s# +bot %s %s", dcc[idx].nick, handle, addr);
776 userlist = adduser(userlist, handle, "none", "-", USER_BOT);
777 u1 = get_user_by_handle(userlist, handle);
778 bi = user_malloc(sizeof(struct bot_addr));
779
780 q = strchr(addr, ':');
781 if (!q) {
782 bi->address = user_malloc(strlen(addr) + 1);
783 strcpy(bi->address, addr);
784 bi->telnet_port = 3333;
785 bi->relay_port = 3333;
786 } else {
787 bi->address = user_malloc(q - addr + 1);
788 strncpy(bi->address, addr, q - addr);
789 bi->address[q - addr] = 0;
790 p = q + 1;
791 bi->telnet_port = atoi(p);
792 q = strchr(p, '/');
793 if (!q) {
794 bi->relay_port = bi->telnet_port;
795 } else {
796 bi->relay_port = atoi(q + 1);
797 }
798 }
799 set_user(&USERENTRY_BOTADDR, u1, bi);
800 dprintf(idx, "Added bot '%s' with address '%s' and no password.\n",
801 handle, addr);
802 host = newsplit(&par);
803 if (host[0]) {
804 addhost_by_handle(handle, host);
805 } else if (!add_bot_hostmask(idx, handle))
806 dprintf(idx, "You'll want to add a hostmask if this bot will ever %s",
807 "be on any channels that I'm on.\n");
808 }
809 }
810 }
811
812 static void cmd_chhandle(struct userrec *u, int idx, char *par)
813 {
814 char hand[HANDLEN + 1], newhand[HANDLEN + 1];
815 int i, atr = u ? u->flags : 0, atr2;
816 struct userrec *u2;
817
818 strncpy(hand, newsplit(&par), sizeof(hand));
819 hand[HANDLEN] = 0;
820 strncpy(newhand, newsplit(&par), sizeof(newhand));
821 newhand[HANDLEN] = 0;
822
823 if (!hand[0] || !newhand[0]) {
824 dprintf(idx, "Usage: chhandle <oldhandle> <newhandle>\n");
825 return;
826 }
827 for (i = 0; i < strlen(newhand); i++)
828 if ((newhand[i] <= 32) || (newhand[i] >= 127) || (newhand[i] == '@'))
829 newhand[i] = '?';
830 if (strchr(BADHANDCHARS, newhand[0]) != NULL)
831 dprintf(idx, "Bizarre quantum forces prevent nicknames from starting with %c\n",
832 newhand[0]);
833 else if (get_user_by_handle(userlist, newhand) &&
834 egg_strcasecmp(hand, newhand))
835 dprintf(idx, "Somebody is already using %s.\n", newhand);
836 else {
837 u2 = get_user_by_handle(userlist, hand);
838 atr2 = u2 ? u2->flags : 0;
839 if ((atr & USER_BOTMAST) && !(atr & USER_MASTER) &&
840 !(atr2 & USER_BOT))
841 dprintf(idx, "You can't change nick for non-bots.\n");
842 else if ((bot_flags(u2) & BOT_SHARE) && !(atr & USER_OWNER))
843 dprintf(idx, "You can't change shared bot's nick.\n");
844 else if ((atr2 & USER_OWNER) && !(atr & USER_OWNER) &&
845 egg_strcasecmp(dcc[idx].nick, hand))
846 dprintf(idx, "Can't change the bot owner's handle.\n");
847 else if (isowner(hand) && egg_strcasecmp(dcc[idx].nick, hand))
848 dprintf(idx, "Can't change the permanent bot owner's handle.\n");
849 else if (!egg_strcasecmp(newhand, botnetnick) && (!(atr2 & USER_BOT) ||
850 nextbot(hand) != -1))
851 dprintf(idx, "Hey! That's MY name!\n");
852 else if (change_handle(u2, newhand)) {
853 putlog(LOG_CMDS, "*", "#%s# chhandle %s %s", dcc[idx].nick,
854 hand, newhand);
855 dprintf(idx, "Changed.\n");
856 } else
857 dprintf(idx, "Failed.\n");
858 }
859 }
860
861 static void cmd_handle(struct userrec *u, int idx, char *par)
862 {
863 char oldhandle[HANDLEN + 1], newhandle[HANDLEN + 1];
864 int i;
865
866 strncpy(newhandle, newsplit(&par), HANDLEN);
867 newhandle[HANDLEN] = 0;
868
869 if (!newhandle[0]) {
870 dprintf(idx, "Usage: handle <new-handle>\n");
871 return;
872 }
873 for (i = 0; i < strlen(newhandle); i++)
874 if ((newhandle[i] <= 32) || (newhandle[i] >= 127) || (newhandle[i] == '@'))
875 newhandle[i] = '?';
876 if (strchr(BADHANDCHARS, newhandle[0]) != NULL) {
877 dprintf(idx, "Bizarre quantum forces prevent handle from starting with '%c'\n",
878 newhandle[0]);
879 } else if (get_user_by_handle(userlist, newhandle) &&
880 egg_strcasecmp(dcc[idx].nick, newhandle)) {
881 dprintf(idx, "Somebody is already using %s.\n", newhandle);
882 } else if (!egg_strcasecmp(newhandle, botnetnick)) {
883 dprintf(idx, "Hey! That's MY name!\n");
884 } else {
885 strncpy(oldhandle, dcc[idx].nick, HANDLEN);
886 oldhandle[HANDLEN] = 0;
887 if (change_handle(u, newhandle)) {
888 putlog(LOG_CMDS, "*", "#%s# handle %s", oldhandle, newhandle);
889 dprintf(idx, "Okay, changed.\n");
890 } else
891 dprintf(idx, "Failed.\n");
892 }
893 }
894
895 static void cmd_chpass(struct userrec *u, int idx, char *par)
896 {
897 char *handle, *new;
898 int atr = u ? u->flags : 0, l;
899
900 if (!par[0])
901 dprintf(idx, "Usage: chpass <handle> [password]\n");
902 else {
903 handle = newsplit(&par);
904 u = get_user_by_handle(userlist, handle);
905 if (!u)
906 dprintf(idx, "No such user.\n");
907 else if ((atr & USER_BOTMAST) && !(atr & USER_MASTER) &&
908 !(u->flags & USER_BOT))
909 dprintf(idx, "You can't change password for non-bots.\n");
910 else if ((bot_flags(u) & BOT_SHARE) && !(atr & USER_OWNER))
911 dprintf(idx, "You can't change shared bot's password.\n");
912 else if ((u->flags & USER_OWNER) && !(atr & USER_OWNER) &&
913 egg_strcasecmp(handle, dcc[idx].nick))
914 dprintf(idx, "Can't change the bot owner's password.\n");
915 else if (isowner(handle) && egg_strcasecmp(dcc[idx].nick, handle))
916 dprintf(idx, "Can't change the permanent bot owner's password.\n");
917 else if (!par[0]) {
918 putlog(LOG_CMDS, "*", "#%s# chpass %s [nothing]", dcc[idx].nick,
919 handle);
920 set_user(&USERENTRY_PASS, u, NULL);
921 dprintf(idx, "Removed password.\n");
922 } else {
923 l = strlen(new = newsplit(&par));
924 if (l > 16)
925 new[16] = 0;
926 if (l < 6)
927 dprintf(idx, "Please use at least 6 characters.\n");
928 else {
929 set_user(&USERENTRY_PASS, u, new);
930 putlog(LOG_CMDS, "*", "#%s# chpass %s [something]", dcc[idx].nick,
931 handle);
932 dprintf(idx, "Changed password.\n");
933 }
934 }
935 }
936 }
937
938 static void cmd_chaddr(struct userrec *u, int idx, char *par)
939 {
940 char *handle, *addr, *p, *q;
941 struct bot_addr *bi;
942 struct userrec *u1;
943
944 if (!par[0]) {
945 dprintf(idx, "Usage: chaddr <botname> <address:botport#/userport#>\n");
946 return;
947 }
948 handle = newsplit(&par);
949 addr = newsplit(&par);
950 if (strlen(addr) > UHOSTMAX)
951 addr[UHOSTMAX] = 0;
952 u1 = get_user_by_handle(userlist, handle);
953 if (!u1 || !(u1->flags & USER_BOT)) {
954 dprintf(idx, "Useful only for tandem bots.\n");
955 return;
956 }
957 if ((bot_flags(u1) & BOT_SHARE) && (!u || !u->flags & USER_OWNER)) {
958 dprintf(idx, "You can't change shared bot's address.\n");
959 return;
960 }
961 putlog(LOG_CMDS, "*", "#%s# chaddr %s %s", dcc[idx].nick, handle, addr);
962 dprintf(idx, "Changed bot's address.\n");
963 bi = user_malloc(sizeof(struct bot_addr));
964
965 q = strchr(addr, ':');
966 if (!q) {
967 bi->address = user_malloc(strlen(addr) + 1);
968 strcpy(bi->address, addr);
969 bi->telnet_port = 3333;
970 bi->relay_port = 3333;
971 } else {
972 bi->address = user_malloc(q - addr + 1);
973 strncpy(bi->address, addr, q - addr);
974 bi->address[q - addr] = 0;
975 p = q + 1;
976 bi->telnet_port = atoi(p);
977 q = strchr(p, '/');
978 if (!q) {
979 bi->relay_port = bi->telnet_port;
980 } else {
981 bi->relay_port = atoi(q + 1);
982 }
983 }
984 set_user(&USERENTRY_BOTADDR, u1, bi);
985 }
986
987 static void cmd_comment(struct userrec *u, int idx, char *par)
988 {
989 char *handle;
990 struct userrec *u1;
991
992 if (!par[0]) {
993 dprintf(idx, "Usage: comment <handle> <newcomment>\n");
994 return;
995 }
996 handle = newsplit(&par);
997 u1 = get_user_by_handle(userlist, handle);
998 if (!u1) {
999 dprintf(idx, "No such user!\n");
1000 return;
1001 }
1002 if ((u1->flags & USER_OWNER) && !(u && (u->flags & USER_OWNER)) &&
1003 egg_strcasecmp(handle, dcc[idx].nick)) {
1004 dprintf(idx, "Can't change comment on the bot owner.\n");
1005 return;
1006 }
1007 putlog(LOG_CMDS, "*", "#%s# comment %s %s", dcc[idx].nick, handle, par);
1008 if (!egg_strcasecmp(par, "none")) {
1009 dprintf(idx, "Okay, comment blanked.\n");
1010 set_user(&USERENTRY_COMMENT, u1, NULL);
1011 return;
1012 }
1013 dprintf(idx, "Changed comment.\n");
1014 set_user(&USERENTRY_COMMENT, u1, par);
1015 }
1016
1017 static void cmd_restart(struct userrec *u, int idx, char *par)
1018 {
1019 putlog(LOG_CMDS, "*", "#%s# restart", dcc[idx].nick);
1020 if (!backgrd) {
1021 dprintf(idx, "You can not .restart a bot when running -n (due to tcl)\n");
1022 return;
1023 }
1024 dprintf(idx, "Restarting.\n");
1025 if (make_userfile) {
1026 putlog(LOG_MISC, "*",
1027 "Uh, guess you don't need to create a new userfile.");
1028 make_userfile = 0;
1029 }
1030 write_userfile(-1);
1031 putlog(LOG_MISC, "*", "Restarting ...");
1032 wipe_timers(interp, &utimer);
1033 wipe_timers(interp, &timer);
1034 do_restart = idx;
1035 }
1036
1037 static void cmd_rehash(struct userrec *u, int idx, char *par)
1038 {
1039 putlog(LOG_CMDS, "*", "#%s# rehash", dcc[idx].nick);
1040 dprintf(idx, "Rehashing.\n");
1041 if (make_userfile) {
1042 putlog(LOG_MISC, "*",
1043 "Uh, guess you don't need to create a new userfile.");
1044 make_userfile = 0;
1045 }
1046 write_userfile(-1);
1047 putlog(LOG_MISC, "*", "Rehashing ...");
1048 do_restart = -2;
1049 }
1050
1051 static void cmd_reload(struct userrec *u, int idx, char *par)
1052 {
1053 putlog(LOG_CMDS, "*", "#%s# reload", dcc[idx].nick);
1054 dprintf(idx, "Reloading user file...\n");
1055 reload();
1056 }
1057
1058 /* NOTE: This gets replaced in the server mod, with a version that handles
1059 * the server disconnect better.
1060 */
1061 void cmd_die(struct userrec *u, int idx, char *par)
1062 {
1063 char s[1024];
1064
1065 putlog(LOG_CMDS, "*", "#%s# die %s", dcc[idx].nick, par);
1066 if (par[0]) {
1067 simple_sprintf(s, "BOT SHUTDOWN (%s: %s)", dcc[idx].nick, par);
1068 } else {
1069 simple_sprintf(s, "BOT SHUTDOWN (authorized by %s)", dcc[idx].nick);
1070 }
1071 chatout("*** %s\n", s);
1072 botnet_send_chat(-1, botnetnick, s);
1073 botnet_send_bye();
1074 write_userfile(-1);
1075 simple_sprintf(s, "DIE BY %s!%s (%s)", dcc[idx].nick,
1076 dcc[idx].host, par[0] ? par : "request");
1077 fatal(s, 0);
1078 }
1079
1080 static void cmd_debug(struct userrec *u, int idx, char *par)
1081 {
1082 if (!egg_strcasecmp(par, "help")) {
1083 putlog(LOG_CMDS, "*", "#%s# debug help", dcc[idx].nick);
1084 debug_help(idx);
1085 } else {
1086 putlog(LOG_CMDS, "*", "#%s# debug", dcc[idx].nick);
1087 debug_mem_to_dcc(idx);
1088 }
1089 }
1090
1091 static void cmd_simul(struct userrec *u, int idx, char *par)
1092 {
1093 char *nick;
1094 int i, ok = 0;
1095
1096 nick = newsplit(&par);
1097 if (!par[0]) {
1098 dprintf(idx, "Usage: simul <hand> <text>\n");
1099 return;
1100 }
1101 if (isowner(nick)) {
1102 dprintf(idx, "Unable to '.simul' permanent owners.\n");
1103 return;
1104 }
1105 for (i = 0; i < dcc_total; i++)
1106 if (!egg_strcasecmp(nick, dcc[i].nick) && !ok &&
1107 (dcc[i].type->flags & DCT_SIMUL)) {
1108 putlog(LOG_CMDS, "*", "#%s# simul %s %s", dcc[idx].nick, nick, par);
1109 if (dcc[i].type && dcc[i].type->activity) {
1110 dcc[i].type->activity(i, par, strlen(par));
1111 ok = 1;
1112 }
1113 }
1114 if (!ok)
1115 dprintf(idx, "No such user on the party line.\n");
1116 }
1117
1118 static void cmd_link(struct userrec *u, int idx, char *par)
1119 {
1120 char *s;
1121 int i;
1122
1123 if (!par[0]) {
1124 dprintf(idx, "Usage: link [some-bot] <new-bot>\n");
1125 return;
1126 }
1127 putlog(LOG_CMDS, "*", "#%s# link %s", dcc[idx].nick, par);
1128 s = newsplit(&par);
1129 if (!par[0] || !egg_strcasecmp(par, botnetnick))
1130 botlink(dcc[idx].nick, idx, s);
1131 else {
1132 char x[40];
1133
1134 i = nextbot(s);
1135 if (i < 0) {
1136 dprintf(idx, "No such bot online.\n");
1137 return;
1138 }
1139 simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1140 botnet_send_link(i, x, s, par);
1141 }
1142 }
1143
1144 static void cmd_unlink(struct userrec *u, int idx, char *par)
1145 {
1146 int i;
1147 char *bot;
1148
1149 if (!par[0]) {
1150 dprintf(idx, "Usage: unlink <bot> [reason]\n");
1151 return;
1152 }
1153 putlog(LOG_CMDS, "*", "#%s# unlink %s", dcc[idx].nick, par);
1154 bot = newsplit(&par);
1155 i = nextbot(bot);
1156 if (i < 0) {
1157 botunlink(idx, bot, par);
1158 return;
1159 }
1160 /* If we're directly connected to that bot, just do it
1161 * (is nike gunna sue?)
1162 */
1163 if (!egg_strcasecmp(dcc[i].nick, bot))
1164 botunlink(idx, bot, par);
1165 else {
1166 char x[40];
1167
1168 simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1169 botnet_send_unlink(i, x, lastbot(bot), bot, par);
1170 }
1171 }
1172
1173 static void cmd_relay(struct userrec *u, int idx, char *par)
1174 {
1175 if (!par[0]) {
1176 dprintf(idx, "Usage: relay <bot>\n");
1177 return;
1178 }
1179 putlog(LOG_CMDS, "*", "#%s# relay %s", dcc[idx].nick, par);
1180 tandem_relay(idx, par, 0);
1181 }
1182
1183 static void cmd_save(struct userrec *u, int idx, char *par)
1184 {
1185 putlog(LOG_CMDS, "*", "#%s# save", dcc[idx].nick);
1186 dprintf(idx, "Saving user file...\n");
1187 write_userfile(-1);
1188 }
1189
1190 static void cmd_backup(struct userrec *u, int idx, char *par)
1191 {
1192 putlog(LOG_CMDS, "*", "#%s# backup", dcc[idx].nick);
1193 dprintf(idx, "Backing up the user file...\n");
1194 backup_userfile();
1195 }
1196
1197 static void cmd_trace(struct userrec *u, int idx, char *par)
1198 {
1199 int i;
1200 char x[NOTENAMELEN + 11], y[11];
1201
1202 if (!par[0]) {
1203 dprintf(idx, "Usage: trace <botname>\n");
1204 return;
1205 }
1206 if (!egg_strcasecmp(par, botnetnick)) {
1207 dprintf(idx, "That's me! Hiya! :)\n");
1208 return;
1209 }
1210 i = nextbot(par);
1211 if (i < 0) {
1212 dprintf(idx, "Unreachable bot.\n");
1213 return;
1214 }
1215 putlog(LOG_CMDS, "*", "#%s# trace %s", dcc[idx].nick, par);
1216 simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1217 simple_sprintf(y, ":%d", now);
1218 botnet_send_trace(i, x, par, y);
1219 }
1220
1221 static void cmd_binds(struct userrec *u, int idx, char *par)
1222 {
1223 putlog(LOG_CMDS, "*", "#%s# binds %s", dcc[idx].nick, par);
1224 tell_binds(idx, par);
1225 }
1226
1227 static void cmd_banner(struct userrec *u, int idx, char *par)
1228 {
1229 char s[1024];
1230 int i;
1231
1232 if (!par[0]) {
1233 dprintf(idx, "Usage: banner <message>\n");
1234 return;
1235 }
1236 simple_sprintf(s, "\007\007### Botwide:[%s] %s\n", dcc[idx].nick, par);
1237 for (i = 0; i < dcc_total; i++)
1238 if (dcc[i].type->flags & DCT_MASTER)
1239 dprintf(i, "%s", s);
1240 }
1241
1242 /* After messing with someone's user flags, make sure the dcc-chat flags
1243 * are set correctly.
1244 */
1245 int check_dcc_attrs(struct userrec *u, int oatr)
1246 {
1247 int i, stat;
1248 char *p, *q, s[121];
1249
1250 /* If it matches someone in the owner list, make sure he/she has +n */
1251 if (!u)
1252 return 0;
1253 /* Make sure default owners are +n */
1254 if (owner[0]) {
1255 q = owner;
1256 p = strchr(q, ',');
1257 while (p) {
1258 strncpy(s, q, p - q);
1259 s[p - q] = 0;
1260 rmspace(s);
1261 if (!egg_strcasecmp(u->handle, s))
1262 u->flags = sanity_check(u->flags | USER_OWNER);
1263 q = p + 1;
1264 p = strchr(q, ',');
1265 }
1266 strcpy(s, q);
1267 rmspace(s);
1268 if (!egg_strcasecmp(u->handle, s))
1269 u->flags = sanity_check(u->flags | USER_OWNER);
1270 }
1271 for (i = 0; i < dcc_total; i++) {
1272 if ((dcc[i].type->flags & DCT_MASTER) &&
1273 (!egg_strcasecmp(u->handle, dcc[i].nick))) {
1274 stat = dcc[i].status;
1275 if ((dcc[i].type == &DCC_CHAT) &&
1276 ((u->flags & (USER_OP | USER_MASTER | USER_OWNER |
1277 USER_BOTMAST))
1278 != (oatr & (USER_OP | USER_MASTER | USER_OWNER |
1279 USER_BOTMAST)))) {
1280 botnet_send_join_idx(i, -1);
1281 }
1282 if ((oatr & USER_MASTER) && !(u->flags & USER_MASTER)) {
1283 struct flag_record fr = {FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
1284
1285 dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_RAW |
1286 LOG_FILES | LOG_LEV1 | LOG_LEV2 |
1287 LOG_LEV3 | LOG_LEV4 | LOG_LEV5 |
1288 LOG_LEV6 | LOG_LEV7 | LOG_LEV8 |
1289 LOG_WALL | LOG_DEBUG);
1290 get_user_flagrec(u, &fr, NULL);
1291 if (!chan_master(fr))
1292 dcc[i].u.chat->con_flags |= (LOG_MISC | LOG_CMDS);
1293 dprintf(i, "*** POOF! ***\n");
1294 dprintf(i, "You are no longer a master on this bot.\n");
1295 }
1296 if (!(oatr & USER_MASTER) && (u->flags & USER_MASTER)) {
1297 dcc[i].u.chat->con_flags |= conmask;
1298 dprintf(i, "*** POOF! ***\n");
1299 dprintf(i, "You are now a master on this bot.\n");
1300 }
1301 if (!(oatr & USER_BOTMAST) && (u->flags & USER_BOTMAST)) {
1302 dprintf(i, "### POOF! ###\n");
1303 dprintf(i, "You are now a botnet master on this bot.\n");
1304 }
1305 if ((oatr & USER_BOTMAST) && !(u->flags & USER_BOTMAST)) {
1306 dprintf(i, "### POOF! ###\n");
1307 dprintf(i, "You are no longer a botnet master on this bot.\n");
1308 }
1309 if (!(oatr & USER_OWNER) && (u->flags & USER_OWNER)) {
1310 dprintf(i, "@@@ POOF! @@@\n");
1311 dprintf(i, "You are now an OWNER of this bot.\n");
1312 }
1313 if ((oatr & USER_OWNER) && !(u->flags & USER_OWNER)) {
1314 dprintf(i, "@@@ POOF! @@@\n");
1315 dprintf(i, "You are no longer an owner of this bot.\n");
1316 }
1317 if ((stat & STAT_PARTY) && (u->flags & USER_OP))
1318 stat &= ~STAT_PARTY;
1319 if (!(stat & STAT_PARTY) && !(u->flags & USER_OP) &&
1320 !(u->flags & USER_MASTER))
1321 stat |= STAT_PARTY;
1322 if ((stat & STAT_CHAT) && !(u->flags & USER_PARTY) &&
1323 !(u->flags & USER_MASTER) &&
1324 (!(u->flags & USER_OP) || require_p))
1325 stat &= ~STAT_CHAT;
1326 if ((dcc[i].type->flags & DCT_FILES) && !(stat & STAT_CHAT) &&
1327 ((u->flags & USER_MASTER) || (u->flags & USER_PARTY) ||
1328 ((u->flags & USER_OP) && !require_p)))
1329 stat |= STAT_CHAT;
1330 dcc[i].status = stat;
1331 /* Check if they no longer have access to wherever they are.
1332 *
1333 * NOTE: DON'T kick someone off the party line just cuz they lost +p
1334 * (pinvite script removes +p after 5 mins automatically)
1335 */
1336 if ((dcc[i].type->flags & DCT_FILES) && !(u->flags & USER_XFER) &&
1337 !(u->flags & USER_MASTER)) {
1338 dprintf(i, "-+- POOF! -+-\n");
1339 dprintf(i, "You no longer have file area access.\n\n");
1340 putlog(LOG_MISC, "*", "DCC user [%s]%s removed from file system",
1341 dcc[i].nick, dcc[i].host);
1342 if (dcc[i].status & STAT_CHAT) {
1343 struct chat_info *ci;
1344
1345 ci = dcc[i].u.file->chat;
1346 nfree(dcc[i].u.file);
1347 dcc[i].u.chat = ci;
1348 dcc[i].status &= (~STAT_CHAT);
1349 dcc[i].type = &DCC_CHAT;
1350 if (dcc[i].u.chat->channel >= 0) {
1351 chanout_but(-1, dcc[i].u.chat->channel,
1352 "*** %s has returned.\n", dcc[i].nick);
1353 Context;
1354 if (dcc[i].u.chat->channel < 100000)
1355 botnet_send_join_idx(i, -1);
1356 }
1357 } else {
1358 killsock(dcc[i].sock);
1359 lostdcc(i);
1360 }
1361 }
1362 }
1363 if (dcc[i].type == &DCC_BOT && !egg_strcasecmp(u->handle, dcc[i].nick)) {
1364 if ((dcc[i].status & STAT_LEAF) && !(u->flags & BOT_LEAF))
1365 dcc[i].status &= ~(STAT_LEAF | STAT_WARNED);
1366 if (!(dcc[i].status & STAT_LEAF) && (u->flags & BOT_LEAF))
1367 dcc[i].status |= STAT_LEAF;
1368 }
1369 }
1370 return u->flags;
1371 }
1372
1373 int check_dcc_chanattrs(struct userrec *u, char *chname, int chflags,
1374 int ochatr)
1375 {
1376 int i, found = 0, atr = u ? u->flags : 0;
1377 struct chanset_t *chan;
1378
1379 if (!u)
1380 return 0;
1381 chan = chanset;
1382 for (i = 0; i < dcc_total; i++) {
1383 if ((dcc[i].type->flags & DCT_MASTER) &&
1384 !egg_strcasecmp(u->handle, dcc[i].nick)) {
1385 if ((dcc[i].type == &DCC_CHAT) &&
1386 ((chflags & (USER_OP | USER_MASTER | USER_OWNER))
1387 != (ochatr & (USER_OP | USER_MASTER | USER_OWNER))))
1388 botnet_send_join_idx(i, -1);
1389 if ((ochatr & USER_MASTER) && !(chflags & USER_MASTER)) {
1390 if (!(atr & USER_MASTER))
1391 dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS);
1392 dprintf(i, "*** POOF! ***\n");
1393 dprintf(i, "You are no longer a master on %s.\n", chname);
1394 }
1395 if (!(ochatr & USER_MASTER) && (chflags & USER_MASTER)) {
1396 dcc[i].u.chat->con_flags |= conmask;
1397 if (!(atr & USER_MASTER))
1398 dcc[i].u.chat->con_flags &=
1399 ~(LOG_LEV1 | LOG_LEV2 | LOG_LEV3 | LOG_LEV4 |
1400 LOG_LEV5 | LOG_LEV6 | LOG_LEV7 | LOG_LEV8 |
1401 LOG_RAW | LOG_DEBUG | LOG_WALL | LOG_FILES | LOG_SRVOUT);
1402 dprintf(i, "*** POOF! ***\n");
1403 dprintf(i, "You are now a master on %s.\n", chname);
1404 }
1405 if (!(ochatr & USER_OWNER) && (chflags & USER_OWNER)) {
1406 dprintf(i, "@@@ POOF! @@@\n");
1407 dprintf(i, "You are now an OWNER of %s.\n", chname);
1408 }
1409 if ((ochatr & USER_OWNER) && !(chflags & USER_OWNER)) {
1410 dprintf(i, "@@@ POOF! @@@\n");
1411 dprintf(i, "You are no longer an owner of %s.\n", chname);
1412 }
1413 if (((ochatr & (USER_OP | USER_MASTER | USER_OWNER)) &&
1414 (!(chflags & (USER_OP | USER_MASTER | USER_OWNER)))) ||
1415 ((chflags & (USER_OP | USER_MASTER | USER_OWNER)) &&
1416 (!(ochatr & (USER_OP | USER_MASTER | USER_OWNER))))) {
1417 struct flag_record fr = {FR_CHAN, 0, 0, 0, 0, 0};
1418
1419 while (chan && !found) {
1420 get_user_flagrec(u, &fr, chan->dname);
1421 if (fr.chan & (USER_OP | USER_MASTER | USER_OWNER))
1422 found = 1;
1423 else
1424 chan = chan->next;
1425 }
1426 if (!chan)
1427 chan = chanset;
1428 if (chan)
1429 strcpy(dcc[i].u.chat->con_chan, chan->dname);
1430 else
1431 strcpy(dcc[i].u.chat->con_chan, "*");
1432 }
1433 }
1434 }
1435 return chflags;
1436 }
1437
1438 static void cmd_chattr(struct userrec *u, int idx, char *par)
1439 {
1440 char *hand, *arg = NULL, *tmpchg = NULL, *chg = NULL, work[1024];
1441 struct chanset_t *chan = NULL;
1442 struct userrec *u2;
1443 struct flag_record pls = {0, 0, 0, 0, 0, 0},
1444 mns = {0, 0, 0, 0, 0, 0},
1445 user = {0, 0, 0, 0, 0, 0};
1446 module_entry *me;
1447 int fl = -1, of = 0, ocf = 0;
1448
1449 if (!par[0]) {
1450 dprintf(idx, "Usage: chattr <handle> [changes] [channel]\n");
1451 return;
1452 }
1453 hand = newsplit(&par);
1454 u2 = get_user_by_handle(userlist, hand);
1455 if (!u2) {
1456 dprintf(idx, "No such user!\n");
1457 return;
1458 }
1459
1460 /* Parse args */
1461 if (par[0]) {
1462 arg = newsplit(&par);
1463 if (par[0]) {
1464 /* .chattr <handle> <changes> <channel> */
1465 chg = arg;
1466 arg = newsplit(&par);
1467 chan = findchan_by_dname(arg);
1468 } else {
1469 chan = findchan_by_dname(arg);
1470 /* Consider modeless channels, starting with '+' */
1471 if (!(arg[0] == '+' && chan) &&
1472 !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
1473 /* .chattr <handle> <changes> */
1474 chg = arg;
1475 chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
1476 arg = NULL;
1477 }
1478 /* .chattr <handle> <channel>: nothing to do... */
1479 }
1480 }
1481 /* arg: pointer to channel name, NULL if none specified
1482 * chan: pointer to channel structure, NULL if none found or none specified
1483 * chg: pointer to changes, NULL if none specified
1484 */
1485 Assert(!(!arg && chan));
1486 if (arg && !chan) {
1487 dprintf(idx, "No channel record for %s.\n", arg);
1488 return;
1489 }
1490 if (chg) {
1491 if (!arg && strpbrk(chg, "&|")) {
1492 /* .chattr <handle> *[&|]*: use console channel if found... */
1493 if (!strcmp ((arg = dcc[idx].u.chat->con_chan), "*"))
1494 arg = NULL;
1495 else
1496 chan = findchan_by_dname(arg);
1497 if (arg && !chan) {
1498 dprintf (idx, "Invalid console channel %s.\n", arg);
1499 return;
1500 }
1501 } else if (arg && !strpbrk(chg, "&|")) {
1502 Context;
1503 tmpchg = nmalloc(strlen(chg) + 2);
1504 strcpy(tmpchg, "|");
1505 strcat(tmpchg, chg);
1506 chg = tmpchg;
1507 }
1508 }
1509 par = arg;
1510 user.match = FR_GLOBAL;
1511 if (chan)
1512 user.match |= FR_CHAN;
1513 get_user_flagrec(u, &user, chan ? chan->dname : 0);
1514 if (!chan && !glob_botmast(user)) {
1515 dprintf(idx, "You do not have Bot Master privileges.\n");
1516 if (tmpchg)
1517 nfree(tmpchg);
1518 return;
1519 }
1520 if (chan && !glob_master(user) && !chan_master(user)) {
1521 dprintf(idx, "You do not have channel master privileges for channel %s\n",
1522 par);
1523 if (tmpchg)
1524 nfree(tmpchg);
1525 return;
1526 }
1527 user.match &= fl;
1528 if (chg) {
1529 pls.match = user.match;
1530 break_down_flags(chg, &pls, &mns);
1531 /* No-one can change these flags on-the-fly */
1532 pls.global &= ~(USER_BOT);
1533 mns.global &= ~(USER_BOT);
1534
1535 if (chan) {
1536 pls.chan &= ~(BOT_SHARE);
1537 mns.chan &= ~(BOT_SHARE);
1538 }
1539 if (!glob_owner(user)) {
1540 pls.global &= ~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1541 mns.global &= ~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1542
1543 if (chan) {
1544 pls.chan &= ~USER_OWNER;
1545 mns.chan &= ~USER_OWNER;
1546 }
1547 if (!glob_master(user)) {
1548 pls.global &= USER_PARTY | USER_XFER;
1549 mns.global &= USER_PARTY | USER_XFER;
1550
1551 if (!glob_botmast(user)) {
1552 pls.global = 0;
1553 mns.global = 0;
1554 }
1555 }
1556 }
1557 if (chan && !chan_owner(user) && !glob_owner(user)) {
1558 pls.chan &= ~USER_MASTER;
1559 mns.chan &= ~USER_MASTER;
1560 if (!chan_master(user) && !glob_master(user)) {
1561 pls.chan = 0;
1562 mns.chan = 0;
1563 }
1564 }
1565 get_user_flagrec(u2, &user, par);
1566 if (user.match & FR_GLOBAL) {
1567 of = user.global;
1568 user.global = sanity_check((user.global |pls.global) &~mns.global);
1569
1570 user.udef_global = (user.udef_global | pls.udef_global)
1571 & ~mns.udef_global;
1572 }
1573 if (chan) {
1574 ocf = user.chan;
1575 user.chan = chan_sanity_check((user.chan | pls.chan) & ~mns.chan,
1576 user.global);
1577
1578 user.udef_chan = (user.udef_chan | pls.udef_chan) & ~mns.udef_chan;
1579 }
1580 set_user_flagrec(u2, &user, par);
1581 }
1582 if (chan)
1583 putlog(LOG_CMDS, "*", "#%s# (%s) chattr %s %s",
1584 dcc[idx].nick, chan ? chan->dname : "*", hand, chg ? chg : "");
1585 else
1586 putlog(LOG_CMDS, "*", "#%s# chattr %s %s", dcc[idx].nick, hand,
1587 chg ? chg : "");
1588 /* Get current flags and display them */
1589 if (user.match & FR_GLOBAL) {
1590 user.match = FR_GLOBAL;
1591 if (chg)
1592 check_dcc_attrs(u2, of);
1593 get_user_flagrec(u2, &user, NULL);
1594 build_flags(work, &user, NULL);
1595 if (work[0] != '-')
1596 dprintf(idx, "Global flags for %s are now +%s\n", hand, work);
1597 else
1598 dprintf(idx, "No global flags for %s.\n", hand);
1599 }
1600 if (chan) {
1601 user.match = FR_CHAN;
1602 get_user_flagrec(u2, &user, par);
1603 user.chan &= ~BOT_SHARE;
1604 if (chg)
1605 check_dcc_chanattrs(u2, chan->dname, user.chan, ocf);
1606 build_flags(work, &user, NULL);
1607 if (work[0] != '-')
1608 dprintf(idx, "Channel flags for %s on %s are now +%s\n", hand,
1609 chan->dname, work);
1610 else
1611 dprintf(idx, "No flags for %s on %s.\n", hand, chan->dname);
1612 if (chg && (me = module_find("irc", 0, 0))) {
1613 Function *func = me->funcs;
1614
1615 if (chan)
1616 (func[IRC_RECHECK_CHANNEL]) (chan, 0);
1617 }
1618 }
1619 if (tmpchg)
1620 nfree(tmpchg);
1621 }
1622
1623 static void cmd_botattr(struct userrec *u, int idx, char *par)
1624 {
1625 char *hand, *chg = NULL, *arg = NULL, *tmpchg = NULL, work[1024];
1626 struct chanset_t *chan = NULL;
1627 struct userrec *u2;
1628 struct flag_record pls = {0, 0, 0, 0, 0, 0},
1629 mns = {0, 0, 0, 0, 0, 0},
1630 user = {0, 0, 0, 0, 0, 0};
1631 int idx2;
1632
1633 if (!par[0]) {
1634 dprintf(idx, "Usage: botattr <handle> [changes] [channel]\n");
1635 return;
1636 }
1637 hand = newsplit(&par);
1638 u2 = get_user_by_handle(userlist, hand);
1639 if (!u2 || !(u2->flags & USER_BOT)) {
1640 dprintf(idx, "No such bot!\n");
1641 return;
1642 }
1643 for (idx2 = 0; idx2 < dcc_total; idx2++)
1644 if (dcc[idx2].type != &DCC_RELAY && dcc[idx2].type != &DCC_FORK_BOT &&
1645 !egg_strcasecmp(dcc[idx2].nick, hand))
1646 break;
1647 if (idx2 != dcc_total) {
1648 dprintf(idx, "You may not change the attributes of a directly linked bot.\n");
1649 return;
1650 }
1651 /* Parse args */
1652 if (par[0]) {
1653 arg = newsplit(&par);
1654 if (par[0]) {
1655 /* .botattr <handle> <changes> <channel> */
1656 chg = arg;
1657 arg = newsplit(&par);
1658 chan = findchan_by_dname(arg);
1659 } else {
1660 chan = findchan_by_dname(arg);
1661 /* Consider modeless channels, starting with '+' */
1662 if (!(arg[0] == '+' && chan) &&
1663 !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
1664 /* .botattr <handle> <changes> */
1665 chg = arg;
1666 chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
1667 arg = NULL;
1668 }
1669 /* .botattr <handle> <channel>: nothing to do... */
1670 }
1671 }
1672 /* arg: pointer to channel name, NULL if none specified
1673 * chan: pointer to channel structure, NULL if none found or none specified
1674 * chg: pointer to changes, NULL if none specified
1675 */
1676 Assert(!(!arg && chan));
1677 if (arg && !chan) {
1678 dprintf(idx, "No channel record for %s.\n", arg);
1679 return;
1680 }
1681 if (chg) {
1682 if (!arg && strpbrk(chg, "&|")) {
1683 /* botattr <handle> *[&|]*: use console channel if found... */
1684 if (!strcmp ((arg = dcc[idx].u.chat->con_chan), "*"))
1685 arg = NULL;
1686 else
1687 chan = findchan_by_dname(arg);
1688 if (arg && !chan) {
1689 dprintf (idx, "Invalid console channel %s.\n", arg);
1690 return;
1691 }
1692 } else if (arg && !strpbrk(chg, "&|")) {
1693 Context;
1694 tmpchg = nmalloc(strlen(chg) + 2);
1695 strcpy (tmpchg, "|");
1696 strcat (tmpchg, chg);
1697 chg = tmpchg;
1698 }
1699 }
1700 par = arg;
1701
1702 user.match = FR_GLOBAL;
1703 get_user_flagrec(u, &user, chan ? chan->dname : 0);
1704 if (!glob_botmast(user)) {
1705 dprintf(idx, "You do not have Bot Master privileges.\n");
1706 if (tmpchg)
1707 nfree(tmpchg);
1708 return;
1709 }
1710 if (chg) {
1711 user.match = FR_BOT | (chan ? FR_CHAN : 0);
1712 pls.match = user.match;
1713 break_down_flags(chg, &pls, &mns);
1714 /* No-one can change these flags on-the-fly */
1715 pls.global &=~BOT_BOT;
1716 mns.global &=~BOT_BOT;
1717
1718 if (chan && glob_owner(user)) {
1719 pls.chan &= BOT_SHARE;
1720 mns.chan &= BOT_SHARE;
1721 } else {
1722 pls.chan = 0;
1723 mns.chan = 0;
1724 }
1725 if (!glob_owner(user)) {
1726 pls.bot &= ~(BOT_SHARE | BOT_GLOBAL);
1727 mns.bot &= ~(BOT_SHARE | BOT_GLOBAL);
1728 }
1729 user.match = FR_BOT | (chan ? FR_CHAN : 0);
1730 get_user_flagrec(u2, &user, par);
1731 user.bot = (user.bot | pls.bot) & ~mns.bot;
1732 if ((user.bot & BOT_SHARE) == BOT_SHARE)
1733 user.bot &= ~BOT_SHARE;
1734 if (chan)
1735 user.chan = (user.chan | pls.chan) & ~mns.chan;
1736 set_user_flagrec(u2, &user, par);
1737 }
1738 if (chan)
1739 putlog(LOG_CMDS, "*", "#%s# (%s) botattr %s %s",
1740 dcc[idx].nick, chan->dname, hand, chg ? chg : "");
1741 else
1742 putlog(LOG_CMDS, "*", "#%s# botattr %s %s", dcc[idx].nick, hand,
1743 chg ? chg : "");
1744 /* get current flags and display them */
1745 if (!chan || pls.bot || mns.bot) {
1746 user.match = FR_BOT;
1747 get_user_flagrec(u2, &user, NULL);
1748 build_flags(work, &user, NULL);
1749 if (work[0] != '-')
1750 dprintf(idx, "Bot flags for %s are now +%s\n", hand, work);
1751 else
1752 dprintf(idx, "No bot flags for %s.\n", hand);
1753 }
1754 if (chan) {
1755 user.match = FR_CHAN;
1756 get_user_flagrec(u2, &user, par);
1757 user.chan &= BOT_SHARE;
1758 build_flags(work, &user, NULL);
1759 if (work[0] != '-')
1760 dprintf(idx, "Bot flags for %s on %s are now +%s\n", hand,
1761 chan->dname, work);
1762 else
1763 dprintf(idx, "No bot flags for %s on %s.\n", hand, chan->dname);
1764 }
1765 if (tmpchg)
1766 nfree(tmpchg);
1767 }
1768
1769 static void cmd_chat(struct userrec *u, int idx, char *par)
1770 {
1771 char *arg;
1772 int newchan, oldchan;
1773 module_entry *me;
1774
1775 arg = newsplit(&par);
1776 if (!egg_strcasecmp(arg, "off")) {
1777 /* Turn chat off */
1778 if (dcc[idx].u.chat->channel < 0) {
1779 dprintf(idx, "You weren't in chat anyway!\n");
1780 return;
1781 } else {
1782 dprintf(idx, "Leaving chat mode...\n");
1783 check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
1784 dcc[idx].u.chat->channel);
1785 chanout_but(-1, dcc[idx].u.chat->channel,
1786 "*** %s left the party line.\n",
1787 dcc[idx].nick);
1788 Context;
1789 if (dcc[idx].u.chat->channel < 100000)
1790 botnet_send_part_idx(idx, "");
1791 }
1792 dcc[idx].u.chat->channel = (-1);
1793 } else {
1794 if (arg[0] == '*') {
1795 if (((arg[1] < '0') || (arg[1] > '9'))) {
1796 if (arg[1] == 0)
1797 newchan = 0;
1798 else {
1799 Tcl_SetVar(interp, "chan", arg, 0);
1800 if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
1801 interp->result[0])
1802 newchan = atoi(interp->result);
1803 else
1804 newchan = -1;
1805 }
1806 if (newchan < 0) {
1807 dprintf(idx, "No channel by that name.\n");
1808 return;
1809 }
1810 } else
1811 newchan = 100000 + atoi(arg + 1);
1812 if (newchan < 100000 || newchan > 199999) {
1813 dprintf(idx, "Channel # out of range: local channels must be *0-*99999\n");
1814 return;
1815 }
1816 } else {
1817 if (((arg[0] < '0') || (arg[0] > '9')) && (arg[0])) {
1818 if (!egg_strcasecmp(arg, "on"))
1819 newchan = 0;
1820 else {
1821 Tcl_SetVar(interp, "chan", arg, 0);
1822 if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
1823 interp->result[0])
1824 newchan = atoi(interp->result);
1825 else
1826 newchan = -1;
1827 }
1828 if (newchan < 0) {
1829 dprintf(idx, "No channel by that name.\n");
1830 return;
1831 }
1832 } else
1833 newchan = atoi(arg);
1834 if ((newchan < 0) || (newchan > 99999)) {
1835 dprintf(idx, "Channel # out of range: must be between 0 and 99999.\n");
1836 return;
1837 }
1838 }
1839 /* If coming back from being off the party line, make sure they're
1840 * not away.
1841 */
1842 if ((dcc[idx].u.chat->channel < 0) && (dcc[idx].u.chat->away != NULL))
1843 not_away(idx);
1844 if (dcc[idx].u.chat->channel == newchan) {
1845 if (newchan == 0) {
1846 dprintf(idx, "You're already on the party line!\n");
1847 return;
1848 } else {
1849 dprintf(idx, "You're already on channel %s%d!\n",
1850 (newchan < 100000) ? "" : "*", newchan % 100000);
1851 return;
1852 }
1853 } else {
1854 oldchan = dcc[idx].u.chat->channel;
1855 if (oldchan >= 0)
1856 check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock, oldchan);
1857 if (oldchan == 0) {
1858 chanout_but(-1, 0, "*** %s left the party line.\n", dcc[idx].nick);
1859 Context;
1860 } else if (oldchan > 0) {
1861 chanout_but(-1, oldchan, "*** %s left the channel.\n", dcc[idx].nick);
1862 Context;
1863 }
1864 dcc[idx].u.chat->channel = newchan;
1865 if (newchan == 0) {
1866 dprintf(idx, "Entering the party line...\n");
1867 chanout_but(-1, 0, "*** %s joined the party line.\n", dcc[idx].nick);
1868 Context;
1869 } else {
1870 dprintf(idx, "Joining channel '%s'...\n", arg);
1871 chanout_but(-1, newchan, "*** %s joined the channel.\n", dcc[idx].nick);
1872 Context;
1873 }
1874 check_tcl_chjn(botnetnick, dcc[idx].nick, newchan, geticon(idx),
1875 dcc[idx].sock, dcc[idx].host);
1876 if (newchan < 100000)
1877 botnet_send_join_idx(idx, oldchan);
1878 else if (oldchan < 100000)
1879 botnet_send_part_idx(idx, "");
1880 }
1881 }
1882 /* New style autosave here too -- rtc, 09/28/1999*/
1883 if ((me = module_find("console", 1, 1))) {
1884 Function *func = me->funcs;
1885 (func[CONSOLE_DOSTORE]) (idx);
1886 }
1887 }
1888
1889 static void cmd_echo(struct userrec *u, int idx, char *par)
1890 {
1891 module_entry *me;
1892
1893 if (!par[0]) {
1894 dprintf(idx, "Echo is currently %s.\n", dcc[idx].status & STAT_ECHO ?
1895 "on" : "off");
1896 return;
1897 }
1898 if (!egg_strcasecmp(par, "on")) {
1899 dprintf(idx, "Echo turned on.\n");
1900 dcc[idx].status |= STAT_ECHO;
1901 } else if (!egg_strcasecmp(par, "off")) {
1902 dprintf(idx, "Echo turned off.\n");
1903 dcc[idx].status &= ~STAT_ECHO;
1904 } else {
1905 dprintf(idx, "Usage: echo <on/off>\n");
1906 return;
1907 }
1908 /* New style autosave here too -- rtc, 09/28/1999*/
1909 if ((me = module_find("console", 1, 1))) {
1910 Function *func = me->funcs;
1911 (func[CONSOLE_DOSTORE]) (idx);
1912 }
1913 }
1914
1915 int stripmodes(char *s)
1916 {
1917 int res = 0;
1918
1919 for (; *s; s++)
1920 switch (tolower(*s)) {
1921 case 'b':
1922 res |= STRIP_BOLD;
1923 break;
1924 case 'c':
1925 res |= STRIP_COLOR;
1926 break;
1927 case 'r':
1928 res |= STRIP_REV;
1929 break;
1930 case 'u':
1931 res |= STRIP_UNDER;
1932 break;
1933 case 'a':
1934 res |= STRIP_ANSI;
1935 break;
1936 case 'g':
1937 res |= STRIP_BELLS;
1938 break;
1939 case '*':
1940 res |= STRIP_ALL;
1941 break;
1942 }
1943 return res;
1944 }
1945
1946 char *stripmasktype(int x)
1947 {
1948 static char s[20];
1949 char *p = s;
1950
1951 if (x & STRIP_BOLD)
1952 *p++ = 'b';
1953 if (x & STRIP_COLOR)
1954 *p++ = 'c';
1955 if (x & STRIP_REV)
1956 *p++ = 'r';
1957 if (x & STRIP_UNDER)
1958 *p++ = 'u';
1959 if (x & STRIP_ANSI)
1960 *p++ = 'a';
1961 if (x & STRIP_BELLS)
1962 *p++ = 'g';
1963 if (p == s)
1964 *p++ = '-';
1965 *p = 0;
1966 return s;
1967 }
1968
1969 static char *stripmaskname(int x)
1970 {
1971 static char s[161];
1972 int i = 0;
1973
1974 s[i] = 0;
1975 if (x & STRIP_BOLD)
1976 i += my_strcpy(s + i, "bold, ");
1977 if (x & STRIP_COLOR)
1978 i += my_strcpy(s + i, "color, ");
1979 if (x & STRIP_REV)
1980 i += my_strcpy(s + i, "reverse, ");
1981 if (x & STRIP_UNDER)
1982 i += my_strcpy(s + i, "underline, ");
1983 if (x & STRIP_ANSI)
1984 i += my_strcpy(s + i, "ansi, ");
1985 if (x & STRIP_BELLS)
1986 i += my_strcpy(s + i, "bells, ");
1987 if (!i)
1988 strcpy(s, "none");
1989 else
1990 s[i - 2] = 0;
1991 return s;
1992 }
1993
1994 static void cmd_strip(struct userrec *u, int idx, char *par)
1995 {
1996 char *nick, *changes, *c, s[2];
1997 int dest = 0, i, pls, md, ok = 0;
1998 module_entry *me;
1999
2000 if (!par[0]) {
2001 dprintf(idx, "Your current strip settings are: %s (%s)\n",
2002 stripmasktype(dcc[idx].u.chat->strip_flags),
2003 stripmaskname(dcc[idx].u.chat->strip_flags));
2004 return;
2005 }
2006 nick = newsplit(&par);
2007 if ((nick[0] != '+') && (nick[0] != '-') && u &&
2008 (u->flags & USER_MASTER)) {
2009 for (i = 0; i < dcc_total; i++)
2010 if (!egg_strcasecmp(nick, dcc[i].nick) && dcc[i].type == &DCC_CHAT &&
2011 !ok) {
2012 ok = 1;
2013 dest = i;
2014 }
2015 if (!ok) {
2016 dprintf(idx, "No such user on the party line!\n");
2017 return;
2018 }
2019 changes = par;
2020 } else {
2021 changes = nick;
2022 nick = "";
2023 dest = idx;
2024 }
2025 c = changes;
2026 if ((c[0] != '+') && (c[0] != '-'))
2027 dcc[dest].u.chat->strip_flags = 0;
2028 s[1] = 0;
2029 for (pls = 1; *c; c++) {
2030 switch (*c) {
2031 case '+':
2032 pls = 1;
2033 break;
2034 case '-':
2035 pls = 0;
2036 break;
2037 default:
2038 s[0] = *c;
2039 md = stripmodes(s);
2040 if (pls == 1)
2041 dcc[dest].u.chat->strip_flags