/[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.46 - (hide annotations) (download) (as text)
Sat Dec 23 06:11:34 2000 UTC (18 years, 11 months ago) by guppy
Branch: MAIN
Changes since 1.45: +5 -5 lines
File MIME type: text/x-chdr
ITE's trafficfix patch (slightly modified to fix a compiler warning and a problem in net.c dealing with extern)

1 segfault 1.1 /*
2     * cmds.c -- handles:
3 fabian 1.15 * commands from a user via dcc
4     * (split in 2, this portion contains no-irc commands)
5     *
6 guppy 1.46 * $Id: cmds.c,v 1.45 2000/12/10 15:10:26 guppy Exp $
7 segfault 1.1 */
8 fabian 1.15 /*
9     * Copyright (C) 1997 Robey Pointer
10 fabian 1.21 * Copyright (C) 1999, 2000 Eggheads
11 fabian 1.15 *
12     * 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     *
17     * 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     *
22     * 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     strict_host;
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     owner[], spaces[];
52     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 fabian 1.36 egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
73 segfault 1.1 u = get_user_by_host(s);
74     if (u) {
75 fabian 1.40 dprintf(idx, "(Can't add hostmask for %s because it matches %s)\n",
76 segfault 1.1 nick, u->handle);
77     return 0;
78     }
79 fabian 1.40 if (strchr("~^+=-", m->userhost[0]))
80     egg_snprintf(s, sizeof s, "*!%s%s", strict_host ? "?" : "", m->userhost+1);
81     else
82     egg_snprintf(s, sizeof s, "*!%s", m->userhost);
83 fabian 1.8 dprintf(idx, "(Added hostmask for %s from %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 fabian 1.41 egg_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     time_t now2;
237     int hr, min;
238    
239     chan = chanset;
240     now2 = now - online_since;
241     s2[0] = 0;
242     if (now2 > 86400) {
243     int days = now2 / 86400;
244    
245 fabian 1.22 /* Days */
246 segfault 1.1 sprintf(s2, "%d day", days);
247     if (days >= 2)
248     strcat(s2, "s");
249     strcat(s2, ", ");
250     now2 -= days * 86400;
251     }
252     hr = (time_t) ((int) now2 / 3600);
253     now2 -= (hr * 3600);
254     min = (time_t) ((int) now2 / 60);
255     sprintf(&s2[strlen(s2)], "%02d:%02d", (int) hr, (int) min);
256     putlog(LOG_CMDS, "*", "#%s# botinfo", dcc[idx].nick);
257     simple_sprintf(s, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
258     botnet_send_infoq(-1, s);
259     s[0] = 0;
260     if (module_find("server", 0, 0)) {
261     while (chan != NULL) {
262     if (!channel_secret(chan)) {
263 fabian 1.8 if ((strlen(s) + strlen(chan->dname) + strlen(network)
264 segfault 1.1 + strlen(botnetnick) + strlen(ver) + 1) >= 490) {
265     strcat(s,"++ ");
266     break; /* yeesh! */
267     }
268 fabian 1.8 strcat(s, chan->dname);
269 segfault 1.1 strcat(s, ", ");
270     }
271     chan = chan->next;
272     }
273    
274     if (s[0]) {
275     s[strlen(s) - 2] = 0;
276     dprintf(idx, "*** [%s] %s <%s> (%s) [UP %s]\n", botnetnick,
277     ver, network, s, s2);
278     } else
279     dprintf(idx, "*** [%s] %s <%s> (%s) [UP %s]\n", botnetnick,
280     ver, network, BOT_NOCHANNELS, s2);
281     } else
282     dprintf(idx, "*** [%s] %s <NO_IRC> [UP %s]\n", botnetnick, ver, s2);
283     }
284    
285     static void cmd_whom(struct userrec *u, int idx, char *par)
286     {
287     if (par[0] == '*') {
288     putlog(LOG_CMDS, "*", "#%s# whom %s", dcc[idx].nick, par);
289     answer_local_whom(idx, -1);
290     return;
291     } else if (dcc[idx].u.chat->channel < 0) {
292     dprintf(idx, "You have chat turned off.\n");
293     return;
294     }
295     putlog(LOG_CMDS, "*", "#%s# whom %s", dcc[idx].nick, par);
296     if (!par[0]) {
297     answer_local_whom(idx, dcc[idx].u.chat->channel);
298     } else {
299     int chan = -1;
300    
301     if ((par[0] < '0') || (par[0] > '9')) {
302     Tcl_SetVar(interp, "chan", par, 0);
303     if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
304     interp->result[0]) {
305     chan = atoi(interp->result);
306     }
307     if (chan <= 0) {
308     dprintf(idx, "No such channel.\n");
309     return;
310     }
311     } else
312     chan = atoi(par);
313     if ((chan < 0) || (chan > 99999)) {
314     dprintf(idx, "Channel # out of range: must be 0-99999\n");
315     return;
316     }
317     answer_local_whom(idx, chan);
318     }
319     }
320    
321     static void cmd_me(struct userrec *u, int idx, char *par)
322     {
323     int i;
324    
325     if (dcc[idx].u.chat->channel < 0) {
326     dprintf(idx, "You have chat turned off.\n");
327     return;
328     }
329     if (!par[0]) {
330     dprintf(idx, "Usage: me <action>\n");
331     return;
332     }
333     if (dcc[idx].u.chat->away != NULL)
334     not_away(idx);
335     for (i = 0; i < dcc_total; i++)
336     if ((dcc[i].type->flags & DCT_CHAT) &&
337     (dcc[i].u.chat->channel == dcc[idx].u.chat->channel) &&
338     ((i != idx) || (dcc[i].status & STAT_ECHO)))
339     dprintf(i, "* %s %s\n", dcc[idx].nick, par);
340     botnet_send_act(idx, botnetnick, dcc[idx].nick,
341     dcc[idx].u.chat->channel, par);
342     check_tcl_act(dcc[idx].nick, dcc[idx].u.chat->channel, par);
343     }
344    
345     static void cmd_motd(struct userrec *u, int idx, char *par)
346     {
347     int i;
348    
349     if (par[0]) {
350     putlog(LOG_CMDS, "*", "#%s# motd %s", dcc[idx].nick, par);
351 fabian 1.26 if (!egg_strcasecmp(par, botnetnick))
352 segfault 1.1 show_motd(idx);
353     else {
354     i = nextbot(par);
355     if (i < 0)
356     dprintf(idx, "That bot isn't connected.\n");
357     else {
358     char x[40];
359    
360     simple_sprintf(x, "%s%d:%s@%s",
361     (u->flags & USER_HIGHLITE) ?
362     ((dcc[idx].status & STAT_TELNET) ? "#" : "!") : "",
363     dcc[idx].sock, dcc[idx].nick, botnetnick);
364     botnet_send_motd(i, x, par);
365     }
366     }
367     } else {
368     putlog(LOG_CMDS, "*", "#%s# motd", dcc[idx].nick);
369     show_motd(idx);
370     }
371     }
372    
373     static void cmd_away(struct userrec *u, int idx, char *par)
374     {
375     if (strlen(par) > 60)
376     par[60] = 0;
377     set_away(idx, par);
378     }
379    
380     static void cmd_back(struct userrec *u, int idx, char *par)
381     {
382     not_away(idx);
383     }
384    
385     static void cmd_newpass(struct userrec *u, int idx, char *par)
386     {
387     char *new;
388    
389     if (!par[0]) {
390     dprintf(idx, "Usage: newpass <newpassword>\n");
391     return;
392     }
393     new = newsplit(&par);
394     if (strlen(new) > 16)
395     new[16] = 0;
396     if (strlen(new) < 6) {
397     dprintf(idx, "Please use at least 6 characters.\n");
398     return;
399     }
400     set_user(&USERENTRY_PASS, u, new);
401     putlog(LOG_CMDS, "*", "#%s# newpass...", dcc[idx].nick);
402     dprintf(idx, "Changed password to '%s'\n", new);
403     }
404    
405     static void cmd_bots(struct userrec *u, int idx, char *par)
406     {
407     putlog(LOG_CMDS, "*", "#%s# bots", dcc[idx].nick);
408     tell_bots(idx);
409     }
410    
411     static void cmd_bottree(struct userrec *u, int idx, char *par)
412     {
413     putlog(LOG_CMDS, "*", "#%s# bottree", dcc[idx].nick);
414     tell_bottree(idx, 0);
415     }
416    
417     static void cmd_vbottree(struct userrec *u, int idx, char *par)
418     {
419     putlog(LOG_CMDS, "*", "#%s# vbottree", dcc[idx].nick);
420     tell_bottree(idx, 1);
421     }
422    
423     static void cmd_rehelp(struct userrec *u, int idx, char *par)
424     {
425     putlog(LOG_CMDS, "*", "#%s# rehelp", dcc[idx].nick);
426     dprintf(idx, "Reload help cache...\n");
427     reload_help_data();
428     }
429    
430     static void cmd_help(struct userrec *u, int idx, char *par)
431     {
432 fabian 1.4 struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
433 segfault 1.1
434     get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
435     if (par[0]) {
436     putlog(LOG_CMDS, "*", "#%s# help %s", dcc[idx].nick, par);
437     if (!strcmp(par, "all"))
438     tellallhelp(idx, "all", &fr);
439 fabian 1.4 else if (strchr(par, '*') || strchr(par, '?')) {
440     char *p = par;
441    
442     /* Check if the search pattern only consists of '*' and/or '?'
443     * If it does, show help for "all" instead of listing all help
444 fabian 1.22 * entries.
445     */
446 fabian 1.4 for (p = par; *p && ((*p == '*') || (*p == '?')); p++);
447     if (*p)
448     tellwildhelp(idx, par, &fr);
449     else
450     tellallhelp(idx, "all", &fr);
451     } else
452 segfault 1.1 tellhelp(idx, par, &fr, 0);
453     } else {
454     putlog(LOG_CMDS, "*", "#%s# help", dcc[idx].nick);
455     if (glob_op(fr) || glob_botmast(fr) || chan_op(fr))
456     tellhelp(idx, "help", &fr, 0);
457     else
458     tellhelp(idx, "helpparty", &fr, 0);
459     }
460     }
461    
462     static void cmd_addlog(struct userrec *u, int idx, char *par)
463     {
464     if (!par[0]) {
465     dprintf(idx, "Usage: addlog <message>\n");
466     return;
467     }
468     dprintf(idx, "Placed entry in the log file.\n");
469     putlog(LOG_MISC, "*", "%s: %s", dcc[idx].nick, par);
470     }
471    
472     static void cmd_who(struct userrec *u, int idx, char *par)
473     {
474     int i;
475    
476     if (par[0]) {
477     if (dcc[idx].u.chat->channel < 0) {
478     dprintf(idx, "You have chat turned off.\n");
479     return;
480     }
481     putlog(LOG_CMDS, "*", "#%s# who %s", dcc[idx].nick, par);
482 fabian 1.26 if (!egg_strcasecmp(par, botnetnick))
483 segfault 1.1 tell_who(u, idx, dcc[idx].u.chat->channel);
484     else {
485     i = nextbot(par);
486     if (i < 0) {
487     dprintf(idx, "That bot isn't connected.\n");
488     } else if (dcc[idx].u.chat->channel > 99999)
489     dprintf(idx, "You are on a local channel\n");
490     else {
491     char s[40];
492    
493     simple_sprintf(s, "%d:%s@%s", dcc[idx].sock,
494     dcc[idx].nick, botnetnick);
495     botnet_send_who(i, s, par, dcc[idx].u.chat->channel);
496     }
497     }
498     } else {
499     putlog(LOG_CMDS, "*", "#%s# who", dcc[idx].nick);
500     if (dcc[idx].u.chat->channel < 0)
501     tell_who(u, idx, 0);
502     else
503     tell_who(u, idx, dcc[idx].u.chat->channel);
504     }
505     }
506    
507     static void cmd_whois(struct userrec *u, int idx, char *par)
508     {
509     if (!par[0]) {
510     dprintf(idx, "Usage: whois <handle>\n");
511     return;
512     }
513     putlog(LOG_CMDS, "*", "#%s# whois %s", dcc[idx].nick, par);
514     tell_user_ident(idx, par, u ? (u->flags & USER_MASTER) : 0);
515     }
516    
517     static void cmd_match(struct userrec *u, int idx, char *par)
518     {
519     int start = 1, limit = 20;
520     char *s, *s1, *chname;
521    
522     if (!par[0]) {
523     dprintf(idx, "Usage: match <nick/host> [[skip] count]\n");
524     return;
525     }
526     putlog(LOG_CMDS, "*", "#%s# match %s", dcc[idx].nick, par);
527     s = newsplit(&par);
528     if (strchr(CHANMETA, par[0]) != NULL)
529     chname = newsplit(&par);
530     else
531     chname = "";
532     if (atoi(par) > 0) {
533     s1 = newsplit(&par);
534     if (atoi(par) > 0) {
535     start = atoi(s1);
536     limit = atoi(par);
537     } else
538     limit = atoi(s1);
539     }
540     tell_users_match(idx, s, start, limit, u ? (u->flags & USER_MASTER) : 0,
541     chname);
542     }
543    
544     static void cmd_uptime(struct userrec *u, int idx, char *par)
545     {
546     putlog(LOG_CMDS, "*", "#%s# uptime", dcc[idx].nick);
547     tell_verbose_uptime(idx);
548     }
549    
550     static void cmd_status(struct userrec *u, int idx, char *par)
551     {
552     int atr = u ? u->flags : 0;
553    
554 fabian 1.26 if (!egg_strcasecmp(par, "all")) {
555 segfault 1.1 if (!(atr & USER_MASTER)) {
556     dprintf(idx, "You do not have Bot Master privileges.\n");
557     return;
558     }
559     putlog(LOG_CMDS, "*", "#%s# status all", dcc[idx].nick);
560     tell_verbose_status(idx);
561     tell_mem_status_dcc(idx);
562     dprintf(idx, "\n");
563     tell_settings(idx);
564     do_module_report(idx, 1, NULL);
565     } else {
566     putlog(LOG_CMDS, "*", "#%s# status", dcc[idx].nick);
567     tell_verbose_status(idx);
568     tell_mem_status_dcc(idx);
569     do_module_report(idx, 0, NULL);
570     }
571     }
572    
573     static void cmd_dccstat(struct userrec *u, int idx, char *par)
574     {
575     putlog(LOG_CMDS, "*", "#%s# dccstat", dcc[idx].nick);
576     tell_dcc(idx);
577     }
578    
579     static void cmd_boot(struct userrec *u, int idx, char *par)
580     {
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     return;
588     }
589     who = newsplit(&par);
590     if (strchr(who, '@') != NULL) {
591 fabian 1.39 char whonick[HANDLEN + 1];
592 segfault 1.1
593 fabian 1.39 splitcn(whonick, who, '@', HANDLEN);
594 fabian 1.26 if (!egg_strcasecmp(who, botnetnick)) {
595 segfault 1.1 cmd_boot(u, idx, whonick);
596     return;
597     }
598     if (remote_boots > 0) {
599     i = nextbot(who);
600     if (i < 0) {
601 fabian 1.39 dprintf(idx, "No such bot connected.\n");
602     return;
603 segfault 1.1 }
604     botnet_send_reject(i, dcc[idx].nick, botnetnick, whonick,
605     who, par[0] ? par : dcc[idx].nick);
606 fabian 1.7 putlog(LOG_BOTS, "*", "#%s# boot %s@%s (%s)", dcc[idx].nick, whonick,
607 segfault 1.1 who, par[0] ? par : dcc[idx].nick);
608     } else
609     dprintf(idx, "Remote boots are disabled here.\n");
610     return;
611     }
612     for (i = 0; i < dcc_total; i++)
613 fabian 1.39 if (!egg_strcasecmp(dcc[i].nick, who)
614     && !ok && (dcc[i].type->flags & DCT_CANBOOT)) {
615 segfault 1.1 u2 = get_user_by_handle(userlist, dcc[i].nick);
616 fabian 1.39 if (u2 && (u2->flags & USER_OWNER)
617     && egg_strcasecmp(dcc[idx].nick, who)) {
618     dprintf(idx, "Can't boot the bot owner.\n");
619     return;
620     }
621     if (u2 && (u2->flags & USER_MASTER) && !(u && (u->flags & USER_MASTER))) {
622     dprintf(idx, "Can't boot a bot master.\n");
623     return;
624 segfault 1.1 }
625     files = (dcc[i].type->flags & DCT_FILES);
626     if (files)
627 fabian 1.39 dprintf(idx, "Booted %s from the file section.\n", dcc[i].nick);
628 segfault 1.1 else
629 fabian 1.39 dprintf(idx, "Booted %s from the bot.\n", dcc[i].nick);
630 segfault 1.1 putlog(LOG_CMDS, "*", "#%s# boot %s %s", dcc[idx].nick, who, par);
631     do_boot(i, dcc[idx].nick, par);
632     ok = 1;
633     }
634     if (!ok)
635     dprintf(idx, "Who? No such person on the party line.\n");
636     }
637    
638     static void cmd_console(struct userrec *u, int idx, char *par)
639     {
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     dprintf(idx, "Your console is %s: %s (%s)\n",
647     dcc[idx].u.chat->con_chan,
648     masktype(dcc[idx].u.chat->con_flags),
649     maskname(dcc[idx].u.chat->con_flags));
650     return;
651     }
652     get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
653     strcpy(s1, par);
654     nick = newsplit(&par);
655 fabian 1.22 /* Don't remove '+' as someone couldn't have '+' in CHANMETA cause
656     * 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 fabian 1.26 if (!egg_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     return;
668     }
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 fabian 1.8 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 segfault 1.1 dprintf(idx, "Invalid console channel: %s\n", nick);
679     return;
680     }
681     get_user_flagrec(u, &fr, nick);
682     if (!chan_op(fr) && !(glob_op(fr) && !chan_deop(fr))) {
683     dprintf(idx, "You don't have op or master access to channel %s\n",
684     nick);
685     return;
686     }
687 guppy 1.45 strncpyz(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     putlog(LOG_CMDS, "*", "#%s# console %s", dcc[idx].nick, s1);
731     if (dest == idx) {
732     dprintf(idx, "Set your console to %s: %s (%s)\n",
733     dcc[idx].u.chat->con_chan,
734     masktype(dcc[idx].u.chat->con_flags),
735     maskname(dcc[idx].u.chat->con_flags));
736     } else {
737     dprintf(idx, "Set console of %s to %s: %s (%s)\n", dcc[dest].nick,
738     dcc[dest].u.chat->con_chan,
739     masktype(dcc[dest].u.chat->con_flags),
740     maskname(dcc[dest].u.chat->con_flags));
741     dprintf(dest, "%s set your console to %s: %s (%s)\n", dcc[idx].nick,
742     dcc[dest].u.chat->con_chan,
743     masktype(dcc[dest].u.chat->con_flags),
744     maskname(dcc[dest].u.chat->con_flags));
745     }
746 fabian 1.22 /* New style autosave -- drummer,07/25/1999*/
747 fabian 1.2 if ((me = module_find("console", 1, 1))) {
748 segfault 1.1 Function *func = me->funcs;
749 fabian 1.3 (func[CONSOLE_DOSTORE]) (dest);
750 segfault 1.1 }
751     }
752    
753     static void cmd_pls_bot(struct userrec *u, int idx, char *par)
754     {
755     char *handle, *addr, *p, *q, *host;
756     struct userrec *u1;
757     struct bot_addr *bi;
758    
759     if (!par[0])
760     dprintf(idx, "Usage: +bot <handle> <address[:telnet-port[/relay-port]]> [host]\n");
761     else {
762     handle = newsplit(&par);
763     addr = newsplit(&par);
764     if (strlen(handle) > HANDLEN)
765     handle[HANDLEN] = 0; /* max len = XX .. for the moment :) */
766     if (get_user_by_handle(userlist, handle))
767     dprintf(idx, "Someone already exists by that name.\n");
768 fabian 1.6 else if (strchr(BADHANDCHARS, handle[0]) != NULL)
769 segfault 1.1 dprintf(idx, "You can't start a botnick with '%c'.\n", handle[0]);
770     else {
771     if (strlen(addr) > 60)
772     addr[60] = 0;
773     putlog(LOG_CMDS, "*", "#%s# +bot %s %s", dcc[idx].nick, handle, addr);
774     userlist = adduser(userlist, handle, "none", "-", USER_BOT);
775     u1 = get_user_by_handle(userlist, handle);
776     bi = user_malloc(sizeof(struct bot_addr));
777    
778     q = strchr(addr, ':');
779     if (!q) {
780     bi->address = user_malloc(strlen(addr) + 1);
781     strcpy(bi->address, addr);
782     bi->telnet_port = 3333;
783     bi->relay_port = 3333;
784     } else {
785     bi->address = user_malloc(q - addr + 1);
786     strncpy(bi->address, addr, q - addr);
787     bi->address[q - addr] = 0;
788     p = q + 1;
789     bi->telnet_port = atoi(p);
790     q = strchr(p, '/');
791     if (!q) {
792     bi->relay_port = bi->telnet_port;
793     } else {
794     bi->relay_port = atoi(q + 1);
795     }
796     }
797     set_user(&USERENTRY_BOTADDR, u1, bi);
798     dprintf(idx, "Added bot '%s' with address '%s' and no password.\n",
799     handle, addr);
800     host = newsplit(&par);
801     if (host[0]) {
802     addhost_by_handle(handle, host);
803     } else if (!add_bot_hostmask(idx, handle))
804     dprintf(idx, "You'll want to add a hostmask if this bot will ever %s",
805     "be on any channels that I'm on.\n");
806     }
807     }
808     }
809    
810 fabian 1.27 static void cmd_chhandle(struct userrec *u, int idx, char *par)
811 segfault 1.1 {
812 fabian 1.2 char hand[HANDLEN + 1], newhand[HANDLEN + 1];
813 segfault 1.1 int i, atr = u ? u->flags : 0, atr2;
814     struct userrec *u2;
815    
816 guppy 1.45 strncpyz(hand, newsplit(&par), sizeof hand);
817     strncpyz(newhand, newsplit(&par), sizeof newhand);
818 fabian 1.2
819     if (!hand[0] || !newhand[0]) {
820 fabian 1.27 dprintf(idx, "Usage: chhandle <oldhandle> <newhandle>\n");
821 fabian 1.2 return;
822     }
823     for (i = 0; i < strlen(newhand); i++)
824     if ((newhand[i] <= 32) || (newhand[i] >= 127) || (newhand[i] == '@'))
825     newhand[i] = '?';
826 fabian 1.6 if (strchr(BADHANDCHARS, newhand[0]) != NULL)
827 fabian 1.2 dprintf(idx, "Bizarre quantum forces prevent nicknames from starting with %c\n",
828     newhand[0]);
829     else if (get_user_by_handle(userlist, newhand) &&
830 fabian 1.26 egg_strcasecmp(hand, newhand))
831 fabian 1.2 dprintf(idx, "Somebody is already using %s.\n", newhand);
832 segfault 1.1 else {
833 fabian 1.2 u2 = get_user_by_handle(userlist, hand);
834     atr2 = u2 ? u2->flags : 0;
835     if ((atr & USER_BOTMAST) && !(atr & USER_MASTER) &&
836     !(atr2 & USER_BOT))
837     dprintf(idx, "You can't change nick for non-bots.\n");
838     else if ((bot_flags(u2) & BOT_SHARE) && !(atr & USER_OWNER))
839     dprintf(idx, "You can't change shared bot's nick.\n");
840     else if ((atr2 & USER_OWNER) && !(atr & USER_OWNER) &&
841 fabian 1.26 egg_strcasecmp(dcc[idx].nick, hand))
842 fabian 1.2 dprintf(idx, "Can't change the bot owner's handle.\n");
843 fabian 1.26 else if (isowner(hand) && egg_strcasecmp(dcc[idx].nick, hand))
844 fabian 1.2 dprintf(idx, "Can't change the permanent bot owner's handle.\n");
845 fabian 1.26 else if (!egg_strcasecmp(newhand, botnetnick) && (!(atr2 & USER_BOT) ||
846 fabian 1.6 nextbot(hand) != -1))
847     dprintf(idx, "Hey! That's MY name!\n");
848 fabian 1.2 else if (change_handle(u2, newhand)) {
849 fabian 1.27 putlog(LOG_CMDS, "*", "#%s# chhandle %s %s", dcc[idx].nick,
850 fabian 1.2 hand, newhand);
851     dprintf(idx, "Changed.\n");
852     } else
853     dprintf(idx, "Failed.\n");
854 segfault 1.1 }
855     }
856    
857 fabian 1.27 static void cmd_handle(struct userrec *u, int idx, char *par)
858 segfault 1.1 {
859 fabian 1.27 char oldhandle[HANDLEN + 1], newhandle[HANDLEN + 1];
860 fabian 1.2 int i;
861    
862 guppy 1.45 strncpyz(newhandle, newsplit(&par), sizeof newhandle);
863 segfault 1.1
864 fabian 1.27 if (!newhandle[0]) {
865     dprintf(idx, "Usage: handle <new-handle>\n");
866 segfault 1.1 return;
867     }
868 fabian 1.27 for (i = 0; i < strlen(newhandle); i++)
869     if ((newhandle[i] <= 32) || (newhandle[i] >= 127) || (newhandle[i] == '@'))
870     newhandle[i] = '?';
871     if (strchr(BADHANDCHARS, newhandle[0]) != NULL) {
872     dprintf(idx, "Bizarre quantum forces prevent handle from starting with '%c'\n",
873     newhandle[0]);
874     } else if (get_user_by_handle(userlist, newhandle) &&
875     egg_strcasecmp(dcc[idx].nick, newhandle)) {
876     dprintf(idx, "Somebody is already using %s.\n", newhandle);
877     } else if (!egg_strcasecmp(newhandle, botnetnick)) {
878 fabian 1.2 dprintf(idx, "Hey! That's MY name!\n");
879 segfault 1.1 } else {
880 guppy 1.45 strncpyz(oldhandle, dcc[idx].nick, sizeof oldhandle);
881 fabian 1.27 if (change_handle(u, newhandle)) {
882     putlog(LOG_CMDS, "*", "#%s# handle %s", oldhandle, newhandle);
883 segfault 1.1 dprintf(idx, "Okay, changed.\n");
884     } else
885     dprintf(idx, "Failed.\n");
886     }
887     }
888    
889     static void cmd_chpass(struct userrec *u, int idx, char *par)
890     {
891     char *handle, *new;
892     int atr = u ? u->flags : 0, l;
893    
894     if (!par[0])
895     dprintf(idx, "Usage: chpass <handle> [password]\n");
896     else {
897     handle = newsplit(&par);
898     u = get_user_by_handle(userlist, handle);
899     if (!u)
900     dprintf(idx, "No such user.\n");
901     else if ((atr & USER_BOTMAST) && !(atr & USER_MASTER) &&
902     !(u->flags & USER_BOT))
903     dprintf(idx, "You can't change password for non-bots.\n");
904     else if ((bot_flags(u) & BOT_SHARE) && !(atr & USER_OWNER))
905     dprintf(idx, "You can't change shared bot's password.\n");
906     else if ((u->flags & USER_OWNER) && !(atr & USER_OWNER) &&
907 fabian 1.26 egg_strcasecmp(handle, dcc[idx].nick))
908 segfault 1.1 dprintf(idx, "Can't change the bot owner's password.\n");
909 fabian 1.26 else if (isowner(handle) && egg_strcasecmp(dcc[idx].nick, handle))
910 fabian 1.19 dprintf(idx, "Can't change the permanent bot owner's password.\n");
911 segfault 1.1 else if (!par[0]) {
912     putlog(LOG_CMDS, "*", "#%s# chpass %s [nothing]", dcc[idx].nick,
913     handle);
914     set_user(&USERENTRY_PASS, u, NULL);
915     dprintf(idx, "Removed password.\n");
916     } else {
917     l = strlen(new = newsplit(&par));
918     if (l > 16)
919     new[16] = 0;
920     if (l < 6)
921     dprintf(idx, "Please use at least 6 characters.\n");
922     else {
923     set_user(&USERENTRY_PASS, u, new);
924     putlog(LOG_CMDS, "*", "#%s# chpass %s [something]", dcc[idx].nick,
925     handle);
926     dprintf(idx, "Changed password.\n");
927     }
928     }
929     }
930     }
931    
932     static void cmd_chaddr(struct userrec *u, int idx, char *par)
933     {
934     char *handle, *addr, *p, *q;
935     struct bot_addr *bi;
936     struct userrec *u1;
937    
938     if (!par[0]) {
939     dprintf(idx, "Usage: chaddr <botname> <address:botport#/userport#>\n");
940     return;
941     }
942     handle = newsplit(&par);
943     addr = newsplit(&par);
944 fabian 1.6 if (strlen(addr) > UHOSTMAX)
945     addr[UHOSTMAX] = 0;
946 segfault 1.1 u1 = get_user_by_handle(userlist, handle);
947     if (!u1 || !(u1->flags & USER_BOT)) {
948     dprintf(idx, "Useful only for tandem bots.\n");
949     return;
950     }
951     if ((bot_flags(u1) & BOT_SHARE) && (!u || !u->flags & USER_OWNER)) {
952     dprintf(idx, "You can't change shared bot's address.\n");
953     return;
954     }
955     putlog(LOG_CMDS, "*", "#%s# chaddr %s %s", dcc[idx].nick, handle, addr);
956     dprintf(idx, "Changed bot's address.\n");
957     bi = user_malloc(sizeof(struct bot_addr));
958    
959     q = strchr(addr, ':');
960     if (!q) {
961     bi->address = user_malloc(strlen(addr) + 1);
962     strcpy(bi->address, addr);
963     bi->telnet_port = 3333;
964     bi->relay_port = 3333;
965     } else {
966     bi->address = user_malloc(q - addr + 1);
967 guppy 1.45 strncpyz(bi->address, addr, q - addr);
968 segfault 1.1 p = q + 1;
969     bi->telnet_port = atoi(p);
970     q = strchr(p, '/');
971     if (!q) {
972     bi->relay_port = bi->telnet_port;
973     } else {
974     bi->relay_port = atoi(q + 1);
975     }
976     }
977     set_user(&USERENTRY_BOTADDR, u1, bi);
978     }
979    
980     static void cmd_comment(struct userrec *u, int idx, char *par)
981     {
982     char *handle;
983     struct userrec *u1;
984    
985     if (!par[0]) {
986     dprintf(idx, "Usage: comment <handle> <newcomment>\n");
987     return;
988     }
989     handle = newsplit(&par);
990     u1 = get_user_by_handle(userlist, handle);
991     if (!u1) {
992     dprintf(idx, "No such user!\n");
993     return;
994     }
995     if ((u1->flags & USER_OWNER) && !(u && (u->flags & USER_OWNER)) &&
996 fabian 1.26 egg_strcasecmp(handle, dcc[idx].nick)) {
997 segfault 1.1 dprintf(idx, "Can't change comment on the bot owner.\n");
998     return;
999     }
1000     putlog(LOG_CMDS, "*", "#%s# comment %s %s", dcc[idx].nick, handle, par);
1001 fabian 1.26 if (!egg_strcasecmp(par, "none")) {
1002 segfault 1.1 dprintf(idx, "Okay, comment blanked.\n");
1003     set_user(&USERENTRY_COMMENT, u1, NULL);
1004     return;
1005     }
1006     dprintf(idx, "Changed comment.\n");
1007     set_user(&USERENTRY_COMMENT, u1, par);
1008     }
1009    
1010     static void cmd_restart(struct userrec *u, int idx, char *par)
1011     {
1012     putlog(LOG_CMDS, "*", "#%s# restart", dcc[idx].nick);
1013     if (!backgrd) {
1014     dprintf(idx, "You can not .restart a bot when running -n (due to tcl)\n");
1015     return;
1016     }
1017     dprintf(idx, "Restarting.\n");
1018     if (make_userfile) {
1019     putlog(LOG_MISC, "*",
1020     "Uh, guess you don't need to create a new userfile.");
1021     make_userfile = 0;
1022     }
1023     write_userfile(-1);
1024     putlog(LOG_MISC, "*", "Restarting ...");
1025     wipe_timers(interp, &utimer);
1026     wipe_timers(interp, &timer);
1027     do_restart = idx;
1028     }
1029    
1030     static void cmd_rehash(struct userrec *u, int idx, char *par)
1031     {
1032     putlog(LOG_CMDS, "*", "#%s# rehash", dcc[idx].nick);
1033     dprintf(idx, "Rehashing.\n");
1034     if (make_userfile) {
1035     putlog(LOG_MISC, "*",
1036     "Uh, guess you don't need to create a new userfile.");
1037     make_userfile = 0;
1038     }
1039     write_userfile(-1);
1040     putlog(LOG_MISC, "*", "Rehashing ...");
1041     do_restart = -2;
1042     }
1043    
1044     static void cmd_reload(struct userrec *u, int idx, char *par)
1045     {
1046     putlog(LOG_CMDS, "*", "#%s# reload", dcc[idx].nick);
1047     dprintf(idx, "Reloading user file...\n");
1048     reload();
1049     }
1050    
1051 fabian 1.22 /* NOTE: This gets replaced in the server mod, with a version that handles
1052     * the server disconnect better.
1053     */
1054 segfault 1.1 void cmd_die(struct userrec *u, int idx, char *par)
1055     {
1056     char s[1024];
1057    
1058     putlog(LOG_CMDS, "*", "#%s# die %s", dcc[idx].nick, par);
1059     if (par[0]) {
1060     simple_sprintf(s, "BOT SHUTDOWN (%s: %s)", dcc[idx].nick, par);
1061     } else {
1062     simple_sprintf(s, "BOT SHUTDOWN (authorized by %s)", dcc[idx].nick);
1063     }
1064     chatout("*** %s\n", s);
1065     botnet_send_chat(-1, botnetnick, s);
1066     botnet_send_bye();
1067     write_userfile(-1);
1068     simple_sprintf(s, "DIE BY %s!%s (%s)", dcc[idx].nick,
1069     dcc[idx].host, par[0] ? par : "request");
1070     fatal(s, 0);
1071     }
1072    
1073     static void cmd_debug(struct userrec *u, int idx, char *par)
1074     {
1075 fabian 1.26 if (!egg_strcasecmp(par, "help")) {
1076 segfault 1.1 putlog(LOG_CMDS, "*", "#%s# debug help", dcc[idx].nick);
1077     debug_help(idx);
1078     } else {
1079     putlog(LOG_CMDS, "*", "#%s# debug", dcc[idx].nick);
1080     debug_mem_to_dcc(idx);
1081     }
1082     }
1083    
1084     static void cmd_simul(struct userrec *u, int idx, char *par)
1085     {
1086     char *nick;
1087     int i, ok = 0;
1088    
1089     nick = newsplit(&par);
1090     if (!par[0]) {
1091 johoho 1.32 dprintf(idx, "Usage: simul <hand> <text>\n");
1092 segfault 1.1 return;
1093     }
1094     if (isowner(nick)) {
1095     dprintf(idx, "Unable to '.simul' permanent owners.\n");
1096     return;
1097     }
1098     for (i = 0; i < dcc_total; i++)
1099 fabian 1.26 if (!egg_strcasecmp(nick, dcc[i].nick) && !ok &&
1100 segfault 1.1 (dcc[i].type->flags & DCT_SIMUL)) {
1101     putlog(LOG_CMDS, "*", "#%s# simul %s %s", dcc[idx].nick, nick, par);
1102     if (dcc[i].type && dcc[i].type->activity) {
1103     dcc[i].type->activity(i, par, strlen(par));
1104     ok = 1;
1105     }
1106     }
1107     if (!ok)
1108     dprintf(idx, "No such user on the party line.\n");
1109     }
1110    
1111     static void cmd_link(struct userrec *u, int idx, char *par)
1112     {
1113     char *s;
1114     int i;
1115    
1116     if (!par[0]) {
1117     dprintf(idx, "Usage: link [some-bot] <new-bot>\n");
1118     return;
1119     }
1120     putlog(LOG_CMDS, "*", "#%s# link %s", dcc[idx].nick, par);
1121     s = newsplit(&par);
1122 fabian 1.26 if (!par[0] || !egg_strcasecmp(par, botnetnick))
1123 segfault 1.1 botlink(dcc[idx].nick, idx, s);
1124     else {
1125     char x[40];
1126    
1127     i = nextbot(s);
1128     if (i < 0) {
1129     dprintf(idx, "No such bot online.\n");
1130     return;
1131     }
1132     simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1133     botnet_send_link(i, x, s, par);
1134     }
1135     }
1136    
1137     static void cmd_unlink(struct userrec *u, int idx, char *par)
1138     {
1139     int i;
1140     char *bot;
1141    
1142     if (!par[0]) {
1143     dprintf(idx, "Usage: unlink <bot> [reason]\n");
1144     return;
1145     }
1146     putlog(LOG_CMDS, "*", "#%s# unlink %s", dcc[idx].nick, par);
1147     bot = newsplit(&par);
1148     i = nextbot(bot);
1149     if (i < 0) {
1150     botunlink(idx, bot, par);
1151     return;
1152     }
1153 fabian 1.22 /* If we're directly connected to that bot, just do it
1154     * (is nike gunna sue?)
1155     */
1156 fabian 1.26 if (!egg_strcasecmp(dcc[i].nick, bot))
1157 segfault 1.1 botunlink(idx, bot, par);
1158     else {
1159     char x[40];
1160    
1161     simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1162     botnet_send_unlink(i, x, lastbot(bot), bot, par);
1163     }
1164     }
1165    
1166     static void cmd_relay(struct userrec *u, int idx, char *par)
1167     {
1168     if (!par[0]) {
1169     dprintf(idx, "Usage: relay <bot>\n");
1170     return;
1171     }
1172     putlog(LOG_CMDS, "*", "#%s# relay %s", dcc[idx].nick, par);
1173     tandem_relay(idx, par, 0);
1174     }
1175    
1176     static void cmd_save(struct userrec *u, int idx, char *par)
1177     {
1178     putlog(LOG_CMDS, "*", "#%s# save", dcc[idx].nick);
1179     dprintf(idx, "Saving user file...\n");
1180     write_userfile(-1);
1181     }
1182    
1183     static void cmd_backup(struct userrec *u, int idx, char *par)
1184     {
1185     putlog(LOG_CMDS, "*", "#%s# backup", dcc[idx].nick);
1186     dprintf(idx, "Backing up the user file...\n");
1187     backup_userfile();
1188     }
1189    
1190     static void cmd_trace(struct userrec *u, int idx, char *par)
1191     {
1192     int i;
1193     char x[NOTENAMELEN + 11], y[11];
1194    
1195     if (!par[0]) {
1196     dprintf(idx, "Usage: trace <botname>\n");
1197     return;
1198     }
1199 fabian 1.26 if (!egg_strcasecmp(par, botnetnick)) {
1200 segfault 1.1 dprintf(idx, "That's me! Hiya! :)\n");
1201     return;
1202     }
1203     i = nextbot(par);
1204     if (i < 0) {
1205     dprintf(idx, "Unreachable bot.\n");
1206     return;
1207     }
1208     putlog(LOG_CMDS, "*", "#%s# trace %s", dcc[idx].nick, par);
1209     simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1210     simple_sprintf(y, ":%d", now);
1211     botnet_send_trace(i, x, par, y);
1212     }
1213    
1214     static void cmd_binds(struct userrec *u, int idx, char *par)
1215     {
1216     putlog(LOG_CMDS, "*", "#%s# binds %s", dcc[idx].nick, par);
1217     tell_binds(idx, par);
1218     }
1219    
1220     static void cmd_banner(struct userrec *u, int idx, char *par)
1221     {
1222     char s[1024];
1223     int i;
1224    
1225     if (!par[0]) {
1226     dprintf(idx, "Usage: banner <message>\n");
1227     return;
1228     }
1229     simple_sprintf(s, "\007\007### Botwide:[%s] %s\n", dcc[idx].nick, par);
1230     for (i = 0; i < dcc_total; i++)
1231     if (dcc[i].type->flags & DCT_MASTER)
1232     dprintf(i, "%s", s);
1233     }
1234    
1235 fabian 1.22 /* After messing with someone's user flags, make sure the dcc-chat flags
1236     * are set correctly.
1237     */
1238 segfault 1.1 int check_dcc_attrs(struct userrec *u, int oatr)
1239     {
1240     int i, stat;
1241     char *p, *q, s[121];
1242    
1243 fabian 1.22 /* If it matches someone in the owner list, make sure he/she has +n */
1244 segfault 1.1 if (!u)
1245     return 0;
1246 fabian 1.22 /* Make sure default owners are +n */
1247 segfault 1.1 if (owner[0]) {
1248     q = owner;
1249     p = strchr(q, ',');
1250     while (p) {
1251 guppy 1.45 strncpyz(s, q, p - q);
1252 segfault 1.1 rmspace(s);
1253 fabian 1.26 if (!egg_strcasecmp(u->handle, s))
1254 segfault 1.1 u->flags = sanity_check(u->flags | USER_OWNER);
1255     q = p + 1;
1256     p = strchr(q, ',');
1257     }
1258     strcpy(s, q);
1259     rmspace(s);
1260 fabian 1.26 if (!egg_strcasecmp(u->handle, s))
1261 segfault 1.1 u->flags = sanity_check(u->flags | USER_OWNER);
1262     }
1263     for (i = 0; i < dcc_total; i++) {
1264     if ((dcc[i].type->flags & DCT_MASTER) &&
1265 fabian 1.26 (!egg_strcasecmp(u->handle, dcc[i].nick))) {
1266 segfault 1.1 stat = dcc[i].status;
1267     if ((dcc[i].type == &DCC_CHAT) &&
1268     ((u->flags & (USER_OP | USER_MASTER | USER_OWNER |
1269     USER_BOTMAST))
1270     != (oatr & (USER_OP | USER_MASTER | USER_OWNER |
1271     USER_BOTMAST)))) {
1272     botnet_send_join_idx(i, -1);
1273     }
1274     if ((oatr & USER_MASTER) && !(u->flags & USER_MASTER)) {
1275 fabian 1.22 struct flag_record fr = {FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
1276 segfault 1.1
1277     dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_RAW |
1278     LOG_FILES | LOG_LEV1 | LOG_LEV2 |
1279     LOG_LEV3 | LOG_LEV4 | LOG_LEV5 |
1280     LOG_LEV6 | LOG_LEV7 | LOG_LEV8 |
1281     LOG_WALL | LOG_DEBUG);
1282     get_user_flagrec(u, &fr, NULL);
1283     if (!chan_master(fr))
1284     dcc[i].u.chat->con_flags |= (LOG_MISC | LOG_CMDS);
1285     dprintf(i, "*** POOF! ***\n");
1286     dprintf(i, "You are no longer a master on this bot.\n");
1287     }
1288     if (!(oatr & USER_MASTER) && (u->flags & USER_MASTER)) {
1289     dcc[i].u.chat->con_flags |= conmask;
1290     dprintf(i, "*** POOF! ***\n");
1291     dprintf(i, "You are now a master on this bot.\n");
1292     }
1293     if (!(oatr & USER_BOTMAST) && (u->flags & USER_BOTMAST)) {
1294     dprintf(i, "### POOF! ###\n");
1295     dprintf(i, "You are now a botnet master on this bot.\n");
1296     }
1297     if ((oatr & USER_BOTMAST) && !(u->flags & USER_BOTMAST)) {
1298     dprintf(i, "### POOF! ###\n");
1299     dprintf(i, "You are no longer a botnet master on this bot.\n");
1300     }
1301     if (!(oatr & USER_OWNER) && (u->flags & USER_OWNER)) {
1302     dprintf(i, "@@@ POOF! @@@\n");
1303     dprintf(i, "You are now an OWNER of this bot.\n");
1304     }
1305     if ((oatr & USER_OWNER) && !(u->flags & USER_OWNER)) {
1306     dprintf(i, "@@@ POOF! @@@\n");
1307     dprintf(i, "You are no longer an owner of this bot.\n");
1308     }
1309     if ((stat & STAT_PARTY) && (u->flags & USER_OP))
1310     stat &= ~STAT_PARTY;
1311     if (!(stat & STAT_PARTY) && !(u->flags & USER_OP) &&
1312     !(u->flags & USER_MASTER))
1313     stat |= STAT_PARTY;
1314     if ((stat & STAT_CHAT) && !(u->flags & USER_PARTY) &&
1315     !(u->flags & USER_MASTER) &&
1316     (!(u->flags & USER_OP) || require_p))
1317     stat &= ~STAT_CHAT;
1318     if ((dcc[i].type->flags & DCT_FILES) && !(stat & STAT_CHAT) &&
1319     ((u->flags & USER_MASTER) || (u->flags & USER_PARTY) ||
1320     ((u->flags & USER_OP) && !require_p)))
1321     stat |= STAT_CHAT;
1322     dcc[i].status = stat;
1323 fabian 1.22 /* Check if they no longer have access to wherever they are.
1324     *
1325     * NOTE: DON'T kick someone off the party line just cuz they lost +p
1326     * (pinvite script removes +p after 5 mins automatically)
1327     */
1328 segfault 1.1 if ((dcc[i].type->flags & DCT_FILES) && !(u->flags & USER_XFER) &&
1329     !(u->flags & USER_MASTER)) {
1330     dprintf(i, "-+- POOF! -+-\n");
1331     dprintf(i, "You no longer have file area access.\n\n");
1332     putlog(LOG_MISC, "*", "DCC user [%s]%s removed from file system",
1333     dcc[i].nick, dcc[i].host);
1334     if (dcc[i].status & STAT_CHAT) {
1335     struct chat_info *ci;
1336    
1337     ci = dcc[i].u.file->chat;
1338     nfree(dcc[i].u.file);
1339     dcc[i].u.chat = ci;
1340     dcc[i].status &= (~STAT_CHAT);
1341     dcc[i].type = &DCC_CHAT;
1342     if (dcc[i].u.chat->channel >= 0) {
1343     chanout_but(-1, dcc[i].u.chat->channel,
1344     "*** %s has returned.\n", dcc[i].nick);
1345     if (dcc[i].u.chat->channel < 100000)
1346     botnet_send_join_idx(i, -1);
1347     }
1348     } else {
1349     killsock(dcc[i].sock);
1350 fabian 1.16 lostdcc(i);
1351 segfault 1.1 }
1352     }
1353     }
1354 fabian 1.26 if (dcc[i].type == &DCC_BOT && !egg_strcasecmp(u->handle, dcc[i].nick)) {
1355 segfault 1.1 if ((dcc[i].status & STAT_LEAF) && !(u->flags & BOT_LEAF))
1356     dcc[i].status &= ~(STAT_LEAF | STAT_WARNED);
1357     if (!(dcc[i].status & STAT_LEAF) && (u->flags & BOT_LEAF))
1358     dcc[i].status |= STAT_LEAF;
1359     }
1360     }
1361     return u->flags;
1362     }
1363    
1364     int check_dcc_chanattrs(struct userrec *u, char *chname, int chflags,
1365     int ochatr)
1366     {
1367     int i, found = 0, atr = u ? u->flags : 0;
1368     struct chanset_t *chan;
1369    
1370     if (!u)
1371     return 0;
1372     chan = chanset;
1373     for (i = 0; i < dcc_total; i++) {
1374     if ((dcc[i].type->flags & DCT_MASTER) &&
1375 fabian 1.26 !egg_strcasecmp(u->handle, dcc[i].nick)) {
1376 segfault 1.1 if ((dcc[i].type == &DCC_CHAT) &&
1377     ((chflags & (USER_OP | USER_MASTER | USER_OWNER))
1378     != (ochatr & (USER_OP | USER_MASTER | USER_OWNER))))
1379     botnet_send_join_idx(i, -1);
1380     if ((ochatr & USER_MASTER) && !(chflags & USER_MASTER)) {
1381     if (!(atr & USER_MASTER))
1382     dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS);
1383     dprintf(i, "*** POOF! ***\n");
1384     dprintf(i, "You are no longer a master on %s.\n", chname);
1385     }
1386     if (!(ochatr & USER_MASTER) && (chflags & USER_MASTER)) {
1387     dcc[i].u.chat->con_flags |= conmask;
1388     if (!(atr & USER_MASTER))
1389     dcc[i].u.chat->con_flags &=
1390     ~(LOG_LEV1 | LOG_LEV2 | LOG_LEV3 | LOG_LEV4 |
1391     LOG_LEV5 | LOG_LEV6 | LOG_LEV7 | LOG_LEV8 |
1392     LOG_RAW | LOG_DEBUG | LOG_WALL | LOG_FILES | LOG_SRVOUT);
1393     dprintf(i, "*** POOF! ***\n");
1394     dprintf(i, "You are now a master on %s.\n", chname);
1395     }
1396     if (!(ochatr & USER_OWNER) && (chflags & USER_OWNER)) {
1397     dprintf(i, "@@@ POOF! @@@\n");
1398     dprintf(i, "You are now an OWNER of %s.\n", chname);
1399     }
1400     if ((ochatr & USER_OWNER) && !(chflags & USER_OWNER)) {
1401     dprintf(i, "@@@ POOF! @@@\n");
1402     dprintf(i, "You are no longer an owner of %s.\n", chname);
1403     }
1404     if (((ochatr & (USER_OP | USER_MASTER | USER_OWNER)) &&
1405     (!(chflags & (USER_OP | USER_MASTER | USER_OWNER)))) ||
1406     ((chflags & (USER_OP | USER_MASTER | USER_OWNER)) &&
1407     (!(ochatr & (USER_OP | USER_MASTER | USER_OWNER))))) {
1408 fabian 1.11 struct flag_record fr = {FR_CHAN, 0, 0, 0, 0, 0};
1409 segfault 1.1
1410     while (chan && !found) {
1411 fabian 1.8 get_user_flagrec(u, &fr, chan->dname);
1412 segfault 1.1 if (fr.chan & (USER_OP | USER_MASTER | USER_OWNER))
1413     found = 1;
1414     else
1415     chan = chan->next;
1416     }
1417     if (!chan)
1418     chan = chanset;
1419     if (chan)
1420 fabian 1.8 strcpy(dcc[i].u.chat->con_chan, chan->dname);
1421 segfault 1.1 else
1422     strcpy(dcc[i].u.chat->con_chan, "*");
1423     }
1424     }
1425     }
1426     return chflags;
1427     }
1428    
1429     static void cmd_chattr(struct userrec *u, int idx, char *par)
1430     {
1431 fabian 1.6 char *hand, *arg = NULL, *tmpchg = NULL, *chg = NULL, work[1024];
1432 segfault 1.1 struct chanset_t *chan = NULL;
1433     struct userrec *u2;
1434 fabian 1.2 struct flag_record pls = {0, 0, 0, 0, 0, 0},
1435     mns = {0, 0, 0, 0, 0, 0},
1436     user = {0, 0, 0, 0, 0, 0};
1437 segfault 1.1 module_entry *me;
1438     int fl = -1, of = 0, ocf = 0;
1439    
1440     if (!par[0]) {
1441     dprintf(idx, "Usage: chattr <handle> [changes] [channel]\n");
1442     return;
1443     }
1444     hand = newsplit(&par);
1445     u2 = get_user_by_handle(userlist, hand);
1446 fabian 1.6 if (!u2) {
1447 segfault 1.1 dprintf(idx, "No such user!\n");
1448     return;
1449     }
1450 fabian 1.6
1451     /* Parse args */
1452     if (par[0]) {
1453 fabian 1.8 arg = newsplit(&par);
1454 fabian 1.6 if (par[0]) {
1455     /* .chattr <handle> <changes> <channel> */
1456     chg = arg;
1457 fabian 1.8 arg = newsplit(&par);
1458     chan = findchan_by_dname(arg);
1459 fabian 1.6 } else {
1460 fabian 1.8 chan = findchan_by_dname(arg);
1461 fabian 1.22 /* Consider modeless channels, starting with '+' */
1462 fabian 1.6 if (!(arg[0] == '+' && chan) &&
1463     !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
1464     /* .chattr <handle> <changes> */
1465     chg = arg;
1466     chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
1467     arg = NULL;
1468     }
1469     /* .chattr <handle> <channel>: nothing to do... */
1470     }
1471     }
1472     /* arg: pointer to channel name, NULL if none specified
1473     * chan: pointer to channel structure, NULL if none found or none specified
1474     * chg: pointer to changes, NULL if none specified
1475     */
1476 fabian 1.13 Assert(!(!arg && chan));
1477 fabian 1.6 if (arg && !chan) {
1478     dprintf(idx, "No channel record for %s.\n", arg);
1479     return;
1480 segfault 1.1 }
1481 fabian 1.6 if (chg) {
1482     if (!arg && strpbrk(chg, "&|")) {
1483     /* .chattr <handle> *[&|]*: use console channel if found... */
1484     if (!strcmp ((arg = dcc[idx].u.chat->con_chan), "*"))
1485     arg = NULL;
1486     else
1487 fabian 1.8 chan = findchan_by_dname(arg);
1488 fabian 1.6 if (arg && !chan) {
1489     dprintf (idx, "Invalid console channel %s.\n", arg);
1490     return;
1491     }
1492     } else if (arg && !strpbrk(chg, "&|")) {
1493     tmpchg = nmalloc(strlen(chg) + 2);
1494 fabian 1.11 strcpy(tmpchg, "|");
1495     strcat(tmpchg, chg);
1496 fabian 1.6 chg = tmpchg;
1497 segfault 1.1 }
1498     }
1499 fabian 1.6 par = arg;
1500 segfault 1.1 user.match = FR_GLOBAL;
1501     if (chan)
1502     user.match |= FR_CHAN;
1503 fabian 1.8 get_user_flagrec(u, &user, chan ? chan->dname : 0);
1504 segfault 1.1 if (!chan && !glob_botmast(user)) {
1505     dprintf(idx, "You do not have Bot Master privileges.\n");
1506 fabian 1.6 if (tmpchg)
1507     nfree(tmpchg);
1508 segfault 1.1 return;
1509     }
1510     if (chan && !glob_master(user) && !chan_master(user)) {
1511     dprintf(idx, "You do not have channel master privileges for channel %s\n",
1512     par);
1513 fabian 1.6 if (tmpchg)
1514     nfree(tmpchg);
1515 segfault 1.1 return;
1516     }
1517     user.match &= fl;
1518     if (chg) {
1519     pls.match = user.match;
1520     break_down_flags(chg, &pls, &mns);
1521 fabian 1.22 /* No-one can change these flags on-the-fly */
1522 fabian 1.6 pls.global &= ~(USER_BOT);
1523     mns.global &= ~(USER_BOT);
1524 segfault 1.1
1525     if (chan) {
1526     pls.chan &= ~(BOT_SHARE);
1527     mns.chan &= ~(BOT_SHARE);
1528     }
1529     if (!glob_owner(user)) {
1530 fabian 1.6 pls.global &= ~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1531     mns.global &= ~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1532 segfault 1.1
1533     if (chan) {
1534     pls.chan &= ~USER_OWNER;
1535     mns.chan &= ~USER_OWNER;
1536     }
1537     if (!glob_master(user)) {
1538 fabian 1.6 pls.global &= USER_PARTY | USER_XFER;
1539     mns.global &= USER_PARTY | USER_XFER;
1540 segfault 1.1
1541     if (!glob_botmast(user)) {
1542     pls.global = 0;
1543     mns.global = 0;
1544     }
1545     }
1546     }
1547     if (chan && !chan_owner(user) && !glob_owner(user)) {
1548     pls.chan &= ~USER_MASTER;
1549     mns.chan &= ~USER_MASTER;
1550     if (!chan_master(user) && !glob_master(user)) {
1551     pls.chan = 0;
1552     mns.chan = 0;
1553     }
1554     }
1555     get_user_flagrec(u2, &user, par);
1556     if (user.match & FR_GLOBAL) {
1557     of = user.global;
1558     user.global = sanity_check((user.global |pls.global) &~mns.global);
1559    
1560     user.udef_global = (user.udef_global | pls.udef_global)
1561     & ~mns.udef_global;
1562     }
1563     if (chan) {
1564     ocf = user.chan;
1565     user.chan = chan_sanity_check((user.chan | pls.chan) & ~mns.chan,
1566     user.global);
1567    
1568     user.udef_chan = (user.udef_chan | pls.udef_chan) & ~mns.udef_chan;
1569     }
1570     set_user_flagrec(u2, &user, par);
1571     }
1572     if (chan)
1573     putlog(LOG_CMDS, "*", "#%s# (%s) chattr %s %s",
1574 fabian 1.8 dcc[idx].nick, chan ? chan->dname : "*", hand, chg ? chg : "");
1575 segfault 1.1 else
1576     putlog(LOG_CMDS, "*", "#%s# chattr %s %s", dcc[idx].nick, hand,
1577     chg ? chg : "");
1578 fabian 1.22 /* Get current flags and display them */
1579 segfault 1.1 if (user.match & FR_GLOBAL) {
1580     user.match = FR_GLOBAL;
1581     if (chg)
1582     check_dcc_attrs(u2, of);
1583     get_user_flagrec(u2, &user, NULL);
1584     build_flags(work, &user, NULL);
1585     if (work[0] != '-')
1586     dprintf(idx, "Global flags for %s are now +%s\n", hand, work);
1587     else
1588     dprintf(idx, "No global flags for %s.\n", hand);
1589     }
1590     if (chan) {
1591     user.match = FR_CHAN;
1592     get_user_flagrec(u2, &user, par);
1593     user.chan &= ~BOT_SHARE;
1594     if (chg)
1595 fabian 1.8 check_dcc_chanattrs(u2, chan->dname, user.chan, ocf);
1596 segfault 1.1 build_flags(work, &user, NULL);
1597     if (work[0] != '-')
1598     dprintf(idx, "Channel flags for %s on %s are now +%s\n", hand,
1599 fabian 1.8 chan->dname, work);
1600 segfault 1.1 else
1601 fabian 1.8 dprintf(idx, "No flags for %s on %s.\n", hand, chan->dname);
1602 fabian 1.6 if (chg && (me = module_find("irc", 0, 0))) {
1603 segfault 1.1 Function *func = me->funcs;
1604    
1605     if (chan)
1606 fabian 1.2 (func[IRC_RECHECK_CHANNEL]) (chan, 0);
1607 segfault 1.1 }
1608     }
1609 fabian 1.6 if (tmpchg)
1610     nfree(tmpchg);
1611 segfault 1.1 }
1612    
1613     static void cmd_botattr(struct userrec *u, int idx, char *par)
1614     {
1615 fabian 1.6 char *hand, *chg = NULL, *arg = NULL, *tmpchg = NULL, work[1024];
1616 segfault 1.1 struct chanset_t *chan = NULL;
1617     struct userrec *u2;
1618 fabian 1.8 struct flag_record pls = {0, 0, 0, 0, 0, 0},
1619     mns = {0, 0, 0, 0, 0, 0},
1620     user = {0, 0, 0, 0, 0, 0};
1621 segfault 1.1 int idx2;
1622    
1623     if (!par[0]) {
1624     dprintf(idx, "Usage: botattr <handle> [changes] [channel]\n");
1625     return;
1626     }
1627     hand = newsplit(&par);
1628     u2 = get_user_by_handle(userlist, hand);
1629 fabian 1.6 if (!u2 || !(u2->flags & USER_BOT)) {
1630 segfault 1.1 dprintf(idx, "No such bot!\n");
1631     return;
1632     }
1633     for (idx2 = 0; idx2 < dcc_total; idx2++)
1634 fabian 1.33 if (dcc[idx2].type != &DCC_RELAY && dcc[idx2].type != &DCC_FORK_BOT &&
1635     !egg_strcasecmp(dcc[idx2].nick, hand))
1636 segfault 1.1 break;
1637     if (idx2 != dcc_total) {
1638 fabian 1.6 dprintf(idx, "You may not change the attributes of a directly linked bot.\n");
1639 segfault 1.1 return;
1640     }
1641 fabian 1.6 /* Parse args */
1642     if (par[0]) {
1643 fabian 1.10 arg = newsplit(&par);
1644 fabian 1.6 if (par[0]) {
1645     /* .botattr <handle> <changes> <channel> */
1646     chg = arg;
1647 fabian 1.10 arg = newsplit(&par);
1648 fabian 1.8 chan = findchan_by_dname(arg);
1649 fabian 1.6 } else {
1650 fabian 1.8 chan = findchan_by_dname(arg);
1651 fabian 1.22 /* Consider modeless channels, starting with '+' */
1652 fabian 1.6 if (!(arg[0] == '+' && chan) &&
1653     !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
1654     /* .botattr <handle> <changes> */
1655     chg = arg;
1656     chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
1657     arg = NULL;
1658     }
1659     /* .botattr <handle> <channel>: nothing to do... */
1660     }
1661     }
1662     /* arg: pointer to channel name, NULL if none specified
1663     * chan: pointer to channel structure, NULL if none found or none specified
1664     * chg: pointer to changes, NULL if none specified
1665     */
1666 fabian 1.13 Assert(!(!arg && chan));
1667 fabian 1.6 if (arg && !chan) {
1668     dprintf(idx, "No channel record for %s.\n", arg);
1669     return;
1670 segfault 1.1 }
1671 fabian 1.6 if (chg) {
1672     if (!arg && strpbrk(chg, "&|")) {
1673     /* botattr <handle> *[&|]*: use console channel if found... */
1674     if (!strcmp ((arg = dcc[idx].u.chat->con_chan), "*"))
1675     arg = NULL;
1676     else
1677 fabian 1.8 chan = findchan_by_dname(arg);
1678 fabian 1.6 if (arg && !chan) {
1679     dprintf (idx, "Invalid console channel %s.\n", arg);
1680     return;
1681     }
1682     } else if (arg && !strpbrk(chg, "&|")) {
1683     tmpchg = nmalloc(strlen(chg) + 2);
1684     strcpy (tmpchg, "|");
1685     strcat (tmpchg, chg);
1686     chg = tmpchg;
1687     }
1688 segfault 1.1 }
1689 fabian 1.6 par = arg;
1690    
1691 segfault 1.1 user.match = FR_GLOBAL;
1692 fabian 1.8 get_user_flagrec(u, &user, chan ? chan->dname : 0);
1693 segfault 1.1 if (!glob_botmast(user))