/[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.13 - (hide annotations) (download) (as text)
Fri Dec 17 18:40:22 1999 UTC (19 years, 11 months ago) by fabian
Branch: MAIN
Changes since 1.12: +2 -4 lines
File MIME type: text/x-chdr
tothwolf's assert-nulls patch

1 segfault 1.1 /*
2     * cmds.c -- handles:
3     * commands from a user via dcc
4     * (split in 2, this portion contains no-irc commands)
5     * *
6     * dprintf'ized, 3nov1995
7     */
8     /*
9     * This file is part of the eggdrop source code
10     * copyright (c) 1997 Robey Pointer
11     * and is distributed according to the GNU general public license.
12     * For full details, read the top of 'main.c' or the file called
13     * COPYING that was distributed with this code.
14     */
15    
16     #include "main.h"
17     #include "tandem.h"
18     #include "modules.h"
19     #include <ctype.h>
20    
21     extern struct chanset_t *chanset;
22     extern struct dcc_t *dcc;
23     extern struct userrec *userlist;
24     extern tcl_timer_t *timer, *utimer;
25     extern int dcc_total, remote_boots, backgrd, make_userfile, do_restart;
26     extern int conmask, require_p;
27     extern int must_be_owner;
28     extern Tcl_Interp *interp;
29     extern char botnetnick[], origbotname[], ver[];
30     extern char network[], owner[], spaces[];
31     extern time_t now, online_since;
32    
33     /* 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 fabian 1.8 dprintf(idx, "(Added hostmask for %s from %s)\n", nick, chan->dname);
55 segfault 1.1 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     char s[512], s2[32];
213     struct chanset_t *chan;
214     time_t now2;
215     int hr, min;
216    
217 fabian 1.12 Context;
218 segfault 1.1 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 fabian 1.8 if ((strlen(s) + strlen(chan->dname) + strlen(network)
243 segfault 1.1 + strlen(botnetnick) + strlen(ver) + 1) >= 490) {
244     strcat(s,"++ ");
245     break; /* yeesh! */
246     }
247 fabian 1.8 strcat(s, chan->dname);
248 segfault 1.1 strcat(s, ", ");
249     }
250     chan = chan->next;
251     }
252    
253     if (s[0]) {
254     s[strlen(s) - 2] = 0;
255     dprintf(idx, "*** [%s] %s <%s> (%s) [UP %s]\n", botnetnick,
256     ver, network, s, s2);
257     } else
258     dprintf(idx, "*** [%s] %s <%s> (%s) [UP %s]\n", botnetnick,
259     ver, network, BOT_NOCHANNELS, s2);
260     } 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 fabian 1.4 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     if (!strcmp(par, "all"))
417     tellallhelp(idx, "all", &fr);
418 fabian 1.4 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 segfault 1.1 tellhelp(idx, par, &fr, 0);
431     } 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     tell_verbose_uptime(idx);
526     }
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     tell_verbose_status(idx);
539     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     tell_verbose_status(idx);
546     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 fabian 1.7 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 fabian 1.8 struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
623 segfault 1.1 module_entry *me;
624    
625     if (!par[0]) {
626     dprintf(idx, "Your console is %s: %s (%s)\n",
627     dcc[idx].u.chat->con_chan,
628     masktype(dcc[idx].u.chat->con_flags),
629     maskname(dcc[idx].u.chat->con_flags));
630     return;
631     }
632     get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
633     strcpy(s1, par);
634     nick = newsplit(&par);
635 fabian 1.6 /* don't remove '+' as someone couldn't have '+' in CHANMETA cause
636     * he doesn't use br0ken IRCnet ++rtc */
637     if (nick[0] && !strchr(CHANMETA "+-*", nick[0]) && glob_master(fr)) {
638 segfault 1.1 for (i = 0; i < dcc_total; i++)
639     if (!strcasecmp(nick, dcc[i].nick) &&
640     (dcc[i].type == &DCC_CHAT) && (!ok)) {
641     ok = 1;
642     dest = i;
643     }
644     if (!ok) {
645     dprintf(idx, "No such user on the party line!\n");
646     return;
647     }
648     nick[0] = 0;
649     } else
650     dest = idx;
651     if (!nick[0])
652     nick = newsplit(&par);
653 fabian 1.10 /* ugly hack for modeless channels -- rtc */
654 fabian 1.8 if ((nick [0] == '+' && findchan_by_dname(nick)) ||
655 fabian 1.6 (nick [0] != '+' && strchr(CHANMETA "*", nick[0]))) {
656 fabian 1.8 if (strcmp(nick, "*") && !findchan_by_dname(nick)) {
657 segfault 1.1 dprintf(idx, "Invalid console channel: %s\n", nick);
658     return;
659     }
660     get_user_flagrec(u, &fr, nick);
661     if (!chan_op(fr) && !(glob_op(fr) && !chan_deop(fr))) {
662     dprintf(idx, "You don't have op or master access to channel %s\n",
663     nick);
664     return;
665     }
666 fabian 1.8 strncpy(dcc[dest].u.chat->con_chan, nick, 81);
667 segfault 1.1 dcc[dest].u.chat->con_chan[80] = 0;
668     nick[0] = 0;
669     if ((dest == idx) && !glob_master(fr) && !chan_master(fr))
670     /* consoling to another channel for self */
671     dcc[dest].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_WALL);
672     }
673     if (!nick[0])
674     nick = newsplit(&par);
675     pls = 1;
676     if (nick[0]) {
677     if ((nick[0] != '+') && (nick[0] != '-'))
678     dcc[dest].u.chat->con_flags = 0;
679     for (; *nick; nick++) {
680     if (*nick == '+')
681     pls = 1;
682     else if (*nick == '-')
683     pls = 0;
684     else {
685     s[0] = *nick;
686     s[1] = 0;
687     md = logmodes(s);
688     if ((dest == idx) && !glob_master(fr) && pls) {
689     if (chan_master(fr))
690     md &= ~(LOG_FILES | LOG_LEV1 | LOG_LEV2 | LOG_LEV3 |
691     LOG_LEV4 | LOG_LEV5 | LOG_LEV6 | LOG_LEV7 |
692     LOG_LEV8 | LOG_DEBUG);
693     else
694     md &= ~(LOG_MISC | LOG_CMDS | LOG_FILES | LOG_LEV1 |
695     LOG_LEV2 | LOG_LEV3 | LOG_LEV4 | LOG_LEV5 |
696     LOG_LEV6 | LOG_LEV7 | LOG_LEV8 | LOG_WALL |
697     LOG_DEBUG);
698     }
699     if (!glob_owner(fr) && pls)
700     md &= ~(LOG_RAW | LOG_SRVOUT | LOG_BOTNET | LOG_BOTSHARE);
701     if (!glob_botmast(fr) && pls)
702     md &= ~LOG_BOTS;
703     if (pls)
704     dcc[dest].u.chat->con_flags |= md;
705     else
706     dcc[dest].u.chat->con_flags &= ~md;
707     }
708     }
709     }
710     putlog(LOG_CMDS, "*", "#%s# console %s", dcc[idx].nick, s1);
711     if (dest == idx) {
712     dprintf(idx, "Set your console to %s: %s (%s)\n",
713     dcc[idx].u.chat->con_chan,
714     masktype(dcc[idx].u.chat->con_flags),
715     maskname(dcc[idx].u.chat->con_flags));
716     } else {
717     dprintf(idx, "Set console of %s to %s: %s (%s)\n", dcc[dest].nick,
718     dcc[dest].u.chat->con_chan,
719     masktype(dcc[dest].u.chat->con_flags),
720     maskname(dcc[dest].u.chat->con_flags));
721     dprintf(dest, "%s set your console to %s: %s (%s)\n", dcc[idx].nick,
722     dcc[dest].u.chat->con_chan,
723     masktype(dcc[dest].u.chat->con_flags),
724     maskname(dcc[dest].u.chat->con_flags));
725     }
726     /* new style autosave -- drummer,07/25/1999*/
727 fabian 1.2 if ((me = module_find("console", 1, 1))) {
728 segfault 1.1 Function *func = me->funcs;
729 fabian 1.3 (func[CONSOLE_DOSTORE]) (dest);
730 segfault 1.1 }
731     }
732    
733     static void cmd_pls_bot(struct userrec *u, int idx, char *par)
734     {
735     char *handle, *addr, *p, *q, *host;
736     struct userrec *u1;
737     struct bot_addr *bi;
738    
739     if (!par[0])
740     dprintf(idx, "Usage: +bot <handle> <address[:telnet-port[/relay-port]]> [host]\n");
741     else {
742     handle = newsplit(&par);
743     addr = newsplit(&par);
744     if (strlen(handle) > HANDLEN)
745     handle[HANDLEN] = 0; /* max len = XX .. for the moment :) */
746     if (get_user_by_handle(userlist, handle))
747     dprintf(idx, "Someone already exists by that name.\n");
748 fabian 1.6 else if (strchr(BADHANDCHARS, handle[0]) != NULL)
749 segfault 1.1 dprintf(idx, "You can't start a botnick with '%c'.\n", handle[0]);
750     else {
751     if (strlen(addr) > 60)
752     addr[60] = 0;
753     putlog(LOG_CMDS, "*", "#%s# +bot %s %s", dcc[idx].nick, handle, addr);
754     userlist = adduser(userlist, handle, "none", "-", USER_BOT);
755     u1 = get_user_by_handle(userlist, handle);
756     bi = user_malloc(sizeof(struct bot_addr));
757    
758     q = strchr(addr, ':');
759     if (!q) {
760     bi->address = user_malloc(strlen(addr) + 1);
761     strcpy(bi->address, addr);
762     bi->telnet_port = 3333;
763     bi->relay_port = 3333;
764     } else {
765     bi->address = user_malloc(q - addr + 1);
766     strncpy(bi->address, addr, q - addr);
767     bi->address[q - addr] = 0;
768     p = q + 1;
769     bi->telnet_port = atoi(p);
770     q = strchr(p, '/');
771     if (!q) {
772     bi->relay_port = bi->telnet_port;
773     } else {
774     bi->relay_port = atoi(q + 1);
775     }
776     }
777     set_user(&USERENTRY_BOTADDR, u1, bi);
778     dprintf(idx, "Added bot '%s' with address '%s' and no password.\n",
779     handle, addr);
780     host = newsplit(&par);
781     if (host[0]) {
782     addhost_by_handle(handle, host);
783     } else if (!add_bot_hostmask(idx, handle))
784     dprintf(idx, "You'll want to add a hostmask if this bot will ever %s",
785     "be on any channels that I'm on.\n");
786     }
787     }
788     }
789    
790     static void cmd_chnick(struct userrec *u, int idx, char *par)
791     {
792 fabian 1.2 char hand[HANDLEN + 1], newhand[HANDLEN + 1];
793 segfault 1.1 int i, atr = u ? u->flags : 0, atr2;
794     struct userrec *u2;
795    
796 fabian 1.2 strncpy(hand, newsplit(&par), sizeof(hand));
797 fabian 1.5 hand[HANDLEN] = 0;
798 fabian 1.2 strncpy(newhand, newsplit(&par), sizeof(newhand));
799 fabian 1.5 newhand[HANDLEN] = 0;
800 fabian 1.2
801     if (!hand[0] || !newhand[0]) {
802 segfault 1.1 dprintf(idx, "Usage: chnick <oldnick> <newnick>\n");
803 fabian 1.2 return;
804     }
805     for (i = 0; i < strlen(newhand); i++)
806     if ((newhand[i] <= 32) || (newhand[i] >= 127) || (newhand[i] == '@'))
807     newhand[i] = '?';
808 fabian 1.6 if (strchr(BADHANDCHARS, newhand[0]) != NULL)
809 fabian 1.2 dprintf(idx, "Bizarre quantum forces prevent nicknames from starting with %c\n",
810     newhand[0]);
811     else if (get_user_by_handle(userlist, newhand) &&
812     strcasecmp(hand, newhand))
813     dprintf(idx, "Somebody is already using %s.\n", newhand);
814 segfault 1.1 else {
815 fabian 1.2 u2 = get_user_by_handle(userlist, hand);
816     atr2 = u2 ? u2->flags : 0;
817     if ((atr & USER_BOTMAST) && !(atr & USER_MASTER) &&
818     !(atr2 & USER_BOT))
819     dprintf(idx, "You can't change nick for non-bots.\n");
820     else if ((bot_flags(u2) & BOT_SHARE) && !(atr & USER_OWNER))
821     dprintf(idx, "You can't change shared bot's nick.\n");
822     else if ((atr2 & USER_OWNER) && !(atr & USER_OWNER) &&
823     strcasecmp(dcc[idx].nick, hand))
824     dprintf(idx, "Can't change the bot owner's handle.\n");
825     else if (isowner(hand) && strcasecmp(dcc[idx].nick, hand))
826     dprintf(idx, "Can't change the permanent bot owner's handle.\n");
827 fabian 1.6 else if (!strcasecmp(newhand, botnetnick) && (!(atr2 & USER_BOT) ||
828     nextbot(hand) != -1))
829     dprintf(idx, "Hey! That's MY name!\n");
830 fabian 1.2 else if (change_handle(u2, newhand)) {
831     putlog(LOG_CMDS, "*", "#%s# chnick %s %s", dcc[idx].nick,
832     hand, newhand);
833     dprintf(idx, "Changed.\n");
834     } else
835     dprintf(idx, "Failed.\n");
836 segfault 1.1 }
837     }
838    
839     static void cmd_nick(struct userrec *u, int idx, char *par)
840     {
841 fabian 1.2 char oldnick[HANDLEN + 1], newnick[HANDLEN + 1];
842     int i;
843    
844 fabian 1.6 strncpy(newnick, newsplit(&par), HANDLEN);
845 fabian 1.5 newnick[HANDLEN] = 0;
846 segfault 1.1
847 fabian 1.2 if (!newnick[0]) {
848 segfault 1.1 dprintf(idx, "Usage: nick <new-handle>\n");
849     return;
850     }
851 fabian 1.2 for (i = 0; i < strlen(newnick); i++)
852 segfault 1.1 if ((newnick[i] <= 32) || (newnick[i] >= 127) || (newnick[i] == '@'))
853     newnick[i] = '?';
854 fabian 1.6 if (strchr(BADHANDCHARS, newnick[0]) != NULL) {
855 segfault 1.1 dprintf(idx, "Bizarre quantum forces prevent nicknames from starting with '%c'\n",
856     newnick[0]);
857     } else if (get_user_by_handle(userlist, newnick) &&
858     strcasecmp(dcc[idx].nick, newnick)) {
859     dprintf(idx, "Somebody is already using %s.\n", newnick);
860 fabian 1.2 } else if (!strcasecmp(newnick, botnetnick)) {
861     dprintf(idx, "Hey! That's MY name!\n");
862 segfault 1.1 } else {
863 fabian 1.6 strncpy(oldnick, dcc[idx].nick, HANDLEN);
864     oldnick[HANDLEN] = 0;
865 segfault 1.1 if (change_handle(u, newnick)) {
866     putlog(LOG_CMDS, "*", "#%s# nick %s", oldnick, newnick);
867     dprintf(idx, "Okay, changed.\n");
868     } else
869     dprintf(idx, "Failed.\n");
870     }
871     }
872    
873     static void cmd_chpass(struct userrec *u, int idx, char *par)
874     {
875     char *handle, *new;
876     int atr = u ? u->flags : 0, l;
877    
878     if (!par[0])
879     dprintf(idx, "Usage: chpass <handle> [password]\n");
880     else {
881     handle = newsplit(&par);
882     u = get_user_by_handle(userlist, handle);
883     if (!u)
884     dprintf(idx, "No such user.\n");
885     else if ((atr & USER_BOTMAST) && !(atr & USER_MASTER) &&
886     !(u->flags & USER_BOT))
887     dprintf(idx, "You can't change password for non-bots.\n");
888     else if ((bot_flags(u) & BOT_SHARE) && !(atr & USER_OWNER))
889     dprintf(idx, "You can't change shared bot's password.\n");
890     else if ((u->flags & USER_OWNER) && !(atr & USER_OWNER) &&
891     strcasecmp(handle, dcc[idx].nick))
892     dprintf(idx, "Can't change the bot owner's password.\n");
893 fabian 1.2 else if (isowner(handle) && strcasecmp(dcc[idx].nick, handle))
894     dprintf(idx, "Can't change the permanent bot owner's handle.\n");
895 segfault 1.1 else if (!par[0]) {
896     putlog(LOG_CMDS, "*", "#%s# chpass %s [nothing]", dcc[idx].nick,
897     handle);
898     set_user(&USERENTRY_PASS, u, NULL);
899     dprintf(idx, "Removed password.\n");
900     } else {
901     l = strlen(new = newsplit(&par));
902     if (l > 16)
903     new[16] = 0;
904     if (l < 6)
905     dprintf(idx, "Please use at least 6 characters.\n");
906     else {
907     set_user(&USERENTRY_PASS, u, new);
908     putlog(LOG_CMDS, "*", "#%s# chpass %s [something]", dcc[idx].nick,
909     handle);
910     dprintf(idx, "Changed password.\n");
911     }
912     }
913     }
914     }
915    
916     static void cmd_chaddr(struct userrec *u, int idx, char *par)
917     {
918     char *handle, *addr, *p, *q;
919     struct bot_addr *bi;
920     struct userrec *u1;
921    
922     if (!par[0]) {
923     dprintf(idx, "Usage: chaddr <botname> <address:botport#/userport#>\n");
924     return;
925     }
926     handle = newsplit(&par);
927     addr = newsplit(&par);
928 fabian 1.6 if (strlen(addr) > UHOSTMAX)
929     addr[UHOSTMAX] = 0;
930 segfault 1.1 u1 = get_user_by_handle(userlist, handle);
931     if (!u1 || !(u1->flags & USER_BOT)) {
932     dprintf(idx, "Useful only for tandem bots.\n");
933     return;
934     }
935     if ((bot_flags(u1) & BOT_SHARE) && (!u || !u->flags & USER_OWNER)) {
936     dprintf(idx, "You can't change shared bot's address.\n");
937     return;
938     }
939     putlog(LOG_CMDS, "*", "#%s# chaddr %s %s", dcc[idx].nick, handle, addr);
940     dprintf(idx, "Changed bot's address.\n");
941     bi = user_malloc(sizeof(struct bot_addr));
942    
943     q = strchr(addr, ':');
944     if (!q) {
945     bi->address = user_malloc(strlen(addr) + 1);
946     strcpy(bi->address, addr);
947     bi->telnet_port = 3333;
948     bi->relay_port = 3333;
949     } else {
950     bi->address = user_malloc(q - addr + 1);
951     strncpy(bi->address, addr, q - addr);
952     bi->address[q - addr] = 0;
953     p = q + 1;
954     bi->telnet_port = atoi(p);
955     q = strchr(p, '/');
956     if (!q) {
957     bi->relay_port = bi->telnet_port;
958     } else {
959     bi->relay_port = atoi(q + 1);
960     }
961     }
962     set_user(&USERENTRY_BOTADDR, u1, bi);
963     }
964    
965     static void cmd_comment(struct userrec *u, int idx, char *par)
966     {
967     char *handle;
968     struct userrec *u1;
969    
970     if (!par[0]) {
971     dprintf(idx, "Usage: comment <handle> <newcomment>\n");
972     return;
973     }
974     handle = newsplit(&par);
975     u1 = get_user_by_handle(userlist, handle);
976     if (!u1) {
977     dprintf(idx, "No such user!\n");
978     return;
979     }
980     if ((u1->flags & USER_OWNER) && !(u && (u->flags & USER_OWNER)) &&
981     strcasecmp(handle, dcc[idx].nick)) {
982     dprintf(idx, "Can't change comment on the bot owner.\n");
983     return;
984     }
985     putlog(LOG_CMDS, "*", "#%s# comment %s %s", dcc[idx].nick, handle, par);
986     if (!strcasecmp(par, "none")) {
987     dprintf(idx, "Okay, comment blanked.\n");
988     set_user(&USERENTRY_COMMENT, u1, NULL);
989     return;
990     }
991     dprintf(idx, "Changed comment.\n");
992     set_user(&USERENTRY_COMMENT, u1, par);
993     }
994    
995     static void cmd_restart(struct userrec *u, int idx, char *par)
996     {
997     putlog(LOG_CMDS, "*", "#%s# restart", dcc[idx].nick);
998     if (!backgrd) {
999     dprintf(idx, "You can not .restart a bot when running -n (due to tcl)\n");
1000     return;
1001     }
1002     dprintf(idx, "Restarting.\n");
1003     if (make_userfile) {
1004     putlog(LOG_MISC, "*",
1005     "Uh, guess you don't need to create a new userfile.");
1006     make_userfile = 0;
1007     }
1008     write_userfile(-1);
1009     putlog(LOG_MISC, "*", "Restarting ...");
1010     wipe_timers(interp, &utimer);
1011     wipe_timers(interp, &timer);
1012     do_restart = idx;
1013     }
1014    
1015     static void cmd_rehash(struct userrec *u, int idx, char *par)
1016     {
1017     putlog(LOG_CMDS, "*", "#%s# rehash", dcc[idx].nick);
1018     dprintf(idx, "Rehashing.\n");
1019     if (make_userfile) {
1020     putlog(LOG_MISC, "*",
1021     "Uh, guess you don't need to create a new userfile.");
1022     make_userfile = 0;
1023     }
1024     write_userfile(-1);
1025     putlog(LOG_MISC, "*", "Rehashing ...");
1026     do_restart = -2;
1027     }
1028    
1029     static void cmd_reload(struct userrec *u, int idx, char *par)
1030     {
1031     putlog(LOG_CMDS, "*", "#%s# reload", dcc[idx].nick);
1032     dprintf(idx, "Reloading user file...\n");
1033     reload();
1034     }
1035    
1036     /* this get replaced in server.so with a version that handles the server */
1037     void cmd_die(struct userrec *u, int idx, char *par)
1038     {
1039     char s[1024];
1040    
1041     putlog(LOG_CMDS, "*", "#%s# die %s", dcc[idx].nick, par);
1042     if (par[0]) {
1043     simple_sprintf(s, "BOT SHUTDOWN (%s: %s)", dcc[idx].nick, par);
1044     } else {
1045     simple_sprintf(s, "BOT SHUTDOWN (authorized by %s)", dcc[idx].nick);
1046     }
1047     chatout("*** %s\n", s);
1048     botnet_send_chat(-1, botnetnick, s);
1049     botnet_send_bye();
1050     write_userfile(-1);
1051     simple_sprintf(s, "DIE BY %s!%s (%s)", dcc[idx].nick,
1052     dcc[idx].host, par[0] ? par : "request");
1053     fatal(s, 0);
1054     }
1055    
1056     static void cmd_debug(struct userrec *u, int idx, char *par)
1057     {
1058     if (!strcasecmp(par, "help")) {
1059     putlog(LOG_CMDS, "*", "#%s# debug help", dcc[idx].nick);
1060     debug_help(idx);
1061     } else {
1062     putlog(LOG_CMDS, "*", "#%s# debug", dcc[idx].nick);
1063     debug_mem_to_dcc(idx);
1064     }
1065     }
1066    
1067     static void cmd_simul(struct userrec *u, int idx, char *par)
1068     {
1069     char *nick;
1070     int i, ok = 0;
1071    
1072     nick = newsplit(&par);
1073     if (!par[0]) {
1074     dprintf(idx, "Usage: simul <nick> <text>\n");
1075     return;
1076     }
1077     if (isowner(nick)) {
1078     dprintf(idx, "Unable to '.simul' permanent owners.\n");
1079     return;
1080     }
1081     for (i = 0; i < dcc_total; i++)
1082     if (!strcasecmp(nick, dcc[i].nick) && !ok &&
1083     (dcc[i].type->flags & DCT_SIMUL)) {
1084     putlog(LOG_CMDS, "*", "#%s# simul %s %s", dcc[idx].nick, nick, par);
1085     if (dcc[i].type && dcc[i].type->activity) {
1086     dcc[i].type->activity(i, par, strlen(par));
1087     ok = 1;
1088     }
1089     }
1090     if (!ok)
1091     dprintf(idx, "No such user on the party line.\n");
1092     }
1093    
1094     static void cmd_link(struct userrec *u, int idx, char *par)
1095     {
1096     char *s;
1097     int i;
1098    
1099     if (!par[0]) {
1100     dprintf(idx, "Usage: link [some-bot] <new-bot>\n");
1101     return;
1102     }
1103     putlog(LOG_CMDS, "*", "#%s# link %s", dcc[idx].nick, par);
1104     s = newsplit(&par);
1105     if (!par[0] || !strcasecmp(par, botnetnick))
1106     botlink(dcc[idx].nick, idx, s);
1107     else {
1108     char x[40];
1109    
1110     i = nextbot(s);
1111     if (i < 0) {
1112     dprintf(idx, "No such bot online.\n");
1113     return;
1114     }
1115     simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1116     botnet_send_link(i, x, s, par);
1117     }
1118     }
1119    
1120     static void cmd_unlink(struct userrec *u, int idx, char *par)
1121     {
1122     int i;
1123     char *bot;
1124    
1125     if (!par[0]) {
1126     dprintf(idx, "Usage: unlink <bot> [reason]\n");
1127     return;
1128     }
1129     putlog(LOG_CMDS, "*", "#%s# unlink %s", dcc[idx].nick, par);
1130     bot = newsplit(&par);
1131     i = nextbot(bot);
1132     if (i < 0) {
1133     botunlink(idx, bot, par);
1134     return;
1135     }
1136     /* if we're directly connected to that bot, just do it
1137     * (is nike gunna sue?) */
1138     if (!strcasecmp(dcc[i].nick, bot))
1139     botunlink(idx, bot, par);
1140     else {
1141     char x[40];
1142    
1143     simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1144     botnet_send_unlink(i, x, lastbot(bot), bot, par);
1145     }
1146     }
1147    
1148     static void cmd_relay(struct userrec *u, int idx, char *par)
1149     {
1150     if (!par[0]) {
1151     dprintf(idx, "Usage: relay <bot>\n");
1152     return;
1153     }
1154     putlog(LOG_CMDS, "*", "#%s# relay %s", dcc[idx].nick, par);
1155     tandem_relay(idx, par, 0);
1156     }
1157    
1158     static void cmd_save(struct userrec *u, int idx, char *par)
1159     {
1160     putlog(LOG_CMDS, "*", "#%s# save", dcc[idx].nick);
1161     dprintf(idx, "Saving user file...\n");
1162     write_userfile(-1);
1163     }
1164    
1165     static void cmd_backup(struct userrec *u, int idx, char *par)
1166     {
1167     putlog(LOG_CMDS, "*", "#%s# backup", dcc[idx].nick);
1168     dprintf(idx, "Backing up the user file...\n");
1169     backup_userfile();
1170     }
1171    
1172     static void cmd_trace(struct userrec *u, int idx, char *par)
1173     {
1174     int i;
1175     char x[NOTENAMELEN + 11], y[11];
1176    
1177     if (!par[0]) {
1178     dprintf(idx, "Usage: trace <botname>\n");
1179     return;
1180     }
1181     if (!strcasecmp(par, botnetnick)) {
1182     dprintf(idx, "That's me! Hiya! :)\n");
1183     return;
1184     }
1185     i = nextbot(par);
1186     if (i < 0) {
1187     dprintf(idx, "Unreachable bot.\n");
1188     return;
1189     }
1190     putlog(LOG_CMDS, "*", "#%s# trace %s", dcc[idx].nick, par);
1191     simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1192     simple_sprintf(y, ":%d", now);
1193     botnet_send_trace(i, x, par, y);
1194     }
1195    
1196     static void cmd_binds(struct userrec *u, int idx, char *par)
1197     {
1198     putlog(LOG_CMDS, "*", "#%s# binds %s", dcc[idx].nick, par);
1199     tell_binds(idx, par);
1200     }
1201    
1202     static void cmd_banner(struct userrec *u, int idx, char *par)
1203     {
1204     char s[1024];
1205     int i;
1206    
1207     if (!par[0]) {
1208     dprintf(idx, "Usage: banner <message>\n");
1209     return;
1210     }
1211     simple_sprintf(s, "\007\007### Botwide:[%s] %s\n", dcc[idx].nick, par);
1212     for (i = 0; i < dcc_total; i++)
1213     if (dcc[i].type->flags & DCT_MASTER)
1214     dprintf(i, "%s", s);
1215     }
1216    
1217     /* after messing with someone's user flags, make sure the dcc-chat flags
1218     * are set correctly */
1219     int check_dcc_attrs(struct userrec *u, int oatr)
1220     {
1221     int i, stat;
1222     char *p, *q, s[121];
1223    
1224     /* if it matches someone in the owner list, make sure he/she has +n */
1225     if (!u)
1226     return 0;
1227     /* make sure default owners are +n */
1228     if (owner[0]) {
1229     q = owner;
1230     p = strchr(q, ',');
1231     while (p) {
1232     strncpy(s, q, p - q);
1233     s[p - q] = 0;
1234     rmspace(s);
1235     if (!strcasecmp(u->handle, s))
1236     u->flags = sanity_check(u->flags | USER_OWNER);
1237     q = p + 1;
1238     p = strchr(q, ',');
1239     }
1240     strcpy(s, q);
1241     rmspace(s);
1242     if (!strcasecmp(u->handle, s))
1243     u->flags = sanity_check(u->flags | USER_OWNER);
1244     }
1245     for (i = 0; i < dcc_total; i++) {
1246     if ((dcc[i].type->flags & DCT_MASTER) &&
1247     (!strcasecmp(u->handle, dcc[i].nick))) {
1248     stat = dcc[i].status;
1249     if ((dcc[i].type == &DCC_CHAT) &&
1250     ((u->flags & (USER_OP | USER_MASTER | USER_OWNER |
1251     USER_BOTMAST))
1252     != (oatr & (USER_OP | USER_MASTER | USER_OWNER |
1253     USER_BOTMAST)))) {
1254     botnet_send_join_idx(i, -1);
1255     }
1256     if ((oatr & USER_MASTER) && !(u->flags & USER_MASTER)) {
1257     struct flag_record fr =
1258     {FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
1259    
1260     dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_RAW |
1261     LOG_FILES | LOG_LEV1 | LOG_LEV2 |
1262     LOG_LEV3 | LOG_LEV4 | LOG_LEV5 |
1263     LOG_LEV6 | LOG_LEV7 | LOG_LEV8 |
1264     LOG_WALL | LOG_DEBUG);
1265     get_user_flagrec(u, &fr, NULL);
1266     if (!chan_master(fr))
1267     dcc[i].u.chat->con_flags |= (LOG_MISC | LOG_CMDS);
1268     dprintf(i, "*** POOF! ***\n");
1269     dprintf(i, "You are no longer a master on this bot.\n");
1270     }
1271     if (!(oatr & USER_MASTER) && (u->flags & USER_MASTER)) {
1272     dcc[i].u.chat->con_flags |= conmask;
1273     dprintf(i, "*** POOF! ***\n");
1274     dprintf(i, "You are now a master on this bot.\n");
1275     }
1276     if (!(oatr & USER_BOTMAST) && (u->flags & USER_BOTMAST)) {
1277     dprintf(i, "### POOF! ###\n");
1278     dprintf(i, "You are now a botnet master on this bot.\n");
1279     }
1280     if ((oatr & USER_BOTMAST) && !(u->flags & USER_BOTMAST)) {
1281     dprintf(i, "### POOF! ###\n");
1282     dprintf(i, "You are no longer a botnet master on this bot.\n");
1283     }
1284     if (!(oatr & USER_OWNER) && (u->flags & USER_OWNER)) {
1285     dprintf(i, "@@@ POOF! @@@\n");
1286     dprintf(i, "You are now an OWNER of this bot.\n");
1287     }
1288     if ((oatr & USER_OWNER) && !(u->flags & USER_OWNER)) {
1289     dprintf(i, "@@@ POOF! @@@\n");
1290     dprintf(i, "You are no longer an owner of this bot.\n");
1291     }
1292     if ((stat & STAT_PARTY) && (u->flags & USER_OP))
1293     stat &= ~STAT_PARTY;
1294     if (!(stat & STAT_PARTY) && !(u->flags & USER_OP) &&
1295     !(u->flags & USER_MASTER))
1296     stat |= STAT_PARTY;
1297     if ((stat & STAT_CHAT) && !(u->flags & USER_PARTY) &&
1298     !(u->flags & USER_MASTER) &&
1299     (!(u->flags & USER_OP) || require_p))
1300     stat &= ~STAT_CHAT;
1301     if ((dcc[i].type->flags & DCT_FILES) && !(stat & STAT_CHAT) &&
1302     ((u->flags & USER_MASTER) || (u->flags & USER_PARTY) ||
1303     ((u->flags & USER_OP) && !require_p)))
1304     stat |= STAT_CHAT;
1305     dcc[i].status = stat;
1306     /* check if they no longer have access to wherever they are */
1307     /* DON'T kick someone off the party line just cuz they lost +p
1308     * (pinvite script removes +p after 5 mins automatically) */
1309     if ((dcc[i].type->flags & DCT_FILES) && !(u->flags & USER_XFER) &&
1310     !(u->flags & USER_MASTER)) {
1311     dprintf(i, "-+- POOF! -+-\n");
1312     dprintf(i, "You no longer have file area access.\n\n");
1313     putlog(LOG_MISC, "*", "DCC user [%s]%s removed from file system",
1314     dcc[i].nick, dcc[i].host);
1315     if (dcc[i].status & STAT_CHAT) {
1316     struct chat_info *ci;
1317    
1318     ci = dcc[i].u.file->chat;
1319     nfree(dcc[i].u.file);
1320     dcc[i].u.chat = ci;
1321     dcc[i].status &= (~STAT_CHAT);
1322     dcc[i].type = &DCC_CHAT;
1323     if (dcc[i].u.chat->channel >= 0) {
1324     chanout_but(-1, dcc[i].u.chat->channel,
1325     "*** %s has returned.\n", dcc[i].nick);
1326 fabian 1.12 Context;
1327 segfault 1.1 if (dcc[i].u.chat->channel < 100000)
1328     botnet_send_join_idx(i, -1);
1329     }
1330     } else {
1331     killsock(dcc[i].sock);
1332     dcc[i].sock = (long) dcc[i].type;
1333     dcc[i].type = &DCC_LOST;
1334     }
1335     }
1336     }
1337     if ((dcc[i].type == &DCC_BOT) && !strcasecmp(u->handle, dcc[i].nick)) {
1338     if ((dcc[i].status & STAT_LEAF) && !(u->flags & BOT_LEAF))
1339     dcc[i].status &= ~(STAT_LEAF | STAT_WARNED);
1340     if (!(dcc[i].status & STAT_LEAF) && (u->flags & BOT_LEAF))
1341     dcc[i].status |= STAT_LEAF;
1342     }
1343     }
1344     return u->flags;
1345     }
1346    
1347     int check_dcc_chanattrs(struct userrec *u, char *chname, int chflags,
1348     int ochatr)
1349     {
1350     int i, found = 0, atr = u ? u->flags : 0;
1351     struct chanset_t *chan;
1352    
1353     if (!u)
1354     return 0;
1355     chan = chanset;
1356     for (i = 0; i < dcc_total; i++) {
1357     if ((dcc[i].type->flags & DCT_MASTER) &&
1358     !strcasecmp(u->handle, dcc[i].nick)) {
1359     if ((dcc[i].type == &DCC_CHAT) &&
1360     ((chflags & (USER_OP | USER_MASTER | USER_OWNER))
1361     != (ochatr & (USER_OP | USER_MASTER | USER_OWNER))))
1362     botnet_send_join_idx(i, -1);
1363     if ((ochatr & USER_MASTER) && !(chflags & USER_MASTER)) {
1364     if (!(atr & USER_MASTER))
1365     dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS);
1366     dprintf(i, "*** POOF! ***\n");
1367     dprintf(i, "You are no longer a master on %s.\n", chname);
1368     }
1369     if (!(ochatr & USER_MASTER) && (chflags & USER_MASTER)) {
1370     dcc[i].u.chat->con_flags |= conmask;
1371     if (!(atr & USER_MASTER))
1372     dcc[i].u.chat->con_flags &=
1373     ~(LOG_LEV1 | LOG_LEV2 | LOG_LEV3 | LOG_LEV4 |
1374     LOG_LEV5 | LOG_LEV6 | LOG_LEV7 | LOG_LEV8 |
1375     LOG_RAW | LOG_DEBUG | LOG_WALL | LOG_FILES | LOG_SRVOUT);
1376     dprintf(i, "*** POOF! ***\n");
1377     dprintf(i, "You are now a master on %s.\n", chname);
1378     }
1379     if (!(ochatr & USER_OWNER) && (chflags & USER_OWNER)) {
1380     dprintf(i, "@@@ POOF! @@@\n");
1381     dprintf(i, "You are now an OWNER of %s.\n", chname);
1382     }
1383     if ((ochatr & USER_OWNER) && !(chflags & USER_OWNER)) {
1384     dprintf(i, "@@@ POOF! @@@\n");
1385     dprintf(i, "You are no longer an owner of %s.\n", chname);
1386     }
1387     if (((ochatr & (USER_OP | USER_MASTER | USER_OWNER)) &&
1388     (!(chflags & (USER_OP | USER_MASTER | USER_OWNER)))) ||
1389     ((chflags & (USER_OP | USER_MASTER | USER_OWNER)) &&
1390     (!(ochatr & (USER_OP | USER_MASTER | USER_OWNER))))) {
1391 fabian 1.11 struct flag_record fr = {FR_CHAN, 0, 0, 0, 0, 0};
1392 segfault 1.1
1393     while (chan && !found) {
1394 fabian 1.8 get_user_flagrec(u, &fr, chan->dname);
1395 segfault 1.1 if (fr.chan & (USER_OP | USER_MASTER | USER_OWNER))
1396     found = 1;
1397     else
1398     chan = chan->next;
1399     }
1400     if (!chan)
1401     chan = chanset;
1402     if (chan)
1403 fabian 1.8 strcpy(dcc[i].u.chat->con_chan, chan->dname);
1404 segfault 1.1 else
1405     strcpy(dcc[i].u.chat->con_chan, "*");
1406     }
1407     }
1408     }
1409     return chflags;
1410     }
1411    
1412     static void cmd_chattr(struct userrec *u, int idx, char *par)
1413     {
1414 fabian 1.6 char *hand, *arg = NULL, *tmpchg = NULL, *chg = NULL, work[1024];
1415 segfault 1.1 struct chanset_t *chan = NULL;
1416     struct userrec *u2;
1417 fabian 1.2 struct flag_record pls = {0, 0, 0, 0, 0, 0},
1418     mns = {0, 0, 0, 0, 0, 0},
1419     user = {0, 0, 0, 0, 0, 0};
1420 segfault 1.1 module_entry *me;
1421     int fl = -1, of = 0, ocf = 0;
1422    
1423     if (!par[0]) {
1424     dprintf(idx, "Usage: chattr <handle> [changes] [channel]\n");
1425     return;
1426     }
1427     hand = newsplit(&par);
1428     u2 = get_user_by_handle(userlist, hand);
1429 fabian 1.6 if (!u2) {
1430 segfault 1.1 dprintf(idx, "No such user!\n");
1431     return;
1432     }
1433 fabian 1.6
1434     /* Parse args */
1435     if (par[0]) {
1436 fabian 1.8 arg = newsplit(&par);
1437 fabian 1.6 if (par[0]) {
1438     /* .chattr <handle> <changes> <channel> */
1439     chg = arg;
1440 fabian 1.8 arg = newsplit(&par);
1441     chan = findchan_by_dname(arg);
1442 fabian 1.6 } else {
1443 fabian 1.8 chan = findchan_by_dname(arg);
1444 fabian 1.10 /* ugly hack for modeless channels -- rtc */
1445 fabian 1.6 if (!(arg[0] == '+' && chan) &&
1446     !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
1447     /* .chattr <handle> <changes> */
1448     chg = arg;
1449     chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
1450     arg = NULL;
1451     }
1452     /* .chattr <handle> <channel>: nothing to do... */
1453     }
1454     }
1455     /* arg: pointer to channel name, NULL if none specified
1456     * chan: pointer to channel structure, NULL if none found or none specified
1457     * chg: pointer to changes, NULL if none specified
1458     */
1459 fabian 1.13 Assert(!(!arg && chan));
1460 fabian 1.6 if (arg && !chan) {
1461     dprintf(idx, "No channel record for %s.\n", arg);
1462     return;
1463 segfault 1.1 }
1464 fabian 1.6 if (chg) {
1465     if (!arg && strpbrk(chg, "&|")) {
1466     /* .chattr <handle> *[&|]*: use console channel if found... */
1467     if (!strcmp ((arg = dcc[idx].u.chat->con_chan), "*"))
1468     arg = NULL;
1469     else
1470 fabian 1.8 chan = findchan_by_dname(arg);
1471 fabian 1.6 if (arg && !chan) {
1472     dprintf (idx, "Invalid console channel %s.\n", arg);
1473     return;
1474     }
1475     } else if (arg && !strpbrk(chg, "&|")) {
1476 fabian 1.12 Context;
1477 fabian 1.6 tmpchg = nmalloc(strlen(chg) + 2);
1478 fabian 1.11 strcpy(tmpchg, "|");
1479     strcat(tmpchg, chg);
1480 fabian 1.6 chg = tmpchg;
1481 segfault 1.1 }
1482     }
1483 fabian 1.6 par = arg;
1484 segfault 1.1 user.match = FR_GLOBAL;
1485     if (chan)
1486     user.match |= FR_CHAN;
1487 fabian 1.8 get_user_flagrec(u, &user, chan ? chan->dname : 0);
1488 segfault 1.1 if (!chan && !glob_botmast(user)) {
1489     dprintf(idx, "You do not have Bot Master privileges.\n");
1490 fabian 1.6 if (tmpchg)
1491     nfree(tmpchg);
1492 segfault 1.1 return;
1493     }
1494     if (chan && !glob_master(user) && !chan_master(user)) {
1495     dprintf(idx, "You do not have channel master privileges for channel %s\n",
1496     par);
1497 fabian 1.6 if (tmpchg)
1498     nfree(tmpchg);
1499 segfault 1.1 return;
1500     }
1501     user.match &= fl;
1502     if (chg) {
1503     pls.match = user.match;
1504     break_down_flags(chg, &pls, &mns);
1505     /* no-one can change these flags on-the-fly */
1506 fabian 1.6 pls.global &= ~(USER_BOT);
1507     mns.global &= ~(USER_BOT);
1508 segfault 1.1
1509     if (chan) {
1510     pls.chan &= ~(BOT_SHARE);
1511     mns.chan &= ~(BOT_SHARE);
1512     }
1513     if (!glob_owner(user)) {
1514 fabian 1.6 pls.global &= ~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1515     mns.global &= ~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1516 segfault 1.1
1517     if (chan) {
1518     pls.chan &= ~USER_OWNER;
1519     mns.chan &= ~USER_OWNER;
1520     }
1521     if (!glob_master(user)) {
1522 fabian 1.6 pls.global &= USER_PARTY | USER_XFER;
1523     mns.global &= USER_PARTY | USER_XFER;
1524 segfault 1.1
1525     if (!glob_botmast(user)) {
1526     pls.global = 0;
1527     mns.global = 0;
1528     }
1529     }
1530     }
1531     if (chan && !chan_owner(user) && !glob_owner(user)) {
1532     pls.chan &= ~USER_MASTER;
1533     mns.chan &= ~USER_MASTER;
1534     if (!chan_master(user) && !glob_master(user)) {
1535     pls.chan = 0;
1536     mns.chan = 0;
1537     }
1538     }
1539     get_user_flagrec(u2, &user, par);
1540     if (user.match & FR_GLOBAL) {
1541     of = user.global;
1542     user.global = sanity_check((user.global |pls.global) &~mns.global);
1543    
1544     user.udef_global = (user.udef_global | pls.udef_global)
1545     & ~mns.udef_global;
1546     }
1547     if (chan) {
1548     ocf = user.chan;
1549     user.chan = chan_sanity_check((user.chan | pls.chan) & ~mns.chan,
1550     user.global);
1551    
1552     user.udef_chan = (user.udef_chan | pls.udef_chan) & ~mns.udef_chan;
1553     }
1554     set_user_flagrec(u2, &user, par);
1555     }
1556     if (chan)
1557     putlog(LOG_CMDS, "*", "#%s# (%s) chattr %s %s",
1558 fabian 1.8 dcc[idx].nick, chan ? chan->dname : "*", hand, chg ? chg : "");
1559 segfault 1.1 else
1560     putlog(LOG_CMDS, "*", "#%s# chattr %s %s", dcc[idx].nick, hand,
1561     chg ? chg : "");
1562     /* get current flags and display them */
1563     if (user.match & FR_GLOBAL) {
1564     user.match = FR_GLOBAL;
1565     if (chg)
1566     check_dcc_attrs(u2, of);
1567     get_user_flagrec(u2, &user, NULL);
1568     build_flags(work, &user, NULL);
1569     if (work[0] != '-')
1570     dprintf(idx, "Global flags for %s are now +%s\n", hand, work);
1571     else
1572     dprintf(idx, "No global flags for %s.\n", hand);
1573     }
1574     if (chan) {
1575     user.match = FR_CHAN;
1576     get_user_flagrec(u2, &user, par);
1577     user.chan &= ~BOT_SHARE;
1578     if (chg)
1579 fabian 1.8 check_dcc_chanattrs(u2, chan->dname, user.chan, ocf);
1580 segfault 1.1 build_flags(work, &user, NULL);
1581     if (work[0] != '-')
1582     dprintf(idx, "Channel flags for %s on %s are now +%s\n", hand,
1583 fabian 1.8 chan->dname, work);
1584 segfault 1.1 else
1585 fabian 1.8 dprintf(idx, "No flags for %s on %s.\n", hand, chan->dname);
1586 fabian 1.6 if (chg && (me = module_find("irc", 0, 0))) {
1587 segfault 1.1 Function *func = me->funcs;
1588    
1589     if (chan)
1590 fabian 1.2 (func[IRC_RECHECK_CHANNEL]) (chan, 0);
1591 segfault 1.1 }
1592     }
1593 fabian 1.6 if (tmpchg)
1594     nfree(tmpchg);
1595 segfault 1.1 }
1596    
1597     static void cmd_botattr(struct userrec *u, int idx, char *par)
1598     {
1599 fabian 1.6 char *hand, *chg = NULL, *arg = NULL, *tmpchg = NULL, work[1024];
1600 segfault 1.1 struct chanset_t *chan = NULL;
1601     struct userrec *u2;
1602 fabian 1.8 struct flag_record pls = {0, 0, 0, 0, 0, 0},
1603     mns = {0, 0, 0, 0, 0, 0},
1604     user = {0, 0, 0, 0, 0, 0};
1605 segfault 1.1 int idx2;
1606    
1607     if (!par[0]) {
1608     dprintf(idx, "Usage: botattr <handle> [changes] [channel]\n");
1609     return;
1610     }
1611     hand = newsplit(&par);
1612     u2 = get_user_by_handle(userlist, hand);
1613 fabian 1.6 if (!u2 || !(u2->flags & USER_BOT)) {
1614 segfault 1.1 dprintf(idx, "No such bot!\n");
1615     return;
1616     }
1617     for (idx2 = 0; idx2 < dcc_total; idx2++)
1618     if (!strcasecmp(dcc[idx2].nick, hand))
1619     break;
1620     if (idx2 != dcc_total) {
1621 fabian 1.6 dprintf(idx, "You may not change the attributes of a directly linked bot.\n");
1622 segfault 1.1 return;
1623     }
1624 fabian 1.6 /* Parse args */
1625     if (par[0]) {
1626 fabian 1.10 arg = newsplit(&par);
1627 fabian 1.6 if (par[0]) {
1628     /* .botattr <handle> <changes> <channel> */
1629     chg = arg;
1630 fabian 1.10 arg = newsplit(&par);
1631 fabian 1.8 chan = findchan_by_dname(arg);
1632 fabian 1.6 } else {
1633 fabian 1.8 chan = findchan_by_dname(arg);
1634 fabian 1.10 /* ugly hack for modeless channels -- rtc */
1635 fabian 1.6 if (!(arg[0] == '+' && chan) &&
1636     !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
1637     /* .botattr <handle> <changes> */
1638     chg = arg;
1639     chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
1640     arg = NULL;
1641     }
1642     /* .botattr <handle> <channel>: nothing to do... */
1643     }
1644     }
1645     /* arg: pointer to channel name, NULL if none specified
1646     * chan: pointer to channel structure, NULL if none found or none specified
1647     * chg: pointer to changes, NULL if none specified
1648     */
1649 fabian 1.13 Assert(!(!arg && chan));
1650 fabian 1.6 if (arg && !chan) {
1651     dprintf(idx, "No channel record for %s.\n", arg);
1652     return;
1653 segfault 1.1 }
1654 fabian 1.6 if (chg) {
1655     if (!arg && strpbrk(chg, "&|")) {
1656     /* botattr <handle> *[&|]*: use console channel if found... */
1657     if (!strcmp ((arg = dcc[idx].u.chat->con_chan), "*"))
1658     arg = NULL;
1659     else
1660 fabian 1.8 chan = findchan_by_dname(arg);
1661 fabian 1.6 if (arg && !chan) {
1662     dprintf (idx, "Invalid console channel %s.\n", arg);
1663     return;
1664     }
1665     } else if (arg && !strpbrk(chg, "&|")) {
1666 fabian 1.12 Context;
1667 fabian 1.6 tmpchg = nmalloc(strlen(chg) + 2);
1668     strcpy (tmpchg, "|");
1669     strcat (tmpchg, chg);
1670     chg = tmpchg;
1671     }
1672 segfault 1.1 }
1673 fabian 1.6 par = arg;
1674    
1675 segfault 1.1 user.match = FR_GLOBAL;
1676 fabian 1.8 get_user_flagrec(u, &user, chan ? chan->dname : 0);
1677 segfault 1.1 if (!glob_botmast(user)) {
1678     dprintf(idx, "You do not have Bot Master privileges.\n");
1679 fabian 1.6 if (tmpchg)
1680     nfree(tmpchg);
1681 segfault 1.1 return;
1682     }
1683     if (chg) {
1684     user.match = FR_BOT | (chan ? FR_CHAN : 0);
1685     pls.match = user.match;
1686     break_down_flags(chg, &pls, &mns);
1687     /* no-one can change these flags on-the-fly */
1688     pls.global &=~BOT_BOT;
1689     mns.global &=~BOT_BOT;
1690    
1691     if (chan && glob_owner(user)) {
1692     pls.chan &= BOT_SHARE;
1693     mns.chan &= BOT_SHARE;
1694     } else {
1695     pls.chan = 0;
1696     mns.chan = 0;
1697     }
1698     if (!glob_owner(user)) {
1699     pls.bot &= ~(BOT_SHARE | BOT_GLOBAL);
1700     mns.bot &= ~(BOT_SHARE | BOT_GLOBAL);
1701     }
1702     user.match