/[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.57 - (show annotations) (download) (as text)
Tue Jul 3 01:33:34 2001 UTC (18 years, 5 months ago) by poptix
Branch: MAIN
Changes since 1.56: +3 -17 lines
File MIME type: text/x-chdr

isowner.patch by me!

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.56 2001/06/30 06:29:55 guppy Exp $
7 */
8 /*
9 * Copyright (C) 1997 Robey Pointer
10 * Copyright (C) 1999, 2000, 2001 Eggheads Development Team
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 */
26
27 #include "main.h"
28 #include "tandem.h"
29 #include "modules.h"
30 #include <ctype.h>
31
32 extern struct chanset_t *chanset;
33 extern struct dcc_t *dcc;
34 extern struct userrec *userlist;
35 extern tcl_timer_t *timer, *utimer;
36 extern int dcc_total, remote_boots, backgrd, make_userfile,
37 do_restart, conmask, require_p, must_be_owner,
38 strict_host;
39 extern unsigned long otraffic_irc, otraffic_irc_today,
40 itraffic_irc, itraffic_irc_today,
41 otraffic_bn, otraffic_bn_today,
42 itraffic_bn, itraffic_bn_today,
43 otraffic_dcc, otraffic_dcc_today,
44 itraffic_dcc, itraffic_dcc_today,
45 otraffic_trans, otraffic_trans_today,
46 itraffic_trans, itraffic_trans_today,
47 otraffic_unknown, otraffic_unknown_today,
48 itraffic_unknown, itraffic_unknown_today;
49 extern Tcl_Interp *interp;
50 extern char botnetnick[], origbotname[], ver[], network[],
51 owner[], spaces[];
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 char *p, *q, s[121];
1248
1249 if (!u)
1250 return 0;
1251 /* Make sure default owners are +n */
1252 if (isowner(u->handle)) {
1253 u->flags = sanity_check(u->flags | USER_OWNER);
1254 }
1255 for (i = 0; i < dcc_total; i++) {
1256 if ((dcc[i].type->flags & DCT_MASTER) &&
1257 (!egg_strcasecmp(u->handle, dcc[i].nick))) {
1258 stat = dcc[i].status;
1259 if ((dcc[i].type == &DCC_CHAT) &&
1260 ((u->flags & (USER_OP | USER_MASTER | USER_OWNER |
1261 USER_BOTMAST))
1262 != (oatr & (USER_OP | USER_MASTER | USER_OWNER |
1263 USER_BOTMAST)))) {
1264 botnet_send_join_idx(i, -1);
1265 }
1266 if ((oatr & USER_MASTER) && !(u->flags & USER_MASTER)) {
1267 struct flag_record fr = {FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
1268
1269 dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_RAW |
1270 LOG_FILES | LOG_LEV1 | LOG_LEV2 |
1271 LOG_LEV3 | LOG_LEV4 | LOG_LEV5 |
1272 LOG_LEV6 | LOG_LEV7 | LOG_LEV8 |
1273 LOG_WALL | LOG_DEBUG);
1274 get_user_flagrec(u, &fr, NULL);
1275 if (!chan_master(fr))
1276 dcc[i].u.chat->con_flags |= (LOG_MISC | LOG_CMDS);
1277 dprintf(i, "*** POOF! ***\n");
1278 dprintf(i, "You are no longer a master on this bot.\n");
1279 }
1280 if (!(oatr & USER_MASTER) && (u->flags & USER_MASTER)) {
1281 dcc[i].u.chat->con_flags |= conmask;
1282 dprintf(i, "*** POOF! ***\n");
1283 dprintf(i, "You are now a master on this bot.\n");
1284 }
1285 if (!(oatr & USER_BOTMAST) && (u->flags & USER_BOTMAST)) {
1286 dprintf(i, "### POOF! ###\n");
1287 dprintf(i, "You are now a botnet master on this bot.\n");
1288 }
1289 if ((oatr & USER_BOTMAST) && !(u->flags & USER_BOTMAST)) {
1290 dprintf(i, "### POOF! ###\n");
1291 dprintf(i, "You are no longer a botnet master on this bot.\n");
1292 }
1293 if (!(oatr & USER_OWNER) && (u->flags & USER_OWNER)) {
1294 dprintf(i, "@@@ POOF! @@@\n");
1295 dprintf(i, "You are now an OWNER of this bot.\n");
1296 }
1297 if ((oatr & USER_OWNER) && !(u->flags & USER_OWNER)) {
1298 dprintf(i, "@@@ POOF! @@@\n");
1299 dprintf(i, "You are no longer an owner of this bot.\n");
1300 }
1301 if ((stat & STAT_PARTY) && (u->flags & USER_OP))
1302 stat &= ~STAT_PARTY;
1303 if (!(stat & STAT_PARTY) && !(u->flags & USER_OP) &&
1304 !(u->flags & USER_MASTER))
1305 stat |= STAT_PARTY;
1306 if ((stat & STAT_CHAT) && !(u->flags & USER_PARTY) &&
1307 !(u->flags & USER_MASTER) &&
1308 (!(u->flags & USER_OP) || require_p))
1309 stat &= ~STAT_CHAT;
1310 if ((dcc[i].type->flags & DCT_FILES) && !(stat & STAT_CHAT) &&
1311 ((u->flags & USER_MASTER) || (u->flags & USER_PARTY) ||
1312 ((u->flags & USER_OP) && !require_p)))
1313 stat |= STAT_CHAT;
1314 dcc[i].status = stat;
1315 /* Check if they no longer have access to wherever they are.
1316 *
1317 * NOTE: DON'T kick someone off the party line just cuz they lost +p
1318 * (pinvite script removes +p after 5 mins automatically)
1319 */
1320 if ((dcc[i].type->flags & DCT_FILES) && !(u->flags & USER_XFER) &&
1321 !(u->flags & USER_MASTER)) {
1322 dprintf(i, "-+- POOF! -+-\n");
1323 dprintf(i, "You no longer have file area access.\n\n");
1324 putlog(LOG_MISC, "*", "DCC user [%s]%s removed from file system",
1325 dcc[i].nick, dcc[i].host);
1326 if (dcc[i].status & STAT_CHAT) {
1327 struct chat_info *ci;
1328
1329 ci = dcc[i].u.file->chat;
1330 nfree(dcc[i].u.file);
1331 dcc[i].u.chat = ci;
1332 dcc[i].status &= (~STAT_CHAT);
1333 dcc[i].type = &DCC_CHAT;
1334 if (dcc[i].u.chat->channel >= 0) {
1335 chanout_but(-1, dcc[i].u.chat->channel,
1336 "*** %s has returned.\n", dcc[i].nick);
1337 if (dcc[i].u.chat->channel < 100000)
1338 botnet_send_join_idx(i, -1);
1339 }
1340 } else {
1341 killsock(dcc[i].sock);
1342 lostdcc(i);
1343 }
1344 }
1345 }
1346 if (dcc[i].type == &DCC_BOT && !egg_strcasecmp(u->handle, dcc[i].nick)) {
1347 if ((dcc[i].status & STAT_LEAF) && !(u->flags & BOT_LEAF))
1348 dcc[i].status &= ~(STAT_LEAF | STAT_WARNED);
1349 if (!(dcc[i].status & STAT_LEAF) && (u->flags & BOT_LEAF))
1350 dcc[i].status |= STAT_LEAF;
1351 }
1352 }
1353 return u->flags;
1354 }
1355
1356 int check_dcc_chanattrs(struct userrec *u, char *chname, int chflags,
1357 int ochatr)
1358 {
1359 int i, found = 0, atr = u ? u->flags : 0;
1360 struct chanset_t *chan;
1361
1362 if (!u)
1363 return 0;
1364 for (i = 0; i < dcc_total; i++) {
1365 if ((dcc[i].type->flags & DCT_MASTER) &&
1366 !egg_strcasecmp(u->handle, dcc[i].nick)) {
1367 if ((dcc[i].type == &DCC_CHAT) &&
1368 ((chflags & (USER_OP | USER_MASTER | USER_OWNER))
1369 != (ochatr & (USER_OP | USER_MASTER | USER_OWNER))))
1370 botnet_send_join_idx(i, -1);
1371 if ((ochatr & USER_MASTER) && !(chflags & USER_MASTER)) {
1372 if (!(atr & USER_MASTER))
1373 dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS);
1374 dprintf(i, "*** POOF! ***\n");
1375 dprintf(i, "You are no longer a master on %s.\n", chname);
1376 }
1377 if (!(ochatr & USER_MASTER) && (chflags & USER_MASTER)) {
1378 dcc[i].u.chat->con_flags |= conmask;
1379 if (!(atr & USER_MASTER))
1380 dcc[i].u.chat->con_flags &=
1381 ~(LOG_LEV1 | LOG_LEV2 | LOG_LEV3 | LOG_LEV4 |
1382 LOG_LEV5 | LOG_LEV6 | LOG_LEV7 | LOG_LEV8 |
1383 LOG_RAW | LOG_DEBUG | LOG_WALL | LOG_FILES | LOG_SRVOUT);
1384 dprintf(i, "*** POOF! ***\n");
1385 dprintf(i, "You are now a master on %s.\n", chname);
1386 }
1387 if (!(ochatr & USER_OWNER) && (chflags & USER_OWNER)) {
1388 dprintf(i, "@@@ POOF! @@@\n");
1389 dprintf(i, "You are now an OWNER of %s.\n", chname);
1390 }
1391 if ((ochatr & USER_OWNER) && !(chflags & USER_OWNER)) {
1392 dprintf(i, "@@@ POOF! @@@\n");
1393 dprintf(i, "You are no longer an owner of %s.\n", chname);
1394 }
1395 if (((ochatr & (USER_OP | USER_MASTER | USER_OWNER)) &&
1396 (!(chflags & (USER_OP | USER_MASTER | USER_OWNER)))) ||
1397 ((chflags & (USER_OP | USER_MASTER | USER_OWNER)) &&
1398 (!(ochatr & (USER_OP | USER_MASTER | USER_OWNER))))) {
1399 struct flag_record fr = {FR_CHAN, 0, 0, 0, 0, 0};
1400
1401 for (chan = chanset; chan && !found; chan = chan->next) {
1402 get_user_flagrec(u, &fr, chan->dname);
1403 if (fr.chan & (USER_OP | USER_MASTER | USER_OWNER))
1404 found = 1;
1405 }
1406 if (!chan)
1407 chan = chanset;
1408 if (chan)
1409 strcpy(dcc[i].u.chat->con_chan, chan->dname);
1410 else
1411 strcpy(dcc[i].u.chat->con_chan, "*");
1412 }
1413 }
1414 }
1415 return chflags;
1416 }
1417
1418 static void cmd_chattr(struct userrec *u, int idx, char *par)
1419 {
1420 char *hand, *arg = NULL, *tmpchg = NULL, *chg = NULL, work[1024];
1421 struct chanset_t *chan = NULL;
1422 struct userrec *u2;
1423 struct flag_record pls = {0, 0, 0, 0, 0, 0},
1424 mns = {0, 0, 0, 0, 0, 0},
1425 user = {0, 0, 0, 0, 0, 0};
1426 module_entry *me;
1427 int fl = -1, of = 0, ocf = 0;
1428
1429 if (!par[0]) {
1430 dprintf(idx, "Usage: chattr <handle> [changes] [channel]\n");
1431 return;
1432 }
1433 hand = newsplit(&par);
1434 u2 = get_user_by_handle(userlist, hand);
1435 if (!u2) {
1436 dprintf(idx, "No such user!\n");
1437 return;
1438 }
1439
1440 /* Parse args */
1441 if (par[0]) {
1442 arg = newsplit(&par);
1443 if (par[0]) {
1444 /* .chattr <handle> <changes> <channel> */
1445 chg = arg;
1446 arg = newsplit(&par);
1447 chan = findchan_by_dname(arg);
1448 } else {
1449 chan = findchan_by_dname(arg);
1450 /* Consider modeless channels, starting with '+' */
1451 if (!(arg[0] == '+' && chan) &&
1452 !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
1453 /* .chattr <handle> <changes> */
1454 chg = arg;
1455 chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
1456 arg = NULL;
1457 }
1458 /* .chattr <handle> <channel>: nothing to do... */
1459 }
1460 }
1461 /* arg: pointer to channel name, NULL if none specified
1462 * chan: pointer to channel structure, NULL if none found or none specified
1463 * chg: pointer to changes, NULL if none specified
1464 */
1465 Assert(!(!arg && chan));
1466 if (arg && !chan) {
1467 dprintf(idx, "No channel record for %s.\n", arg);
1468 return;
1469 }
1470 if (chg) {
1471 if (!arg && strpbrk(chg, "&|")) {
1472 /* .chattr <handle> *[&|]*: use console channel if found... */
1473 if (!strcmp ((arg = dcc[idx].u.chat->con_chan), "*"))
1474 arg = NULL;
1475 else
1476 chan = findchan_by_dname(arg);
1477 if (arg && !chan) {
1478 dprintf (idx, "Invalid console channel %s.\n", arg);
1479 return;
1480 }
1481 } else if (arg && !strpbrk(chg, "&|")) {
1482 tmpchg = nmalloc(strlen(chg) + 2);
1483 strcpy(tmpchg, "|");
1484 strcat(tmpchg, chg);
1485 chg = tmpchg;
1486 }
1487 }
1488 par = arg;
1489 user.match = FR_GLOBAL;
1490 if (chan)
1491 user.match |= FR_CHAN;
1492 get_user_flagrec(u, &user, chan ? chan->dname : 0);
1493 if (!chan && !glob_botmast(user)) {
1494 dprintf(idx, "You do not have Bot Master privileges.\n");
1495 if (tmpchg)
1496 nfree(tmpchg);
1497 return;
1498 }
1499 if (chan && !glob_master(user) && !chan_master(user)) {
1500 dprintf(idx, "You do not have channel master privileges for channel %s\n",
1501 par);
1502 if (tmpchg)
1503 nfree(tmpchg);
1504 return;
1505 }
1506 user.match &= fl;
1507 if (chg) {
1508 pls.match = user.match;
1509 break_down_flags(chg, &pls, &mns);
1510 /* No-one can change these flags on-the-fly */
1511 pls.global &= ~(USER_BOT);
1512 mns.global &= ~(USER_BOT);
1513
1514 if (chan) {
1515 pls.chan &= ~(BOT_SHARE);
1516 mns.chan &= ~(BOT_SHARE);
1517 }
1518 if (!glob_owner(user)) {
1519 pls.global &= ~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1520 mns.global &= ~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1521
1522 if (chan) {
1523 pls.chan &= ~USER_OWNER;
1524 mns.chan &= ~USER_OWNER;
1525 }
1526 if (!glob_master(user)) {
1527 pls.global &= USER_PARTY | USER_XFER;
1528 mns.global &= USER_PARTY | USER_XFER;
1529
1530 if (!glob_botmast(user)) {
1531 pls.global = 0;
1532 mns.global = 0;
1533 }
1534 }
1535 }
1536 if (chan && !chan_owner(user) && !glob_owner(user)) {
1537 pls.chan &= ~USER_MASTER;
1538 mns.chan &= ~USER_MASTER;
1539 if (!chan_master(user) && !glob_master(user)) {
1540 pls.chan = 0;
1541 mns.chan = 0;
1542 }
1543 }
1544 get_user_flagrec(u2, &user, par);
1545 if (user.match & FR_GLOBAL) {
1546 of = user.global;
1547 user.global = sanity_check((user.global |pls.global) &~mns.global);
1548
1549 user.udef_global = (user.udef_global | pls.udef_global)
1550 & ~mns.udef_global;
1551 }
1552 if (chan) {
1553 ocf = user.chan;
1554 user.chan = chan_sanity_check((user.chan | pls.chan) & ~mns.chan,
1555 user.global);
1556
1557 user.udef_chan = (user.udef_chan | pls.udef_chan) & ~mns.udef_chan;
1558 }
1559 set_user_flagrec(u2, &user, par);
1560 }
1561 if (chan)
1562 putlog(LOG_CMDS, "*", "#%s# (%s) chattr %s %s",
1563 dcc[idx].nick, chan ? chan->dname : "*", hand, chg ? chg : "");
1564 else
1565 putlog(LOG_CMDS, "*", "#%s# chattr %s %s", dcc[idx].nick, hand,
1566 chg ? chg : "");
1567 /* Get current flags and display them */
1568 if (user.match & FR_GLOBAL) {
1569 user.match = FR_GLOBAL;
1570 if (chg)
1571 check_dcc_attrs(u2, of);
1572 get_user_flagrec(u2, &user, NULL);
1573 build_flags(work, &user, NULL);
1574 if (work[0] != '-')
1575 dprintf(idx, "Global flags for %s are now +%s\n", hand, work);
1576 else
1577 dprintf(idx, "No global flags for %s.\n", hand);
1578 }
1579 if (chan) {
1580 user.match = FR_CHAN;
1581 get_user_flagrec(u2, &user, par);
1582 user.chan &= ~BOT_SHARE;
1583 if (chg)
1584 check_dcc_chanattrs(u2, chan->dname, user.chan, ocf);
1585 build_flags(work, &user, NULL);
1586 if (work[0] != '-')
1587 dprintf(idx, "Channel flags for %s on %s are now +%s\n", hand,
1588 chan->dname, work);
1589 else
1590 dprintf(idx, "No flags for %s on %s.\n", hand, chan->dname);
1591 if (chg && (me = module_find("irc", 0, 0))) {
1592 Function *func = me->funcs;
1593
1594 if (chan)
1595 (func[IRC_RECHECK_CHANNEL]) (chan, 0);
1596 }
1597 }
1598 if (tmpchg)
1599 nfree(tmpchg);
1600 }
1601
1602 static void cmd_botattr(struct userrec *u, int idx, char *par)
1603 {
1604 char *hand, *chg = NULL, *arg = NULL, *tmpchg = NULL, work[1024];
1605 struct chanset_t *chan = NULL;
1606 struct userrec *u2;
1607 struct flag_record pls = {0, 0, 0, 0, 0, 0},
1608 mns = {0, 0, 0, 0, 0, 0},
1609 user = {0, 0, 0, 0, 0, 0};
1610 int idx2;
1611
1612 if (!par[0]) {
1613 dprintf(idx, "Usage: botattr <handle> [changes] [channel]\n");
1614 return;
1615 }
1616 hand = newsplit(&par);
1617 u2 = get_user_by_handle(userlist, hand);
1618 if (!u2 || !(u2->flags & USER_BOT)) {
1619 dprintf(idx, "No such bot!\n");
1620 return;
1621 }
1622 for (idx2 = 0; idx2 < dcc_total; idx2++)
1623 if (dcc[idx2].type != &DCC_RELAY && dcc[idx2].type != &DCC_FORK_BOT &&
1624 !egg_strcasecmp(dcc[idx2].nick, hand))
1625 break;
1626 if (idx2 != dcc_total) {
1627 dprintf(idx, "You may not change the attributes of a directly linked bot.\n");
1628 return;
1629 }
1630 /* Parse args */
1631 if (par[0]) {
1632 arg = newsplit(&par);
1633 if (par[0]) {
1634 /* .botattr <handle> <changes> <channel> */
1635 chg = arg;
1636 arg = newsplit(&par);
1637 chan = findchan_by_dname(arg);
1638 } else {
1639 chan = findchan_by_dname(arg);
1640 /* Consider modeless channels, starting with '+' */
1641 if (!(arg[0] == '+' && chan) &&
1642 !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
1643 /* .botattr <handle> <changes> */
1644 chg = arg;
1645 chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
1646 arg = NULL;
1647 }
1648 /* .botattr <handle> <channel>: nothing to do... */
1649 }
1650 }
1651 /* arg: pointer to channel name, NULL if none specified
1652 * chan: pointer to channel structure, NULL if none found or none specified
1653 * chg: pointer to changes, NULL if none specified
1654 */
1655 Assert(!(!arg && chan));
1656 if (arg && !chan) {
1657 dprintf(idx, "No channel record for %s.\n", arg);
1658 return;
1659 }
1660 if (chg) {
1661 if (!arg && strpbrk(chg, "&|")) {
1662 /* botattr <handle> *[&|]*: use console channel if found... */
1663 if (!strcmp ((arg = dcc[idx].u.chat->con_chan), "*"))
1664 arg = NULL;
1665 else
1666 chan = findchan_by_dname(arg);
1667 if (arg && !chan) {
1668 dprintf (idx, "Invalid console channel %s.\n", arg);
1669 return;
1670 }
1671 } else if (arg && !strpbrk(chg, "&|")) {
1672 tmpchg = nmalloc(strlen(chg) + 2);
1673 strcpy (tmpchg, "|");
1674 strcat (tmpchg, chg);
1675 chg = tmpchg;
1676 }
1677 }
1678 par = arg;
1679
1680 user.match = FR_GLOBAL;
1681 get_user_flagrec(u, &user, chan ? chan->dname : 0);
1682 if (!glob_botmast(user)) {
1683 dprintf(idx, "You do not have Bot Master privileges.\n");
1684 if (tmpchg)
1685 nfree(tmpchg);
1686 return;
1687 }
1688 if (chg) {
1689 user.match = FR_BOT | (chan ? FR_CHAN : 0);
1690 pls.match = user.match;
1691 break_down_flags(chg, &pls, &mns);
1692 /* No-one can change these flags on-the-fly */
1693 pls.global &=~BOT_BOT;
1694 mns.global &=~BOT_BOT;
1695
1696 if (chan && glob_owner(user)) {
1697 pls.chan &= BOT_SHARE;
1698 mns.chan &= BOT_SHARE;
1699 } else {
1700 pls.chan = 0;
1701 mns.chan = 0;
1702 }
1703 if (!glob_owner(user)) {
1704 pls.bot &= ~(BOT_SHARE | BOT_GLOBAL);
1705 mns.bot &= ~(BOT_SHARE | BOT_GLOBAL);
1706 }
1707 user.match = FR_BOT | (chan ? FR_CHAN : 0);
1708 get_user_flagrec(u2, &user, par);
1709 user.bot = (user.bot | pls.bot) & ~mns.bot;
1710 if ((user.bot & BOT_SHARE) == BOT_SHARE)
1711 user.bot &= ~BOT_SHARE;
1712 if (chan)
1713 user.chan = (user.chan | pls.chan) & ~mns.chan;
1714 set_user_flagrec(u2, &user, par);
1715 }
1716 if (chan)
1717 putlog(LOG_CMDS, "*", "#%s# (%s) botattr %s %s",
1718 dcc[idx].nick, chan->dname, hand, chg ? chg : "");
1719 else
1720 putlog(LOG_CMDS, "*", "#%s# botattr %s %s", dcc[idx].nick, hand,
1721 chg ? chg : "");
1722 /* get current flags and display them */
1723 if (!chan || pls.bot || mns.bot) {
1724 user.match = FR_BOT;
1725 get_user_flagrec(u2, &user, NULL);
1726 build_flags(work, &user, NULL);
1727 if (work[0] != '-')
1728 dprintf(idx, "Bot flags for %s are now +%s\n", hand, work);
1729 else
1730 dprintf(idx, "No bot flags for %s.\n", hand);
1731 }
1732 if (chan) {
1733 user.match = FR_CHAN;
1734 get_user_flagrec(u2, &user, par);
1735 user.chan &= BOT_SHARE;
1736 build_flags(work, &user, NULL);
1737 if (work[0] != '-')
1738 dprintf(idx, "Bot flags for %s on %s are now +%s\n", hand,
1739 chan->dname, work);
1740 else
1741 dprintf(idx, "No bot flags for %s on %s.\n", hand, chan->dname);
1742 }
1743 if (tmpchg)
1744 nfree(tmpchg);
1745 }
1746
1747 static void cmd_chat(struct userrec *u, int idx, char *par)
1748 {
1749 char *arg;
1750 int newchan, oldchan;
1751 module_entry *me;
1752
1753 arg = newsplit(&par);
1754 if (!egg_strcasecmp(arg, "off")) {
1755 /* Turn chat off */
1756 if (dcc[idx].u.chat->channel < 0) {
1757 dprintf(idx, "You weren't in chat anyway!\n");
1758 return;
1759 } else {
1760 dprintf(idx, "Leaving chat mode...\n");
1761 check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
1762 dcc[idx].u.chat->channel);
1763 chanout_but(-1, dcc[idx].u.chat->channel,
1764 "*** %s left the party line.\n",
1765 dcc[idx].nick);
1766 if (dcc[idx].u.chat->channel < 100000)
1767 botnet_send_part_idx(idx, "");
1768 }
1769 dcc[idx].u.chat->channel = (-1);
1770 } else {
1771 if (arg[0] == '*') {
1772 if (((arg[1] < '0') || (arg[1] > '9'))) {
1773 if (!arg[1])
1774 newchan = 0;
1775 else {
1776 Tcl_SetVar(interp, "chan", arg, 0);
1777 if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
1778 interp->result[0])
1779 newchan = atoi(interp->result);
1780 else
1781 newchan = -1;
1782 }
1783 if (newchan < 0) {
1784 dprintf(idx, "No channel by that name.\n");
1785 return;
1786 }
1787 } else
1788 newchan = 100000 + atoi(arg + 1);
1789 if (newchan < 100000 || newchan > 199999) {
1790 dprintf(idx, "Channel # out of range: local channels must be *0-*99999\n");
1791 return;
1792 }
1793 } else {
1794 if (((arg[0] < '0') || (arg[0] > '9')) && (arg[0])) {
1795 if (!egg_strcasecmp(arg, "on"))
1796 newchan = 0;
1797 else {
1798 Tcl_SetVar(interp, "chan", arg, 0);
1799 if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
1800 interp->result[0])
1801 newchan = atoi(interp->result);
1802 else
1803 newchan = -1;
1804 }
1805 if (newchan < 0) {
1806 dprintf(idx, "No channel by that name.\n");
1807 return;
1808 }
1809 } else
1810 newchan = atoi(arg);
1811 if ((newchan < 0) || (newchan > 99999)) {
1812 dprintf(idx, "Channel # out of range: must be between 0 and 99999.\n");
1813 return;
1814 }
1815 }
1816 /* If coming back from being off the party line, make sure they're
1817 * not away.
1818 */
1819 if ((dcc[idx].u.chat->channel < 0) && (dcc[idx].u.chat->away != NULL))
1820 not_away(idx);
1821 if (dcc[idx].u.chat->channel == newchan) {
1822 if (!newchan) {
1823 dprintf(idx, "You're already on the party line!\n");
1824 return;
1825 } else {
1826 dprintf(idx, "You're already on channel %s%d!\n",
1827 (newchan < 100000) ? "" : "*", newchan % 100000);
1828 return;
1829 }
1830 } else {
1831 oldchan = dcc[idx].u.chat->channel;
1832 if (oldchan >= 0)
1833 check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock, oldchan);
1834 if (!oldchan) {
1835 chanout_but(-1, 0, "*** %s left the party line.\n", dcc[idx].nick);
1836 } else if (oldchan > 0) {
1837 chanout_but(-1, oldchan, "*** %s left the channel.\n", dcc[idx].nick);
1838 }
1839 dcc[idx].u.chat->channel = newchan;
1840 if (!newchan) {
1841 dprintf(idx, "Entering the party line...\n");
1842 chanout_but(-1, 0, "*** %s joined the party line.\n", dcc[idx].nick);
1843 } else {
1844 dprintf(idx, "Joining channel '%s'...\n", arg);
1845 chanout_but(-1, newchan, "*** %s joined the channel.\n", dcc[idx].nick);
1846 }
1847 check_tcl_chjn(botnetnick, dcc[idx].nick, newchan, geticon(idx),
1848 dcc[idx].sock, dcc[idx].host);
1849 if (newchan < 100000)
1850 botnet_send_join_idx(idx, oldchan);
1851 else if (oldchan < 100000)
1852 botnet_send_part_idx(idx, "");
1853 }
1854 }
1855 /* New style autosave here too -- rtc, 09/28/1999*/
1856 if ((me = module_find("console", 1, 1))) {
1857 Function *func = me->funcs;
1858 (func[CONSOLE_DOSTORE]) (idx);
1859 }
1860 }
1861
1862 static void cmd_echo(struct userrec *u, int idx, char *par)
1863 {
1864 module_entry *me;
1865
1866 if (!par[0]) {
1867 dprintf(idx, "Echo is currently %s.\n", dcc[idx].status & STAT_ECHO ?
1868 "on" : "off");
1869 return;
1870 }
1871 if (!egg_strcasecmp(par, "on")) {
1872 dprintf(idx, "Echo turned on.\n");
1873 dcc[idx].status |= STAT_ECHO;
1874 } else if (!egg_strcasecmp(par, "off")) {
1875 dprintf(idx, "Echo turned off.\n");
1876 dcc[idx].status &= ~STAT_ECHO;
1877 } else {
1878 dprintf(idx, "Usage: echo <on/off>\n");
1879 return;
1880 }
1881 /* New style autosave here too -- rtc, 09/28/1999*/
1882 if ((me = module_find("console", 1, 1))) {
1883 Function *func = me->funcs;
1884 (func[CONSOLE_DOSTORE]) (idx);
1885 }
1886 }
1887
1888 int stripmodes(char *s)
1889 {
1890 int res = 0;
1891
1892 for (; *s; s++)
1893 switch (tolower(*s)) {
1894 case 'b':
1895 res |= STRIP_BOLD;
1896 break;
1897 case 'c':
1898 res |= STRIP_COLOR;
1899 break;
1900 case 'r':
1901 res |= STRIP_REV;
1902 break;
1903 case 'u':
1904 res |= STRIP_UNDER;
1905 break;
1906 case 'a':
1907 res |= STRIP_ANSI;
1908 break;
1909 case 'g':
1910 res |= STRIP_BELLS;
1911 break;
1912 case '*':
1913 res |= STRIP_ALL;
1914 break;
1915 }
1916 return res;
1917 }
1918
1919 char *stripmasktype(int x)
1920 {
1921 static char s[20];
1922 char *p = s;
1923
1924 if (x & STRIP_BOLD)
1925 *p++ = 'b';
1926 if (x & STRIP_COLOR)
1927 *p++ = 'c';
1928 if (x & STRIP_REV)
1929 *p++ = 'r';
1930 if (x & STRIP_UNDER)
1931 *p++ = 'u';
1932 if (x & STRIP_ANSI)
1933 *p++ = 'a';
1934 if (x & STRIP_BELLS)
1935 *p++ = 'g';
1936 if (p == s)
1937 *p++ = '-';
1938 *p = 0;
1939 return s;
1940 }
1941
1942 static char *stripmaskname(int x)
1943 {
1944 static char s[161];
1945 int i = 0;
1946
1947 s[i] = 0;
1948 if (x & STRIP_BOLD)
1949 i += my_strcpy(s + i, "bold, ");
1950 if (x & STRIP_COLOR)
1951 i += my_strcpy(s + i, "color, ");
1952 if (x & STRIP_REV)
1953 i += my_strcpy(s + i, "reverse, ");
1954 if (x & STRIP_UNDER)
1955 i += my_strcpy(s + i, "underline, ");
1956 if (x & STRIP_ANSI)
1957 i += my_strcpy(s + i, "ansi, ");
1958 if (x & STRIP_BELLS)
1959 i += my_strcpy(s + i, "bells, ");
1960 if (!i)
1961 strcpy(s, "none");
1962 else
1963 s[i - 2] = 0;
1964 return s;
1965 }
1966
1967 static void cmd_strip(struct userrec *u, int idx, char *par)
1968 {
1969 char *nick, *changes, *c, s[2];
1970 int dest = 0, i, pls, md, ok = 0;
1971 module_entry *me;
1972
1973 if (!par[0]) {
1974 dprintf(idx, "Your current strip settings are: %s (%s)\n",
1975 stripmasktype(dcc[idx].u.chat->strip_flags),
1976 stripmaskname(dcc[idx].u.chat->strip_flags));
1977 return;
1978 }
1979 nick = newsplit(&par);
1980 if ((nick[0] != '+') && (nick[0] != '-') && u &&
1981 (u->flags & USER_MASTER)) {
1982 for (i = 0; i < dcc_total; i++)
1983 if (!egg_strcasecmp(nick, dcc[i].nick) && dcc[i].type == &DCC_CHAT &&
1984 !ok) {
1985 ok = 1;
1986 dest = i;
1987 }
1988 if (!ok) {
1989 dprintf(idx, "No such user on the party line!\n");
1990 return;
1991 }
1992 changes = par;
1993 } else {
1994 changes = nick;
1995 nick = "";
1996 dest = idx;
1997 }
1998 c = changes;
1999 if ((c[0] != '+') && (c[0] != '-'))
2000 dcc[dest].u.chat->strip_flags = 0;
2001 s[1] = 0;
2002 for (pls = 1; *c; c++) {
2003 switch (*c) {
2004 case '+':
2005 pls = 1;
2006 break;
2007 case '-':
2008 pls = 0;
2009 break;
2010 default:
2011 s[0] = *c;
2012 md = stripmodes(s);
2013 if (pls == 1)
2014 dcc[dest].u.chat->strip_flags |= md;
2015 else
2016 dcc[dest].u.chat->strip_flags &= ~md;
2017 }
2018 }
2019 if (nick[0])
2020 putlog(LOG_CMDS, "*", "#%s# strip %s %s", dcc[idx].nick, nick, changes);
2021 else
2022 putlog(LOG_CMDS, "*", "#%s# strip %s", dcc[idx].nick, changes);
2023 if (dest == idx) {
2024 dprintf(idx, "Your strip settings are: %s (%s)\n",
2025 stripmasktype(dcc[idx].u.chat->strip_flags),
2026 stripmaskname(dcc[idx].u.chat->strip_flags));
2027 } else {
2028 dprintf(idx, "Strip setting for %s: %s (%s)\n", dcc[dest].nick,
2029 stripmasktype(dcc[dest].u.chat->strip_flags),
2030 stripmaskname(dcc[dest].u.chat->strip_flags));
2031 dprintf(dest, "%s set your strip settings to: %s (%s)\n", dcc[idx].nick,
2032 stripmasktype(dcc[dest].u.chat->strip_flags),
2033 stripmaskname(dcc[dest].u.chat->strip_flags));
2034 }