/[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.94 - (hide annotations) (download) (as text)
Sun Mar 3 20:17:54 2002 UTC (17 years, 9 months ago) by stdarg
Branch: MAIN
Changes since 1.93: +1 -20 lines
File MIME type: text/x-chdr
* Moved .tcl command to the tcl module

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