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