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

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

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


Revision 1.78 - (hide annotations) (download) (as text)
Sat Dec 8 15:59:26 2001 UTC (18 years ago) by ite
Branch: MAIN
Changes since 1.77: +5 -5 lines
File MIME type: text/x-chdr
Rebound some commands to less restrictive bindings (relay, botinfo, bottree, vbottree). Patch by Matthew Hallacy <poptix@techmonkeys.org>

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