1 /*
2  * cmds.c -- handles:
3  *   commands from a user via dcc
4  *   (split in 2, this portion contains no-irc commands)
5  *
6  * $Id: cmds.c,v 1.107 (1.0.4) 2004/04/17 22:47:48 [Xp-AvR] Exp $
7  */
8 
9 #include "main.h"
10 #include "tandem.h"
11 #include "modules.h"
12 #include <ctype.h>
13 
14 extern struct chanset_t *chanset;
15 extern struct dcc_t *dcc;
16 extern struct userrec *userlist;
17 extern tcl_timer_t *timer, *utimer;
18 extern int dcc_total, remote_boots, backgrd, make_userfile, do_restart,
19            conmask, require_p, must_be_owner, strict_host, noshare;
20 extern unsigned long otraffic_irc, otraffic_irc_today, itraffic_irc,
21                      itraffic_irc_today, otraffic_bn, otraffic_bn_today,
22                      itraffic_bn, itraffic_bn_today, otraffic_dcc,
23                      otraffic_dcc_today, itraffic_dcc, itraffic_dcc_today,
24                      otraffic_trans, otraffic_trans_today, itraffic_trans,
25                      itraffic_trans_today, otraffic_unknown,
26                      otraffic_unknown_today, itraffic_unknown,
27                      itraffic_unknown_today;
28 extern Tcl_Interp *interp;
29 extern char botnetnick[], origbotname[], ver[], network[], owner[],
30             quit_msg[], userfileCryptKey[], datadir[], userfile[];
31 extern time_t now, online_since;
32 extern module_entry *module_list;
33 
34 static char *btos(unsigned long);
35 
36 
37 /* Add hostmask to a bot's record if possible. */
add_bot_hostmask(int idx,char * nick)38 static int add_bot_hostmask(int idx, char *nick)
39 {
40   struct chanset_t *chan;
41 
42   for (chan = chanset; chan; chan = chan->next)
43     if (channel_active(chan)) {
44       memberlist *m = ismember(chan, nick);
45 
46       if (m) {
47         char s[UHOSTLEN];
48         struct userrec *u;
49 
50         EvangelineSnprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
51         u = get_user_by_host(s);
52         if (u) {
53           dprintf(idx, "(Can't add hostmask for %s because it matches %s)\n",
54                   nick, u->handle);
55           return 0;
56         }
57         if (strchr("~^+=-", m->userhost[0]))
58           EvangelineSnprintf(s, sizeof s, "*!%s%s", strict_host ? "?" : "",
59                        m->userhost + 1);
60         else
61           EvangelineSnprintf(s, sizeof s, "*!%s", m->userhost);
62         dprintf(idx, "(Added hostmask for %s from %s)\n", nick, chan->dname);
63         addhost_by_handle(nick, s);
64         return 1;
65       }
66     }
67   return 0;
68 }
69 
tell_who(struct userrec * u,int idx,int chan)70 static void tell_who(struct userrec *u, int idx, int chan)
71 {
72   int i, k, ok = 0, atr = u ? u->flags : 0;
73   int nicklen;
74   char format[81];
75   char s[1024];
76 
77   if (!chan)
78     dprintf(idx, "%s (* = owner, + = master, %% = botmaster, @ = op)\n", BOT_PARTYMEMBS);
79   else {
80     simple_sprintf(s, "assoc %d", chan);
81     if ((Tcl_Eval(interp, s) != TCL_OK) || !Tcl_GetStringResult(interp)[0])
82       dprintf(idx, "%s %s%d: (* = owner, + = master, %% = botmaster, @ = op)\n",
83                   BOT_PEOPLEONCHAN, (chan < GLOBAL_CHANS) ? "" :
84               "*", chan % GLOBAL_CHANS);
85     else
86       dprintf(idx, "%s '%s' (%s%d): (* = owner, + = master, %% = botmaster, @ = op)\n",
87                   BOT_PEOPLEONCHAN, Tcl_GetStringResult(interp),
88               (chan < GLOBAL_CHANS) ? "" : "*", chan % GLOBAL_CHANS);
89   }
90 
91   nicklen = 0;
92   for (i = 0; i < dcc_total; i++) {
93     if (strlen(dcc[i].nick) > nicklen)
94       nicklen = strlen(dcc[i].nick);
95   }
96   if (nicklen < 9)
97     nicklen = 9;
98 
99   for (i = 0; i < dcc_total; i++)
100     if (dcc[i].type == &DCC_CHAT)
101       if (dcc[i].u.chat->channel == chan) {
102         if (atr & USER_OWNER) {
103           EvangelineSnprintf(format, sizeof format, "  [%%.2lu]  %%c%%-%us %%s",
104                        nicklen);
105           sprintf(s, format, dcc[i].sock,
106                   (geticon(i) == '-' ? ' ' : geticon(i)), dcc[i].nick,
107                   dcc[i].host);
108         } else {
109           EvangelineSnprintf(format, sizeof format, "  %%c%%-%us %%s", nicklen);
110           sprintf(s, format,
111                   (geticon(i) == '-' ? ' ' : geticon(i)),
112                   dcc[i].nick, dcc[i].host);
113         }
114         if (atr & USER_MASTER) {
115           if (dcc[i].u.chat->con_flags)
116             sprintf(&s[strlen(s)], " (con:%s)",
117                     masktype(dcc[i].u.chat->con_flags));
118         }
119         if (now - dcc[i].timeval > 300) {
120           unsigned long days, hrs, mins;
121 
122           days = (now - dcc[i].timeval) / 86400;
123           hrs = ((now - dcc[i].timeval) - (days * 86400)) / 3600;
124           mins = ((now - dcc[i].timeval) - (hrs * 3600)) / 60;
125           if (days > 0)
126             sprintf(&s[strlen(s)], " (idle %lud%luh)", days, hrs);
127           else if (hrs > 0)
128             sprintf(&s[strlen(s)], " (idle %luh%lum)", hrs, mins);
129           else
130             sprintf(&s[strlen(s)], " (idle %lum)", mins);
131         }
132         dprintf(idx, "%s\n", s);
133         if (dcc[i].u.chat->away != NULL)
134           dprintf(idx, "      AWAY: %s\n", dcc[i].u.chat->away);
135       }
136   for (i = 0; i < dcc_total; i++)
137     if (dcc[i].type == &DCC_BOT) {
138       if (!ok) {
139         ok = 1;
140         dprintf(idx, "Bots connected:\n");
141       }
142       EvangelineStrftime(s, 14, "%d %b %H:%M", localtime(&dcc[i].timeval));
143       if (atr & USER_OWNER) {
144         EvangelineSnprintf(format, sizeof format,
145                      "  [%%.2lu]  %%s%%c%%-%us (%%s) %%s\n", nicklen);
146         dprintf(idx, format, dcc[i].sock,
147                 dcc[i].status & STAT_CALLED ? "<-" : "->",
148                 dcc[i].status & STAT_SHARE ? '+' : ' ', dcc[i].nick, s,
149                 dcc[i].u.bot->version);
150       } else {
151         EvangelineSnprintf(format, sizeof format, "  %%s%%c%%-%us (%%s) %%s\n",
152                      nicklen);
153         dprintf(idx, format, dcc[i].status & STAT_CALLED ? "<-" : "->",
154                 dcc[i].status & STAT_SHARE ? '+' : ' ', dcc[i].nick, s,
155                 dcc[i].u.bot->version);
156       }
157     }
158   ok = 0;
159   for (i = 0; i < dcc_total; i++) {
160     if ((dcc[i].type == &DCC_CHAT) && (dcc[i].u.chat->channel != chan)) {
161       if (!ok) {
162         ok = 1;
163         dprintf(idx, "Other people on the bot:\n");
164       }
165       if (atr & USER_OWNER) {
166         EvangelineSnprintf(format, sizeof format, "  [%%.2lu]  %%c%%-%us ", nicklen);
167         sprintf(s, format, dcc[i].sock,
168                 (geticon(i) == '-' ? ' ' : geticon(i)), dcc[i].nick);
169       } else {
170         EvangelineSnprintf(format, sizeof format, "  %%c%%-%us ", nicklen);
171         sprintf(s, format, (geticon(i) == '-' ? ' ' : geticon(i)), dcc[i].nick);
172       }
173       if (atr & USER_MASTER) {
174         if (dcc[i].u.chat->channel < 0)
175           strcat(s, "(-OFF-) ");
176         else if (!dcc[i].u.chat->channel)
177           strcat(s, "(party) ");
178         else
179           sprintf(&s[strlen(s)], "(%5d) ", dcc[i].u.chat->channel);
180       }
181       strcat(s, dcc[i].host);
182       if (atr & USER_MASTER) {
183         if (dcc[i].u.chat->con_flags)
184           sprintf(&s[strlen(s)], " (con:%s)",
185                   masktype(dcc[i].u.chat->con_flags));
186       }
187       if (now - dcc[i].timeval > 300) {
188         k = (now - dcc[i].timeval) / 60;
189         if (k < 60)
190           sprintf(&s[strlen(s)], " (idle %dm)", k);
191         else
192           sprintf(&s[strlen(s)], " (idle %dh%dm)", k / 60, k % 60);
193       }
194       dprintf(idx, "%s\n", s);
195       if (dcc[i].u.chat->away != NULL)
196         dprintf(idx, "      AWAY: %s\n", dcc[i].u.chat->away);
197     }
198     if ((atr & USER_MASTER) && (dcc[i].type->flags & DCT_SHOWWHO) &&
199         (dcc[i].type != &DCC_CHAT)) {
200       if (!ok) {
201         ok = 1;
202         dprintf(idx, "Other people on the bot:\n");
203       }
204       if (atr & USER_OWNER) {
205         EvangelineSnprintf(format, sizeof format, "  [%%.2lu]  %%c%%-%us (files) %%s",
206                      nicklen);
207         sprintf(s, format,
208                 dcc[i].sock, dcc[i].status & STAT_CHAT ? '+' : ' ',
209                 dcc[i].nick, dcc[i].host);
210       } else {
211         EvangelineSnprintf(format, sizeof format, "  %%c%%-%us (files) %%s", nicklen);
212         sprintf(s, format,
213                 dcc[i].status & STAT_CHAT ? '+' : ' ',
214                 dcc[i].nick, dcc[i].host);
215       }
216       dprintf(idx, "%s\n", s);
217     }
218   }
219 }
220 /*
221 static void cmd_botinfo(struct userrec *u, int idx, char *par)
222 {
223   char s[512], s2[32];
224   struct chanset_t *chan;
225   time_t now2;
226   int hr, min;
227 
228   now2 = now - online_since;
229   s2[0] = 0;
230   if (now2 > 86400) {
231     int days = now2 / 86400;
232 
233     sprintf(s2, "%d day", days);
234     if (days >= 2)
235       strcat(s2, "s");
236     strcat(s2, ", ");
237     now2 -= days * 86400;
238   }
239   hr = (time_t) ((int) now2 / 3600);
240   now2 -= (hr * 3600);
241   min = (time_t) ((int) now2 / 60);
242   sprintf(&s2[strlen(s2)], "%02d:%02d", (int) hr, (int) min);
243   putlog(LOG_CMDS, "*", "#%s# botinfo", dcc[idx].nick);
244   simple_sprintf(s, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
245   botnet_send_infoq(-1, s);
246   s[0] = 0;
247   if (module_find("server", 0, 0)) {
248     for (chan = chanset; chan; chan = chan->next) {
249       if (!channel_secret(chan)) {
250         if ((strlen(s) + strlen(chan->dname) + strlen(network)
251              + strlen(botnetnick) + strlen(ver) + 1) >= 490) {
252           strcat(s, "++  ");
253           break;
254         }
255         strcat(s, chan->dname);
256         strcat(s, ", ");
257       }
258     }
259 
260     if (s[0]) {
261       s[strlen(s) - 2] = 0;
262       dprintf(idx, "*** [%s] %s <%s> (%s) [UP %s]\n", botnetnick,
263               ver, network, s, s2);
264     } else
265       dprintf(idx, "*** [%s] %s <%s> (%s) [UP %s]\n", botnetnick,
266               ver, network, BOT_NOCHANNELS, s2);
267   } else
268     dprintf(idx, "*** [%s] %s <NO_IRC> [UP %s]\n", botnetnick, ver, s2);
269 }
270 */
cmd_whom(struct userrec * u,int idx,char * par)271 static void cmd_whom(struct userrec *u, int idx, char *par)
272 {
273   if (par[0] == '*') {
274     putlog(LOG_CMDS, "*", "#%s# whom %s", dcc[idx].nick, par);
275     answer_local_whom(idx, -1);
276     return;
277   } else if (dcc[idx].u.chat->channel < 0) {
278     dprintf(idx, "You have chat turned off.\n");
279     return;
280   }
281   putlog(LOG_CMDS, "*", "#%s# whom %s", dcc[idx].nick, par);
282   if (!par[0]) {
283     answer_local_whom(idx, dcc[idx].u.chat->channel);
284   } else {
285     int chan = -1;
286 
287     if ((par[0] < '0') || (par[0] > '9')) {
288       Tcl_SetVar(interp, "chan", par, 0);
289       if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
290           Tcl_GetStringResult(interp)[0]) {
291         Tcl_GetIntFromObj(interp, Tcl_GetObjResult(interp), &chan);
292       }
293       if (chan <= 0) {
294         dprintf(idx, "No such channel exists.\n");
295         return;
296       }
297     } else
298       chan = atoi(par);
299     if ((chan < 0) || (chan >= GLOBAL_CHANS)) {
300       dprintf(idx, "Channel number out of range: must be between 0 and %d."
301               "\n", GLOBAL_CHANS);
302       return;
303     }
304     answer_local_whom(idx, chan);
305   }
306 }
307 
cmd_me(struct userrec * u,int idx,char * par)308 static void cmd_me(struct userrec *u, int idx, char *par)
309 {
310   int i;
311 
312   if (dcc[idx].u.chat->channel < 0) {
313     dprintf(idx, "You have chat turned off.\n");
314     return;
315   }
316   if (!par[0]) {
317     dprintf(idx, "Usage: me <action>\n");
318     return;
319   }
320   if (dcc[idx].u.chat->away != NULL)
321     not_away(idx);
322   for (i = 0; i < dcc_total; i++)
323     if ((dcc[i].type->flags & DCT_CHAT) &&
324         (dcc[i].u.chat->channel == dcc[idx].u.chat->channel) &&
325         ((i != idx) || (dcc[i].status & STAT_ECHO)))
326       dprintf(i, "* %s %s\n", dcc[idx].nick, par);
327   botnet_send_act(idx, botnetnick, dcc[idx].nick,
328                   dcc[idx].u.chat->channel, par);
329   check_tcl_act(dcc[idx].nick, dcc[idx].u.chat->channel, par);
330 }
331 
cmd_away(struct userrec * u,int idx,char * par)332 static void cmd_away(struct userrec *u, int idx, char *par)
333 {
334   if (strlen(par) > 60)
335     par[60] = 0;
336   set_away(idx, par);
337 }
338 
cmd_back(struct userrec * u,int idx,char * par)339 static void cmd_back(struct userrec *u, int idx, char *par)
340 {
341   not_away(idx);
342 }
343 
cmd_export(struct userrec * u,int idx,char * par)344 static void cmd_export(struct userrec *u, int idx, char *par)
345 {
346   if (!isowner(dcc[idx].nick) && !isadmin(dcc[idx].nick)) {
347     dprintf(idx, MISC_NOSUCHCMD);
348     return;
349   }
350   putlog(LOG_CMDS, "*", "#%s# export...", dcc[idx].nick);
351   exportUserfile();
352   dprintf(idx, "Exported userfile...\n");
353 }
354 
cmd_newpass(struct userrec * u,int idx,char * par)355 static void cmd_newpass(struct userrec *u, int idx, char *par)
356 {
357   char *new;
358 
359   if (!par[0]) {
360     dprintf(idx, "Usage: newpass <newpassword>\n");
361     return;
362   }
363   new = newsplit(&par);
364   if (strlen(new) > 16)
365     new[16] = 0;
366   if (strlen(new) < 6) {
367     dprintf(idx, "Please use at least 6 characters.\n");
368     return;
369   }
370   set_user(&USERENTRY_PASS, u, new);
371   putlog(LOG_CMDS, "*", "#%s# newpass...", dcc[idx].nick);
372   dprintf(idx, "Changed password to '%s'.\n", new);
373 }
374 
cmd_bots(struct userrec * u,int idx,char * par)375 static void cmd_bots(struct userrec *u, int idx, char *par)
376 {
377   putlog(LOG_CMDS, "*", "#%s# bots", dcc[idx].nick);
378   tell_bots(idx);
379 }
380 
cmd_bottree(struct userrec * u,int idx,char * par)381 static void cmd_bottree(struct userrec *u, int idx, char *par)
382 {
383   putlog(LOG_CMDS, "*", "#%s# bottree", dcc[idx].nick);
384   tell_bottree(idx, 0);
385 }
386 
cmd_vbottree(struct userrec * u,int idx,char * par)387 static void cmd_vbottree(struct userrec *u, int idx, char *par)
388 {
389   putlog(LOG_CMDS, "*", "#%s# vbottree", dcc[idx].nick);
390   tell_bottree(idx, 1);
391 }
392 
cmd_addlog(struct userrec * u,int idx,char * par)393 static void cmd_addlog(struct userrec *u, int idx, char *par)
394 {
395   if (!par[0]) {
396     dprintf(idx, "Usage: addlog <message>\n");
397     return;
398   }
399   dprintf(idx, "Placed entry in the log file.\n");
400   putlog(LOG_MISC, "*", "%s: %s", dcc[idx].nick, par);
401 }
402 
cmd_who(struct userrec * u,int idx,char * par)403 static void cmd_who(struct userrec *u, int idx, char *par)
404 {
405   int i;
406 
407   if (par[0]) {
408     if (dcc[idx].u.chat->channel < 0) {
409       dprintf(idx, "You have chat turned off.\n");
410       return;
411     }
412     putlog(LOG_CMDS, "*", "#%s# who %s", dcc[idx].nick, par);
413     if (!EvangelineStrcasecmp(par, botnetnick))
414       tell_who(u, idx, dcc[idx].u.chat->channel);
415     else {
416       i = nextbot(par);
417       if (i < 0) {
418         dprintf(idx, "That bot isn't connected.\n");
419       } else if (dcc[idx].u.chat->channel >= GLOBAL_CHANS)
420         dprintf(idx, "You are on a local channel.\n");
421       else {
422         char s[40];
423 
424         simple_sprintf(s, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
425         botnet_send_who(i, s, par, dcc[idx].u.chat->channel);
426       }
427     }
428   } else {
429     putlog(LOG_CMDS, "*", "#%s# who", dcc[idx].nick);
430     if (dcc[idx].u.chat->channel < 0)
431       tell_who(u, idx, 0);
432     else
433       tell_who(u, idx, dcc[idx].u.chat->channel);
434   }
435 }
436 
cmd_whois(struct userrec * u,int idx,char * par)437 static void cmd_whois(struct userrec *u, int idx, char *par)
438 {
439   struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0 };
440   char *handle;
441 
442   if (!par[0]) {
443     dprintf(idx, "Usage: whois <handle>\n");
444     return;
445   }
446   handle = newsplit(&par);
447   get_user_flagrec(u, &fr, NULL);
448   if (EvangelineStrcasecmp(handle, dcc[idx].nick) && !glob_botmast(fr) &&
449       !glob_op(fr) && !chan_master(fr)) {
450     dprintf(idx, "You do not have access to whois handles other than your "
451             "own.\n");
452     return;
453   }
454   putlog(LOG_CMDS, "*", "#%s# whois %s", dcc[idx].nick, handle);
455   tell_user_ident(idx, handle, u ? (u->flags & USER_MASTER) : 0);
456 }
457 
cmd_match(struct userrec * u,int idx,char * par)458 static void cmd_match(struct userrec *u, int idx, char *par)
459 {
460   int start = 1, limit = 20;
461   char *s, *s1, *chname;
462 
463   if (!par[0]) {
464     dprintf(idx, "Usage: match <nick/host> [[skip] count]\n");
465     return;
466   }
467   putlog(LOG_CMDS, "*", "#%s# match %s", dcc[idx].nick, par);
468   s = newsplit(&par);
469   if (strchr(CHANMETA, par[0]) != NULL)
470     chname = newsplit(&par);
471   else
472     chname = "";
473   if (atoi(par) > 0) {
474     s1 = newsplit(&par);
475     if (atoi(par) > 0) {
476       start = atoi(s1);
477       limit = atoi(par);
478     } else
479       limit = atoi(s1);
480   }
481   tell_users_match(idx, s, start, limit, u ? (u->flags & USER_MASTER) : 0,
482                    chname);
483 }
484 
cmd_uptime(struct userrec * u,int idx,char * par)485 static void cmd_uptime(struct userrec *u, int idx, char *par)
486 {
487   putlog(LOG_CMDS, "*", "#%s# uptime", dcc[idx].nick);
488   tell_verbose_uptime(idx);
489 }
490 
cmd_status(struct userrec * u,int idx,char * par)491 static void cmd_status(struct userrec *u, int idx, char *par)
492 {
493   int atr = u ? u->flags : 0;
494 
495   if (!EvangelineStrcasecmp(par, "all")) {
496     if (!(atr & USER_MASTER)) {
497       dprintf(idx, "You do not have Bot Master privileges.\n");
498       return;
499     }
500     putlog(LOG_CMDS, "*", "#%s# status all", dcc[idx].nick);
501     tell_verbose_status(idx);
502     tell_mem_status_dcc(idx);
503     dprintf(idx, "\n");
504     tell_settings(idx);
505     do_module_report(idx, 1, NULL);
506   } else {
507     putlog(LOG_CMDS, "*", "#%s# status", dcc[idx].nick);
508     tell_verbose_status(idx);
509     tell_mem_status_dcc(idx);
510     do_module_report(idx, 0, NULL);
511   }
512 }
513 
cmd_dccstat(struct userrec * u,int idx,char * par)514 static void cmd_dccstat(struct userrec *u, int idx, char *par)
515 {
516   putlog(LOG_CMDS, "*", "#%s# dccstat", dcc[idx].nick);
517   tell_dcc(idx);
518 }
519 
cmd_boot(struct userrec * u,int idx,char * par)520 static void cmd_boot(struct userrec *u, int idx, char *par)
521 {
522   int i, files = 0, ok = 0;
523   char *who;
524   struct userrec *u2;
525 
526   if (!par[0]) {
527     dprintf(idx, "Usage: boot nick[@bot]\n");
528     return;
529   }
530   who = newsplit(&par);
531   if (strchr(who, '@') != NULL) {
532     char whonick[HANDLEN + 1];
533 
534     splitcn(whonick, who, '@', HANDLEN + 1);
535     if (!EvangelineStrcasecmp(who, botnetnick)) {
536       cmd_boot(u, idx, whonick);
537       return;
538     }
539     if (remote_boots > 0) {
540       i = nextbot(who);
541       if (i < 0) {
542         dprintf(idx, "No such bot connected.\n");
543         return;
544       }
545       if (!isadmin(dcc[idx].nick) && isowner(whonick))
546         return;
547       botnet_send_reject(i, dcc[idx].nick, botnetnick, whonick,
548                          who, par[0] ? par : dcc[idx].nick);
549       putlog(LOG_BOTS, "*", "#%s# boot %s@%s (%s)", dcc[idx].nick, whonick,
550              who, par[0] ? par : dcc[idx].nick);
551     } else
552       dprintf(idx, "Remote boots are disabled here.\n");
553     return;
554   }
555   for (i = 0; i < dcc_total; i++)
556     if (!EvangelineStrcasecmp(dcc[i].nick, who) && !ok &&
557         (dcc[i].type->flags & DCT_CANBOOT)) {
558       u2 = get_user_by_handle(userlist, dcc[i].nick);
559       if (u2 && (u2->flags & USER_OWNER) &&
560           EvangelineStrcasecmp(dcc[idx].nick, who)) {
561         dprintf(idx, "You can't boot a bot owner.\n");
562         return;
563       }
564       if (isowner(who) && !isadmin(dcc[idx].nick)) {
565          dprintf(idx, "You can't boot a bot permowner.\n");
566          return;
567       }
568       if (u2 && (u2->flags & USER_MASTER) && !(u && (u->flags & USER_MASTER))) {
569         dprintf(idx, "You can't boot a bot master.\n");
570         return;
571       }
572       files = (dcc[i].type->flags & DCT_FILES);
573       if (files)
574         dprintf(idx, "Booted %s from the file area.\n", dcc[i].nick);
575       else
576         dprintf(idx, "Booted %s from the party line.\n", dcc[i].nick);
577       putlog(LOG_CMDS, "*", "#%s# boot %s %s", dcc[idx].nick, who, par);
578       do_boot(i, dcc[idx].nick, par);
579       ok = 1;
580     }
581   if (!ok)
582     dprintf(idx, "Who?  No such person on the party line.\n");
583 }
584 
cmd_console(struct userrec * u,int idx,char * par)585 static void cmd_console(struct userrec *u, int idx, char *par)
586 {
587   char *nick, s[2], s1[512];
588   int dest = 0, i, ok = 0, pls, md;
589   struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
590   module_entry *me;
591 
592   if (!par[0]) {
593     dprintf(idx, "Your console is %s: %s (%s).\n",
594             dcc[idx].u.chat->con_chan,
595             masktype(dcc[idx].u.chat->con_flags),
596             maskname(dcc[idx].u.chat->con_flags));
597     return;
598   }
599   get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
600   strcpy(s1, par);
601   nick = newsplit(&par);
602   if (nick[0] && !strchr(CHANMETA "+-*", nick[0]) && glob_master(fr)) {
603     for (i = 0; i < dcc_total; i++)
604       if (!EvangelineStrcasecmp(nick, dcc[i].nick) &&
605           (dcc[i].type == &DCC_CHAT) && (!ok)) {
606         ok = 1;
607         dest = i;
608       }
609     if (!ok) {
610       dprintf(idx, "No such user on the party line!\n");
611       return;
612     }
613     nick[0] = 0;
614   } else
615     dest = idx;
616   if (!nick[0])
617     nick = newsplit(&par);
618   if ((nick[0] == '+' && findchan_by_dname(nick)) ||
619       (nick[0] != '+' && strchr(CHANMETA "*", nick[0]))) {
620     if (strcmp(nick, "*") && !findchan_by_dname(nick)) {
621       dprintf(idx, "Invalid console channel: %s.\n", nick);
622       return;
623     }
624     get_user_flagrec(u, &fr, nick);
625     if (!chan_op(fr) && !(glob_op(fr) && !chan_deop(fr))) {
626       dprintf(idx, "You don't have op or master access to channel %s.\n",
627               nick);
628       return;
629     }
630     strncpyz(dcc[dest].u.chat->con_chan, nick, 81);
631     nick[0] = 0;
632     if ((dest == idx) && !glob_master(fr) && !chan_master(fr))
633       dcc[dest].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_WALL);
634   }
635   if (!nick[0])
636     nick = newsplit(&par);
637   pls = 1;
638   if (nick[0]) {
639     if ((nick[0] != '+') && (nick[0] != '-'))
640       dcc[dest].u.chat->con_flags = 0;
641     for (; *nick; nick++) {
642       if (*nick == '+')
643         pls = 1;
644       else if (*nick == '-')
645         pls = 0;
646       else {
647         s[0] = *nick;
648         s[1] = 0;
649         md = logmodes(s);
650         if ((dest == idx) && !glob_master(fr) && pls) {
651           if (chan_master(fr))
652             md &= ~(LOG_FILES | LOG_LEV1 | LOG_LEV2 | LOG_LEV3 |
653                     LOG_LEV4 | LOG_LEV5 | LOG_LEV6 | LOG_LEV7 | LOG_DEBUG);
654           else
655             md &= ~(LOG_MISC | LOG_CMDS | LOG_FILES | LOG_LEV1 |
656                     LOG_LEV2 | LOG_LEV3 | LOG_LEV4 | LOG_LEV5 |
657                     LOG_LEV6 | LOG_LEV7 | LOG_WALL | LOG_DEBUG);
658         }
659         if (!glob_owner(fr) && pls)
660           md &= ~(LOG_RAW | LOG_SRVOUT | LOG_BOTNET | LOG_BOTSHARE);
661         if (!glob_botmast(fr) && pls)
662           md &= ~LOG_BOTS;
663         if (pls)
664           dcc[dest].u.chat->con_flags |= md;
665         else
666           dcc[dest].u.chat->con_flags &= ~md;
667       }
668     }
669   }
670   putlog(LOG_CMDS, "*", "#%s# console %s", dcc[idx].nick, s1);
671   if (dest == idx) {
672     dprintf(idx, "Set your console to %s: %s (%s).\n",
673             dcc[idx].u.chat->con_chan,
674             masktype(dcc[idx].u.chat->con_flags),
675             maskname(dcc[idx].u.chat->con_flags));
676   } else {
677     dprintf(idx, "Set console of %s to %s: %s (%s).\n", dcc[dest].nick,
678             dcc[dest].u.chat->con_chan,
679             masktype(dcc[dest].u.chat->con_flags),
680             maskname(dcc[dest].u.chat->con_flags));
681     dprintf(dest, "%s set your console to %s: %s (%s).\n", dcc[idx].nick,
682             dcc[dest].u.chat->con_chan,
683             masktype(dcc[dest].u.chat->con_flags),
684             maskname(dcc[dest].u.chat->con_flags));
685   }
686   if ((me = module_find("console", 1, 1))) {
687     Function *func = me->funcs;
688 
689     (func[CONSOLE_DOSTORE]) (dest);
690   }
691 }
692 
cmd_pls_bot(struct userrec * u,int idx,char * par)693 static void cmd_pls_bot(struct userrec *u, int idx, char *par)
694 {
695   char *handle, *addr, *p, *q, *host, comment[128], s[24]="";
696   struct userrec *u1;
697   struct bot_addr *bi;
698 
699   if (!par[0]) {
700     dprintf(idx, "Usage: +bot <handle> [address[:telnet-port[/relay-port]]] "
701             "[host]\n");
702     return;
703   }
704 
705   handle = newsplit(&par);
706   addr = newsplit(&par);
707   host = newsplit(&par);
708 
709   if (strlen(handle) > HANDLEN)
710     handle[HANDLEN] = 0;
711 
712   if (get_user_by_handle(userlist, handle))
713     dprintf(idx, "Someone already exists by that name.\n");
714   else if (strchr(BADHANDCHARS, handle[0]) != NULL)
715     dprintf(idx, "You can't start a botnick with '%c'.\n", handle[0]);
716   else {
717     if (strlen(addr) > 60)
718       addr[60] = 0;
719     putlog(LOG_CMDS, "*", "#%s# +bot %s%s%s%s%s", dcc[idx].nick, handle,
720            addr[0] ? " " : "", addr, host[0] ? " " : "", host);
721     userlist = adduser(userlist, handle, "none", "-", USER_BOT);
722     u1 = get_user_by_handle(userlist, handle);
723     bi = user_malloc(sizeof(struct bot_addr));
724 
725     q = strchr(addr, ':');
726     if (!q) {
727       bi->address = user_malloc(strlen(addr) + 1);
728       strcpy(bi->address, addr);
729       bi->telnet_port = 3333;
730       bi->relay_port = 3333;
731     } else {
732       bi->address = user_malloc(q - addr + 1);
733       strncpy(bi->address, addr, q - addr);
734       bi->address[q - addr] = 0;
735       p = q + 1;
736       bi->telnet_port = atoi(p);
737       q = strchr(p, '/');
738       if (!q)
739         bi->relay_port = bi->telnet_port;
740       else
741         bi->relay_port = atoi(q + 1);
742     }
743     set_user(&USERENTRY_BOTADDR, u1, bi);
744     strftime(s, 23, "%d.%m.%Y %H:%M:%S", localtime(&now));
745     sprintf(comment, "Added by: %s (%s)", dcc[idx].nick, s);
746     set_user(&USERENTRY_COMMENT, u1, comment);
747     dprintf(idx, "Added bot '%s' with %s%s%s%s and %s%s%s%s.\n", handle,
748             addr[0] ? "address " : "no address ", addr[0] ? "'" : "",
749             addr[0] ? addr : "", addr[0] ? "'" : "",
750             host[0] ? "hostmask " : "no hostmask", addr[0] ? "'" : "",
751             host[0] ? host : "", addr[0] ? "'" : "");
752     if (host[0])
753       addhost_by_handle(handle, host);
754     else if (!add_bot_hostmask(idx, handle))
755       dprintf(idx, "You'll want to add a hostmask if this bot will ever %s",
756               "be on any channels that I'm on.\n");
757   }
758 }
759 
cmd_chhandle(struct userrec * u,int idx,char * par)760 static void cmd_chhandle(struct userrec *u, int idx, char *par)
761 {
762   char hand[HANDLEN + 1], newhand[HANDLEN + 1];
763   int i, atr = u ? u->flags : 0, atr2;
764   struct userrec *u2;
765 
766   strncpyz(hand, newsplit(&par), sizeof hand);
767   strncpyz(newhand, newsplit(&par), sizeof newhand);
768 
769   if (!hand[0] || !newhand[0]) {
770     dprintf(idx, "Usage: chhandle <oldhandle> <newhandle>\n");
771     return;
772   }
773   for (i = 0; i < strlen(newhand); i++)
774     if ((newhand[i] <= 32) || (newhand[i] >= 127) || (newhand[i] == '@'))
775       newhand[i] = '?';
776   if (strchr(BADHANDCHARS, newhand[0]) != NULL)
777     dprintf(idx, "Bizarre quantum forces prevent nicknames from starting with "
778             "'%c'.\n", newhand[0]);
779   else if (get_user_by_handle(userlist, newhand) &&
780            EvangelineStrcasecmp(hand, newhand))
781     dprintf(idx, "Somebody is already using %s.\n", newhand);
782   else {
783     u2 = get_user_by_handle(userlist, hand);
784     atr2 = u2 ? u2->flags : 0;
785     if ((atr & USER_BOTMAST) && !(atr & USER_MASTER) && !(atr2 & USER_BOT))
786       dprintf(idx, "You can't change handles for non-bots.\n");
787     else if ((bot_flags(u2) & BOT_SHARE) && !(atr & USER_OWNER))
788       dprintf(idx, "You can't change share bot's nick.\n");
789     else if ((atr2 & USER_OWNER) && !(atr & USER_OWNER) &&
790              EvangelineStrcasecmp(dcc[idx].nick, hand))
791       dprintf(idx, "You can't change a bot owner's handle.\n");
792     else if (isowner(hand) && EvangelineStrcasecmp(dcc[idx].nick, hand) && !isadmin(dcc[idx].nick))
793       dprintf(idx, "You can't change a permanent bot owner's handle.\n");
794     else if (isadmin(hand) && EvangelineStrcasecmp(dcc[idx].nick, hand) && !isadmin(dcc[idx].nick))
795       dprintf(idx, "Can't change the bot admin handle.\n");
796     else if (!EvangelineStrcasecmp(newhand, botnetnick) && (!(atr2 & USER_BOT) ||
797              nextbot(hand) != -1))
798       dprintf(idx, "Hey! That's MY name!\n");
799     else if (change_handle(u2, newhand)) {
800       putlog(LOG_CMDS, "*", "#%s# chhandle %s %s", dcc[idx].nick,
801              hand, newhand);
802       dprintf(idx, "Changed.\n");
803     } else
804       dprintf(idx, "Failed.\n");
805   }
806 }
807 
cmd_handle(struct userrec * u,int idx,char * par)808 static void cmd_handle(struct userrec *u, int idx, char *par)
809 {
810   char oldhandle[HANDLEN + 1], newhandle[HANDLEN + 1];
811   int i;
812 
813   strncpyz(newhandle, newsplit(&par), sizeof newhandle);
814 
815   if (!newhandle[0]) {
816     dprintf(idx, "Usage: handle <new-handle>\n");
817     return;
818   }
819   for (i = 0; i < strlen(newhandle); i++)
820     if ((newhandle[i] <= 32) || (newhandle[i] >= 127) || (newhandle[i] == '@'))
821       newhandle[i] = '?';
822   if (strchr(BADHANDCHARS, newhandle[0]) != NULL)
823     dprintf(idx,
824             "Bizarre quantum forces prevent handle from starting with '%c'.\n",
825             newhandle[0]);
826   else if (get_user_by_handle(userlist, newhandle) &&
827            EvangelineStrcasecmp(dcc[idx].nick, newhandle))
828     dprintf(idx, "Somebody is already using %s.\n", newhandle);
829   else if (!EvangelineStrcasecmp(newhandle, botnetnick))
830     dprintf(idx, "Hey!  That's MY name!\n");
831   else {
832     strncpyz(oldhandle, dcc[idx].nick, sizeof oldhandle);
833     if (change_handle(u, newhandle)) {
834       putlog(LOG_CMDS, "*", "#%s# handle %s", oldhandle, newhandle);
835       dprintf(idx, "Okay, changed.\n");
836     } else
837       dprintf(idx, "Failed.\n");
838   }
839 }
840 
cmd_chpass(struct userrec * u,int idx,char * par)841 static void cmd_chpass(struct userrec *u, int idx, char *par)
842 {
843   char *handle, *new;
844   int atr = u ? u->flags : 0, l;
845 
846   if (!par[0])
847     dprintf(idx, "Usage: chpass <handle> [password]\n");
848   else {
849     handle = newsplit(&par);
850     u = get_user_by_handle(userlist, handle);
851     if (!u)
852       dprintf(idx, "No such user.\n");
853     else if ((atr & USER_BOTMAST) && !(atr & USER_MASTER) &&
854              !(u->flags & USER_BOT))
855       dprintf(idx, "You can't change passwords for non-bots.\n");
856     else if ((bot_flags(u) & BOT_SHARE) && !(atr & USER_OWNER))
857       dprintf(idx, "You can't change a share bot's password.\n");
858     else if ((u->flags & USER_OWNER) && !(atr & USER_OWNER) &&
859              EvangelineStrcasecmp(handle, dcc[idx].nick))
860       dprintf(idx, "You can't change a bot owner's password.\n");
861     else if (isowner(handle) && EvangelineStrcasecmp(dcc[idx].nick, handle) && !isadmin(dcc[idx].nick))
862       dprintf(idx, "You can't change a permanent bot owner's password.\n");
863     else if (isadmin(handle) && EvangelineStrcasecmp(dcc[idx].nick, handle) && !isadmin(dcc[idx].nick))
864       dprintf(idx, "Can't change the bot admin password.\n");
865     else if (!par[0]) {
866       putlog(LOG_CMDS, "*", "#%s# chpass %s [nothing]", dcc[idx].nick, handle);
867       set_user(&USERENTRY_PASS, u, NULL);
868       dprintf(idx, "Removed password.\n");
869     } else {
870       l = strlen(new = newsplit(&par));
871       if (l > 16)
872         new[16] = 0;
873       if (l < 6)
874         dprintf(idx, "Please use at least 6 characters.\n");
875       else {
876         set_user(&USERENTRY_PASS, u, new);
877         putlog(LOG_CMDS, "*", "#%s# chpass %s [something]", dcc[idx].nick,
878                handle);
879         dprintf(idx, "Changed password.\n");
880       }
881     }
882   }
883 }
884 
cmd_chaddr(struct userrec * u,int idx,char * par)885 static void cmd_chaddr(struct userrec *u, int idx, char *par)
886 {
887   int telnet_port = 3333, relay_port = 3333;
888   char *handle, *addr, *p, *q;
889   struct bot_addr *bi;
890   struct userrec *u1;
891 
892   handle = newsplit(&par);
893   if (!par[0]) {
894     dprintf(idx, "Usage: chaddr <botname> "
895             "<address[:telnet-port[/relay-port]]>\n");
896     return;
897   }
898   addr = newsplit(&par);
899   if (strlen(addr) > UHOSTMAX)
900     addr[UHOSTMAX] = 0;
901   u1 = get_user_by_handle(userlist, handle);
902   if (!u1 || !(u1->flags & USER_BOT)) {
903     dprintf(idx, "This command is only useful for tandem bots.\n");
904     return;
905   }
906   if ((bot_flags(u1) & BOT_SHARE) && (!u || !u->flags & USER_OWNER)) {
907     dprintf(idx, "You can't change a share bot's address.\n");
908     return;
909   }
910   putlog(LOG_CMDS, "*", "#%s# chaddr %s %s", dcc[idx].nick, handle, addr);
911   dprintf(idx, "Changed bot's address.\n");
912 
913   bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u1);
914   if (bi) {
915     telnet_port = bi->telnet_port;
916     relay_port = bi->relay_port;
917   }
918 
919   bi = user_malloc(sizeof(struct bot_addr));
920 
921   q = strchr(addr, ':');
922   if (!q) {
923     bi->address = user_malloc(strlen(addr) + 1);
924     strcpy(bi->address, addr);
925     bi->telnet_port = telnet_port;
926     bi->relay_port = relay_port;
927   } else {
928     bi->address = user_malloc(q - addr + 1);
929     strncpyz(bi->address, addr, q - addr + 1);
930     p = q + 1;
931     bi->telnet_port = atoi(p);
932     q = strchr(p, '/');
933     if (!q)
934       bi->relay_port = bi->telnet_port;
935     else
936       bi->relay_port = atoi(q + 1);
937   }
938   set_user(&USERENTRY_BOTADDR, u1, bi);
939 }
940 
cmd_comment(struct userrec * u,int idx,char * par)941 static void cmd_comment(struct userrec *u, int idx, char *par)
942 {
943   char *handle;
944   struct userrec *u1;
945 
946   if (!isowner(dcc[idx].nick) && !isadmin(dcc[idx].nick)) {
947     dprintf(idx, MISC_NOSUCHCMD);
948     return;
949   }
950 
951   handle = newsplit(&par);
952   if (!par[0]) {
953     dprintf(idx, "Usage: comment <handle> <newcomment>\n");
954     return;
955   }
956   u1 = get_user_by_handle(userlist, handle);
957   if (!u1) {
958     dprintf(idx, "No such user!\n");
959     return;
960   }
961   if ((u1->flags & USER_OWNER) && !(u && (u->flags & USER_OWNER)) &&
962       EvangelineStrcasecmp(handle, dcc[idx].nick)) {
963     dprintf(idx, "You can't change comment on a bot owner.\n");
964     return;
965   }
966   putlog(LOG_CMDS, "*", "#%s# comment %s %s", dcc[idx].nick, handle, par);
967   if (!EvangelineStrcasecmp(par, "none")) {
968     dprintf(idx, "Okay, comment blanked.\n");
969     set_user(&USERENTRY_COMMENT, u1, NULL);
970     return;
971   }
972   dprintf(idx, "Changed comment.\n");
973   set_user(&USERENTRY_COMMENT, u1, par);
974 }
975 
cmd_import(struct userrec * u,int idx,char * par)976 static void cmd_import(struct userrec *u, int idx, char *par)
977 {
978   FILE *tmpf;
979   char *fname, tmpfn[100], tmp[512];
980 
981   if (!isowner(dcc[idx].nick) && !isadmin(dcc[idx].nick)) {
982     dprintf(idx, MISC_NOSUCHCMD);
983     return;
984   }
985   if (!par[0]) {
986     dprintf(idx, "Usage: .import <userfile>\n");
987     return;
988   }
989   fname = newsplit(&par);
990   if (file_readable(fname))
991     sprintf(tmpfn, "%s", fname);
992   else
993     sprintf(tmpfn, "%s%s", datadir, fname);
994   tmpf = fopen(tmpfn, "r");
995   if (tmpf == NULL) {
996     fclose(tmpf);
997     dprintf(idx, "Can't open file: %s\n", fname);
998     return;
999   }
1000   if (is_compressedfile(tmpfn))
1001     uncompress_file(tmpfn);
1002   fgets(tmp, 511, tmpf);
1003   if (strncmp(tmp, "#4v: ", 5) && strncmp(tmp, "#4!: ", 5)) {
1004     dprintf(idx, "Invalid userfile format: %s\n", tmpfn);
1005     return;
1006   }
1007   fclose(tmpf);
1008   sprintf(tmp, "%s.prv", userfile);
1009   copyfile(userfile, tmp);
1010   copyfile(tmpfn, userfile);
1011   decryptUserfile(userfile, 1);
1012   noshare = 1;
1013   clear_userlist(userlist);
1014   noshare = 0;
1015   userlist = NULL;
1016   if (!readuserfile(userfile, &userlist, userfileCryptKey))
1017     fatal(MISC_MISSINGUSERF, 0);
1018   reaffirm_owners();
1019   call_hook(HOOK_READ_USERFILE);
1020   write_userfile(-1, userfileCryptKey);
1021   putlog(LOG_MISC, "*", "Imported userfile: %s", tmpfn);
1022   dprintf(idx, "Old userfile saved to: %s\n", tmp);
1023   return;
1024 }
1025 
cmd_restart(struct userrec * u,int idx,char * par)1026 static void cmd_restart(struct userrec *u, int idx, char *par)
1027 {
1028   putlog(LOG_CMDS, "*", "#%s# restart", dcc[idx].nick);
1029   if (!backgrd) {
1030     dprintf(idx, "You cannot .restart a bot when running -n (due to Tcl).\n");
1031     return;
1032   }
1033   dprintf(idx, "Restarting.\n");
1034   if (make_userfile) {
1035     putlog(LOG_MISC, "*", "Uh, guess you don't need to create a new userfile.");
1036     make_userfile = 0;
1037   }
1038   write_userfile(-1, userfileCryptKey);
1039   putlog(LOG_MISC, "*", "Restarting ...");
1040   wipe_timers(interp, &utimer);
1041   wipe_timers(interp, &timer);
1042   do_restart = idx;
1043 }
1044 
cmd_rehash(struct userrec * u,int idx,char * par)1045 static void cmd_rehash(struct userrec *u, int idx, char *par)
1046 {
1047   putlog(LOG_CMDS, "*", "#%s# rehash", dcc[idx].nick);
1048   dprintf(idx, "Rehashing.\n");
1049   if (make_userfile) {
1050     putlog(LOG_MISC, "*", "Uh, guess you don't need to create a new userfile.");
1051     make_userfile = 0;
1052   }
1053   write_userfile(-1, userfileCryptKey);
1054   putlog(LOG_MISC, "*", "Rehashing ...");
1055   do_restart = -2;
1056 }
1057 
cmd_reload(struct userrec * u,int idx,char * par)1058 static void cmd_reload(struct userrec *u, int idx, char *par)
1059 {
1060   putlog(LOG_CMDS, "*", "#%s# reload", dcc[idx].nick);
1061   dprintf(idx, "Reloading user file...\n");
1062   reload();
1063 }
1064 
cmd_die(struct userrec * u,int idx,char * par)1065 void cmd_die(struct userrec *u, int idx, char *par)
1066 {
1067   char s1[1024], s2[1024];
1068 
1069   putlog(LOG_CMDS, "*", "#%s# die %s", dcc[idx].nick, par);
1070   if (par[0]) {
1071     EvangelineSnprintf(s1, sizeof s1, "BOT SHUTDOWN (%s: %s)", dcc[idx].nick, par);
1072     EvangelineSnprintf(s2, sizeof s2, "DIE BY %s!%s (%s)", dcc[idx].nick,
1073                  dcc[idx].host, par);
1074     strncpyz(quit_msg, par, 1024);
1075   } else {
1076     EvangelineSnprintf(s1, sizeof s1, "BOT SHUTDOWN (Authorized by %s)",
1077                  dcc[idx].nick);
1078     EvangelineSnprintf(s2, sizeof s2, "DIE BY %s!%s (request)", dcc[idx].nick,
1079                  dcc[idx].host);
1080     strncpyz(quit_msg, dcc[idx].nick, 1024);
1081   }
1082   kill_bot(s1, s2);
1083 }
1084 
cmd_debug(struct userrec * u,int idx,char * par)1085 static void cmd_debug(struct userrec *u, int idx, char *par)
1086 {
1087   putlog(LOG_CMDS, "*", "#%s# debug", dcc[idx].nick);
1088   debug_mem_to_dcc(idx);
1089 }
1090 
cmd_simul(struct userrec * u,int idx,char * par)1091 static void cmd_simul(struct userrec *u, int idx, char *par)
1092 {
1093   char *nick;
1094   int i, ok = 0;
1095 
1096   nick = newsplit(&par);
1097   if (!par[0]) {
1098     dprintf(idx, "Usage: simul <hand> <text>\n");
1099     return;
1100   }
1101   if ((isowner(nick) || isadmin(nick)) && !isadmin(dcc[idx].nick)) {
1102     dprintf(idx, "Unable to '.simul' permanent owners.\n");
1103     return;
1104   }
1105   for (i = 0; i < dcc_total; i++)
1106     if (!EvangelineStrcasecmp(nick, dcc[i].nick) && !ok &&
1107         (dcc[i].type->flags & DCT_SIMUL)) {
1108       putlog(LOG_CMDS, "*", "#%s# simul %s %s", dcc[idx].nick, nick, par);
1109       if (dcc[i].type && dcc[i].type->activity) {
1110         dcc[i].type->activity(i, par, strlen(par));
1111         ok = 1;
1112       }
1113     }
1114   if (!ok)
1115     dprintf(idx, "No such user on the party line.\n");
1116 }
1117 
cmd_link(struct userrec * u,int idx,char * par)1118 static void cmd_link(struct userrec *u, int idx, char *par)
1119 {
1120   char *s;
1121   int i;
1122 
1123   if (!par[0]) {
1124     dprintf(idx, "Usage: link [some-bot] <new-bot>\n");
1125     return;
1126   }
1127   putlog(LOG_CMDS, "*", "#%s# link %s", dcc[idx].nick, par);
1128   s = newsplit(&par);
1129   if (!par[0] || !EvangelineStrcasecmp(par, botnetnick))
1130     botlink(dcc[idx].nick, idx, s);
1131   else {
1132     char x[40];
1133 
1134     i = nextbot(s);
1135     if (i < 0) {
1136       dprintf(idx, "No such bot online.\n");
1137       return;
1138     }
1139     simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1140     botnet_send_link(i, x, s, par);
1141   }
1142 }
1143 
cmd_unlink(struct userrec * u,int idx,char * par)1144 static void cmd_unlink(struct userrec *u, int idx, char *par)
1145 {
1146   int i;
1147   char *bot;
1148 
1149   if (!par[0]) {
1150     dprintf(idx, "Usage: unlink <bot> [reason]\n");
1151     return;
1152   }
1153   putlog(LOG_CMDS, "*", "#%s# unlink %s", dcc[idx].nick, par);
1154   bot = newsplit(&par);
1155   i = nextbot(bot);
1156   if (i < 0) {
1157     botunlink(idx, bot, par, dcc[idx].nick);
1158     return;
1159   }
1160   if (!EvangelineStrcasecmp(dcc[i].nick, bot))
1161     botunlink(idx, bot, par, dcc[i].nick);
1162   else {
1163     char x[40];
1164 
1165     simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1166     botnet_send_unlink(i, x, lastbot(bot), bot, par);
1167   }
1168 }
1169 
cmd_relay(struct userrec * u,int idx,char * par)1170 static void cmd_relay(struct userrec *u, int idx, char *par)
1171 {
1172   if (!par[0]) {
1173     dprintf(idx, "Usage: relay <bot>\n");
1174     return;
1175   }
1176   putlog(LOG_CMDS, "*", "#%s# relay %s", dcc[idx].nick, par);
1177   tandem_relay(idx, par, 0);
1178 }
1179 
cmd_save(struct userrec * u,int idx,char * par)1180 static void cmd_save(struct userrec *u, int idx, char *par)
1181 {
1182   putlog(LOG_CMDS, "*", "#%s# save", dcc[idx].nick);
1183   dprintf(idx, "Saving...\n");
1184   write_userfile(-1, userfileCryptKey);
1185 }
1186 
cmd_backup(struct userrec * u,int idx,char * par)1187 static void cmd_backup(struct userrec *u, int idx, char *par)
1188 {
1189   putlog(LOG_CMDS, "*", "#%s# backup", dcc[idx].nick);
1190   dprintf(idx, "Backing up the channel & user files...\n");
1191   call_hook(HOOK_BACKUP);
1192 }
1193 
cmd_trace(struct userrec * u,int idx,char * par)1194 static void cmd_trace(struct userrec *u, int idx, char *par)
1195 {
1196   int i;
1197   char x[NOTENAMELEN + 11], y[11];
1198 
1199   if (!par[0]) {
1200     dprintf(idx, "Usage: trace <botname>\n");
1201     return;
1202   }
1203   if (!EvangelineStrcasecmp(par, botnetnick)) {
1204     dprintf(idx, "That's me!  Hiya! :)\n");
1205     return;
1206   }
1207   i = nextbot(par);
1208   if (i < 0) {
1209     dprintf(idx, "Unreachable bot.\n");
1210     return;
1211   }
1212   putlog(LOG_CMDS, "*", "#%s# trace %s", dcc[idx].nick, par);
1213   simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
1214   simple_sprintf(y, ":%d", now);
1215   botnet_send_trace(i, x, par, y);
1216 }
1217 
cmd_binds(struct userrec * u,int idx,char * par)1218 static void cmd_binds(struct userrec *u, int idx, char *par)
1219 {
1220   putlog(LOG_CMDS, "*", "#%s# binds %s", dcc[idx].nick, par);
1221   tell_binds(idx, par);
1222 }
1223 
1224 /* After messing with someone's user flags, make sure the dcc-chat flags are set correctly. */
check_dcc_attrs(struct userrec * u,int oatr)1225 int check_dcc_attrs(struct userrec *u, int oatr)
1226 {
1227   int i, stat;
1228 
1229   if (!u)
1230     return 0;
1231   /* Make sure default owners are +n */
1232   if (isowner(u->handle)) {
1233     u->flags = sanity_check(u->flags | USER_OWNER);
1234   }
1235   for (i = 0; i < dcc_total; i++) {
1236     if ((dcc[i].type->flags & DCT_MASTER) &&
1237         (!EvangelineStrcasecmp(u->handle, dcc[i].nick))) {
1238       stat = dcc[i].status;
1239       if ((dcc[i].type == &DCC_CHAT) &&
1240           ((u->flags & (USER_OP | USER_MASTER | USER_OWNER | USER_BOTMAST)) !=
1241           (oatr & (USER_OP | USER_MASTER | USER_OWNER | USER_BOTMAST)))) {
1242         botnet_send_join_idx(i, -1);
1243       }
1244       if ((oatr & USER_MASTER) && !(u->flags & USER_MASTER)) {
1245         struct flag_record fr = { FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0 };
1246 
1247         dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_RAW |
1248                                       LOG_FILES | LOG_LEV1 | LOG_LEV2 |
1249                                       LOG_LEV3 | LOG_LEV4 | LOG_LEV5 |
1250                                       LOG_LEV6 | LOG_LEV7 | LOG_WALL | LOG_DEBUG);
1251         get_user_flagrec(u, &fr, NULL);
1252         if (!chan_master(fr))
1253           dcc[i].u.chat->con_flags |= (LOG_MISC | LOG_CMDS);
1254         dprintf(i, "*** POOF! ***\n");
1255         dprintf(i, "You are no longer a master on this bot.\n");
1256       }
1257       if (!(oatr & USER_MASTER) && (u->flags & USER_MASTER)) {
1258         dcc[i].u.chat->con_flags |= conmask;
1259         dprintf(i, "*** POOF! ***\n");
1260         dprintf(i, "You are now a master on this bot.\n");
1261       }
1262       if (!(oatr & USER_BOTMAST) && (u->flags & USER_BOTMAST)) {
1263         dprintf(i, "### POOF! ###\n");
1264         dprintf(i, "You are now a botnet master on this bot.\n");
1265       }
1266       if ((oatr & USER_BOTMAST) && !(u->flags & USER_BOTMAST)) {
1267         dprintf(i, "### POOF! ###\n");
1268         dprintf(i, "You are no longer a botnet master on this bot.\n");
1269       }
1270       if (!(oatr & USER_OWNER) && (u->flags & USER_OWNER)) {
1271         dprintf(i, "@@@ POOF! @@@\n");
1272         dprintf(i, "You are now an OWNER of this bot.\n");
1273       }
1274       if ((oatr & USER_OWNER) && !(u->flags & USER_OWNER)) {
1275         dprintf(i, "@@@ POOF! @@@\n");
1276         dprintf(i, "You are no longer an owner of this bot.\n");
1277       }
1278       if ((stat & STAT_PARTY) && (u->flags & USER_OP))
1279         stat &= ~STAT_PARTY;
1280       if (!(stat & STAT_PARTY) && !(u->flags & USER_OP) &&
1281           !(u->flags & USER_MASTER))
1282         stat |= STAT_PARTY;
1283       if ((stat & STAT_CHAT) && !(u->flags & USER_PARTY) &&
1284           !(u->flags & USER_MASTER) && (!(u->flags & USER_OP) || require_p))
1285         stat &= ~STAT_CHAT;
1286       if ((dcc[i].type->flags & DCT_FILES) && !(stat & STAT_CHAT) &&
1287           ((u->flags & USER_MASTER) || (u->flags & USER_PARTY) ||
1288           ((u->flags & USER_OP) && !require_p)))
1289         stat |= STAT_CHAT;
1290       dcc[i].status = stat;
1291       if ((dcc[i].type->flags & DCT_FILES) && !(u->flags & USER_XFER) &&
1292           !(u->flags & USER_MASTER)) {
1293         dprintf(i, "-+- POOF! -+-\n");
1294         dprintf(i, "You no longer have file area access.\n\n");
1295         putlog(LOG_MISC, "*", "DCC user [%s]%s removed from file system",
1296                dcc[i].nick, dcc[i].host);
1297         if (dcc[i].status & STAT_CHAT) {
1298           struct chat_info *ci;
1299 
1300           ci = dcc[i].u.file->chat;
1301           nfree(dcc[i].u.file);
1302           dcc[i].u.chat = ci;
1303           dcc[i].status &= (~STAT_CHAT);
1304           dcc[i].type = &DCC_CHAT;
1305           if (dcc[i].u.chat->channel >= 0) {
1306             chanout_but(-1, dcc[i].u.chat->channel,
1307                         "*** %s has returned.\n", dcc[i].nick);
1308             if (dcc[i].u.chat->channel < GLOBAL_CHANS)
1309               botnet_send_join_idx(i, -1);
1310           }
1311         } else {
1312           killsock(dcc[i].sock);
1313           lostdcc(i);
1314         }
1315       }
1316     }
1317     if (dcc[i].type == &DCC_BOT && !EvangelineStrcasecmp(u->handle, dcc[i].nick)) {
1318       if ((dcc[i].status & STAT_LEAF) && !(u->flags & BOT_LEAF))
1319         dcc[i].status &= ~(STAT_LEAF | STAT_WARNED);
1320       if (!(dcc[i].status & STAT_LEAF) && (u->flags & BOT_LEAF))
1321         dcc[i].status |= STAT_LEAF;
1322     }
1323   }
1324   return u->flags;
1325 }
1326 
check_dcc_chanattrs(struct userrec * u,char * chname,int chflags,int ochatr)1327 int check_dcc_chanattrs(struct userrec *u, char *chname, int chflags,
1328                         int ochatr)
1329 {
1330   int i, found = 0, atr = u ? u->flags : 0;
1331   struct chanset_t *chan;
1332 
1333   if (!u)
1334     return 0;
1335   for (i = 0; i < dcc_total; i++) {
1336     if ((dcc[i].type->flags & DCT_MASTER) &&
1337         !EvangelineStrcasecmp(u->handle, dcc[i].nick)) {
1338       if ((dcc[i].type == &DCC_CHAT) &&
1339           ((chflags & (USER_OP | USER_MASTER | USER_OWNER)) !=
1340           (ochatr & (USER_OP | USER_MASTER | USER_OWNER))))
1341         botnet_send_join_idx(i, -1);
1342       if ((ochatr & USER_MASTER) && !(chflags & USER_MASTER)) {
1343         if (!(atr & USER_MASTER))
1344           dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS);
1345         dprintf(i, "*** POOF! ***\n");
1346         dprintf(i, "You are no longer a master on %s.\n", chname);
1347       }
1348       if (!(ochatr & USER_MASTER) && (chflags & USER_MASTER)) {
1349         dcc[i].u.chat->con_flags |= conmask;
1350         if (!(atr & USER_MASTER))
1351           dcc[i].u.chat->con_flags &= ~(LOG_LEV1 | LOG_LEV2 | LOG_LEV3 |
1352                                         LOG_LEV4 | LOG_LEV5 | LOG_LEV6 |
1353                                         LOG_LEV7 | LOG_RAW | LOG_DEBUG |
1354                                         LOG_WALL | LOG_FILES | LOG_SRVOUT);
1355         dprintf(i, "*** POOF! ***\n");
1356         dprintf(i, "You are now a master on %s.\n", chname);
1357       }
1358       if (!(ochatr & USER_OWNER) && (chflags & USER_OWNER)) {
1359         dprintf(i, "@@@ POOF! @@@\n");
1360         dprintf(i, "You are now an OWNER of %s.\n", chname);
1361       }
1362       if ((ochatr & USER_OWNER) && !(chflags & USER_OWNER)) {
1363         dprintf(i, "@@@ POOF! @@@\n");
1364         dprintf(i, "You are no longer an owner of %s.\n", chname);
1365       }
1366       if (((ochatr & (USER_OP | USER_MASTER | USER_OWNER)) &&
1367           (!(chflags & (USER_OP | USER_MASTER | USER_OWNER)))) ||
1368           ((chflags & (USER_OP | USER_MASTER | USER_OWNER)) &&
1369           (!(ochatr & (USER_OP | USER_MASTER | USER_OWNER))))) {
1370         struct flag_record fr = { FR_CHAN, 0, 0, 0, 0, 0 };
1371 
1372         for (chan = chanset; chan && !found; chan = chan->next) {
1373           get_user_flagrec(u, &fr, chan->dname);
1374           if (fr.chan & (USER_OP | USER_MASTER | USER_OWNER))
1375             found = 1;
1376         }
1377         if (!chan)
1378           chan = chanset;
1379         if (chan)
1380           strcpy(dcc[i].u.chat->con_chan, chan->dname);
1381         else
1382           strcpy(dcc[i].u.chat->con_chan, "*");
1383       }
1384     }
1385   }
1386   return chflags;
1387 }
1388 
cmd_chattr(struct userrec * u,int idx,char * par)1389 static void cmd_chattr(struct userrec *u, int idx, char *par)
1390 {
1391   char *hand, *arg = NULL, *tmpchg = NULL, *chg = NULL, work[1024];
1392   struct chanset_t *chan = NULL;
1393   struct userrec *u2;
1394   struct flag_record pls = { 0, 0, 0, 0, 0, 0 },
1395                      mns = { 0, 0, 0, 0, 0, 0 },
1396                      user = { 0, 0, 0, 0, 0, 0 };
1397   module_entry *me;
1398   int fl = -1, of = 0, ocf = 0;
1399 
1400   if (!par[0]) {
1401     dprintf(idx, "Usage: chattr <handle> [changes] [channel]\n");
1402     return;
1403   }
1404   hand = newsplit(&par);
1405   u2 = get_user_by_handle(userlist, hand);
1406   if (!u2) {
1407     dprintf(idx, "No such user!\n");
1408     return;
1409   } else if (u2 && isowner(hand) && EvangelineStrcasecmp(dcc[idx].nick, hand) && !isadmin(dcc[idx].nick)) {
1410     dprintf(idx, "You can't change attributes of permanent owner(s)\n");
1411     return;
1412   } else if (u2 && isadmin(hand) && !isadmin(dcc[idx].nick)) {
1413     dprintf(idx, "You can't change attributes of the bot admin\n");
1414     return;
1415   }
1416 
1417   if (par[0]) {
1418     arg = newsplit(&par);
1419     if (par[0]) {
1420       chg = arg;
1421       arg = newsplit(&par);
1422       chan = findchan_by_dname(arg);
1423     } else {
1424       chan = findchan_by_dname(arg);
1425       if (!(arg[0] == '+' && chan) &&
1426           !(arg[0] != '+' && strchr(CHANMETA, arg[0]))) {
1427         chg = arg;
1428         chan = NULL;
1429         arg = NULL;
1430       }
1431     }
1432   }
1433   Assert(!(!arg && chan));
1434   if (arg && !chan) {
1435     dprintf(idx, "No channel record for %s.\n", arg);
1436     return;
1437   }
1438   if (!isowner(dcc[idx].nick) && !isadmin(dcc[idx].nick) && (strstr(chg, "r") || strstr(chg, "s"))) {
1439     dprintf(idx, "You have to be admin or permowner to add/remove 'rs' flags\n");
1440     return;
1441   }
1442   if (chg) {
1443     if (!arg && strpbrk(chg, "&|")) {
1444       if (!strcmp((arg = dcc[idx].u.chat->con_chan), "*"))
1445         arg = NULL;
1446       else
1447         chan = findchan_by_dname(arg);
1448       if (arg && !chan) {
1449         dprintf(idx, "Invalid console channel %s.\n", arg);
1450         return;
1451       }
1452     } else if (arg && !strpbrk(chg, "&|")) {
1453       tmpchg = nmalloc(strlen(chg) + 2);
1454       strcpy(tmpchg, "|");
1455       strcat(tmpchg, chg);
1456       chg = tmpchg;
1457     }
1458   }
1459   par = arg;
1460   user.match = FR_GLOBAL;
1461   if (chan)
1462     user.match |= FR_CHAN;
1463   get_user_flagrec(u, &user, chan ? chan->dname : 0);
1464   if (!chan && !glob_botmast(user)) {
1465     dprintf(idx, "You do not have Bot Master privileges.\n");
1466     if (tmpchg)
1467       nfree(tmpchg);
1468     return;
1469   }
1470   if (chan && !glob_master(user) && !chan_master(user)) {
1471     dprintf(idx, "You do not have channel master privileges for channel %s.\n",
1472             par);
1473     if (tmpchg)
1474       nfree(tmpchg);
1475     return;
1476   }
1477   user.match &= fl;
1478   if (chg) {
1479     pls.match = user.match;
1480     break_down_flags(chg, &pls, &mns);
1481     pls.global &=~(USER_BOT);
1482     mns.global &=~(USER_BOT);
1483 
1484     if (chan) {
1485       pls.chan &= ~(BOT_SHARE);
1486       mns.chan &= ~(BOT_SHARE);
1487     }
1488     if (!glob_owner(user)) {
1489       pls.global &=~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1490       mns.global &=~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
1491 
1492       if (chan) {
1493         pls.chan &= ~USER_OWNER;
1494         mns.chan &= ~USER_OWNER;
1495       }
1496       if (!glob_master(user)) {
1497         pls.global &=USER_PARTY | USER_XFER;
1498         mns.global &=USER_PARTY | USER_XFER;
1499 
1500         if (!glob_botmast(user)) {
1501           pls.global = 0;
1502           mns.global = 0;
1503         }
1504       }
1505     }
1506     if (chan && !chan_owner(user) && !glob_owner(user)) {
1507       pls.chan &= ~USER_MASTER;
1508       mns.chan &= ~USER_MASTER;
1509       if (!chan_master(user) && !glob_master(user)) {
1510         pls.chan = 0;
1511         mns.chan = 0;
1512       }
1513     }
1514     get_user_flagrec(u2, &user, par);
1515     if (user.match & FR_GLOBAL) {
1516       of = user.global;
1517       user.global = sanity_check((user.global |pls.global) &~mns.global);
1518 
1519       user.udef_global = (user.udef_global | pls.udef_global)
1520                          & ~mns.udef_global;
1521     }
1522     if (chan) {
1523       ocf = user.chan;
1524       user.chan = chan_sanity_check((user.chan | pls.chan) & ~mns.chan,
1525                                     user.global);
1526 
1527       user.udef_chan = (user.udef_chan | pls.udef_chan) & ~mns.udef_chan;
1528     }
1529     set_user_flagrec(u2, &user, par);
1530   }
1531   if (chan)
1532     putlog(LOG_CMDS, "*", "#%s# (%s) chattr %s %s",
1533            dcc[idx].nick, chan ? chan->dname : "*", hand, chg ? chg : "");
1534   else
1535     putlog(LOG_CMDS, "*", "#%s# chattr %s %s", dcc[idx].nick, hand,
1536            chg ? chg : "");
1537   if (user.match & FR_GLOBAL) {
1538     user.match = FR_GLOBAL;
1539     if (chg)
1540       check_dcc_attrs(u2, of);
1541     get_user_flagrec(u2, &user, NULL);
1542     build_flags(work, &user, NULL);
1543     if (work[0] != '-')
1544       dprintf(idx, "Global flags for %s are now +%s.\n", hand, work);
1545     else
1546       dprintf(idx, "No global flags for %s.\n", hand);
1547   }
1548   if (chan) {
1549     user.match = FR_CHAN;
1550     get_user_flagrec(u2, &user, par);
1551     user.chan &= ~BOT_SHARE;
1552     if (chg)
1553       check_dcc_chanattrs(u2, chan->dname, user.chan, ocf);
1554     build_flags(work, &user, NULL);
1555     if (work[0] != '-')
1556       dprintf(idx, "Channel flags for %s on %s are now +%s.\n", hand,
1557               chan->dname, work);
1558     else
1559       dprintf(idx, "No flags for %s on %s.\n", hand, chan->dname);
1560   }
1561   if (chg && (me = module_find("irc", 0, 0))) {
1562     Function *func = me->funcs;
1563 
1564     (func[IRC_CHECK_THIS_USER]) (hand, 0, NULL);
1565   }
1566   if (tmpchg)
1567     nfree(tmpchg);
1568 }
1569 
cmd_botattr(struct userrec * u,int idx,char * par)1570 static void cmd_botattr(struct userrec *u, int idx, char *par)
1571 {
1572   char *hand, *chg = NULL, *arg = NULL, *tmpchg = NULL, work[1024];
1573   struct chanset_t *chan = NULL;
1574   struct userrec *u2;
1575   struct flag_record  pls = { 0, 0, 0, 0, 0, 0 },
1576                       mns = { 0, 0, 0, 0, 0, 0 },
1577                       user = { 0, 0, 0, 0, 0, 0 };
1578   int idx2;
1579 
1580   if (!par[0]) {
1581     dprintf(idx, "Usage: botattr <handle> [changes] [channel]\n");
1582     return;
1583   }
1584   hand = newsplit(&par);
1585   u2 = get_user_by_handle(userlist, hand);
1586   if (!u2 || !(u2->flags & USER_BOT)) {
1587     dprintf(idx, "No such bot!\n");
1588     return;
1589   }
1590   for (idx2 = 0; idx2 < dcc_total; idx2++)
1591     if (dcc[idx2].type != &DCC_RELAY && dcc[idx2].type != &DCC_FORK_BOT &&
1592         !EvangelineStrcasecmp(dcc[idx2].nick, hand))
1593       break;
1594   if (idx2 != dcc_total) {
1595     dprintf(idx,
1596             "You may not change the attributes of a directly linked bot.\n");
1597     return;
1598   }
1599   if (par[0]) {
1600     arg = newsplit(&par);
1601     if (par[0]) {
1602       chg = arg;
1603       arg = newsplit(&par);
1604       chan = findchan_by_dname(arg);
1605     } else {
1606       chan = findchan_by_dname(arg);
1607       if (!(arg[0] == '+' && chan) &&
1608           !(arg[0] != '+' && strchr(CHANMETA, arg[0]))) {
1609         chg = arg;
1610         chan = NULL;
1611         arg = NULL;
1612       }
1613     }
1614   }
1615   Assert(!(!arg && chan));
1616   if (arg && !chan) {
1617     dprintf(idx, "No channel record for %s.\n", arg);
1618     return;
1619   }
1620   if (chg) {
1621     if (!arg && strpbrk(chg, "&|")) {
1622       if (!strcmp((arg = dcc[idx].u.chat->con_chan), "*"))
1623         arg = NULL;
1624       else
1625         chan = findchan_by_dname(arg);
1626       if (arg && !chan) {
1627         dprintf(idx, "Invalid console channel %s.\n", arg);
1628         return;
1629       }
1630     } else if (arg && !strpbrk(chg, "&|")) {
1631       tmpchg = nmalloc(strlen(chg) + 2);
1632       strcpy(tmpchg, "|");
1633       strcat(tmpchg, chg);
1634       chg = tmpchg;
1635     }
1636   }
1637   par = arg;
1638 
1639   user.match = FR_GLOBAL;
1640   get_user_flagrec(u, &user, chan ? chan->dname : 0);
1641   if (!glob_botmast(user)) {
1642     dprintf(idx, "You do not have Bot Master privileges.\n");
1643     if (tmpchg)
1644       nfree(tmpchg);
1645     return;
1646   }
1647   if (chg) {
1648     user.match = FR_BOT | (chan ? FR_CHAN : 0);
1649     pls.match = user.match;
1650     break_down_flags(chg, &pls, &mns);
1651     pls.global &=~BOT_BOT;
1652     mns.global &=~BOT_BOT;
1653 
1654     if (chan && glob_owner(user)) {
1655       pls.chan &= BOT_SHARE;
1656       mns.chan &= BOT_SHARE;
1657     } else {
1658       pls.chan = 0;
1659       mns.chan = 0;
1660     }
1661     if (!glob_owner(user)) {
1662       pls.bot &= ~(BOT_SHARE | BOT_GLOBAL);
1663       mns.bot &= ~(BOT_SHARE | BOT_GLOBAL);
1664     }
1665     user.match = FR_BOT | (chan ? FR_CHAN : 0);
1666     get_user_flagrec(u2, &user, par);
1667     user.bot = (user.bot | pls.bot) & ~mns.bot;
1668     if ((user.bot & BOT_SHARE) == BOT_SHARE)
1669       user.bot &= ~BOT_SHARE;
1670     if (chan)
1671       user.chan = (user.chan | pls.chan) & ~mns.chan;
1672     set_user_flagrec(u2, &user, par);
1673   }
1674   if (chan)
1675     putlog(LOG_CMDS, "*", "#%s# (%s) botattr %s %s",
1676            dcc[idx].nick, chan->dname, hand, chg ? chg : "");
1677   else
1678     putlog(LOG_CMDS, "*", "#%s# botattr %s %s", dcc[idx].nick, hand,
1679            chg ? chg : "");
1680   if (!chan || pls.bot || mns.bot) {
1681     user.match = FR_BOT;
1682     get_user_flagrec(u2, &user, NULL);
1683     build_flags(work, &user, NULL);
1684     if (work[0] != '-')
1685       dprintf(idx, "Bot flags for %s are now +%s.\n", hand, work);
1686     else
1687       dprintf(idx, "There are no bot flags for %s.\n", hand);
1688   }
1689   if (chan) {
1690     user.match = FR_CHAN;
1691     get_user_flagrec(u2, &user, par);
1692     user.chan &= BOT_SHARE;
1693     build_flags(work, &user, NULL);
1694     if (work[0] != '-')
1695       dprintf(idx, "Bot flags for %s on %s are now +%s.\n", hand,
1696               chan->dname, work);
1697     else
1698       dprintf(idx, "There are no bot flags for %s on %s.\n", hand, chan->dname);
1699   }
1700   if (tmpchg)
1701     nfree(tmpchg);
1702 }
1703 
cmd_chat(struct userrec * u,int idx,char * par)1704 static void cmd_chat(struct userrec *u, int idx, char *par)
1705 {
1706   char *arg;
1707   int newchan, oldchan;
1708   module_entry *me;
1709 
1710   arg = newsplit(&par);
1711   if (!EvangelineStrcasecmp(arg, "off")) {
1712     if (dcc[idx].u.chat->channel < 0) {
1713       dprintf(idx, "You weren't in chat anyway!\n");
1714       return;
1715     } else {
1716       dprintf(idx, "Leaving chat mode...\n");
1717       check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
1718                      dcc[idx].u.chat->channel);
1719       chanout_but(-1, dcc[idx].u.chat->channel,
1720                   "*** %s left the party line.\n", dcc[idx].nick);
1721       if (dcc[idx].u.chat->channel < GLOBAL_CHANS)
1722         botnet_send_part_idx(idx, "");
1723     }
1724     dcc[idx].u.chat->channel = -1;
1725   } else {
1726     if (arg[0] == '*') {
1727       if (((arg[1] < '0') || (arg[1] > '9'))) {
1728         if (!arg[1])
1729           newchan = 0;
1730         else {
1731           Tcl_SetVar(interp, "chan", arg, 0);
1732           if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
1733               Tcl_GetStringResult(interp)[0])
1734             Tcl_GetIntFromObj(interp, Tcl_GetObjResult(interp), &newchan);
1735           else
1736             newchan = -1;
1737         }
1738         if (newchan < 0) {
1739           dprintf(idx, "No channel exists by that name.\n");
1740           return;
1741         }
1742       } else
1743         newchan = GLOBAL_CHANS + atoi(arg + 1);
1744       if (newchan < GLOBAL_CHANS || newchan > 199999) {
1745         dprintf(idx, "Channel number out of range: local channels must be "
1746                 "*0-*99999.\n");
1747         return;
1748       }
1749     } else {
1750       if (((arg[0] < '0') || (arg[0] > '9')) && (arg[0])) {
1751         if (!EvangelineStrcasecmp(arg, "on"))
1752           newchan = 0;
1753         else {
1754           Tcl_SetVar(interp, "chan", arg, 0);
1755           if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
1756               Tcl_GetStringResult(interp)[0])
1757             Tcl_GetIntFromObj(interp, Tcl_GetObjResult(interp), &newchan);
1758           else
1759             newchan = -1;
1760         }
1761         if (newchan < 0) {
1762           dprintf(idx, "No channel exists by that name.\n");
1763           return;
1764         }
1765       } else
1766         newchan = atoi(arg);
1767       if ((newchan < 0) || (newchan >= GLOBAL_CHANS)) {
1768         dprintf(idx, "Channel number out of range: must be between 0 and %d."
1769                 "\n", GLOBAL_CHANS);
1770         return;
1771       }
1772     }
1773     if ((dcc[idx].u.chat->channel < 0) && (dcc[idx].u.chat->away != NULL))
1774       not_away(idx);
1775     if (dcc[idx].u.chat->channel == newchan) {
1776       if (!newchan) {
1777         dprintf(idx, "You're already on the party line!\n");
1778         return;
1779       } else {
1780         dprintf(idx, "You're already on channel %s%d!\n",
1781                 (newchan < GLOBAL_CHANS) ? "" : "*", newchan % GLOBAL_CHANS);
1782         return;
1783       }
1784     } else {
1785       oldchan = dcc[idx].u.chat->channel;
1786       if (oldchan >= 0)
1787         check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock, oldchan);
1788       if (!oldchan)
1789         chanout_but(-1, 0, "*** %s left the party line.\n", dcc[idx].nick);
1790       else if (oldchan > 0)
1791         chanout_but(-1, oldchan, "*** %s left the channel.\n", dcc[idx].nick);
1792       dcc[idx].u.chat->channel = newchan;
1793       if (!newchan) {
1794         dprintf(idx, "Entering the party line...\n");
1795         chanout_but(-1, 0, "*** %s joined the party line.\n", dcc[idx].nick);
1796       } else {
1797         dprintf(idx, "Joining channel '%s'...\n", arg);
1798         chanout_but(-1, newchan, "*** %s joined the channel.\n", dcc[idx].nick);
1799       }
1800       check_tcl_chjn(botnetnick, dcc[idx].nick, newchan, geticon(idx),
1801                      dcc[idx].sock, dcc[idx].host);
1802       if (newchan < GLOBAL_CHANS)
1803         botnet_send_join_idx(idx, oldchan);
1804       else if (oldchan < GLOBAL_CHANS)
1805         botnet_send_part_idx(idx, "");
1806     }
1807   }
1808   if ((me = module_find("console", 1, 1))) {
1809     Function *func = me->funcs;
1810 
1811     (func[CONSOLE_DOSTORE]) (idx);
1812   }
1813 }
1814 
cmd_echo(struct userrec * u,int idx,char * par)1815 static void cmd_echo(struct userrec *u, int idx, char *par)
1816 {
1817   module_entry *me;
1818 
1819   if (!par[0]) {
1820     dprintf(idx, "Echo is currently %s.\n", dcc[idx].status & STAT_ECHO ?
1821             "on" : "off");
1822     return;
1823   }
1824   if (!EvangelineStrcasecmp(par, "on")) {
1825     dprintf(idx, "Echo turned on.\n");
1826     dcc[idx].status |= STAT_ECHO;
1827   } else if (!EvangelineStrcasecmp(par, "off")) {
1828     dprintf(idx, "Echo turned off.\n");
1829     dcc[idx].status &= ~STAT_ECHO;
1830   } else {
1831     dprintf(idx, "Usage: echo <on/off>\n");
1832     return;
1833   }
1834   if ((me = module_find("console", 1, 1))) {
1835     Function *func = me->funcs;
1836 
1837     (func[CONSOLE_DOSTORE]) (idx);
1838   }
1839 }
1840 
stripmodes(char * s)1841 int stripmodes(char *s)
1842 {
1843   int res = 0;
1844 
1845   for (; *s; s++)
1846     switch (tolower(*s)) {
1847     case 'b':
1848       res |= STRIP_BOLD;
1849       break;
1850     case 'c':
1851       res |= STRIP_COLOR;
1852       break;
1853     case 'r':
1854       res |= STRIP_REV;
1855       break;
1856     case 'u':
1857       res |= STRIP_UNDER;
1858       break;
1859     case 'a':
1860       res |= STRIP_ANSI;
1861       break;
1862     case 'g':
1863       res |= STRIP_BELLS;
1864       break;
1865     case '*':
1866       res |= STRIP_ALL;
1867       break;
1868     }
1869   return res;
1870 }
1871 
stripmasktype(int x)1872 char *stripmasktype(int x)
1873 {
1874   static char s[20];
1875   char *p = s;
1876 
1877   if (x & STRIP_BOLD)
1878     *p++ = 'b';
1879   if (x & STRIP_COLOR)
1880     *p++ = 'c';
1881   if (x & STRIP_REV)
1882     *p++ = 'r';
1883   if (x & STRIP_UNDER)
1884     *p++ = 'u';
1885   if (x & STRIP_ANSI)
1886     *p++ = 'a';
1887   if (x & STRIP_BELLS)
1888     *p++ = 'g';
1889   if (p == s)
1890     *p++ = '-';
1891   *p = 0;
1892   return s;
1893 }
1894 
stripmaskname(int x)1895 static char *stripmaskname(int x)
1896 {
1897   static char s[161];
1898   int i = 0;
1899 
1900   s[i] = 0;
1901   if (x & STRIP_BOLD)
1902     i += my_strcpy(s + i, "bold, ");
1903   if (x & STRIP_COLOR)
1904     i += my_strcpy(s + i, "color, ");
1905   if (x & STRIP_REV)
1906     i += my_strcpy(s + i, "reverse, ");
1907   if (x & STRIP_UNDER)
1908     i += my_strcpy(s + i, "underline, ");
1909   if (x & STRIP_ANSI)
1910     i += my_strcpy(s + i, "ansi, ");
1911   if (x & STRIP_BELLS)
1912     i += my_strcpy(s + i, "bells, ");
1913   if (!i)
1914     strcpy(s, "none");
1915   else
1916     s[i - 2] = 0;
1917   return s;
1918 }
1919 
cmd_strip(struct userrec * u,int idx,char * par)1920 static void cmd_strip(struct userrec *u, int idx, char *par)
1921 {
1922   char *nick, *changes, *c, s[2];
1923   int dest = 0, i, pls, md, ok = 0;
1924   module_entry *me;
1925 
1926   if (!par[0]) {
1927     dprintf(idx, "Your current strip settings are: %s (%s).\n",
1928             stripmasktype(dcc[idx].u.chat->strip_flags),
1929             stripmaskname(dcc[idx].u.chat->strip_flags));
1930     return;
1931   }
1932   nick = newsplit(&par);
1933   if ((nick[0] != '+') && (nick[0] != '-') && u && (u->flags & USER_MASTER)) {
1934     for (i = 0; i < dcc_total; i++)
1935       if (!EvangelineStrcasecmp(nick, dcc[i].nick) && dcc[i].type == &DCC_CHAT && !ok) {
1936         ok = 1;
1937         dest = i;
1938       }
1939     if (!ok) {
1940       dprintf(idx, "No such user on the party line!\n");
1941       return;
1942     }
1943     changes = par;
1944   } else {
1945     changes = nick;
1946     nick = "";
1947     dest = idx;
1948   }
1949   c = changes;
1950   if ((c[0] != '+') && (c[0] != '-'))
1951     dcc[dest].u.chat->strip_flags = 0;
1952   s[1] = 0;
1953   for (pls = 1; *c; c++) {
1954     switch (*c) {
1955     case '+':
1956       pls = 1;
1957       break;
1958     case '-':
1959       pls = 0;
1960       break;
1961     default:
1962       s[0] = *c;
1963       md = stripmodes(s);
1964       if (pls == 1)
1965         dcc[dest].u.chat->strip_flags |= md;
1966       else
1967         dcc[dest].u.chat->strip_flags &= ~md;
1968     }
1969   }
1970   if (nick[0])
1971     putlog(LOG_CMDS, "*", "#%s# strip %s %s", dcc[idx].nick, nick, changes);
1972   else
1973     putlog(LOG_CMDS, "*", "#%s# strip %s", dcc[idx].nick, changes);
1974   if (dest == idx) {
1975     dprintf(idx, "Your strip settings are: %s (%s).\n",
1976             stripmasktype(dcc[idx].u.chat->strip_flags),
1977             stripmaskname(dcc[idx].u.chat->strip_flags));
1978   } else {
1979     dprintf(idx, "Strip setting for %s: %s (%s).\n", dcc[dest].nick,
1980             stripmasktype(dcc[dest].u.chat->strip_flags),
1981             stripmaskname(dcc[dest].u.chat->strip_flags));
1982     dprintf(dest, "%s set your strip settings to: %s (%s).\n", dcc[idx].nick,
1983             stripmasktype(dcc[dest].u.chat->strip_flags),
1984             stripmaskname(dcc[dest].u.chat->strip_flags));
1985   }
1986   if (dcc[dest].u.chat->strip_flags & STRIP_BOLD && u->flags & USER_HIGHLITE) {
1987     u->flags &= ~USER_HIGHLITE;
1988   } else if (!(dcc[dest].u.chat->strip_flags & STRIP_BOLD) &&
1989            !(u->flags & USER_HIGHLITE)) {
1990     u->flags |= USER_HIGHLITE;
1991   }
1992   if ((me = module_find("console", 1, 1))) {
1993     Function *func = me->funcs;
1994 
1995     (func[CONSOLE_DOSTORE]) (dest);
1996   }
1997 }
1998 
cmd_su(struct userrec * u,int idx,char * par)1999 static void cmd_su(struct userrec *u, int idx, char *par)
2000 {
2001   int atr = u ? u->flags : 0;
2002   struct flag_record fr = { FR_ANYWH | FR_CHAN | FR_GLOBAL, 0, 0, 0, 0, 0 };
2003 
2004   u = get_user_by_handle(userlist, par);
2005 
2006   if (!par[0])
2007     dprintf(idx, "Usage: su <user>\n");
2008   else if (!u)
2009     dprintf(idx, "No such user.\n");
2010   else if (u->flags & USER_BOT)
2011     dprintf(idx, "You can't su to a bot... then again, why would you wanna?\n");
2012   else if (dcc[idx].u.chat->su_nick)
2013     dprintf(idx, "You cannot currently double .su; try .su'ing directly.\n");
2014   else {
2015     get_user_flagrec(u, &fr, NULL);
2016     if ((!glob_party(fr) && (require_p || !(glob_op(fr) || chan_op(fr)))) &&
2017         !(atr & USER_BOTMAST))
2018       dprintf(idx, "No party line access permitted for %s.\n", par);
2019     else {
2020       correct_handle(par);
2021       putlog(LOG_CMDS, "*", "#%s# su %s", dcc[idx].nick, par);
2022       if (isadmin(par)) {
2023         dprintf(idx, "You can't su on admin account.\n");
2024         return;
2025       }
2026       if (isowner(par) && !isadmin(dcc[idx].nick))
2027         return;
2028       if (!(atr & USER_OWNER) || ((u->flags & USER_OWNER) && (isowner(par)) &&
2029           !(isadmin(dcc[idx].nick)))) {
2030         if (u_pass_match(u, "-")) {
2031           dprintf(idx, "No password set for user. You may not .su to them.\n");
2032           return;
2033         }
2034         if (dcc[idx].u.chat->channel < GLOBAL_CHANS)
2035           botnet_send_part_idx(idx, "");
2036         chanout_but(-1, dcc[idx].u.chat->channel,
2037                     "*** %s left the party line.\n", dcc[idx].nick);
2038         if (dcc[idx].u.chat->away != NULL)
2039           nfree(dcc[idx].u.chat->away);
2040         dcc[idx].u.chat->away = get_data_ptr(strlen(dcc[idx].nick) + 1);
2041         strcpy(dcc[idx].u.chat->away, dcc[idx].nick);
2042         dcc[idx].u.chat->su_nick = get_data_ptr(strlen(dcc[idx].nick) + 1);
2043         strcpy(dcc[idx].u.chat->su_nick, dcc[idx].nick);
2044         dcc[idx].user = u;
2045         strcpy(dcc[idx].nick, par);
2046         dprintf(idx, "Enter password for %s%s\n", par,
2047                 (dcc[idx].status & STAT_TELNET) ? TLN_IAC_C TLN_WILL_C
2048                 TLN_ECHO_C : "");
2049         dcc[idx].type = &DCC_CHAT_PASS;
2050       } else if (atr & USER_OWNER) {
2051         if (dcc[idx].u.chat->channel < GLOBAL_CHANS)
2052           botnet_send_part_idx(idx, "");
2053         chanout_but(-1, dcc[idx].u.chat->channel,
2054                     "*** %s left the party line.\n", dcc[idx].nick);
2055         dprintf(idx, "Setting your username to %s.\n", par);
2056         if (atr & USER_MASTER)
2057           dcc[idx].u.chat->con_flags = conmask;
2058         dcc[idx].u.chat->su_nick = get_data_ptr(strlen(dcc[idx].nick) + 1);
2059         strcpy(dcc[idx].u.chat->su_nick, dcc[idx].nick);
2060         dcc[idx].user = u;
2061         strcpy(dcc[idx].nick, par);
2062         dcc_chatter(idx);
2063       }
2064     }
2065   }
2066 }
2067 
cmd_fixcodes(struct userrec * u,int idx,char * par)2068 static void cmd_fixcodes(struct userrec *u, int idx, char *par)
2069 {
2070   if (dcc[idx].status & STAT_TELNET) {
2071     dcc[idx].status |= STAT_ECHO;
2072     dcc[idx].status &= ~STAT_TELNET;
2073     dprintf(idx, "Turned off telnet codes.\n");
2074     putlog(LOG_CMDS, "*", "#%s# fixcodes (telnet off)", dcc[idx].nick);
2075   } else {
2076     dcc[idx].status |= STAT_TELNET;
2077     dcc[idx].status &= ~STAT_ECHO;
2078     dprintf(idx, "Turned on telnet codes.\n");
2079     putlog(LOG_CMDS, "*", "#%s# fixcodes (telnet on)", dcc[idx].nick);
2080   }
2081 }
2082 
cmd_page(struct userrec * u,int idx,char * par)2083 static void cmd_page(struct userrec *u, int idx, char *par)
2084 {
2085   int a;
2086   module_entry *me;
2087 
2088   if (!par[0]) {
2089     if (dcc[idx].status & STAT_PAGE) {
2090       dprintf(idx, "Currently paging outputs to %d lines.\n",
2091               dcc[idx].u.chat->max_line);
2092     } else
2093       dprintf(idx, "You don't have paging on.\n");
2094     return;
2095   }
2096   a = atoi(par);
2097   if ((!a && !par[0]) || !EvangelineStrcasecmp(par, "off")) {
2098     dcc[idx].status &= ~STAT_PAGE;
2099     dcc[idx].u.chat->max_line = 0x7ffffff;
2100     while (dcc[idx].u.chat->buffer)
2101       flush_lines(idx, dcc[idx].u.chat);
2102     dprintf(idx, "Paging turned off.\n");
2103     putlog(LOG_CMDS, "*", "#%s# page off", dcc[idx].nick);
2104   } else if (a > 0) {
2105     dprintf(idx, "Paging turned on, stopping every %d line%s.\n", a,
2106             (a != 1) ? "s" : "");
2107     dcc[idx].status |= STAT_PAGE;
2108     dcc[idx].u.chat->max_line = a;
2109     dcc[idx].u.chat->line_count = 0;
2110     dcc[idx].u.chat->current_lines = 0;
2111     putlog(LOG_CMDS, "*", "#%s# page %d", dcc[idx].nick, a);
2112   } else {
2113     dprintf(idx, "Usage: page <off or #>\n");
2114     return;
2115   }
2116   if ((me = module_find("console", 1, 1))) {
2117     Function *func = me->funcs;
2118 
2119     (func[CONSOLE_DOSTORE]) (idx);
2120   }
2121 }
2122 
2123 /* Evaluate a Tcl command, send output to a dcc user. */
cmd_tcl(struct userrec * u,int idx,char * msg)2124 static void cmd_tcl(struct userrec *u, int idx, char *msg)
2125 {
2126   int code;
2127 
2128   if (!isowner(dcc[idx].nick) && !isadmin(dcc[idx].nick)) {
2129     dprintf(idx, MISC_NOSUCHCMD);
2130     return;
2131   }
2132   debug1("(cmds.c->cmd_tcl) tcl: evaluate (.tcl): %s", msg);
2133   code = Tcl_GlobalEval(interp, msg);
2134   if (code == TCL_OK)
2135     dumplots(idx, "Tcl: ", (char *)Tcl_GetStringResult(interp));
2136   else
2137     dumplots(idx, "Tcl error: ", (char *)Tcl_GetStringResult(interp));
2138 }
2139 
2140 /* Perform a 'set' command */
cmd_set(struct userrec * u,int idx,char * msg)2141 static void cmd_set(struct userrec *u, int idx, char *msg)
2142 {
2143   int code;
2144   char s[512];
2145 
2146   if (!isowner(dcc[idx].nick) && !isadmin(dcc[idx].nick)) {
2147     dprintf(idx, MISC_NOSUCHCMD);
2148     return;
2149   }
2150   putlog(LOG_CMDS, "*", "#%s# set %s", dcc[idx].nick, msg);
2151   strcpy(s, "set ");
2152   if (!msg[0]) {
2153     strcpy(s, "info globals");
2154     Tcl_Eval(interp, s);
2155     dumplots(idx, "Global vars: ", (char *)Tcl_GetStringResult(interp));
2156     return;
2157   }
2158   strcpy(s + 4, msg);
2159   code = Tcl_Eval(interp, s);
2160   if (code == TCL_OK) {
2161     if (!strchr(msg, ' '))
2162       dumplots(idx, "Currently: ", (char *)Tcl_GetStringResult(interp));
2163     else
2164       dprintf(idx, "Ok, set.\n");
2165   } else
2166     dprintf(idx, "Error: %s\n", (char *)Tcl_GetStringResult(interp));
2167 }
2168 
cmd_module(struct userrec * u,int idx,char * par)2169 static void cmd_module(struct userrec *u, int idx, char *par)
2170 {
2171   putlog(LOG_CMDS, "*", "#%s# module %s", dcc[idx].nick, par);
2172   do_module_report(idx, 2, par[0] ? par : NULL);
2173 }
2174 
cmd_loadmod(struct userrec * u,int idx,char * par)2175 static void cmd_loadmod(struct userrec *u, int idx, char *par)
2176 {
2177   const char *p;
2178 
2179   if (!isowner(dcc[idx].nick) && !isadmin(dcc[idx].nick)) {
2180     dprintf(idx, MISC_NOSUCHCMD);
2181     return;
2182   }
2183   if (!par[0]) {
2184     dprintf(idx, "%s: loadmod <module>\n", MISC_USAGE);
2185   } else {
2186     p = module_load(par);
2187     if (p)
2188       dprintf(idx, "%s: %s %s\n", par, MOD_LOADERROR, p);
2189     else {
2190       putlog(LOG_CMDS, "*", "#%s# loadmod %s", dcc[idx].nick, par);
2191       dprintf(idx, MOD_LOADED, par);
2192       dprintf(idx, "\n");
2193     }
2194   }
2195 }
2196 
cmd_unloadmod(struct userrec * u,int idx,char * par)2197 static void cmd_unloadmod(struct userrec *u, int idx, char *par)
2198 {
2199   char *p;
2200 
2201   if (!isowner(dcc[idx].nick) && !isadmin(dcc[idx].nick)) {
2202     dprintf(idx, MISC_NOSUCHCMD);
2203     return;
2204   }
2205   if (!par[0])
2206     dprintf(idx, "%s: unloadmod <module>\n", MISC_USAGE);
2207   else {
2208     p = module_unload(par, dcc[idx].nick);
2209     if (p)
2210       dprintf(idx, "%s %s: %s\n", MOD_UNLOADERROR, par, p);
2211     else {
2212       putlog(LOG_CMDS, "*", "#%s# unloadmod %s", dcc[idx].nick, par);
2213       dprintf(idx, "%s %s\n", MOD_UNLOADED, par);
2214     }
2215   }
2216 }
2217 
cmd_pls_ignore(struct userrec * u,int idx,char * par)2218 static void cmd_pls_ignore(struct userrec *u, int idx, char *par)
2219 {
2220   char *who, s[UHOSTLEN];
2221   unsigned long int expire_time = 0;
2222 
2223   if (!par[0]) {
2224     dprintf(idx, "Usage: +ignore <hostmask> [%%<XdXhXm>] [comment]\n");
2225     return;
2226   }
2227 
2228   who = newsplit(&par);
2229   if (par[0] == '%') {
2230     char *p, *p_expire;
2231     unsigned long int expire_foo;
2232 
2233     p = newsplit(&par);
2234     p_expire = p + 1;
2235     while (*(++p) != 0) {
2236       switch (tolower(*p)) {
2237       case 'd':
2238         *p = 0;
2239         expire_foo = strtol(p_expire, NULL, 10);
2240         if (expire_foo > 365)
2241           expire_foo = 365;
2242         expire_time += 86400 * expire_foo;
2243         p_expire = p + 1;
2244         break;
2245       case 'h':
2246         *p = 0;
2247         expire_foo = strtol(p_expire, NULL, 10);
2248         if (expire_foo > 8760)
2249           expire_foo = 8760;
2250         expire_time += 3600 * expire_foo;
2251         p_expire = p + 1;
2252         break;
2253       case 'm':
2254         *p = 0;
2255         expire_foo = strtol(p_expire, NULL, 10);
2256         if (expire_foo > 525600)
2257           expire_foo = 525600;
2258         expire_time += 60 * expire_foo;
2259         p_expire = p + 1;
2260       }
2261     }
2262   }
2263   if (!par[0])
2264     par = "requested";
2265   else if (strlen(par) > 65)
2266     par[65] = 0;
2267   if (strlen(who) > UHOSTMAX - 4)
2268     who[UHOSTMAX - 4] = 0;
2269 
2270   if (!strchr(who, '!')) {
2271     if (!strchr(who, '@'))
2272       simple_sprintf(s, "%s!*@*", who);
2273     else
2274       simple_sprintf(s, "*!%s", who);
2275   } else if (!strchr(who, '@'))
2276     simple_sprintf(s, "%s@*", who);
2277   else
2278     strcpy(s, who);
2279 
2280   if (match_ignore(s))
2281     dprintf(idx, "That already matches an existing ignore.\n");
2282   else {
2283     dprintf(idx, "Now ignoring: %s (%s)\n", s, par);
2284     addignore(s, dcc[idx].nick, par, expire_time ? now + expire_time : 0L);
2285     putlog(LOG_CMDS, "*", "#%s# +ignore %s %s", dcc[idx].nick, s, par);
2286   }
2287 }
2288 
cmd_mns_ignore(struct userrec * u,int idx,char * par)2289 static void cmd_mns_ignore(struct userrec *u, int idx, char *par)
2290 {
2291   char buf[UHOSTLEN];
2292 
2293   if (!par[0]) {
2294     dprintf(idx, "Usage: -ignore <hostmask | ignore #>\n");
2295     return;
2296   }
2297   strncpyz(buf, par, sizeof buf);
2298   if (delignore(buf)) {
2299     putlog(LOG_CMDS, "*", "#%s# -ignore %s", dcc[idx].nick, buf);
2300     dprintf(idx, "No longer ignoring: %s\n", buf);
2301   } else
2302     dprintf(idx, "That ignore cannot be found.\n");
2303 }
2304 
cmd_ignores(struct userrec * u,int idx,char * par)2305 static void cmd_ignores(struct userrec *u, int idx, char *par)
2306 {
2307   putlog(LOG_CMDS, "*", "#%s# ignores %s", dcc[idx].nick, par);
2308   tell_ignores(idx, par);
2309 }
2310 
cmd_pls_user(struct userrec * u,int idx,char * par)2311 static void cmd_pls_user(struct userrec *u, int idx, char *par)
2312 {
2313   char *handle, *host, comment[128], s[24]="";
2314 
2315   if (!par[0]) {
2316     dprintf(idx, "Usage: +user <handle> [hostmask]\n");
2317     return;
2318   }
2319   handle = newsplit(&par);
2320   host = newsplit(&par);
2321   if (strlen(handle) > HANDLEN)
2322     handle[HANDLEN] = 0;
2323   if (!isadmin(dcc[idx].nick) && !isowner(dcc[idx].nick) && !isadder(dcc[idx].nick)) {
2324     return;
2325   }
2326   if (get_user_by_handle(userlist, handle))
2327     dprintf(idx, "Someone already exists by that name.\n");
2328   else if (strchr(BADNICKCHARS, handle[0]) != NULL)
2329     dprintf(idx, "You can't start a nick with '%c'.\n", handle[0]);
2330   else if (!EvangelineStrcasecmp(handle, botnetnick))
2331     dprintf(idx, "Hey! That's MY name!\n");
2332   else {
2333     putlog(LOG_CMDS, "*", "#%s# +user %s %s", dcc[idx].nick, handle, host);
2334     userlist = adduser(userlist, handle, host, "-", 0);
2335     strftime(s, 23, "%d.%m.%Y %H:%M:%S", localtime(&now));
2336     sprintf(comment, "Added by: %s (%s)", dcc[idx].nick, s);
2337     set_user(&USERENTRY_COMMENT, get_user_by_handle(userlist, handle), comment);
2338     dprintf(idx, "Added %s (%s) with no password and no flags.\n", handle,
2339             host[0] ? host : "no host");
2340   }
2341 }
2342 
cmd_mns_user(struct userrec * u,int idx,char * par)2343 static void cmd_mns_user(struct userrec *u, int idx, char *par)
2344 {
2345   int idx2;
2346   char *handle;
2347   struct userrec *u2;
2348   module_entry *me;
2349 
2350   if (!par[0]) {
2351     dprintf(idx, "Usage: -user <hand>\n");
2352     return;
2353   }
2354   if (!isadmin(dcc[idx].nick) && !isowner(dcc[idx].nick) && !isadder(dcc[idx].nick)) {
2355     return;
2356   }
2357   handle = newsplit(&par);
2358   u2 = get_user_by_handle(userlist, handle);
2359   if (!u2 || !u) {
2360     dprintf(idx, "No such user!\n");
2361     return;
2362   }
2363   if (isowner(u2->handle) && !isadmin(dcc[idx].nick)) {
2364     dprintf(idx, "You can't remove a permanent bot owner!\n");
2365     return;
2366   }
2367   if (isadmin(u2->handle)) {
2368     dprintf(idx, "Can't remove the bot admin!\n");
2369     return;
2370   }
2371   if ((u2->flags & USER_OWNER) && !(u->flags & USER_OWNER)) {
2372     dprintf(idx, "You can't remove a bot owner!\n");
2373     return;
2374   }
2375   if (u2->flags & USER_BOT) {
2376     if ((bot_flags(u2) & BOT_SHARE) && !(u->flags & USER_OWNER)) {
2377       dprintf(idx, "You can't remove share bots.\n");
2378       return;
2379     }
2380     for (idx2 = 0; idx2 < dcc_total; idx2++)
2381       if (dcc[idx2].type != &DCC_RELAY && dcc[idx2].type != &DCC_FORK_BOT &&
2382           !EvangelineStrcasecmp(dcc[idx2].nick, handle))
2383         break;
2384     if (idx2 != dcc_total) {
2385       dprintf(idx, "You can't remove a directly linked bot.\n");
2386       return;
2387     }
2388   }
2389   if ((u->flags & USER_BOTMAST) && !(u->flags & USER_MASTER) &&
2390       !(u2->flags & USER_BOT)) {
2391     dprintf(idx, "You can't remove users who aren't bots!\n");
2392     return;
2393   }
2394   if ((me = module_find("irc", 0, 0))) {
2395     Function *func = me->funcs;
2396 
2397     (func[IRC_CHECK_THIS_USER]) (handle, 1, NULL);
2398   }
2399   if (deluser(handle)) {
2400     putlog(LOG_CMDS, "*", "#%s# -user %s", dcc[idx].nick, handle);
2401     dprintf(idx, "Deleted %s.\n", handle);
2402   } else
2403     dprintf(idx, "Failed.\n");
2404 }
2405 
cmd_pls_host(struct userrec * u,int idx,char * par)2406 static void cmd_pls_host(struct userrec *u, int idx, char *par)
2407 {
2408   char *handle, *host;
2409   struct userrec *u2;
2410   struct list_type *q;
2411   struct flag_record fr2 = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0 },
2412                       fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0 };
2413   module_entry *me;
2414 
2415   if (!par[0]) {
2416     dprintf(idx, "Usage: +host [handle] <newhostmask>\n");
2417     return;
2418   }
2419 
2420   handle = newsplit(&par);
2421   if (isowner(handle) && EvangelineStrcasecmp(dcc[idx].nick, handle) && !isadmin(dcc[idx].nick)) {
2422     dprintf(idx, "You can't add hostmasks to permowners\n");
2423     return;
2424   }
2425   if (isadmin(handle) && !isadmin(dcc[idx].nick)) {
2426     dprintf(idx, "You can't add hostmasks to the bot admin\n");
2427     return;
2428   }
2429 
2430   if (par[0]) {
2431     host = newsplit(&par);
2432     u2 = get_user_by_handle(userlist, handle);
2433   } else {
2434     host = handle;
2435     handle = dcc[idx].nick;
2436     u2 = u;
2437   }
2438   if (!u2 || !u) {
2439     dprintf(idx, "No such user.\n");
2440     return;
2441   }
2442   get_user_flagrec(u, &fr, NULL);
2443   if (EvangelineStrcasecmp(handle, dcc[idx].nick)) {
2444     get_user_flagrec(u2, &fr2, NULL);
2445     if (!glob_master(fr) && !glob_bot(fr2) && !chan_master(fr)) {
2446       dprintf(idx, "You can't add hostmasks to non-bots.\n");
2447       return;
2448     }
2449     if (!glob_owner(fr) && glob_bot(fr2) && (bot_flags(u2) & BOT_SHARE)) {
2450       dprintf(idx, "You can't add hostmasks to share bots.\n");
2451       return;
2452     }
2453     if ((glob_owner(fr2) || glob_master(fr2)) && !glob_owner(fr)) {
2454       dprintf(idx, "You can't add hostmasks to a bot owner/master.\n");
2455       return;
2456     }
2457     if ((chan_owner(fr2) || chan_master(fr2)) && !glob_master(fr) &&
2458         !glob_owner(fr) && !chan_owner(fr)) {
2459       dprintf(idx, "You can't add hostmasks to a channel owner/master.\n");
2460       return;
2461     }
2462     if (!glob_botmast(fr) && !glob_master(fr) && !chan_master(fr)) {
2463       dprintf(idx, "Permission denied.\n");
2464       return;
2465     }
2466   }
2467   if (!glob_botmast(fr) && !chan_master(fr) && get_user_by_host(host)) {
2468     dprintf(idx, "You cannot add a host matching another user!\n");
2469     return;
2470   }
2471   for (q = get_user(&USERENTRY_HOSTS, u); q; q = q->next)
2472     if (!EvangelineStrcasecmp(q->extra, host)) {
2473       dprintf(idx, "That hostmask is already there.\n");
2474       return;
2475     }
2476   putlog(LOG_CMDS, "*", "#%s# +host %s %s", dcc[idx].nick, handle, host);
2477   addhost_by_handle(handle, host);
2478   dprintf(idx, "Added '%s' to %s.\n", host, handle);
2479   if ((me = module_find("irc", 0, 0))) {
2480     Function *func = me->funcs;
2481 
2482     (func[IRC_CHECK_THIS_USER]) (handle, 0, NULL);
2483   }
2484 }
2485 
cmd_mns_host(struct userrec * u,int idx,char * par)2486 static void cmd_mns_host(struct userrec *u, int idx, char *par)
2487 {
2488   char *handle, *host;
2489   struct userrec *u2;
2490   struct flag_record fr2 = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0 },
2491                       fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0 };
2492   module_entry *me;
2493 
2494   if (!par[0]) {
2495     dprintf(idx, "Usage: -host [handle] <hostmask>\n");
2496     return;
2497   }
2498   handle = newsplit(&par);
2499   if (isowner(handle) && EvangelineStrcasecmp(dcc[idx].nick, handle) && !isadmin(dcc[idx].nick)) {
2500     dprintf(idx, "You can't remove hostmasks from permowners\n");
2501     return;
2502   }
2503   if (isadmin(handle) && !isadmin(dcc[idx].nick)) {
2504     dprintf(idx, "You can't remove hostmasks from the bot admin\n");
2505     return;
2506   }
2507   if (par[0]) {
2508     host = newsplit(&par);
2509     u2 = get_user_by_handle(userlist, handle);
2510   } else {
2511     host = handle;
2512     handle = dcc[idx].nick;
2513     u2 = u;
2514   }
2515   if (!u2 || !u) {
2516     dprintf(idx, "No such user.\n");
2517     return;
2518   }
2519 
2520   get_user_flagrec(u, &fr, NULL);
2521   get_user_flagrec(u2, &fr2, NULL);
2522   if (glob_deop(fr) || glob_kick(fr) || chan_deop(fr) || chan_kick(fr)) {
2523     dprintf(idx, "You can't remove hostmasks while having the +d or +k "
2524             "flag.\n");
2525     return;
2526   }
2527 
2528   if (EvangelineStrcasecmp(handle, dcc[idx].nick)) {
2529     if (!glob_master(fr) && !glob_bot(fr2) && !chan_master(fr)) {
2530       dprintf(idx, "You can't remove hostmasks from non-bots.\n");
2531       return;
2532     }
2533     if (glob_bot(fr2) && (bot_flags(u2) & BOT_SHARE) && !glob_owner(fr)) {
2534       dprintf(idx, "You can't remove hostmasks from a share bot.\n");
2535       return;
2536     }
2537     if ((glob_owner(fr2) || glob_master(fr2)) && !glob_owner(fr)) {
2538       dprintf(idx, "You can't remove hostmasks from a bot owner/master.\n");
2539       return;
2540     }
2541     if ((chan_owner(fr2) || chan_master(fr2)) && !glob_master(fr) &&
2542         !glob_owner(fr) && !chan_owner(fr)) {
2543       dprintf(idx, "You can't remove hostmasks from a channel owner/master.\n");
2544       return;
2545     }
2546     if (!glob_botmast(fr) && !glob_master(fr) && !chan_master(fr)) {
2547       dprintf(idx, "Permission denied.\n");
2548       return;
2549     }
2550   }
2551   if (delhost_by_handle(handle, host)) {
2552     putlog(LOG_CMDS, "*", "#%s# -host %s %s", dcc[idx].nick, handle, host);
2553     dprintf(idx, "Removed '%s' from %s.\n", host, handle);
2554     if ((me = module_find("irc", 0, 0))) {
2555       Function *func = me->funcs;
2556 
2557       (func[IRC_CHECK_THIS_USER]) (handle, 2, host);
2558     }
2559   } else
2560     dprintf(idx, "Failed.\n");
2561 }
2562 
cmd_modules(struct userrec * u,int idx,char * par)2563 static void cmd_modules(struct userrec *u, int idx, char *par)
2564 {
2565   int ptr;
2566   char *bot;
2567   module_entry *me;
2568 
2569   putlog(LOG_CMDS, "*", "#%s# modules %s", dcc[idx].nick, par);
2570 
2571   if (!par[0]) {
2572     dprintf(idx, "Modules loaded:\n");
2573     for (me = module_list; me; me = me->next)
2574       dprintf(idx, "  Module: %s (v%d.%d)\n", me->name, me->major, me->minor);
2575     dprintf(idx, "End of modules list.\n");
2576   } else {
2577     bot = newsplit(&par);
2578     if ((ptr = nextbot(bot)) >= 0)
2579       dprintf(ptr, "v %s %s %d:%s\n", botnetnick, bot, dcc[idx].sock,
2580               dcc[idx].nick);
2581     else
2582       dprintf(idx, "No such bot online.\n");
2583   }
2584 }
2585 
cmd_traffic(struct userrec * u,int idx,char * par)2586 static void cmd_traffic(struct userrec *u, int idx, char *par)
2587 {
2588   unsigned long itmp, itmp2;
2589 
2590   dprintf(idx, "Traffic since last restart\n");
2591   dprintf(idx, "==========================\n");
2592   if (otraffic_irc > 0 || itraffic_irc > 0 || otraffic_irc_today > 0 ||
2593       itraffic_irc_today > 0) {
2594     dprintf(idx, "IRC:\n");
2595     dprintf(idx, "  out: %s", btos(otraffic_irc + otraffic_irc_today));
2596     dprintf(idx, " (%s today)\n", btos(otraffic_irc_today));
2597     dprintf(idx, "   in: %s", btos(itraffic_irc + itraffic_irc_today));
2598     dprintf(idx, " (%s today)\n", btos(itraffic_irc_today));
2599   }
2600   if (otraffic_bn > 0 || itraffic_bn > 0 || otraffic_bn_today > 0 ||
2601       itraffic_bn_today > 0) {
2602     dprintf(idx, "Botnet:\n");
2603     dprintf(idx, "  out: %s", btos(otraffic_bn + otraffic_bn_today));
2604     dprintf(idx, " (%s today)\n", btos(otraffic_bn_today));
2605     dprintf(idx, "   in: %s", btos(itraffic_bn + itraffic_bn_today));
2606     dprintf(idx, " (%s today)\n", btos(itraffic_bn_today));
2607   }
2608   if (otraffic_dcc > 0 || itraffic_dcc > 0 || otraffic_dcc_today > 0 ||
2609       itraffic_dcc_today > 0) {
2610     dprintf(idx, "Partyline:\n");
2611     itmp = otraffic_dcc + otraffic_dcc_today;
2612     itmp2 = otraffic_dcc_today;
2613     dprintf(idx, "  out: %s", btos(itmp));
2614     dprintf(idx, " (%s today)\n", btos(itmp2));
2615     dprintf(idx, "   in: %s", btos(itraffic_dcc + itraffic_dcc_today));
2616     dprintf(idx, " (%s today)\n", btos(itraffic_dcc_today));
2617   }
2618   if (otraffic_trans > 0 || itraffic_trans > 0 || otraffic_trans_today > 0 ||
2619       itraffic_trans_today > 0) {
2620     dprintf(idx, "Transfer.mod:\n");
2621     dprintf(idx, "  out: %s", btos(otraffic_trans + otraffic_trans_today));
2622     dprintf(idx, " (%s today)\n", btos(otraffic_trans_today));
2623     dprintf(idx, "   in: %s", btos(itraffic_trans + itraffic_trans_today));
2624     dprintf(idx, " (%s today)\n", btos(itraffic_trans_today));
2625   }
2626   if (otraffic_unknown > 0 || otraffic_unknown_today > 0) {
2627     dprintf(idx, "Misc:\n");
2628     dprintf(idx, "  out: %s", btos(otraffic_unknown + otraffic_unknown_today));
2629     dprintf(idx, " (%s today)\n", btos(otraffic_unknown_today));
2630     dprintf(idx, "   in: %s", btos(itraffic_unknown + itraffic_unknown_today));
2631     dprintf(idx, " (%s today)\n", btos(itraffic_unknown_today));
2632   }
2633   dprintf(idx, "---\n");
2634   dprintf(idx, "Total:\n");
2635   itmp = otraffic_irc + otraffic_bn + otraffic_dcc + otraffic_trans +
2636          otraffic_unknown + otraffic_irc_today + otraffic_bn_today +
2637          otraffic_dcc_today + otraffic_trans_today + otraffic_unknown_today;
2638   itmp2 = otraffic_irc_today + otraffic_bn_today + otraffic_dcc_today +
2639           otraffic_trans_today + otraffic_unknown_today;
2640   dprintf(idx, "  out: %s", btos(itmp));
2641   dprintf(idx, " (%s today)\n", btos(itmp2));
2642   dprintf(idx, "   in: %s", btos(itraffic_irc + itraffic_bn + itraffic_dcc +
2643           itraffic_trans + itraffic_unknown + itraffic_irc_today +
2644           itraffic_bn_today + itraffic_dcc_today + itraffic_trans_today +
2645           itraffic_unknown_today));
2646   dprintf(idx, " (%s today)\n", btos(itraffic_irc_today + itraffic_bn_today +
2647           itraffic_dcc_today + itraffic_trans_today + itraffic_unknown_today));
2648   putlog(LOG_CMDS, "*", "#%s# traffic", dcc[idx].nick);
2649 }
2650 
2651 static char traffictxt[20];
btos(unsigned long bytes)2652 static char *btos(unsigned long bytes)
2653 {
2654   char unit[10];
2655   float xbytes;
2656 
2657   sprintf(unit, "Bytes");
2658   xbytes = bytes;
2659   if (xbytes > 1024.0) {
2660     sprintf(unit, "KBytes");
2661     xbytes = xbytes / 1024.0;
2662   }
2663   if (xbytes > 1024.0) {
2664     sprintf(unit, "MBytes");
2665     xbytes = xbytes / 1024.0;
2666   }
2667   if (xbytes > 1024.0) {
2668     sprintf(unit, "GBytes");
2669     xbytes = xbytes / 1024.0;
2670   }
2671   if (xbytes > 1024.0) {
2672     sprintf(unit, "TBytes");
2673     xbytes = xbytes / 1024.0;
2674   }
2675   if (bytes > 1024)
2676     sprintf(traffictxt, "%.2f %s", xbytes, unit);
2677   else
2678     sprintf(traffictxt, "%lu Bytes", bytes);
2679   return traffictxt;
2680 }
2681 
cmd_whoami(struct userrec * u,int idx,char * par)2682 static void cmd_whoami(struct userrec *u, int idx, char *par)
2683 {
2684   dprintf(idx, "You are %s@%s.\n", dcc[idx].nick, botnetnick);
2685   putlog(LOG_CMDS, "*", "#%s# whoami", dcc[idx].nick);
2686 }
2687 
2688 /* DCC CHAT COMMANDS */
2689 /* Function call should be:
2690  *   static void cmd_whatever(struct userrec *u, int idx, char *par);
2691  * As with msg commands, function is responsible for any logging.
2692  */
2693 cmd_t C_dcc[] = {
2694   {"+bot",      "t",    (Function) cmd_pls_bot,    NULL},
2695   {"+host",     "t|m",  (Function) cmd_pls_host,   NULL},
2696   {"+ignore",   "m",    (Function) cmd_pls_ignore, NULL},
2697   {"+user",     "m",    (Function) cmd_pls_user,   NULL},
2698   {"-bot",      "t",    (Function) cmd_mns_user,   NULL},
2699   {"-host",     "",     (Function) cmd_mns_host,   NULL},
2700   {"-ignore",   "m",    (Function) cmd_mns_ignore, NULL},
2701   {"-user",     "m",    (Function) cmd_mns_user,   NULL},
2702   {"addlog",    "to|o", (Function) cmd_addlog,     NULL},
2703   {"away",      "",     (Function) cmd_away,       NULL},
2704   {"back",      "",     (Function) cmd_back,       NULL},
2705   {"backup",    "m|m",  (Function) cmd_backup,     NULL},
2706   {"binds",     "m",    (Function) cmd_binds,      NULL},
2707   {"boot",      "t",    (Function) cmd_boot,       NULL},
2708   {"botattr",   "t",    (Function) cmd_botattr,    NULL},
2709 //  {"botinfo",   "",     (Function) cmd_botinfo,    NULL},
2710   {"bots",      "",     (Function) cmd_bots,       NULL},
2711   {"bottree",   "n",    (Function) cmd_bottree,    NULL},
2712   {"chaddr",    "t",    (Function) cmd_chaddr,     NULL},
2713   {"chat",      "",     (Function) cmd_chat,       NULL},
2714   {"chattr",    "m|m",  (Function) cmd_chattr,     NULL},
2715   {"chhandle",  "t",    (Function) cmd_chhandle,   NULL},
2716   {"chnick",    "t",    (Function) cmd_chhandle,   NULL},
2717   {"chpass",    "t",    (Function) cmd_chpass,     NULL},
2718   {"comment",   "m",    (Function) cmd_comment,    NULL},
2719   {"console",   "to|o", (Function) cmd_console,    NULL},
2720   {"dccstat",   "t",    (Function) cmd_dccstat,    NULL},
2721   {"debug",     "m",    (Function) cmd_debug,      NULL},
2722   {"die",       "n",    (Function) cmd_die,        NULL},
2723   {"d13",       "n",    (Function) cmd_die,        NULL},
2724   {"echo",      "",     (Function) cmd_echo,       NULL},
2725   {"export",    "n",    (Function) cmd_export,     NULL},
2726   {"fixcodes",  "",     (Function) cmd_fixcodes,   NULL},
2727   {"ignores",   "m",    (Function) cmd_ignores,    NULL},
2728   {"import",    "n",    (Function) cmd_import,     NULL},
2729   {"link",      "t",    (Function) cmd_link,       NULL},
2730   {"loadmod",   "n",    (Function) cmd_loadmod,    NULL},
2731   {"match",     "to|o", (Function) cmd_match,      NULL},
2732   {"me",        "",     (Function) cmd_me,         NULL},
2733   {"module",    "m",    (Function) cmd_module,     NULL},
2734   {"modules",   "n",    (Function) cmd_modules,    NULL},
2735   {"newpass",   "",     (Function) cmd_newpass,    NULL},
2736   {"handle",    "",     (Function) cmd_handle,     NULL},
2737   {"nick",      "",     (Function) cmd_handle,     NULL},
2738   {"page",      "",     (Function) cmd_page,       NULL},
2739   {"quit",      "",     (Function) NULL,           NULL},
2740   {"rehash",    "m",    (Function) cmd_rehash,     NULL},
2741   {"relay",     "o",    (Function) cmd_relay,      NULL},
2742   {"reload",    "m|m",  (Function) cmd_reload,     NULL},
2743   {"restart",   "m",    (Function) cmd_restart,    NULL},
2744   {"save",      "m|m",  (Function) cmd_save,       NULL},
2745   {"set",       "n",    (Function) cmd_set,        NULL},
2746   {"simul",     "n",    (Function) cmd_simul,      NULL},
2747   {"status",    "m|m",  (Function) cmd_status,     NULL},
2748   {"strip",     "",     (Function) cmd_strip,      NULL},
2749   {"su",        "",     (Function) cmd_su,         NULL},
2750   {"tcl",       "n",    (Function) cmd_tcl,        NULL},
2751   {"trace",     "t",    (Function) cmd_trace,      NULL},
2752   {"unlink",    "t",    (Function) cmd_unlink,     NULL},
2753   {"unloadmod", "n",    (Function) cmd_unloadmod,  NULL},
2754   {"uptime",    "m|m",  (Function) cmd_uptime,     NULL},
2755   {"vbottree",  "n",    (Function) cmd_vbottree,   NULL},
2756   {"who",       "",     (Function) cmd_who,        NULL},
2757   {"whoami",    "",     (Function) cmd_whoami,     NULL},
2758   {"whois",     "to|o", (Function) cmd_whois,      NULL},
2759   {"whom",      "",     (Function) cmd_whom,       NULL},
2760   {"wi",        "to|o", (Function) cmd_whois,      NULL},
2761   {"traffic",   "m|m",  (Function) cmd_traffic,    NULL},
2762   {NULL,        NULL,   NULL,                      NULL}
2763 };
2764