/[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.95 - (show annotations) (download) (as text)
Mon Mar 4 03:55:28 2002 UTC (17 years, 9 months ago) by stdarg
Branch: MAIN
Changes since 1.94: +1 -32 lines
File MIME type: text/x-chdr
* Got rid of .set command
* Moved Tcl info from chanprog.c to tcl module

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