/[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.61 - (hide annotations) (download) (as text)
Thu Jul 26 17:04:33 2001 UTC (18 years, 4 months ago) by drummer
Branch: MAIN
Changes since 1.60: +39 -10 lines
File MIME type: text/x-chdr
added adns dir

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 drummer 1.61 * $Id: cmds.c,v 1.60 2001/07/24 14:19:19 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 drummer 1.61 int addrlen;
757 segfault 1.1
758     if (!par[0])
759     dprintf(idx, "Usage: +bot <handle> <address[:telnet-port[/relay-port]]> [host]\n");
760     else {
761     handle = newsplit(&par);
762     addr = newsplit(&par);
763     if (strlen(handle) > HANDLEN)
764     handle[HANDLEN] = 0; /* max len = XX .. for the moment :) */
765     if (get_user_by_handle(userlist, handle))
766     dprintf(idx, "Someone already exists by that name.\n");
767 fabian 1.6 else if (strchr(BADHANDCHARS, handle[0]) != NULL)
768 segfault 1.1 dprintf(idx, "You can't start a botnick with '%c'.\n", handle[0]);
769     else {
770     if (strlen(addr) > 60)
771     addr[60] = 0;
772     putlog(LOG_CMDS, "*", "#%s# +bot %s %s", dcc[idx].nick, handle, addr);
773     userlist = adduser(userlist, handle, "none", "-", USER_BOT);
774     u1 = get_user_by_handle(userlist, handle);
775     bi = user_malloc(sizeof(struct bot_addr));
776    
777 drummer 1.61 if (*addr == '[') {
778     addr++;
779     if ((q = strchr(addr, ']'))) {
780     addrlen = q - addr;
781     q++;
782     if (*q != ':')
783     q = 0;
784     } else
785     addrlen = strlen(addr);
786     } else {
787     if ((q = strchr(addr, ':')))
788     addrlen = q - addr;
789     else
790     addrlen = strlen(addr);
791     }
792 segfault 1.1 if (!q) {
793 drummer 1.61 bi->address = user_malloc(addrlen + 1);
794 segfault 1.1 strcpy(bi->address, addr);
795     bi->telnet_port = 3333;
796     bi->relay_port = 3333;
797     } else {
798 drummer 1.61 bi->address = user_malloc(addrlen + 1);
799     strncpyz(bi->address, addr, addrlen + 1);
800 segfault 1.1 p = q + 1;
801     bi->telnet_port = atoi(p);
802     q = strchr(p, '/');
803     if (!q) {
804     bi->relay_port = bi->telnet_port;
805     } else {
806     bi->relay_port = atoi(q + 1);
807     }
808     }
809     set_user(&USERENTRY_BOTADDR, u1, bi);
810     dprintf(idx, "Added bot '%s' with address '%s' and no password.\n",
811     handle, addr);
812     host = newsplit(&par);
813     if (host[0]) {
814     addhost_by_handle(handle, host);
815     } else if (!add_bot_hostmask(idx, handle))
816     dprintf(idx, "You'll want to add a hostmask if this bot will ever %s",
817     "be on any channels that I'm on.\n");
818     }
819     }
820     }
821    
822 fabian 1.27 static void cmd_chhandle(struct userrec *u, int idx, char *par)
823 segfault 1.1 {
824 fabian 1.2 char hand[HANDLEN + 1], newhand[HANDLEN + 1];
825 segfault 1.1 int i, atr = u ? u->flags : 0, atr2;
826     struct userrec *u2;
827    
828 guppy 1.45 strncpyz(hand, newsplit(&par), sizeof hand);
829     strncpyz(newhand, newsplit(&par), sizeof newhand);
830 fabian 1.2
831     if (!hand[0] || !newhand[0]) {
832 fabian 1.27 dprintf(idx, "Usage: chhandle <oldhandle> <newhandle>\n");
833 fabian 1.2 return;
834     }
835     for (i = 0; i < strlen(newhand); i++)
836     if ((newhand[i] <= 32) || (newhand[i] >= 127) || (newhand[i] == '@'))
837     newhand[i] = '?';
838 fabian 1.6 if (strchr(BADHANDCHARS, newhand[0]) != NULL)
839 fabian 1.2 dprintf(idx, "Bizarre quantum forces prevent nicknames from starting with %c\n",
840     newhand[0]);
841     else if (get_user_by_handle(userlist, newhand) &&
842 fabian 1.26 egg_strcasecmp(hand, newhand))
843 fabian 1.2 dprintf(idx, "Somebody is already using %s.\n", newhand);
844 segfault 1.1 else {
845 fabian 1.2 u2 = get_user_by_handle(userlist, hand);
846     atr2 = u2 ? u2->flags : 0;
847     if ((atr & USER_BOTMAST) && !(atr & USER_MASTER) &&
848     !(atr2 & USER_BOT))
849     dprintf(idx, "You can't change nick for non-bots.\n");
850     else if ((bot_flags(u2) & BOT_SHARE) && !(atr & USER_OWNER))
851     dprintf(idx, "You can't change shared bot's nick.\n");
852     else if ((atr2 & USER_OWNER) && !(atr & USER_OWNER) &&
853 fabian 1.26 egg_strcasecmp(dcc[idx].nick, hand))
854 fabian 1.2 dprintf(idx, "Can't change the bot owner's handle.\n");
855 fabian 1.26 else if (isowner(hand) && egg_strcasecmp(dcc[idx].nick, hand))
856 fabian 1.2 dprintf(idx, "Can't change the permanent bot owner's handle.\n");
857 fabian 1.26 else if (!egg_strcasecmp(newhand, botnetnick) && (!(atr2 & USER_BOT) ||
858 fabian 1.6 nextbot(hand) != -1))
859     dprintf(idx, "Hey! That's MY name!\n");
860 fabian 1.2 else if (change_handle(u2, newhand)) {
861 fabian 1.27 putlog(LOG_CMDS, "*", "#%s# chhandle %s %s", dcc[idx].nick,
862 fabian 1.2 hand, newhand);
863     dprintf(idx, "Changed.\n");
864     } else
865     dprintf(idx, "Failed.\n");
866 segfault 1.1 }
867     }
868    
869 fabian 1.27 static void cmd_handle(struct userrec *u, int idx, char *par)
870 segfault 1.1 {
871 fabian 1.27 char oldhandle[HANDLEN + 1], newhandle[HANDLEN + 1];
872 fabian 1.2 int i;
873    
874 guppy 1.45 strncpyz(newhandle, newsplit(&par), sizeof newhandle);
875 segfault 1.1
876 fabian 1.27 if (!newhandle[0]) {
877     dprintf(idx, "Usage: handle <new-handle>\n");
878 segfault 1.1 return;
879     }
880 fabian 1.27 for (i = 0; i < strlen(newhandle); i++)
881     if ((newhandle[i] <= 32) || (newhandle[i] >= 127) || (newhandle[i] == '@'))
882     newhandle[i] = '?';
883     if (strchr(BADHANDCHARS, newhandle[0]) != NULL) {
884     dprintf(idx, "Bizarre quantum forces prevent handle from starting with '%c'\n",
885     newhandle[0]);
886     } else if (get_user_by_handle(userlist, newhandle) &&
887     egg_strcasecmp(dcc[idx].nick, newhandle)) {
888     dprintf(idx, "Somebody is already using %s.\n", newhandle);
889     } else if (!egg_strcasecmp(newhandle, botnetnick)) {
890 fabian 1.2 dprintf(idx, "Hey! That's MY name!\n");
891 segfault 1.1 } else {
892 guppy 1.45 strncpyz(oldhandle, dcc[idx].nick, sizeof oldhandle);
893 fabian 1.27 if (change_handle(u, newhandle)) {
894     putlog(LOG_CMDS, "*", "#%s# handle %s", oldhandle, newhandle);
895 segfault 1.1 dprintf(idx, "Okay, changed.\n");
896     } else
897     dprintf(idx, "Failed.\n");
898     }
899     }
900    
901     static void cmd_chpass(struct userrec *u, int idx, char *par)
902     {
903     char *handle, *new;
904     int atr = u ? u->flags : 0, l;
905    
906     if (!par[0])
907     dprintf(idx, "Usage: chpass <handle> [password]\n");
908     else {
909     handle = newsplit(&par);
910     u = get_user_by_handle(userlist, handle);
911     if (!u)
912     dprintf(idx, "No such user.\n");
913     else if ((atr & USER_BOTMAST) && !(atr & USER_MASTER) &&
914     !(u->flags & USER_BOT))
915     dprintf(idx, "You can't change password for non-bots.\n");
916     else if ((bot_flags(u) & BOT_SHARE) && !(atr & USER_OWNER))
917     dprintf(idx, "You can't change shared bot's password.\n");
918     else if ((u->flags & USER_OWNER) && !(atr & USER_OWNER) &&
919 fabian 1.26 egg_strcasecmp(handle, dcc[idx].nick))
920 segfault 1.1 dprintf(idx, "Can't change the bot owner's password.\n");
921 fabian 1.26 else if (isowner(handle) && egg_strcasecmp(dcc[idx].nick, handle))
922 fabian 1.19 dprintf(idx, "Can't change the permanent bot owner's password.\n");
923 segfault 1.1 else if (!par[0]) {
924     putlog(LOG_CMDS, "*", "#%s# chpass %s [nothing]", dcc[idx].nick,
925     handle);
926     set_user(&USERENTRY_PASS, u, NULL);
927     dprintf(idx, "Removed password.\n");
928     } else {
929     l = strlen(new = newsplit(&par));
930     if (l > 16)
931     new[16] = 0;
932     if (l < 6)
933     dprintf(idx, "Please use at least 6 characters.\n");
934     else {
935     set_user(&USERENTRY_PASS, u, new);
936     putlog(LOG_CMDS, "*", "#%s# chpass %s [something]", dcc[idx].nick,
937     handle);
938     dprintf(idx, "Changed password.\n");
939     }
940     }
941     }
942     }
943    
944     static void cmd_chaddr(struct userrec *u, int idx, char *par)
945     {
946 guppy 1.51 int telnet_port = 3333, relay_port = 3333;
947 segfault 1.1 char *handle, *addr, *p, *q;
948     struct bot_addr *bi;
949     struct userrec *u1;
950 drummer 1.61 int addrlen;
951 segfault 1.1
952     if (!par[0]) {
953 guppy 1.51 dprintf(idx, "Usage: chaddr <botname> <address[:telnet-port[/relay-port]]>\n");
954 segfault 1.1 return;
955     }
956     handle = newsplit(&par);
957     addr = newsplit(&par);
958 fabian 1.6 if (strlen(addr) > UHOSTMAX)
959     addr[UHOSTMAX] = 0;
960 segfault 1.1 u1 = get_user_by_handle(userlist, handle);
961     if (!u1 || !(u1->flags & USER_BOT)) {
962     dprintf(idx, "Useful only for tandem bots.\n");
963     return;
964     }
965     if ((bot_flags(u1) & BOT_SHARE) && (!u || !u->flags & USER_OWNER)) {
966     dprintf(idx, "You can't change shared bot's address.\n");
967     return;
968     }
969     putlog(LOG_CMDS, "*", "#%s# chaddr %s %s", dcc[idx].nick, handle, addr);
970     dprintf(idx, "Changed bot's address.\n");
971 guppy 1.51
972     bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u1);
973     if (bi) {
974     telnet_port = bi->telnet_port;
975     relay_port = bi->relay_port;
976     }
977    
978 segfault 1.1 bi = user_malloc(sizeof(struct bot_addr));
979    
980 drummer 1.61 if (*addr == '[') {
981     addr++;
982     if ((q = strchr(addr, ']'))) {
983     addrlen = q - addr;
984     q++;
985     if (*q != ':')
986     q = 0;
987     } else
988     addrlen = strlen(addr);
989     } else {
990     if ((q = strchr(addr, ':')))
991     addrlen = q - addr;
992     else
993     addrlen = strlen(addr);
994     }
995 segfault 1.1 if (!q) {
996 drummer 1.61 bi->address = user_malloc(addrlen + 1);
997 segfault 1.1 strcpy(bi->address, addr);
998 guppy 1.51 bi->telnet_port = telnet_port;
999     bi->relay_port = relay_port;
1000 segfault 1.1 } else {
1001 drummer 1.61 bi->address = user_malloc(addrlen + 1);
1002     strncpyz(bi->address, addr, addrlen + 1);
1003 segfault 1.1 p = q + 1;
1004     bi->telnet_port = atoi(p);
1005     q = strchr(p, '/');
1006     if (!q) {
1007     bi->relay_port = bi->telnet_port;
1008     } else {
1009     bi->relay_port = atoi(q + 1);
1010     }
1011     }
1012     set_user(&USERENTRY_BOTADDR, u1, bi);
1013     }
1014    
1015     static void cmd_comment(struct userrec *u, int idx, char *par)
1016     {
1017     char *handle;
1018     struct userrec *u1;
1019    
1020     if (!par[0]) {
1021     dprintf(idx, "Usage: comment <handle> <newcomment>\n");
1022     return;
1023     }
1024     handle = newsplit(&par);
1025     u1 = get_user_by_handle(userlist, handle);
1026     if (!u1) {
1027     dprintf(idx, "No such user!\n");
1028     return;
1029     }
1030     if ((u1->flags & USER_OWNER) && !(u && (u->flags & USER_OWNER)) &&
1031 fabian 1.26 egg_strcasecmp(handle, dcc[idx].nick)) {
1032 segfault 1.1 dprintf(idx, "Can't change comment on the bot owner.\n");
1033     return;
1034     }
1035     putlog(LOG_CMDS, "*", "#%s# comment %s %s", dcc[idx].nick, handle, par);
1036 fabian 1.26 if (!egg_strcasecmp(par, "none")) {
1037 segfault 1.1 dprintf(idx, "Okay, comment blanked.\n");
1038     set_user(&USERENTRY_COMMENT, u1, NULL);
1039     return;
1040     }
1041     dprintf(idx, "Changed comment.\n");
1042     set_user(&USERENTRY_COMMENT, u1, par);
1043     }
1044    
1045     static void cmd_restart(struct userrec *u, int idx, char *par)
1046     {
1047     putlog(LOG_CMDS, "*", "#%s# restart", dcc[idx].nick);
1048     if (!backgrd) {
1049     dprintf(idx, "You can not .restart a bot when running -n (due to tcl)\n");
1050     return;
1051     }
1052     dprintf(idx, "Restarting.\n");
1053     if (make_userfile) {
1054     putlog(LOG_MISC, "*",
1055     "Uh, guess you don't need to create a new userfile.");
1056     make_userfile = 0;
1057     }
1058     write_userfile(-1);
1059     putlog(LOG_MISC, "*", "Restarting ...");
1060     wipe_timers(interp, &utimer);
1061     wipe_timers(interp, &timer);
1062     do_restart = idx;
1063     }
1064    
1065     static void cmd_rehash(struct userrec *u, int idx, char *par)
1066     {
1067     putlog(LOG_CMDS, "*", "#%s# rehash", dcc[idx].nick);
1068     dprintf(idx, "Rehashing.\n");
1069     if (make_userfile) {
1070     putlog(LOG_MISC, "*",
1071     "Uh, guess you don't need to create a new userfile.");
1072     make_userfile = 0;
1073     }
1074     write_userfile(-1);
1075     putlog(LOG_MISC, "*", "Rehashing ...");
1076     do_restart = -2;
1077     }
1078    
1079     static void cmd_reload(struct userrec *u, int idx, char *par)
1080     {
1081     putlog(LOG_CMDS, "*", "#%s# reload", dcc[idx].nick);
1082     dprintf(idx, "Reloading user file...\n");
1083     reload();
1084     }
1085    
1086 fabian 1.22 /* NOTE: This gets replaced in the server mod, with a version that handles
1087     * the server disconnect better.
1088     */
1089 segfault 1.1 void cmd_die(struct userrec *u, int idx, char *par)
1090     {
1091     char s[1024];
1092    
1093     putlog(LOG_CMDS, "*", "#%s# die %s", dcc[idx].nick, par);
1094     if (par[0]) {
1095     simple_sprintf(s, "BOT SHUTDOWN (%s: %s)", dcc[idx].nick, par);
1096     } else {
1097     simple_sprintf(s, "BOT SHUTDOWN (authorized by %s)", dcc[idx].nick);
1098     }
1099     chatout("*** %s\n", s);
1100     botnet_send_chat(-1, botnetnick, s);
1101     botnet_send_bye();
1102     write_userfile(-1);
1103     simple_sprintf(s, "DIE BY %s!%s (%s)", dcc[idx].nick,
1104     dcc[idx].host, par[0] ? par : "request");
1105     fatal(s, 0);
1106     }
1107    
1108     static void cmd_debug(struct userrec *u, int idx, char *par)
1109     {
1110 fabian 1.26 if (!egg_strcasecmp(par, "help")) {
1111 segfault 1.1 putlog(LOG_CMDS, "*", "#%s# debug help", dcc[idx].nick);
1112     debug_help(idx);
1113     } else {
1114     putlog(LOG_CMDS, "*", "#%s# debug", dcc[idx].nick);
1115     debug_mem_to_dcc(idx);
1116     }
1117     }
1118    
1119     static void cmd_simul(struct userrec *u, int idx, char *par)
1120     {
1121     char *nick;
1122     int i, ok = 0;
1123    
1124     nick = newsplit(&par);
1125     if (!par[0]) {
1126 johoho 1.32 dprintf(idx, "Usage: simul <hand> <text>\n");
1127 segfault 1.1 return;
1128     }
1129     if (isowner(nick)) {
1130     dprintf(idx, "Unable to '.simul' permanent owners.\n");
1131     return;
1132     }
1133     for (i = 0; i < dcc_total; i++)
1134 fabian 1.26 if (!egg_strcasecmp(nick, dcc[i].nick) && !ok &&
1135 segfault 1.1 (dcc[i].type->flags & DCT_SIMUL)) {
1136     putlog(LOG_CMDS, "*", "#%s# simul %s %s", dcc[idx].nick, nick, par);
1137     if (dcc[i].type && dcc[i].type->activity) {
1138     dcc[i].type->activity(i, par, strlen(par));
1139     ok = 1;
1140     }
1141     }
1142     if (!ok)
1143     dprintf(idx, "No such user on the party line.\n");
1144     }
1145    
1146     static void cmd_link(struct userrec *u, int idx, char *par)
1147     {
1148     char *s;
1149     int i;
1150    
1151     if (!par[0]) {
1152     dprintf(idx, "Usage: link [some-bot] <new-bot>\n");
1153     return;
1154     }
1155     putlog(LOG_CMDS, "*", "#%s# link %s", dcc[idx].nick, par);
1156     s = newsplit(&par);
1157 fabian 1.26 if (!par[0] || !egg_strcasecmp(par, botnetnick))
1158 segfault 1.1 botlink(dcc[idx].nick, idx, s);
1159     else {
1160     char x[40];
1161    
1162     i = nextbot(s);
1163     if (i < 0) {
1164     dprintf(idx, "No such bot online.\n");
1165     return;
1166     }
1167     simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1168     botnet_send_link(i, x, s, par);
1169     }
1170     }
1171    
1172     static void cmd_unlink(struct userrec *u, int idx, char *par)
1173     {
1174     int i;
1175     char *bot;
1176    
1177     if (!par[0]) {
1178     dprintf(idx, "Usage: unlink <bot> [reason]\n");
1179     return;
1180     }
1181     putlog(LOG_CMDS, "*", "#%s# unlink %s", dcc[idx].nick, par);
1182     bot = newsplit(&par);
1183     i = nextbot(bot);
1184     if (i < 0) {
1185     botunlink(idx, bot, par);
1186     return;
1187     }
1188 guppy 1.49 /* If we're directly connected to that bot, just do it
1189 fabian 1.22 * (is nike gunna sue?)
1190     */
1191 fabian 1.26 if (!egg_strcasecmp(dcc[i].nick, bot))
1192 segfault 1.1 botunlink(idx, bot, par);
1193     else {
1194     char x[40];
1195    
1196     simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1197     botnet_send_unlink(i, x, lastbot(bot), bot, par);
1198     }
1199     }
1200    
1201     static void cmd_relay(struct userrec *u, int idx, char *par)
1202     {
1203     if (!par[0]) {
1204     dprintf(idx, "Usage: relay <bot>\n");
1205     return;
1206     }
1207     putlog(LOG_CMDS, "*", "#%s# relay %s", dcc[idx].nick, par);
1208     tandem_relay(idx, par, 0);
1209     }
1210    
1211     static void cmd_save(struct userrec *u, int idx, char *par)
1212     {
1213     putlog(LOG_CMDS, "*", "#%s# save", dcc[idx].nick);
1214     dprintf(idx, "Saving user file...\n");
1215     write_userfile(-1);
1216     }
1217    
1218     static void cmd_backup(struct userrec *u, int idx, char *par)
1219     {
1220     putlog(LOG_CMDS, "*", "#%s# backup", dcc[idx].nick);
1221 guppy 1.60 dprintf(idx, "Backing up the channel & user file...\n");
1222     call_hook(HOOK_BACKUP);
1223 segfault 1.1 }
1224    
1225     static void cmd_trace(struct userrec *u, int idx, char *par)
1226     {
1227     int i;
1228     char x[NOTENAMELEN + 11], y[11];
1229    
1230     if (!par[0]) {
1231     dprintf(idx, "Usage: trace <botname>\n");
1232     return;
1233     }
1234 fabian 1.26 if (!egg_strcasecmp(par, botnetnick)) {
1235 segfault 1.1 dprintf(idx, "That's me! Hiya! :)\n");
1236     return;
1237     }
1238     i = nextbot(par);
1239     if (i < 0) {
1240     dprintf(idx, "Unreachable bot.\n");
1241     return;
1242     }
1243     putlog(LOG_CMDS, "*", "#%s# trace %s", dcc[idx].nick, par);
1244     simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1245     simple_sprintf(y, ":%d", now);
1246     botnet_send_trace(i, x, par, y);
1247     }
1248    
1249     static void cmd_binds(struct userrec *u, int idx, char *par)
1250     {
1251     putlog(LOG_CMDS, "*", "#%s# binds %s", dcc[idx].nick, par);
1252     tell_binds(idx, par);
1253     }
1254    
1255     static void cmd_banner(struct userrec *u, int idx, char *par)
1256     {
1257     char s[1024];
1258     int i;
1259    
1260     if (!par[0]) {
1261     dprintf(idx, "Usage: banner <message>\n");
1262     return;
1263     }
1264 guppy 1.50 simple_sprintf(s, "\007### Botwide: [%s] %s\n", dcc[idx].nick, par);
1265 segfault 1.1 for (i = 0; i < dcc_total; i++)
1266     if (dcc[i].type->flags & DCT_MASTER)
1267     dprintf(i, "%s", s);
1268     }
1269    
1270 fabian 1.22 /* After messing with someone's user flags, make sure the dcc-chat flags
1271     * are set correctly.
1272     */
1273 segfault 1.1 int check_dcc_attrs(struct userrec *u, int oatr)
1274     {
1275     int i, stat;
1276    
1277     if (!u)
1278     return 0;
1279 fabian 1.22 /* Make sure default owners are +n */
1280 poptix 1.57 if (isowner(u->handle)) {
1281     u->flags = sanity_check(u->flags | USER_OWNER);
1282 segfault 1.1 }
1283     for (i = 0; i < dcc_total; i++) {
1284     if ((dcc[i].type->flags & DCT_MASTER) &&
1285 fabian 1.26 (!egg_strcasecmp(u->handle, dcc[i].nick))) {
1286 segfault 1.1 stat = dcc[i].status;
1287     if ((dcc[i].type == &DCC_CHAT) &&
1288     ((u->flags & (USER_OP | USER_MASTER | USER_OWNER |
1289     USER_BOTMAST))
1290     != (oatr & (USER_OP | USER_MASTER | USER_OWNER |
1291     USER_BOTMAST)))) {
1292     botnet_send_join_idx(i, -1);
1293     }
1294     if ((oatr & USER_MASTER) && !(u->flags & USER_MASTER)) {
1295 fabian 1.22 struct flag_record fr = {FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
1296 segfault 1.1
1297     dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_RAW |
1298     LOG_FILES | LOG_LEV1 | LOG_LEV2 |
1299     LOG_LEV3 | LOG_LEV4 | LOG_LEV5 |
1300     LOG_LEV6 | LOG_LEV7 | LOG_LEV8 |
1301     LOG_WALL | LOG_DEBUG);
1302     get_user_flagrec(u, &fr, NULL);
1303     if (!chan_master(fr))
1304     dcc[i].u.chat->con_flags |= (LOG_MISC | LOG_CMDS);
1305     dprintf(i, "*** POOF! ***\n");
1306     dprintf(i, "You are no longer a master on this bot.\n");
1307     }
1308     if (!(oatr & USER_MASTER) && (u->flags & USER_MASTER)) {
1309     dcc[i].u.chat->con_flags |= conmask;
1310     dprintf(i, "*** POOF! ***\n");
1311     dprintf(i, "You are now a master on this bot.\n");
1312     }
1313     if (!(oatr & USER_BOTMAST) && (u->flags & USER_BOTMAST)) {
1314     dprintf(i, "### POOF! ###\n");
1315     dprintf(i, "You are now a botnet master on this bot.\n");
1316     }
1317     if ((oatr & USER_BOTMAST) && !(u->flags & USER_BOTMAST)) {
1318     dprintf(i, "### POOF! ###\n");
1319     dprintf(i, "You are no longer a botnet master on this bot.\n");
1320     }
1321     if (!(oatr & USER_OWNER) && (u->flags & USER_OWNER)) {
1322     dprintf(i, "@@@ POOF! @@@\n");
1323     dprintf(i, "You are now an OWNER of this bot.\n");
1324     }
1325     if ((oatr & USER_OWNER) && !(u->flags & USER_OWNER)) {
1326     dprintf(i, "@@@ POOF! @@@\n");
1327     dprintf(i, "You are no longer an owner of this bot.\n");
1328     }
1329     if ((stat & STAT_PARTY) && (u->flags & USER_OP))
1330     stat &= ~STAT_PARTY;
1331     if (!(stat & STAT_PARTY) && !(u->flags & USER_OP) &&
1332     !(u->flags & USER_MASTER))
1333     stat |= STAT_PARTY;
1334     if ((stat & STAT_CHAT) && !(u->flags & USER_PARTY) &&
1335     !(u->flags & USER_MASTER) &&
1336     (!(u->flags & USER_OP) || require_p))
1337     stat &= ~STAT_CHAT;
1338     if ((dcc[i].type->flags & DCT_FILES) && !(stat & STAT_CHAT) &&
1339     ((u->flags & USER_MASTER) || (u->flags & USER_PARTY) ||
1340     ((u->flags & USER_OP) && !require_p)))
1341     stat |= STAT_CHAT;
1342     dcc[i].status = stat;
1343 fabian 1.22 /* Check if they no longer have access to wherever they are.
1344 guppy 1.49 *
1345 fabian 1.22 * NOTE: DON'T kick someone off the party line just cuz they lost +p
1346     * (pinvite script removes +p after 5 mins automatically)
1347     */
1348 segfault 1.1 if ((dcc[i].type->flags & DCT_FILES) && !(u->flags & USER_XFER) &&
1349     !(u->flags & USER_MASTER)) {
1350     dprintf(i, "-+- POOF! -+-\n");
1351     dprintf(i, "You no longer have file area access.\n\n");
1352     putlog(LOG_MISC, "*", "DCC user [%s]%s removed from file system",
1353     dcc[i].nick, dcc[i].host);
1354     if (dcc[i].status & STAT_CHAT) {
1355     struct chat_info *ci;
1356    
1357     ci = dcc[i].u.file->chat;
1358     nfree(dcc[i].u.file);
1359     dcc[i].u.chat = ci;
1360     dcc[i].status &= (~STAT_CHAT);
1361     dcc[i].type = &DCC_CHAT;
1362     if (dcc[i].u.chat->channel >= 0) {
1363     chanout_but(-1, dcc[i].u.chat->channel,
1364     "*** %s has returned.\n", dcc[i].nick);
1365     if (dcc[i].u.chat->channel < 100000)
1366     botnet_send_join_idx(i, -1);
1367     }
1368     } else {
1369     killsock(dcc[i].sock);
1370 fabian 1.16 lostdcc(i);
1371 segfault 1.1 }
1372     }
1373     }
1374 fabian 1.26 if (dcc[i].type == &DCC_BOT && !egg_strcasecmp(u->handle, dcc[i].nick)) {
1375 segfault 1.1 if ((dcc[i].status & STAT_LEAF) && !(u->flags & BOT_LEAF))
1376     dcc[i].status &= ~(STAT_LEAF | STAT_WARNED);
1377     if (!(dcc[i].status & STAT_LEAF) && (u->flags & BOT_LEAF))
1378     dcc[i].status |= STAT_LEAF;
1379     }
1380     }
1381     return u->flags;
1382     }
1383    
1384     int check_dcc_chanattrs(struct userrec *u, char *chname, int chflags,
1385     int ochatr)
1386     {
1387     int i, found = 0, atr = u ? u->flags : 0;
1388     struct chanset_t *chan;
1389    
1390     if (!u)
1391     return 0;
1392     for (i = 0; i < dcc_total; i++) {
1393     if ((dcc[i].type->flags & DCT_MASTER) &&
1394 fabian 1.26 !egg_strcasecmp(u->handle, dcc[i].nick)) {
1395 segfault 1.1 if ((dcc[i].type == &DCC_CHAT) &&
1396     ((chflags & (USER_OP | USER_MASTER | USER_OWNER))
1397     != (ochatr & (USER_OP | USER_MASTER | USER_OWNER))))
1398     botnet_send_join_idx(i, -1);
1399     if ((ochatr & USER_MASTER) && !(chflags & USER_MASTER)) {
1400     if (!(atr & USER_MASTER))
1401     dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS);
1402     dprintf(i, "*** POOF! ***\n");
1403     dprintf(i, "You are no longer a master on %s.\n", chname);
1404     }
1405     if (!(ochatr & USER_MASTER) && (chflags & USER_MASTER)) {
1406     dcc[i].u.chat->con_flags |= conmask;
1407     if (!(atr & USER_MASTER))
1408     dcc[i].u.chat->con_flags &=
1409     ~(LOG_LEV1 | LOG_LEV2 | LOG_LEV3 | LOG_LEV4 |
1410     LOG_LEV5 | LOG_LEV6 | LOG_LEV7 | LOG_LEV8 |
1411     LOG_RAW | LOG_DEBUG | LOG_WALL | LOG_FILES | LOG_SRVOUT);
1412     dprintf(i, "*** POOF! ***\n");
1413     dprintf(i, "You are now a master on %s.\n", chname);
1414     }
1415     if (!(ochatr & USER_OWNER) && (chflags & USER_OWNER)) {
1416     dprintf(i, "@@@ POOF! @@@\n");
1417     dprintf(i, "You are now an OWNER of %s.\n", chname);
1418     }
1419     if ((ochatr & USER_OWNER) && !(chflags & USER_OWNER)) {
1420     dprintf(i, "@@@ POOF! @@@\n");
1421     dprintf(i, "You are no longer an owner of %s.\n", chname);
1422     }
1423     if (((ochatr & (USER_OP | USER_MASTER | USER_OWNER)) &&
1424     (!(chflags & (USER_OP | USER_MASTER | USER_OWNER)))) ||
1425     ((chflags & (USER_OP | USER_MASTER | USER_OWNER)) &&
1426     (!(ochatr & (USER_OP | USER_MASTER | USER_OWNER))))) {
1427 fabian 1.11 struct flag_record fr = {FR_CHAN, 0, 0, 0, 0, 0};
1428 segfault 1.1
1429 guppy 1.56 for (chan = chanset; chan && !found; chan = chan->next) {
1430 fabian 1.8 get_user_flagrec(u, &fr, chan->dname);
1431 segfault 1.1 if (fr.chan & (USER_OP | USER_MASTER | USER_OWNER))
1432     found = 1;
1433     }
1434     if (!chan)
1435     chan = chanset;
1436     if (chan)
1437 fabian 1.8 strcpy(dcc[i].u.chat->con_chan, chan->dname);
1438 segfault 1.1 else
1439     strcpy(dcc[i].u.chat->con_chan, "*");
1440     }
1441     }
1442     }
1443     return chflags;
1444     }
1445    
1446     static void cmd_chattr(struct userrec *u, int idx, char *par)
1447     {
1448 fabian 1.6 char *hand, *arg = NULL, *tmpchg = NULL, *chg = NULL, work[1024];
1449 segfault 1.1 struct chanset_t *chan = NULL;
1450     struct userrec *u2;
1451 fabian 1.2 struct flag_record pls = {0, 0, 0, 0, 0, 0},
1452     mns = {0, 0, 0, 0, 0, 0},
1453     user = {0, 0, 0, 0, 0, 0};
1454 segfault 1.1 module_entry *me;
1455     int fl = -1, of = 0, ocf = 0;
1456    
1457     if (!par[0]) {
1458     dprintf(idx, "Usage: chattr <handle> [changes] [channel]\n");
1459     return;
1460     }
1461     hand = newsplit(&par);
1462     u2 = get_user_by_handle(userlist, hand);
1463 fabian 1.6 if (!u2) {
1464 segfault 1.1 dprintf(idx, "No such user!\n");
1465     return;
1466     }
1467 fabian 1.6
1468     /* Parse args */
1469     if (par[0]) {
1470 fabian 1.8 arg = newsplit(&par);
1471 fabian 1.6 if (par[0]) {
1472     /* .chattr <handle> <changes> <channel> */
1473     chg = arg;
1474 fabian 1.8 arg = newsplit(&par);
1475     chan = findchan_by_dname(arg);
1476 fabian 1.6 } else {
1477 fabian 1.8 chan = findchan_by_dname(arg);
1478 fabian 1.22 /* Consider modeless channels, starting with '+' */
1479 fabian 1.6 if (!(arg[0] == '+' && chan) &&
1480     !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
1481     /* .chattr <handle> <changes> */
1482     chg = arg;
1483     chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
1484     arg = NULL;
1485     }
1486     /* .chattr <handle> <channel>: nothing to do... */
1487     }
1488     }
1489     /* arg: pointer to channel name, NULL if none specified
1490     * chan: pointer to channel structure, NULL if none found or none specified
1491     * chg: pointer to changes, NULL if none specified
1492     */
1493 fabian 1.13 Assert(!(!arg && chan));
1494 fabian 1.6 if (arg && !chan) {
1495     dprintf(idx, "No channel record for %s.\n", arg);
1496     return;
1497 segfault 1.1 }
1498 fabian 1.6 if (chg) {
1499     if (!arg && strpbrk(chg, "&|")) {
1500     /* .chattr <handle> *[&|]*: use console channel if found... */
1501     if (!strcmp ((arg = dcc[idx].u.chat->con_chan), "*"))
1502     arg = NULL;
1503     else
1504 fabian 1.8 chan = findchan_by_dname(arg);
1505 fabian 1.6 if (arg && !chan) {
1506     dprintf (idx, "Invalid console channel %s.\n", arg);
1507     return;
1508     }
1509     } else if (arg && !strpbrk(chg, "&|")) {
1510     tmpchg = nmalloc(strlen(chg) + 2);
1511 fabian 1.11 strcpy(tmpchg, "|");
1512     strcat(tmpchg, chg);
1513 fabian 1.6 chg = tmpchg;
1514 segfault 1.1 }
1515     }
1516 fabian 1.6 par = arg;
1517 segfault 1.1 user.match = FR_GLOBAL;
1518     if (chan)
1519     user.match |= FR_CHAN;
1520 fabian 1.8 get_user_flagrec(u, &user, chan ? chan->dname : 0);
1521 segfault 1.1 if (!chan && !glob_botmast(user)) {
1522     dprintf(idx, "You do not have Bot Master privileges.\n");
1523 fabian 1.6 if (tmpchg)
1524     nfree(tmpchg);
1525 segfault 1.1 return;
1526     }
1527     if (chan && !glob_master(user) && !chan_master(user)) {
1528     dprintf(idx, "You do not have channel master privileges for channel %s\n",
1529     par);
1530 fabian 1.6 if (tmpchg)
1531     nfree(tmpchg);
1532 segfault 1.1 return;
1533     }
1534     user.match &= fl;
1535     if (chg) {
1536     pls.match = user.match;
1537     break_down_flags(chg, &pls, &mns);
1538 fabian 1.22 /* No-one can change these flags on-the-fly */
1539 fabian 1.6 pls.global &= ~(USER_BOT);
1540     mns.global &= ~(USER_BOT);
1541 segfault 1.1
1542     if (chan) {
1543     pls.chan &= ~(BOT_SHARE);
1544     mns.chan &= ~(BOT_SHARE);
1545     }
1546     if (!glob_owner(user)) {
1547 fabian 1.6 pls.global &= ~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1548     mns.global &= ~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1549 segfault 1.1
1550     if (chan) {
1551     pls.chan &= ~USER_OWNER;
1552     mns.chan &= ~USER_OWNER;
1553     }
1554     if (!glob_master(user)) {
1555 fabian 1.6 pls.global &= USER_PARTY | USER_XFER;
1556     mns.global &= USER_PARTY | USER_XFER;
1557 segfault 1.1
1558     if (!glob_botmast(user)) {
1559     pls.global = 0;
1560     mns.global = 0;
1561     }
1562     }
1563     }
1564     if (chan && !chan_owner(user) && !glob_owner(user)) {
1565     pls.chan &= ~USER_MASTER;
1566     mns.chan &= ~USER_MASTER;
1567     if (!chan_master(user) && !glob_master(user)) {
1568     pls.chan = 0;
1569     mns.chan = 0;
1570     }
1571     }
1572     get_user_flagrec(u2, &user, par);
1573     if (user.match & FR_GLOBAL) {
1574     of = user.global;
1575     user.global = sanity_check((user.global |pls.global) &~mns.global);
1576    
1577     user.udef_global = (user.udef_global | pls.udef_global)
1578     & ~mns.udef_global;
1579     }
1580     if (chan) {
1581     ocf = user.chan;
1582     user.chan = chan_sanity_check((user.chan | pls.chan) & ~mns.chan,
1583     user.global);
1584    
1585     user.udef_chan = (user.udef_chan | pls.udef_chan) & ~mns.udef_chan;
1586     }
1587     set_user_flagrec(u2, &user, par);
1588     }
1589     if (chan)
1590     putlog(LOG_CMDS, "*", "#%s# (%s) chattr %s %s",
1591 fabian 1.8 dcc[idx].nick, chan ? chan->dname : "*", hand, chg ? chg : "");
1592 segfault 1.1 else
1593     putlog(LOG_CMDS, "*", "#%s# chattr %s %s", dcc[idx].nick, hand,
1594     chg ? chg : "");
1595 fabian 1.22 /* Get current flags and display them */
1596 segfault 1.1 if (user.match & FR_GLOBAL) {
1597     user.match = FR_GLOBAL;
1598     if (chg)
1599     check_dcc_attrs(u2, of);
1600     get_user_flagrec(u2, &user, NULL);
1601     build_flags(work, &user, NULL);
1602     if (work[0] != '-')
1603     dprintf(idx, "Global flags for %s are now +%s\n", hand, work);
1604     else
1605     dprintf(idx, "No global flags for %s.\n", hand);
1606     }
1607     if (chan) {
1608     user.match = FR_CHAN;
1609     get_user_flagrec(u2, &user, par);
1610     user.chan &= ~BOT_SHARE;
1611     if (chg)
1612 fabian 1.8 check_dcc_chanattrs(u2, chan->dname, user.chan, ocf);
1613 segfault 1.1 build_flags(work, &user, NULL);
1614     if (work[0] != '-')
1615     dprintf(idx, "Channel flags for %s on %s are now +%s\n", hand,
1616 fabian 1.8 chan->dname, work);
1617 segfault 1.1 else
1618 fabian 1.8 dprintf(idx, "No flags for %s on %s.\n", hand, chan->dname);
1619 fabian 1.6 if (chg && (me = module_find("irc", 0, 0))) {
1620 segfault 1.1 Function *func = me->funcs;
1621    
1622     if (chan)
1623 fabian 1.2 (func[IRC_RECHECK_CHANNEL]) (chan, 0);
1624 segfault 1.1 }
1625     }
1626 fabian 1.6 if (tmpchg)
1627     nfree(tmpchg);
1628 segfault 1.1 }
1629    
1630     static void cmd_botattr(struct userrec *u, int idx, char *par)
1631     {
1632 fabian 1.6 char *hand, *chg = NULL, *arg = NULL, *tmpchg = NULL, work[1024];
1633 segfault 1.1 struct chanset_t *chan = NULL;
1634     struct userrec *u2;
1635 fabian 1.8 struct flag_record pls = {0, 0, 0, 0, 0, 0},
1636     mns = {0, 0, 0, 0, 0, 0},
1637     user = {0, 0, 0, 0, 0, 0};
1638 segfault 1.1 int idx2;
1639    
1640     if (!par[0]) {
1641     dprintf(idx, "Usage: botattr <handle> [changes] [channel]\n");
1642     return;
1643     }
1644     hand = newsplit(&par);
1645     u2 = get_user_by_handle(userlist, hand);
1646 fabian 1.6 if (!u2 || !(u2->flags & USER_BOT)) {
1647 segfault 1.1 dprintf(idx, "No such bot!\n");
1648     return;
1649     }
1650     for (idx2 = 0; idx2 < dcc_total; idx2++)
1651 fabian 1.33 if (dcc[idx2].type != &DCC_RELAY && dcc[idx2].type != &DCC_FORK_BOT &&
1652     !egg_strcasecmp(dcc[idx2].nick, hand))
1653 segfault 1.1 break;
1654     if (idx2 != dcc_total) {
1655 fabian 1.6 dprintf(idx, "You may not change the attributes of a directly linked bot.\n");
1656 segfault 1.1 return;
1657     }
1658 fabian 1.6 /* Parse args */
1659     if (par[0]) {
1660 fabian 1.10 arg = newsplit(&par);
1661 fabian 1.6 if (par[0]) {
1662     /* .botattr <handle> <changes> <channel> */
1663     chg = arg;
1664 fabian 1.10 arg = newsplit(&par);
1665 fabian 1.8 chan = findchan_by_dname(arg);
1666 fabian 1.6 } else {
1667 fabian 1.8 chan = findchan_by_dname(arg);
1668 fabian 1.22 /* Consider modeless channels, starting with '+' */
1669 fabian 1.6 if (!(arg[0] == '+' && chan) &&
1670     !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
1671     /* .botattr <handle> <changes> */
1672     chg = arg;
1673     chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
1674     arg = NULL;
1675     }
1676     /* .botattr <handle> <channel>: nothing to do... */
1677     }
1678     }
1679     /* arg: pointer to channel name, NULL if none specified
1680     * chan: pointer to channel structure, NULL if none found or none specified
1681     * chg: pointer to changes, NULL if none specified
1682     */
1683 fabian 1.13 Assert(!(!arg && chan));
1684 fabian 1.6 if (arg && !chan) {
1685     dprintf(idx, "No channel record for %s.\n", arg);
1686     return;
1687 segfault 1.1 }
1688 fabian 1.6 if (chg) {
1689     if (!arg && strpbrk(chg, "&|")) {
1690     /* botattr <handle> *[&|]*: use c