/[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.22 - (hide annotations) (download) (as text)
Sun Jan 30 19:26:20 2000 UTC (19 years, 10 months ago) by fabian
Branch: MAIN
Changes since 1.21: +163 -143 lines
File MIME type: text/x-chdr
cleanup3 patch

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