/[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.91 - (show annotations) (download) (as text)
Mon Feb 18 00:07:16 2002 UTC (17 years, 9 months ago) by ite
Branch: MAIN
Changes since 1.90: +4 -3 lines
File MIME type: text/x-chdr
Fixed a couple of cosmetic problems in cmd_pls_user (synch 1.6)

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