/[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.19 - (hide annotations) (download) (as text)
Wed Oct 6 19:45:59 1999 UTC (20 years, 2 months ago) by guppy
Branch: MAIN
Changes since 1.18: +1 -1 lines
File MIME type: text/x-chdr
more patches .. including the configure patch

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