/[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.103 - (hide annotations) (download) (as text)
Sat May 11 01:08:43 2002 UTC (17 years, 7 months ago) by stdarg
Branch: MAIN
Changes since 1.102: +226 -243 lines
File MIME type: text/x-chdr
* Fixed a lot of duplicate log messages from dcc commands.

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