/[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.37 - (hide annotations) (download) (as text)
Sun Aug 6 14:51:38 2000 UTC (19 years, 4 months ago) by fabian
Branch: MAIN
Changes since 1.36: +2 -8 lines
File MIME type: text/x-chdr
Tothwolf's strftime2 patch

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