/[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.58 - (show annotations) (download) (as text)
Tue Jul 3 16:46:08 2001 UTC (18 years, 5 months ago) by guppy
Branch: MAIN
CVS Tags: eggdrop1_6_5
Changes since 1.57: +1 -2 lines
File MIME type: text/x-chdr
BAD POPTIX. BAD.

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.57 2001/07/03 01:33:34 poptix 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[];
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, BOT_NOCHANNELS, 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
757 if (!par[0])
758 dprintf(idx, "Usage: +bot <handle> <address[:telnet-port[/relay-port]]> [host]\n");
759 else {
760 handle = newsplit(&par);
761 addr = newsplit(&par);
762 if (strlen(handle) > HANDLEN)
763 handle[HANDLEN] = 0; /* max len = XX .. for the moment :) */
764 if (get_user_by_handle(userlist, handle))
765 dprintf(idx, "Someone already exists by that name.\n");
766 else if (strchr(BADHANDCHARS, handle[0]) != NULL)
767 dprintf(idx, "You can't start a botnick with '%c'.\n", handle[0]);
768 else {
769 if (strlen(addr) > 60)
770 addr[60] = 0;
771 putlog(LOG_CMDS, "*", "#%s# +bot %s %s", dcc[idx].nick, handle, addr);
772 userlist = adduser(userlist, handle, "none", "-", USER_BOT);
773 u1 = get_user_by_handle(userlist, handle);
774 bi = user_malloc(sizeof(struct bot_addr));
775
776 q = strchr(addr, ':');
777 if (!q) {
778 bi->address = user_malloc(strlen(addr) + 1);
779 strcpy(bi->address, addr);
780 bi->telnet_port = 3333;
781 bi->relay_port = 3333;
782 } else {
783 bi->address = user_malloc(q - addr + 1);
784 strncpy(bi->address, addr, q - addr);
785 bi->address[q - addr] = 0;
786 p = q + 1;
787 bi->telnet_port = atoi(p);
788 q = strchr(p, '/');
789 if (!q) {
790 bi->relay_port = bi->telnet_port;
791 } else {
792 bi->relay_port = atoi(q + 1);
793 }
794 }
795 set_user(&USERENTRY_BOTADDR, u1, bi);
796 dprintf(idx, "Added bot '%s' with address '%s' and no password.\n",
797 handle, addr);
798 host = newsplit(&par);
799 if (host[0]) {
800 addhost_by_handle(handle, host);
801 } else if (!add_bot_hostmask(idx, handle))
802 dprintf(idx, "You'll want to add a hostmask if this bot will ever %s",
803 "be on any channels that I'm on.\n");
804 }
805 }
806 }
807
808 static void cmd_chhandle(struct userrec *u, int idx, char *par)
809 {
810 char hand[HANDLEN + 1], newhand[HANDLEN + 1];
811 int i, atr = u ? u->flags : 0, atr2;
812 struct userrec *u2;
813
814 strncpyz(hand, newsplit(&par), sizeof hand);
815 strncpyz(newhand, newsplit(&par), sizeof newhand);
816
817 if (!hand[0] || !newhand[0]) {
818 dprintf(idx, "Usage: chhandle <oldhandle> <newhandle>\n");
819 return;
820 }
821 for (i = 0; i < strlen(newhand); i++)
822 if ((newhand[i] <= 32) || (newhand[i] >= 127) || (newhand[i] == '@'))
823 newhand[i] = '?';
824 if (strchr(BADHANDCHARS, newhand[0]) != NULL)
825 dprintf(idx, "Bizarre quantum forces prevent nicknames from starting with %c\n",
826 newhand[0]);
827 else if (get_user_by_handle(userlist, newhand) &&
828 egg_strcasecmp(hand, newhand))
829 dprintf(idx, "Somebody is already using %s.\n", newhand);
830 else {
831 u2 = get_user_by_handle(userlist, hand);
832 atr2 = u2 ? u2->flags : 0;
833 if ((atr & USER_BOTMAST) && !(atr & USER_MASTER) &&
834 !(atr2 & USER_BOT))
835 dprintf(idx, "You can't change nick for non-bots.\n");
836 else if ((bot_flags(u2) & BOT_SHARE) && !(atr & USER_OWNER))
837 dprintf(idx, "You can't change shared bot's nick.\n");
838 else if ((atr2 & USER_OWNER) && !(atr & USER_OWNER) &&
839 egg_strcasecmp(dcc[idx].nick, hand))
840 dprintf(idx, "Can't change the bot owner's handle.\n");
841 else if (isowner(hand) && egg_strcasecmp(dcc[idx].nick, hand))
842 dprintf(idx, "Can't change the permanent bot owner's handle.\n");
843 else if (!egg_strcasecmp(newhand, botnetnick) && (!(atr2 & USER_BOT) ||
844 nextbot(hand) != -1))
845 dprintf(idx, "Hey! That's MY name!\n");
846 else if (change_handle(u2, newhand)) {
847 putlog(LOG_CMDS, "*", "#%s# chhandle %s %s", dcc[idx].nick,
848 hand, newhand);
849 dprintf(idx, "Changed.\n");
850 } else
851 dprintf(idx, "Failed.\n");
852 }
853 }
854
855 static void cmd_handle(struct userrec *u, int idx, char *par)
856 {
857 char oldhandle[HANDLEN + 1], newhandle[HANDLEN + 1];
858 int i;
859
860 strncpyz(newhandle, newsplit(&par), sizeof newhandle);
861
862 if (!newhandle[0]) {
863 dprintf(idx, "Usage: handle <new-handle>\n");
864 return;
865 }
866 for (i = 0; i < strlen(newhandle); i++)
867 if ((newhandle[i] <= 32) || (newhandle[i] >= 127) || (newhandle[i] == '@'))
868 newhandle[i] = '?';
869 if (strchr(BADHANDCHARS, newhandle[0]) != NULL) {
870 dprintf(idx, "Bizarre quantum forces prevent handle from starting with '%c'\n",
871 newhandle[0]);
872 } else if (get_user_by_handle(userlist, newhandle) &&
873 egg_strcasecmp(dcc[idx].nick, newhandle)) {
874 dprintf(idx, "Somebody is already using %s.\n", newhandle);
875 } else if (!egg_strcasecmp(newhandle, botnetnick)) {
876 dprintf(idx, "Hey! That's MY name!\n");
877 } else {
878 strncpyz(oldhandle, dcc[idx].nick, sizeof oldhandle);
879 if (change_handle(u, newhandle)) {
880 putlog(LOG_CMDS, "*", "#%s# handle %s", oldhandle, newhandle);
881 dprintf(idx, "Okay, changed.\n");
882 } else
883 dprintf(idx, "Failed.\n");
884 }
885 }
886
887 static void cmd_chpass(struct userrec *u, int idx, char *par)
888 {
889 char *handle, *new;
890 int atr = u ? u->flags : 0, l;
891
892 if (!par[0])
893 dprintf(idx, "Usage: chpass <handle> [password]\n");
894 else {
895 handle = newsplit(&par);
896 u = get_user_by_handle(userlist, handle);
897 if (!u)
898 dprintf(idx, "No such user.\n");
899 else if ((atr & USER_BOTMAST) && !(atr & USER_MASTER) &&
900 !(u->flags & USER_BOT))
901 dprintf(idx, "You can't change password for non-bots.\n");
902 else if ((bot_flags(u) & BOT_SHARE) && !(atr & USER_OWNER))
903 dprintf(idx, "You can't change shared bot's password.\n");
904 else if ((u->flags & USER_OWNER) && !(atr & USER_OWNER) &&
905 egg_strcasecmp(handle, dcc[idx].nick))
906 dprintf(idx, "Can't change the bot owner's password.\n");
907 else if (isowner(handle) && egg_strcasecmp(dcc[idx].nick, handle))
908 dprintf(idx, "Can't change the permanent bot owner's password.\n");
909 else if (!par[0]) {
910 putlog(LOG_CMDS, "*", "#%s# chpass %s [nothing]", dcc[idx].nick,
911 handle);
912 set_user(&USERENTRY_PASS, u, NULL);
913 dprintf(idx, "Removed password.\n");
914 } else {
915 l = strlen(new = newsplit(&par));
916 if (l > 16)
917 new[16] = 0;
918 if (l < 6)
919 dprintf(idx, "Please use at least 6 characters.\n");
920 else {
921 set_user(&USERENTRY_PASS, u, new);
922 putlog(LOG_CMDS, "*", "#%s# chpass %s [something]", dcc[idx].nick,
923 handle);
924 dprintf(idx, "Changed password.\n");
925 }
926 }
927 }
928 }
929
930 static void cmd_chaddr(struct userrec *u, int idx, char *par)
931 {
932 int telnet_port = 3333, relay_port = 3333;
933 char *handle, *addr, *p, *q;
934 struct bot_addr *bi;
935 struct userrec *u1;
936
937 if (!par[0]) {
938 dprintf(idx, "Usage: chaddr <botname> <address[:telnet-port[/relay-port]]>\n");
939 return;
940 }
941 handle = newsplit(&par);
942 addr = newsplit(&par);
943 if (strlen(addr) > UHOSTMAX)
944 addr[UHOSTMAX] = 0;
945 u1 = get_user_by_handle(userlist, handle);
946 if (!u1 || !(u1->flags & USER_BOT)) {
947 dprintf(idx, "Useful only for tandem bots.\n");
948 return;
949 }
950 if ((bot_flags(u1) & BOT_SHARE) && (!u || !u->flags & USER_OWNER)) {
951 dprintf(idx, "You can't change shared bot's address.\n");
952 return;
953 }
954 putlog(LOG_CMDS, "*", "#%s# chaddr %s %s", dcc[idx].nick, handle, addr);
955 dprintf(idx, "Changed bot's address.\n");
956
957 bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u1);
958 if (bi) {
959 telnet_port = bi->telnet_port;
960 relay_port = bi->relay_port;
961 }
962
963 bi = user_malloc(sizeof(struct bot_addr));
964
965 q = strchr(addr, ':');
966 if (!q) {
967 bi->address = user_malloc(strlen(addr) + 1);
968 strcpy(bi->address, addr);
969 bi->telnet_port = telnet_port;
970 bi->relay_port = relay_port;
971 } else {
972 bi->address = user_malloc(q - addr + 1);
973 strncpyz(bi->address, addr, q - addr + 1);
974 p = q + 1;
975 bi->telnet_port = atoi(p);
976 q = strchr(p, '/');
977 if (!q) {
978 bi->relay_port = bi->telnet_port;
979 } else {
980 bi->relay_port = atoi(q + 1);
981 }
982 }
983 set_user(&USERENTRY_BOTADDR, u1, bi);
984 }
985
986 static void cmd_comment(struct userrec *u, int idx, char *par)
987 {
988 char *handle;
989 struct userrec *u1;
990
991 if (!par[0]) {
992 dprintf(idx, "Usage: comment <handle> <newcomment>\n");
993 return;
994 }
995 handle = newsplit(&par);
996 u1 = get_user_by_handle(userlist, handle);
997 if (!u1) {
998 dprintf(idx, "No such user!\n");
999 return;
1000 }
1001 if ((u1->flags & USER_OWNER) && !(u && (u->flags & USER_OWNER)) &&
1002 egg_strcasecmp(handle, dcc[idx].nick)) {
1003 dprintf(idx, "Can't change comment on the bot owner.\n");
1004 return;
1005 }
1006 putlog(LOG_CMDS, "*", "#%s# comment %s %s", dcc[idx].nick, handle, par);
1007 if (!egg_strcasecmp(par, "none")) {
1008 dprintf(idx, "Okay, comment blanked.\n");
1009 set_user(&USERENTRY_COMMENT, u1, NULL);
1010 return;
1011 }
1012 dprintf(idx, "Changed comment.\n");
1013 set_user(&USERENTRY_COMMENT, u1, par);
1014 }
1015
1016 static void cmd_restart(struct userrec *u, int idx, char *par)
1017 {
1018 putlog(LOG_CMDS, "*", "#%s# restart", dcc[idx].nick);
1019 if (!backgrd) {
1020 dprintf(idx, "You can not .restart a bot when running -n (due to tcl)\n");
1021 return;
1022 }
1023 dprintf(idx, "Restarting.\n");
1024 if (make_userfile) {
1025 putlog(LOG_MISC, "*",
1026 "Uh, guess you don't need to create a new userfile.");
1027 make_userfile = 0;
1028 }
1029 write_userfile(-1);
1030 putlog(LOG_MISC, "*", "Restarting ...");
1031 wipe_timers(interp, &utimer);
1032 wipe_timers(interp, &timer);
1033 do_restart = idx;
1034 }
1035
1036 static void cmd_rehash(struct userrec *u, int idx, char *par)
1037 {
1038 putlog(LOG_CMDS, "*", "#%s# rehash", dcc[idx].nick);
1039 dprintf(idx, "Rehashing.\n");
1040 if (make_userfile) {
1041 putlog(LOG_MISC, "*",
1042 "Uh, guess you don't need to create a new userfile.");
1043 make_userfile = 0;
1044 }
1045 write_userfile(-1);
1046 putlog(LOG_MISC, "*", "Rehashing ...");
1047 do_restart = -2;
1048 }
1049
1050 static void cmd_reload(struct userrec *u, int idx, char *par)
1051 {
1052 putlog(LOG_CMDS, "*", "#%s# reload", dcc[idx].nick);
1053 dprintf(idx, "Reloading user file...\n");
1054 reload();
1055 }
1056
1057 /* NOTE: This gets replaced in the server mod, with a version that handles
1058 * the server disconnect better.
1059 */
1060 void cmd_die(struct userrec *u, int idx, char *par)
1061 {
1062 char s[1024];
1063
1064 putlog(LOG_CMDS, "*", "#%s# die %s", dcc[idx].nick, par);
1065 if (par[0]) {
1066 simple_sprintf(s, "BOT SHUTDOWN (%s: %s)", dcc[idx].nick, par);
1067 } else {
1068 simple_sprintf(s, "BOT SHUTDOWN (authorized by %s)", dcc[idx].nick);
1069 }
1070 chatout("*** %s\n", s);
1071 botnet_send_chat(-1, botnetnick, s);
1072 botnet_send_bye();
1073 write_userfile(-1);
1074 simple_sprintf(s, "DIE BY %s!%s (%s)", dcc[idx].nick,
1075 dcc[idx].host, par[0] ? par : "request");
1076 fatal(s, 0);
1077 }
1078
1079 static void cmd_debug(struct userrec *u, int idx, char *par)
1080 {
1081 if (!egg_strcasecmp(par, "help")) {
1082 putlog(LOG_CMDS, "*", "#%s# debug help", dcc[idx].nick);
1083 debug_help(idx);
1084 } else {
1085 putlog(LOG_CMDS, "*", "#%s# debug", dcc[idx].nick);
1086 debug_mem_to_dcc(idx);
1087 }
1088 }
1089
1090 static void cmd_simul(struct userrec *u, int idx, char *par)
1091 {
1092 char *nick;
1093 int i, ok = 0;
1094
1095 nick = newsplit(&par);
1096 if (!par[0]) {
1097 dprintf(idx, "Usage: simul <hand> <text>\n");
1098 return;
1099 }
1100 if (isowner(nick)) {
1101 dprintf(idx, "Unable to '.simul' permanent owners.\n");
1102 return;
1103 }
1104 for (i = 0; i < dcc_total; i++)
1105 if (!egg_strcasecmp(nick, dcc[i].nick) && !ok &&
1106 (dcc[i].type->flags & DCT_SIMUL)) {
1107 putlog(LOG_CMDS, "*", "#%s# simul %s %s", dcc[idx].nick, nick, par);
1108 if (dcc[i].type && dcc[i].type->activity) {
1109 dcc[i].type->activity(i, par, strlen(par));
1110 ok = 1;
1111 }
1112 }
1113 if (!ok)
1114 dprintf(idx, "No such user on the party line.\n");
1115 }
1116
1117 static void cmd_link(struct userrec *u, int idx, char *par)
1118 {
1119 char *s;
1120 int i;
1121
1122 if (!par[0]) {
1123 dprintf(idx, "Usage: link [some-bot] <new-bot>\n");
1124 return;
1125 }
1126 putlog(LOG_CMDS, "*", "#%s# link %s", dcc[idx].nick, par);
1127 s = newsplit(&par);
1128 if (!par[0] || !egg_strcasecmp(par, botnetnick))
1129 botlink(dcc[idx].nick, idx, s);
1130 else {
1131 char x[40];
1132
1133 i = nextbot(s);
1134 if (i < 0) {
1135 dprintf(idx, "No such bot online.\n");
1136 return;
1137 }
1138 simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1139 botnet_send_link(i, x, s, par);
1140 }
1141 }
1142
1143 static void cmd_unlink(struct userrec *u, int idx, char *par)
1144 {
1145 int i;
1146 char *bot;
1147
1148 if (!par[0]) {
1149 dprintf(idx, "Usage: unlink <bot> [reason]\n");
1150 return;
1151 }
1152 putlog(LOG_CMDS, "*", "#%s# unlink %s", dcc[idx].nick, par);
1153 bot = newsplit(&par);
1154 i = nextbot(bot);
1155 if (i < 0) {
1156 botunlink(idx, bot, par);
1157 return;
1158 }
1159 /* If we're directly connected to that bot, just do it
1160 * (is nike gunna sue?)
1161 */
1162 if (!egg_strcasecmp(dcc[i].nick, bot))
1163 botunlink(idx, bot, par);
1164 else {
1165 char x[40];
1166
1167 simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1168 botnet_send_unlink(i, x, lastbot(bot), bot, par);
1169 }
1170 }
1171
1172 static void cmd_relay(struct userrec *u, int idx, char *par)
1173 {
1174 if (!par[0]) {
1175 dprintf(idx, "Usage: relay <bot>\n");
1176 return;
1177 }
1178 putlog(LOG_CMDS, "*", "#%s# relay %s", dcc[idx].nick, par);
1179 tandem_relay(idx, par, 0);
1180 }
1181
1182 static void cmd_save(struct userrec *u, int idx, char *par)
1183 {
1184 putlog(LOG_CMDS, "*", "#%s# save", dcc[idx].nick);
1185 dprintf(idx, "Saving user file...\n");
1186 write_userfile(-1);
1187 }
1188
1189 static void cmd_backup(struct userrec *u, int idx, char *par)
1190 {
1191 putlog(LOG_CMDS, "*", "#%s# backup", dcc[idx].nick);
1192 dprintf(idx, "Backing up the user file...\n");
1193 backup_userfile();
1194 }
1195
1196 static void cmd_trace(struct userrec *u, int idx, char *par)
1197 {
1198 int i;
1199 char x[NOTENAMELEN + 11], y[11];
1200
1201 if (!par[0]) {
1202 dprintf(idx, "Usage: trace <botname>\n");
1203 return;
1204 }
1205 if (!egg_strcasecmp(par, botnetnick)) {
1206 dprintf(idx, "That's me! Hiya! :)\n");
1207 return;
1208 }
1209 i = nextbot(par);
1210 if (i < 0) {
1211 dprintf(idx, "Unreachable bot.\n");
1212 return;
1213 }
1214 putlog(LOG_CMDS, "*", "#%s# trace %s", dcc[idx].nick, par);
1215 simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1216 simple_sprintf(y, ":%d", now);
1217 botnet_send_trace(i, x, par, y);
1218 }
1219
1220 static void cmd_binds(struct userrec *u, int idx, char *par)
1221 {
1222 putlog(LOG_CMDS, "*", "#%s# binds %s", dcc[idx].nick, par);
1223 tell_binds(idx, par);
1224 }
1225
1226 static void cmd_banner(struct userrec *u, int idx, char *par)
1227 {
1228 char s[1024];
1229 int i;
1230
1231 if (!par[0]) {
1232 dprintf(idx, "Usage: banner <message>\n");
1233 return;
1234 }
1235 simple_sprintf(s, "\007### Botwide: [%s] %s\n", dcc[idx].nick, par);
1236 for (i = 0; i < dcc_total; i++)
1237 if (dcc[i].type->flags & DCT_MASTER)
1238 dprintf(i, "%s", s);
1239 }
1240
1241 /* After messing with someone's user flags, make sure the dcc-chat flags
1242 * are set correctly.
1243 */
1244 int check_dcc_attrs(struct userrec *u, int oatr)
1245 {
1246 int i, stat;
1247
1248 if (!u)
1249 return 0;
1250 /* Make sure default owners are +n */
1251 if (isowner(u->handle)) {
1252 u->flags = sanity_check(u->flags | USER_OWNER);
1253 }
1254 for (i = 0; i < dcc_total; i++) {
1255 if ((dcc[i].type->flags & DCT_MASTER) &&
1256 (!egg_strcasecmp(u->handle, dcc[i].nick))) {
1257 stat = dcc[i].status;
1258 if ((dcc[i].type == &DCC_CHAT) &&
1259 ((u->flags & (USER_OP | USER_MASTER | USER_OWNER |
1260 USER_BOTMAST))
1261 != (oatr & (USER_OP | USER_MASTER | USER_OWNER |
1262 USER_BOTMAST)))) {
1263 botnet_send_join_idx(i, -1);
1264 }
1265 if ((oatr & USER_MASTER) && !(u->flags & USER_MASTER)) {
1266 struct flag_record fr = {FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
1267
1268 dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_RAW |
1269 LOG_FILES | LOG_LEV1 | LOG_LEV2 |
1270 LOG_LEV3 | LOG_LEV4 | LOG_LEV5 |
1271 LOG_LEV6 | LOG_LEV7 | LOG_LEV8 |
1272 LOG_WALL | LOG_DEBUG);
1273 get_user_flagrec(u, &fr, NULL);
1274 if (!chan_master(fr))
1275 dcc[i].u.chat->con_flags |= (LOG_MISC | LOG_CMDS);
1276 dprintf(i, "*** POOF! ***\n");
1277 dprintf(i, "You are no longer a master on this bot.\n");
1278 }
1279 if (!(oatr & USER_MASTER) && (u->flags & USER_MASTER)) {
1280 dcc[i].u.chat->con_flags |= conmask;
1281 dprintf(i, "*** POOF! ***\n");
1282 dprintf(i, "You are now a master on this bot.\n");
1283 }
1284 if (!(oatr & USER_BOTMAST) && (u->flags & USER_BOTMAST)) {
1285 dprintf(i, "### POOF! ###\n");
1286 dprintf(i, "You are now a botnet master on this bot.\n");
1287 }
1288 if ((oatr & USER_BOTMAST) && !(u->flags & USER_BOTMAST)) {
1289 dprintf(i, "### POOF! ###\n");
1290 dprintf(i, "You are no longer a botnet master on this bot.\n");
1291 }
1292 if (!(oatr & USER_OWNER) && (u->flags & USER_OWNER)) {
1293 dprintf(i, "@@@ POOF! @@@\n");
1294 dprintf(i, "You are now an OWNER of this bot.\n");
1295 }
1296 if ((oatr & USER_OWNER) && !(u->flags & USER_OWNER)) {
1297 dprintf(i, "@@@ POOF! @@@\n");
1298 dprintf(i, "You are no longer an owner of this bot.\n");
1299 }
1300 if ((stat & STAT_PARTY) && (u->flags & USER_OP))
1301 stat &= ~STAT_PARTY;
1302 if (!(stat & STAT_PARTY) && !(u->flags & USER_OP) &&
1303 !(u->flags & USER_MASTER))
1304 stat |= STAT_PARTY;
1305 if ((stat & STAT_CHAT) && !(u->flags & USER_PARTY) &&
1306 !(u->flags & USER_MASTER) &&
1307 (!(u->flags & USER_OP) || require_p))
1308 stat &= ~STAT_CHAT;
1309 if ((dcc[i].type->flags & DCT_FILES) && !(stat & STAT_CHAT) &&
1310 ((u->flags & USER_MASTER) || (u->flags & USER_PARTY) ||
1311 ((u->flags & USER_OP) && !require_p)))
1312 stat |= STAT_CHAT;
1313 dcc[i].status = stat;
1314 /* Check if they no longer have access to wherever they are.
1315 *
1316 * NOTE: DON'T kick someone off the party line just cuz they lost +p
1317 * (pinvite script removes +p after 5 mins automatically)
1318 */
1319 if ((dcc[i].type->flags & DCT_FILES) && !(u->flags & USER_XFER) &&
1320 !(u->flags & USER_MASTER)) {
1321 dprintf(i, "-+- POOF! -+-\n");
1322 dprintf(i, "You no longer have file area access.\n\n");
1323 putlog(LOG_MISC, "*", "DCC user [%s]%s removed from file system",
1324 dcc[i].nick, dcc[i].host);
1325 if (dcc[i].status & STAT_CHAT) {
1326 struct chat_info *ci;
1327
1328 ci = dcc[i].u.file->chat;
1329 nfree(dcc[i].u.file);
1330 dcc[i].u.chat = ci;
1331 dcc[i].status &= (~STAT_CHAT);
1332 dcc[i].type = &DCC_CHAT;
1333 if (dcc[i].u.chat->channel >= 0) {
1334 chanout_but(-1, dcc[i].u.chat->channel,
1335 "*** %s has returned.\n", dcc[i].nick);
1336 if (dcc[i].u.chat->channel < 100000)
1337 botnet_send_join_idx(i, -1);
1338 }
1339 } else {
1340 killsock(dcc[i].sock);
1341 lostdcc(i);
1342 }
1343 }
1344 }
1345 if (dcc[i].type == &DCC_BOT && !egg_strcasecmp(u->handle, dcc[i].nick)) {
1346 if ((dcc[i].status & STAT_LEAF) && !(u->flags & BOT_LEAF))
1347 dcc[i].status &= ~(STAT_LEAF | STAT_WARNED);
1348 if (!(dcc[i].status & STAT_LEAF) && (u->flags & BOT_LEAF))
1349 dcc[i].status |= STAT_LEAF;
1350 }
1351 }
1352 return u->flags;
1353 }
1354
1355 int check_dcc_chanattrs(struct userrec *u, char *chname, int chflags,
1356 int ochatr)
1357 {
1358 int i, found = 0, atr = u ? u->flags : 0;
1359 struct chanset_t *chan;
1360
1361 if (!u)
1362 return 0;
1363 for (i = 0; i < dcc_total; i++) {
1364 if ((dcc[i].type->flags & DCT_MASTER) &&
1365 !egg_strcasecmp(u->handle, dcc[i].nick)) {
1366 if ((dcc[i].type == &DCC_CHAT) &&
1367 ((chflags & (USER_OP | USER_MASTER | USER_OWNER))
1368 != (ochatr & (USER_OP | USER_MASTER | USER_OWNER))))
1369 botnet_send_join_idx(i, -1);
1370 if ((ochatr & USER_MASTER) && !(chflags & USER_MASTER)) {
1371 if (!(atr & USER_MASTER))
1372 dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS);
1373 dprintf(i, "*** POOF! ***\n");
1374 dprintf(i, "You are no longer a master on %s.\n", chname);
1375 }
1376 if (!(ochatr & USER_MASTER) && (chflags & USER_MASTER)) {
1377 dcc[i].u.chat->con_flags |= conmask;
1378 if (!(atr & USER_MASTER))
1379 dcc[i].u.chat->con_flags &=
1380 ~(LOG_LEV1 | LOG_LEV2 | LOG_LEV3 | LOG_LEV4 |
1381 LOG_LEV5 | LOG_LEV6 | LOG_LEV7 | LOG_LEV8 |
1382 LOG_RAW | LOG_DEBUG | LOG_WALL | LOG_FILES | LOG_SRVOUT);
1383 dprintf(i, "*** POOF! ***\n");
1384 dprintf(i, "You are now a master on %s.\n", chname);
1385 }
1386 if (!(ochatr & USER_OWNER) && (chflags & USER_OWNER)) {
1387 dprintf(i, "@@@ POOF! @@@\n");
1388 dprintf(i, "You are now an OWNER of %s.\n", chname);
1389 }
1390 if ((ochatr & USER_OWNER) && !(chflags & USER_OWNER)) {
1391 dprintf(i, "@@@ POOF! @@@\n");
1392 dprintf(i, "You are no longer an owner of %s.\n", chname);
1393 }
1394 if (((ochatr & (USER_OP | USER_MASTER | USER_OWNER)) &&
1395 (!(chflags & (USER_OP | USER_MASTER | USER_OWNER)))) ||
1396 ((chflags & (USER_OP | USER_MASTER | USER_OWNER)) &&
1397 (!(ochatr & (USER_OP | USER_MASTER | USER_OWNER))))) {
1398 struct flag_record fr = {FR_CHAN, 0, 0, 0, 0, 0};
1399
1400 for (chan = chanset; chan && !found; chan = chan->next) {
1401 get_user_flagrec(u, &fr, chan->dname);
1402 if (fr.chan & (USER_OP | USER_MASTER | USER_OWNER))
1403 found = 1;
1404 }
1405 if (!chan)
1406 chan = chanset;
1407 if (chan)
1408 strcpy(dcc[i].u.chat->con_chan, chan->dname);
1409 else
1410 strcpy(dcc[i].u.chat->con_chan, "*");
1411 }
1412 }
1413 }
1414 return chflags;
1415 }
1416
1417 static void cmd_chattr(struct userrec *u, int idx, char *par)
1418 {
1419 char *hand, *arg = NULL, *tmpchg = NULL, *chg = NULL, work[1024];
1420 struct chanset_t *chan = NULL;
1421 struct userrec *u2;
1422 struct flag_record pls = {0, 0, 0, 0, 0, 0},
1423 mns = {0, 0, 0, 0, 0, 0},
1424 user = {0, 0, 0, 0, 0, 0};
1425 module_entry *me;
1426 int fl = -1, of = 0, ocf = 0;
1427
1428 if (!par[0]) {
1429 dprintf(idx, "Usage: chattr <handle> [changes] [channel]\n");
1430 return;
1431 }
1432 hand = newsplit(&par);
1433 u2 = get_user_by_handle(userlist, hand);
1434 if (!u2) {
1435 dprintf(idx, "No such user!\n");
1436 return;
1437 }
1438
1439 /* Parse args */
1440 if (par[0]) {
1441 arg = newsplit(&par);
1442 if (par[0]) {
1443 /* .chattr <handle> <changes> <channel> */
1444 chg = arg;
1445 arg = newsplit(&par);
1446 chan = findchan_by_dname(arg);
1447 } else {
1448 chan = findchan_by_dname(arg);
1449 /* Consider modeless channels, starting with '+' */
1450 if (!(arg[0] == '+' && chan) &&
1451 !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
1452 /* .chattr <handle> <changes> */
1453 chg = arg;
1454 chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
1455 arg = NULL;
1456 }
1457 /* .chattr <handle> <channel>: nothing to do... */
1458 }
1459 }
1460 /* arg: pointer to channel name, NULL if none specified
1461 * chan: pointer to channel structure, NULL if none found or none specified
1462 * chg: pointer to changes, NULL if none specified
1463 */
1464 Assert(!(!arg && chan));
1465 if (arg && !chan) {
1466 dprintf(idx, "No channel record for %s.\n", arg);
1467 return;
1468 }
1469 if (chg) {
1470 if (!arg && strpbrk(chg, "&|")) {
1471 /* .chattr <handle> *[&|]*: use console channel if found... */
1472 if (!strcmp ((arg = dcc[idx].u.chat->con_chan), "*"))
1473 arg = NULL;
1474 else
1475 chan = findchan_by_dname(arg);
1476 if (arg && !chan) {
1477 dprintf (idx, "Invalid console channel %s.\n", arg);
1478 return;
1479 }
1480 } else if (arg && !strpbrk(chg, "&|")) {
1481 tmpchg = nmalloc(strlen(chg) + 2);
1482 strcpy(tmpchg, "|");
1483 strcat(tmpchg, chg);
1484 chg = tmpchg;
1485 }
1486 }
1487 par = arg;
1488 user.match = FR_GLOBAL;
1489 if (chan)
1490 user.match |= FR_CHAN;
1491 get_user_flagrec(u, &user, chan ? chan->dname : 0);
1492 if (!chan && !glob_botmast(user)) {
1493 dprintf(idx, "You do not have Bot Master privileges.\n");
1494 if (tmpchg)
1495 nfree(tmpchg);
1496 return;
1497 }
1498 if (chan && !glob_master(user) && !chan_master(user)) {
1499 dprintf(idx, "You do not have channel master privileges for channel %s\n",
1500 par);
1501 if (tmpchg)
1502 nfree(tmpchg);
1503 return;
1504 }
1505 user.match &= fl;
1506 if (chg) {
1507 pls.match = user.match;
1508 break_down_flags(chg, &pls, &mns);
1509 /* No-one can change these flags on-the-fly */
1510 pls.global &= ~(USER_BOT);
1511 mns.global &= ~(USER_BOT);
1512
1513 if (chan) {
1514 pls.chan &= ~(BOT_SHARE);
1515 mns.chan &= ~(BOT_SHARE);
1516 }
1517 if (!glob_owner(user)) {
1518 pls.global &= ~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1519 mns.global &= ~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1520
1521 if (chan) {
1522 pls.chan &= ~USER_OWNER;
1523 mns.chan &= ~USER_OWNER;
1524 }
1525 if (!glob_master(user)) {
1526 pls.global &= USER_PARTY | USER_XFER;
1527 mns.global &= USER_PARTY | USER_XFER;
1528
1529 if (!glob_botmast(user)) {
1530 pls.global = 0;
1531 mns.global = 0;
1532 }
1533 }
1534 }
1535 if (chan && !chan_owner(user) && !glob_owner(user)) {
1536 pls.chan &= ~USER_MASTER;
1537 mns.chan &= ~USER_MASTER;
1538 if (!chan_master(user) && !glob_master(user)) {
1539 pls.chan = 0;
1540 mns.chan = 0;
1541 }
1542 }
1543 get_user_flagrec(u2, &user, par);
1544 if (user.match & FR_GLOBAL) {
1545 of = user.global;
1546 user.global = sanity_check((user.global |pls.global) &~mns.global);
1547
1548 user.udef_global = (user.udef_global | pls.udef_global)
1549 & ~mns.udef_global;
1550 }
1551 if (chan) {
1552 ocf = user.chan;
1553 user.chan = chan_sanity_check((user.chan | pls.chan) & ~mns.chan,
1554 user.global);
1555
1556 user.udef_chan = (user.udef_chan | pls.udef_chan) & ~mns.udef_chan;
1557 }
1558 set_user_flagrec(u2, &user, par);
1559 }
1560 if (chan)
1561 putlog(LOG_CMDS, "*", "#%s# (%s) chattr %s %s",
1562 dcc[idx].nick, chan ? chan->dname : "*", hand, chg ? chg : "");
1563 else
1564 putlog(LOG_CMDS, "*", "#%s# chattr %s %s", dcc[idx].nick, hand,
1565 chg ? chg : "");
1566 /* Get current flags and display them */
1567 if (user.match & FR_GLOBAL) {
1568 user.match = FR_GLOBAL;
1569 if (chg)
1570 check_dcc_attrs(u2, of);
1571 get_user_flagrec(u2, &user, NULL);
1572 build_flags(work, &user, NULL);
1573 if (work[0] != '-')
1574 dprintf(idx, "Global flags for %s are now +%s\n", hand, work);
1575 else
1576 dprintf(idx, "No global flags for %s.\n", hand);
1577 }
1578 if (chan) {
1579 user.match = FR_CHAN;
1580 get_user_flagrec(u2, &user, par);
1581 user.chan &= ~BOT_SHARE;
1582 if (chg)
1583 check_dcc_chanattrs(u2, chan->dname, user.chan, ocf);
1584 build_flags(work, &user, NULL);
1585 if (work[0] != '-')
1586 dprintf(idx, "Channel flags for %s on %s are now +%s\n", hand,
1587 chan->dname, work);
1588 else
1589 dprintf(idx, "No flags for %s on %s.\n", hand, chan->dname);
1590 if (chg && (me = module_find("irc", 0, 0))) {
1591 Function *func = me->funcs;
1592
1593 if (chan)
1594 (func[IRC_RECHECK_CHANNEL]) (chan, 0);
1595 }
1596 }
1597 if (tmpchg)
1598 nfree(tmpchg);
1599 }
1600
1601 static void cmd_botattr(struct userrec *u, int idx, char *par)
1602 {
1603 char *hand, *chg = NULL, *arg = NULL, *tmpchg = NULL, work[1024];
1604 struct chanset_t *chan = NULL;
1605 struct userrec *u2;
1606 struct flag_record pls = {0, 0, 0, 0, 0, 0},
1607 mns = {0, 0, 0, 0, 0, 0},
1608 user = {0, 0, 0, 0, 0, 0};
1609 int idx2;
1610
1611 if (!par[0]) {
1612 dprintf(idx, "Usage: botattr <handle> [changes] [channel]\n");
1613 return;
1614 }
1615 hand = newsplit(&par);
1616 u2 = get_user_by_handle(userlist, hand);
1617 if (!u2 || !(u2->flags & USER_BOT)) {
1618 dprintf(idx, "No such bot!\n");
1619 return;
1620 }
1621 for (idx2 = 0; idx2 < dcc_total; idx2++)
1622 if (dcc[idx2].type != &DCC_RELAY && dcc[idx2].type != &DCC_FORK_BOT &&
1623 !egg_strcasecmp(dcc[idx2].nick, hand))
1624 break;
1625 if (idx2 != dcc_total) {
1626 dprintf(idx, "You may not change the attributes of a directly linked bot.\n");
1627 return;
1628 }
1629 /* Parse args */
1630 if (par[0]) {
1631 arg = newsplit(&par);
1632 if (par[0]) {
1633 /* .botattr <handle> <changes> <channel> */
1634 chg = arg;
1635 arg = newsplit(&par);
1636 chan = findchan_by_dname(arg);
1637 } else {
1638 chan = findchan_by_dname(arg);
1639 /* Consider modeless channels, starting with '+' */
1640 if (!(arg[0] == '+' && chan) &&
1641 !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
1642 /* .botattr <handle> <changes> */
1643 chg = arg;
1644 chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
1645 arg = NULL;
1646 }
1647 /* .botattr <handle> <channel>: nothing to do... */
1648 }
1649 }
1650 /* arg: pointer to channel name, NULL if none specified
1651 * chan: pointer to channel structure, NULL if none found or none specified
1652 * chg: pointer to changes, NULL if none specified
1653 */
1654 Assert(!(!arg && chan));
1655 if (arg && !chan) {
1656 dprintf(idx, "No channel record for %s.\n", arg);
1657 return;
1658 }
1659 if (chg) {
1660 if (!arg && strpbrk(chg, "&|")) {
1661 /* botattr <handle> *[&|]*: use console channel if found... */
1662 if (!strcmp ((arg = dcc[idx].u.chat->con_chan), "*"))
1663 arg = NULL;
1664 else
1665 chan = findchan_by_dname(arg);
1666 if (arg && !chan) {
1667 dprintf (idx, "Invalid console channel %s.\n", arg);
1668 return;
1669 }
1670 } else if (arg && !strpbrk(chg, "&|")) {
1671 tmpchg = nmalloc(strlen(chg) + 2);
1672 strcpy (tmpchg, "|");
1673 strcat (tmpchg, chg);
1674 chg = tmpchg;
1675 }
1676 }
1677 par = arg;
1678
1679 user.match = FR_GLOBAL;
1680 get_user_flagrec(u, &user, chan ? chan->dname : 0);
1681 if (!glob_botmast(user)) {
1682 dprintf(idx, "You do not have Bot Master privileges.\n");
1683 if (tmpchg)
1684 nfree(tmpchg);
1685 return;
1686 }
1687 if (chg) {
1688 user.match = FR_BOT | (chan ? FR_CHAN : 0);
1689 pls.match = user.match;
1690 break_down_flags(chg, &pls, &mns);
1691 /* No-one can change these flags on-the-fly */
1692 pls.global &=~BOT_BOT;
1693 mns.global &=~BOT_BOT;
1694
1695 if (chan && glob_owner(user)) {
1696 pls.chan &= BOT_SHARE;
1697 mns.chan &= BOT_SHARE;
1698 } else {
1699 pls.chan = 0;
1700 mns.chan = 0;
1701 }
1702 if (!glob_owner(user)) {
1703 pls.bot &= ~(BOT_SHARE | BOT_GLOBAL);
1704 mns.bot &= ~(BOT_SHARE | BOT_GLOBAL);
1705 }
1706 user.match = FR_BOT | (chan ? FR_CHAN : 0);
1707 get_user_flagrec(u2, &user, par);
1708 user.bot = (user.bot | pls.bot) & ~mns.bot;
1709 if ((user.bot & BOT_SHARE) == BOT_SHARE)
1710 user.bot &= ~BOT_SHARE;
1711 if (chan)
1712 user.chan = (user.chan | pls.chan) & ~mns.chan;
1713 set_user_flagrec(u2, &user, par);
1714 }
1715 if (chan)
1716 putlog(LOG_CMDS, "*", "#%s# (%s) botattr %s %s",
1717 dcc[idx].nick, chan->dname, hand, chg ? chg : "");
1718 else
1719 putlog(LOG_CMDS, "*", "#%s# botattr %s %s", dcc[idx].nick, hand,
1720 chg ? chg : "");
1721 /* get current flags and display them */
1722 if (!chan || pls.bot || mns.bot) {
1723 user.match = FR_BOT;
1724 get_user_flagrec(u2, &user, NULL);
1725 build_flags(work, &user, NULL);
1726 if (work[0] != '-')
1727 dprintf(idx, "Bot flags for %s are now +%s\n", hand, work);
1728 else
1729 dprintf(idx, "No bot flags for %s.\n", hand);
1730 }
1731 if (chan) {
1732 user.match = FR_CHAN;
1733 get_user_flagrec(u2, &user, par);
1734 user.chan &= BOT_SHARE;
1735 build_flags(work, &user, NULL);
1736 if (work[0] != '-')
1737 dprintf(idx, "Bot flags for %s on %s are now +%s\n", hand,
1738 chan->dname, work);
1739 else
1740 dprintf(idx, "No bot flags for %s on %s.\n", hand, chan->dname);
1741 }
1742 if (tmpchg)
1743 nfree(tmpchg);
1744 }
1745
1746 static void cmd_chat(struct userrec *u, int idx, char *par)
1747 {
1748 char *arg;
1749 int newchan, oldchan;
1750 module_entry *me;
1751
1752 arg = newsplit(&par);
1753 if (!egg_strcasecmp(arg, "off")) {
1754 /* Turn chat off */
1755 if (dcc[idx].u.chat->channel < 0) {
1756 dprintf(idx, "You weren't in chat anyway!\n");
1757 return;
1758 } else {
1759 dprintf(idx, "Leaving chat mode...\n");
1760 check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
1761 dcc[idx].u.chat->channel);
1762 chanout_but(-1, dcc[idx].u.chat->channel,
1763 "*** %s left the party line.\n",
1764 dcc[idx].nick);
1765 if (dcc[idx].u.chat->channel < 100000)
1766 botnet_send_part_idx(idx, "");
1767 }
1768 dcc[idx].u.chat->channel = (-1);
1769 } else {
1770 if (arg[0] == '*') {
1771 if (((arg[1] < '0') || (arg[1] > '9'))) {
1772 if (!arg[1])
1773 newchan = 0;
1774 else {
1775 Tcl_SetVar(interp, "chan", arg, 0);
1776 if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
1777 interp->result[0])
1778 newchan = atoi(interp->result);
1779 else
1780 newchan = -1;
1781 }
1782 if (newchan < 0) {
1783 dprintf(idx, "No channel by that name.\n");
1784 return;
1785 }
1786 } else
1787 newchan = 100000 + atoi(arg + 1);
1788 if (newchan < 100000 || newchan > 199999) {
1789 dprintf(idx, "Channel # out of range: local channels must be *0-*99999\n");
1790 return;
1791 }
1792 } else {
1793 if (((arg[0] < '0') || (arg[0] > '9')) && (arg[0])) {
1794 if (!egg_strcasecmp(arg, "on"))
1795 newchan = 0;
1796 else {
1797 Tcl_SetVar(interp, "chan", arg, 0);
1798 if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
1799 interp->result[0])
1800 newchan = atoi(interp->result);
1801 else
1802 newchan = -1;
1803 }
1804 if (newchan < 0) {
1805 dprintf(idx, "No channel by that name.\n");
1806 return;
1807 }
1808 } else
1809 newchan = atoi(arg);
1810 if ((newchan < 0) || (newchan > 99999)) {
1811 dprintf(idx, "Channel # out of range: must be between 0 and 99999.\n");
1812 return;
1813 }
1814 }
1815 /* If coming back from being off the party line, make sure they're
1816 * not away.
1817 */
1818 if ((dcc[idx].u.chat->channel < 0) && (dcc[idx].u.chat->away != NULL))
1819 not_away(idx);
1820 if (dcc[idx].u.chat->channel == newchan) {
1821 if (!newchan) {
1822 dprintf(idx, "You're already on the party line!\n");
1823 return;
1824 } else {
1825 dprintf(idx, "You're already on channel %s%d!\n",
1826 (newchan < 100000) ? "" : "*", newchan % 100000);
1827 return;
1828 }
1829 } else {
1830 oldchan = dcc[idx].u.chat->channel;
1831 if (oldchan >= 0)
1832 check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock, oldchan);
1833 if (!oldchan) {
1834 chanout_but(-1, 0, "*** %s left the party line.\n", dcc[idx].nick);
1835 } else if (oldchan > 0) {
1836 chanout_but(-1, oldchan, "*** %s left the channel.\n", dcc[idx].nick);
1837 }
1838 dcc[idx].u.chat->channel = newchan;
1839 if (!newchan) {
1840 dprintf(idx, "Entering the party line...\n");
1841 chanout_but(-1, 0, "*** %s joined the party line.\n", dcc[idx].nick);
1842 } else {
1843 dprintf(idx, "Joining channel '%s'...\n", arg);
1844 chanout_but(-1, newchan, "*** %s joined the channel.\n", dcc[idx].nick);
1845 }
1846 check_tcl_chjn(botnetnick, dcc[idx].nick, newchan, geticon(idx),
1847 dcc[idx].sock, dcc[idx].host);
1848 if (newchan < 100000)
1849 botnet_send_join_idx(idx, oldchan);
1850 else if (oldchan < 100000)
1851 botnet_send_part_idx(idx, "");
1852 }
1853 }
1854 /* New style autosave here too -- rtc, 09/28/1999*/
1855 if ((me = module_find("console", 1, 1))) {
1856 Function *func = me->funcs;
1857 (func[CONSOLE_DOSTORE]) (idx);
1858 }
1859 }
1860
1861 static void cmd_echo(struct userrec *u, int idx, char *par)
1862 {
1863 module_entry *me;
1864
1865 if (!par[0]) {
1866 dprintf(idx, "Echo is currently %s.\n", dcc[idx].status & STAT_ECHO ?
1867 "on" : "off");
1868 return;
1869 }
1870 if (!egg_strcasecmp(par, "on")) {
1871 dprintf(idx, "Echo turned on.\n");
1872 dcc[idx].status |= STAT_ECHO;
1873 } else if (!egg_strcasecmp(par, "off")) {
1874 dprintf(idx, "Echo turned off.\n");
1875 dcc[idx].status &= ~STAT_ECHO;
1876 } else {
1877 dprintf(idx, "Usage: echo <on/off>\n");
1878 return;
1879 }
1880 /* New style autosave here too -- rtc, 09/28/1999*/
1881 if ((me = module_find("console", 1, 1))) {
1882 Function *func = me->funcs;
1883 (func[CONSOLE_DOSTORE]) (idx);
1884 }
1885 }
1886
1887 int stripmodes(char *s)
1888 {
1889 int res = 0;
1890
1891 for (; *s; s++)
1892 switch (tolower(*s)) {
1893 case 'b':
1894 res |= STRIP_BOLD;
1895 break;
1896 case 'c':
1897 res |= STRIP_COLOR;
1898 break;
1899 case 'r':
1900 res |= STRIP_REV;
1901 break;
1902 case 'u':
1903 res |= STRIP_UNDER;
1904 break;
1905 case 'a':
1906 res |= STRIP_ANSI;
1907 break;
1908 case 'g':
1909 res |= STRIP_BELLS;
1910 break;
1911 case '*':
1912 res |= STRIP_ALL;
1913 break;
1914 }
1915 return res;
1916 }
1917
1918 char *stripmasktype(int x)
1919 {
1920 static char s[20];
1921 char *p = s;
1922
1923 if (x & STRIP_BOLD)
1924 *p++ = 'b';
1925 if (x & STRIP_COLOR)
1926 *p++ = 'c';
1927 if (x & STRIP_REV)
1928 *p++ = 'r';
1929 if (x & STRIP_UNDER)
1930 *p++ = 'u';
1931 if (x & STRIP_ANSI)
1932 *p++ = 'a';
1933 if (x & STRIP_BELLS)
1934 *p++ = 'g';
1935 if (p == s)
1936 *p++ = '-';
1937 *p = 0;
1938 return s;
1939 }
1940
1941 static char *stripmaskname(int x)
1942 {
1943 static char s[161];
1944 int i = 0;
1945
1946 s[i] = 0;
1947 if (x & STRIP_BOLD)
1948 i += my_strcpy(s + i, "bold, ");
1949 if (x & STRIP_COLOR)
1950 i += my_strcpy(s + i, "color, ");
1951 if (x & STRIP_REV)
1952 i += my_strcpy(s + i, "reverse, ");
1953 if (x & STRIP_UNDER)
1954 i += my_strcpy(s + i, "underline, ");
1955 if (x & STRIP_ANSI)
1956 i += my_strcpy(s + i, "ansi, ");
1957 if (x & STRIP_BELLS)
1958 i += my_strcpy(s + i, "bells, ");
1959 if (!i)
1960 strcpy(s, "none");
1961 else
1962 s[i - 2] = 0;
1963 return s;
1964 }
1965
1966 static void cmd_strip(struct userrec *u, int idx, char *par)
1967 {
1968 char *nick, *changes, *c, s[2];
1969 int dest = 0, i, pls, md, ok = 0;
1970 module_entry *me;
1971
1972 if (!par[0]) {
1973 dprintf(idx, "Your current strip settings are: %s (%s)\n",
1974 stripmasktype(dcc[idx].u.chat->strip_flags),
1975 stripmaskname(dcc[idx].u.chat->strip_flags));
1976 return;
1977 }
1978 nick = newsplit(&par);
1979 if ((nick[0] != '+') && (nick[0] != '-') && u &&
1980 (u->flags & USER_MASTER)) {
1981 for (i = 0; i < dcc_total; i++)
1982 if (!egg_strcasecmp(nick, dcc[i].nick) && dcc[i].type == &DCC_CHAT &&
1983 !ok) {
1984 ok = 1;
1985 dest = i;
1986 }
1987 if (!ok) {
1988 dprintf(idx, "No such user on the party line!\n");
1989 return;
1990 }
1991 changes = par;
1992 } else {
1993 changes = nick;
1994 nick = "";
1995 dest = idx;
1996 }
1997 c = changes;
1998 if ((c[0] != '+') && (c[0] != '-'))
1999 dcc[dest].u.chat->strip_flags = 0;
2000 s[1] = 0;
2001 for (pls = 1; *c; c++) {
2002 switch (*c) {
2003 case '+':
2004 pls = 1;
2005 break;
2006 case '-':
2007 pls = 0;
2008 break;
2009 default:
2010 s[0] = *c;
2011 md = stripmodes(s);
2012 if (pls == 1)
2013 dcc[dest].u.chat->strip_flags |= md;
2014 else
2015 dcc[dest].u.chat->strip_flags &= ~md;
2016 }
2017 }
2018 if (nick[0])
2019 putlog(LOG_CMDS, "*", "#%s# strip %s %s", dcc[idx].nick, nick, changes);
2020 else
2021 putlog(LOG_CMDS, "*", "#%s# strip %s", dcc[idx].nick, changes);
2022 if (dest == idx) {
2023 dprintf(idx, "Your strip settings are: %s (%s)\n",
2024 stripmasktype(dcc[idx].u.chat->strip_flags),
2025 stripmaskname(dcc[idx].u.chat->strip_flags));
2026 } else {
2027 dprintf(idx, "Strip setting for %s: %s (%s)\n", dcc[dest].nick,
2028 stripmasktype(dcc[dest].u.chat->strip_flags),
2029 stripmaskname(dcc[dest].u.chat->strip_flags));
2030 dprintf(dest, "%s set your strip settings to: %s (%s)\n", dcc[idx].nick,
2031 stripmasktype(dcc[dest].u.chat->strip_flags),
2032 stripmaskname(dcc[dest].u.chat->strip_flags));
2033 }
2034 /* Set highlight flag here so user is able to control stripping of
2035 * bold also as intended -- dw 27/12/1999
2036 */