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

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

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


Revision 1.9 - (show annotations) (download) (as text)
Thu Aug 26 08:41:29 1999 UTC (20 years ago) by guppy
Branch: MAIN
Changes since 1.8: +6 -0 lines
File MIME type: text/x-chdr
console autosave patch by drummer

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