/[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.3 - (hide annotations) (download) (as text)
Tue Jul 13 14:26:11 1999 UTC (20 years, 5 months ago) by poptix
Branch: MAIN
Changes since 1.2: +10 -10 lines
File MIME type: text/x-chdr
           Fixed some buffer overflows, fixed a duplication, moved text
     to language file, fixed some cosmetic stuff.

				-poptix

 Modified Files:
 	doc/UPDATES1.3 language/core.english.lang src/botcmd.c
 	src/cmds.c src/patch.h

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     tellhelp(idx, par, &fr, 0);
446     } else {
447     putlog(LOG_CMDS, "*", "#%s# help", dcc[idx].nick);
448     if (glob_op(fr) || glob_botmast(fr) || chan_op(fr))
449     tellhelp(idx, "help", &fr, 0);
450     else
451     tellhelp(idx, "helpparty", &fr, 0);
452     }
453     }
454    
455     static void cmd_addlog(struct userrec *u, int idx, char *par)
456     {
457     if (!par[0]) {
458     dprintf(idx, "Usage: addlog <message>\n");
459     return;
460     }
461     dprintf(idx, "Placed entry in the log file.\n");
462     putlog(LOG_MISC, "*", "%s: %s", dcc[idx].nick, par);
463     }
464    
465     static void cmd_who(struct userrec *u, int idx, char *par)
466     {
467     int i;
468    
469     if (par[0]) {
470     if (dcc[idx].u.chat->channel < 0) {
471     dprintf(idx, "You have chat turned off.\n");
472     return;
473     }
474     putlog(LOG_CMDS, "*", "#%s# who %s", dcc[idx].nick, par);
475     if (!strcasecmp(par, botnetnick))
476     tell_who(u, idx, dcc[idx].u.chat->channel);
477     else {
478     i = nextbot(par);
479     if (i < 0) {
480     dprintf(idx, "That bot isn't connected.\n");
481     } else if (dcc[idx].u.chat->channel > 99999)
482     dprintf(idx, "You are on a local channel\n");
483     else {
484     char s[40];
485    
486     simple_sprintf(s, "%d:%s@%s", dcc[idx].sock,
487     dcc[idx].nick, botnetnick);
488     botnet_send_who(i, s, par, dcc[idx].u.chat->channel);
489     }
490     }
491     } else {
492     putlog(LOG_CMDS, "*", "#%s# who", dcc[idx].nick);
493     if (dcc[idx].u.chat->channel < 0)
494     tell_who(u, idx, 0);
495     else
496     tell_who(u, idx, dcc[idx].u.chat->channel);
497     }
498     }
499    
500     static void cmd_whois(struct userrec *u, int idx, char *par)
501     {
502     if (!par[0]) {
503     dprintf(idx, "Usage: whois <handle>\n");
504     return;
505     }
506     putlog(LOG_CMDS, "*", "#%s# whois %s", dcc[idx].nick, par);
507     tell_user_ident(idx, par, u ? (u->flags & USER_MASTER) : 0);
508     }
509    
510     static void cmd_match(struct userrec *u, int idx, char *par)
511     {
512     int start = 1, limit = 20;
513     char *s, *s1, *chname;
514    
515     if (!par[0]) {
516     dprintf(idx, "Usage: match <nick/host> [[skip] count]\n");
517     return;
518     }
519     putlog(LOG_CMDS, "*", "#%s# match %s", dcc[idx].nick, par);
520     s = newsplit(&par);
521     if (strchr(CHANMETA, par[0]) != NULL)
522     chname = newsplit(&par);
523     else
524     chname = "";
525     if (atoi(par) > 0) {
526     s1 = newsplit(&par);
527     if (atoi(par) > 0) {
528     start = atoi(s1);
529     limit = atoi(par);
530     } else
531     limit = atoi(s1);
532     }
533     tell_users_match(idx, s, start, limit, u ? (u->flags & USER_MASTER) : 0,
534     chname);
535     }
536    
537     static void cmd_uptime(struct userrec *u, int idx, char *par)
538     {
539     putlog(LOG_CMDS, "*", "#%s# uptime", dcc[idx].nick);
540     tell_verbose_uptime(idx, 1);
541     }
542    
543     static void cmd_status(struct userrec *u, int idx, char *par)
544     {
545     int atr = u ? u->flags : 0;
546    
547     if (!strcasecmp(par, "all")) {
548     if (!(atr & USER_MASTER)) {
549     dprintf(idx, "You do not have Bot Master privileges.\n");
550     return;
551     }
552     putlog(LOG_CMDS, "*", "#%s# status all", dcc[idx].nick);
553     tell_verbose_status(idx, 1);
554     tell_mem_status_dcc(idx);
555     dprintf(idx, "\n");
556     tell_settings(idx);
557     do_module_report(idx, 1, NULL);
558     } else {
559     putlog(LOG_CMDS, "*", "#%s# status", dcc[idx].nick);
560     tell_verbose_status(idx, 1);
561     tell_mem_status_dcc(idx);
562     do_module_report(idx, 0, NULL);
563     }
564     }
565    
566     static void cmd_dccstat(struct userrec *u, int idx, char *par)
567     {
568     putlog(LOG_CMDS, "*", "#%s# dccstat", dcc[idx].nick);
569     tell_dcc(idx);
570     }
571    
572     static void cmd_boot(struct userrec *u, int idx, char *par)
573     {
574     int i, files = 0, ok = 0;
575     char *who;
576     struct userrec *u2;
577    
578     if (!par[0]) {
579     dprintf(idx, "Usage: boot nick[@bot]\n");
580     return;
581     }
582     who = newsplit(&par);
583     if (strchr(who, '@') != NULL) {
584     char whonick[512];
585    
586     splitc(whonick, who, '@');
587     whonick[20] = 0;
588     if (!strcasecmp(who, botnetnick)) {
589     cmd_boot(u, idx, whonick);
590     return;
591     }
592     if (remote_boots > 0) {
593     i = nextbot(who);
594     if (i < 0) {
595     dprintf(idx, "No such bot connected.\n");
596     return;
597     }
598     botnet_send_reject(i, dcc[idx].nick, botnetnick, whonick,
599     who, par[0] ? par : dcc[idx].nick);
600     putlog(LOG_MISC, "*", "#%s# boot %s@%s (%s)", dcc[idx].nick, whonick,
601     who, par[0] ? par : dcc[idx].nick);
602     } else
603     dprintf(idx, "Remote boots are disabled here.\n");
604     return;
605     }
606     for (i = 0; i < dcc_total; i++)
607     if (!strcasecmp(dcc[i].nick, who) && !ok &&
608     (dcc[i].type->flags & DCT_CANBOOT)) {
609     u2 = get_user_by_handle(userlist, dcc[i].nick);
610     if (u2 && (u2->flags & USER_OWNER) &&
611     strcasecmp(dcc[idx].nick, who)) {
612     dprintf(idx, "Can't boot the bot owner.\n");
613     return;
614     }
615     if (u2 && (u2->flags & USER_MASTER) &&
616     !(u && (u->flags & USER_MASTER))) {
617     dprintf(idx, "Can't boot a bot master.\n");
618     return;
619     }
620     files = (dcc[i].type->flags & DCT_FILES);
621     if (files)
622     dprintf(idx, "Booted %s from the file section.\n", dcc[i].nick);
623     else
624     dprintf(idx, "Booted %s from the bot.\n", dcc[i].nick);
625     putlog(LOG_CMDS, "*", "#%s# boot %s %s", dcc[idx].nick, who, par);
626     do_boot(i, dcc[idx].nick, par);
627     ok = 1;
628     }
629     if (!ok)
630     dprintf(idx, "Who? No such person on the party line.\n");
631     }
632    
633     static void cmd_console(struct userrec *u, int idx, char *par)
634     {
635     char *nick, s[2], s1[512];
636     int dest = 0, i, ok = 0, pls, md;
637     struct flag_record fr =
638     {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
639    
640     if (!par[0]) {
641     dprintf(idx, "Your console is %s: %s (%s)\n",
642     dcc[idx].u.chat->con_chan,
643     masktype(dcc[idx].u.chat->con_flags),
644     maskname(dcc[idx].u.chat->con_flags));
645     return;
646     }
647     get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
648     strcpy(s1, par);
649     nick = newsplit(&par);
650     if (nick[0] && !strchr("#&+-*", nick[0]) && glob_master(fr)) {
651     for (i = 0; i < dcc_total; i++)
652     if (!strcasecmp(nick, dcc[i].nick) &&
653     (dcc[i].type == &DCC_CHAT) && (!ok)) {
654     ok = 1;
655     dest = i;
656     }
657     if (!ok) {
658     dprintf(idx, "No such user on the party line!\n");
659     return;
660     }
661     nick[0] = 0;
662     } else
663     dest = idx;
664     if (!nick[0])
665     nick = newsplit(&par);
666     if (strchr("#&*", nick[0])) {
667     if ((nick[0] != '*') && !findchan(nick)) {
668     dprintf(idx, "Invalid console channel: %s\n", nick);
669     return;
670     }
671     get_user_flagrec(u, &fr, nick);
672     if (!chan_op(fr) && !(glob_op(fr) && !chan_deop(fr))) {
673     dprintf(idx, "You don't have op or master access to channel %s\n",
674     nick);
675     return;
676     }
677     strncpy(dcc[dest].u.chat->con_chan, nick, 80);
678     dcc[dest].u.chat->con_chan[80] = 0;
679     nick[0] = 0;
680     if ((dest == idx) && !glob_master(fr) && !chan_master(fr))
681     /* consoling to another channel for self */
682     dcc[dest].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_WALL);
683     }
684     if (!nick[0])
685     nick = newsplit(&par);
686     pls = 1;
687     if (nick[0]) {
688     if ((nick[0] != '+') && (nick[0] != '-'))
689     dcc[dest].u.chat->con_flags = 0;
690     for (; *nick; nick++) {
691     if (*nick == '+')
692     pls = 1;
693     else if (*nick == '-')
694     pls = 0;
695     else {
696     s[0] = *nick;
697     s[1] = 0;
698     md = logmodes(s);
699     if ((dest == idx) && !glob_master(fr) && pls) {
700     if (chan_master(fr))
701     md &= ~(LOG_FILES | LOG_LEV1 | LOG_LEV2 | LOG_LEV3 |
702     LOG_LEV4 | LOG_LEV5 | LOG_LEV6 | LOG_LEV7 |
703     LOG_LEV8 | LOG_DEBUG);
704     else
705     md &= ~(LOG_MISC | LOG_CMDS | LOG_FILES | LOG_LEV1 |
706     LOG_LEV2 | LOG_LEV3 | LOG_LEV4 | LOG_LEV5 |
707     LOG_LEV6 | LOG_LEV7 | LOG_LEV8 | LOG_WALL |
708     LOG_DEBUG);
709     }
710     if (!glob_owner(fr) && pls)
711     md &= ~(LOG_RAW | LOG_SRVOUT | LOG_BOTNET | LOG_BOTSHARE);
712     if (!glob_botmast(fr) && pls)
713     md &= ~LOG_BOTS;
714     if (pls)
715     dcc[dest].u.chat->con_flags |= md;
716     else
717     dcc[dest].u.chat->con_flags &= ~md;
718     }
719     }
720     }
721     putlog(LOG_CMDS, "*", "#%s# console %s", dcc[idx].nick, s1);
722     if (dest == idx) {
723     dprintf(idx, "Set your console to %s: %s (%s)\n",
724     dcc[idx].u.chat->con_chan,
725     masktype(dcc[idx].u.chat->con_flags),
726     maskname(dcc[idx].u.chat->con_flags));
727     } else {
728     dprintf(idx, "Set console of %s to %s: %s (%s)\n", dcc[dest].nick,
729     dcc[dest].u.chat->con_chan,
730     masktype(dcc[dest].u.chat->con_flags),
731     maskname(dcc[dest].u.chat->con_flags));
732     dprintf(dest, "%s set your console to %s: %s (%s)\n", dcc[idx].nick,
733     dcc[dest].u.chat->con_chan,
734     masktype(dcc[dest].u.chat->con_flags),
735     maskname(dcc[dest].u.chat->con_flags));
736     }
737     }
738    
739     static void cmd_pls_bot(struct userrec *u, int idx, char *par)
740     {
741     char *handle, *addr, *p, *q, *host;
742     struct userrec *u1;
743     struct bot_addr *bi;
744    
745     if (!par[0])
746     dprintf(idx, "Usage: +bot <handle> <address[:telnet-port[/relay-port]]> [host]\n");
747     else {
748     handle = newsplit(&par);
749     addr = newsplit(&par);
750     if (strlen(handle) > HANDLEN)
751     handle[HANDLEN] = 0; /* max len = XX .. for the moment :) */
752     if (get_user_by_handle(userlist, handle))
753     dprintf(idx, "Someone already exists by that name.\n");
754     else if (strchr(BADNICKCHARS, handle[0]) != NULL)
755     dprintf(idx, "You can't start a botnick with '%c'.\n", handle[0]);
756     else {
757     if (strlen(addr) > 60)
758     addr[60] = 0;
759     putlog(LOG_CMDS, "*", "#%s# +bot %s %s", dcc[idx].nick, handle, addr);
760     userlist = adduser(userlist, handle, "none", "-", USER_BOT);
761     u1 = get_user_by_handle(userlist, handle);
762     bi = user_malloc(sizeof(struct bot_addr));
763    
764     q = strchr(addr, ':');
765     if (!q) {
766     bi->address = user_malloc(strlen(addr) + 1);
767     strcpy(bi->address, addr);
768     bi->telnet_port = 3333;
769     bi->relay_port = 3333;
770     } else {
771     bi->address = user_malloc(q - addr + 1);
772     strncpy(bi->address, addr, q - addr);
773     bi->address[q - addr] = 0;
774     p = q + 1;
775     bi->telnet_port = atoi(p);
776     q = strchr(p, '/');
777     if (!q) {
778     bi->relay_port = bi->telnet_port;
779     } else {
780     bi->relay_port = atoi(q + 1);
781     }
782     }
783     set_user(&USERENTRY_BOTADDR, u1, bi);
784     dprintf(idx, "Added bot '%s' with address '%s' and no password.\n",
785     handle, addr);
786     host = newsplit(&par);
787     if (host[0]) {
788     addhost_by_handle(handle, host);
789     } else if (!add_bot_hostmask(idx, handle))
790     dprintf(idx, "You'll want to add a hostmask if this bot will ever %s",
791     "be on any channels that I'm on.\n");
792     }
793     }
794     }
795    
796     static void cmd_chnick(struct userrec *u, int idx, char *par)
797     {
798     char *hand, *newhand;
799     int i, atr = u ? u->flags : 0, atr2;
800     struct userrec *u2;
801    
802     hand = newsplit(&par);
803     if (!hand[0] || !par[0])
804     dprintf(idx, "Usage: chnick <oldnick> <newnick>\n");
805     else {
806     newhand = newsplit(&par);
807     if (strlen(newhand) > HANDLEN)
808     newhand[HANDLEN] = 0;
809     for (i = 0; i < strlen(newhand); i++)
810     if ((newhand[i] <= 32) || (newhand[i] >= 127) || (newhand[i] == '@'))
811     newhand[i] = '?';
812     if (strchr(BADNICKCHARS, newhand[0]) != NULL)
813     dprintf(idx, "Bizarre quantum forces prevent nicknames from starting with %c\n",
814     newhand[0]);
815     else if (get_user_by_handle(userlist, newhand) &&
816     strcasecmp(hand, newhand))
817     dprintf(idx, "Already a user %s.\n", newhand);
818     else if (!strcasecmp(newhand, origbotname) ||
819     !strcasecmp(newhand, botnetnick))
820     dprintf(idx, "Hey! That's MY name!\n", newhand);
821     else {
822     u2 = get_user_by_handle(userlist, hand);
823     atr2 = u2 ? u2->flags : 0;
824     if ((atr & USER_BOTMAST) && !(atr & USER_MASTER) &&
825     !(atr2 & USER_BOT))
826     dprintf(idx, "You can't change nick for non-bots.\n");
827     else if ((bot_flags(u2) & BOT_SHARE) && !(atr & USER_OWNER))
828     dprintf(idx, "You can't change shared bot's nick.\n");
829     else if ((atr2 & USER_OWNER) && !(atr & USER_OWNER) &&
830     strcasecmp(dcc[idx].nick, hand))
831     dprintf(idx, "Can't change the bot owner's handle.\n");
832     /* FIXME: do we need rfc_casecmp() here ? */
833     else if (isowner(hand) && strcasecmp(dcc[idx].nick, hand))
834     dprintf(idx, "Can't change the permanent bot owner's handle.\n");
835     else if (change_handle(u2, newhand)) {
836     putlog(LOG_CMDS, "*", "#%s# chnick %s %s", dcc[idx].nick,
837     hand, newhand);
838     dprintf(idx, "Changed.\n");
839     } else
840     dprintf(idx, "Failed.\n");
841     }
842     }
843     }
844    
845     static void cmd_nick(struct userrec *u, int idx, char *par)
846     {
847     int i, len = strlen(par);
848     char oldnick[HANDLEN + 1], *newnick;
849    
850     if (!len) {
851     dprintf(idx, "Usage: nick <new-handle>\n");
852     return;
853     }
854     newnick = newsplit(&par);
855     if (len > HANDLEN)
856     newnick[len = HANDLEN] = 0;
857     for (i = 0; i < len; i++)
858     if ((newnick[i] <= 32) || (newnick[i] >= 127) || (newnick[i] == '@'))
859     newnick[i] = '?';
860     if (strchr(BADNICKCHARS, newnick[0]) != NULL) {
861     dprintf(idx, "Bizarre quantum forces prevent nicknames from starting with '%c'\n",
862     newnick[0]);
863     } else if (get_user_by_handle(userlist, newnick) &&
864     strcasecmp(dcc[idx].nick, newnick)) {
865     dprintf(idx, "Somebody is already using %s.\n", newnick);
866     } else if (!strcasecmp(newnick, origbotname) ||
867     !strcasecmp(newnick, botnetnick)) {
868     dprintf(idx, "Hey! That's MY name!\n", par);
869     } else {
870     strcpy(oldnick, dcc[idx].nick);
871     if (change_handle(u, newnick)) {
872     putlog(LOG_CMDS, "*", "#%s# nick %s", oldnick, newnick);
873     dprintf(idx, "Okay, changed.\n");
874     } else
875     dprintf(idx, "Failed.\n");
876     }
877     }
878    
879     static void cmd_chpass(struct userrec *u, int idx, char *par)
880     {
881     char *handle, *new;
882     int atr = u ? u->flags : 0, l;
883    
884     if (!par[0])
885     dprintf(idx, "Usage: chpass <handle> [password]\n");
886     else {
887     handle = newsplit(&par);
888     u = get_user_by_handle(userlist, handle);
889     if (!u)
890     dprintf(idx, "No such user.\n");
891     else if ((atr & USER_BOTMAST) && !(atr & USER_MASTER) &&
892     !(u->flags & USER_BOT))
893     dprintf(idx, "You can't change password for non-bots.\n");
894     else if ((bot_flags(u) & BOT_SHARE) && !(atr & USER_OWNER))
895     dprintf(idx, "You can't change shared bot's password.\n");
896     else if ((u->flags & USER_OWNER) && !(atr & USER_OWNER) &&
897     strcasecmp(handle, dcc[idx].nick))
898     dprintf(idx, "Can't change the bot owner's password.\n");
899     else if (!par[0]) {
900     putlog(LOG_CMDS, "*", "#%s# chpass %s [nothing]", dcc[idx].nick,
901     handle);
902     set_user(&USERENTRY_PASS, u, NULL);
903     dprintf(idx, "Removed password.\n");
904     } else {
905     l = strlen(new = newsplit(&par));
906     if (l > 16)
907     new[16] = 0;
908     if (l < 6)
909     dprintf(idx, "Please use at least 6 characters.\n");
910     else {
911     set_user(&USERENTRY_PASS, u, new);
912     putlog(LOG_CMDS, "*", "#%s# chpass %s [something]", dcc[idx].nick,
913     handle);
914     dprintf(idx, "Changed password.\n");
915     }
916     }
917     }
918     }
919    
920     static void cmd_chaddr(struct userrec *u, int idx, char *par)
921     {
922     char *handle, *addr, *p, *q;
923     struct bot_addr *bi;
924     struct userrec *u1;
925    
926     if (!par[0]) {
927     dprintf(idx, "Usage: chaddr <botname> <address:botport#/userport#>\n");
928     return;
929     }
930     handle = newsplit(&par);
931     addr = newsplit(&par);
932     if (strlen(addr) > UHOSTLEN)
933     addr[UHOSTLEN] = 0;
934     u1 = get_user_by_handle(userlist, handle);
935     if (!u1 || !(u1->flags & USER_BOT)) {
936     dprintf(idx, "Useful only for tandem bots.\n");
937     return;
938     }
939     if ((bot_flags(u1) & BOT_SHARE) && (!u || !u->flags & USER_OWNER)) {
940     dprintf(idx, "You can't change shared bot's address.\n");
941     return;
942     }
943     putlog(LOG_CMDS, "*", "#%s# chaddr %s %s", dcc[idx].nick, handle, addr);
944     dprintf(idx, "Changed bot's address.\n");
945     bi = user_malloc(sizeof(struct bot_addr));
946    
947     q = strchr(addr, ':');
948     if (!q) {
949     bi->address = user_malloc(strlen(addr) + 1);
950     strcpy(bi->address, addr);
951     bi->telnet_port = 3333;
952     bi->relay_port = 3333;
953     } else {
954     bi->address = user_malloc(q - addr + 1);
955     strncpy(bi->address, addr, q - addr);
956     bi->address[q - addr] = 0;
957     p = q + 1;
958     bi->telnet_port = atoi(p);
959     q = strchr(p, '/');
960     if (!q) {
961     bi->relay_port = bi->telnet_port;
962     } else {
963     bi->relay_port = atoi(q + 1);
964     }
965     }
966     set_user(&USERENTRY_BOTADDR, u1, bi);
967     }
968    
969     static void cmd_comment(struct userrec *u, int idx, char *par)
970     {
971     char *handle;
972     struct userrec *u1;
973    
974     if (!par[0]) {
975     dprintf(idx, "Usage: comment <handle> <newcomment>\n");
976     return;
977     }
978     handle = newsplit(&par);
979     u1 = get_user_by_handle(userlist, handle);
980     if (!u1) {
981     dprintf(idx, "No such user!\n");
982     return;
983     }
984     if ((u1->flags & USER_OWNER) && !(u && (u->flags & USER_OWNER)) &&
985     strcasecmp(handle, dcc[idx].nick)) {
986     dprintf(idx, "Can't change comment on the bot owner.\n");
987     return;
988     }
989     putlog(LOG_CMDS, "*", "#%s# comment %s %s", dcc[idx].nick, handle, par);
990     if (!strcasecmp(par, "none")) {
991     dprintf(idx, "Okay, comment blanked.\n");
992     set_user(&USERENTRY_COMMENT, u1, NULL);
993     return;
994     }
995     dprintf(idx, "Changed comment.\n");
996     set_user(&USERENTRY_COMMENT, u1, par);
997     }
998    
999     static void cmd_restart(struct userrec *u, int idx, char *par)
1000     {
1001     putlog(LOG_CMDS, "*", "#%s# restart", dcc[idx].nick);
1002     if (!backgrd) {
1003     dprintf(idx, "You can not .restart a bot when running -n (due to tcl)\n");
1004     return;
1005     }
1006     dprintf(idx, "Restarting.\n");
1007     if (make_userfile) {
1008     putlog(LOG_MISC, "*",
1009     "Uh, guess you don't need to create a new userfile.");
1010     make_userfile = 0;
1011     }
1012     write_userfile(-1);
1013     putlog(LOG_MISC, "*", "Restarting ...");
1014     wipe_timers(interp, &utimer);
1015     wipe_timers(interp, &timer);
1016     do_restart = idx;
1017     }
1018    
1019     static void cmd_rehash(struct userrec *u, int idx, char *par)
1020     {
1021     putlog(LOG_CMDS, "*", "#%s# rehash", dcc[idx].nick);
1022     dprintf(idx, "Rehashing.\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, "*", "Rehashing ...");
1030     do_restart = -2;
1031     }
1032    
1033     static void cmd_reload(struct userrec *u, int idx, char *par)
1034     {
1035     putlog(LOG_CMDS, "*", "#%s# reload", dcc[idx].nick);
1036     dprintf(idx, "Reloading user file...\n");
1037     reload();
1038     }
1039    
1040     /* this get replaced in server.so with a version that handles the server */
1041     void cmd_die(struct userrec *u, int idx, char *par)
1042     {
1043     char s[1024];
1044    
1045     putlog(LOG_CMDS, "*", "#%s# die %s", dcc[idx].nick, par);
1046     if (par[0]) {
1047     simple_sprintf(s, "BOT SHUTDOWN (%s: %s)", dcc[idx].nick, par);
1048     } else {
1049     simple_sprintf(s, "BOT SHUTDOWN (authorized by %s)", dcc[idx].nick);
1050     }
1051     chatout("*** %s\n", s);
1052     botnet_send_chat(-1, botnetnick, s);
1053     botnet_send_bye();
1054     write_userfile(-1);
1055     simple_sprintf(s, "DIE BY %s!%s (%s)", dcc[idx].nick,
1056     dcc[idx].host, par[0] ? par : "request");
1057     fatal(s, 0);
1058     }
1059    
1060     static void cmd_debug(struct userrec *u, int idx, char *par)
1061     {
1062     if (!strcasecmp(par, "help")) {
1063     putlog(LOG_CMDS, "*", "#%s# debug help", dcc[idx].nick);
1064     debug_help(idx);
1065     } else {
1066     putlog(LOG_CMDS, "*", "#%s# debug", dcc[idx].nick);
1067     debug_mem_to_dcc(idx);
1068     }
1069     }
1070    
1071     static void cmd_simul(struct userrec *u, int idx, char *par)
1072     {
1073     char *nick;
1074     int i, ok = 0;
1075    
1076     nick = newsplit(&par);
1077     if (!par[0]) {
1078     dprintf(idx, "Usage: simul <nick> <text>\n");
1079     return;
1080     }
1081     if (isowner(nick)) {
1082     dprintf(idx, "Unable to '.simul' permanent owners.\n");
1083     return;
1084     }
1085     for (i = 0; i < dcc_total; i++)
1086     if (!strcasecmp(nick, dcc[i].nick) && !ok &&
1087     (dcc[i].type->flags & DCT_SIMUL)) {
1088     putlog(LOG_CMDS, "*", "#%s# simul %s %s", dcc[idx].nick, nick, par);
1089     if (dcc[i].type && dcc[i].type->activity) {
1090     dcc[i].type->activity(i, par, strlen(par));
1091     ok = 1;
1092     }
1093     }
1094     if (!ok)
1095     dprintf(idx, "No such user on the party line.\n");
1096     }
1097    
1098     static void cmd_link(struct userrec *u, int idx, char *par)
1099     {
1100     char *s;
1101     int i;
1102    
1103     if (!par[0]) {
1104     dprintf(idx, "Usage: link [some-bot] <new-bot>\n");
1105     return;
1106     }
1107     putlog(LOG_CMDS, "*", "#%s# link %s", dcc[idx].nick, par);
1108     s = newsplit(&par);
1109     if (!par[0] || !strcasecmp(par, botnetnick))
1110     botlink(dcc[idx].nick, idx, s);
1111     else {
1112     char x[40];
1113    
1114     i = nextbot(s);
1115     if (i < 0) {
1116     dprintf(idx, "No such bot online.\n");
1117     return;
1118     }
1119     simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1120     botnet_send_link(i, x, s, par);
1121     }
1122     }
1123    
1124     static void cmd_unlink(struct userrec *u, int idx, char *par)
1125     {
1126     int i;
1127     char *bot;
1128    
1129     if (!par[0]) {
1130     dprintf(idx, "Usage: unlink <bot> [reason]\n");
1131     return;
1132     }
1133     putlog(LOG_CMDS, "*", "#%s# unlink %s", dcc[idx].nick, par);
1134     bot = newsplit(&par);
1135     i = nextbot(bot);
1136     if (i < 0) {
1137     botunlink(idx, bot, par);
1138     return;
1139     }
1140     /* if we're directly connected to that bot, just do it
1141     * (is nike gunna sue?) */
1142     if (!strcasecmp(dcc[i].nick, bot))
1143     botunlink(idx, bot, par);
1144     else {
1145     char x[40];
1146    
1147     simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1148     botnet_send_unlink(i, x, lastbot(bot), bot, par);
1149     }
1150     }
1151    
1152     static void cmd_relay(struct userrec *u, int idx, char *par)
1153     {
1154     if (!par[0]) {
1155     dprintf(idx, "Usage: relay <bot>\n");
1156     return;
1157     }
1158     putlog(LOG_CMDS, "*", "#%s# relay %s", dcc[idx].nick, par);
1159     tandem_relay(idx, par, 0);
1160     }
1161    
1162     static void cmd_save(struct userrec *u, int idx, char *par)
1163     {
1164     putlog(LOG_CMDS, "*", "#%s# save", dcc[idx].nick);
1165     dprintf(idx, "Saving user file...\n");
1166     write_userfile(-1);
1167     }
1168    
1169     static void cmd_backup(struct userrec *u, int idx, char *par)
1170     {
1171     putlog(LOG_CMDS, "*", "#%s# backup", dcc[idx].nick);
1172     dprintf(idx, "Backing up the user file...\n");
1173     backup_userfile();
1174     }
1175    
1176     static void cmd_trace(struct userrec *u, int idx, char *par)
1177     {
1178     int i;
1179     char x[NOTENAMELEN + 11], y[11];
1180    
1181     if (!par[0]) {
1182     dprintf(idx, "Usage: trace <botname>\n");
1183     return;
1184     }
1185     if (!strcasecmp(par, botnetnick)) {
1186     dprintf(idx, "That's me! Hiya! :)\n");
1187     return;
1188     }
1189     i = nextbot(par);
1190     if (i < 0) {
1191     dprintf(idx, "Unreachable bot.\n");
1192     return;
1193     }
1194     putlog(LOG_CMDS, "*", "#%s# trace %s", dcc[idx].nick, par);
1195     simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1196     simple_sprintf(y, ":%d", now);
1197     botnet_send_trace(i, x, par, y);
1198     }
1199    
1200     static void cmd_binds(struct userrec *u, int idx, char *par)
1201     {
1202     putlog(LOG_CMDS, "*", "#%s# binds %s", dcc[idx].nick, par);
1203     tell_binds(idx, par);
1204     }
1205    
1206     static void cmd_banner(struct userrec *u, int idx, char *par)
1207     {
1208     char s[1024];
1209     int i;
1210    
1211     if (!par[0]) {
1212     dprintf(idx, "Usage: banner <message>\n");
1213     return;
1214     }
1215     simple_sprintf(s, "\007\007### Botwide:[%s] %s\n", dcc[idx].nick, par);
1216     for (i = 0; i < dcc_total; i++)
1217     if (dcc[i].type->flags & DCT_MASTER)
1218     dprintf(i, "%s", s);
1219     }
1220    
1221     /* after messing with someone's user flags, make sure the dcc-chat flags
1222     * are set correctly */
1223     int check_dcc_attrs(struct userrec *u, int oatr)
1224     {
1225     int i, stat;
1226     char *p, *q, s[121];
1227    
1228     /* if it matches someone in the owner list, make sure he/she has +n */
1229     if (!u)
1230     return 0;
1231     /* make sure default owners are +n */
1232     if (owner[0]) {
1233     q = owner;
1234     p = strchr(q, ',');
1235     while (p) {
1236     strncpy(s, q, p - q);
1237     s[p - q] = 0;
1238     rmspace(s);
1239     if (!strcasecmp(u->handle, s))
1240     u->flags = sanity_check(u->flags | USER_OWNER);
1241     q = p + 1;
1242     p = strchr(q, ',');
1243     }
1244     strcpy(s, q);
1245     rmspace(s);
1246     if (!strcasecmp(u->handle, s))
1247     u->flags = sanity_check(u->flags | USER_OWNER);
1248     }
1249     for (i = 0; i < dcc_total; i++) {
1250     if ((dcc[i].type->flags & DCT_MASTER) &&
1251     (!strcasecmp(u->handle, dcc[i].nick))) {
1252     stat = dcc[i].status;
1253     if ((dcc[i].type == &DCC_CHAT) &&
1254     ((u->flags & (USER_OP | USER_MASTER | USER_OWNER |
1255     USER_BOTMAST))
1256     != (oatr & (USER_OP | USER_MASTER | USER_OWNER |
1257     USER_BOTMAST)))) {
1258     botnet_send_join_idx(i, -1);
1259     }
1260     if ((oatr & USER_MASTER) && !(u->flags & USER_MASTER)) {
1261     struct flag_record fr =
1262     {FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
1263    
1264     dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_RAW |
1265     LOG_FILES | LOG_LEV1 | LOG_LEV2 |
1266     LOG_LEV3 | LOG_LEV4 | LOG_LEV5 |
1267     LOG_LEV6 | LOG_LEV7 | LOG_LEV8 |
1268     LOG_WALL | LOG_DEBUG);
1269     get_user_flagrec(u, &fr, NULL);
1270     if (!chan_master(fr))
1271     dcc[i].u.chat->con_flags |= (LOG_MISC | LOG_CMDS);
1272     dprintf(i, "*** POOF! ***\n");
1273     dprintf(i, "You are no longer a master on this bot.\n");
1274     }
1275     if (!(oatr & USER_MASTER) && (u->flags & USER_MASTER)) {
1276     dcc[i].u.chat->con_flags |= conmask;
1277     dprintf(i, "*** POOF! ***\n");
1278     dprintf(i, "You are now a master on this bot.\n");
1279     }
1280     if (!(oatr & USER_BOTMAST) && (u->flags & USER_BOTMAST)) {
1281     dprintf(i, "### POOF! ###\n");
1282     dprintf(i, "You are now a botnet master on this bot.\n");
1283     }
1284     if ((oatr & USER_BOTMAST) && !(u->flags & USER_BOTMAST)) {
1285     dprintf(i, "### POOF! ###\n");
1286     dprintf(i, "You are no longer a botnet master on this bot.\n");
1287     }
1288     if (!(oatr & USER_OWNER) && (u->flags & USER_OWNER)) {
1289     dprintf(i, "@@@ POOF! @@@\n");
1290     dprintf(i, "You are now an OWNER of this bot.\n");
1291     }
1292     if ((oatr & USER_OWNER) && !(u->flags & USER_OWNER)) {
1293     dprintf(i, "@@@ POOF! @@@\n");
1294     dprintf(i, "You are no longer an owner of this bot.\n");
1295     }
1296     if ((stat & STAT_PARTY) && (u->flags & USER_OP))
1297     stat &= ~STAT_PARTY;
1298     if (!(stat & STAT_PARTY) && !(u->flags & USER_OP) &&
1299     !(u->flags & USER_MASTER))
1300     stat |= STAT_PARTY;
1301     if ((stat & STAT_CHAT) && !(u->flags & USER_PARTY) &&
1302     !(u->flags & USER_MASTER) &&
1303     (!(u->flags & USER_OP) || require_p))
1304     stat &= ~STAT_CHAT;
1305     if ((dcc[i].type->flags & DCT_FILES) && !(stat & STAT_CHAT) &&
1306     ((u->flags & USER_MASTER) || (u->flags & USER_PARTY) ||
1307     ((u->flags & USER_OP) && !require_p)))
1308     stat |= STAT_CHAT;
1309     dcc[i].status = stat;
1310     /* check if they no longer have access to wherever they are */
1311     /* DON'T kick someone off the party line just cuz they lost +p
1312     * (pinvite script removes +p after 5 mins automatically) */
1313     if ((dcc[i].type->flags & DCT_FILES) && !(u->flags & USER_XFER) &&
1314     !(u->flags & USER_MASTER)) {
1315     dprintf(i, "-+- POOF! -+-\n");
1316     dprintf(i, "You no longer have file area access.\n\n");
1317     putlog(LOG_MISC, "*", "DCC user [%s]%s removed from file system",
1318     dcc[i].nick, dcc[i].host);
1319     if (dcc[i].status & STAT_CHAT) {
1320     struct chat_info *ci;
1321    
1322     ci = dcc[i].u.file->chat;
1323     nfree(dcc[i].u.file);
1324     dcc[i].u.chat = ci;
1325     dcc[i].status &= (~STAT_CHAT);
1326     dcc[i].type = &DCC_CHAT;
1327     if (dcc[i].u.chat->channel >= 0) {
1328     chanout_but(-1, dcc[i].u.chat->channel,
1329     "*** %s has returned.\n", dcc[i].nick);
1330     context;
1331     if (dcc[i].u.chat->channel < 100000)
1332     botnet_send_join_idx(i, -1);
1333     }
1334     } else {
1335     killsock(dcc[i].sock);
1336     dcc[i].sock = (long) dcc[i].type;
1337     dcc[i].type = &DCC_LOST;
1338     }
1339     }
1340     }
1341     if ((dcc[i].type == &DCC_BOT) && !strcasecmp(u->handle, dcc[i].nick)) {
1342     if ((dcc[i].status & STAT_LEAF) && !(u->flags & BOT_LEAF))
1343     dcc[i].status &= ~(STAT_LEAF | STAT_WARNED);
1344     if (!(dcc[i].status & STAT_LEAF) && (u->flags & BOT_LEAF))
1345     dcc[i].status |= STAT_LEAF;
1346     }
1347     }
1348     return u->flags;
1349     }
1350    
1351     int check_dcc_chanattrs(struct userrec *u, char *chname, int chflags,
1352     int ochatr)
1353     {
1354     int i, found = 0, atr = u ? u->flags : 0;
1355     struct chanset_t *chan;
1356    
1357     if (!u)
1358     return 0;
1359     chan = chanset;
1360     for (i = 0; i < dcc_total; i++) {
1361     if ((dcc[i].type->flags & DCT_MASTER) &&
1362     !strcasecmp(u->handle, dcc[i].nick)) {
1363     if ((dcc[i].type == &DCC_CHAT) &&
1364     ((chflags & (USER_OP | USER_MASTER | USER_OWNER))
1365     != (ochatr & (USER_OP | USER_MASTER | USER_OWNER))))
1366     botnet_send_join_idx(i, -1);
1367     if ((ochatr & USER_MASTER) && !(chflags & USER_MASTER)) {
1368     if (!(atr & USER_MASTER))
1369     dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS);
1370     dprintf(i, "*** POOF! ***\n");
1371     dprintf(i, "You are no longer a master on %s.\n", chname);
1372     }
1373     if (!(ochatr & USER_MASTER) && (chflags & USER_MASTER)) {
1374     dcc[i].u.chat->con_flags |= conmask;
1375     if (!(atr & USER_MASTER))
1376     dcc[i].u.chat->con_flags &=
1377     ~(LOG_LEV1 | LOG_LEV2 | LOG_LEV3 | LOG_LEV4 |
1378     LOG_LEV5 | LOG_LEV6 | LOG_LEV7 | LOG_LEV8 |
1379     LOG_RAW | LOG_DEBUG | LOG_WALL | LOG_FILES | LOG_SRVOUT);
1380     dprintf(i, "*** POOF! ***\n");
1381     dprintf(i, "You are now a master on %s.\n", chname);
1382     }
1383     if (!(ochatr & USER_OWNER) && (chflags & USER_OWNER)) {
1384     dprintf(i, "@@@ POOF! @@@\n");
1385     dprintf(i, "You are now an OWNER of %s.\n", chname);
1386     }
1387     if ((ochatr & USER_OWNER) && !(chflags & USER_OWNER)) {
1388     dprintf(i, "@@@ POOF! @@@\n");
1389     dprintf(i, "You are no longer an owner of %s.\n", chname);
1390     }
1391     if (((ochatr & (USER_OP | USER_MASTER | USER_OWNER)) &&
1392     (!(chflags & (USER_OP | USER_MASTER | USER_OWNER)))) ||
1393     ((chflags & (USER_OP | USER_MASTER | USER_OWNER)) &&
1394     (!(ochatr & (USER_OP | USER_MASTER | USER_OWNER))))) {
1395     struct flag_record fr =
1396     {FR_CHAN, 0, 0, 0, 0, 0};
1397    
1398     while (chan && !found) {
1399     get_user_flagrec(u, &fr, chan->name);
1400     if (fr.chan & (USER_OP | USER_MASTER | USER_OWNER))
1401     found = 1;
1402     else
1403     chan = chan->next;
1404     }
1405     if (!chan)
1406     chan = chanset;
1407     if (chan)
1408     strcpy(dcc[i].u.chat->con_chan, chan->name);
1409     else
1410     strcpy(dcc[i].u.chat->con_chan, "*");
1411     }
1412     }
1413     }
1414     return chflags;
1415     }
1416    
1417     static void cmd_chattr(struct userrec *u, int idx, char *par)
1418     {
1419     char *hand, *chg = NULL, work[1024];
1420     struct chanset_t *chan = NULL;
1421     struct userrec *u2;
1422     struct flag_record pls =
1423     {0, 0, 0, 0, 0, 0}, mns =
1424     {0, 0, 0, 0, 0, 0}, user =
1425     {0, 0, 0, 0, 0, 0};
1426     module_entry *me;
1427     int fl = -1, of = 0, ocf = 0;
1428    
1429     if (!par[0]) {
1430     dprintf(idx, "Usage: chattr <handle> [changes] [channel]\n");
1431     return;
1432     }
1433     hand = newsplit(&par);
1434     u2 = get_user_by_handle(userlist, hand);
1435     if ((hand[0] == '*') || !u2) {
1436     dprintf(idx, "No such user!\n");
1437     return;
1438     }
1439     if (strchr(CHANMETA, par[0]) == NULL || par[0]=='+') {
1440     chg = newsplit(&par);
1441     if (!par[0] && strpbrk(chg, "&|"))
1442     par = dcc[idx].u.chat->con_chan;
1443     else if (par[0] && !strpbrk(chg, "&|"))
1444     fl = ~FR_GLOBAL;
1445     }
1446     chan = findchan(par);
1447     if (!chan && par[0] && (par[0] != '*')) {
1448     dprintf(idx, "No channel record for %s.\n", par);
1449     return;
1450     }
1451     user.match = FR_GLOBAL;
1452     if (chan)
1453     user.match |= FR_CHAN;
1454     get_user_flagrec(u, &user, chan ? chan->name : 0);
1455     if (!chan && !glob_botmast(user)) {
1456     dprintf(idx, "You do not have Bot Master privileges.\n");
1457     return;
1458     }
1459     if (chan && !glob_master(user) && !chan_master(user)) {
1460     dprintf(idx, "You do not have channel master privileges for channel %s\n",
1461     par);
1462     return;
1463     }
1464     user.match &= fl;
1465     if (chg) {
1466     pls.match = user.match;
1467     break_down_flags(chg, &pls, &mns);
1468     /* no-one can change these flags on-the-fly */
1469     pls.global &=~(USER_BOT);
1470     mns.global &=~(USER_BOT);
1471    
1472     if (chan) {
1473     pls.chan &= ~(BOT_SHARE);
1474     mns.chan &= ~(BOT_SHARE);
1475     }
1476     if (!glob_owner(user)) {
1477     pls.global &=~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1478     mns.global &=~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1479    
1480     if (chan) {
1481     pls.chan &= ~USER_OWNER;
1482     mns.chan &= ~USER_OWNER;
1483     }
1484     if (!glob_master(user)) {
1485     pls.global &=USER_PARTY | USER_XFER;
1486     mns.global &=USER_PARTY | USER_XFER;
1487    
1488     if (!glob_botmast(user)) {
1489     pls.global = 0;
1490     mns.global = 0;
1491     }
1492     }
1493     }
1494     if (chan && !chan_owner(user) && !glob_owner(user)) {
1495     pls.chan &= ~USER_MASTER;
1496     mns.chan &= ~USER_MASTER;
1497     if (!chan_master(user) && !glob_master(user)) {
1498     pls.chan = 0;
1499     mns.chan = 0;
1500     }
1501     }
1502     get_user_flagrec(u2, &user, par);
1503     if (user.match & FR_GLOBAL) {
1504     of = user.global;
1505     user.global = sanity_check((user.global |pls.global) &~mns.global);
1506    
1507     user.udef_global = (user.udef_global | pls.udef_global)
1508     & ~mns.udef_global;
1509     }
1510     if (chan) {
1511     ocf = user.chan;
1512     user.chan = chan_sanity_check((user.chan | pls.chan) & ~mns.chan,
1513     user.global);
1514    
1515     user.udef_chan = (user.udef_chan | pls.udef_chan) & ~mns.udef_chan;
1516     }
1517     set_user_flagrec(u2, &user, par);
1518     }
1519     if (chan)
1520     putlog(LOG_CMDS, "*", "#%s# (%s) chattr %s %s",
1521     dcc[idx].nick, chan ? chan->name : "*", hand, chg ? chg : "");
1522     else
1523     putlog(LOG_CMDS, "*", "#%s# chattr %s %s", dcc[idx].nick, hand,
1524     chg ? chg : "");
1525     /* get current flags and display them */
1526     if (user.match & FR_GLOBAL) {
1527     user.match = FR_GLOBAL;
1528     if (chg)
1529     check_dcc_attrs(u2, of);
1530     get_user_flagrec(u2, &user, NULL);
1531     build_flags(work, &user, NULL);
1532     if (work[0] != '-')
1533     dprintf(idx, "Global flags for %s are now +%s\n", hand, work);
1534     else
1535     dprintf(idx, "No global flags for %s.\n", hand);
1536     }
1537     if (chan) {
1538     user.match = FR_CHAN;
1539     get_user_flagrec(u2, &user, par);
1540     user.chan &= ~BOT_SHARE;
1541     if (chg)
1542     check_dcc_chanattrs(u2, chan->name, user.chan, ocf);
1543     build_flags(work, &user, NULL);
1544     if (work[0] != '-')
1545     dprintf(idx, "Channel flags for %s on %s are now +%s\n", hand,
1546     chan->name, work);
1547     else
1548     dprintf(idx, "No flags for %s on %s.\n", hand, chan->name);
1549     if ((me = module_find("irc", 0, 0))) {
1550     Function *func = me->funcs;
1551    
1552     if (chan)
1553     (func[15]) (chan, 0);
1554     }
1555     }
1556     }
1557    
1558     static void cmd_botattr(struct userrec *u, int idx, char *par)
1559     {
1560     char *hand, *chg = NULL, work[1024];
1561     struct chanset_t *chan = NULL;
1562     struct userrec *u2;
1563     struct flag_record pls =
1564     {0, 0, 0, 0, 0, 0}, mns =
1565     {0, 0, 0, 0, 0, 0}, user =
1566     {0, 0, 0, 0, 0, 0};
1567     int idx2;
1568    
1569     if (!par[0]) {
1570     dprintf(idx, "Usage: botattr <handle> [changes] [channel]\n");
1571     return;
1572     }
1573     hand = newsplit(&par);
1574     u2 = get_user_by_handle(userlist, hand);
1575     if ((hand[0] == '*') || !u2 || !(u2->flags & USER_BOT)) {
1576     dprintf(idx, "No such bot!\n");
1577     return;
1578     }
1579     for (idx2 = 0; idx2 < dcc_total; idx2++)
1580     if (!strcasecmp(dcc[idx2].nick, hand))
1581     break;
1582     if (idx2 != dcc_total) {
1583     dprintf(idx, "You may not change the attributes of a linked bot.\n");
1584     return;
1585     }
1586     if (strchr(CHANMETA, par[0]) == NULL || par[0]=='+') {
1587     chg = newsplit(&par);
1588     if (!par[0] && strpbrk(chg, "|&"))
1589     par = dcc[idx].u.chat->con_chan;
1590     }
1591     if (!(chan = findchan(par)) && par[0]) {
1592     dprintf(idx, "No channel record for %s.\n", par);
1593     return;
1594     }
1595     user.match = FR_GLOBAL;
1596     get_user_flagrec(u, &user, chan ? chan->name : 0);
1597     if (!glob_botmast(user)) {
1598     dprintf(idx, "You do not have Bot Master privileges.\n");
1599     return;
1600     }
1601     if (chg) {
1602     user.match = FR_BOT | (chan ? FR_CHAN : 0);
1603     pls.match = user.match;
1604     break_down_flags(chg, &pls, &mns);
1605     /* no-one can change these flags on-the-fly */
1606     pls.global &=~BOT_BOT;
1607     mns.global &=~BOT_BOT;
1608    
1609     if (chan && glob_owner(user)) {
1610     pls.chan &= BOT_SHARE;
1611     mns.chan &= BOT_SHARE;
1612     } else {
1613     pls.chan = 0;
1614     mns.chan = 0;
1615     }
1616     if (!glob_owner(user)) {
1617     pls.bot &= ~(BOT_SHARE | BOT_GLOBAL);
1618     mns.bot &= ~(BOT_SHARE | BOT_GLOBAL);
1619     }
1620     user.match = FR_BOT | (chan ? FR_CHAN : 0);
1621     get_user_flagrec(u2, &user, par);
1622     user.bot = (user.bot | pls.bot) & ~mns.bot;
1623     if ((user.bot & BOT_SHARE) == BOT_SHARE)
1624     user.bot &= ~BOT_SHARE;
1625     if (chan)
1626     user.chan = (user.chan | pls.chan) & ~mns.chan;
1627     set_user_flagrec(u2, &user, par);
1628     }
1629     if (chan)
1630     putlog(LOG_CMDS, "*", "#%s# (%s) botattr %s %s",
1631     dcc[idx].nick, chan->name, hand, chg ? chg : "");
1632     else
1633     putlog(LOG_CMDS, "*", "#%s# botattr %s %s", dcc[idx].nick, hand,
1634     chg ? chg : "");
1635     /* get current flags and display them */
1636     if (!chan || pls.bot || mns.bot) {
1637     user.match = FR_BOT;
1638     get_user_flagrec(u2, &user, NULL);
1639     build_flags(work, &user, NULL);
1640     if (work[0] != '-')
1641     dprintf(idx, "Bot flags for %s are now +%s\n", hand, work);
1642     else
1643     dprintf(idx, "No bot flags for %s.\n", hand);
1644     }
1645     if (chan) {
1646     user.match = FR_CHAN;
1647     get_user_flagrec(u2, &user, par);
1648     user.chan &= BOT_SHARE;
1649     build_flags(work, &user, NULL);
1650     if (work[0] != '-')
1651     dprintf(idx, "Bot flags for %s on %s are now +%s\n", hand,
1652     chan->name, work);
1653     else
1654     dprintf(idx, "No bot flags for %s on %s.\n", hand, chan->name);
1655     }
1656     }
1657    
1658     static void cmd_chat(struct userrec *u, int idx, char *par)
1659     {
1660     int newchan, oldchan;
1661    
1662     if (!strcasecmp(par, "off")) {
1663     /* turn chat off */
1664     if (dcc[idx].u.chat->channel < 0)
1665     dprintf(idx, "You weren't in chat anyway!\n");
1666     else {
1667     dprintf(idx, "Leaving chat mode...\n");
1668     check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
1669     dcc[idx].u.chat->channel);
1670     chanout_but(-1, dcc[idx].u.chat->channel,
1671     "*** %s left the party line.\n",
1672     dcc[idx].nick);
1673     context;
1674     if (dcc[idx].u.chat->channel < 100000)
1675     botnet_send_part_idx(idx, "");
1676     }
1677     dcc[idx].u.chat->channel = (-1);
1678     } else {
1679     if (par[0] == '*') {
1680     if (((par[1] < '0') || (par[1] > '9'))) {
1681     if (par[1] == 0)
1682     newchan = 0;
1683     else {
1684     Tcl_SetVar(interp, "chan", par, 0);
1685     if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
1686     interp->result[0])
1687     newchan = atoi(interp->result);
1688     else
1689     newchan = -1;
1690     }
1691     if (newchan < 0) {
1692     dprintf(idx, "No channel by that name.\n");
1693     return;
1694     }
1695     } else
1696     newchan = 100000 + atoi(par + 1);
1697     if (newchan < 100000 || newchan > 199999) {
1698     dprintf(idx, "Channel # out of range: local channels must be *0-*99999\n");
1699     return;
1700     }
1701     } else {
1702     if (((par[0] < '0') || (par[0] > '9')) && (par[0])) {
1703     if (!strcasecmp(par, "on"))
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