/[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.82 - (show annotations) (download) (as text)
Wed Dec 19 06:25:08 2001 UTC (17 years, 11 months ago) by guppy
Branch: MAIN
Changes since 1.81: +15 -3 lines
File MIME type: text/x-chdr
added Eule's membercheck 2 and 3 patches from eggdrop1.6 (Eule can you please check these over as the diff seemed to fail alot and I had to manually patch it)

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