00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "main.h"
00028 #include "tandem.h"
00029 #include "modules.h"
00030 #include <ctype.h>
00031
00032 extern struct chanset_t *chanset;
00033 extern struct dcc_t *dcc;
00034 extern struct userrec *userlist;
00035 extern tcl_timer_t *timer, *utimer;
00036 extern int dcc_total, remote_boots, backgrd, make_userfile, do_restart,
00037 conmask, require_p, must_be_owner, strict_host;
00038 extern unsigned long otraffic_irc, otraffic_irc_today, itraffic_irc,
00039 itraffic_irc_today, otraffic_bn, otraffic_bn_today,
00040 itraffic_bn, itraffic_bn_today, otraffic_dcc,
00041 otraffic_dcc_today, itraffic_dcc, itraffic_dcc_today,
00042 otraffic_trans, otraffic_trans_today, itraffic_trans,
00043 itraffic_trans_today, otraffic_unknown,
00044 otraffic_unknown_today, itraffic_unknown,
00045 itraffic_unknown_today;
00046 extern Tcl_Interp *interp;
00047 extern char botnetnick[], origbotname[], ver[], network[], owner[], quit_msg[];
00048 extern time_t now, online_since;
00049 extern module_entry *module_list;
00050
00051 static char *btos(unsigned long);
00052
00053
00054
00055
00056 static int add_bot_hostmask(int idx, char *nick)
00057 {
00058 struct chanset_t *chan;
00059
00060 for (chan = chanset; chan; chan = chan->next)
00061 if (channel_active(chan)) {
00062 memberlist *m = ismember(chan, nick);
00063
00064 if (m) {
00065 char s[UHOSTLEN];
00066 struct userrec *u;
00067
00068 egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
00069 u = get_user_by_host(s);
00070 if (u) {
00071 dprintf(idx, "(Can't add hostmask for %s because it matches %s)\n",
00072 nick, u->handle);
00073 return 0;
00074 }
00075 if (strchr("~^+=-", m->userhost[0]))
00076 egg_snprintf(s, sizeof s, "*!%s%s", strict_host ? "?" : "",
00077 m->userhost + 1);
00078 else
00079 egg_snprintf(s, sizeof s, "*!%s", m->userhost);
00080 dprintf(idx, "(Added hostmask for %s from %s)\n", nick, chan->dname);
00081 addhost_by_handle(nick, s);
00082 return 1;
00083 }
00084 }
00085 return 0;
00086 }
00087
00088 static void tell_who(struct userrec *u, int idx, int chan)
00089 {
00090 int i, k, ok = 0, atr = u ? u->flags : 0;
00091 int nicklen;
00092 char format[81];
00093 char s[1024];
00094
00095 if (!chan)
00096 dprintf(idx, "%s (* = owner, + = master, %% = botmaster, @ = op, "
00097 "^ = halfop)\n", BOT_PARTYMEMBS);
00098 else {
00099 simple_sprintf(s, "assoc %d", chan);
00100 if ((Tcl_Eval(interp, s) != TCL_OK) || tcl_resultempty())
00101 dprintf(idx, "%s %s%d: (* = owner, + = master, %% = botmaster, @ = op, "
00102 "^ = halfop)\n", BOT_PEOPLEONCHAN, (chan < GLOBAL_CHANS) ? "" :
00103 "*", chan % GLOBAL_CHANS);
00104 else
00105 dprintf(idx, "%s '%s' (%s%d): (* = owner, + = master, %% = botmaster, @ = op, "
00106 "^ = halfop)\n", BOT_PEOPLEONCHAN, tcl_resultstring(),
00107 (chan < GLOBAL_CHANS) ? "" : "*", chan % GLOBAL_CHANS);
00108 }
00109
00110
00111 nicklen = 0;
00112 for (i = 0; i < dcc_total; i++) {
00113 if (strlen(dcc[i].nick) > nicklen)
00114 nicklen = strlen(dcc[i].nick);
00115 }
00116 if (nicklen < 9)
00117 nicklen = 9;
00118
00119 for (i = 0; i < dcc_total; i++)
00120 if (dcc[i].type == &DCC_CHAT)
00121 if (dcc[i].u.chat->channel == chan) {
00122 if (atr & USER_OWNER) {
00123 egg_snprintf(format, sizeof format, " [%%.2lu] %%c%%-%us %%s",
00124 nicklen);
00125 sprintf(s, format, dcc[i].sock,
00126 (geticon(i) == '-' ? ' ' : geticon(i)), dcc[i].nick,
00127 dcc[i].host);
00128 } else {
00129 egg_snprintf(format, sizeof format, " %%c%%-%us %%s", nicklen);
00130 sprintf(s, format,
00131 (geticon(i) == '-' ? ' ' : geticon(i)),
00132 dcc[i].nick, dcc[i].host);
00133 }
00134 if (atr & USER_MASTER) {
00135 if (dcc[i].u.chat->con_flags)
00136 sprintf(&s[strlen(s)], " (con:%s)",
00137 masktype(dcc[i].u.chat->con_flags));
00138 }
00139 if (now - dcc[i].timeval > 300) {
00140 unsigned long days, hrs, mins;
00141
00142 days = (now - dcc[i].timeval) / 86400;
00143 hrs = ((now - dcc[i].timeval) - (days * 86400)) / 3600;
00144 mins = ((now - dcc[i].timeval) - (hrs * 3600)) / 60;
00145 if (days > 0)
00146 sprintf(&s[strlen(s)], " (idle %lud%luh)", days, hrs);
00147 else if (hrs > 0)
00148 sprintf(&s[strlen(s)], " (idle %luh%lum)", hrs, mins);
00149 else
00150 sprintf(&s[strlen(s)], " (idle %lum)", mins);
00151 }
00152 dprintf(idx, "%s\n", s);
00153 if (dcc[i].u.chat->away != NULL)
00154 dprintf(idx, " AWAY: %s\n", dcc[i].u.chat->away);
00155 }
00156 for (i = 0; i < dcc_total; i++)
00157 if (dcc[i].type == &DCC_BOT) {
00158 if (!ok) {
00159 ok = 1;
00160 dprintf(idx, "Bots connected:\n");
00161 }
00162 egg_strftime(s, 14, "%d %b %H:%M", localtime(&dcc[i].timeval));
00163 if (atr & USER_OWNER) {
00164 egg_snprintf(format, sizeof format,
00165 " [%%.2lu] %%s%%c%%-%us (%%s) %%s\n", nicklen);
00166 dprintf(idx, format, dcc[i].sock,
00167 dcc[i].status & STAT_CALLED ? "<-" : "->",
00168 dcc[i].status & STAT_SHARE ? '+' : ' ', dcc[i].nick, s,
00169 dcc[i].u.bot->version);
00170 } else {
00171 egg_snprintf(format, sizeof format, " %%s%%c%%-%us (%%s) %%s\n",
00172 nicklen);
00173 dprintf(idx, format, dcc[i].status & STAT_CALLED ? "<-" : "->",
00174 dcc[i].status & STAT_SHARE ? '+' : ' ', dcc[i].nick, s,
00175 dcc[i].u.bot->version);
00176 }
00177 }
00178 ok = 0;
00179 for (i = 0; i < dcc_total; i++) {
00180 if ((dcc[i].type == &DCC_CHAT) && (dcc[i].u.chat->channel != chan)) {
00181 if (!ok) {
00182 ok = 1;
00183 dprintf(idx, "Other people on the bot:\n");
00184 }
00185 if (atr & USER_OWNER) {
00186 egg_snprintf(format, sizeof format, " [%%.2lu] %%c%%-%us ", nicklen);
00187 sprintf(s, format, dcc[i].sock,
00188 (geticon(i) == '-' ? ' ' : geticon(i)), dcc[i].nick);
00189 } else {
00190 egg_snprintf(format, sizeof format, " %%c%%-%us ", nicklen);
00191 sprintf(s, format, (geticon(i) == '-' ? ' ' : geticon(i)), dcc[i].nick);
00192 }
00193 if (atr & USER_MASTER) {
00194 if (dcc[i].u.chat->channel < 0)
00195 strcat(s, "(-OFF-) ");
00196 else if (!dcc[i].u.chat->channel)
00197 strcat(s, "(party) ");
00198 else
00199 sprintf(&s[strlen(s)], "(%5d) ", dcc[i].u.chat->channel);
00200 }
00201 strcat(s, dcc[i].host);
00202 if (atr & USER_MASTER) {
00203 if (dcc[i].u.chat->con_flags)
00204 sprintf(&s[strlen(s)], " (con:%s)",
00205 masktype(dcc[i].u.chat->con_flags));
00206 }
00207 if (now - dcc[i].timeval > 300) {
00208 k = (now - dcc[i].timeval) / 60;
00209 if (k < 60)
00210 sprintf(&s[strlen(s)], " (idle %dm)", k);
00211 else
00212 sprintf(&s[strlen(s)], " (idle %dh%dm)", k / 60, k % 60);
00213 }
00214 dprintf(idx, "%s\n", s);
00215 if (dcc[i].u.chat->away != NULL)
00216 dprintf(idx, " AWAY: %s\n", dcc[i].u.chat->away);
00217 }
00218 if ((atr & USER_MASTER) && (dcc[i].type->flags & DCT_SHOWWHO) &&
00219 (dcc[i].type != &DCC_CHAT)) {
00220 if (!ok) {
00221 ok = 1;
00222 dprintf(idx, "Other people on the bot:\n");
00223 }
00224 if (atr & USER_OWNER) {
00225 egg_snprintf(format, sizeof format, " [%%.2lu] %%c%%-%us (files) %%s",
00226 nicklen);
00227 sprintf(s, format,
00228 dcc[i].sock, dcc[i].status & STAT_CHAT ? '+' : ' ',
00229 dcc[i].nick, dcc[i].host);
00230 } else {
00231 egg_snprintf(format, sizeof format, " %%c%%-%us (files) %%s", nicklen);
00232 sprintf(s, format,
00233 dcc[i].status & STAT_CHAT ? '+' : ' ',
00234 dcc[i].nick, dcc[i].host);
00235 }
00236 dprintf(idx, "%s\n", s);
00237 }
00238 }
00239 }
00240
00241 static void cmd_botinfo(struct userrec *u, int idx, char *par)
00242 {
00243 char s[512], s2[32];
00244 struct chanset_t *chan;
00245 time_t now2;
00246 int hr, min;
00247
00248 now2 = now - online_since;
00249 s2[0] = 0;
00250 if (now2 > 86400) {
00251 int days = now2 / 86400;
00252
00253
00254 sprintf(s2, "%d day", days);
00255 if (days >= 2)
00256 strcat(s2, "s");
00257 strcat(s2, ", ");
00258 now2 -= days * 86400;
00259 }
00260 hr = (time_t) ((int) now2 / 3600);
00261 now2 -= (hr * 3600);
00262 min = (time_t) ((int) now2 / 60);
00263 sprintf(&s2[strlen(s2)], "%02d:%02d", (int) hr, (int) min);
00264 putlog(LOG_CMDS, "*", "#%s# botinfo", dcc[idx].nick);
00265 simple_sprintf(s, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
00266 botnet_send_infoq(-1, s);
00267 s[0] = 0;
00268 if (module_find("server", 0, 0)) {
00269 for (chan = chanset; chan; chan = chan->next) {
00270 if (!channel_secret(chan)) {
00271 if ((strlen(s) + strlen(chan->dname) + strlen(network)
00272 + strlen(botnetnick) + strlen(ver) + 1) >= 490) {
00273 strcat(s, "++ ");
00274 break;
00275 }
00276 strcat(s, chan->dname);
00277 strcat(s, ", ");
00278 }
00279 }
00280
00281 if (s[0]) {
00282 s[strlen(s) - 2] = 0;
00283 dprintf(idx, "*** [%s] %s <%s> (%s) [UP %s]\n", botnetnick,
00284 ver, network, s, s2);
00285 } else
00286 dprintf(idx, "*** [%s] %s <%s> (%s) [UP %s]\n", botnetnick,
00287 ver, network, BOT_NOCHANNELS, s2);
00288 } else
00289 dprintf(idx, "*** [%s] %s <NO_IRC> [UP %s]\n", botnetnick, ver, s2);
00290 }
00291
00292 static void cmd_whom(struct userrec *u, int idx, char *par)
00293 {
00294 if (par[0] == '*') {
00295 putlog(LOG_CMDS, "*", "#%s# whom %s", dcc[idx].nick, par);
00296 answer_local_whom(idx, -1);
00297 return;
00298 } else if (dcc[idx].u.chat->channel < 0) {
00299 dprintf(idx, "You have chat turned off.\n");
00300 return;
00301 }
00302 putlog(LOG_CMDS, "*", "#%s# whom %s", dcc[idx].nick, par);
00303 if (!par[0]) {
00304 answer_local_whom(idx, dcc[idx].u.chat->channel);
00305 } else {
00306 int chan = -1;
00307
00308 if ((par[0] < '0') || (par[0] > '9')) {
00309 Tcl_SetVar(interp, "_chan", par, 0);
00310 if ((Tcl_VarEval(interp, "assoc ", "$_chan", NULL) == TCL_OK) &&
00311 !tcl_resultempty()) {
00312 chan = tcl_resultint();
00313 }
00314 if (chan <= 0) {
00315 dprintf(idx, "No such channel exists.\n");
00316 return;
00317 }
00318 } else
00319 chan = atoi(par);
00320 if ((chan < 0) || (chan >= GLOBAL_CHANS)) {
00321 dprintf(idx, "Channel number out of range: must be between 0 and %d."
00322 "\n", GLOBAL_CHANS);
00323 return;
00324 }
00325 answer_local_whom(idx, chan);
00326 }
00327 }
00328
00329 static void cmd_me(struct userrec *u, int idx, char *par)
00330 {
00331 int i;
00332
00333 if (dcc[idx].u.chat->channel < 0) {
00334 dprintf(idx, "You have chat turned off.\n");
00335 return;
00336 }
00337 if (!par[0]) {
00338 dprintf(idx, "Usage: me <action>\n");
00339 return;
00340 }
00341 if (dcc[idx].u.chat->away != NULL)
00342 not_away(idx);
00343 for (i = 0; i < dcc_total; i++)
00344 if ((dcc[i].type->flags & DCT_CHAT) &&
00345 (dcc[i].u.chat->channel == dcc[idx].u.chat->channel) &&
00346 ((i != idx) || (dcc[i].status & STAT_ECHO)))
00347 dprintf(i, "* %s %s\n", dcc[idx].nick, par);
00348 botnet_send_act(idx, botnetnick, dcc[idx].nick,
00349 dcc[idx].u.chat->channel, par);
00350 check_tcl_act(dcc[idx].nick, dcc[idx].u.chat->channel, par);
00351 }
00352
00353 static void cmd_motd(struct userrec *u, int idx, char *par)
00354 {
00355 int i;
00356
00357 if (par[0]) {
00358 putlog(LOG_CMDS, "*", "#%s# motd %s", dcc[idx].nick, par);
00359 if (!egg_strcasecmp(par, botnetnick))
00360 show_motd(idx);
00361 else {
00362 i = nextbot(par);
00363 if (i < 0)
00364 dprintf(idx, "That bot isn't connected.\n");
00365 else {
00366 char x[40];
00367
00368 simple_sprintf(x, "%s%d:%s@%s",
00369 (u->flags & USER_HIGHLITE) ?
00370 ((dcc[idx].status & STAT_TELNET) ? "#" : "!") : "",
00371 dcc[idx].sock, dcc[idx].nick, botnetnick);
00372 botnet_send_motd(i, x, par);
00373 }
00374 }
00375 } else {
00376 putlog(LOG_CMDS, "*", "#%s# motd", dcc[idx].nick);
00377 show_motd(idx);
00378 }
00379 }
00380
00381 static void cmd_away(struct userrec *u, int idx, char *par)
00382 {
00383 if (strlen(par) > 60)
00384 par[60] = 0;
00385 set_away(idx, par);
00386 }
00387
00388 static void cmd_back(struct userrec *u, int idx, char *par)
00389 {
00390 not_away(idx);
00391 }
00392
00393 static void cmd_newpass(struct userrec *u, int idx, char *par)
00394 {
00395 char *new;
00396
00397 if (!par[0]) {
00398 dprintf(idx, "Usage: newpass <newpassword>\n");
00399 return;
00400 }
00401 new = newsplit(&par);
00402 if (strlen(new) > 16)
00403 new[16] = 0;
00404 if (strlen(new) < 6) {
00405 dprintf(idx, "Please use at least 6 characters.\n");
00406 return;
00407 }
00408 set_user(&USERENTRY_PASS, u, new);
00409 putlog(LOG_CMDS, "*", "#%s# newpass...", dcc[idx].nick);
00410 dprintf(idx, "Changed password to '%s'.\n", new);
00411 }
00412
00413 static void cmd_bots(struct userrec *u, int idx, char *par)
00414 {
00415 putlog(LOG_CMDS, "*", "#%s# bots", dcc[idx].nick);
00416 tell_bots(idx);
00417 }
00418
00419 static void cmd_bottree(struct userrec *u, int idx, char *par)
00420 {
00421 putlog(LOG_CMDS, "*", "#%s# bottree", dcc[idx].nick);
00422 tell_bottree(idx, 0);
00423 }
00424
00425 static void cmd_vbottree(struct userrec *u, int idx, char *par)
00426 {
00427 putlog(LOG_CMDS, "*", "#%s# vbottree", dcc[idx].nick);
00428 tell_bottree(idx, 1);
00429 }
00430
00431 static void cmd_rehelp(struct userrec *u, int idx, char *par)
00432 {
00433 putlog(LOG_CMDS, "*", "#%s# rehelp", dcc[idx].nick);
00434 dprintf(idx, "Reload help cache...\n");
00435 reload_help_data();
00436 }
00437
00438 static void cmd_help(struct userrec *u, int idx, char *par)
00439 {
00440 struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
00441
00442 get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
00443 if (par[0]) {
00444 putlog(LOG_CMDS, "*", "#%s# help %s", dcc[idx].nick, par);
00445 if (!strcmp(par, "all"))
00446 tellallhelp(idx, "all", &fr);
00447 else if (strchr(par, '*') || strchr(par, '?')) {
00448 char *p = par;
00449
00450
00451
00452
00453
00454 for (p = par; *p && ((*p == '*') || (*p == '?')); p++);
00455 if (*p)
00456 tellwildhelp(idx, par, &fr);
00457 else
00458 tellallhelp(idx, "all", &fr);
00459 } else
00460 tellhelp(idx, par, &fr, 0);
00461 } else {
00462 putlog(LOG_CMDS, "*", "#%s# help", dcc[idx].nick);
00463 if (glob_op(fr) || glob_botmast(fr) || chan_op(fr))
00464 tellhelp(idx, "help", &fr, 0);
00465 else
00466 tellhelp(idx, "partyline", &fr, 0);
00467 }
00468 }
00469
00470 static void cmd_addlog(struct userrec *u, int idx, char *par)
00471 {
00472 if (!par[0]) {
00473 dprintf(idx, "Usage: addlog <message>\n");
00474 return;
00475 }
00476 dprintf(idx, "Placed entry in the log file.\n");
00477 putlog(LOG_MISC, "*", "%s: %s", dcc[idx].nick, par);
00478 }
00479
00480 static void cmd_who(struct userrec *u, int idx, char *par)
00481 {
00482 int i;
00483
00484 if (par[0]) {
00485 if (dcc[idx].u.chat->channel < 0) {
00486 dprintf(idx, "You have chat turned off.\n");
00487 return;
00488 }
00489 putlog(LOG_CMDS, "*", "#%s# who %s", dcc[idx].nick, par);
00490 if (!egg_strcasecmp(par, botnetnick))
00491 tell_who(u, idx, dcc[idx].u.chat->channel);
00492 else {
00493 i = nextbot(par);
00494 if (i < 0) {
00495 dprintf(idx, "That bot isn't connected.\n");
00496 } else if (dcc[idx].u.chat->channel >= GLOBAL_CHANS)
00497 dprintf(idx, "You are on a local channel.\n");
00498 else {
00499 char s[40];
00500
00501 simple_sprintf(s, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
00502 botnet_send_who(i, s, par, dcc[idx].u.chat->channel);
00503 }
00504 }
00505 } else {
00506 putlog(LOG_CMDS, "*", "#%s# who", dcc[idx].nick);
00507 if (dcc[idx].u.chat->channel < 0)
00508 tell_who(u, idx, 0);
00509 else
00510 tell_who(u, idx, dcc[idx].u.chat->channel);
00511 }
00512 }
00513
00514 static void cmd_whois(struct userrec *u, int idx, char *par)
00515 {
00516 if (!par[0]) {
00517 dprintf(idx, "Usage: whois <handle>\n");
00518 return;
00519 }
00520
00521 putlog(LOG_CMDS, "*", "#%s# whois %s", dcc[idx].nick, par);
00522 tell_user_ident(idx, par, u ? (u->flags & USER_MASTER) : 0);
00523 }
00524
00525 static void cmd_match(struct userrec *u, int idx, char *par)
00526 {
00527 int start = 1, limit = 20;
00528 char *s, *s1, *chname;
00529
00530 if (!par[0]) {
00531 dprintf(idx, "Usage: match <nick/host> [[skip] count]\n");
00532 return;
00533 }
00534 putlog(LOG_CMDS, "*", "#%s# match %s", dcc[idx].nick, par);
00535 s = newsplit(&par);
00536 if (strchr(CHANMETA, par[0]) != NULL)
00537 chname = newsplit(&par);
00538 else
00539 chname = "";
00540 if (atoi(par) > 0) {
00541 s1 = newsplit(&par);
00542 if (atoi(par) > 0) {
00543 start = atoi(s1);
00544 limit = atoi(par);
00545 } else
00546 limit = atoi(s1);
00547 }
00548 tell_users_match(idx, s, start, limit, u ? (u->flags & USER_MASTER) : 0,
00549 chname);
00550 }
00551
00552 static void cmd_uptime(struct userrec *u, int idx, char *par)
00553 {
00554 putlog(LOG_CMDS, "*", "#%s# uptime", dcc[idx].nick);
00555 tell_verbose_uptime(idx);
00556 }
00557
00558 static void cmd_status(struct userrec *u, int idx, char *par)
00559 {
00560 int atr = u ? u->flags : 0;
00561
00562 if (!egg_strcasecmp(par, "all")) {
00563 if (!(atr & USER_MASTER)) {
00564 dprintf(idx, "You do not have Bot Master privileges.\n");
00565 return;
00566 }
00567 putlog(LOG_CMDS, "*", "#%s# status all", dcc[idx].nick);
00568 tell_verbose_status(idx);
00569 tell_mem_status_dcc(idx);
00570 dprintf(idx, "\n");
00571 tell_settings(idx);
00572 do_module_report(idx, 1, NULL);
00573 } else {
00574 putlog(LOG_CMDS, "*", "#%s# status", dcc[idx].nick);
00575 tell_verbose_status(idx);
00576 tell_mem_status_dcc(idx);
00577 do_module_report(idx, 0, NULL);
00578 }
00579 }
00580
00581 static void cmd_dccstat(struct userrec *u, int idx, char *par)
00582 {
00583 putlog(LOG_CMDS, "*", "#%s# dccstat", dcc[idx].nick);
00584 tell_dcc(idx);
00585 }
00586
00587 static void cmd_boot(struct userrec *u, int idx, char *par)
00588 {
00589 int i, files = 0, ok = 0;
00590 char *who;
00591 struct userrec *u2;
00592
00593 if (!par[0]) {
00594 dprintf(idx, "Usage: boot nick[@bot]\n");
00595 return;
00596 }
00597 who = newsplit(&par);
00598 if (strchr(who, '@') != NULL) {
00599 char whonick[HANDLEN + 1];
00600
00601 splitcn(whonick, who, '@', HANDLEN + 1);
00602 if (!egg_strcasecmp(who, botnetnick)) {
00603 cmd_boot(u, idx, whonick);
00604 return;
00605 }
00606 if (remote_boots > 0) {
00607 i = nextbot(who);
00608 if (i < 0) {
00609 dprintf(idx, "No such bot connected.\n");
00610 return;
00611 }
00612 botnet_send_reject(i, dcc[idx].nick, botnetnick, whonick,
00613 who, par[0] ? par : dcc[idx].nick);
00614 putlog(LOG_BOTS, "*", "#%s# boot %s@%s (%s)", dcc[idx].nick, whonick,
00615 who, par[0] ? par : dcc[idx].nick);
00616 } else
00617 dprintf(idx, "Remote boots are disabled here.\n");
00618 return;
00619 }
00620 for (i = 0; i < dcc_total; i++)
00621 if (!egg_strcasecmp(dcc[i].nick, who) && !ok &&
00622 (dcc[i].type->flags & DCT_CANBOOT)) {
00623 u2 = get_user_by_handle(userlist, dcc[i].nick);
00624 if (u2 && (u2->flags & USER_OWNER) &&
00625 egg_strcasecmp(dcc[idx].nick, who)) {
00626 dprintf(idx, "You can't boot a bot owner.\n");
00627 return;
00628 }
00629 if (u2 && (u2->flags & USER_MASTER) && !(u && (u->flags & USER_MASTER))) {
00630 dprintf(idx, "You can't boot a bot master.\n");
00631 return;
00632 }
00633 files = (dcc[i].type->flags & DCT_FILES);
00634 if (files)
00635 dprintf(idx, "Booted %s from the file area.\n", dcc[i].nick);
00636 else
00637 dprintf(idx, "Booted %s from the party line.\n", dcc[i].nick);
00638 putlog(LOG_CMDS, "*", "#%s# boot %s %s", dcc[idx].nick, who, par);
00639 do_boot(i, dcc[idx].nick, par);
00640 ok = 1;
00641 }
00642 if (!ok)
00643 dprintf(idx, "Who? No such person on the party line.\n");
00644 }
00645
00646 static void cmd_console(struct userrec *u, int idx, char *par)
00647 {
00648 char *nick, s[2], s1[512];
00649 int dest = 0, i, ok = 0, pls;
00650 struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
00651 module_entry *me;
00652
00653 if (!par[0]) {
00654 dprintf(idx, "Your console is %s: %s (%s).\n",
00655 dcc[idx].u.chat->con_chan,
00656 masktype(dcc[idx].u.chat->con_flags),
00657 maskname(dcc[idx].u.chat->con_flags));
00658 return;
00659 }
00660 get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
00661 strcpy(s1, par);
00662 nick = newsplit(&par);
00663
00664
00665
00666 if (nick[0] && !strchr(CHANMETA "+-*", nick[0]) && glob_master(fr)) {
00667 for (i = 0; i < dcc_total; i++)
00668 if (!egg_strcasecmp(nick, dcc[i].nick) &&
00669 (dcc[i].type == &DCC_CHAT) && (!ok)) {
00670 ok = 1;
00671 dest = i;
00672 }
00673 if (!ok) {
00674 dprintf(idx, "No such user on the party line!\n");
00675 return;
00676 }
00677 nick[0] = 0;
00678 } else
00679 dest = idx;
00680 if (!nick[0])
00681 nick = newsplit(&par);
00682
00683 if ((nick[0] == '+' && findchan_by_dname(nick)) ||
00684 (nick[0] != '+' && strchr(CHANMETA "*", nick[0]))) {
00685 if (strcmp(nick, "*") && !findchan_by_dname(nick)) {
00686 dprintf(idx, "Invalid console channel: %s.\n", nick);
00687 return;
00688 }
00689 get_user_flagrec(u, &fr, nick);
00690 if (!chan_op(fr) && !(glob_op(fr) && !chan_deop(fr))) {
00691 dprintf(idx, "You don't have op or master access to channel %s.\n",
00692 nick);
00693 return;
00694 }
00695 strncpyz(dcc[dest].u.chat->con_chan, nick, 81);
00696 nick[0] = 0;
00697 if (dest != idx)
00698 get_user_flagrec(dcc[dest].user, &fr, dcc[dest].u.chat->con_chan);
00699 }
00700 if (!nick[0])
00701 nick = newsplit(&par);
00702 pls = 1;
00703 if (nick[0]) {
00704 if ((nick[0] != '+') && (nick[0] != '-'))
00705 dcc[dest].u.chat->con_flags = 0;
00706 for (; *nick; nick++) {
00707 if (*nick == '+')
00708 pls = 1;
00709 else if (*nick == '-')
00710 pls = 0;
00711 else {
00712 s[0] = *nick;
00713 s[1] = 0;
00714 if (pls)
00715 dcc[dest].u.chat->con_flags |= logmodes(s);
00716 else
00717 dcc[dest].u.chat->con_flags &= ~logmodes(s);
00718 }
00719 }
00720 }
00721 dcc[dest].u.chat->con_flags = check_conflags(&fr,
00722 dcc[dest].u.chat->con_flags);
00723 putlog(LOG_CMDS, "*", "#%s# console %s", dcc[idx].nick, s1);
00724 if (dest == idx) {
00725 dprintf(idx, "Set your console to %s: %s (%s).\n",
00726 dcc[idx].u.chat->con_chan,
00727 masktype(dcc[idx].u.chat->con_flags),
00728 maskname(dcc[idx].u.chat->con_flags));
00729 } else {
00730 dprintf(idx, "Set console of %s to %s: %s (%s).\n", dcc[dest].nick,
00731 dcc[dest].u.chat->con_chan,
00732 masktype(dcc[dest].u.chat->con_flags),
00733 maskname(dcc[dest].u.chat->con_flags));
00734 dprintf(dest, "%s set your console to %s: %s (%s).\n", dcc[idx].nick,
00735 dcc[dest].u.chat->con_chan,
00736 masktype(dcc[dest].u.chat->con_flags),
00737 maskname(dcc[dest].u.chat->con_flags));
00738 }
00739
00740 if ((me = module_find("console", 1, 1))) {
00741 Function *func = me->funcs;
00742
00743 (func[CONSOLE_DOSTORE]) (dest);
00744 }
00745 }
00746
00747 static void cmd_pls_bot(struct userrec *u, int idx, char *par)
00748 {
00749 char *handle, *addr, *p, *q, *host;
00750 struct userrec *u1;
00751 struct bot_addr *bi;
00752
00753 if (!par[0]) {
00754 dprintf(idx, "Usage: +bot <handle> [address[:telnet-port[/relay-port]]] "
00755 "[host]\n");
00756 return;
00757 }
00758
00759 handle = newsplit(&par);
00760 addr = newsplit(&par);
00761 host = newsplit(&par);
00762
00763 if (strlen(handle) > HANDLEN)
00764 handle[HANDLEN] = 0;
00765
00766 if (get_user_by_handle(userlist, handle)) {
00767 dprintf(idx, "Someone already exists by that name.\n");
00768 return;
00769 }
00770
00771 if (strchr(BADHANDCHARS, handle[0]) != NULL) {
00772 dprintf(idx, "You can't start a botnick with '%c'.\n", handle[0]);
00773 return;
00774 }
00775
00776 if (strlen(addr) > 60)
00777 addr[60] = 0;
00778
00779 putlog(LOG_CMDS, "*", "#%s# +bot %s%s%s%s%s", dcc[idx].nick, handle,
00780 addr[0] ? " " : "", addr, host[0] ? " " : "", host);
00781 userlist = adduser(userlist, handle, "none", "-", USER_BOT);
00782 u1 = get_user_by_handle(userlist, handle);
00783 bi = user_malloc(sizeof(struct bot_addr));
00784
00785 q = strchr(addr, ':');
00786 if (!q) {
00787 bi->address = user_malloc(strlen(addr) + 1);
00788 strcpy(bi->address, addr);
00789 bi->telnet_port = 3333;
00790 bi->relay_port = 3333;
00791 } else {
00792 bi->address = user_malloc(q - addr + 1);
00793 strncpy(bi->address, addr, q - addr);
00794 bi->address[q - addr] = 0;
00795 p = q + 1;
00796 bi->telnet_port = atoi(p);
00797 q = strchr(p, '/');
00798 if (!q) {
00799 bi->relay_port = bi->telnet_port;
00800 } else {
00801 bi->relay_port = atoi(q + 1);
00802 }
00803 }
00804
00805 set_user(&USERENTRY_BOTADDR, u1, bi);
00806 if (addr[0]) {
00807 dprintf(idx, "Added bot '%s' with address '%s' and %s%s%s.\n", handle,
00808 addr, host[0] ? "hostmask '" : "no hostmask", host[0] ? host : "",
00809 host[0] ? "'" : "");
00810 } else{
00811 dprintf(idx, "Added bot '%s' with no address and %s%s%s.\n", handle,
00812 host[0] ? "hostmask '" : "no hostmask", host[0] ? host : "",
00813 host[0] ? "'" : "");
00814 }
00815 if (host[0]) {
00816 addhost_by_handle(handle, host);
00817 } else if (!add_bot_hostmask(idx, handle)) {
00818 dprintf(idx, "You'll want to add a hostmask if this bot will ever be on "
00819 "any channels that I'm on.\n");
00820 }
00821 }
00822
00823 static void cmd_chhandle(struct userrec *u, int idx, char *par)
00824 {
00825 char hand[HANDLEN + 1], newhand[HANDLEN + 1];
00826 int i, atr = u ? u->flags : 0, atr2;
00827 struct userrec *u2;
00828
00829 strncpyz(hand, newsplit(&par), sizeof hand);
00830 strncpyz(newhand, newsplit(&par), sizeof newhand);
00831
00832 if (!hand[0] || !newhand[0]) {
00833 dprintf(idx, "Usage: chhandle <oldhandle> <newhandle>\n");
00834 return;
00835 }
00836 for (i = 0; i < strlen(newhand); i++)
00837 if (((unsigned char) newhand[i] <= 32) || (newhand[i] == '@'))
00838 newhand[i] = '?';
00839 if (strchr(BADHANDCHARS, newhand[0]) != NULL)
00840 dprintf(idx, "Bizarre quantum forces prevent nicknames from starting with "
00841 "'%c'.\n", newhand[0]);
00842 else if (get_user_by_handle(userlist, newhand) &&
00843 egg_strcasecmp(hand, newhand))
00844 dprintf(idx, "Somebody is already using %s.\n", newhand);
00845 else {
00846 u2 = get_user_by_handle(userlist, hand);
00847 atr2 = u2 ? u2->flags : 0;
00848 if ((atr & USER_BOTMAST) && !(atr & USER_MASTER) && !(atr2 & USER_BOT))
00849 dprintf(idx, "You can't change handles for non-bots.\n");
00850 else if ((bot_flags(u2) & BOT_SHARE) && !(atr & USER_OWNER))
00851 dprintf(idx, "You can't change share bot's nick.\n");
00852 else if ((atr2 & USER_OWNER) && !(atr & USER_OWNER) &&
00853 egg_strcasecmp(dcc[idx].nick, hand))
00854 dprintf(idx, "You can't change a bot owner's handle.\n");
00855 else if (isowner(hand) && egg_strcasecmp(dcc[idx].nick, hand))
00856 dprintf(idx, "You can't change a permanent bot owner's handle.\n");
00857 else if (!egg_strcasecmp(newhand, botnetnick) && (!(atr2 & USER_BOT) ||
00858 nextbot(hand) != -1))
00859 dprintf(idx, "Hey! That's MY name!\n");
00860 else if (change_handle(u2, newhand)) {
00861 putlog(LOG_CMDS, "*", "#%s# chhandle %s %s", dcc[idx].nick,
00862 hand, newhand);
00863 dprintf(idx, "Changed.\n");
00864 } else
00865 dprintf(idx, "Failed.\n");
00866 }
00867 }
00868
00869 static void cmd_handle(struct userrec *u, int idx, char *par)
00870 {
00871 char oldhandle[HANDLEN + 1], newhandle[HANDLEN + 1];
00872 int i;
00873
00874 strncpyz(newhandle, newsplit(&par), sizeof newhandle);
00875
00876 if (!newhandle[0]) {
00877 dprintf(idx, "Usage: handle <new-handle>\n");
00878 return;
00879 }
00880 for (i = 0; i < strlen(newhandle); i++)
00881 if (((unsigned char) newhandle[i] <= 32) || (newhandle[i] == '@'))
00882 newhandle[i] = '?';
00883 if (strchr(BADHANDCHARS, newhandle[0]) != NULL)
00884 dprintf(idx,
00885 "Bizarre quantum forces prevent handle from starting with '%c'.\n",
00886 newhandle[0]);
00887 else if (get_user_by_handle(userlist, newhandle) &&
00888 egg_strcasecmp(dcc[idx].nick, newhandle))
00889 dprintf(idx, "Somebody is already using %s.\n", newhandle);
00890 else if (!egg_strcasecmp(newhandle, botnetnick))
00891 dprintf(idx, "Hey! That's MY name!\n");
00892 else {
00893 strncpyz(oldhandle, dcc[idx].nick, sizeof oldhandle);
00894 if (change_handle(u, newhandle)) {
00895 putlog(LOG_CMDS, "*", "#%s# handle %s", oldhandle, newhandle);
00896 dprintf(idx, "Okay, changed.\n");
00897 } else
00898 dprintf(idx, "Failed.\n");
00899 }
00900 }
00901
00902 static void cmd_chpass(struct userrec *u, int idx, char *par)
00903 {
00904 char *handle, *new;
00905 int atr = u ? u->flags : 0, l;
00906
00907 if (!par[0])
00908 dprintf(idx, "Usage: chpass <handle> [password]\n");
00909 else {
00910 handle = newsplit(&par);
00911 u = get_user_by_handle(userlist, handle);
00912 if (!u)
00913 dprintf(idx, "No such user.\n");
00914 else if ((atr & USER_BOTMAST) && !(atr & USER_MASTER) &&
00915 !(u->flags & USER_BOT))
00916 dprintf(idx, "You can't change passwords for non-bots.\n");
00917 else if ((bot_flags(u) & BOT_SHARE) && !(atr & USER_OWNER))
00918 dprintf(idx, "You can't change a share bot's password.\n");
00919 else if ((u->flags & USER_OWNER) && !(atr & USER_OWNER) &&
00920 egg_strcasecmp(handle, dcc[idx].nick))
00921 dprintf(idx, "You can't change a bot owner's password.\n");
00922 else if (isowner(handle) && egg_strcasecmp(dcc[idx].nick, handle))
00923 dprintf(idx, "You can't change a permanent bot owner's password.\n");
00924 else if (!par[0]) {
00925 putlog(LOG_CMDS, "*", "#%s# chpass %s [nothing]", dcc[idx].nick, handle);
00926 set_user(&USERENTRY_PASS, u, NULL);
00927 dprintf(idx, "Removed password.\n");
00928 } else {
00929 l = strlen(new = newsplit(&par));
00930 if (l > 16)
00931 new[16] = 0;
00932 if (l < 6)
00933 dprintf(idx, "Please use at least 6 characters.\n");
00934 else {
00935 set_user(&USERENTRY_PASS, u, new);
00936 putlog(LOG_CMDS, "*", "#%s# chpass %s [something]", dcc[idx].nick,
00937 handle);
00938 dprintf(idx, "Changed password.\n");
00939 }
00940 }
00941 }
00942 }
00943
00944 static void cmd_chaddr(struct userrec *u, int idx, char *par)
00945 {
00946 int telnet_port = 3333, relay_port = 3333;
00947 char *handle, *addr, *p, *q;
00948 struct bot_addr *bi;
00949 struct userrec *u1;
00950
00951 handle = newsplit(&par);
00952 if (!par[0]) {
00953 dprintf(idx, "Usage: chaddr <botname> "
00954 "<address[:telnet-port[/relay-port]]>\n");
00955 return;
00956 }
00957 addr = newsplit(&par);
00958 if (strlen(addr) > UHOSTMAX)
00959 addr[UHOSTMAX] = 0;
00960 u1 = get_user_by_handle(userlist, handle);
00961 if (!u1 || !(u1->flags & USER_BOT)) {
00962 dprintf(idx, "This command is only useful for tandem bots.\n");
00963 return;
00964 }
00965 if ((bot_flags(u1) & BOT_SHARE) && (!u || !(u->flags & USER_OWNER))) {
00966 dprintf(idx, "You can't change a share bot's address.\n");
00967 return;
00968 }
00969 putlog(LOG_CMDS, "*", "#%s# chaddr %s %s", dcc[idx].nick, handle, addr);
00970 dprintf(idx, "Changed bot's address.\n");
00971
00972 bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u1);
00973 if (bi) {
00974 telnet_port = bi->telnet_port;
00975 relay_port = bi->relay_port;
00976 }
00977
00978 bi = user_malloc(sizeof(struct bot_addr));
00979
00980 q = strchr(addr, ':');
00981 if (!q) {
00982 bi->address = user_malloc(strlen(addr) + 1);
00983 strcpy(bi->address, addr);
00984 bi->telnet_port = telnet_port;
00985 bi->relay_port = relay_port;
00986 } else {
00987 bi->address = user_malloc(q - addr + 1);
00988 strncpyz(bi->address, addr, q - addr + 1);
00989 p = q + 1;
00990 bi->telnet_port = atoi(p);
00991 q = strchr(p, '/');
00992 if (!q) {
00993 bi->relay_port = bi->telnet_port;
00994 } else {
00995 bi->relay_port = atoi(q + 1);
00996 }
00997 }
00998 set_user(&USERENTRY_BOTADDR, u1, bi);
00999 }
01000
01001 static void cmd_comment(struct userrec *u, int idx, char *par)
01002 {
01003 char *handle;
01004 struct userrec *u1;
01005
01006 handle = newsplit(&par);
01007 if (!par[0]) {
01008 dprintf(idx, "Usage: comment <handle> <newcomment>\n");
01009 return;
01010 }
01011 u1 = get_user_by_handle(userlist, handle);
01012 if (!u1) {
01013 dprintf(idx, "No such user!\n");
01014 return;
01015 }
01016 if ((u1->flags & USER_OWNER) && !(u && (u->flags & USER_OWNER)) &&
01017 egg_strcasecmp(handle, dcc[idx].nick)) {
01018 dprintf(idx, "You can't change comment on a bot owner.\n");
01019 return;
01020 }
01021 putlog(LOG_CMDS, "*", "#%s# comment %s %s", dcc[idx].nick, handle, par);
01022 if (!egg_strcasecmp(par, "none")) {
01023 dprintf(idx, "Okay, comment blanked.\n");
01024 set_user(&USERENTRY_COMMENT, u1, NULL);
01025 return;
01026 }
01027 dprintf(idx, "Changed comment.\n");
01028 set_user(&USERENTRY_COMMENT, u1, par);
01029 }
01030
01031 static void cmd_restart(struct userrec *u, int idx, char *par)
01032 {
01033 putlog(LOG_CMDS, "*", "#%s# restart", dcc[idx].nick);
01034 if (!backgrd) {
01035 dprintf(idx, "You cannot .restart a bot when running -n (due to Tcl).\n");
01036 return;
01037 }
01038 dprintf(idx, "Restarting.\n");
01039 if (make_userfile) {
01040 putlog(LOG_MISC, "*", "Uh, guess you don't need to create a new userfile.");
01041 make_userfile = 0;
01042 }
01043 write_userfile(-1);
01044 putlog(LOG_MISC, "*", "Restarting ...");
01045 wipe_timers(interp, &utimer);
01046 wipe_timers(interp, &timer);
01047 do_restart = idx;
01048 }
01049
01050 static void cmd_rehash(struct userrec *u, int idx, char *par)
01051 {
01052 putlog(LOG_CMDS, "*", "#%s# rehash", dcc[idx].nick);
01053 dprintf(idx, "Rehashing.\n");
01054 if (make_userfile) {
01055 putlog(LOG_MISC, "*", "Uh, guess you don't need to create a new userfile.");
01056 make_userfile = 0;
01057 }
01058 write_userfile(-1);
01059 putlog(LOG_MISC, "*", "Rehashing ...");
01060 do_restart = -2;
01061 }
01062
01063 static void cmd_reload(struct userrec *u, int idx, char *par)
01064 {
01065 putlog(LOG_CMDS, "*", "#%s# reload", dcc[idx].nick);
01066 dprintf(idx, "Reloading user file...\n");
01067 reload();
01068 }
01069
01070 void cmd_die(struct userrec *u, int idx, char *par)
01071 {
01072 char s1[1024], s2[1024];
01073
01074 putlog(LOG_CMDS, "*", "#%s# die %s", dcc[idx].nick, par);
01075 if (par[0]) {
01076 egg_snprintf(s1, sizeof s1, "BOT SHUTDOWN (%s: %s)", dcc[idx].nick, par);
01077 egg_snprintf(s2, sizeof s2, "DIE BY %s!%s (%s)", dcc[idx].nick,
01078 dcc[idx].host, par);
01079 strncpyz(quit_msg, par, 1024);
01080 } else {
01081 egg_snprintf(s1, sizeof s1, "BOT SHUTDOWN (Authorized by %s)",
01082 dcc[idx].nick);
01083 egg_snprintf(s2, sizeof s2, "DIE BY %s!%s (request)", dcc[idx].nick,
01084 dcc[idx].host);
01085 strncpyz(quit_msg, dcc[idx].nick, 1024);
01086 }
01087 kill_bot(s1, s2);
01088 }
01089
01090 static void cmd_debug(struct userrec *u, int idx, char *par)
01091 {
01092 if (!egg_strcasecmp(par, "help")) {
01093 putlog(LOG_CMDS, "*", "#%s# debug help", dcc[idx].nick);
01094 debug_help(idx);
01095 } else {
01096 putlog(LOG_CMDS, "*", "#%s# debug", dcc[idx].nick);
01097 debug_mem_to_dcc(idx);
01098 }
01099 }
01100
01101 static void cmd_simul(struct userrec *u, int idx, char *par)
01102 {
01103 char *nick;
01104 int i, ok = 0;
01105
01106 nick = newsplit(&par);
01107 if (!par[0]) {
01108 dprintf(idx, "Usage: simul <hand> <text>\n");
01109 return;
01110 }
01111 if (isowner(nick)) {
01112 dprintf(idx, "Unable to '.simul' permanent owners.\n");
01113 return;
01114 }
01115 for (i = 0; i < dcc_total; i++)
01116 if (!egg_strcasecmp(nick, dcc[i].nick) && !ok &&
01117 (dcc[i].type->flags & DCT_SIMUL)) {
01118 putlog(LOG_CMDS, "*", "#%s# simul %s %s", dcc[idx].nick, nick, par);
01119 if (dcc[i].type && dcc[i].type->activity) {
01120 dcc[i].type->activity(i, par, strlen(par));
01121 ok = 1;
01122 }
01123 }
01124 if (!ok)
01125 dprintf(idx, "No such user on the party line.\n");
01126 }
01127
01128 static void cmd_link(struct userrec *u, int idx, char *par)
01129 {
01130 char *s;
01131 int i;
01132
01133 if (!par[0]) {
01134 dprintf(idx, "Usage: link [some-bot] <new-bot>\n");
01135 return;
01136 }
01137 putlog(LOG_CMDS, "*", "#%s# link %s", dcc[idx].nick, par);
01138 s = newsplit(&par);
01139 if (!par[0] || !egg_strcasecmp(par, botnetnick))
01140 botlink(dcc[idx].nick, idx, s);
01141 else {
01142 char x[40];
01143
01144 i = nextbot(s);
01145 if (i < 0) {
01146 dprintf(idx, "No such bot online.\n");
01147 return;
01148 }
01149 simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
01150 botnet_send_link(i, x, s, par);
01151 }
01152 }
01153
01154 static void cmd_unlink(struct userrec *u, int idx, char *par)
01155 {
01156 int i;
01157 char *bot;
01158
01159 if (!par[0]) {
01160 dprintf(idx, "Usage: unlink <bot> [reason]\n");
01161 return;
01162 }
01163 putlog(LOG_CMDS, "*", "#%s# unlink %s", dcc[idx].nick, par);
01164 bot = newsplit(&par);
01165 i = nextbot(bot);
01166 if (i < 0) {
01167 botunlink(idx, bot, par, dcc[idx].nick);
01168 return;
01169 }
01170
01171
01172
01173 if (!egg_strcasecmp(dcc[i].nick, bot))
01174 botunlink(idx, bot, par, dcc[i].nick);
01175 else {
01176 char x[40];
01177
01178 simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
01179 botnet_send_unlink(i, x, lastbot(bot), bot, par);
01180 }
01181 }
01182
01183 static void cmd_relay(struct userrec *u, int idx, char *par)
01184 {
01185 if (!par[0]) {
01186 dprintf(idx, "Usage: relay <bot>\n");
01187 return;
01188 }
01189 putlog(LOG_CMDS, "*", "#%s# relay %s", dcc[idx].nick, par);
01190 tandem_relay(idx, par, 0);
01191 }
01192
01193 static void cmd_save(struct userrec *u, int idx, char *par)
01194 {
01195 putlog(LOG_CMDS, "*", "#%s# save", dcc[idx].nick);
01196 dprintf(idx, "Saving user file...\n");
01197 write_userfile(-1);
01198 }
01199
01200 static void cmd_backup(struct userrec *u, int idx, char *par)
01201 {
01202 putlog(LOG_CMDS, "*", "#%s# backup", dcc[idx].nick);
01203 dprintf(idx, "Backing up the channel & user files...\n");
01204 call_hook(HOOK_BACKUP);
01205 }
01206
01207 static void cmd_trace(struct userrec *u, int idx, char *par)
01208 {
01209 int i;
01210 char x[NOTENAMELEN + 11], y[11];
01211
01212 if (!par[0]) {
01213 dprintf(idx, "Usage: trace <botname>\n");
01214 return;
01215 }
01216 if (!egg_strcasecmp(par, botnetnick)) {
01217 dprintf(idx, "That's me! Hiya! :)\n");
01218 return;
01219 }
01220 i = nextbot(par);
01221 if (i < 0) {
01222 dprintf(idx, "Unreachable bot.\n");
01223 return;
01224 }
01225 putlog(LOG_CMDS, "*", "#%s# trace %s", dcc[idx].nick, par);
01226 simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
01227 simple_sprintf(y, ":%d", now);
01228 botnet_send_trace(i, x, par, y);
01229 }
01230
01231 static void cmd_binds(struct userrec *u, int idx, char *par)
01232 {
01233 putlog(LOG_CMDS, "*", "#%s# binds %s", dcc[idx].nick, par);
01234 tell_binds(idx, par);
01235 }
01236
01237 static void cmd_banner(struct userrec *u, int idx, char *par)
01238 {
01239 char s[1024];
01240 int i;
01241
01242 if (!par[0]) {
01243 dprintf(idx, "Usage: banner <message>\n");
01244 return;
01245 }
01246 simple_sprintf(s, "\007### Botwide: [%s] %s\n", dcc[idx].nick, par);
01247 for (i = 0; i < dcc_total; i++)
01248 if (dcc[i].type->flags & DCT_MASTER)
01249 dprintf(i, "%s", s);
01250 }
01251
01252
01253
01254
01255 int check_dcc_attrs(struct userrec *u, int oatr)
01256 {
01257 int i, stat;
01258 struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
01259
01260 if (!u)
01261 return 0;
01262
01263 if (isowner(u->handle)) {
01264 u->flags = sanity_check(u->flags | USER_OWNER);
01265 }
01266 for (i = 0; i < dcc_total; i++) {
01267 if ((dcc[i].type->flags & DCT_MASTER) &&
01268 (!egg_strcasecmp(u->handle, dcc[i].nick))) {
01269 stat = dcc[i].status;
01270 if ((dcc[i].type == &DCC_CHAT) &&
01271 ((u->flags & (USER_OP | USER_MASTER | USER_OWNER | USER_BOTMAST)) !=
01272 (oatr & (USER_OP | USER_MASTER | USER_OWNER | USER_BOTMAST)))) {
01273 botnet_send_join_idx(i, -1);
01274 }
01275 if ((oatr & USER_MASTER) && !(u->flags & USER_MASTER)) {
01276 dprintf(i, "*** POOF! ***\n");
01277 dprintf(i, "You are no longer a master on this bot.\n");
01278 }
01279 if (!(oatr & USER_MASTER) && (u->flags & USER_MASTER)) {
01280 dcc[i].u.chat->con_flags |= conmask;
01281 dprintf(i, "*** POOF! ***\n");
01282 dprintf(i, "You are now a master on this bot.\n");
01283 }
01284 if (!(oatr & USER_BOTMAST) && (u->flags & USER_BOTMAST)) {
01285 dprintf(i, "### POOF! ###\n");
01286 dprintf(i, "You are now a botnet master on this bot.\n");
01287 }
01288 if ((oatr & USER_BOTMAST) && !(u->flags & USER_BOTMAST)) {
01289 dprintf(i, "### POOF! ###\n");
01290 dprintf(i, "You are no longer a botnet master on this bot.\n");
01291 }
01292 if (!(oatr & USER_OWNER) && (u->flags & USER_OWNER)) {
01293 dprintf(i, "@@@ POOF! @@@\n");
01294 dprintf(i, "You are now an OWNER of this bot.\n");
01295 }
01296 if ((oatr & USER_OWNER) && !(u->flags & USER_OWNER)) {
01297 dprintf(i, "@@@ POOF! @@@\n");
01298 dprintf(i, "You are no longer an owner of this bot.\n");
01299 }
01300 get_user_flagrec(u, &fr, dcc[i].u.chat->con_chan);
01301 dcc[i].u.chat->con_flags = check_conflags(&fr,
01302 dcc[i].u.chat->con_flags);
01303 if ((stat & STAT_PARTY) && (u->flags & USER_OP))
01304 stat &= ~STAT_PARTY;
01305 if (!(stat & STAT_PARTY) && !(u->flags & USER_OP) &&
01306 !(u->flags & USER_MASTER))
01307 stat |= STAT_PARTY;
01308 if ((stat & STAT_CHAT) && !(u->flags & USER_PARTY) &&
01309 !(u->flags & USER_MASTER) && (!(u->flags & USER_OP) || require_p))
01310 stat &= ~STAT_CHAT;
01311 if ((dcc[i].type->flags & DCT_FILES) && !(stat & STAT_CHAT) &&
01312 ((u->flags & USER_MASTER) || (u->flags & USER_PARTY) ||
01313 ((u->flags & USER_OP) && !require_p)))
01314 stat |= STAT_CHAT;
01315 dcc[i].status = stat;
01316
01317
01318
01319
01320
01321 if ((dcc[i].type->flags & DCT_FILES) && !(u->flags & USER_XFER) &&
01322 !(u->flags & USER_MASTER)) {
01323 dprintf(i, "-+- POOF! -+-\n");
01324 dprintf(i, "You no longer have file area access.\n\n");
01325 putlog(LOG_MISC, "*", "DCC user [%s]%s removed from file system",
01326 dcc[i].nick, dcc[i].host);
01327 if (dcc[i].status & STAT_CHAT) {
01328 struct chat_info *ci;
01329
01330 ci = dcc[i].u.file->chat;
01331 nfree(dcc[i].u.file);
01332 dcc[i].u.chat = ci;
01333 dcc[i].status &= (~STAT_CHAT);
01334 dcc[i].type = &DCC_CHAT;
01335 if (dcc[i].u.chat->channel >= 0) {
01336 chanout_but(-1, dcc[i].u.chat->channel,
01337 "*** %s has returned.\n", dcc[i].nick);
01338 if (dcc[i].u.chat->channel < GLOBAL_CHANS)
01339 botnet_send_join_idx(i, -1);
01340 }
01341 } else {
01342 killsock(dcc[i].sock);
01343 lostdcc(i);
01344 }
01345 }
01346 }
01347
01348 if (dcc[i].type == &DCC_BOT && !egg_strcasecmp(u->handle, dcc[i].nick)) {
01349 if ((dcc[i].status & STAT_LEAF) && !(bot_flags(u) & BOT_LEAF))
01350 dcc[i].status &= ~(STAT_LEAF | STAT_WARNED);
01351 if (!(dcc[i].status & STAT_LEAF) && (bot_flags(u) & BOT_LEAF))
01352 dcc[i].status |= STAT_LEAF;
01353 }
01354 }
01355
01356 return u->flags;
01357 }
01358
01359 int check_dcc_chanattrs(struct userrec *u, char *chname, int chflags,
01360 int ochatr)
01361 {
01362 int i, found = 0;
01363 struct flag_record fr = { FR_CHAN, 0, 0, 0, 0, 0 };
01364 struct chanset_t *chan;
01365
01366 if (!u)
01367 return 0;
01368 for (i = 0; i < dcc_total; i++) {
01369 if ((dcc[i].type->flags & DCT_MASTER) &&
01370 !egg_strcasecmp(u->handle, dcc[i].nick)) {
01371 if ((dcc[i].type == &DCC_CHAT) &&
01372 ((chflags & (USER_OP | USER_MASTER | USER_OWNER)) !=
01373 (ochatr & (USER_OP | USER_MASTER | USER_OWNER))))
01374 botnet_send_join_idx(i, -1);
01375 if ((ochatr & USER_MASTER) && !(chflags & USER_MASTER)) {
01376 dprintf(i, "*** POOF! ***\n");
01377 dprintf(i, "You are no longer a master on %s.\n", chname);
01378 }
01379 if (!(ochatr & USER_MASTER) && (chflags & USER_MASTER)) {
01380 dcc[i].u.chat->con_flags |= conmask;
01381 dprintf(i, "*** POOF! ***\n");
01382 dprintf(i, "You are now a master on %s.\n", chname);
01383 }
01384 if (!(ochatr & USER_OWNER) && (chflags & USER_OWNER)) {
01385 dprintf(i, "@@@ POOF! @@@\n");
01386 dprintf(i, "You are now an OWNER of %s.\n", chname);
01387 }
01388 if ((ochatr & USER_OWNER) && !(chflags & USER_OWNER)) {
01389 dprintf(i, "@@@ POOF! @@@\n");
01390 dprintf(i, "You are no longer an owner of %s.\n", chname);
01391 }
01392 if (((ochatr & (USER_OP | USER_MASTER | USER_OWNER)) &&
01393 (!(chflags & (USER_OP | USER_MASTER | USER_OWNER)))) ||
01394 ((chflags & (USER_OP | USER_MASTER | USER_OWNER)) &&
01395 (!(ochatr & (USER_OP | USER_MASTER | USER_OWNER))))) {
01396
01397 for (chan = chanset; chan && !found; chan = chan->next) {
01398 get_user_flagrec(u, &fr, chan->dname);
01399 if (fr.chan & (USER_OP | USER_MASTER | USER_OWNER))
01400 found = 1;
01401 }
01402 if (!chan)
01403 chan = chanset;
01404 if (chan)
01405 strcpy(dcc[i].u.chat->con_chan, chan->dname);
01406 else
01407 strcpy(dcc[i].u.chat->con_chan, "*");
01408 }
01409 fr.match = (FR_CHAN | FR_GLOBAL);
01410 get_user_flagrec(u, &fr, dcc[i].u.chat->con_chan);
01411 dcc[i].u.chat->con_flags = check_conflags(&fr,
01412 dcc[i].u.chat->con_flags);
01413 }
01414 }
01415 return chflags;
01416 }
01417
01418 static void cmd_chattr(struct userrec *u, int idx, char *par)
01419 {
01420 char *hand, *arg = NULL, *tmpchg = NULL, *chg = NULL, work[1024];
01421 struct chanset_t *chan = NULL;
01422 struct userrec *u2;
01423 struct flag_record pls = { 0, 0, 0, 0, 0, 0 },
01424 mns = { 0, 0, 0, 0, 0, 0 },
01425 user = { 0, 0, 0, 0, 0, 0 };
01426 module_entry *me;
01427 int fl = -1, of = 0, ocf = 0;
01428
01429 if (!par[0]) {
01430 dprintf(idx, "Usage: chattr <handle> [changes] [channel]\n");
01431 return;
01432 }
01433 hand = newsplit(&par);
01434 u2 = get_user_by_handle(userlist, hand);
01435 if (!u2) {
01436 dprintf(idx, "No such user!\n");
01437 return;
01438 }
01439
01440
01441 if (par[0]) {
01442 arg = newsplit(&par);
01443 if (par[0]) {
01444
01445 chg = arg;
01446 arg = newsplit(&par);
01447 chan = findchan_by_dname(arg);
01448 } else {
01449 chan = findchan_by_dname(arg);
01450
01451 if (!(arg[0] == '+' && chan) &&
01452 !(arg[0] != '+' && strchr(CHANMETA, arg[0]))) {
01453
01454 chg = arg;
01455 chan = NULL;
01456 arg = NULL;
01457 }
01458
01459 }
01460 }
01461
01462
01463
01464
01465 Assert(!(!arg && chan));
01466 if (arg && !chan) {
01467 dprintf(idx, "No channel record for %s.\n", arg);
01468 return;
01469 }
01470 if (chg) {
01471 if (!arg && strpbrk(chg, "&|")) {
01472
01473 if (!strcmp((arg = dcc[idx].u.chat->con_chan), "*"))
01474 arg = NULL;
01475 else
01476 chan = findchan_by_dname(arg);
01477 if (arg && !chan) {
01478 dprintf(idx, "Invalid console channel %s.\n", arg);
01479 return;
01480 }
01481 } else if (arg && !strpbrk(chg, "&|")) {
01482 tmpchg = nmalloc(strlen(chg) + 2);
01483 strcpy(tmpchg, "|");
01484 strcat(tmpchg, chg);
01485 chg = tmpchg;
01486 }
01487 }
01488 par = arg;
01489 user.match = FR_GLOBAL;
01490 if (chan)
01491 user.match |= FR_CHAN;
01492 get_user_flagrec(u, &user, chan ? chan->dname : 0);
01493 if (!chan && !glob_botmast(user)) {
01494 dprintf(idx, "You do not have Bot Master privileges.\n");
01495 if (tmpchg)
01496 nfree(tmpchg);
01497 return;
01498 }
01499 if (chan && !glob_master(user) && !chan_master(user)) {
01500 dprintf(idx, "You do not have channel master privileges for channel %s.\n",
01501 par);
01502 if (tmpchg)
01503 nfree(tmpchg);
01504 return;
01505 }
01506 user.match &= fl;
01507 if (chg) {
01508 pls.match = user.match;
01509 break_down_flags(chg, &pls, &mns);
01510
01511 pls.global &=~(USER_BOT);
01512 mns.global &=~(USER_BOT);
01513
01514 if (chan) {
01515 pls.chan &= ~(BOT_SHARE);
01516 mns.chan &= ~(BOT_SHARE);
01517 }
01518 if (!glob_owner(user)) {
01519 pls.global &=~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
01520 mns.global &=~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
01521
01522 if (chan) {
01523 pls.chan &= ~USER_OWNER;
01524 mns.chan &= ~USER_OWNER;
01525 }
01526 if (!glob_master(user)) {
01527 pls.global &=USER_PARTY | USER_XFER;
01528 mns.global &=USER_PARTY | USER_XFER;
01529
01530 if (!glob_botmast(user)) {
01531 pls.global = 0;
01532 mns.global = 0;
01533 }
01534 }
01535 }
01536 if (chan && !chan_owner(user) && !glob_owner(user)) {
01537 pls.chan &= ~USER_MASTER;
01538 mns.chan &= ~USER_MASTER;
01539 if (!chan_master(user) && !glob_master(user)) {
01540 pls.chan = 0;
01541 mns.chan = 0;
01542 }
01543 }
01544 get_user_flagrec(u2, &user, par);
01545 if (user.match & FR_GLOBAL) {
01546 of = user.global;
01547 user.global = sanity_check((user.global |pls.global) &~mns.global);
01548
01549 user.udef_global = (user.udef_global | pls.udef_global)
01550 & ~mns.udef_global;
01551 }
01552 if (chan) {
01553 ocf = user.chan;
01554 user.chan = chan_sanity_check((user.chan | pls.chan) & ~mns.chan,
01555 user.global);
01556
01557 user.udef_chan = (user.udef_chan | pls.udef_chan) & ~mns.udef_chan;
01558 }
01559 set_user_flagrec(u2, &user, par);
01560 }
01561 if (chan)
01562 putlog(LOG_CMDS, "*", "#%s# (%s) chattr %s %s",
01563 dcc[idx].nick, chan ? chan->dname : "*", hand, chg ? chg : "");
01564 else
01565 putlog(LOG_CMDS, "*", "#%s# chattr %s %s", dcc[idx].nick, hand,
01566 chg ? chg : "");
01567
01568 if (user.match & FR_GLOBAL) {
01569 user.match = FR_GLOBAL;
01570 if (chg)
01571 check_dcc_attrs(u2, of);
01572 get_user_flagrec(u2, &user, NULL);
01573 build_flags(work, &user, NULL);
01574 if (work[0] != '-')
01575 dprintf(idx, "Global flags for %s are now +%s.\n", hand, work);
01576 else
01577 dprintf(idx, "No global flags for %s.\n", hand);
01578 }
01579 if (chan) {
01580 user.match = FR_CHAN;
01581 get_user_flagrec(u2, &user, par);
01582 user.chan &= ~BOT_SHARE;
01583 if (chg)
01584 check_dcc_chanattrs(u2, chan->dname, user.chan, ocf);
01585 build_flags(work, &user, NULL);
01586 if (work[0] != '-')
01587 dprintf(idx, "Channel flags for %s on %s are now +%s.\n", hand,
01588 chan->dname, work);
01589 else
01590 dprintf(idx, "No flags for %s on %s.\n", hand, chan->dname);
01591 }
01592 if (chg && (me = module_find("irc", 0, 0))) {
01593 Function *func = me->funcs;
01594 (func[IRC_CHECK_THIS_USER]) (hand, 0, NULL);
01595 }
01596 if (tmpchg)
01597 nfree(tmpchg);
01598 }
01599
01600 static void cmd_botattr(struct userrec *u, int idx, char *par)
01601 {
01602 char *hand, *chg = NULL, *arg = NULL, *tmpchg = NULL, work[1024];
01603 struct chanset_t *chan = NULL;
01604 struct userrec *u2;
01605 struct flag_record pls = { 0, 0, 0, 0, 0, 0 },
01606 mns = { 0, 0, 0, 0, 0, 0 },
01607 user = { 0, 0, 0, 0, 0, 0 };
01608 int idx2;
01609
01610 if (!par[0]) {
01611 dprintf(idx, "Usage: botattr <handle> [changes] [channel]\n");
01612 return;
01613 }
01614 hand = newsplit(&par);
01615 u2 = get_user_by_handle(userlist, hand);
01616 if (!u2 || !(u2->flags & USER_BOT)) {
01617 dprintf(idx, "No such bot!\n");
01618 return;
01619 }
01620 for (idx2 = 0; idx2 < dcc_total; idx2++)
01621 if (dcc[idx2].type != &DCC_RELAY && dcc[idx2].type != &DCC_FORK_BOT &&
01622 !egg_strcasecmp(dcc[idx2].nick, hand))
01623 break;
01624 if (idx2 != dcc_total) {
01625 dprintf(idx,
01626 "You may not change the attributes of a directly linked bot.\n");
01627 return;
01628 }
01629
01630 if (par[0]) {
01631 arg = newsplit(&par);
01632 if (par[0]) {
01633
01634 chg = arg;
01635 arg = newsplit(&par);
01636 chan = findchan_by_dname(arg);
01637 } else {
01638 chan = findchan_by_dname(arg);
01639
01640 if (!(arg[0] == '+' && chan) &&
01641 !(arg[0] != '+' && strchr(CHANMETA, arg[0]))) {
01642
01643 chg = arg;
01644 chan = NULL;
01645 arg = NULL;
01646 }
01647
01648 }
01649 }
01650
01651
01652
01653
01654 Assert(!(!arg && chan));
01655 if (arg && !chan) {
01656 dprintf(idx, "No channel record for %s.\n", arg);
01657 return;
01658 }
01659 if (chg) {
01660 if (!arg && strpbrk(chg, "&|")) {
01661
01662 if (!strcmp((arg = dcc[idx].u.chat->con_chan), "*"))
01663 arg = NULL;
01664 else
01665 chan = findchan_by_dname(arg);
01666 if (arg && !chan) {
01667 dprintf(idx, "Invalid console channel %s.\n", arg);
01668 return;
01669 }
01670 } else if (arg && !strpbrk(chg, "&|")) {
01671 tmpchg = nmalloc(strlen(chg) + 2);
01672 strcpy(tmpchg, "|");
01673 strcat(tmpchg, chg);
01674 chg = tmpchg;
01675 }
01676 }
01677 par = arg;
01678
01679 user.match = FR_GLOBAL;
01680 get_user_flagrec(u, &user, chan ? chan->dname : 0);
01681 if (!glob_botmast(user)) {
01682 dprintf(idx, "You do not have Bot Master privileges.\n");
01683 if (tmpchg)
01684 nfree(tmpchg);
01685 return;
01686 }
01687 if (chg) {
01688 user.match = FR_BOT | (chan ? FR_CHAN : 0);
01689 pls.match = user.match;
01690 break_down_flags(chg, &pls, &mns);
01691
01692 pls.global &=~BOT_BOT;
01693 mns.global &=~BOT_BOT;
01694
01695 if (chan && glob_owner(user)) {
01696 pls.chan &= BOT_SHARE;
01697 mns.chan &= BOT_SHARE;
01698 } else {
01699 pls.chan = 0;
01700 mns.chan = 0;
01701 }
01702 if (!glob_owner(user)) {
01703 pls.bot &= ~(BOT_SHARE | BOT_GLOBAL);
01704 mns.bot &= ~(BOT_SHARE | BOT_GLOBAL);
01705 }
01706 user.match = FR_BOT | (chan ? FR_CHAN : 0);
01707 get_user_flagrec(u2, &user, par);
01708 user.bot = (user.bot | pls.bot) & ~mns.bot;
01709 if ((user.bot & BOT_SHARE) == BOT_SHARE)
01710 user.bot &= ~BOT_SHARE;
01711 if (chan)
01712 user.chan = (user.chan | pls.chan) & ~mns.chan;
01713 set_user_flagrec(u2, &user, par);
01714 }
01715 if (chan)
01716 putlog(LOG_CMDS, "*", "#%s# (%s) botattr %s %s",
01717 dcc[idx].nick, chan->dname, hand, chg ? chg : "");
01718 else
01719 putlog(LOG_CMDS, "*", "#%s# botattr %s %s", dcc[idx].nick, hand,
01720 chg ? chg : "");
01721
01722 if (!chan || pls.bot || mns.bot) {
01723 user.match = FR_BOT;
01724 get_user_flagrec(u2, &user, NULL);
01725 build_flags(work, &user, NULL);
01726 if (work[0] != '-')
01727 dprintf(idx, "Bot flags for %s are now +%s.\n", hand, work);
01728 else
01729 dprintf(idx, "There are no bot flags for %s.\n", hand);
01730 }
01731 if (chan) {
01732 user.match = FR_CHAN;
01733 get_user_flagrec(u2, &user, par);
01734 user.chan &= BOT_SHARE;
01735 user.udef_chan = 0;
01736 build_flags(work, &user, NULL);
01737 if (work[0] != '-')
01738 dprintf(idx, "Bot flags for %s on %s are now +%s.\n", hand,
01739 chan->dname, work);
01740 else
01741 dprintf(idx, "There are no bot flags for %s on %s.\n", hand, chan->dname);
01742 }
01743 if (tmpchg)
01744 nfree(tmpchg);
01745 }
01746
01747 static void cmd_chat(struct userrec *u, int idx, char *par)
01748 {
01749 char *arg;
01750 int newchan, oldchan;
01751 module_entry *me;
01752
01753 arg = newsplit(&par);
01754 if (!egg_strcasecmp(arg, "off")) {
01755
01756 if (dcc[idx].u.chat->channel < 0) {
01757 dprintf(idx, "You weren't in chat anyway!\n");
01758 return;
01759 } else {
01760 dprintf(idx, "Leaving chat mode...\n");
01761 check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
01762 dcc[idx].u.chat->channel);
01763 chanout_but(-1, dcc[idx].u.chat->channel,
01764 "*** %s left the party line.\n", dcc[idx].nick);
01765 if (dcc[idx].u.chat->channel < GLOBAL_CHANS)
01766 botnet_send_part_idx(idx, "");
01767 }
01768 dcc[idx].u.chat->channel = -1;
01769 } else {
01770 if (arg[0] == '*') {
01771 if (((arg[1] < '0') || (arg[1] > '9'))) {
01772 if (!arg[1])
01773 newchan = 0;
01774 else {
01775 Tcl_SetVar(interp, "_chan", arg, 0);
01776 if ((Tcl_VarEval(interp, "assoc ", "$_chan", NULL) == TCL_OK) &&
01777 !tcl_resultempty())
01778 newchan = tcl_resultint();
01779 else
01780 newchan = -1;
01781 }
01782 if (newchan < 0) {
01783 dprintf(idx, "No channel exists by that name.\n");
01784 return;
01785 }
01786 } else
01787 newchan = GLOBAL_CHANS + atoi(arg + 1);
01788 if (newchan < GLOBAL_CHANS || newchan > 199999) {
01789 dprintf(idx, "Channel number out of range: local channels must be "
01790 "*0-*99999.\n");
01791 return;
01792 }
01793 } else {
01794 if (((arg[0] < '0') || (arg[0] > '9')) && (arg[0])) {
01795 if (!egg_strcasecmp(arg, "on"))
01796 newchan = 0;
01797 else {
01798 Tcl_SetVar(interp, "_chan", arg, 0);
01799 if ((Tcl_VarEval(interp, "assoc ", "$_chan", NULL) == TCL_OK) &&
01800 !tcl_resultempty())
01801 newchan = tcl_resultint();
01802 else
01803 newchan = -1;
01804 }
01805 if (newchan < 0) {
01806 dprintf(idx, "No channel exists by that name.\n");
01807 return;
01808 }
01809 } else
01810 newchan = atoi(arg);
01811 if ((newchan < 0) || (newchan >= GLOBAL_CHANS)) {
01812 dprintf(idx, "Channel number out of range: must be between 0 and %d."
01813 "\n", GLOBAL_CHANS);
01814 return;
01815 }
01816 }
01817
01818
01819
01820 if ((dcc[idx].u.chat->channel < 0) && (dcc[idx].u.chat->away != NULL))
01821 not_away(idx);
01822 if (dcc[idx].u.chat->channel == newchan) {
01823 if (!newchan) {
01824 dprintf(idx, "You're already on the party line!\n");
01825 return;
01826 } else {
01827 dprintf(idx, "You're already on channel %s%d!\n",
01828 (newchan < GLOBAL_CHANS) ? "" : "*", newchan % GLOBAL_CHANS);
01829 return;
01830 }
01831 } else {
01832 oldchan = dcc[idx].u.chat->channel;
01833 if (oldchan >= 0)
01834 check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock, oldchan);
01835 if (!oldchan)
01836 chanout_but(-1, 0, "*** %s left the party line.\n", dcc[idx].nick);
01837 else if (oldchan > 0)
01838 chanout_but(-1, oldchan, "*** %s left the channel.\n", dcc[idx].nick);
01839 dcc[idx].u.chat->channel = newchan;
01840 if (!newchan) {
01841 dprintf(idx, "Entering the party line...\n");
01842 chanout_but(-1, 0, "*** %s joined the party line.\n", dcc[idx].nick);
01843 } else {
01844 dprintf(idx, "Joining channel '%s'...\n", arg);
01845 chanout_but(-1, newchan, "*** %s joined the channel.\n", dcc[idx].nick);
01846 }
01847 check_tcl_chjn(botnetnick, dcc[idx].nick, newchan, geticon(idx),
01848 dcc[idx].sock, dcc[idx].host);
01849 if (newchan < GLOBAL_CHANS)
01850 botnet_send_join_idx(idx, oldchan);
01851 else if (oldchan < GLOBAL_CHANS)
01852 botnet_send_part_idx(idx, "");
01853 }
01854 }
01855
01856 if ((me = module_find("console", 1, 1))) {
01857 Function *func = me->funcs;
01858
01859 (func[CONSOLE_DOSTORE]) (idx);
01860 }
01861 }
01862
01863 static void cmd_echo(struct userrec *u, int idx, char *par)
01864 {
01865 module_entry *me;
01866
01867 if (!par[0]) {
01868 dprintf(idx, "Echo is currently %s.\n", dcc[idx].status & STAT_ECHO ?
01869 "on" : "off");
01870 return;
01871 }
01872 if (!egg_strcasecmp(par, "on")) {
01873 dprintf(idx, "Echo turned on.\n");
01874 dcc[idx].status |= STAT_ECHO;
01875 } else if (!egg_strcasecmp(par, "off")) {
01876 dprintf(idx, "Echo turned off.\n");
01877 dcc[idx].status &= ~STAT_ECHO;
01878 } else {
01879 dprintf(idx, "Usage: echo <on/off>\n");
01880 return;
01881 }
01882
01883 if ((me = module_find("console", 1, 1))) {
01884 Function *func = me->funcs;
01885
01886 (func[CONSOLE_DOSTORE]) (idx);
01887 }
01888 }
01889
01890 int stripmodes(char *s)
01891 {
01892 int res = 0;
01893
01894 for (; *s; s++)
01895 switch (tolower((unsigned) *s)) {
01896 case 'b':
01897 res |= STRIP_BOLD;
01898 break;
01899 case 'c':
01900 res |= STRIP_COLOR;
01901 break;
01902 case 'r':
01903 res |= STRIP_REV;
01904 break;
01905 case 'u':
01906 res |= STRIP_UNDER;
01907 break;
01908 case 'a':
01909 res |= STRIP_ANSI;
01910 break;
01911 case 'g':
01912 res |= STRIP_BELLS;
01913 break;
01914 case '*':
01915 res |= STRIP_ALL;
01916 break;
01917 }
01918 return res;
01919 }
01920
01921 char *stripmasktype(int x)
01922 {
01923 static char s[20];
01924 char *p = s;
01925
01926 if (x & STRIP_BOLD)
01927 *p++ = 'b';
01928 if (x & STRIP_COLOR)
01929 *p++ = 'c';
01930 if (x & STRIP_REV)
01931 *p++ = 'r';
01932 if (x & STRIP_UNDER)
01933 *p++ = 'u';
01934 if (x & STRIP_ANSI)
01935 *p++ = 'a';
01936 if (x & STRIP_BELLS)
01937 *p++ = 'g';
01938 if (p == s)
01939 *p++ = '-';
01940 *p = 0;
01941 return s;
01942 }
01943
01944 static char *stripmaskname(int x)
01945 {
01946 static char s[161];
01947 int i = 0;
01948
01949 s[i] = 0;
01950 if (x & STRIP_BOLD)
01951 i += my_strcpy(s + i, "bold, ");
01952 if (x & STRIP_COLOR)
01953 i += my_strcpy(s + i, "color, ");
01954 if (x & STRIP_REV)
01955 i += my_strcpy(s + i, "reverse, ");
01956 if (x & STRIP_UNDER)
01957 i += my_strcpy(s + i, "underline, ");
01958 if (x & STRIP_ANSI)
01959 i += my_strcpy(s + i, "ansi, ");
01960 if (x & STRIP_BELLS)
01961 i += my_strcpy(s + i, "bells, ");
01962 if (!i)
01963 strcpy(s, "none");
01964 else
01965 s[i - 2] = 0;
01966 return s;
01967 }
01968
01969 static void cmd_strip(struct userrec *u, int idx, char *par)
01970 {
01971 char *nick, *changes, *c, s[2];
01972 int dest = 0, i, pls, md, ok = 0;
01973 module_entry *me;
01974
01975 if (!par[0]) {
01976 dprintf(idx, "Your current strip settings are: %s (%s).\n",
01977 stripmasktype(dcc[idx].u.chat->strip_flags),
01978 stripmaskname(dcc[idx].u.chat->strip_flags));
01979 return;
01980 }
01981 nick = newsplit(&par);
01982 if ((nick[0] != '+') && (nick[0] != '-') && u && (u->flags & USER_MASTER)) {
01983 for (i = 0; i < dcc_total; i++)
01984 if (!egg_strcasecmp(nick, dcc[i].nick) && dcc[i].type == &DCC_CHAT && !ok) {
01985 ok = 1;
01986 dest = i;
01987 }
01988 if (!ok) {
01989 dprintf(idx, "No such user on the party line!\n");
01990 return;
01991 }
01992 changes = par;
01993 } else {
01994 changes = nick;
01995 nick = "";
01996 dest = idx;
01997 }
01998 c = changes;
01999 if ((c[0] != '+') && (c[0] != '-'))
02000 dcc[dest].u.chat->strip_flags = 0;
02001 s[1] = 0;
02002 for (pls = 1; *c; c++) {
02003 switch (*c) {
02004 case '+':
02005 pls = 1;
02006 break;
02007 case '-':
02008 pls = 0;
02009 break;
02010 default:
02011 s[0] = *c;
02012 md = stripmodes(s);
02013 if (pls == 1)
02014 dcc[dest].u.chat->strip_flags |= md;
02015 else
02016 dcc[dest].u.chat->strip_flags &= ~md;
02017 }
02018 }
02019 if (nick[0])
02020 putlog(LOG_CMDS, "*", "#%s# strip %s %s", dcc[idx].nick, nick, changes);
02021 else
02022 putlog(LOG_CMDS, "*", "#%s# strip %s", dcc[idx].nick, changes);
02023 if (dest == idx) {
02024 dprintf(idx, "Your strip settings are: %s (%s).\n",
02025 stripmasktype(dcc[idx].u.chat->strip_flags),
02026 stripmaskname(dcc[idx].u.chat->strip_flags));
02027 } else {
02028 dprintf(idx, "Strip setting for %s: %s (%s).\n", dcc[dest].nick,
02029 stripmasktype(dcc[dest].u.chat->strip_flags),
02030 stripmaskname(dcc[dest].u.chat->strip_flags));
02031 dprintf(dest, "%s set your strip settings to: %s (%s).\n", dcc[idx].nick,
02032 stripmasktype(dcc[dest].u.chat->strip_flags),
02033 stripmaskname(dcc[dest].u.chat->strip_flags));
02034 }
02035
02036
02037
02038 if (dcc[dest].u.chat->strip_flags & STRIP_BOLD && u->flags & USER_HIGHLITE) {
02039 u->flags &= ~USER_HIGHLITE;
02040 } else if (!(dcc[dest].u.chat->strip_flags & STRIP_BOLD) &&
02041 !(u->flags & USER_HIGHLITE)) {
02042 u->flags |= USER_HIGHLITE;
02043 }
02044
02045 if ((me = module_find("console", 1, 1))) {
02046 Function *func = me->funcs;
02047
02048 (func[CONSOLE_DOSTORE]) (dest);
02049 }
02050 }
02051
02052 static void cmd_su(struct userrec *u, int idx, char *par)
02053 {
02054 int atr = u ? u->flags : 0;
02055 struct flag_record fr = { FR_ANYWH | FR_CHAN | FR_GLOBAL, 0, 0, 0, 0, 0 };
02056
02057 u = get_user_by_handle(userlist, par);
02058
02059 if (!par[0])
02060 dprintf(idx, "Usage: su <user>\n");
02061 else if (!u)
02062 dprintf(idx, "No such user.\n");
02063 else if (u->flags & USER_BOT)
02064 dprintf(idx, "You can't su to a bot... then again, why would you wanna?\n");
02065 else if (dcc[idx].u.chat->su_nick)
02066 dprintf(idx, "You cannot currently double .su; try .su'ing directly.\n");
02067 else {
02068 get_user_flagrec(u, &fr, NULL);
02069 if ((!glob_party(fr) && (require_p || !(glob_op(fr) || chan_op(fr)))) &&
02070 !(atr & USER_BOTMAST))
02071 dprintf(idx, "No party line access permitted for %s.\n", par);
02072 else {
02073 correct_handle(par);
02074 putlog(LOG_CMDS, "*", "#%s# su %s", dcc[idx].nick, par);
02075 if (!(atr & USER_OWNER) || ((u->flags & USER_OWNER) && (isowner(par)) &&
02076 !(isowner(dcc[idx].nick)))) {
02077
02078 if (u_pass_match(u, "-")) {
02079 dprintf(idx, "No password set for user. You may not .su to them.\n");
02080 return;
02081 }
02082 if (dcc[idx].u.chat->channel < GLOBAL_CHANS)
02083 botnet_send_part_idx(idx, "");
02084 chanout_but(-1, dcc[idx].u.chat->channel,
02085 "*** %s left the party line.\n", dcc[idx].nick);
02086
02087
02088
02089 if (dcc[idx].u.chat->away != NULL)
02090 nfree(dcc[idx].u.chat->away);
02091 dcc[idx].u.chat->away = get_data_ptr(strlen(dcc[idx].nick) + 1);
02092 strcpy(dcc[idx].u.chat->away, dcc[idx].nick);
02093 dcc[idx].u.chat->su_nick = get_data_ptr(strlen(dcc[idx].nick) + 1);
02094 strcpy(dcc[idx].u.chat->su_nick, dcc[idx].nick);
02095 dcc[idx].user = u;
02096 strcpy(dcc[idx].nick, par);
02097
02098 dprintf(idx, "Enter password for %s%s\n", par,
02099 (dcc[idx].status & STAT_TELNET) ? TLN_IAC_C TLN_WILL_C
02100 TLN_ECHO_C : "");
02101 dcc[idx].type = &DCC_CHAT_PASS;
02102 } else if (atr & USER_OWNER) {
02103 if (dcc[idx].u.chat->channel < GLOBAL_CHANS)
02104 botnet_send_part_idx(idx, "");
02105 chanout_but(-1, dcc[idx].u.chat->channel,
02106 "*** %s left the party line.\n", dcc[idx].nick);
02107 dprintf(idx, "Setting your username to %s.\n", par);
02108 if (atr & USER_MASTER)
02109 dcc[idx].u.chat->con_flags = conmask;
02110 dcc[idx].u.chat->su_nick = get_data_ptr(strlen(dcc[idx].nick) + 1);
02111 strcpy(dcc[idx].u.chat->su_nick, dcc[idx].nick);
02112 dcc[idx].user = u;
02113 strcpy(dcc[idx].nick, par);
02114 dcc_chatter(idx);
02115 }
02116 }
02117 }
02118 }
02119
02120 static void cmd_fixcodes(struct userrec *u, int idx, char *par)
02121 {
02122 if (dcc[idx].status & STAT_TELNET) {
02123 dcc[idx].status |= STAT_ECHO;
02124 dcc[idx].status &= ~STAT_TELNET;
02125 dprintf(idx, "Turned off telnet codes.\n");
02126 putlog(LOG_CMDS, "*", "#%s# fixcodes (telnet off)", dcc[idx].nick);
02127 } else {
02128 dcc[idx].status |= STAT_TELNET;
02129 dcc[idx].status &= ~STAT_ECHO;
02130 dprintf(idx, "Turned on telnet codes.\n");
02131 putlog(LOG_CMDS, "*", "#%s# fixcodes (telnet on)", dcc[idx].nick);
02132 }
02133 }
02134
02135 static void cmd_page(struct userrec *u, int idx, char *par)
02136 {
02137 int a;
02138 module_entry *me;
02139
02140 if (!par[0]) {
02141 if (dcc[idx].status & STAT_PAGE) {
02142 dprintf(idx, "Currently paging outputs to %d lines.\n",
02143 dcc[idx].u.chat->max_line);
02144 } else
02145 dprintf(idx, "You don't have paging on.\n");
02146 return;
02147 }
02148 a = atoi(par);
02149 if ((!a && !par[0]) || !egg_strcasecmp(par, "off")) {
02150 dcc[idx].status &= ~STAT_PAGE;
02151 dcc[idx].u.chat->max_line = 0x7ffffff;
02152 while (dcc[idx].u.chat->buffer)
02153 flush_lines(idx, dcc[idx].u.chat);
02154 dprintf(idx, "Paging turned off.\n");
02155 putlog(LOG_CMDS, "*", "#%s# page off", dcc[idx].nick);
02156 } else if (a > 0) {
02157 dprintf(idx, "Paging turned on, stopping every %d line%s.\n", a,
02158 (a != 1) ? "s" : "");
02159 dcc[idx].status |= STAT_PAGE;
02160 dcc[idx].u.chat->max_line = a;
02161 dcc[idx].u.chat->line_count = 0;
02162 dcc[idx].u.chat->current_lines = 0;
02163 putlog(LOG_CMDS, "*", "#%s# page %d", dcc[idx].nick, a);
02164 } else {
02165 dprintf(idx, "Usage: page <off or #>\n");
02166 return;
02167 }
02168
02169 if ((me = module_find("console", 1, 1))) {
02170 Function *func = me->funcs;
02171
02172 (func[CONSOLE_DOSTORE]) (idx);
02173 }
02174 }
02175
02176
02177
02178 static void cmd_tcl(struct userrec *u, int idx, char *msg)
02179 {
02180 int code;
02181 char *result;
02182 #ifdef USE_TCL_ENCODING
02183 Tcl_DString dstr;
02184 #endif
02185
02186 if (!(isowner(dcc[idx].nick)) && (must_be_owner)) {
02187 dprintf(idx, MISC_NOSUCHCMD);
02188 return;
02189 }
02190 debug1("tcl: evaluate (.tcl): %s", msg);
02191 code = Tcl_GlobalEval(interp, msg);
02192
02193 #ifdef USE_TCL_ENCODING
02194
02195 Tcl_DStringInit(&dstr);
02196 Tcl_UtfToExternalDString(NULL, tcl_resultstring(), -1, &dstr);
02197 result = Tcl_DStringValue(&dstr);
02198 #else
02199
02200 result = tcl_resultstring();
02201 #endif
02202
02203 if (code == TCL_OK)
02204 dumplots(idx, "Tcl: ", result);
02205 else
02206 dumplots(idx, "Tcl error: ", result);
02207
02208 #ifdef USE_TCL_ENCODING
02209 Tcl_DStringFree(&dstr);
02210 #endif
02211 }
02212
02213
02214
02215 static void cmd_set(struct userrec *u, int idx, char *msg)
02216 {
02217 int code;
02218 char s[512], *result;
02219 #ifdef USE_TCL_ENCODING
02220 Tcl_DString dstr;
02221 #endif
02222
02223 if (!(isowner(dcc[idx].nick)) && (must_be_owner)) {
02224 dprintf(idx, MISC_NOSUCHCMD);
02225 return;
02226 }
02227 putlog(LOG_CMDS, "*", "#%s# set %s", dcc[idx].nick, msg);
02228 strcpy(s, "set ");
02229 if (!msg[0]) {
02230 strcpy(s, "info globals");
02231 Tcl_Eval(interp, s);
02232 dumplots(idx, "Global vars: ", tcl_resultstring());
02233 return;
02234 }
02235 strcpy(s + 4, msg);
02236 code = Tcl_Eval(interp, s);
02237
02238 #ifdef USE_TCL_ENCODING
02239
02240 Tcl_DStringInit(&dstr);
02241 Tcl_UtfToExternalDString(NULL, tcl_resultstring(), -1, &dstr);
02242 result = Tcl_DStringValue(&dstr);
02243 #else
02244
02245 result = tcl_resultstring();
02246 #endif
02247
02248 if (code == TCL_OK) {
02249 if (!strchr(msg, ' '))
02250 dumplots(idx, "Currently: ", result);
02251 else
02252 dprintf(idx, "Ok, set.\n");
02253 } else
02254 dprintf(idx, "Error: %s\n", result);
02255
02256 #ifdef USE_TCL_ENCODING
02257 Tcl_DStringFree(&dstr);
02258 #endif
02259 }
02260
02261 static void cmd_module(struct userrec *u, int idx, char *par)
02262 {
02263 putlog(LOG_CMDS, "*", "#%s# module %s", dcc[idx].nick, par);
02264 do_module_report(idx, 2, par[0] ? par : NULL);
02265 }
02266
02267 static void cmd_loadmod(struct userrec *u, int idx, char *par)
02268 {
02269 const char *p;
02270
02271 if (!(isowner(dcc[idx].nick)) && (must_be_owner)) {
02272 dprintf(idx, MISC_NOSUCHCMD);
02273 return;
02274 }
02275 if (!par[0]) {
02276 dprintf(idx, "%s: loadmod <module>\n", MISC_USAGE);
02277 } else {
02278 p = module_load(par);
02279 if (p)
02280 dprintf(idx, "%s: %s %s\n", par, MOD_LOADERROR, p);
02281 else {
02282 putlog(LOG_CMDS, "*", "#%s# loadmod %s", dcc[idx].nick, par);
02283 dprintf(idx, MOD_LOADED, par);
02284 dprintf(idx, "\n");
02285 }
02286 }
02287 }
02288
02289 static void cmd_unloadmod(struct userrec *u, int idx, char *par)
02290 {
02291 char *p;
02292
02293 if (!(isowner(dcc[idx].nick)) && (must_be_owner)) {
02294 dprintf(idx, MISC_NOSUCHCMD);
02295 return;
02296 }
02297 if (!par[0])
02298 dprintf(idx, "%s: unloadmod <module>\n", MISC_USAGE);
02299 else {
02300 p = module_unload(par, dcc[idx].nick);
02301 if (p)
02302 dprintf(idx, "%s %s: %s\n", MOD_UNLOADERROR, par, p);
02303 else {
02304 putlog(LOG_CMDS, "*", "#%s# unloadmod %s", dcc[idx].nick, par);
02305 dprintf(idx, "%s %s\n", MOD_UNLOADED, par);
02306 }
02307 }
02308 }
02309
02310 static void cmd_pls_ignore(struct userrec *u, int idx, char *par)
02311 {
02312 char *who, s[UHOSTLEN];
02313 unsigned long int expire_time = 0;
02314
02315 if (!par[0]) {
02316 dprintf(idx, "Usage: +ignore <hostmask> [%%<XdXhXm>] [comment]\n");
02317 return;
02318 }
02319
02320 who = newsplit(&par);
02321 if (par[0] == '%') {
02322 char *p, *p_expire;
02323 unsigned long int expire_foo;
02324
02325 p = newsplit(&par);
02326 p_expire = p + 1;
02327 while (*(++p) != 0) {
02328 switch (tolower((unsigned) *p)) {
02329 case 'd':
02330 *p = 0;
02331 expire_foo = strtol(p_expire, NULL, 10);
02332 if (expire_foo > 365)
02333 expire_foo = 365;
02334 expire_time += 86400 * expire_foo;
02335 p_expire = p + 1;
02336 break;
02337 case 'h':
02338 *p = 0;
02339 expire_foo = strtol(p_expire, NULL, 10);
02340 if (expire_foo > 8760)
02341 expire_foo = 8760;
02342 expire_time += 3600 * expire_foo;
02343 p_expire = p + 1;
02344 break;
02345 case 'm':
02346 *p = 0;
02347 expire_foo = strtol(p_expire, NULL, 10);
02348 if (expire_foo > 525600)
02349 expire_foo = 525600;
02350 expire_time += 60 * expire_foo;
02351 p_expire = p + 1;
02352 }
02353 }
02354 }
02355 if (!par[0])
02356 par = "requested";
02357 else if (strlen(par) > 65)
02358 par[65] = 0;
02359 if (strlen(who) > UHOSTMAX - 4)
02360 who[UHOSTMAX - 4] = 0;
02361
02362
02363 if (!strchr(who, '!')) {
02364 if (!strchr(who, '@'))
02365 simple_sprintf(s, "%s!*@*", who);
02366 else
02367 simple_sprintf(s, "*!%s", who);
02368 } else if (!strchr(who, '@'))
02369 simple_sprintf(s, "%s@*", who);
02370 else
02371 strcpy(s, who);
02372
02373 if (match_ignore(s))
02374 dprintf(idx, "That already matches an existing ignore.\n");
02375 else {
02376 dprintf(idx, "Now ignoring: %s (%s)\n", s, par);
02377 addignore(s, dcc[idx].nick, par, expire_time ? now + expire_time : 0L);
02378 putlog(LOG_CMDS, "*", "#%s# +ignore %s %s", dcc[idx].nick, s, par);
02379 }
02380 }
02381
02382 static void cmd_mns_ignore(struct userrec *u, int idx, char *par)
02383 {
02384 char buf[UHOSTLEN];
02385
02386 if (!par[0]) {
02387 dprintf(idx, "Usage: -ignore <hostmask | ignore #>\n");
02388 return;
02389 }
02390 strncpyz(buf, par, sizeof buf);
02391 if (delignore(buf)) {
02392 putlog(LOG_CMDS, "*", "#%s# -ignore %s", dcc[idx].nick, buf);
02393 dprintf(idx, "No longer ignoring: %s\n", buf);
02394 } else
02395 dprintf(idx, "That ignore cannot be found.\n");
02396 }
02397
02398 static void cmd_ignores(struct userrec *u, int idx, char *par)
02399 {
02400 putlog(LOG_CMDS, "*", "#%s# ignores %s", dcc[idx].nick, par);
02401 tell_ignores(idx, par);
02402 }
02403
02404 static void cmd_pls_user(struct userrec *u, int idx, char *par)
02405 {
02406 char *handle, *host;
02407
02408 if (!par[0]) {
02409 dprintf(idx, "Usage: +user <handle> [hostmask]\n");
02410 return;
02411 }
02412 handle = newsplit(&par);
02413 host = newsplit(&par);
02414 if (strlen(handle) > HANDLEN)
02415 handle[HANDLEN] = 0;
02416 if (get_user_by_handle(userlist, handle))
02417 dprintf(idx, "Someone already exists by that name.\n");
02418 else if (strchr(BADNICKCHARS, handle[0]) != NULL)
02419 dprintf(idx, "You can't start a nick with '%c'.\n", handle[0]);
02420 else if (!egg_strcasecmp(handle, botnetnick))
02421 dprintf(idx, "Hey! That's MY name!\n");
02422 else {
02423 putlog(LOG_CMDS, "*", "#%s# +user %s %s", dcc[idx].nick, handle, host);
02424 userlist = adduser(userlist, handle, host, "-", 0);
02425 dprintf(idx, "Added %s (%s) with no password and no flags.\n", handle,
02426 host[0] ? host : "no host");
02427 }
02428 }
02429
02430 static void cmd_mns_user(struct userrec *u, int idx, char *par)
02431 {
02432 int idx2;
02433 char *handle;
02434 struct userrec *u2;
02435 module_entry *me;
02436
02437 if (!par[0]) {
02438 dprintf(idx, "Usage: -user <hand>\n");
02439 return;
02440 }
02441 handle = newsplit(&par);
02442 u2 = get_user_by_handle(userlist, handle);
02443 if (!u2 || !u) {
02444 dprintf(idx, "No such user!\n");
02445 return;
02446 }
02447 if (isowner(u2->handle)) {
02448 dprintf(idx, "You can't remove a permanent bot owner!\n");
02449 return;
02450 }
02451 if ((u2->flags & USER_OWNER) && !(u->flags & USER_OWNER)) {
02452 dprintf(idx, "You can't remove a bot owner!\n");
02453 return;
02454 }
02455 if (u2->flags & USER_BOT) {
02456 if ((bot_flags(u2) & BOT_SHARE) && !(u->flags & USER_OWNER)) {
02457 dprintf(idx, "You can't remove share bots.\n");
02458 return;
02459 }
02460 for (idx2 = 0; idx2 < dcc_total; idx2++)
02461 if (dcc[idx2].type != &DCC_RELAY && dcc[idx2].type != &DCC_FORK_BOT &&
02462 !egg_strcasecmp(dcc[idx2].nick, handle))
02463 break;
02464 if (idx2 != dcc_total) {
02465 dprintf(idx, "You can't remove a directly linked bot.\n");
02466 return;
02467 }
02468 }
02469 if ((u->flags & USER_BOTMAST) && !(u->flags & USER_MASTER) &&
02470 !(u2->flags & USER_BOT)) {
02471 dprintf(idx, "You can't remove users who aren't bots!\n");
02472 return;
02473 }
02474 if ((me = module_find("irc", 0, 0))) {
02475 Function *func = me->funcs;
02476
02477 (func[IRC_CHECK_THIS_USER]) (handle, 1, NULL);
02478 }
02479 if (deluser(handle)) {
02480 putlog(LOG_CMDS, "*", "#%s# -user %s", dcc[idx].nick, handle);
02481 dprintf(idx, "Deleted %s.\n", handle);
02482 } else
02483 dprintf(idx, "Failed.\n");
02484 }
02485
02486 static void cmd_pls_host(struct userrec *u, int idx, char *par)
02487 {
02488 char *handle, *host;
02489 struct userrec *u2;
02490 struct list_type *q;
02491 struct flag_record fr2 = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0 },
02492 fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0 };
02493 module_entry *me;
02494
02495 if (!par[0]) {
02496 dprintf(idx, "Usage: +host [handle] <newhostmask>\n");
02497 return;
02498 }
02499
02500 handle = newsplit(&par);
02501
02502 if (par[0]) {
02503 host = newsplit(&par);
02504 u2 = get_user_by_handle(userlist, handle);
02505 } else {
02506 host = handle;
02507 handle = dcc[idx].nick;
02508 u2 = u;
02509 }
02510 if (!u2 || !u) {
02511 dprintf(idx, "No such user.\n");
02512 return;
02513 }
02514 get_user_flagrec(u, &fr, NULL);
02515 if (egg_strcasecmp(handle, dcc[idx].nick)) {
02516 get_user_flagrec(u2, &fr2, NULL);
02517 if (!glob_master(fr) && !glob_bot(fr2) && !chan_master(fr)) {
02518 dprintf(idx, "You can't add hostmasks to non-bots.\n");
02519 return;
02520 }
02521 if (!glob_owner(fr) && glob_bot(fr2) && (bot_flags(u2) & BOT_SHARE)) {
02522 dprintf(idx, "You can't add hostmasks to share bots.\n");
02523 return;
02524 }
02525 if ((glob_owner(fr2) || glob_master(fr2)) && !glob_owner(fr)) {
02526 dprintf(idx, "You can't add hostmasks to a bot owner/master.\n");
02527 return;
02528 }
02529 if ((chan_owner(fr2) || chan_master(fr2)) && !glob_master(fr) &&
02530 !glob_owner(fr) && !chan_owner(fr)) {
02531 dprintf(idx, "You can't add hostmasks to a channel owner/master.\n");
02532 return;
02533 }
02534 if (!glob_botmast(fr) && !glob_master(fr) && !chan_master(fr)) {
02535 dprintf(idx, "Permission denied.\n");
02536 return;
02537 }
02538 }
02539 if (!glob_botmast(fr) && !chan_master(fr) && get_user_by_host(host)) {
02540 dprintf(idx, "You cannot add a host matching another user!\n");
02541 return;
02542 }
02543 for (q = get_user(&USERENTRY_HOSTS, u); q; q = q->next)
02544 if (!egg_strcasecmp(q->extra, host)) {
02545 dprintf(idx, "That hostmask is already there.\n");
02546 return;
02547 }
02548 putlog(LOG_CMDS, "*", "#%s# +host %s %s", dcc[idx].nick, handle, host);
02549 addhost_by_handle(handle, host);
02550 dprintf(idx, "Added '%s' to %s.\n", host, handle);
02551 if ((me = module_find("irc", 0, 0))) {
02552 Function *func = me->funcs;
02553
02554 (func[IRC_CHECK_THIS_USER]) (handle, 0, NULL);
02555 }
02556 }
02557
02558 static void cmd_mns_host(struct userrec *u, int idx, char *par)
02559 {
02560 char *handle, *host;
02561 struct userrec *u2;
02562 struct flag_record fr2 = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0 },
02563 fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0 };
02564 module_entry *me;
02565
02566 if (!par[0]) {
02567 dprintf(idx, "Usage: -host [handle] <hostmask>\n");
02568 return;
02569 }
02570 handle = newsplit(&par);
02571 if (par[0]) {
02572 host = newsplit(&par);
02573 u2 = get_user_by_handle(userlist, handle);
02574 } else {
02575 host = handle;
02576 handle = dcc[idx].nick;
02577 u2 = u;
02578 }
02579 if (!u2 || !u) {
02580 dprintf(idx, "No such user.\n");
02581 return;
02582 }
02583
02584 get_user_flagrec(u, &fr, NULL);
02585 get_user_flagrec(u2, &fr2, NULL);
02586
02587 if (((glob_deop(fr) || glob_kick(fr)) && !glob_master(fr)) ||
02588 ((chan_deop(fr) || chan_kick(fr)) && !chan_master(fr))) {
02589 dprintf(idx, "You can't remove hostmasks while having the +d or +k "
02590 "flag.\n");
02591 return;
02592 }
02593
02594 if (egg_strcasecmp(handle, dcc[idx].nick)) {
02595 if (!glob_master(fr) && !glob_bot(fr2) && !chan_master(fr)) {
02596 dprintf(idx, "You can't remove hostmasks from non-bots.\n");
02597 return;
02598 }
02599 if (glob_bot(fr2) && (bot_flags(u2) & BOT_SHARE) && !glob_owner(fr)) {
02600 dprintf(idx, "You can't remove hostmasks from a share bot.\n");
02601 return;
02602 }
02603 if ((glob_owner(fr2) || glob_master(fr2)) && !glob_owner(fr)) {
02604 dprintf(idx, "You can't remove hostmasks from a bot owner/master.\n");
02605 return;
02606 }
02607 if ((chan_owner(fr2) || chan_master(fr2)) && !glob_master(fr) &&
02608 !glob_owner(fr) && !chan_owner(fr)) {
02609 dprintf(idx, "You can't remove hostmasks from a channel owner/master.\n");
02610 return;
02611 }
02612 if (!glob_botmast(fr) && !glob_master(fr) && !chan_master(fr)) {
02613 dprintf(idx, "Permission denied.\n");
02614 return;
02615 }
02616 }
02617 if (delhost_by_handle(handle, host)) {
02618 putlog(LOG_CMDS, "*", "#%s# -host %s %s", dcc[idx].nick, handle, host);
02619 dprintf(idx, "Removed '%s' from %s.\n", host, handle);
02620 if ((me = module_find("irc", 0, 0))) {
02621 Function *func = me->funcs;
02622
02623 (func[IRC_CHECK_THIS_USER]) (handle, 2, host);
02624 }
02625 } else
02626 dprintf(idx, "Failed.\n");
02627 }
02628
02629 static void cmd_modules(struct userrec *u, int idx, char *par)
02630 {
02631 int ptr;
02632 char *bot;
02633 module_entry *me;
02634
02635 putlog(LOG_CMDS, "*", "#%s# modules %s", dcc[idx].nick, par);
02636
02637 if (!par[0]) {
02638 dprintf(idx, "Modules loaded:\n");
02639 for (me = module_list; me; me = me->next)
02640 dprintf(idx, " Module: %s (v%d.%d)\n", me->name, me->major, me->minor);
02641 dprintf(idx, "End of modules list.\n");
02642 } else {
02643 bot = newsplit(&par);
02644 if ((ptr = nextbot(bot)) >= 0)
02645 dprintf(ptr, "v %s %s %d:%s\n", botnetnick, bot, dcc[idx].sock,
02646 dcc[idx].nick);
02647 else
02648 dprintf(idx, "No such bot online.\n");
02649 }
02650 }
02651
02652 static void cmd_traffic(struct userrec *u, int idx, char *par)
02653 {
02654 unsigned long itmp, itmp2;
02655
02656 dprintf(idx, "Traffic since last restart\n");
02657 dprintf(idx, "==========================\n");
02658 if (otraffic_irc > 0 || itraffic_irc > 0 || otraffic_irc_today > 0 ||
02659 itraffic_irc_today > 0) {
02660 dprintf(idx, "IRC:\n");
02661 dprintf(idx, " out: %s", btos(otraffic_irc + otraffic_irc_today));
02662 dprintf(idx, " (%s today)\n", btos(otraffic_irc_today));
02663 dprintf(idx, " in: %s", btos(itraffic_irc + itraffic_irc_today));
02664 dprintf(idx, " (%s today)\n", btos(itraffic_irc_today));
02665 }
02666 if (otraffic_bn > 0 || itraffic_bn > 0 || otraffic_bn_today > 0 ||
02667 itraffic_bn_today > 0) {
02668 dprintf(idx, "Botnet:\n");
02669 dprintf(idx, " out: %s", btos(otraffic_bn + otraffic_bn_today));
02670 dprintf(idx, " (%s today)\n", btos(otraffic_bn_today));
02671 dprintf(idx, " in: %s", btos(itraffic_bn + itraffic_bn_today));
02672 dprintf(idx, " (%s today)\n", btos(itraffic_bn_today));
02673 }
02674 if (otraffic_dcc > 0 || itraffic_dcc > 0 || otraffic_dcc_today > 0 ||
02675 itraffic_dcc_today > 0) {
02676 dprintf(idx, "Partyline:\n");
02677 itmp = otraffic_dcc + otraffic_dcc_today;
02678 itmp2 = otraffic_dcc_today;
02679 dprintf(idx, " out: %s", btos(itmp));
02680 dprintf(idx, " (%s today)\n", btos(itmp2));
02681 dprintf(idx, " in: %s", btos(itraffic_dcc + itraffic_dcc_today));
02682 dprintf(idx, " (%s today)\n", btos(itraffic_dcc_today));
02683 }
02684 if (otraffic_trans > 0 || itraffic_trans > 0 || otraffic_trans_today > 0 ||
02685 itraffic_trans_today > 0) {
02686 dprintf(idx, "Transfer.mod:\n");
02687 dprintf(idx, " out: %s", btos(otraffic_trans + otraffic_trans_today));
02688 dprintf(idx, " (%s today)\n", btos(otraffic_trans_today));
02689 dprintf(idx, " in: %s", btos(itraffic_trans + itraffic_trans_today));
02690 dprintf(idx, " (%s today)\n", btos(itraffic_trans_today));
02691 }
02692 if (otraffic_unknown > 0 || otraffic_unknown_today > 0) {
02693 dprintf(idx, "Misc:\n");
02694 dprintf(idx, " out: %s", btos(otraffic_unknown + otraffic_unknown_today));
02695 dprintf(idx, " (%s today)\n", btos(otraffic_unknown_today));
02696 dprintf(idx, " in: %s", btos(itraffic_unknown + itraffic_unknown_today));
02697 dprintf(idx, " (%s today)\n", btos(itraffic_unknown_today));
02698 }
02699 dprintf(idx, "---\n");
02700 dprintf(idx, "Total:\n");
02701 itmp = otraffic_irc + otraffic_bn + otraffic_dcc + otraffic_trans +
02702 otraffic_unknown + otraffic_irc_today + otraffic_bn_today +
02703 otraffic_dcc_today + otraffic_trans_today + otraffic_unknown_today;
02704 itmp2 = otraffic_irc_today + otraffic_bn_today + otraffic_dcc_today +
02705 otraffic_trans_today + otraffic_unknown_today;
02706 dprintf(idx, " out: %s", btos(itmp));
02707 dprintf(idx, " (%s today)\n", btos(itmp2));
02708 dprintf(idx, " in: %s", btos(itraffic_irc + itraffic_bn + itraffic_dcc +
02709 itraffic_trans + itraffic_unknown + itraffic_irc_today +
02710 itraffic_bn_today + itraffic_dcc_today + itraffic_trans_today +
02711 itraffic_unknown_today));
02712 dprintf(idx, " (%s today)\n", btos(itraffic_irc_today + itraffic_bn_today +
02713 itraffic_dcc_today + itraffic_trans_today + itraffic_unknown_today));
02714 putlog(LOG_CMDS, "*", "#%s# traffic", dcc[idx].nick);
02715 }
02716
02717 static char traffictxt[20];
02718 static char *btos(unsigned long bytes)
02719 {
02720 char unit[10];
02721 float xbytes;
02722
02723 sprintf(unit, "Bytes");
02724 xbytes = bytes;
02725 if (xbytes > 1024.0) {
02726 sprintf(unit, "KBytes");
02727 xbytes = xbytes / 1024.0;
02728 }
02729 if (xbytes > 1024.0) {
02730 sprintf(unit, "MBytes");
02731 xbytes = xbytes / 1024.0;
02732 }
02733 if (xbytes > 1024.0) {
02734 sprintf(unit, "GBytes");
02735 xbytes = xbytes / 1024.0;
02736 }
02737 if (xbytes > 1024.0) {
02738 sprintf(unit, "TBytes");
02739 xbytes = xbytes / 1024.0;
02740 }
02741 if (bytes > 1024)
02742 sprintf(traffictxt, "%.2f %s", xbytes, unit);
02743 else
02744 sprintf(traffictxt, "%lu Bytes", bytes);
02745 return traffictxt;
02746 }
02747
02748 static void cmd_whoami(struct userrec *u, int idx, char *par)
02749 {
02750 dprintf(idx, "You are %s@%s.\n", dcc[idx].nick, botnetnick);
02751 putlog(LOG_CMDS, "*", "#%s# whoami", dcc[idx].nick);
02752 }
02753
02754
02755
02756
02757
02758
02759
02760 cmd_t C_dcc[] = {
02761 {"+bot", "t", (IntFunc) cmd_pls_bot, NULL},
02762 {"+host", "t|m", (IntFunc) cmd_pls_host, NULL},
02763 {"+ignore", "m", (IntFunc) cmd_pls_ignore, NULL},
02764 {"+user", "m", (IntFunc) cmd_pls_user, NULL},
02765 {"-bot", "t", (IntFunc) cmd_mns_user, NULL},
02766 {"-host", "", (IntFunc) cmd_mns_host, NULL},
02767 {"-ignore", "m", (IntFunc) cmd_mns_ignore, NULL},
02768 {"-user", "m", (IntFunc) cmd_mns_user, NULL},
02769 {"addlog", "to|o", (IntFunc) cmd_addlog, NULL},
02770 {"away", "", (IntFunc) cmd_away, NULL},
02771 {"back", "", (IntFunc) cmd_back, NULL},
02772 {"backup", "m|m", (IntFunc) cmd_backup, NULL},
02773 {"banner", "t", (IntFunc) cmd_banner, NULL},
02774 {"binds", "m", (IntFunc) cmd_binds, NULL},
02775 {"boot", "t", (IntFunc) cmd_boot, NULL},
02776 {"botattr", "t", (IntFunc) cmd_botattr, NULL},
02777 {"botinfo", "", (IntFunc) cmd_botinfo, NULL},
02778 {"bots", "", (IntFunc) cmd_bots, NULL},
02779 {"bottree", "", (IntFunc) cmd_bottree, NULL},
02780 {"chaddr", "t", (IntFunc) cmd_chaddr, NULL},
02781 {"chat", "", (IntFunc) cmd_chat, NULL},
02782 {"chattr", "m|m", (IntFunc) cmd_chattr, NULL},
02783 {"chhandle", "t", (IntFunc) cmd_chhandle, NULL},
02784 {"chnick", "t", (IntFunc) cmd_chhandle, NULL},
02785 {"chpass", "t", (IntFunc) cmd_chpass, NULL},
02786 {"comment", "m", (IntFunc) cmd_comment, NULL},
02787 {"console", "to|o", (IntFunc) cmd_console, NULL},
02788 {"dccstat", "t", (IntFunc) cmd_dccstat, NULL},
02789 {"debug", "m", (IntFunc) cmd_debug, NULL},
02790 {"die", "n", (IntFunc) cmd_die, NULL},
02791 {"echo", "", (IntFunc) cmd_echo, NULL},
02792 {"fixcodes", "", (IntFunc) cmd_fixcodes, NULL},
02793 {"help", "", (IntFunc) cmd_help, NULL},
02794 {"ignores", "m", (IntFunc) cmd_ignores, NULL},
02795 {"link", "t", (IntFunc) cmd_link, NULL},
02796 {"loadmod", "n", (IntFunc) cmd_loadmod, NULL},
02797 {"match", "to|o", (IntFunc) cmd_match, NULL},
02798 {"me", "", (IntFunc) cmd_me, NULL},
02799 {"module", "m", (IntFunc) cmd_module, NULL},
02800 {"modules", "n", (IntFunc) cmd_modules, NULL},
02801 {"motd", "", (IntFunc) cmd_motd, NULL},
02802 {"newpass", "", (IntFunc) cmd_newpass, NULL},
02803 {"handle", "", (IntFunc) cmd_handle, NULL},
02804 {"nick", "", (IntFunc) cmd_handle, NULL},
02805 {"page", "", (IntFunc) cmd_page, NULL},
02806 {"quit", "", (IntFunc) CMD_LEAVE, NULL},
02807 {"rehash", "m", (IntFunc) cmd_rehash, NULL},
02808 {"rehelp", "n", (IntFunc) cmd_rehelp, NULL},
02809 {"relay", "o", (IntFunc) cmd_relay, NULL},
02810 {"reload", "m|m", (IntFunc) cmd_reload, NULL},
02811 {"restart", "m", (IntFunc) cmd_restart, NULL},
02812 {"save", "m|m", (IntFunc) cmd_save, NULL},
02813 {"set", "n", (IntFunc) cmd_set, NULL},
02814 {"simul", "n", (IntFunc) cmd_simul, NULL},
02815 {"status", "m|m", (IntFunc) cmd_status, NULL},
02816 {"strip", "", (IntFunc) cmd_strip, NULL},
02817 {"su", "", (IntFunc) cmd_su, NULL},
02818 {"tcl", "n", (IntFunc) cmd_tcl, NULL},
02819 {"trace", "t", (IntFunc) cmd_trace, NULL},
02820 {"unlink", "t", (IntFunc) cmd_unlink, NULL},
02821 {"unloadmod", "n", (IntFunc) cmd_unloadmod, NULL},
02822 {"uptime", "m|m", (IntFunc) cmd_uptime, NULL},
02823 {"vbottree", "", (IntFunc) cmd_vbottree, NULL},
02824 {"who", "", (IntFunc) cmd_who, NULL},
02825 {"whois", "to|o", (IntFunc) cmd_whois, NULL},
02826 {"whom", "", (IntFunc) cmd_whom, NULL},
02827 {"traffic", "m|m", (IntFunc) cmd_traffic, NULL},
02828 {"whoami", "", (IntFunc) cmd_whoami, NULL},
02829 {NULL, NULL, NULL, NULL}
02830 };