/[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.59 - (hide annotations) (download) (as text)
Sat Jul 14 12:37:08 2001 UTC (18 years, 4 months ago) by poptix
Branch: MAIN
CVS Tags: eggdrop1_6_6
Changes since 1.58: +2 -2 lines
File MIME type: text/x-chdr

Cosmetic TCL fixes, plus TCL threaded info, primarily ITE's patch.

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