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