/[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.97 - (show annotations) (download) (as text)
Mon Apr 1 13:33:33 2002 UTC (17 years, 8 months ago) by ite
Branch: MAIN
Changes since 1.96: +11 -11 lines
File MIME type: text/x-chdr
* Got rid of strncpyz() in favour of BSD's strlcpy(). Fallback function provided.
* BSD's strlcat() provided as fallback function.
* Fallback functions weren't linked as expected when needed.

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