/[cvs]/eggdrop1.4/src/cmds.c
ViewVC logotype

Contents of /eggdrop1.4/src/cmds.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.32 - (show annotations) (download) (as text)
Sun Jan 2 18:05:31 2000 UTC (19 years, 11 months ago) by guppy
Branch: MAIN
Changes since 1.31: +2 -2 lines
File MIME type: text/x-chdr
y2k bugs ... what y2k bugs

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