/[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.26 - (hide annotations) (download) (as text)
Mon Nov 1 17:01:00 1999 UTC (19 years, 10 months ago) by guppy
Branch: MAIN
Changes since 1.25: +0 -2 lines
File MIME type: text/x-chdr
blah last patches I hope

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