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