/[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.12 - (show annotations) (download) (as text)
Wed Sep 8 19:35:47 1999 UTC (19 years, 11 months ago) by poptix
Branch: MAIN
Changes since 1.11: +0 -1 lines
File MIME type: text/x-chdr
 lame FIXME's abound.

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