/[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.13 - (show annotations) (download) (as text)
Fri Dec 17 18:40:22 1999 UTC (19 years, 11 months ago) by fabian
Branch: MAIN
Changes since 1.12: +2 -4 lines
File MIME type: text/x-chdr
tothwolf's assert-nulls 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 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 = {FR_CHAN, 0, 0, 0, 0, 0};
1392
1393 while (chan && !found) {
1394 get_user_flagrec(u, &fr, chan->dname);
1395 if (fr.chan & (USER_OP | USER_MASTER | USER_OWNER))
1396 found = 1;
1397 else
1398 chan = chan->next;
1399 }
1400 if (!chan)
1401 chan = chanset;
1402 if (chan)
1403 strcpy(dcc[i].u.chat->con_chan, chan->dname);
1404 else
1405 strcpy(dcc[i].u.chat->con_chan, "*");
1406 }
1407 }
1408 }
1409 return chflags;
1410 }
1411
1412 static void cmd_chattr(struct userrec *u, int idx, char *par)
1413 {
1414 char *hand, *arg = NULL, *tmpchg = NULL, *chg = NULL, work[1024];
1415 struct chanset_t *chan = NULL;
1416 struct userrec *u2;
1417 struct flag_record pls = {0, 0, 0, 0, 0, 0},
1418 mns = {0, 0, 0, 0, 0, 0},
1419 user = {0, 0, 0, 0, 0, 0};
1420 module_entry *me;
1421 int fl = -1, of = 0, ocf = 0;
1422
1423 if (!par[0]) {
1424 dprintf(idx, "Usage: chattr <handle> [changes] [channel]\n");
1425 return;
1426 }
1427 hand = newsplit(&par);
1428 u2 = get_user_by_handle(userlist, hand);
1429 if (!u2) {
1430 dprintf(idx, "No such user!\n");
1431 return;
1432 }
1433
1434 /* Parse args */
1435 if (par[0]) {
1436 arg = newsplit(&par);
1437 if (par[0]) {
1438 /* .chattr <handle> <changes> <channel> */
1439 chg = arg;
1440 arg = newsplit(&par);
1441 chan = findchan_by_dname(arg);
1442 } else {
1443 chan = findchan_by_dname(arg);
1444 /* ugly hack for modeless channels -- rtc */
1445 if (!(arg[0] == '+' && chan) &&
1446 !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
1447 /* .chattr <handle> <changes> */
1448 chg = arg;
1449 chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
1450 arg = NULL;
1451 }
1452 /* .chattr <handle> <channel>: nothing to do... */
1453 }
1454 }
1455 /* arg: pointer to channel name, NULL if none specified
1456 * chan: pointer to channel structure, NULL if none found or none specified
1457 * chg: pointer to changes, NULL if none specified
1458 */
1459 Assert(!(!arg && chan));
1460 if (arg && !chan) {
1461 dprintf(idx, "No channel record for %s.\n", arg);
1462 return;
1463 }
1464 if (chg) {
1465 if (!arg && strpbrk(chg, "&|")) {
1466 /* .chattr <handle> *[&|]*: use console channel if found... */
1467 if (!strcmp ((arg = dcc[idx].u.chat->con_chan), "*"))
1468 arg = NULL;
1469 else
1470 chan = findchan_by_dname(arg);
1471 if (arg && !chan) {
1472 dprintf (idx, "Invalid console channel %s.\n", arg);
1473 return;
1474 }
1475 } else if (arg && !strpbrk(chg, "&|")) {
1476 Context;
1477 tmpchg = nmalloc(strlen(chg) + 2);
1478 strcpy(tmpchg, "|");
1479 strcat(tmpchg, chg);
1480 chg = tmpchg;
1481 }
1482 }
1483 par = arg;
1484 user.match = FR_GLOBAL;
1485 if (chan)
1486 user.match |= FR_CHAN;
1487 get_user_flagrec(u, &user, chan ? chan->dname : 0);
1488 if (!chan && !glob_botmast(user)) {
1489 dprintf(idx, "You do not have Bot Master privileges.\n");
1490 if (tmpchg)
1491 nfree(tmpchg);
1492 return;
1493 }
1494 if (chan && !glob_master(user) && !chan_master(user)) {
1495 dprintf(idx, "You do not have channel master privileges for channel %s\n",
1496 par);
1497 if (tmpchg)
1498 nfree(tmpchg);
1499 return;
1500 }
1501 user.match &= fl;
1502 if (chg) {
1503 pls.match = user.match;
1504 break_down_flags(chg, &pls, &mns);
1505 /* no-one can change these flags on-the-fly */
1506 pls.global &= ~(USER_BOT);
1507 mns.global &= ~(USER_BOT);
1508
1509 if (chan) {
1510 pls.chan &= ~(BOT_SHARE);
1511 mns.chan &= ~(BOT_SHARE);
1512 }
1513 if (!glob_owner(user)) {
1514 pls.global &= ~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1515 mns.global &= ~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1516
1517 if (chan) {
1518 pls.chan &= ~USER_OWNER;
1519 mns.chan &= ~USER_OWNER;
1520 }
1521 if (!glob_master(user)) {
1522 pls.global &= USER_PARTY | USER_XFER;
1523 mns.global &= USER_PARTY | USER_XFER;
1524
1525 if (!glob_botmast(user)) {
1526 pls.global = 0;
1527 mns.global = 0;
1528 }
1529 }
1530 }
1531 if (chan && !chan_owner(user) && !glob_owner(user)) {
1532 pls.chan &= ~USER_MASTER;
1533 mns.chan &= ~USER_MASTER;
1534 if (!chan_master(user) && !glob_master(user)) {
1535 pls.chan = 0;
1536 mns.chan = 0;
1537 }
1538 }
1539 get_user_flagrec(u2, &user, par);
1540 if (user.match & FR_GLOBAL) {
1541 of = user.global;
1542 user.global = sanity_check((user.global |pls.global) &~mns.global);
1543
1544 user.udef_global = (user.udef_global | pls.udef_global)
1545 & ~mns.udef_global;
1546 }
1547 if (chan) {
1548 ocf = user.chan;
1549 user.chan = chan_sanity_check((user.chan | pls.chan) & ~mns.chan,
1550 user.global);
1551
1552 user.udef_chan = (user.udef_chan | pls.udef_chan) & ~mns.udef_chan;
1553 }
1554 set_user_flagrec(u2, &user, par);
1555 }
1556 if (chan)
1557 putlog(LOG_CMDS, "*", "#%s# (%s) chattr %s %s",
1558 dcc[idx].nick, chan ? chan->dname : "*", hand, chg ? chg : "");
1559 else
1560 putlog(LOG_CMDS, "*", "#%s# chattr %s %s", dcc[idx].nick, hand,
1561 chg ? chg : "");
1562 /* get current flags and display them */
1563 if (user.match & FR_GLOBAL) {
1564 user.match = FR_GLOBAL;
1565 if (chg)
1566 check_dcc_attrs(u2, of);
1567 get_user_flagrec(u2, &user, NULL);
1568 build_flags(work, &user, NULL);
1569 if (work[0] != '-')
1570 dprintf(idx, "Global flags for %s are now +%s\n", hand, work);
1571 else
1572 dprintf(idx, "No global flags for %s.\n", hand);
1573 }
1574 if (chan) {
1575 user.match = FR_CHAN;
1576 get_user_flagrec(u2, &user, par);
1577 user.chan &= ~BOT_SHARE;
1578 if (chg)
1579 check_dcc_chanattrs(u2, chan->dname, user.chan, ocf);
1580 build_flags(work, &user, NULL);
1581 if (work[0] != '-')
1582 dprintf(idx, "Channel flags for %s on %s are now +%s\n", hand,
1583 chan->dname, work);
1584 else
1585 dprintf(idx, "No flags for %s on %s.\n", hand, chan->dname);
1586 if (chg && (me = module_find("irc", 0, 0))) {
1587 Function *func = me->funcs;
1588
1589 if (chan)
1590 (func[IRC_RECHECK_CHANNEL]) (chan, 0);
1591 }
1592 }
1593 if (tmpchg)
1594 nfree(tmpchg);
1595 }
1596
1597 static void cmd_botattr(struct userrec *u, int idx, char *par)
1598 {
1599 char *hand, *chg = NULL, *arg = NULL, *tmpchg = NULL, work[1024];
1600 struct chanset_t *chan = NULL;
1601 struct userrec *u2;
1602 struct flag_record pls = {0, 0, 0, 0, 0, 0},
1603 mns = {0, 0, 0, 0, 0, 0},
1604 user = {0, 0, 0, 0, 0, 0};
1605 int idx2;
1606
1607 if (!par[0]) {
1608 dprintf(idx, "Usage: botattr <handle> [changes] [channel]\n");
1609 return;
1610 }
1611 hand = newsplit(&par);
1612 u2 = get_user_by_handle(userlist, hand);
1613 if (!u2 || !(u2->flags & USER_BOT)) {
1614 dprintf(idx, "No such bot!\n");
1615 return;
1616 }
1617 for (idx2 = 0; idx2 < dcc_total; idx2++)
1618 if (!strcasecmp(dcc[idx2].nick, hand))
1619 break;
1620 if (idx2 != dcc_total) {
1621 dprintf(idx, "You may not change the attributes of a directly linked bot.\n");
1622 return;
1623 }
1624 /* Parse args */
1625 if (par[0]) {
1626 arg = newsplit(&par);
1627 if (par[0]) {
1628 /* .botattr <handle> <changes> <channel> */
1629 chg = arg;
1630 arg = newsplit(&par);
1631 chan = findchan_by_dname(arg);
1632 } else {
1633 chan = findchan_by_dname(arg);
1634 /* ugly hack for modeless channels -- rtc */
1635 if (!(arg[0] == '+' && chan) &&
1636 !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
1637 /* .botattr <handle> <changes> */
1638 chg = arg;
1639 chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
1640 arg = NULL;
1641 }
1642 /* .botattr <handle> <channel>: nothing to do... */
1643 }
1644 }
1645 /* arg: pointer to channel name, NULL if none specified
1646 * chan: pointer to channel structure, NULL if none found or none specified
1647 * chg: pointer to changes, NULL if none specified
1648 */
1649 Assert(!(!arg && chan));
1650 if (arg && !chan) {
1651 dprintf(idx, "No channel record for %s.\n", arg);
1652 return;
1653 }
1654 if (chg) {
1655 if (!arg && strpbrk(chg, "&|")) {
1656 /* botattr <handle> *[&|]*: use console channel if found... */
1657 if (!strcmp ((arg = dcc[idx].u.chat->con_chan), "*"))
1658 arg = NULL;
1659 else
1660 chan = findchan_by_dname(arg);
1661 if (arg && !chan) {
1662 dprintf (idx, "Invalid console channel %s.\n", arg);
1663 return;
1664 }
1665 } else if (arg && !strpbrk(chg, "&|")) {
1666 Context;
1667 tmpchg = nmalloc(strlen(chg) + 2);
1668 strcpy (tmpchg, "|");
1669 strcat (tmpchg, chg);
1670 chg = tmpchg;
1671 }
1672 }
1673 par = arg;
1674
1675 user.match = FR_GLOBAL;
1676 get_user_flagrec(u, &user, chan ? chan->dname : 0);
1677 if (!glob_botmast(user)) {
1678 dprintf(idx, "You do not have Bot Master privileges.\n");
1679 if (tmpchg)
1680 nfree(tmpchg);
1681 return;
1682 }
1683 if (chg) {
1684 user.match = FR_BOT | (chan ? FR_CHAN : 0);
1685 pls.match = user.match;
1686 break_down_flags(chg, &pls, &mns);
1687 /* no-one can change these flags on-the-fly */
1688 pls.global &=~BOT_BOT;
1689 mns.global &=~BOT_BOT;
1690
1691 if (chan && glob_owner(user)) {
1692 pls.chan &= BOT_SHARE;
1693 mns.chan &= BOT_SHARE;
1694 } else {
1695 pls.chan = 0;
1696 mns.chan = 0;
1697 }
1698 if (!glob_owner(user)) {
1699 pls.bot &= ~(BOT_SHARE | BOT_GLOBAL);
1700 mns.bot &= ~(BOT_SHARE | BOT_GLOBAL);
1701 }
1702 user.match = FR_BOT | (chan ? FR_CHAN : 0);
1703 get_user_flagrec(u2, &user, par);
1704 user.bot = (user.bot | pls.bot) & ~mns.bot;
1705 if ((user.bot & BOT_SHARE) == BOT_SHARE)
1706 user.bot &= ~BOT_SHARE;
1707 if (chan)
1708 user.chan = (user.chan | pls.chan) & ~mns.chan;
1709 set_user_flagrec(u2, &user, par);
1710 }
1711 if (chan)
1712 putlog(LOG_CMDS, "*", "#%s# (%s) botattr %s %s",
1713 dcc[idx].nick, chan->dname, hand, chg ? chg : "");
1714 else
1715 putlog(LOG_CMDS, "*", "#%s# botattr %s %s", dcc[idx].nick, hand,
1716 chg ? chg : "");
1717 /* get current flags and display them */
1718 if (!chan || pls.bot || mns.bot) {
1719 user.match = FR_BOT;
1720 get_user_flagrec(u2, &user, NULL);
1721 build_flags(work, &user, NULL);
1722 if (work[0] != '-')
1723 dprintf(idx, "Bot flags for %s are now +%s\n", hand, work);
1724 else
1725 dprintf(idx, "No bot flags for %s.\n", hand);
1726 }
1727 if (chan) {
1728 user.match = FR_CHAN;
1729 get_user_flagrec(u2, &user, par);
1730 user.chan &= BOT_SHARE;
1731 build_flags(work, &user, NULL);
1732 if (work[0] != '-')
1733 dprintf(idx, "Bot flags for %s on %s are now +%s\n", hand,
1734 chan->dname, work);
1735 else
1736 dprintf(idx, "No bot flags for %s on %s.\n", hand, chan->dname);
1737 }
1738 if (tmpchg)
1739 nfree(tmpchg);
1740 }
1741
1742 static void cmd_chat(struct userrec *u, int idx, char *par)
1743 {
1744 char *arg;
1745 int newchan, oldchan;
1746 module_entry *me;
1747
1748 arg = newsplit(&par);
1749 if (!strcasecmp(arg, "off")) {
1750 /* turn chat off */
1751 if (dcc[idx].u.chat->channel < 0) {
1752 dprintf(idx, "You weren't in chat anyway!\n");
1753 return;
1754 } else {
1755 dprintf(idx, "Leaving chat mode...\n");
1756 check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
1757 dcc[idx].u.chat->channel);
1758 chanout_but(-1, dcc[idx].u.chat->channel,
1759 "*** %s left the party line.\n",
1760 dcc[idx].nick);
1761 Context;
1762 if (dcc[idx].u.chat->channel < 100000)
1763 botnet_send_part_idx(idx, "");
1764 }
1765 dcc[idx].u.chat->channel = (-1);
1766 } else {
1767 if (arg[0] == '*') {
1768 if (((arg[1] < '0') || (arg[1] > '9'))) {
1769 if (arg[1] == 0)
1770 newchan = 0;
1771 else {
1772 Tcl_SetVar(interp, "chan", arg, 0);
1773 if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
1774 interp->result[0])
1775 newchan = atoi(interp->result);
1776 else
1777 newchan = -1;
1778 }
1779 if (newchan < 0) {
1780 dprintf(idx, "No channel by that name.\n");
1781 return;
1782 }
1783 } else
1784 newchan = 100000 + atoi(arg + 1);
1785 if (newchan < 100000 || newchan > 199999) {
1786 dprintf(idx, "Channel # out of range: local channels must be *0-*99999\n");
1787 return;
1788 }
1789 } else {
1790 if (((arg[0] < '0') || (arg[0] > '9')) && (arg[0])) {
1791 if (!strcasecmp(arg, "on"))
1792 newchan = 0;
1793 else {
1794 Tcl_SetVar(interp, "chan", arg, 0);
1795 if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
1796 interp->result[0])
1797 newchan = atoi(interp->result);
1798 else
1799 newchan = -1;
1800 }
1801 if (newchan < 0) {
1802 dprintf(idx, "No channel by that name.\n");
1803 return;
1804 }
1805 } else
1806 newchan = atoi(arg);
1807 if ((newchan < 0) || (newchan > 99999)) {
1808 dprintf(idx, "Channel # out of range: must be between 0 and 99999.\n");
1809 return;
1810 }
1811 }
1812 /* if coming back from being off the party line, make sure they're
1813 * not away */
1814 if ((dcc[idx].u.chat->channel < 0) && (dcc[idx].u.chat->away != NULL))
1815 not_away(idx);
1816 if (dcc[idx].u.chat->channel == newchan) {
1817 if (newchan == 0) {
1818 dprintf(idx, "You're already on the party line!\n");
1819 return;
1820 } else {
1821 dprintf(idx, "You're already on channel %s%d!\n",
1822 (newchan < 100000) ? "" : "*", newchan % 100000);
1823 return;
1824 }
1825 } else {
1826 oldchan = dcc[idx].u.chat->channel;
1827 if (oldchan >= 0)
1828 check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock, oldchan);
1829 if (oldchan == 0) {
1830 chanout_but(-1, 0, "*** %s left the party line.\n", dcc[idx].nick);
1831 Context;
1832 } else if (oldchan > 0) {
1833 chanout_but(-1, oldchan, "*** %s left the channel.\n", dcc[idx].nick);
1834 Context;
1835 }
1836 dcc[idx].u.chat->channel = newchan;
1837 if (newchan == 0) {
1838 dprintf(idx, "Entering the party line...\n");
1839 chanout_but(-1, 0, "*** %s joined the party line.\n", dcc[idx].nick);
1840 Context;
1841 } else {
1842 dprintf(idx, "Joining channel '%s'...\n", arg);
1843 chanout_but(-1, newchan, "*** %s joined the channel.\n", dcc[idx].nick);
1844 Context;
1845 }
1846 check_tcl_chjn(botnetnick, dcc[idx].nick, newchan, geticon(idx),
1847 dcc[idx].sock, dcc[idx].host);
1848 if (newchan < 100000)
1849 botnet_send_join_idx(idx, oldchan);
1850 else if (oldchan < 100000)
1851 botnet_send_part_idx(idx, "");
1852 }
1853 }
1854 /* new style autosave here too -- rtc, 09/28/1999*/
1855 if ((me = module_find("console", 1, 1))) {
1856 Function *func = me->funcs;
1857 (func[CONSOLE_DOSTORE]) (idx);
1858 }
1859 }
1860
1861 static void cmd_echo(struct userrec *u, int idx, char *par)
1862 {
1863 module_entry *me;
1864
1865 if (!par[0]) {
1866 dprintf(idx, "Echo is currently %s.\n", dcc[idx].status & STAT_ECHO ?
1867 "on" : "off");
1868 return;
1869 }
1870 if (!strcasecmp(par, "on")) {
1871 dprintf(idx, "Echo turned on.\n");
1872 dcc[idx].status |= STAT_ECHO;
1873 } else if (!strcasecmp(par, "off")) {
1874 dprintf(idx, "Echo turned off.\n");
1875 dcc[idx].status &= ~STAT_ECHO;
1876 } else {
1877 dprintf(idx, "Usage: echo <on/off>\n");
1878 return;
1879 }
1880 /* new style autosave here too -- rtc, 09/28/1999*/
1881 if ((me = module_find("console", 1, 1))) {
1882 Function *func = me->funcs;
1883 (func[CONSOLE_DOSTORE]) (idx);
1884 }
1885 }
1886
1887 int stripmodes(char *s)
1888 {
1889 int res = 0;
1890
1891 for (; *s; s++)
1892 switch (tolower(*s)) {
1893 case 'b':
1894 res |= STRIP_BOLD;
1895 break;
1896 case 'c':
1897 res |= STRIP_COLOR;
1898 break;
1899 case 'r':
1900 res |= STRIP_REV;
1901 break;
1902 case 'u':
1903 res |= STRIP_UNDER;
1904 break;
1905 case 'a':
1906 res |= STRIP_ANSI;
1907 break;
1908 case 'g':
1909 res |= STRIP_BELLS;
1910 break;
1911 case '*':
1912 res |= STRIP_ALL;
1913 break;
1914 }
1915 return res;
1916 }
1917
1918 char *stripmasktype(int x)
1919 {
1920 static char s[20];
1921 char *p = s;
1922
1923 if (x & STRIP_BOLD)
1924 *p++ = 'b';
1925 if (x & STRIP_COLOR)
1926 *p++ = 'c';
1927 if (x & STRIP_REV)
1928 *p++ = 'r';
1929 if (x & STRIP_UNDER)
1930 *p++ = 'u';
1931 if (x & STRIP_ANSI)
1932 *p++ = 'a';
1933 if (x & STRIP_BELLS)
1934 *p++ = 'g';
1935 if (p == s)
1936 *p++ = '-';
1937 *p = 0;
1938 return s;
1939 }
1940
1941 static char *stripmaskname(int x)
1942 {
1943 static char s[161];
1944 int i = 0;
1945
1946 s[i] = 0;
1947 if (x & STRIP_BOLD)
1948 i += my_strcpy(s + i, "bold, ");
1949 if (x & STRIP_COLOR)
1950 i += my_strcpy(s + i, "color, ");
1951 if (x & STRIP_REV)
1952 i += my_strcpy(s + i, "reverse, ");
1953 if (x & STRIP_UNDER)
1954 i += my_strcpy(s + i, "underline, ");
1955 if (x & STRIP_ANSI)
1956 i += my_strcpy(s + i, "ansi, ");
1957 if (x & STRIP_BELLS)
1958 i += my_strcpy(s + i, "bells, ");
1959 if (!i)
1960 strcpy(s, "none");
1961 else
1962 s[i - 2] = 0;
1963 return s;
1964 }
1965
1966 static void cmd_strip(struct userrec *u, int idx, char *par)
1967 {
1968 char *nick, *changes, *c, s[2];
1969 int dest = 0, i, pls, md, ok = 0;
1970 module_entry *me;
1971
1972 if (!par[0]) {
1973 dprintf(idx, "Your current strip settings are: %s (%s)\n",
1974 stripmasktype(dcc[idx].u.chat->strip_flags),
1975 stripmaskname(dcc[idx].u.chat->strip_flags));
1976 return;
1977 }
1978 nick = newsplit(&par);
1979 if ((nick[0] != '+') && (nick[0] != '-') && u &&
1980 (u->flags & USER_MASTER)) {
1981 for (i = 0; i < dcc_total; i++)
1982 if (!strcasecmp(nick, dcc[i].nick) && (dcc[i].type == &DCC_CHAT) &&
1983 !ok) {
1984 ok = 1;
1985 dest = i;
1986 }
1987 if (!ok) {
1988 dprintf(idx, "No such user on the party line!\n");
1989 return;
1990 }
1991 changes = par;
1992 } else {
1993 changes = nick;
1994 nick = "";
1995 dest = idx;
1996 }
1997 c = changes;
1998 if ((c[0] != '+') && (c[0] != '-'))
1999 dcc[dest].u.chat->strip_flags = 0;
2000 s[1] = 0;
2001 for (pls = 1; *c; c++) {
2002 switch (*c) {
2003 case '+':
2004 pls = 1;
2005 break;
2006 case '-':
2007 pls = 0;
2008 break;
2009 default:
2010 s[0] = *c;
2011 md = stripmodes(s);
2012 if (pls == 1)
2013 dcc[dest].u.chat->strip_flags |= md;
2014 else
2015 dcc[dest].u.chat->strip_flags &= ~md;
2016 }
2017 }
2018 if (nick[0])
2019 putlog(LOG_CMDS, "*", "#%s# strip %s %s", dcc[idx].nick, nick, changes);
2020 else
2021 putlog(LOG_CMDS, "*", "#%s# strip %s", dcc[idx].nick, changes);
2022 if (dest == idx) {
2023 dprintf(idx, "Your strip settings are: %s (%s)\n",
2024 stripmasktype(dcc[idx].u.chat->strip_flags),
2025 stripmaskname(dcc[idx].u.chat->strip_flags));
2026 } else {
2027 dprintf(idx, "Strip setting for %s: %s (%s)\n", dcc[dest].nick,
2028