/[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.90 - (hide annotations) (download) (as text)
Thu Feb 7 22:19:04 2002 UTC (17 years, 10 months ago) by wcc
Branch: MAIN
Changes since 1.89: +2 -2 lines
File MIME type: text/x-chdr
Updated copyright info for 2002

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