/[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.13 - (show annotations) (download) (as text)
Wed Sep 15 06:04:08 1999 UTC (20 years ago) by poptix
Branch: MAIN
Changes since 1.12: +1 -130 lines
File MIME type: text/x-chdr

notesignore3 and notesignore4.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 #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 else if (isowner(hand) && strcasecmp(dcc[idx].nick, hand))
844 dprintf(idx, "Can't change the permanent bot owner's handle.\n");
845 else if (change_handle(u2, newhand)) {
846 putlog(LOG_CMDS, "*", "#%s# chnick %s %s", dcc[idx].nick,
847 hand, newhand);
848 dprintf(idx, "Changed.\n");
849 } else
850 dprintf(idx, "Failed.\n");
851 }
852 }
853 }
854
855 static void cmd_nick(struct userrec *u, int idx, char *par)
856 {
857 int i, len = strlen(par);
858 char oldnick[HANDLEN + 1], *newnick;
859
860 if (!len) {
861 dprintf(idx, "Usage: nick <new-handle>\n");
862 return;
863 }
864 newnick = newsplit(&par);
865 if (len > HANDLEN)
866 newnick[len = HANDLEN] = 0;
867 for (i = 0; i < len; i++)
868 if ((newnick[i] <= 32) || (newnick[i] >= 127) || (newnick[i] == '@'))
869 newnick[i] = '?';
870 if (strchr(BADNICKCHARS, newnick[0]) != NULL) {
871 dprintf(idx, "Bizarre quantum forces prevent nicknames from starting with '%c'\n",
872 newnick[0]);
873 } else if (get_user_by_handle(userlist, newnick) &&
874 strcasecmp(dcc[idx].nick, newnick)) {
875 dprintf(idx, "Somebody is already using %s.\n", newnick);
876 } else if (!strcasecmp(newnick, origbotname) ||
877 !strcasecmp(newnick, botnetnick)) {
878 dprintf(idx, "Hey! That's MY name!\n", par);
879 } else {
880 strcpy(oldnick, dcc[idx].nick);
881 if (change_handle(u, newnick)) {
882 putlog(LOG_CMDS, "*", "#%s# nick %s", oldnick, newnick);
883 dprintf(idx, "Okay, changed.\n");
884 } else
885 dprintf(idx, "Failed.\n");
886 }
887 }
888
889 static void cmd_chpass(struct userrec *u, int idx, char *par)
890 {
891 char *handle, *new;
892 int atr = u ? u->flags : 0, l;
893
894 if (!par[0])
895 dprintf(idx, "Usage: chpass <handle> [password]\n");
896 else {
897 handle = newsplit(&par);
898 u = get_user_by_handle(userlist, handle);
899 if (!u)
900 dprintf(idx, "No such user.\n");
901 else if ((atr & USER_BOTMAST) && !(atr & USER_MASTER) &&
902 !(u->flags & USER_BOT))
903 dprintf(idx, "You can't change password for non-bots.\n");
904 else if ((bot_flags(u) & BOT_SHARE) && !(atr & USER_OWNER))
905 dprintf(idx, "You can't change shared bot's password.\n");
906 else if ((u->flags & USER_OWNER) && !(atr & USER_OWNER) &&
907 strcasecmp(handle, dcc[idx].nick))
908 dprintf(idx, "Can't change the bot owner's password.\n");
909 else if (!par[0]) {
910 putlog(LOG_CMDS, "*", "#%s# chpass %s [nothing]", dcc[idx].nick,
911 handle);
912 set_user(&USERENTRY_PASS, u, NULL);
913 dprintf(idx, "Removed password.\n");
914 } else {
915 l = strlen(new = newsplit(&par));
916 if (l > 16)
917 new[16] = 0;
918 if (l < 6)
919 dprintf(idx, "Please use at least 6 characters.\n");
920 else {
921 set_user(&USERENTRY_PASS, u, new);
922 putlog(LOG_CMDS, "*", "#%s# chpass %s [something]", dcc[idx].nick,
923 handle);
924 dprintf(idx, "Changed password.\n");
925 }
926 }
927 }
928 }
929
930 static void cmd_chaddr(struct userrec *u, int idx, char *par)
931 {
932 char *handle, *addr, *p, *q;
933 struct bot_addr *bi;
934 struct userrec *u1;
935
936 if (!par[0]) {
937 dprintf(idx, "Usage: chaddr <botname> <address:botport#/userport#>\n");
938 return;
939 }
940 handle = newsplit(&par);
941 addr = newsplit(&par);
942 if (strlen(addr) > UHOSTLEN)
943 addr[UHOSTLEN] = 0;
944 u1 = get_user_by_handle(userlist, handle);
945 if (!u1 || !(u1->flags & USER_BOT)) {
946 dprintf(idx, "Useful only for tandem bots.\n");
947 return;
948 }
949 if ((bot_flags(u1) & BOT_SHARE) && (!u || !u->flags & USER_OWNER)) {
950 dprintf(idx, "You can't change shared bot's address.\n");
951 return;
952 }
953 putlog(LOG_CMDS, "*", "#%s# chaddr %s %s", dcc[idx].nick, handle, addr);
954 dprintf(idx, "Changed bot's address.\n");
955 bi = user_malloc(sizeof(struct bot_addr));
956
957 q = strchr(addr, ':');
958 if (!q) {
959 bi->address = user_malloc(strlen(addr) + 1);
960 strcpy(bi->address, addr);
961 bi->telnet_port = 3333;
962 bi->relay_port = 3333;
963 } else {
964 bi->address = user_malloc(q - addr + 1);
965 strncpy(bi->address, addr, q - addr);
966 bi->address[q - addr] = 0;
967 p = q + 1;
968 bi->telnet_port = atoi(p);
969 q = strchr(p, '/');
970 if (!q) {
971 bi->relay_port = bi->telnet_port;
972 } else {
973 bi->relay_port = atoi(q + 1);
974 }
975 }
976 set_user(&USERENTRY_BOTADDR, u1, bi);
977 }
978
979 static void cmd_comment(struct userrec *u, int idx, char *par)
980 {
981 char *handle;
982 struct userrec *u1;
983
984 if (!par[0]) {
985 dprintf(idx, "Usage: comment <handle> <newcomment>\n");
986 return;
987 }
988 handle = newsplit(&par);
989 u1 = get_user_by_handle(userlist, handle);
990 if (!u1) {
991 dprintf(idx, "No such user!\n");
992 return;
993 }
994 if ((u1->flags & USER_OWNER) && !(u && (u->flags & USER_OWNER)) &&
995 strcasecmp(handle, dcc[idx].nick)) {
996 dprintf(idx, "Can't change comment on the bot owner.\n");
997 return;
998 }
999 putlog(LOG_CMDS, "*", "#%s# comment %s %s", dcc[idx].nick, handle, par);
1000 if (!strcasecmp(par, "none")) {
1001 dprintf(idx, "Okay, comment blanked.\n");
1002 set_user(&USERENTRY_COMMENT, u1, NULL);
1003 return;
1004 }
1005 dprintf(idx, "Changed comment.\n");
1006 set_user(&USERENTRY_COMMENT, u1, par);
1007 }
1008
1009 static void cmd_restart(struct userrec *u, int idx, char *par)
1010 {
1011 putlog(LOG_CMDS, "*", "#%s# restart", dcc[idx].nick);
1012 if (!backgrd) {
1013 dprintf(idx, "You can not .restart a bot when running -n (due to tcl)\n");
1014 return;
1015 }
1016 dprintf(idx, "Restarting.\n");
1017 if (make_userfile) {
1018 putlog(LOG_MISC, "*",
1019 "Uh, guess you don't need to create a new userfile.");
1020 make_userfile = 0;
1021 }
1022 write_userfile(-1);
1023 putlog(LOG_MISC, "*", "Restarting ...");
1024 wipe_timers(interp, &utimer);
1025 wipe_timers(interp, &timer);
1026 do_restart = idx;
1027 }
1028
1029 static void cmd_rehash(struct userrec *u, int idx, char *par)
1030 {
1031 putlog(LOG_CMDS, "*", "#%s# rehash", dcc[idx].nick);
1032 dprintf(idx, "Rehashing.\n");
1033 if (make_userfile) {
1034 putlog(LOG_MISC, "*",
1035 "Uh, guess you don't need to create a new userfile.");
1036 make_userfile = 0;
1037 }
1038 write_userfile(-1);
1039 putlog(LOG_MISC, "*", "Rehashing ...");
1040 do_restart = -2;
1041 }
1042
1043 static void cmd_reload(struct userrec *u, int idx, char *par)
1044 {
1045 putlog(LOG_CMDS, "*", "#%s# reload", dcc[idx].nick);
1046 dprintf(idx, "Reloading user file...\n");
1047 reload();
1048 }
1049
1050 /* this get replaced in server.so with a version that handles the server */
1051 void cmd_die(struct userrec *u, int idx, char *par)
1052 {
1053 char s[1024];
1054
1055 putlog(LOG_CMDS, "*", "#%s# die %s", dcc[idx].nick, par);
1056 if (par[0]) {
1057 simple_sprintf(s, "BOT SHUTDOWN (%s: %s)", dcc[idx].nick, par);
1058 } else {
1059 simple_sprintf(s, "BOT SHUTDOWN (authorized by %s)", dcc[idx].nick);
1060 }
1061 chatout("*** %s\n", s);
1062 botnet_send_chat(-1, botnetnick, s);
1063 botnet_send_bye();
1064 write_userfile(-1);
1065 simple_sprintf(s, "DIE BY %s!%s (%s)", dcc[idx].nick,
1066 dcc[idx].host, par[0] ? par : "request");
1067 fatal(s, 0);
1068 }
1069
1070 static void cmd_debug(struct userrec *u, int idx, char *par)
1071 {
1072 if (!strcasecmp(par, "help")) {
1073 putlog(LOG_CMDS, "*", "#%s# debug help", dcc[idx].nick);
1074 debug_help(idx);
1075 } else {
1076 putlog(LOG_CMDS, "*", "#%s# debug", dcc[idx].nick);
1077 debug_mem_to_dcc(idx);
1078 }
1079 }
1080
1081 static void cmd_simul(struct userrec *u, int idx, char *par)
1082 {
1083 char *nick;
1084 int i, ok = 0;
1085
1086 nick = newsplit(&par);
1087 if (!par[0]) {
1088 dprintf(idx, "Usage: simul <nick> <text>\n");
1089 return;
1090 }
1091 if (isowner(nick)) {
1092 dprintf(idx, "Unable to '.simul' permanent owners.\n");
1093 return;
1094 }
1095 for (i = 0; i < dcc_total; i++)
1096 if (!strcasecmp(nick, dcc[i].nick) && !ok &&
1097 (dcc[i].type->flags & DCT_SIMUL)) {
1098 putlog(LOG_CMDS, "*", "#%s# simul %s %s", dcc[idx].nick, nick, par);
1099 if (dcc[i].type && dcc[i].type->activity) {
1100 dcc[i].type->activity(i, par, strlen(par));
1101 ok = 1;
1102 }
1103 }
1104 if (!ok)
1105 dprintf(idx, "No such user on the party line.\n");
1106 }
1107
1108 static void cmd_link(struct userrec *u, int idx, char *par)
1109 {
1110 char *s;
1111 int i;
1112
1113 if (!par[0]) {
1114 dprintf(idx, "Usage: link [some-bot] <new-bot>\n");
1115 return;
1116 }
1117 putlog(LOG_CMDS, "*", "#%s# link %s", dcc[idx].nick, par);
1118 s = newsplit(&par);
1119 if (!par[0] || !strcasecmp(par, botnetnick))
1120 botlink(dcc[idx].nick, idx, s);
1121 else {
1122 char x[40];
1123
1124 i = nextbot(s);
1125 if (i < 0) {
1126 dprintf(idx, "No such bot online.\n");
1127 return;
1128 }
1129 simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1130 botnet_send_link(i, x, s, par);
1131 }
1132 }
1133
1134 static void cmd_unlink(struct userrec *u, int idx, char *par)
1135 {
1136 int i;
1137 char *bot;
1138
1139 if (!par[0]) {
1140 dprintf(idx, "Usage: unlink <bot> [reason]\n");
1141 return;
1142 }
1143 putlog(LOG_CMDS, "*", "#%s# unlink %s", dcc[idx].nick, par);
1144 bot = newsplit(&par);
1145 i = nextbot(bot);
1146 if (i < 0) {
1147 botunlink(idx, bot, par);
1148 return;
1149 }
1150 /* if we're directly connected to that bot, just do it
1151 * (is nike gunna sue?) */
1152 if (!strcasecmp(dcc[i].nick, bot))
1153 botunlink(idx, bot, par);
1154 else {
1155 char x[40];
1156
1157 simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1158 botnet_send_unlink(i, x, lastbot(bot), bot, par);
1159 }
1160 }
1161
1162 static void cmd_relay(struct userrec *u, int idx, char *par)
1163 {
1164 if (!par[0]) {
1165 dprintf(idx, "Usage: relay <bot>\n");
1166 return;
1167 }
1168 putlog(LOG_CMDS, "*", "#%s# relay %s", dcc[idx].nick, par);
1169 tandem_relay(idx, par, 0);
1170 }
1171
1172 static void cmd_save(struct userrec *u, int idx, char *par)
1173 {
1174 putlog(LOG_CMDS, "*", "#%s# save", dcc[idx].nick);
1175 dprintf(idx, "Saving user file...\n");
1176 write_userfile(-1);
1177 }
1178
1179 static void cmd_backup(struct userrec *u, int idx, char *par)
1180 {
1181 putlog(LOG_CMDS, "*", "#%s# backup", dcc[idx].nick);
1182 dprintf(idx, "Backing up the user file...\n");
1183 backup_userfile();
1184 }
1185
1186 static void cmd_trace(struct userrec *u, int idx, char *par)
1187 {
1188 int i;
1189 char x[NOTENAMELEN + 11], y[11];
1190
1191 if (!par[0]) {
1192 dprintf(idx, "Usage: trace <botname>\n");
1193 return;
1194 }
1195 if (!strcasecmp(par, botnetnick)) {
1196 dprintf(idx, "That's me! Hiya! :)\n");
1197 return;
1198 }
1199 i = nextbot(par);
1200 if (i < 0) {
1201 dprintf(idx, "Unreachable bot.\n");
1202 return;
1203 }
1204 putlog(LOG_CMDS, "*", "#%s# trace %s", dcc[idx].nick, par);
1205 simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1206 simple_sprintf(y, ":%d", now);
1207 botnet_send_trace(i, x, par, y);
1208 }
1209
1210 static void cmd_binds(struct userrec *u, int idx, char *par)
1211 {
1212 putlog(LOG_CMDS, "*", "#%s# binds %s", dcc[idx].nick, par);
1213 tell_binds(idx, par);
1214 }
1215
1216 static void cmd_banner(struct userrec *u, int idx, char *par)
1217 {
1218 char s[1024];
1219 int i;
1220
1221 if (!par[0]) {
1222 dprintf(idx, "Usage: banner <message>\n");
1223 return;
1224 }
1225 simple_sprintf(s, "\007\007### Botwide:[%s] %s\n", dcc[idx].nick, par);
1226 for (i = 0; i < dcc_total; i++)
1227 if (dcc[i].type->flags & DCT_MASTER)
1228 dprintf(i, "%s", s);
1229 }
1230
1231 /* after messing with someone's user flags, make sure the dcc-chat flags
1232 * are set correctly */
1233 int check_dcc_attrs(struct userrec *u, int oatr)
1234 {
1235 int i, stat;
1236 char *p, *q, s[121];
1237
1238 /* if it matches someone in the owner list, make sure he/she has +n */
1239 if (!u)
1240 return 0;
1241 /* make sure default owners are +n */
1242 if (owner[0]) {
1243 q = owner;
1244 p = strchr(q, ',');
1245 while (p) {
1246 strncpy(s, q, p - q);
1247 s[p - q] = 0;
1248 rmspace(s);
1249 if (!strcasecmp(u->handle, s))
1250 u->flags = sanity_check(u->flags | USER_OWNER);
1251 q = p + 1;
1252 p = strchr(q, ',');
1253 }
1254 strcpy(s, q);
1255 rmspace(s);
1256 if (!strcasecmp(u->handle, s))
1257 u->flags = sanity_check(u->flags | USER_OWNER);
1258 }
1259 for (i = 0; i < dcc_total; i++) {
1260 if ((dcc[i].type->flags & DCT_MASTER) &&
1261 (!strcasecmp(u->handle, dcc[i].nick))) {
1262 stat = dcc[i].status;
1263 if ((dcc[i].type == &DCC_CHAT) &&
1264 ((u->flags & (USER_OP | USER_MASTER | USER_OWNER |
1265 USER_BOTMAST))
1266 != (oatr & (USER_OP | USER_MASTER | USER_OWNER |
1267 USER_BOTMAST)))) {
1268 botnet_send_join_idx(i, -1);
1269 }
1270 if ((oatr & USER_MASTER) && !(u->flags & USER_MASTER)) {
1271 struct flag_record fr =
1272 {FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
1273
1274 dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_RAW |
1275 LOG_FILES | LOG_LEV1 | LOG_LEV2 |
1276 LOG_LEV3 | LOG_LEV4 | LOG_LEV5 |
1277 LOG_LEV6 | LOG_LEV7 | LOG_LEV8 |
1278 LOG_WALL | LOG_DEBUG);
1279 get_user_flagrec(u, &fr, NULL);
1280 if (!chan_master(fr))
1281 dcc[i].u.chat->con_flags |= (LOG_MISC | LOG_CMDS);
1282 dprintf(i, "*** POOF! ***\n");
1283 dprintf(i, "You are no longer a master on this bot.\n");
1284 }
1285 if (!(oatr & USER_MASTER) && (u->flags & USER_MASTER)) {
1286 dcc[i].u.chat->con_flags |= conmask;
1287 dprintf(i, "*** POOF! ***\n");
1288 dprintf(i, "You are now a master on this bot.\n");
1289 }
1290 if (!(oatr & USER_BOTMAST) && (u->flags & USER_BOTMAST)) {
1291 dprintf(i, "### POOF! ###\n");
1292 dprintf(i, "You are now a botnet master on this bot.\n");
1293 }
1294 if ((oatr & USER_BOTMAST) && !(u->flags & USER_BOTMAST)) {
1295 dprintf(i, "### POOF! ###\n");
1296 dprintf(i, "You are no longer a botnet master on this bot.\n");
1297 }
1298 if (!(oatr & USER_OWNER) && (u->flags & USER_OWNER)) {
1299 dprintf(i, "@@@ POOF! @@@\n");
1300 dprintf(i, "You are now an OWNER of this bot.\n");
1301 }
1302 if ((oatr & USER_OWNER) && !(u->flags & USER_OWNER)) {
1303 dprintf(i, "@@@ POOF! @@@\n");
1304 dprintf(i, "You are no longer an owner of this bot.\n");
1305 }
1306 if ((stat & STAT_PARTY) && (u->flags & USER_OP))
1307 stat &= ~STAT_PARTY;
1308 if (!(stat & STAT_PARTY) && !(u->flags & USER_OP) &&
1309 !(u->flags & USER_MASTER))
1310 stat |= STAT_PARTY;
1311 if ((stat & STAT_CHAT) && !(u->flags & USER_PARTY) &&
1312 !(u->flags & USER_MASTER) &&
1313 (!(u->flags & USER_OP) || require_p))
1314 stat &= ~STAT_CHAT;
1315 if ((dcc[i].type->flags & DCT_FILES) && !(stat & STAT_CHAT) &&
1316 ((u->flags & USER_MASTER) || (u->flags & USER_PARTY) ||
1317 ((u->flags & USER_OP) && !require_p)))
1318 stat |= STAT_CHAT;
1319 dcc[i].status = stat;
1320 /* check if they no longer have access to wherever they are */
1321 /* DON'T kick someone off the party line just cuz they lost +p
1322 * (pinvite script removes +p after 5 mins automatically) */
1323 if ((dcc[i].type->flags & DCT_FILES) && !(u->flags & USER_XFER) &&
1324 !(u->flags & USER_MASTER)) {
1325 dprintf(i, "-+- POOF! -+-\n");
1326 dprintf(i, "You no longer have file area access.\n\n");
1327 putlog(LOG_MISC, "*", "DCC user [%s]%s removed from file system",
1328 dcc[i].nick, dcc[i].host);
1329 if (dcc[i].status & STAT_CHAT) {
1330 struct chat_info *ci;
1331
1332 ci = dcc[i].u.file->chat;
1333 nfree(dcc[i].u.file);
1334 dcc[i].u.chat = ci;
1335 dcc[i].status &= (~STAT_CHAT);
1336 dcc[i].type = &DCC_CHAT;
1337 if (dcc[i].u.chat->channel >= 0) {
1338 chanout_but(-1, dcc[i].u.chat->channel,
1339 "*** %s has returned.\n", dcc[i].nick);
1340 context;
1341 if (dcc[i].u.chat->channel < 100000)
1342 botnet_send_join_idx(i, -1);
1343 }
1344 } else {
1345 killsock(dcc[i].sock);
1346 dcc[i].sock = (long) dcc[i].type;
1347 dcc[i].type = &DCC_LOST;
1348 }
1349 }
1350 }
1351 if ((dcc[i].type == &DCC_BOT) && !strcasecmp(u->handle, dcc[i].nick)) {
1352 if ((dcc[i].status & STAT_LEAF) && !(u->flags & BOT_LEAF))
1353 dcc[i].status &= ~(STAT_LEAF | STAT_WARNED);
1354 if (!(dcc[i].status & STAT_LEAF) && (u->flags & BOT_LEAF))
1355 dcc[i].status |= STAT_LEAF;
1356 }
1357 }
1358 return u->flags;
1359 }
1360
1361 int check_dcc_chanattrs(struct userrec *u, char *chname, int chflags,
1362 int ochatr)
1363 {
1364 int i, found = 0, atr = u ? u->flags : 0;
1365 struct chanset_t *chan;
1366
1367 if (!u)
1368 return 0;
1369 chan = chanset;
1370 for (i = 0; i < dcc_total; i++) {
1371 if ((dcc[i].type->flags & DCT_MASTER) &&
1372 !strcasecmp(u->handle, dcc[i].nick)) {
1373 if ((dcc[i].type == &DCC_CHAT) &&
1374 ((chflags & (USER_OP | USER_MASTER | USER_OWNER))
1375 != (ochatr & (USER_OP | USER_MASTER | USER_OWNER))))
1376 botnet_send_join_idx(i, -1);
1377 if ((ochatr & USER_MASTER) && !(chflags & USER_MASTER)) {
1378 if (!(atr & USER_MASTER))
1379 dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS);
1380 dprintf(i, "*** POOF! ***\n");
1381 dprintf(i, "You are no longer a master on %s.\n", chname);
1382 }
1383 if (!(ochatr & USER_MASTER) && (chflags & USER_MASTER)) {
1384 dcc[i].u.chat->con_flags |= conmask;
1385 if (!(atr & USER_MASTER))
1386 dcc[i].u.chat->con_flags &=
1387 ~(LOG_LEV1 | LOG_LEV2 | LOG_LEV3 | LOG_LEV4 |
1388 LOG_LEV5 | LOG_LEV6 | LOG_LEV7 | LOG_LEV8 |
1389 LOG_RAW | LOG_DEBUG | LOG_WALL | LOG_FILES | LOG_SRVOUT);
1390 dprintf(i, "*** POOF! ***\n");
1391 dprintf(i, "You are now a master on %s.\n", chname);
1392 }
1393 if (!(ochatr & USER_OWNER) && (chflags & USER_OWNER)) {
1394 dprintf(i, "@@@ POOF! @@@\n");
1395 dprintf(i, "You are now an OWNER of %s.\n", chname);
1396 }
1397 if ((ochatr & USER_OWNER) && !(chflags & USER_OWNER)) {
1398 dprintf(i, "@@@ POOF! @@@\n");
1399 dprintf(i, "You are no longer an owner of %s.\n", chname);
1400 }
1401 if (((ochatr & (USER_OP | USER_MASTER | USER_OWNER)) &&
1402 (!(chflags & (USER_OP | USER_MASTER | USER_OWNER)))) ||
1403 ((chflags & (USER_OP | USER_MASTER | USER_OWNER)) &&
1404 (!(ochatr & (USER_OP | USER_MASTER | USER_OWNER))))) {
1405 struct flag_record fr =
1406 {FR_CHAN, 0, 0, 0, 0, 0};
1407
1408 while (chan && !found) {
1409 get_user_flagrec(u, &fr, chan->name);
1410 if (fr.chan & (USER_OP | USER_MASTER | USER_OWNER))
1411 found = 1;
1412 else
1413 chan = chan->next;
1414 }
1415 if (!chan)
1416 chan = chanset;
1417 if (chan)
1418 strcpy(dcc[i].u.chat->con_chan, chan->name);
1419 else
1420 strcpy(dcc[i].u.chat->con_chan, "*");
1421 }
1422 }
1423 }
1424 return chflags;
1425 }
1426
1427 static void cmd_chattr(struct userrec *u, int idx, char *par)
1428 {
1429 char *hand, *tmpchg = NULL, *chg = NULL, work[1024];
1430 struct chanset_t *chan = NULL;
1431 struct userrec *u2;
1432 struct flag_record pls =
1433 {0, 0, 0, 0, 0, 0}, mns =
1434 {0, 0, 0, 0, 0, 0}, user =
1435 {0, 0, 0, 0, 0, 0};
1436 module_entry *me;
1437 int fl = -1, of = 0, ocf = 0;
1438
1439 if (!par[0]) {
1440 dprintf(idx, "Usage: chattr <handle> [changes] [channel]\n");
1441 return;
1442 }
1443 hand = newsplit(&par);
1444 u2 = get_user_by_handle(userlist, hand);
1445 if ((hand[0] == '*') || !u2) {
1446 dprintf(idx, "No such user!\n");
1447 return;
1448 }
1449 if (par[0] && ((strchr(CHANMETA, par[0]) == NULL) || par[0]=='+')) {
1450 chg = newsplit(&par);
1451 if (!par[0] && strpbrk(chg, "&|"))
1452 par = dcc[idx].u.chat->con_chan;
1453 else if (par[0] && !strpbrk(chg, "&|")) {
1454 context;
1455 tmpchg = nmalloc(sizeof(chg)+1);
1456 sprintf(tmpchg,"|%s",chg);
1457 chg = nmalloc(sizeof(tmpchg));
1458 strcpy(chg,tmpchg);
1459 }
1460 }
1461 chan = findchan(par);
1462 if (!chan && par[0] && (par[0] != '*')) {
1463 dprintf(idx, "No channel record for %s.\n", par);
1464 if (tmpchg) {
1465 nfree(chg); nfree(tmpchg);
1466 }
1467 return;
1468 }
1469 user.match = FR_GLOBAL;
1470 if (chan)
1471 user.match |= FR_CHAN;
1472 get_user_flagrec(u, &user, chan ? chan->name : 0);
1473 if (!chan && !glob_botmast(user)) {
1474 dprintf(idx, "You do not have Bot Master privileges.\n");
1475 if (tmpchg) {
1476 nfree(chg); nfree(tmpchg);
1477 }
1478 return;
1479 }
1480 if (chan && !glob_master(user) && !chan_master(user)) {
1481 dprintf(idx, "You do not have channel master privileges for channel %s\n",
1482 par);
1483 if (tmpchg) {
1484 nfree(chg); nfree(tmpchg);
1485 }
1486 return;
1487 }
1488 user.match &= fl;
1489 if (chg) {
1490 pls.match = user.match;
1491 break_down_flags(chg, &pls, &mns);
1492 /* no-one can change these flags on-the-fly */
1493 pls.global &=~(USER_BOT);
1494 mns.global &=~(USER_BOT);
1495
1496 if (chan) {
1497 pls.chan &= ~(BOT_SHARE);
1498 mns.chan &= ~(BOT_SHARE);
1499 }
1500 if (!glob_owner(user)) {
1501 pls.global &=~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1502 mns.global &=~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1503
1504 if (chan) {
1505 pls.chan &= ~USER_OWNER;
1506 mns.chan &= ~USER_OWNER;
1507 }
1508 if (!glob_master(user)) {
1509 pls.global &=USER_PARTY | USER_XFER;
1510 mns.global &=USER_PARTY | USER_XFER;
1511
1512 if (!glob_botmast(user)) {
1513 pls.global = 0;
1514 mns.global = 0;
1515 }
1516 }
1517 }
1518 if (chan && !chan_owner(user) && !glob_owner(user)) {
1519 pls.chan &= ~USER_MASTER;
1520 mns.chan &= ~USER_MASTER;
1521 if (!chan_master(user) && !glob_master(user)) {
1522 pls.chan = 0;
1523 mns.chan = 0;
1524 }
1525 }
1526 get_user_flagrec(u2, &user, par);
1527 if (user.match & FR_GLOBAL) {
1528 of = user.global;
1529 user.global = sanity_check((user.global |pls.global) &~mns.global);
1530
1531 user.udef_global = (user.udef_global | pls.udef_global)
1532 & ~mns.udef_global;
1533 }
1534 if (chan) {
1535 ocf = user.chan;
1536 user.chan = chan_sanity_check((user.chan | pls.chan) & ~mns.chan,
1537 user.global);
1538
1539 user.udef_chan = (user.udef_chan | pls.udef_chan) & ~mns.udef_chan;
1540 }
1541 set_user_flagrec(u2, &user, par);
1542 }
1543 if (chan)
1544 putlog(LOG_CMDS, "*", "#%s# (%s) chattr %s %s",
1545 dcc[idx].nick, chan ? chan->name : "*", hand, chg ? chg : "");
1546 else
1547 putlog(LOG_CMDS, "*", "#%s# chattr %s %s", dcc[idx].nick, hand,
1548 chg ? chg : "");
1549 /* get current flags and display them */
1550 if (user.match & FR_GLOBAL) {
1551 user.match = FR_GLOBAL;
1552 if (chg)
1553 check_dcc_attrs(u2, of);
1554 get_user_flagrec(u2, &user, NULL);
1555 build_flags(work, &user, NULL);
1556 if (work[0] != '-')
1557 dprintf(idx, "Global flags for %s are now +%s\n", hand, work);
1558 else
1559 dprintf(idx, "No global flags for %s.\n", hand);
1560 }
1561 if (chan) {
1562 user.match = FR_CHAN;
1563 get_user_flagrec(u2, &user, par);
1564 user.chan &= ~BOT_SHARE;
1565 if (chg)
1566 check_dcc_chanattrs(u2, chan->name, user.chan, ocf);
1567 build_flags(work, &user, NULL);
1568 if (work[0] != '-')
1569 dprintf(idx, "Channel flags for %s on %s are now +%s\n", hand,
1570 chan->name, work);
1571 else
1572 dprintf(idx, "No flags for %s on %s.\n", hand, chan->name);
1573 if ((me = module_find("irc", 0, 0))) {
1574 Function *func = me->funcs;
1575
1576 if (chan)
1577 (func[15]) (chan, 0);
1578 }
1579 }
1580 if (tmpchg) {
1581 nfree(chg); nfree(tmpchg);
1582 }
1583 }
1584
1585 static void cmd_botattr(struct userrec *u, int idx, char *par)
1586 {
1587 char *hand, *chg = NULL, work[1024];
1588 struct chanset_t *chan = NULL;
1589 struct userrec *u2;
1590 struct flag_record pls =
1591 {0, 0, 0, 0, 0, 0}, mns =
1592 {0, 0, 0, 0, 0, 0}, user =
1593 {0, 0, 0, 0, 0, 0};
1594 int idx2;
1595
1596 if (!par[0]) {
1597 dprintf(idx, "Usage: botattr <handle> [changes] [channel]\n");
1598 return;
1599 }
1600 hand = newsplit(&par);
1601 u2 = get_user_by_handle(userlist, hand);
1602 if ((hand[0] == '*') || !u2 || !(u2->flags & USER_BOT)) {
1603 dprintf(idx, "No such bot!\n");
1604 return;
1605 }
1606 for (idx2 = 0; idx2 < dcc_total; idx2++)
1607 if (!strcasecmp(dcc[idx2].nick, hand))
1608 break;
1609 if (idx2 != dcc_total) {
1610 dprintf(idx, "You may not change the attributes of a linked bot.\n");
1611 return;
1612 }
1613 if (par[0] && ((strchr(CHANMETA, par[0]) == NULL) || par[0]=='+')) {
1614 chg = newsplit(&par);
1615 if (!par[0] && strpbrk(chg, "|&"))
1616 par = dcc[idx].u.chat->con_chan;
1617 }
1618 if (!(chan = findchan(par)) && par[0]) {
1619 dprintf(idx, "No channel record for %s.\n", par);
1620 return;
1621 }
1622 user.match = FR_GLOBAL;
1623 get_user_flagrec(u, &user, chan ? chan->name : 0);
1624 if (!glob_botmast(user)) {
1625 dprintf(idx, "You do not have Bot Master privileges.\n");
1626 return;
1627 }
1628 if (chg) {
1629 user.match = FR_BOT | (chan ? FR_CHAN : 0);
1630 pls.match = user.match;
1631 break_down_flags(chg, &pls, &mns);
1632 /* no-one can change these flags on-the-fly */
1633 pls.global &=~BOT_BOT;
1634 mns.global &=~BOT_BOT;
1635
1636 if (chan && glob_owner(user)) {
1637 pls.chan &= BOT_SHARE;
1638 mns.chan &= BOT_SHARE;
1639 } else {
1640 pls.chan = 0;
1641 mns.chan = 0;
1642 }
1643 if (!glob_owner(user)) {
1644 pls.bot &= ~(BOT_SHARE | BOT_GLOBAL);
1645 mns.bot &= ~(BOT_SHARE | BOT_GLOBAL);
1646 }
1647 user.match = FR_BOT | (chan ? FR_CHAN : 0);
1648 get_user_flagrec(u2, &user, par);
1649 user.bot = (user.bot | pls.bot) & ~mns.bot;
1650 if ((user.bot & BOT_SHARE) == BOT_SHARE)
1651 user.bot &= ~BOT_SHARE;
1652 if (chan)
1653 user.chan = (user.chan | pls.chan) & ~mns.chan;
1654 set_user_flagrec(u2, &user, par);
1655 }
1656 if (chan)
1657 putlog(LOG_CMDS, "*", "#%s# (%s) botattr %s %s",
1658 dcc[idx].nick, chan->name, hand, chg ? chg : "");
1659 else
1660 putlog(LOG_CMDS, "*", "#%s# botattr %s %s", dcc[idx].nick, hand,
1661 chg ? chg : "");
1662 /* get current flags and display them */
1663 if (!chan || pls.bot || mns.bot) {
1664 user.match = FR_BOT;
1665 get_user_flagrec(u2, &user, NULL);
1666 build_flags(work, &user, NULL);
1667 if (work[0] != '-')
1668 dprintf(idx, "Bot flags for %s are now +%s\n", hand, work);
1669 else
1670 dprintf(idx, "No bot flags for %s.\n", hand);
1671 }
1672 if (chan) {
1673 user.match = FR_CHAN;
1674 get_user_flagrec(u2, &user, par);
1675 user.chan &= BOT_SHARE;
1676 build_flags(work, &user, NULL);
1677 if (work[0] != '-')
1678 dprintf(idx, "Bot flags for %s on %s are now +%s\n", hand,
1679 chan->name, work);
1680 else
1681 dprintf(idx, "No bot flags for %s on %s.\n", hand, chan->name);
1682 }
1683 }
1684
1685 static void cmd_chat(struct userrec *u, int idx, char *par)
1686 {
1687 int newchan, oldchan;
1688
1689 if (!strcasecmp(par, "off")) {
1690 /* turn chat off */
1691 if (dcc[idx].u.chat->channel < 0)
1692 dprintf(idx, "You weren't in chat anyway!\n");
1693 else {
1694 dprintf(idx, "Leaving chat mode...\n");
1695 check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
1696 dcc[idx].u.chat->channel);
1697 chanout_but(-1, dcc[idx].u.chat->channel,
1698 "*** %s left the party line.\n",
1699 dcc[idx].nick);
1700 context;
1701 if (dcc[idx].u.chat->channel < 100000)
1702 botnet_send_part_idx(idx, "");
1703 }
1704 dcc[idx].u.chat->channel = (-1);
1705 } else {
1706 if (par[0] == '*') {
1707 if (((par[1] < '0') || (par[1] > '9'))) {
1708 if (par[1] == 0)
1709 newchan = 0;
1710 else {
1711 Tcl_SetVar(interp, "chan", par, 0);
1712 if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
1713 interp->result[0])
1714 newchan = atoi(interp->result);
1715 else
1716 newchan = -1;
1717 }
1718 if (newchan < 0) {
1719 dprintf(idx, "No channel by that name.\n");
1720 return;
1721 }
1722 } else
1723 newchan = 100000 + atoi(par + 1);
1724 if (newchan < 100000 || newchan > 199999) {
1725 dprintf(idx, "Channel # out of range: local channels must be *0-*99999\n");
1726 return;
1727 }
1728 } else {
1729 if (((par[0] < '0') || (par[0] > '9')) && (par[0])) {
1730 if (!strcasecmp(par, "on"))
1731 newchan = 0;
1732 else {
1733 Tcl_SetVar(interp, "chan", par, 0);
1734 if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
1735 interp->result[0])
1736 newchan = atoi(interp->result);
1737 else
1738 newchan = -1;
1739 }
1740 if (newchan < 0) {
1741 dprintf(idx, "No channel by that name.\n");
1742 return;
1743 }
1744 } else
1745 newchan = atoi(par);
1746 if ((newchan < 0) || (newchan > 199999)) {
1747 dprintf(idx, "Channel # out of range: must be between 0 and 99999.\n");
1748 return;
1749 }
1750 }
1751 /* if coming back from being off the party line, make sure they're
1752 * not away */
1753 if ((dcc[idx].u.chat->channel < 0) && (dcc[idx].u.chat->away != NULL))
1754 not_away(idx);
1755 if (dcc[idx].u.chat->channel == newchan) {
1756 if (newchan == 0)
1757 dprintf(idx, "You're already on the party line!\n");
1758 else
1759 dprintf(idx, "You're already on channel %s%d!\n",
1760 (newchan < 100000) ? "" : "*", newchan % 100000);
1761 } else {
1762 oldchan = dcc[idx].u.chat->channel;
1763 if (oldchan >= 0)
1764 check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock, oldchan);
1765 if (oldchan == 0) {
1766 chanout_but(-1, 0, "*** %s left the party line.\n", dcc[idx].nick);
1767 context;
1768 } else if (oldchan > 0) {
1769 chanout_but(-1, oldchan, "*** %s left the channel.\n", dcc[idx].nick);
1770 context;
1771 }
1772 dcc[idx].u.chat->channel = newchan;
1773 if (newchan == 0) {
1774 dprintf(idx, "Entering the party line...\n");
1775 chanout_but(-1, 0, "*** %s joined the party line.\n", dcc[idx].nick);
1776 context;
1777 } else {
1778 dprintf(idx, "Joining channel '%s'...\n", par);
1779 chanout_but(-1, newchan, "*** %s joined the channel.\n", dcc[idx].nick);
1780 context;
1781 }
1782 check_tcl_chjn(botnetnick, dcc[idx].nick, newchan, geticon(idx),
1783 dcc[idx].sock, dcc[idx].host);
1784 if (newchan < 100000)
1785 botnet_send_join_idx(idx, oldchan);
1786 else if (oldchan < 100000)
1787 botnet_send_part_idx(idx, "");
1788 }
1789 }
1790 }
1791
1792 static void cmd_echo(struct userrec *u, int idx, char *par)
1793 {
1794 if (!par[0]) {
1795 dprintf(idx, "Echo is currently %s.\n", dcc[idx].status & STAT_ECHO ?
1796 "on" : "off");
1797 return;
1798 }
1799 if (!strcasecmp(par, "on")) {
1800 dprintf(idx, "Echo turned on.\n");
1801 dcc[idx].status |= STAT_ECHO;
1802 return;
1803 }
1804 if (!strcasecmp(par, "off")) {
1805 dprintf(idx, "Echo turned off.\n");
1806 dcc[idx].status &= ~STAT_ECHO;
1807 return;
1808 }
1809 dprintf(idx, "Usage: echo <on/off>\n");
1810 }
1811
1812 int stripmodes(char *s)
1813 {
1814 int res = 0;
1815
1816 for (; *s; s++)
1817 switch (tolower(*s)) {
1818 case 'b':
1819 res |= STRIP_BOLD;
1820 break;
1821 case 'c':
1822 res |= STRIP_COLOR;
1823 break;
1824 case 'r':
1825 res |= STRIP_REV;
1826 break;
1827 case 'u':
1828 res |= STRIP_UNDER;
1829 break;
1830 case 'a':
1831 res |= STRIP_ANSI;
1832 break;
1833 case 'g':
1834 res |= STRIP_BELLS;
1835 break;
1836 case '*':
1837 res |= STRIP_ALL;
1838 break;
1839 }
1840 return res;
1841 }
1842
1843 char *stripmasktype(int x)
1844 {
1845 static char s[20];
1846 char *p = s;
1847
1848 if (x & STRIP_BOLD)
1849 *p++ = 'b';
1850 if (x & STRIP_COLOR)
1851 *p++ = 'c';
1852 if (x & STRIP_REV)
1853 *p++ = 'r';
1854 if (x & STRIP_UNDER)
1855 *p++ = 'u';
1856 if (x & STRIP_ANSI)
1857 *p++ = 'a';
1858 if (x & STRIP_BELLS)
1859 *p++ = 'g';
1860 if (p == s)
1861 *p++ = '-';
1862 *p = 0;
1863 return s;
1864 }
1865
1866 static char *stripmaskname(int x)
1867 {
1868 static char s[161];
1869 int i = 0;
1870
1871 s[i] = 0;
1872 if (x & STRIP_BOLD)
1873 i += my_strcpy(s + i, "bold, ");
1874 if (x & STRIP_COLOR)
1875 i += my_strcpy(s + i, "color, ");
1876 if (x & STRIP_REV)
1877 i += my_strcpy(s + i, "reverse, ");
1878 if (x & STRIP_UNDER)
1879 i += my_strcpy(s + i, "underline, ");
1880 if (x & STRIP_ANSI)
1881 i += my_strcpy(s + i, "ansi, ");
1882 if (x & STRIP_BELLS)
1883 i += my_strcpy(s + i, "bells, ");
1884 if (!i)
1885 strcpy(s, "none");
1886 else
1887 s[i - 2] = 0;
1888 return s;
1889 }
1890
1891 static void cmd_strip(struct userrec *u, int idx, char *par)
1892 {
1893 char *nick, *changes, s[2];
1894 int dest = 0, i, pls, md, ok = 0;
1895
1896 if (!par[0]) {
1897 dprintf(idx, "Your current strip settings are: %s (%s)\n",
1898 stripmasktype(dcc[idx].u.chat->strip_flags),
1899 stripmaskname(dcc[idx].u.chat->strip_flags));
1900 return;
1901 }
1902 nick = newsplit(&par);
1903 if ((nick[0] != '+') && (nick[0] != '-') && u &&
1904 (u->flags & USER_MASTER)) {
1905 for (i = 0; i < dcc_total; i++)
1906 if (!strcasecmp(nick, dcc[i].nick) && (dcc[i].type == &DCC_CHAT) &&
1907 !ok) {
1908 ok = 1;
1909 dest = i;
1910 }
1911 if (!ok) {
1912 dprintf(idx, "No such user on the party line!\n");
1913 return;
1914 }
1915 changes = par;
1916 } else {
1917 changes = nick;
1918 nick = "";
1919 dest = idx;
1920 }
1921 if ((changes[0] != '+') && (changes[0] != '-'))
1922 dcc[dest].u.chat->strip_flags = 0;
1923 s[1] = 0;
1924 for (pls = 1; *changes; changes++) {
1925 switch (*changes) {
1926 case '+':
1927 pls = 1;
1928 break;
1929 case '-':
1930 pls = 0;
1931 break;
1932 default:
1933 s[0] = *changes;
1934 md = stripmodes(s);
1935 if (pls == 1)
1936 dcc[dest].u.chat->strip_flags |= md;
1937 else
1938 dcc[dest].u.chat->strip_flags &= ~md;
1939 }
1940 }
1941 putlog(LOG_CMDS, "*", "#%s# strip %s %s", dcc[idx].nick, nick, changes);
1942 if (dest == idx) {
1943 dprintf(idx, "Your strip settings are: %s (%s)\n",
1944 stripmasktype(dcc[idx].u.chat->strip_flags),
1945 stripmaskname(dcc[idx].u.chat->strip_flags));
1946 } else {
1947 dprintf(idx, "Strip setting for %s: %s (%s)\n", dcc[dest].nick,
1948 stripmasktype(dcc[dest].u.chat->strip_flags),
1949 stripmaskname(dcc[dest].u.chat->strip_flags));
1950 dprintf(dest, "%s set your strip settings to: %s (%s)\n", dcc[idx].nick,
1951 stripmasktype(dcc[dest].u.chat->strip_flags),
1952 stripmaskname(dcc[dest].u.chat->strip_flags));
1953 }
1954 }
1955
1956 static void cmd_su(struct userrec *u, int idx, char *par)
1957 {
1958 int atr = u ? u->flags : 0;
1959 struct flag_record fr =
1960 {FR_ANYWH | FR_CHAN | FR_GLOBAL, 0, 0, 0, 0, 0};
1961
1962 context;
1963 u = get_user_by_handle(userlist, par);
1964
1965 if (!par[0])
1966 dprintf(idx, "Usage: su <user>\n");
1967 else if (!u)
1968 dprintf(idx, "No such user.\n");
1969 else if (u->flags & USER_BOT)
1970 dprintf(idx, "Can't su to a bot... then again, why would you wanna?\n");
1971 else if (u_pass_match(u, "-"))
1972 dprintf(idx, "No password set for user. You may not .su to them\n");
1973 else if (dcc[idx].u.chat->su_nick)
1974 dprintf(idx, "You cannot currently double .su, try .su'ing directly\n");
1975 else {
1976 get_user_flagrec(u, &fr, NULL);
1977 if ((!glob_party(fr) && (require_p || !(glob_op(fr) || chan_op(fr)))) &&
1978 !(atr & USER_BOTMAST))
1979 dprintf(idx, "No party line access permitted for %s.\n", par);
1980 else {
1981 correct_handle(par);
1982 putlog(LOG_CMDS, "*", "#%s# su %s", dcc[idx].nick, par);
1983 if (!(atr & USER_OWNER) ||
1984 ((atr & USER_OWNER) && !(isowner(dcc[idx].nick))) ||
1985 ((u->flags & USER_OWNER) && (isowner(par)))) {
1986 if (dcc[idx].u.chat->channel < 100000)
1987 botnet_send_part_idx(idx, "");
1988 chanout_but(-1, dcc[idx].u.chat->channel,
1989 "*** %s left the party line.\n", dcc[idx].nick);
1990 context;
1991 /* store the old nick in the away section, for weenies who can't get
1992 * their password right ;) */
1993 if (dcc[idx].u.chat->away != NULL)
1994 nfree(dcc[idx].u.chat->away);
1995 dcc[idx].u.chat->away = n_malloc(strlen(dcc[idx].nick) + 1,
1996 "dccutil.c", 9999); /* evil hack :) */
1997 strcpy(dcc[idx].u.chat->away, dcc[idx].nick);
1998 dcc[idx].u.chat->su_nick = n_malloc(strlen(dcc[idx].nick) + 1,
1999 "dccutil.c", 9999);
2000 strcpy(dcc[idx].u.chat->su_nick, dcc[idx].nick);
2001 dcc[idx].user = u;
2002 strcpy(dcc[idx].nick, par);
2003 dprintf(idx, "Enter password for %s%s\n", par,
2004 (dcc[idx].status & STAT_TELNET) ? "\377\373\001" : "");
2005 dcc[idx].type = &DCC_CHAT_PASS;