/[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.76 - (hide annotations) (download) (as text)
Tue Oct 23 08:47:51 2001 UTC (18 years, 1 month ago) by stdarg
Branch: MAIN
Changes since 1.75: +2 -2 lines
File MIME type: text/x-chdr
* Added a "loadscript" script command.
* Fixed up perlscript.mod a little bit, so that it can do stuff.
* Wrote a test script in perl that uses timers, binds, and putlog successfully.

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