/[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.6 - (show annotations) (download) (as text)
Sat Jul 24 02:18:25 1999 UTC (20 years, 3 months ago) by poptix
Branch: MAIN
Changes since 1.5: +12 -1 lines
File MIME type: text/x-chdr
: Modified Files:

  dw's patch, try # 3, heh..

: 	Makefile TODO doc/UPDATES1.3 doc/tcl-commands.doc src/cmds.c
: 	src/patch.h src/mod/channels.mod/userchan.c
: 	src/mod/filesys.mod/filesys.h src/mod/irc.mod/chan.c
: 	src/mod/irc.mod/irc.c src/mod/irc.mod/mode.c

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