/[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.21 - (hide annotations) (download) (as text)
Sat Oct 9 22:24:15 1999 UTC (19 years, 11 months ago) by guppy
Branch: MAIN
Changes since 1.20: +22 -15 lines
File MIME type: text/x-chdr
blah ... I need a drink

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