/[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.49 - (show annotations) (download) (as text)
Thu Apr 12 02:39:43 2001 UTC (18 years, 7 months ago) by guppy
Branch: MAIN
Changes since 1.48: +21 -21 lines
File MIME type: text/x-chdr
lets update the copyright info for 2001 k? :P~

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