/[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.106 - (hide annotations) (download) (as text)
Tue Jun 18 06:12:32 2002 UTC (17 years, 6 months ago) by guppy
Branch: MAIN
Changes since 1.105: +4 -167 lines
File MIME type: text/x-chdr

- removed userflag +k
- removed userflag +h
- removed all the code related to .strip since stdarg is going to redo it in a
better fashion using network filters.
- removed woobie since woobie is useless and we would be much better suited with
a "sample" module that actually does something useful

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