/[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.74 - (hide annotations) (download) (as text)
Fri Oct 19 01:55:04 2001 UTC (18 years, 2 months ago) by tothwolf
Branch: MAIN
Changes since 1.73: +47 -47 lines
File MIME type: text/x-chdr
* removed obsolete EGG_CHECK_FUNC_VSPRINTF autoconf macro
* removed obsolete EGG_HEADER_STDC autoconf macro
* added EGG_C_LONG_LONG autoconf macro
* added EGG_FUNC_C99_VSNPRINTF autoconf macro
* added EGG_REPLACE_SNPRINTF autoconf macro
* added EGG_TYPE_32BIT autoconf macro

* removed unused dlfcn.h header check from configure.ac
* removed AC_CHECK_SIZEOF long and int from configure.ac
* added many required autoconf macros to configure.ac
* added AC_REPLACE_FUNCS to configure.ac for compat functions
* many configure.ac cleanups

* updated compat/snprintf.c with latest version from Samba
* added code to link libm with compat library for snprintf.c
* added support for LIBOBJS to compat/Makefile.am
* added memset back to compat
* added memcpy back to compat
* many compat cleanups

* renamed egg_strcasecmp() to strcasecmp()
* renamed egg_strncasecmp() to strncasecmp()
* renamed egg_snprintf() to snprintf()
* renamed egg_vsnprintf() to vsnprintf()
* renamed egg_strftime() to strftime()
* renamed egg_inet_aton() to inet_aton()
* renamed egg_inet_ntop() to inet_ntop()
* renamed egg_inet_pton() to inet_pton()

* exported strftime() for modules
* exported inet_ntop() for modules
* exported inet_pton() for modules
* exported vasprintf() for modules
* exported asprintf() for modules

* renamed u_32bit_t typedef to u_32int_t
* extended stat.h to support standard bits and checks

* major function changes:
  + egg_strcasecmp -> strcasecmp
  + egg_strncasecmp -> strncasecmp
  + egg_snprintf -> snprintf
  + egg_vsnprintf -> vsnprintf
  + egg_strftime -> strftime
  + egg_inet_aton -> inet_aton
  + egg_inet_ntop -> inet_ntop
  + egg_inet_pton -> inet_pton

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