/[cvs]/eggdrop1.4/src/cmds.c
ViewVC logotype

Annotation of /eggdrop1.4/src/cmds.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.7 - (hide annotations) (download) (as text)
Tue Aug 17 22:26:16 1999 UTC (20 years, 4 months ago) by poptix
Branch: MAIN
Changes since 1.6: +6 -1 lines
File MIME type: text/x-chdr
 Committing in .

 Modified Files: 	Makefile TODO doc/UPDATES1.3 src/cmds.c src/language.c
 	src/main.c src/mem.c src/misc.c src/modules.h src/patch.h
 	src/proto.h src/tclegg.h src/users.c
 	src/mod/channels.mod/userchan.c src/mod/filesys.mod/filesys.h

all of fabian's patches.

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