/[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.38 - (show annotations) (download) (as text)
Fri Aug 18 16:45:51 2000 UTC (19 years, 3 months ago) by fabian
Branch: MAIN
CVS Tags: eggdrop105040
Changes since 1.37: +49 -10 lines
File MIME type: text/x-chdr
guppy's ign-lifetime patch

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