/[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.39 - (show annotations) (download) (as text)
Fri Aug 25 13:14:27 2000 UTC (19 years, 3 months ago) by fabian
Branch: MAIN
Changes since 1.38: +17 -19 lines
File MIME type: text/x-chdr
<Fabian> Cybah's splitcn patch. Small style corrections (added newline after var def).

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