/[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.75 - (show annotations) (download) (as text)
Sun Oct 21 03:44:30 2001 UTC (18 years, 1 month ago) by stdarg
Branch: MAIN
Changes since 1.74: +4 -2 lines
File MIME type: text/x-chdr
* Applied Oskar Liljeblad's patch to convert more bind tables.
* Fixed bug in putlog which causes an infinite loop.
* Added console error logging into tclscript.mod.
* Added external error logging via "error_logfile" variable, for more detailed information. Default filename is logs/tcl_errors.log.

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