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

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

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


Revision 1.5 - (hide annotations) (download) (as text)
Fri Oct 15 10:44:57 1999 UTC (20 years, 1 month ago) by fabian
Branch: MAIN
Changes since 1.4: +3 -0 lines
File MIME type: text/x-chdr
resync 1.3: 939574072->939863113

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     #define BADNICKCHARS "-,+*=:!.@#;$%&"
34    
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     char s[512], s2[32];
215     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     if ((strlen(s) + strlen(chan->name) + strlen(network)
245     + strlen(botnetnick) + strlen(ver) + 1) >= 490) {
246     strcat(s,"++ ");
247     break; /* yeesh! */
248     }
249     strcat(s, chan->name);
250     strcat(s, ", ");
251     }
252     chan = chan->next;
253     }
254    
255     if (s[0]) {
256     s[strlen(s) - 2] = 0;
257     dprintf(idx, "*** [%s] %s <%s> (%s) [UP %s]\n", botnetnick,
258     ver, network, s, s2);
259     } else
260     dprintf(idx, "*** [%s] %s <%s> (%s) [UP %s]\n", botnetnick,
261     ver, network, BOT_NOCHANNELS, s2);
262     } 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 fabian 1.4 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     if (!strcmp(par, "all"))
419     tellallhelp(idx, "all", &fr);
420 fabian 1.4 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 segfault 1.1 tellhelp(idx, par, &fr, 0);
433     } 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     tell_verbose_uptime(idx);
528     }
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     tell_verbose_status(idx);
541     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     tell_verbose_status(idx);
548     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     module_entry *me;
627    
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 fabian 1.2 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     }
725     /* new style autosave -- drummer,07/25/1999*/
726 fabian 1.2 if ((me = module_find("console", 1, 1))) {
727 segfault 1.1 Function *func = me->funcs;
728 fabian 1.3 (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 fabian 1.2 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 fabian 1.2 strncpy(hand, newsplit(&par), sizeof(hand));
796 fabian 1.5 hand[HANDLEN] = 0;
797 fabian 1.2 strncpy(newhand, newsplit(&par), sizeof(newhand));
798 fabian 1.5 newhand[HANDLEN] = 0;
799 fabian 1.2
800     if (!hand[0] || !newhand[0]) {
801 segfault 1.1 dprintf(idx, "Usage: chnick <oldnick> <newnick>\n");
802 fabian 1.2 return;
803     }
804     for (i = 0; i < strlen(newhand); i++)
805     if ((newhand[i] <= 32) || (newhand[i] >= 127) || (newhand[i] == '@'))
806     newhand[i] = '?';
807     if (strchr(BADNICKCHARS, newhand[0]) != NULL)
808     dprintf(idx, "Bizarre quantum forces prevent nicknames from starting with %c\n",
809     newhand[0]);
810     else if (get_user_by_handle(userlist, newhand) &&
811     strcasecmp(hand, newhand))
812     dprintf(idx, "Somebody is already using %s.\n", newhand);
813     else if (!strcasecmp(newhand, botnetnick))
814     dprintf(idx, "Hey! That's MY name!\n");
815 segfault 1.1 else {
816 fabian 1.2 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     else if (change_handle(u2, newhand)) {
829     putlog(LOG_CMDS, "*", "#%s# chnick %s %s", dcc[idx].nick,
830     hand, newhand);
831     dprintf(idx, "Changed.\n");
832     } else
833     dprintf(idx, "Failed.\n");
834 segfault 1.1 }
835     }
836    
837     static void cmd_nick(struct userrec *u, int idx, char *par)
838     {
839 fabian 1.2 char oldnick[HANDLEN + 1], newnick[HANDLEN + 1];
840     int i;
841    
842     strncpy(newnick, newsplit(&par), sizeof(newnick));
843 fabian 1.5 newnick[HANDLEN] = 0;
844 segfault 1.1
845 fabian 1.2 if (!newnick[0]) {
846 segfault 1.1 dprintf(idx, "Usage: nick <new-handle>\n");
847     return;
848     }
849 fabian 1.2 for (i = 0; i < strlen(newnick); i++)
850 segfault 1.1 if ((newnick[i] <= 32) || (newnick[i] >= 127) || (newnick[i] == '@'))
851     newnick[i] = '?';
852     if (strchr(BADNICKCHARS, newnick[0]) != NULL) {
853     dprintf(idx, "Bizarre quantum forces prevent nicknames from starting with '%c'\n",
854     newnick[0]);
855     } else if (get_user_by_handle(userlist, newnick) &&
856     strcasecmp(dcc[idx].nick, newnick)) {
857     dprintf(idx, "Somebody is already using %s.\n", newnick);
858 fabian 1.2 } else if (!strcasecmp(newnick, botnetnick)) {
859     dprintf(idx, "Hey! That's MY name!\n");
860 segfault 1.1 } else {
861 fabian 1.2 strncpy(oldnick, dcc[idx].nick, sizeof(oldnick));
862 segfault 1.1 if (change_handle(u, newnick)) {
863     putlog(LOG_CMDS, "*", "#%s# nick %s", oldnick, newnick);
864     dprintf(idx, "Okay, changed.\n");
865     } else
866     dprintf(idx, "Failed.\n");
867     }
868     }
869    
870     static void cmd_chpass(struct userrec *u, int idx, char *par)
871     {
872     char *handle, *new;
873     int atr = u ? u->flags : 0, l;
874    
875     if (!par[0])
876     dprintf(idx, "Usage: chpass <handle> [password]\n");
877     else {
878     handle = newsplit(&par);
879     u = get_user_by_handle(userlist, handle);
880     if (!u)
881     dprintf(idx, "No such user.\n");
882     else if ((atr & USER_BOTMAST) && !(atr & USER_MASTER) &&
883     !(u->flags & USER_BOT))
884     dprintf(idx, "You can't change password for non-bots.\n");
885     else if ((bot_flags(u) & BOT_SHARE) && !(atr & USER_OWNER))
886     dprintf(idx, "You can't change shared bot's password.\n");
887     else if ((u->flags & USER_OWNER) && !(atr & USER_OWNER) &&
888     strcasecmp(handle, dcc[idx].nick))
889     dprintf(idx, "Can't change the bot owner's password.\n");
890 fabian 1.2 else if (isowner(handle) && strcasecmp(dcc[idx].nick, handle))
891     dprintf(idx, "Can't change the permanent bot owner's handle.\n");
892 segfault 1.1 else if (!par[0]) {
893     putlog(LOG_CMDS, "*", "#%s# chpass %s [nothing]", dcc[idx].nick,
894     handle);
895     set_user(&USERENTRY_PASS, u, NULL);
896     dprintf(idx, "Removed password.\n");
897     } else {
898     l = strlen(new = newsplit(&par));
899     if (l > 16)
900     new[16] = 0;
901     if (l < 6)
902     dprintf(idx, "Please use at least 6 characters.\n");
903     else {
904     set_user(&USERENTRY_PASS, u, new);
905     putlog(LOG_CMDS, "*", "#%s# chpass %s [something]", dcc[idx].nick,
906     handle);
907     dprintf(idx, "Changed password.\n");
908     }
909     }
910     }
911     }
912    
913     static void cmd_chaddr(struct userrec *u, int idx, char *par)
914     {
915     char *handle, *addr, *p, *q;
916     struct bot_addr *bi;
917     struct userrec *u1;
918    
919     if (!par[0]) {
920     dprintf(idx, "Usage: chaddr <botname> <address:botport#/userport#>\n");
921     return;
922     }
923     handle = newsplit(&par);
924     addr = newsplit(&par);
925     if (strlen(addr) > UHOSTLEN)
926     addr[UHOSTLEN] = 0;
927     u1 = get_user_by_handle(userlist, handle);
928     if (!u1 || !(u1->flags & USER_BOT)) {
929     dprintf(idx, "Useful only for tandem bots.\n");
930     return;
931     }
932     if ((bot_flags(u1) & BOT_SHARE) && (!u || !u->flags & USER_OWNER)) {
933     dprintf(idx, "You can't change shared bot's address.\n");
934     return;
935     }
936     putlog(LOG_CMDS, "*", "#%s# chaddr %s %s", dcc[idx].nick, handle, addr);
937     dprintf(idx, "Changed bot's address.\n");
938     bi = user_malloc(sizeof(struct bot_addr));
939    
940     q = strchr(addr, ':');
941     if (!q) {
942     bi->address = user_malloc(strlen(addr) + 1);
943     strcpy(bi->address, addr);
944     bi->telnet_port = 3333;
945     bi->relay_port = 3333;
946     } else {
947     bi->address = user_malloc(q - addr + 1);
948     strncpy(bi->address, addr, q - addr);
949     bi->address[q - addr] = 0;
950     p = q + 1;
951     bi->telnet_port = atoi(p);
952     q = strchr(p, '/');
953     if (!q) {
954     bi->relay_port = bi->telnet_port;
955     } else {
956     bi->relay_port = atoi(q + 1);
957     }
958     }
959     set_user(&USERENTRY_BOTADDR, u1, bi);
960     }
961    
962     static void cmd_comment(struct userrec *u, int idx, char *par)
963     {
964     char *handle;
965     struct userrec *u1;
966    
967     if (!par[0]) {
968     dprintf(idx, "Usage: comment <handle> <newcomment>\n");
969     return;
970     }
971     handle = newsplit(&par);
972     u1 = get_user_by_handle(userlist, handle);
973     if (!u1) {
974     dprintf(idx, "No such user!\n");
975     return;
976     }
977     if ((u1->flags & USER_OWNER) && !(u && (u->flags & USER_OWNER)) &&
978     strcasecmp(handle, dcc[idx].nick)) {
979     dprintf(idx, "Can't change comment on the bot owner.\n");
980     return;
981     }
982     putlog(LOG_CMDS, "*", "#%s# comment %s %s", dcc[idx].nick, handle, par);
983     if (!strcasecmp(par, "none")) {
984     dprintf(idx, "Okay, comment blanked.\n");
985     set_user(&USERENTRY_COMMENT, u1, NULL);
986     return;
987     }
988     dprintf(idx, "Changed comment.\n");
989     set_user(&USERENTRY_COMMENT, u1, par);
990     }
991    
992     static void cmd_restart(struct userrec *u, int idx, char *par)
993     {
994     putlog(LOG_CMDS, "*", "#%s# restart", dcc[idx].nick);
995     if (!backgrd) {
996     dprintf(idx, "You can not .restart a bot when running -n (due to tcl)\n");
997     return;
998     }
999     dprintf(idx, "Restarting.\n");
1000     if (make_userfile) {
1001     putlog(LOG_MISC, "*",
1002     "Uh, guess you don't need to create a new userfile.");
1003     make_userfile = 0;
1004     }
1005     write_userfile(-1);
1006     putlog(LOG_MISC, "*", "Restarting ...");
1007     wipe_timers(interp, &utimer);
1008     wipe_timers(interp, &timer);
1009     do_restart = idx;
1010     }
1011    
1012     static void cmd_rehash(struct userrec *u, int idx, char *par)
1013     {
1014     putlog(LOG_CMDS, "*", "#%s# rehash", dcc[idx].nick);
1015     dprintf(idx, "Rehashing.\n");
1016     if (make_userfile) {
1017     putlog(LOG_MISC, "*",
1018     "Uh, guess you don't need to create a new userfile.");
1019     make_userfile = 0;
1020     }
1021     write_userfile(-1);
1022     putlog(LOG_MISC, "*", "Rehashing ...");
1023     do_restart = -2;
1024     }
1025    
1026     static void cmd_reload(struct userrec *u, int idx, char *par)
1027     {
1028     putlog(LOG_CMDS, "*", "#%s# reload", dcc[idx].nick);
1029     dprintf(idx, "Reloading user file...\n");
1030     reload();
1031     }
1032    
1033     /* this get replaced in server.so with a version that handles the server */
1034     void cmd_die(struct userrec *u, int idx, char *par)
1035     {
1036     char s[1024];
1037    
1038     putlog(LOG_CMDS, "*", "#%s# die %s", dcc[idx].nick, par);
1039     if (par[0]) {
1040     simple_sprintf(s, "BOT SHUTDOWN (%s: %s)", dcc[idx].nick, par);
1041     } else {
1042     simple_sprintf(s, "BOT SHUTDOWN (authorized by %s)", dcc[idx].nick);
1043     }
1044     chatout("*** %s\n", s);
1045     botnet_send_chat(-1, botnetnick, s);
1046     botnet_send_bye();
1047     write_userfile(-1);
1048     simple_sprintf(s, "DIE BY %s!%s (%s)", dcc[idx].nick,
1049     dcc[idx].host, par[0] ? par : "request");
1050     fatal(s, 0);
1051     }
1052    
1053     static void cmd_debug(struct userrec *u, int idx, char *par)
1054     {
1055     if (!strcasecmp(par, "help")) {
1056     putlog(LOG_CMDS, "*", "#%s# debug help", dcc[idx].nick);
1057     debug_help(idx);
1058     } else {
1059     putlog(LOG_CMDS, "*", "#%s# debug", dcc[idx].nick);
1060     debug_mem_to_dcc(idx);
1061     }
1062     }
1063    
1064     static void cmd_simul(struct userrec *u, int idx, char *par)
1065     {
1066     char *nick;
1067     int i, ok = 0;
1068    
1069     nick = newsplit(&par);
1070     if (!par[0]) {
1071     dprintf(idx, "Usage: simul <nick> <text>\n");
1072     return;
1073     }
1074     if (isowner(nick)) {
1075     dprintf(idx, "Unable to '.simul' permanent owners.\n");
1076     return;
1077     }
1078     for (i = 0; i < dcc_total; i++)
1079     if (!strcasecmp(nick, dcc[i].nick) && !ok &&
1080     (dcc[i].type->flags & DCT_SIMUL)) {
1081     putlog(LOG_CMDS, "*", "#%s# simul %s %s", dcc[idx].nick, nick, par);
1082     if (dcc[i].type && dcc[i].type->activity) {
1083     dcc[i].type->activity(i, par, strlen(par));
1084     ok = 1;
1085     }
1086     }
1087     if (!ok)
1088     dprintf(idx, "No such user on the party line.\n");
1089     }
1090    
1091     static void cmd_link(struct userrec *u, int idx, char *par)
1092     {
1093     char *s;
1094     int i;
1095    
1096     if (!par[0]) {
1097     dprintf(idx, "Usage: link [some-bot] <new-bot>\n");
1098     return;
1099     }
1100     putlog(LOG_CMDS, "*", "#%s# link %s", dcc[idx].nick, par);
1101     s = newsplit(&par);
1102     if (!par[0] || !strcasecmp(par, botnetnick))
1103     botlink(dcc[idx].nick, idx, s);
1104     else {
1105     char x[40];
1106    
1107     i = nextbot(s);
1108     if (i < 0) {
1109     dprintf(idx, "No such bot online.\n");
1110     return;
1111     }
1112     simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1113     botnet_send_link(i, x, s, par);
1114     }
1115     }
1116    
1117     static void cmd_unlink(struct userrec *u, int idx, char *par)
1118     {
1119     int i;
1120     char *bot;
1121    
1122     if (!par[0]) {
1123     dprintf(idx, "Usage: unlink <bot> [reason]\n");
1124     return;
1125     }
1126     putlog(LOG_CMDS, "*", "#%s# unlink %s", dcc[idx].nick, par);
1127     bot = newsplit(&par);
1128     i = nextbot(bot);
1129     if (i < 0) {
1130     botunlink(idx, bot, par);
1131     return;
1132     }
1133     /* if we're directly connected to that bot, just do it
1134     * (is nike gunna sue?) */
1135     if (!strcasecmp(dcc[i].nick, bot))
1136     botunlink(idx, bot, par);
1137     else {
1138     char x[40];
1139    
1140     simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1141     botnet_send_unlink(i, x, lastbot(bot), bot, par);
1142     }
1143     }
1144    
1145     static void cmd_relay(struct userrec *u, int idx, char *par)
1146     {
1147     if (!par[0]) {
1148     dprintf(idx, "Usage: relay <bot>\n");
1149     return;
1150     }
1151     putlog(LOG_CMDS, "*", "#%s# relay %s", dcc[idx].nick, par);
1152     tandem_relay(idx, par, 0);
1153     }
1154    
1155     static void cmd_save(struct userrec *u, int idx, char *par)
1156     {
1157     putlog(LOG_CMDS, "*", "#%s# save", dcc[idx].nick);
1158     dprintf(idx, "Saving user file...\n");
1159     write_userfile(-1);
1160     }
1161    
1162     static void cmd_backup(struct userrec *u, int idx, char *par)
1163     {
1164     putlog(LOG_CMDS, "*", "#%s# backup", dcc[idx].nick);
1165     dprintf(idx, "Backing up the user file...\n");
1166     backup_userfile();
1167     }
1168    
1169     static void cmd_trace(struct userrec *u, int idx, char *par)
1170     {
1171     int i;
1172     char x[NOTENAMELEN + 11], y[11];
1173    
1174     if (!par[0]) {
1175     dprintf(idx, "Usage: trace <botname>\n");
1176     return;
1177     }
1178     if (!strcasecmp(par, botnetnick)) {
1179     dprintf(idx, "That's me! Hiya! :)\n");
1180     return;
1181     }
1182     i = nextbot(par);
1183     if (i < 0) {
1184     dprintf(idx, "Unreachable bot.\n");
1185     return;
1186     }
1187     putlog(LOG_CMDS, "*", "#%s# trace %s", dcc[idx].nick, par);
1188     simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1189     simple_sprintf(y, ":%d", now);
1190     botnet_send_trace(i, x, par, y);
1191     }
1192    
1193     static void cmd_binds(struct userrec *u, int idx, char *par)
1194     {
1195     putlog(LOG_CMDS, "*", "#%s# binds %s", dcc[idx].nick, par);
1196     tell_binds(idx, par);
1197     }
1198    
1199     static void cmd_banner(struct userrec *u, int idx, char *par)
1200     {
1201     char s[1024];
1202     int i;
1203    
1204     if (!par[0]) {
1205     dprintf(idx, "Usage: banner <message>\n");
1206     return;
1207     }
1208     simple_sprintf(s, "\007\007### Botwide:[%s] %s\n", dcc[idx].nick, par);
1209     for (i = 0; i < dcc_total; i++)
1210     if (dcc[i].type->flags & DCT_MASTER)
1211     dprintf(i, "%s", s);
1212     }
1213    
1214     /* after messing with someone's user flags, make sure the dcc-chat flags
1215     * are set correctly */
1216     int check_dcc_attrs(struct userrec *u, int oatr)
1217     {
1218     int i, stat;
1219     char *p, *q, s[121];
1220    
1221     /* if it matches someone in the owner list, make sure he/she has +n */
1222     if (!u)
1223     return 0;
1224     /* make sure default owners are +n */
1225     if (owner[0]) {
1226     q = owner;
1227     p = strchr(q, ',');
1228     while (p) {
1229     strncpy(s, q, p - q);
1230     s[p - q] = 0;
1231     rmspace(s);
1232     if (!strcasecmp(u->handle, s))
1233     u->flags = sanity_check(u->flags | USER_OWNER);
1234     q = p + 1;
1235     p = strchr(q, ',');
1236     }
1237     strcpy(s, q);
1238     rmspace(s);
1239     if (!strcasecmp(u->handle, s))
1240     u->flags = sanity_check(u->flags | USER_OWNER);
1241     }
1242     for (i = 0; i < dcc_total; i++) {
1243     if ((dcc[i].type->flags & DCT_MASTER) &&
1244     (!strcasecmp(u->handle, dcc[i].nick))) {
1245     stat = dcc[i].status;
1246     if ((dcc[i].type == &DCC_CHAT) &&
1247     ((u->flags & (USER_OP | USER_MASTER | USER_OWNER |
1248     USER_BOTMAST))
1249     != (oatr & (USER_OP | USER_MASTER | USER_OWNER |
1250     USER_BOTMAST)))) {
1251     botnet_send_join_idx(i, -1);
1252     }
1253     if ((oatr & USER_MASTER) && !(u->flags & USER_MASTER)) {
1254     struct flag_record fr =
1255     {FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
1256    
1257     dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_RAW |
1258     LOG_FILES | LOG_LEV1 | LOG_LEV2 |
1259     LOG_LEV3 | LOG_LEV4 | LOG_LEV5 |
1260     LOG_LEV6 | LOG_LEV7 | LOG_LEV8 |
1261     LOG_WALL | LOG_DEBUG);
1262     get_user_flagrec(u, &fr, NULL);
1263     if (!chan_master(fr))
1264     dcc[i].u.chat->con_flags |= (LOG_MISC | LOG_CMDS);
1265     dprintf(i, "*** POOF! ***\n");
1266     dprintf(i, "You are no longer a master on this bot.\n");
1267     }
1268     if (!(oatr & USER_MASTER) && (u->flags & USER_MASTER)) {
1269     dcc[i].u.chat->con_flags |= conmask;
1270     dprintf(i, "*** POOF! ***\n");
1271     dprintf(i, "You are now a master on this bot.\n");
1272     }
1273     if (!(oatr & USER_BOTMAST) && (u->flags & USER_BOTMAST)) {
1274     dprintf(i, "### POOF! ###\n");
1275     dprintf(i, "You are now a botnet 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 no longer a botnet master on this bot.\n");
1280     }
1281     if (!(oatr & USER_OWNER) && (u->flags & USER_OWNER)) {
1282     dprintf(i, "@@@ POOF! @@@\n");
1283     dprintf(i, "You are now an OWNER of this bot.\n");
1284     }
1285     if ((oatr & USER_OWNER) && !(u->flags & USER_OWNER)) {
1286     dprintf(i, "@@@ POOF! @@@\n");
1287     dprintf(i, "You are no longer an owner of this bot.\n");
1288     }
1289     if ((stat & STAT_PARTY) && (u->flags & USER_OP))
1290     stat &= ~STAT_PARTY;
1291     if (!(stat & STAT_PARTY) && !(u->flags & USER_OP) &&
1292     !(u->flags & USER_MASTER))
1293     stat |= STAT_PARTY;
1294     if ((stat & STAT_CHAT) && !(u->flags & USER_PARTY) &&
1295     !(u->flags & USER_MASTER) &&
1296     (!(u->flags & USER_OP) || require_p))
1297     stat &= ~STAT_CHAT;
1298     if ((dcc[i].type->flags & DCT_FILES) && !(stat & STAT_CHAT) &&
1299     ((u->flags & USER_MASTER) || (u->flags & USER_PARTY) ||
1300     ((u->flags & USER_OP) && !require_p)))
1301     stat |= STAT_CHAT;
1302     dcc[i].status = stat;
1303     /* check if they no longer have access to wherever they are */
1304     /* DON'T kick someone off the party line just cuz they lost +p
1305     * (pinvite script removes +p after 5 mins automatically) */
1306     if ((dcc[i].type->flags & DCT_FILES) && !(u->flags & USER_XFER) &&
1307     !(u->flags & USER_MASTER)) {
1308     dprintf(i, "-+- POOF! -+-\n");
1309     dprintf(i, "You no longer have file area access.\n\n");
1310     putlog(LOG_MISC, "*", "DCC user [%s]%s removed from file system",
1311     dcc[i].nick, dcc[i].host);
1312     if (dcc[i].status & STAT_CHAT) {
1313     struct chat_info *ci;
1314    
1315     ci = dcc[i].u.file->chat;
1316     nfree(dcc[i].u.file);
1317     dcc[i].u.chat = ci;
1318     dcc[i].status &= (~STAT_CHAT);
1319     dcc[i].type = &DCC_CHAT;
1320     if (dcc[i].u.chat->channel >= 0) {
1321     chanout_but(-1, dcc[i].u.chat->channel,
1322     "*** %s has returned.\n", dcc[i].nick);
1323     context;
1324     if (dcc[i].u.chat->channel < 100000)
1325     botnet_send_join_idx(i, -1);
1326     }
1327     } else {
1328     killsock(dcc[i].sock);
1329     dcc[i].sock = (long) dcc[i].type;
1330     dcc[i].type = &DCC_LOST;
1331     }
1332     }
1333     }
1334     if ((dcc[i].type == &DCC_BOT) && !strcasecmp(u->handle, dcc[i].nick)) {
1335     if ((dcc[i].status & STAT_LEAF) && !(u->flags & BOT_LEAF))
1336     dcc[i].status &= ~(STAT_LEAF | STAT_WARNED);
1337     if (!(dcc[i].status & STAT_LEAF) && (u->flags & BOT_LEAF))
1338     dcc[i].status |= STAT_LEAF;
1339     }
1340     }
1341     return u->flags;
1342     }
1343    
1344     int check_dcc_chanattrs(struct userrec *u, char *chname, int chflags,
1345     int ochatr)
1346     {
1347     int i, found = 0, atr = u ? u->flags : 0;
1348     struct chanset_t *chan;
1349    
1350     if (!u)
1351     return 0;
1352     chan = chanset;
1353     for (i = 0; i < dcc_total; i++) {
1354     if ((dcc[i].type->flags & DCT_MASTER) &&
1355     !strcasecmp(u->handle, dcc[i].nick)) {
1356     if ((dcc[i].type == &DCC_CHAT) &&
1357     ((chflags & (USER_OP | USER_MASTER | USER_OWNER))
1358     != (ochatr & (USER_OP | USER_MASTER | USER_OWNER))))
1359     botnet_send_join_idx(i, -1);
1360     if ((ochatr & USER_MASTER) && !(chflags & USER_MASTER)) {
1361     if (!(atr & USER_MASTER))
1362     dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS);
1363     dprintf(i, "*** POOF! ***\n");
1364     dprintf(i, "You are no longer a master on %s.\n", chname);
1365     }
1366     if (!(ochatr & USER_MASTER) && (chflags & USER_MASTER)) {
1367     dcc[i].u.chat->con_flags |= conmask;
1368     if (!(atr & USER_MASTER))
1369     dcc[i].u.chat->con_flags &=
1370     ~(LOG_LEV1 | LOG_LEV2 | LOG_LEV3 | LOG_LEV4 |
1371     LOG_LEV5 | LOG_LEV6 | LOG_LEV7 | LOG_LEV8 |
1372     LOG_RAW | LOG_DEBUG | LOG_WALL | LOG_FILES | LOG_SRVOUT);
1373     dprintf(i, "*** POOF! ***\n");
1374     dprintf(i, "You are now a master on %s.\n", chname);
1375     }
1376     if (!(ochatr & USER_OWNER) && (chflags & USER_OWNER)) {
1377     dprintf(i, "@@@ POOF! @@@\n");
1378     dprintf(i, "You are now an OWNER of %s.\n", chname);
1379     }
1380     if ((ochatr & USER_OWNER) && !(chflags & USER_OWNER)) {
1381     dprintf(i, "@@@ POOF! @@@\n");
1382     dprintf(i, "You are no longer an owner of %s.\n", chname);
1383     }
1384     if (((ochatr & (USER_OP | USER_MASTER | USER_OWNER)) &&
1385     (!(chflags & (USER_OP | USER_MASTER | USER_OWNER)))) ||
1386     ((chflags & (USER_OP | USER_MASTER | USER_OWNER)) &&
1387     (!(ochatr & (USER_OP | USER_MASTER | USER_OWNER))))) {
1388     struct flag_record fr =
1389     {FR_CHAN, 0, 0, 0, 0, 0};
1390    
1391     while (chan && !found) {
1392     get_user_flagrec(u, &fr, chan->name);
1393     if (fr.chan & (USER_OP | USER_MASTER | USER_OWNER))
1394     found = 1;
1395     else
1396     chan = chan->next;
1397     }
1398     if (!chan)
1399     chan = chanset;
1400     if (chan)
1401     strcpy(dcc[i].u.chat->con_chan, chan->name);
1402     else
1403     strcpy(dcc[i].u.chat->con_chan, "*");
1404     }
1405     }
1406     }
1407     return chflags;
1408     }
1409    
1410     static void cmd_chattr(struct userrec *u, int idx, char *par)
1411     {
1412     char *hand, *tmpchg = NULL, *chg = NULL, work[1024];
1413     struct chanset_t *chan = NULL;
1414     struct userrec *u2;
1415 fabian 1.2 struct flag_record pls = {0, 0, 0, 0, 0, 0},
1416     mns = {0, 0, 0, 0, 0, 0},
1417     user = {0, 0, 0, 0, 0, 0};
1418 segfault 1.1 module_entry *me;
1419     int fl = -1, of = 0, ocf = 0;
1420    
1421     if (!par[0]) {
1422     dprintf(idx, "Usage: chattr <handle> [changes] [channel]\n");
1423     return;
1424     }
1425     hand = newsplit(&par);
1426     u2 = get_user_by_handle(userlist, hand);
1427     if ((hand[0] == '*') || !u2) {
1428     dprintf(idx, "No such user!\n");
1429     return;
1430     }
1431     if (par[0] && ((strchr(CHANMETA, par[0]) == NULL) || par[0]=='+')) {
1432     chg = newsplit(&par);
1433     if (!par[0] && strpbrk(chg, "&|"))
1434     par = dcc[idx].u.chat->con_chan;
1435     else if (par[0] && !strpbrk(chg, "&|")) {
1436     context;
1437     tmpchg = nmalloc(sizeof(chg)+1);
1438     sprintf(tmpchg,"|%s",chg);
1439     chg = nmalloc(sizeof(tmpchg));
1440     strcpy(chg,tmpchg);
1441     }
1442     }
1443     chan = findchan(par);
1444     if (!chan && par[0] && (par[0] != '*')) {
1445     dprintf(idx, "No channel record for %s.\n", par);
1446     if (tmpchg) {
1447     nfree(chg); nfree(tmpchg);
1448     }
1449     return;
1450     }
1451     user.match = FR_GLOBAL;
1452     if (chan)
1453     user.match |= FR_CHAN;
1454     get_user_flagrec(u, &user, chan ? chan->name : 0);
1455     if (!chan && !glob_botmast(user)) {
1456     dprintf(idx, "You do not have Bot Master privileges.\n");
1457     if (tmpchg) {
1458     nfree(chg); nfree(tmpchg);
1459     }
1460     return;
1461     }
1462     if (chan && !glob_master(user) && !chan_master(user)) {
1463     dprintf(idx, "You do not have channel master privileges for channel %s\n",
1464     par);
1465     if (tmpchg) {
1466     nfree(chg); nfree(tmpchg);
1467     }
1468     return;
1469     }
1470     user.match &= fl;
1471     if (chg) {
1472     pls.match = user.match;
1473     break_down_flags(chg, &pls, &mns);
1474     /* no-one can change these flags on-the-fly */
1475     pls.global &=~(USER_BOT);
1476     mns.global &=~(USER_BOT);
1477    
1478     if (chan) {
1479     pls.chan &= ~(BOT_SHARE);
1480     mns.chan &= ~(BOT_SHARE);
1481     }
1482     if (!glob_owner(user)) {
1483     pls.global &=~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1484     mns.global &=~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1485    
1486     if (chan) {
1487     pls.chan &= ~USER_OWNER;
1488     mns.chan &= ~USER_OWNER;
1489     }
1490     if (!glob_master(user)) {
1491     pls.global &=USER_PARTY | USER_XFER;
1492     mns.global &=USER_PARTY | USER_XFER;
1493    
1494     if (!glob_botmast(user)) {
1495     pls.global = 0;
1496     mns.global = 0;
1497     }
1498     }
1499     }
1500     if (chan && !chan_owner(user) && !glob_owner(user)) {
1501     pls.chan &= ~USER_MASTER;
1502     mns.chan &= ~USER_MASTER;
1503     if (!chan_master(user) && !glob_master(user)) {
1504     pls.chan = 0;
1505     mns.chan = 0;
1506     }
1507     }
1508     get_user_flagrec(u2, &user, par);
1509     if (user.match & FR_GLOBAL) {
1510     of = user.global;
1511     user.global = sanity_check((user.global |pls.global) &~mns.global);
1512    
1513     user.udef_global = (user.udef_global | pls.udef_global)
1514     & ~mns.udef_global;
1515     }
1516     if (chan) {
1517     ocf = user.chan;
1518     user.chan = chan_sanity_check((user.chan | pls.chan) & ~mns.chan,
1519     user.global);
1520    
1521     user.udef_chan = (user.udef_chan | pls.udef_chan) & ~mns.udef_chan;
1522     }
1523     set_user_flagrec(u2, &user, par);
1524     }
1525     if (chan)
1526     putlog(LOG_CMDS, "*", "#%s# (%s) chattr %s %s",
1527     dcc[idx].nick, chan ? chan->name : "*", hand, chg ? chg : "");
1528     else
1529     putlog(LOG_CMDS, "*", "#%s# chattr %s %s", dcc[idx].nick, hand,
1530     chg ? chg : "");
1531     /* get current flags and display them */
1532     if (user.match & FR_GLOBAL) {
1533     user.match = FR_GLOBAL;
1534     if (chg)
1535     check_dcc_attrs(u2, of);
1536     get_user_flagrec(u2, &user, NULL);
1537     build_flags(work, &user, NULL);
1538     if (work[0] != '-')
1539     dprintf(idx, "Global flags for %s are now +%s\n", hand, work);
1540     else
1541     dprintf(idx, "No global flags for %s.\n", hand);
1542     }
1543     if (chan) {
1544     user.match = FR_CHAN;
1545     get_user_flagrec(u2, &user, par);
1546     user.chan &= ~BOT_SHARE;
1547     if (chg)
1548     check_dcc_chanattrs(u2, chan->name, user.chan, ocf);
1549     build_flags(work, &user, NULL);
1550     if (work[0] != '-')
1551     dprintf(idx, "Channel flags for %s on %s are now +%s\n", hand,
1552     chan->name, work);
1553     else
1554     dprintf(idx, "No flags for %s on %s.\n", hand, chan->name);
1555     if ((me = module_find("irc", 0, 0))) {
1556     Function *func = me->funcs;
1557    
1558     if (chan)
1559 fabian 1.2 (func[IRC_RECHECK_CHANNEL]) (chan, 0);
1560 segfault 1.1 }
1561     }
1562     if (tmpchg) {
1563     nfree(chg); nfree(tmpchg);
1564     }
1565     }
1566    
1567     static void cmd_botattr(struct userrec *u, int idx, char *par)
1568     {
1569     char *hand, *chg = NULL, work[1024];
1570     struct chanset_t *chan = NULL;
1571     struct userrec *u2;
1572     struct flag_record pls =
1573     {0, 0, 0, 0, 0, 0}, mns =
1574     {0, 0, 0, 0, 0, 0}, user =
1575     {0, 0, 0, 0, 0, 0};
1576     int idx2;
1577    
1578     if (!par[0]) {
1579     dprintf(idx, "Usage: botattr <handle> [changes] [channel]\n");
1580     return;
1581     }
1582     hand = newsplit(&par);
1583     u2 = get_user_by_handle(userlist, hand);
1584     if ((hand[0] == '*') || !u2 || !(u2->flags & USER_BOT)) {
1585     dprintf(idx, "No such bot!\n");
1586     return;
1587     }
1588     for (idx2 = 0; idx2 < dcc_total; idx2++)
1589     if (!strcasecmp(dcc[idx2].nick, hand))
1590     break;
1591     if (idx2 != dcc_total) {
1592     dprintf(idx, "You may not change the attributes of a linked bot.\n");
1593     return;
1594     }
1595     if (par[0] && ((strchr(CHANMETA, par[0]) == NULL) || par[0]=='+')) {
1596     chg = newsplit(&par);
1597     if (!par[0] && strpbrk(chg, "|&"))
1598     par = dcc[idx].u.chat->con_chan;
1599     }
1600     if (!(chan = findchan(par)) && par[0]) {
1601     dprintf(idx, "No channel record for %s.\n", par);
1602     return;
1603     }
1604     user.match = FR_GLOBAL;
1605     get_user_flagrec(u, &user, chan ? chan->name : 0);
1606     if (!glob_botmast(user)) {
1607     dprintf(idx, "You do not have Bot Master privileges.\n");
1608     return;
1609     }
1610     if (chg) {
1611     user.match = FR_BOT | (chan ? FR_CHAN : 0);
1612     pls.match = user.match;
1613     break_down_flags(chg, &pls, &mns);
1614     /* no-one can change these flags on-the-fly */
1615     pls.global &=~BOT_BOT;
1616     mns.global &=~BOT_BOT;
1617    
1618     if (chan && glob_owner(user)) {
1619     pls.chan &= BOT_SHARE;
1620     mns.chan &= BOT_SHARE;
1621     } else {
1622     pls.chan = 0;
1623     mns.chan = 0;
1624     }
1625     if (!glob_owner(user)) {
1626     pls.bot &= ~(BOT_SHARE | BOT_GLOBAL);
1627     mns.bot &= ~(BOT_SHARE | BOT_GLOBAL);
1628     }
1629     user.match = FR_BOT | (chan ? FR_CHAN : 0);
1630     get_user_flagrec(u2, &user, par);
1631     user.bot = (user.bot | pls.bot) & ~mns.bot;
1632     if ((user.bot & BOT_SHARE) == BOT_SHARE)
1633     user.bot &= ~BOT_SHARE;
1634     if (chan)
1635     user.chan = (user.chan | pls.chan) & ~mns.chan;
1636     set_user_flagrec(u2, &user, par);
1637     }
1638     if (chan)
1639     putlog(LOG_CMDS, "*", "#%s# (%s) botattr %s %s",
1640     dcc[idx].nick, chan->name, hand, chg ? chg : "");
1641     else
1642     putlog(LOG_CMDS, "*", "#%s# botattr %s %s", dcc[idx].nick, hand,
1643     chg ? chg : "");
1644     /* get current flags and display them */
1645     if (!chan || pls.bot || mns.bot) {
1646     user.match = FR_BOT;
1647     get_user_flagrec(u2, &user, NULL);
1648     build_flags(work, &user, NULL);
1649     if (work[0] != '-')
1650     dprintf(idx, "Bot flags for %s are now +%s\n", hand, work);
1651     else
1652     dprintf(idx, "No bot flags for %s.\n", hand);
1653     }
1654     if (chan) {
1655     user.match = FR_CHAN;
1656     get_user_flagrec(u2, &user, par);
1657     user.chan &= BOT_SHARE;
1658     build_flags(work, &user, NULL);
1659     if (work[0] != '-')
1660     dprintf(idx, "Bot flags for %s on %s are now +%s\n", hand,
1661     chan->name, work);
1662     else
1663     dprintf(idx, "No bot flags for %s on %s.\n", hand, chan->name);
1664     }
1665     }
1666    
1667     static void cmd_chat(struct userrec *u, int idx, char *par)
1668     {
1669 fabian 1.2 char *arg;
1670 segfault 1.1 int newchan, oldchan;
1671 fabian 1.2 module_entry *me;
1672 segfault 1.1
1673 fabian 1.2 if (!par[0]) {
1674     oldchan = dcc[idx].u.chat->channel;
1675     switch (oldchan) {
1676     case -1:
1677     dprintf(idx, "You're currently not in chat mode\n");
1678     break;
1679     case 0:
1680     dprintf(idx, "You're currently on the party line\n");
1681     break;
1682     default:
1683     dprintf(idx, "You're currently on channel %s%d!\n",
1684     (oldchan < 100000) ? "" : "*", oldchan % 100000);
1685     break;
1686     }
1687     return;
1688     }
1689    
1690     arg = newsplit(&par);
1691    
1692     if (!strcasecmp(arg, "off")) {
1693 segfault 1.1 /* turn chat off */
1694 fabian 1.2 if (dcc[idx].u.chat->channel < 0) {
1695 segfault 1.1 dprintf(idx, "You weren't in chat anyway!\n");
1696 fabian 1.2 return;
1697     } else {
1698 segfault 1.1 dprintf(idx, "Leaving chat mode...\n");
1699     check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
1700     dcc[idx].u.chat->channel);
1701     chanout_but(-1, dcc[idx].u.chat->channel,
1702     "*** %s left the party line.\n",
1703     dcc[idx].nick);
1704     context;
1705     if (dcc[idx].u.chat->channel < 100000)
1706     botnet_send_part_idx(idx, "");
1707     }
1708     dcc[idx].u.chat->channel = (-