/[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.63 - (show annotations) (download) (as text)
Fri Aug 10 23:51:20 2001 UTC (18 years, 3 months ago) by ite
Branch: MAIN
Changes since 1.62: +12 -12 lines
File MIME type: text/x-chdr
Gettext phase 1: created a dummy _() macro, replaced old get_lang #defines with the respective string entries in english.*.lang and removed them.

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