/[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.28 - (show annotations) (download) (as text)
Sat May 6 22:00:31 2000 UTC (19 years, 6 months ago) by fabian
Branch: MAIN
Changes since 1.27: +3 -2 lines
File MIME type: text/x-chdr
misc_fix patch

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