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

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

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


Revision 1.20 - (show annotations) (download) (as text)
Mon Jan 17 21:59:10 2000 UTC (19 years, 10 months ago) by fabian
Branch: MAIN
Changes since 1.19: +3 -4 lines
File MIME type: text/x-chdr
resync with 1.4, 17Jan2000

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