/[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.88 - (show annotations) (download) (as text)
Tue Jan 22 01:17:16 2002 UTC (17 years, 10 months ago) by ite
Branch: MAIN
Changes since 1.87: +9 -9 lines
File MIME type: text/x-chdr
geticon() didn't really need to care about dcc table

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