| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555 |
- /*
- * botcmd.c -- handles:
- * commands that comes across the botnet
- * userfile transfer and update commands from sharebots
- *
- */
- #include "main.h"
- #include "tandem.h"
- #include "users.h"
- #include "chan.h"
- #include "modules.h"
- extern char botnetnick[], ver[], admin[], network[], motdfile[];
- extern int dcc_total, remote_boots, noshare, timesync, conmask;
- extern struct dcc_t *dcc;
- extern struct chanset_t *chanset;
- extern struct userrec *userlist;
- extern Tcl_Interp *interp;
- extern time_t now, online_since;
- extern party_t *party;
- extern module_entry *module_list;
- static char TBUF[1024]; /* Static buffer for goofy bot stuff */
- static char base64to[256] =
- {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0,
- 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 62, 0, 63, 0, 0, 0, 26, 27, 28,
- 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
- 49, 50, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
- };
- int base64_to_int(char *buf)
- {
- int i = 0;
- while (*buf) {
- i = i << 6;
- i += base64to[(int) *buf];
- buf++;
- }
- return i;
- }
- /* Used for 1.0 compatibility: if a join message arrives with no sock#,
- * i'll just grab the next "fakesock" # (incrementing to assure uniqueness)
- */
- static int fakesock = 2300;
- static void fake_alert(int idx, char *item, char *extra)
- {
- static unsigned long lastfake; /* The last time fake_alert was used */
- if (now - lastfake > 10) {
- /* Don't fake_alert more than once every 10secs */
- dprintf(idx, "ct %s NOTICE: %s (%s != %s).\n",
- botnetnick, NET_FAKEREJECT, item, extra);
- putlog(LOG_BOTS, "*", "%s %s (%s != %s).", dcc[idx].nick, NET_FAKEREJECT,
- item, extra);
- lastfake = now;
- }
- }
- /* chan <from> <chan> <text>
- */
- static void bot_chan2(int idx, char *msg)
- {
- char *from, *p;
- int i, chan;
- if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
- return;
- from = newsplit(&msg);
- p = newsplit(&msg);
- chan = base64_to_int(p);
- /* Strip annoying control chars */
- for (p = from; *p;) {
- if ((*p < 32) || (*p == 127))
- strcpy(p, p + 1);
- else
- p++;
- }
- p = strchr(from, '@');
- if (p) {
- sprintf(TBUF, "<%s> %s", from, msg);
- *p = 0;
- if (!partyidle(p + 1, from)) {
- *p = '@';
- fake_alert(idx, "user", from);
- return;
- }
- *p = '@';
- p++;
- } else {
- sprintf(TBUF, "*** (%s) %s", from, msg);
- p = from;
- }
- i = nextbot(p);
- if (i != idx) {
- fake_alert(idx, "direction", p);
- } else {
- chanout_but(-1, chan, "%s\n", TBUF);
- /* Send to new version bots */
- if (i >= 0)
- botnet_send_chan(idx, from, NULL, chan, msg);
- if (strchr(from, '@') != NULL)
- check_tcl_chat(from, chan, msg);
- else
- check_tcl_bcst(from, chan, msg);
- }
- }
- #ifdef S_DCCPASS
- void bot_cmdpass(int idx, char *par)
- {
- char *p;
- p = strchr(par, ' ');
- if (p) {
- *p++ = 0;
- botnet_send_cmdpass(idx, par, p);
- p--;
- *p = ' ';
- } else {
- botnet_send_cmdpass(idx, par, "");
- }
- set_cmd_pass(par, 0);
- }
- #endif
- void bot_config(int idx, char *par)
- {
- got_config_share(idx, par);
- }
- void bot_remotecmd(int idx, char *par) {
- char *tbot, *fbot, *fhnd, *fidx;
- tbot=newsplit(&par);
- fbot=newsplit(&par);
- fhnd=newsplit(&par);
- fidx=newsplit(&par);
- if (!strcmp(tbot, botnetnick)) {
- gotremotecmd(tbot, fbot, fhnd, fidx, par);
- } else if (!strcmp(tbot, "*")) {
- botnet_send_cmd_broad(idx, fbot, fhnd, atoi(fidx), par);
- gotremotecmd(tbot, fbot, fhnd, fidx, par);
- } else {
- if (nextbot(tbot)!=idx)
- botnet_send_cmd(fbot, tbot, fhnd, atoi(fidx), par);
- }
- }
- void bot_remotereply(int idx, char *par) {
- char *tbot, *fbot, *fhnd, *fidx;
- tbot=newsplit(&par);
- fbot=newsplit(&par);
- fhnd=newsplit(&par);
- fidx=newsplit(&par);
- if (!strcmp(tbot, botnetnick)) {
- gotremotereply(fbot, fhnd, fidx, par);
- } else {
- if (nextbot(tbot)!=idx)
- botnet_send_cmdreply(fbot, tbot, fhnd, fidx, par);
- }
- }
- /* chat <from> <notice> -- only from bots
- */
- static void bot_chat(int idx, char *par)
- {
- char *from;
- int i;
- if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
- return;
- from = newsplit(&par);
- if (strchr(from, '@') != NULL) {
- fake_alert(idx, "bot", from);
- return;
- }
- /* Make sure the bot is valid */
- i = nextbot(from);
- if (i != idx) {
- fake_alert(idx, "direction", from);
- return;
- }
- chatout("*** (%s) %s\n", from, par);
- botnet_send_chat(idx, from, par);
- }
- /* actchan <from> <chan> <text>
- */
- static void bot_actchan(int idx, char *par)
- {
- char *from, *p;
- int i, chan;
- if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
- return;
- from = newsplit(&par);
- p = strchr(from, '@');
- if (p == NULL) {
- /* How can a bot do an action? */
- fake_alert(idx, "user@bot", from);
- return;
- }
- *p = 0;
- if (!partyidle(p + 1, from)) {
- *p = '@';
- fake_alert(idx, "user", from);
- return;
- }
- *p = '@';
- p++;
- i = nextbot(p);
- if (i != idx) {
- fake_alert(idx, "direction", p);
- return;
- }
- p = newsplit(&par);
- chan = base64_to_int(p);
- for (p = from; *p;) {
- if ((*p < 32) || (*p == 127))
- strcpy(p, p + 1);
- else
- p++;
- }
- chanout_but(-1, chan, "* %s %s\n", from, par);
- botnet_send_act(idx, from, NULL, chan, par);
- check_tcl_act(from, chan, par);
- }
- /* priv <from> <to> <message>
- */
- static void bot_priv(int idx, char *par)
- {
- char *from, *p, *to = TBUF, *tobot;
- int i;
- from = newsplit(&par);
- tobot = newsplit(&par);
- splitc(to, tobot, '@');
- p = strchr(from, '@');
- if (p != NULL)
- p++;
- else
- p = from;
- i = nextbot(p);
- if (i != idx) {
- fake_alert(idx, "direction", p);
- return;
- }
- if (!to[0])
- return; /* Silently ignore notes to '@bot' this
- * is legacy code */
- if (!egg_strcasecmp(tobot, botnetnick)) { /* For me! */
- if (p == from)
- add_note(to, from, par, -2, 0);
- else {
- i = add_note(to, from, par, -1, 0);
- if (from[0] != '@')
- switch (i) {
- case NOTE_ERROR:
- botnet_send_priv(idx, botnetnick, from, NULL, "%s %s.", BOT_NOSUCHUSER, to);
- break;
- case NOTE_STORED:
- botnet_send_priv(idx, botnetnick, from, NULL, "%s", BOT_NOTESTORED2);
- break;
- case NOTE_FULL:
- botnet_send_priv(idx, botnetnick, from, NULL, "%s", BOT_NOTEBOXFULL);
- break;
- case NOTE_AWAY:
- botnet_send_priv(idx, botnetnick, from, NULL, "%s %s", to, BOT_NOTEISAWAY);
- break;
- case NOTE_FWD:
- botnet_send_priv(idx, botnetnick, from, NULL, "%s %s", "Not online; note forwarded to:", to);
- break;
- case NOTE_REJECT:
- botnet_send_priv(idx, botnetnick, from, NULL, "%s %s", to, "rejected your note.");
- break;
- case NOTE_TCL:
- break; /* Do nothing */
- case NOTE_OK:
- botnet_send_priv(idx, botnetnick, from, NULL, "%s %s.", BOT_NOTESENTTO, to);
- break;
- }
- }
- } else { /* Pass it on */
- i = nextbot(tobot);
- if (i >= 0)
- botnet_send_priv(i, from, to, tobot, "%s", par);
- }
- }
- static void bot_bye(int idx, char *par)
- {
- char s[1024];
- int users, bots;
- bots = bots_in_subtree(findbot(dcc[idx].nick));
- users = users_in_subtree(findbot(dcc[idx].nick));
- simple_sprintf(s, "%s %s. %s (lost %d bot%s and %d user%s)",
- BOT_DISCONNECTED, dcc[idx].nick, par[0] ?
- par : "No reason", bots, (bots != 1) ?
- "s" : "", users, (users != 1) ? "s" : "");
- putlog(LOG_BOTS, "*", "%s", s);
- chatout("*** %s\n", s);
- botnet_send_unlinked(idx, dcc[idx].nick, s);
- dprintf(idx, "*bye\n");
- killsock(dcc[idx].sock);
- lostdcc(idx);
- }
- static void remote_tell_who(int idx, char *nick, int chan)
- {
- int i = 10, k, l, ok = 0;
- char s[1024], *realnick;
- struct chanset_t *c;
- realnick = strchr(nick, ':');
- if (realnick)
- realnick++;
- else
- realnick = nick;
- putlog(LOG_BOTS, "*", "#%s# who", realnick);
- strcpy(s, "Channels: ");
- for (c = chanset; c; c = c->next)
- if (!channel_secret(c) && !channel_inactive(c)) {
- l = strlen(c->name);
- if (i + l < 1021) {
- if (i > 10)
- sprintf(s, "%s, %s", s, c->name);
- else {
- strcpy(s, c->name);
- i += (l + 2);
- }
- }
- }
- if (i > 10) {
- botnet_send_priv(idx, botnetnick, nick, NULL, "%s (%s)", s, ver);
- } else
- botnet_send_priv(idx, botnetnick, nick, NULL, "%s (%s)", BOT_NOCHANNELS,
- ver);
- if (admin[0])
- botnet_send_priv(idx, botnetnick, nick, NULL, "Admin: %s", admin);
- if (chan == 0)
- botnet_send_priv(idx, botnetnick, nick, NULL,
- "%s (* = %s, + = %s, @ = %s)",
- BOT_PARTYMEMBS, MISC_OWNER, MISC_MASTER, MISC_OP);
- else {
- simple_sprintf(s, "assoc %d", chan);
- if ((Tcl_Eval(interp, s) != TCL_OK) || !interp->result[0])
- botnet_send_priv(idx, botnetnick, nick, NULL,
- "%s %s%d: (* = %s, + = %s, @ = %s)\n",
- BOT_PEOPLEONCHAN,
- (chan < GLOBAL_CHANS) ? "" : "*",
- chan % GLOBAL_CHANS,
- MISC_OWNER, MISC_MASTER, MISC_OP);
- else
- botnet_send_priv(idx, botnetnick, nick, NULL,
- "%s '%s' (%s%d): (* = %s, + = %s, @ = %s)\n",
- BOT_PEOPLEONCHAN, interp->result,
- (chan < GLOBAL_CHANS) ? "" : "*",
- chan % GLOBAL_CHANS,
- MISC_OWNER, MISC_MASTER, MISC_OP);
- }
- for (i = 0; i < dcc_total; i++)
- if (dcc[i].type->flags & DCT_REMOTEWHO)
- if (dcc[i].u.chat->channel == chan) {
- k = sprintf(s, " %c%-15s %s",
- (geticon(i) == '-' ? ' ' : geticon(i)),
- dcc[i].nick, dcc[i].host);
- if (now - dcc[i].timeval > 300) {
- unsigned long days, hrs, mins;
- days = (now - dcc[i].timeval) / 86400;
- hrs = ((now - dcc[i].timeval) - (days * 86400)) / 3600;
- mins = ((now - dcc[i].timeval) - (hrs * 3600)) / 60;
- if (days > 0)
- sprintf(s + k, " (%s %lud%luh)",
- MISC_IDLE, days, hrs);
- else if (hrs > 0)
- sprintf(s + k, " (%s %luh%lum)",
- MISC_IDLE, hrs, mins);
- else
- sprintf(s + k, " (%s %lum)",
- MISC_IDLE, mins);
- }
- botnet_send_priv(idx, botnetnick, nick, NULL, "%s", s);
- if (dcc[i].u.chat->away != NULL)
- botnet_send_priv(idx, botnetnick, nick, NULL, " %s: %s",
- MISC_AWAY, dcc[i].u.chat->away);
- }
- for (i = 0; i < dcc_total; i++)
- if (dcc[i].type == &DCC_BOT) {
- if (!ok) {
- ok = 1;
- botnet_send_priv(idx, botnetnick, nick, NULL,
- "%s:", BOT_BOTSCONNECTED);
- }
- sprintf(s, " %s%c%-15s %s",
- dcc[i].status & STAT_CALLED ? "<-" : "->",
- dcc[i].status & STAT_SHARE ? '+' : ' ',
- dcc[i].nick, dcc[i].u.bot->version);
- botnet_send_priv(idx, botnetnick, nick, NULL, "%s", s);
- }
- ok = 0;
- for (i = 0; i < dcc_total; i++)
- if (dcc[i].type->flags & DCT_REMOTEWHO)
- if (dcc[i].u.chat->channel != chan) {
- if (!ok) {
- ok = 1;
- botnet_send_priv(idx, botnetnick, nick, NULL, "%s:",
- BOT_OTHERPEOPLE);
- }
- l = sprintf(s, " %c%-15s %s", (geticon(i) == '-' ? ' ' : geticon(i)),
- dcc[i].nick, dcc[i].host);
- if (now - dcc[i].timeval > 300) {
- k = (now - dcc[i].timeval) / 60;
- if (k < 60)
- sprintf(s + l, " (%s %dm)", MISC_IDLE, k);
- else
- sprintf(s + l, " (%s %dh%dm)", MISC_IDLE, k / 60, k % 60);
- }
- botnet_send_priv(idx, botnetnick, nick, NULL, "%s", s);
- if (dcc[i].u.chat->away != NULL)
- botnet_send_priv(idx, botnetnick, nick, NULL,
- " %s: %s", MISC_AWAY,
- dcc[i].u.chat->away);
- }
- }
- static void bot_sysname(int idx, char *par)
- {
- //simply copy it all to the string pointer.
- putlog(LOG_DEBUG, "@", "%s is using %s", dcc[idx].nick, par);
- dcc[idx].u.bot->sysname[0] = 0;
- strcpy(dcc[idx].u.bot->sysname, par);
- }
- /* who <from@bot> <tobot> <chan#>
- */
- static void bot_who(int idx, char *par)
- {
- char *from, *to, *p;
- int i, chan;
- from = newsplit(&par);
- p = strchr(from, '@');
- if (!p) {
- sprintf(TBUF, "%s@%s", from, dcc[idx].nick);
- from = TBUF;
- }
- to = newsplit(&par);
- if (!egg_strcasecmp(to, botnetnick))
- to[0] = 0; /* (for me) */
- chan = base64_to_int(par);
- if (to[0]) { /* Pass it on */
- i = nextbot(to);
- if (i >= 0)
- botnet_send_who(i, from, to, chan);
- } else {
- remote_tell_who(idx, from, chan);
- }
- }
- static void bot_endlink(int idx, char *par)
- {
- dcc[idx].status &= ~STAT_LINKING;
- }
- /* info? <from@bot> -> send priv
- */
- static void bot_infoq(int idx, char *par)
- {
- char s[200], s2[32], *realnick;
- struct chanset_t *chan;
- time_t now2;
- int hr, min;
- /* Strip the idx from user@bot */
- realnick = strchr(par, ':');
- if (realnick)
- realnick++;
- else
- realnick = par;
- putlog(LOG_BOTS, "@", "#%s# botinfo", realnick);
- now2 = now - online_since;
- s2[0] = 0;
- if (now2 > 86400) {
- int days = now2 / 86400;
- /* Days */
- sprintf(s2, "%d day", days);
- if (days >= 2)
- strcat(s2, "s");
- strcat(s2, ", ");
- now2 -= days * 86400;
- }
- hr = (time_t) ((int) now2 / 3600);
- now2 -= (hr * 3600);
- min = (time_t) ((int) now2 / 60);
- sprintf(&s2[strlen(s2)], "%02d:%02d", (int) hr, (int) min);
- if (module_find("server", 0, 0)) {
- s[0] = 0;
- for (chan = chanset; chan; chan = chan->next) {
- if (!channel_secret(chan)) {
- if ((strlen(s) + strlen(chan->dname) + strlen(network)
- + strlen(botnetnick) + strlen(ver) + 1) >= 200) {
- strcat(s,"++ ");
- break; /* Yegads..! */
- }
- strcat(s, chan->dname);
- strcat(s, ", ");
- }
- }
- if (s[0]) {
- s[strlen(s) - 2] = 0;
- botnet_send_priv(idx, botnetnick, par, NULL,
- "%s <%s> (%s) [UP %s]", ver, network, s, s2);
- } else
- botnet_send_priv(idx, botnetnick, par, NULL,
- "%s <%s> (%s) [UP %s]", ver, network, BOT_NOCHANNELS,
- s2);
- } else
- botnet_send_priv(idx, botnetnick, par, NULL,
- "%s <NO_IRC> [UP %s]", ver, s2);
- botnet_send_infoq(idx, par);
- }
- static void bot_ping(int idx, char *par)
- {
- botnet_send_pong(idx);
- }
- static void bot_pong(int idx, char *par)
- {
- dcc[idx].status &= ~STAT_PINGED;
- if (dcc[idx].pingtime > (now - 120))
- dcc[idx].pingtime -= now;
- else
- dcc[idx].pingtime = 120;
- }
- /* link <from@bot> <who> <to-whom>
- */
- static void bot_link(int idx, char *par)
- {
- char *from, *bot, *rfrom;
- int i;
- from = newsplit(&par);
- bot = newsplit(&par);
- if (!egg_strcasecmp(bot, botnetnick)) {
- if ((rfrom = strchr(from, ':')))
- rfrom++;
- else
- rfrom = from;
- putlog(LOG_CMDS, "*", "#%s# link %s", rfrom, par);
- if (botlink(from, -1, par))
- botnet_send_priv(idx, botnetnick, from, NULL, "%s %s ...",
- BOT_LINKATTEMPT, par);
- else
- botnet_send_priv(idx, botnetnick, from, NULL, "%s.",
- BOT_CANTLINKTHERE);
- } else {
- i = nextbot(bot);
- if (i >= 0)
- botnet_send_link(i, from, bot, par);
- }
- }
- /* unlink <from@bot> <linking-bot> <undesired-bot> <reason>
- */
- static void bot_unlink(int idx, char *par)
- {
- char *from, *bot, *rfrom, *p, *undes;
- int i;
- from = newsplit(&par);
- bot = newsplit(&par);
- undes = newsplit(&par);
- if (!egg_strcasecmp(bot, botnetnick)) {
- if ((rfrom = strchr(from, ':')))
- rfrom++;
- else
- rfrom = from;
- putlog(LOG_CMDS, "*", "#%s# unlink %s (%s)", rfrom, undes, par[0] ? par :
- "No reason");
- i = botunlink(-3, undes, par[0] ? par : NULL);
- if (i == 1) {
- p = strchr(from, '@');
- if (p) {
- /* idx will change after unlink -- get new idx
- *
- * TODO: This has changed with the new lostdcc() behaviour. Check
- * if we can optimise the situation.
- */
- i = nextbot(p + 1);
- if (i >= 0)
- botnet_send_priv(i, botnetnick, from, NULL,
- "Unlinked from %s.", undes);
- }
- } else if (i == 0) {
- botnet_send_unlinked(-1, undes, "");
- p = strchr(from, '@');
- if (p) {
- /* Ditto above, about idx */
- i = nextbot(p + 1);
- if (i >= 0)
- botnet_send_priv(i, botnetnick, from, NULL,
- "%s %s.", BOT_CANTUNLINK, undes);
- }
- } else {
- p = strchr(from, '@');
- if (p) {
- i = nextbot(p + 1);
- if (i >= 0)
- botnet_send_priv(i, botnetnick, from, NULL,
- "Can't remotely unlink sharebots.");
- }
- }
- } else {
- i = nextbot(bot);
- if (i >= 0)
- botnet_send_unlink(i, from, bot, undes, par);
- }
- }
- /* Bot next share?
- */
- static void bot_update(int idx, char *par)
- {
- char *bot, x;
- int vnum;
- bot = newsplit(&par);
- x = par[0];
- if (x)
- par++;
- vnum = base64_to_int(par);
- if (in_chain(bot))
- updatebot(idx, bot, x, vnum);
- }
- static void bot_mtcl(char *botnick, char *code, char *par)
- {
- int oidx = 0, tcode = 0;
- char ret[2000];
-
- if (!par[0])
- return;
- oidx = atoi(newsplit(&par));
- if (!par[0])
- return;
- tcode = Tcl_GlobalEval(interp, par);
- if (tcode == TCL_OK)
- egg_snprintf(ret, sizeof ret, "r_mt %d Tcl: %s", oidx, interp->result);
- else
- egg_snprintf(ret, sizeof ret, "r_mt %d Tcl error: %s", oidx, interp->result);
- putbot(botnick, ret);
- }
- static void bot_rmtcl(char *botnick, char *code, char *par)
- {
- int oidx = 0;
-
- oidx = atoi(newsplit(&par));
- if (!par[0])
- return;
- dprintf(oidx, "(%s) %s\n", botnick, par);
- }
- /* Newbot next share?
- */
- static void bot_nlinked(int idx, char *par)
- {
- char *newbot, *next, *p, s[1024], x;
- int bogus = 0, i;
- struct userrec *u;
- newbot = newsplit(&par);
- next = newsplit(&par);
- s[0] = 0;
- if (!next[0]) {
- putlog(LOG_BOTS, "*", "Invalid eggnet protocol from %s (zapfing)",
- dcc[idx].nick);
- simple_sprintf(s, "%s %s (%s)", MISC_DISCONNECTED, dcc[idx].nick,
- MISC_INVALIDBOT);
- dprintf(idx, "error invalid eggnet protocol for 'nlinked'\n");
- } else if ((in_chain(newbot)) || (!egg_strcasecmp(newbot, botnetnick))) {
- /* Loop! */
- putlog(LOG_BOTS, "*", "%s %s (mutual: %s)",
- BOT_LOOPDETECT, dcc[idx].nick, newbot);
- simple_sprintf(s, "%s %s: disconnecting %s", MISC_LOOP, newbot,
- dcc[idx].nick);
- dprintf(idx, "error Loop (%s)\n", newbot);
- }
- if (!s[0]) {
- for (p = newbot; *p; p++)
- if ((*p < 32) || (*p == 127) || ((p - newbot) >= HANDLEN))
- bogus = 1;
- i = nextbot(next);
- if (i != idx)
- bogus = 1;
- }
- if (bogus) {
- putlog(LOG_BOTS, "*", "%s %s! (%s -> %s)", BOT_BOGUSLINK, dcc[idx].nick,
- next, newbot);
- simple_sprintf(s, "%s: %s %s", BOT_BOGUSLINK, dcc[idx].nick,
- MISC_DISCONNECTED);
- dprintf(idx, "error %s (%s -> %s)\n",
- BOT_BOGUSLINK, next, newbot);
- }
- if (s[0]) {
- chatout("*** %s\n", s);
- botnet_send_unlinked(idx, dcc[idx].nick, s);
- dprintf(idx, "bye %s\n", BOT_ILLEGALLINK);
- killsock(dcc[idx].sock);
- lostdcc(idx);
- return;
- }
- x = par[0];
- if (x)
- par++;
- else
- x = '-';
- i = base64_to_int(par);
- botnet_send_nlinked(idx, newbot, next, x, i);
- if (x == '!') {
- #ifdef HUB
- chatout("*** (%s) %s %s.\n", next, NET_LINKEDTO, newbot);
- #else
- chatout("*** %s linked to botnet.\n", newbot);
- #endif
- x = '-';
- }
- addbot(newbot, dcc[idx].nick, next, x, i);
- check_tcl_link(newbot, next);
- u = get_user_by_handle(userlist, newbot);
- if (bot_flags(u) & BOT_REJECT) {
- botnet_send_reject(idx, botnetnick, NULL, newbot, NULL, NULL);
- putlog(LOG_BOTS, "*", "%s %s %s %s", BOT_REJECTING,
- newbot, MISC_FROM, dcc[idx].nick);
- }
- }
- static void bot_unlinked(int idx, char *par)
- {
- int i;
- char *bot;
- bot = newsplit(&par);
- i = nextbot(bot);
- if ((i >= 0) && (i != idx)) /* Bot is NOT downstream along idx, so
- * BOGUS! */
- fake_alert(idx, "direction", bot);
- else if (i >= 0) { /* Valid bot downstream of idx */
- if (par[0])
- //#ifdef HUB
- chatout("*** (%s) %s\n", lastbot(bot), par);
- //#else
- // chatout("*** %s unlinked from botnet.\n", par);
- //#endif
- botnet_send_unlinked(idx, bot, par);
- unvia(idx, findbot(bot));
- rembot(bot);
- }
- /* Otherwise it's not even a valid bot, so just ignore! */
- }
- /* trace <from@bot> <dest> <chain:chain..>
- */
- static void bot_trace(int idx, char *par)
- {
- char *from, *dest;
- int i;
- from = newsplit(&par);
- dest = newsplit(&par);
- simple_sprintf(TBUF, "%s:%s", par, botnetnick);
- botnet_send_traced(idx, from, TBUF);
- if (egg_strcasecmp(dest, botnetnick) && ((i = nextbot(dest)) > 0))
- botnet_send_trace(i, from, dest, par);
- }
- /* traced <to@bot> <chain:chain..>
- */
- static void bot_traced(int idx, char *par)
- {
- char *to, *p;
- int i, sock;
- to = newsplit(&par);
- p = strchr(to, '@');
- if (p == NULL)
- p = to;
- else {
- *p = 0;
- p++;
- }
- if (!egg_strcasecmp(p, botnetnick)) {
- time_t t = 0;
- char *p = par, *ss = TBUF;
- splitc(ss, to, ':');
- if (ss[0])
- sock = atoi(ss);
- else
- sock = (-1);
- if (par[0] == ':') {
- t = atoi(par + 1);
- p = strchr(par + 1, ':');
- if (p)
- p++;
- else
- p = par + 1;
- }
- for (i = 0; i < dcc_total; i++)
- if ((dcc[i].type->flags & DCT_CHAT) &&
- (!egg_strcasecmp(dcc[i].nick, to)) &&
- ((sock == (-1)) || (sock == dcc[i].sock))) {
- if (t) {
- int j=0;
- {
- register char *c=p;
- for (; *c != '\0'; c++) if (*c == ':') j++;
- }
- dprintf(i, "%s -> %s (%lu secs, %d hop%s)\n", BOT_TRACERESULT, p,
- now - t, j, (j != 1) ? "s" : "");
- } else
- dprintf(i, "%s -> %s\n", BOT_TRACERESULT, p);
- }
- } else {
- i = nextbot(p);
- if (p != to)
- *--p = '@';
- if (i >= 0)
- botnet_send_traced(i, to, par);
- }
- }
- void bot_timesync(int idx, char *par)
- {
- putlog(LOG_DEBUG, "@", "Got timesync from %s: %s\n", dcc[idx].nick, par);
- timesync = atoi(par) - now;
- #ifdef HUB
- send_timesync(-1);
- #endif
- }
- /* reject <from> <bot>
- */
- static void bot_reject(int idx, char *par)
- {
- char *from, *who, *destbot, *frombot;
- struct userrec *u;
- int i;
- if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
- return;
- from = newsplit(&par);
- frombot = strchr(from, '@');
- if (frombot)
- frombot++;
- else
- frombot = from;
- i = nextbot(frombot);
- if (i != idx) {
- fake_alert(idx, "direction", frombot);
- return;
- }
- who = newsplit(&par);
- if (!(destbot = strchr(who, '@'))) {
- /* Rejecting a bot */
- i = nextbot(who);
- if (i < 0) {
- botnet_send_priv(idx, botnetnick, from, NULL, "%s %s (%s)",
- BOT_CANTUNLINK, who, BOT_DOESNTEXIST);
- } else if (!egg_strcasecmp(dcc[i].nick, who)) {
- char s[1024];
- /* I'm the connection to the rejected bot */
- putlog(LOG_BOTS, "*", "%s %s %s", from, MISC_REJECTED, dcc[i].nick);
- dprintf(i, "bye %s\n", par[0] ? par : MISC_REJECTED);
- simple_sprintf(s, "%s %s (%s: %s)",
- MISC_DISCONNECTED, dcc[i].nick, from,
- par[0] ? par : MISC_REJECTED);
- chatout("*** %s\n", s);
- botnet_send_unlinked(i, dcc[i].nick, s);
- killsock(dcc[i].sock);
- lostdcc(i);
- } else {
- if (i >= 0)
- botnet_send_reject(i, from, NULL, who, NULL, par);
- }
- } else { /* Rejecting user */
- *destbot++ = 0;
- if (!egg_strcasecmp(destbot, botnetnick)) {
- /* Kick someone here! */
- int ok = 0;
- if (remote_boots == 1) {
- frombot = strchr(from, '@');
- if (frombot == NULL)
- frombot = from;
- else
- frombot++;
- u = get_user_by_handle(userlist, frombot);
- if (!(bot_flags(u) & BOT_SHARE)) {
- add_note(from, botnetnick, "No non sharebot boots.", -1, 0);
- ok = 1;
- }
- } else if (remote_boots == 0) {
- botnet_send_priv(idx, botnetnick, from, NULL, "%s",
- BOT_NOREMOTEBOOT);
- ok = 1;
- }
- for (i = 0; (i < dcc_total) && (!ok); i++)
- if ((!egg_strcasecmp(who, dcc[i].nick)) &&
- (dcc[i].type->flags & DCT_CHAT)) {
- u = get_user_by_handle(userlist, dcc[i].nick);
- if (u &&
- ((u->flags & USER_OWNER) && !(dcc[idx].user->flags & USER_ADMIN))) {
- add_note(from, botnetnick, BOT_NOOWNERBOOT, -1, 0);
- return;
- }
- do_boot(i, from, par);
- ok = 1;
- putlog(LOG_CMDS, "*", "#%s# boot %s (%s)", from, who,
- par[0] ? par : "No reason");
- }
- } else {
- i = nextbot(destbot);
- *--destbot = '@';
- if (i >= 0)
- botnet_send_reject(i, from, NULL, who, NULL, par);
- }
- }
- }
- static void bot_thisbot(int idx, char *par)
- {
- if (egg_strcasecmp(par, dcc[idx].nick)) {
- char s[1024];
- putlog(LOG_BOTS, "*", NET_WRONGBOT, dcc[idx].nick, par);
- dprintf(idx, "bye %s\n", MISC_IMPOSTER);
- simple_sprintf(s, "%s %s (%s)", MISC_DISCONNECTED, dcc[idx].nick,
- MISC_IMPOSTER);
- chatout("*** %s\n", s);
- botnet_send_unlinked(idx, dcc[idx].nick, s);
- unvia(idx, findbot(dcc[idx].nick));
- killsock(dcc[idx].sock);
- lostdcc(idx);
- return;
- }
- if (bot_flags(dcc[idx].user) & BOT_LEAF)
- dcc[idx].status |= STAT_LEAF;
- /* Set capitalization the way they want it */
- noshare = 1;
- change_handle(dcc[idx].user, par);
- noshare = 0;
- strcpy(dcc[idx].nick, par);
- }
- static void bot_hublog(char *botnick, char *code, char *par)
- {
- #ifdef HUB
- int type;
- type = atoi(newsplit(&par));
- putlog(type, "@", "(%s) %s", botnick, par);
- #endif
- }
- static void bot_handshake(int idx, char *par)
- {
- struct userrec *u = get_user_by_handle(userlist, dcc[idx].nick);
- /* We *don't* want botnet passwords migrating */
- noshare = 1;
- set_user(&USERENTRY_PASS, u, par);
- noshare = 0;
- }
- /* Used to send a direct msg from Tcl on one bot to Tcl on another
- * zapf <frombot> <tobot> <code [param]>
- */
- static void bot_zapf(int idx, char *par)
- {
- char *from, *to;
- int i;
- from = newsplit(&par);
- to = newsplit(&par);
- i = nextbot(from);
- if (i != idx) {
- fake_alert(idx, "direction", from);
- return;
- }
- if (!egg_strcasecmp(to, botnetnick)) {
- /* For me! */
- char *opcode;
- opcode = newsplit(&par);
- check_tcl_bot(from, opcode, par);
- return;
- }
- i = nextbot(to);
- if (i >= 0)
- botnet_send_zapf(i, from, to, par);
- }
- /* Used to send a global msg from Tcl on one bot to every other bot
- * zapf-broad <frombot> <code [param]>
- */
- static void bot_zapfbroad(int idx, char *par)
- {
- char *from, *opcode;
- int i;
- from = newsplit(&par);
- opcode = newsplit(&par);
- i = nextbot(from);
- if (i != idx) {
- fake_alert(idx, "direction", from);
- return;
- }
- check_tcl_bot(from, opcode, par);
- botnet_send_zapf_broad(idx, from, opcode, par);
- }
- /* These are still here, so that they will pass the relevant
- * requests through even if no filesys is loaded.
- *
- * filereject <bot:filepath> <sock:nick@bot> <reason...>
- */
- static void bot_filereject(int idx, char *par)
- {
- char *path, *to, *tobot, *p;
- int i;
- path = newsplit(&par);
- to = newsplit(&par);
- if ((tobot = strchr(to, '@')))
- tobot++;
- else
- tobot = to; /* Bot wants a file?! :) */
- if (egg_strcasecmp(tobot, botnetnick)) { /* for me! */
- p = strchr(to, ':');
- if (p != NULL) {
- *p = 0;
- for (i = 0; i < dcc_total; i++) {
- if (dcc[i].sock == atoi(to))
- dprintf(i, "%s (%s): %s\n", BOT_XFERREJECTED, path, par);
- }
- *p = ':';
- }
- /* No ':'? malformed */
- putlog(LOG_FILES, "*", "%s %s: %s", path, MISC_REJECTED, par);
- } else { /* Pass it on */
- i = nextbot(tobot);
- if (i >= 0)
- botnet_send_filereject(i, path, to, par);
- }
- }
- /* filereq <sock:nick@bot> <bot:file>
- */
- static void bot_filereq(int idx, char *tobot)
- {
- char *from, *path;
- int i;
- from = newsplit(&tobot);
- if ((path = strchr(tobot, ':'))) {
- *path++ = 0;
- if (!egg_strcasecmp(tobot, botnetnick)) { /* For me! */
- /* Process this */
- module_entry *fs = module_find("filesys", 0, 0);
- if (fs == NULL)
- botnet_send_priv(idx, botnetnick, from, NULL, MOD_NOFILESYSMOD);
- else {
- Function f = fs->funcs[FILESYS_REMOTE_REQ];
- f(idx, from, path);
- }
- } else { /* Pass it on */
- i = nextbot(tobot);
- if (i >= 0)
- botnet_send_filereq(i, from, tobot, path);
- }
- }
- }
- /* filesend <bot:path> <sock:nick@bot> <IP#> <port> <size>
- */
- static void bot_filesend(int idx, char *par)
- {
- char *botpath, *to, *tobot, *nick;
- int i;
- char *nfn;
- botpath = newsplit(&par);
- to = newsplit(&par);
- if ((tobot = strchr(to, '@'))) {
- *tobot = 0;
- tobot++;
- } else {
- tobot = to;
- }
- if (!egg_strcasecmp(tobot, botnetnick)) { /* For me! */
- nfn = strrchr(botpath, '/');
- if (nfn == NULL) {
- nfn = strrchr(botpath, ':');
- if (nfn == NULL)
- nfn = botpath; /* That's odd. */
- else
- nfn++;
- } else
- nfn++;
- if ((nick = strchr(to, ':')))
- nick++;
- else
- nick = to;
- /* Send it to 'nick' as if it's from me */
- dprintf(DP_SERVER, "PRIVMSG %s :\001DCC SEND %s %s\001\n", nick, nfn, par);
- } else {
- i = nextbot(tobot);
- if (i >= 0) {
- *--tobot = '@';
- botnet_send_filesend(i, botpath, to, par);
- }
- }
- }
- static void bot_error(int idx, char *par)
- {
- putlog(LOG_MISC | LOG_BOTS, "*", "%s: %s", dcc[idx].nick, par);
- }
- /* nc <bot> <sock> <newnick>
- */
- static void bot_nickchange(int idx, char *par)
- {
- char *bot, *ssock, *newnick;
- int sock, i;
- if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
- return;
- bot = newsplit(&par);
- i = nextbot(bot);
- if (i != idx) {
- fake_alert(idx, "direction", bot);
- return;
- }
- ssock = newsplit(&par);
- sock = base64_to_int(ssock);
- newnick = newsplit(&par);
- i = partynick(bot, sock, newnick);
- if (i < 0) {
- fake_alert(idx, "sock#", ssock);
- return;
- }
- chanout_but(-1, party[i].chan, "*** (%s) Nick change: %s -> %s\n",
- bot, newnick, party[i].nick);
- botnet_send_nkch_part(idx, i, newnick);
- }
- /* join <bot> <nick> <chan> <flag><sock> <from>
- */
- static void bot_join(int idx, char *par)
- {
- char *bot, *nick, *x, *y;
- struct userrec *u;
- int i, sock, chan, i2, linking = 0;
- if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
- return;
- bot = newsplit(&par);
- if (bot[0] == '!') {
- linking = 1;
- bot++;
- }
- if (b_status(idx) & STAT_LINKING) {
- linking = 1;
- }
- nick = newsplit(&par);
- x = newsplit(&par);
- chan = base64_to_int(x);
- y = newsplit(&par);
- if ((chan < 0) || !y[0])
- return; /* Woops! pre 1.2.1's send .chat off'ers
- * too!! */
- if (!y[0]) {
- y[0] = '-';
- sock = 0;
- } else {
- sock = base64_to_int(y + 1);
- }
- /* 1.1 bots always send a sock#, even on a channel change
- * so if sock# is 0, this is from an old bot and we must tread softly
- * grab old sock# if there is one, otherwise make up one.
- */
- if (sock == 0)
- sock = partysock(bot, nick);
- if (sock == 0)
- sock = fakesock++;
- i = nextbot(bot);
- if (i != idx) { /* Ok, garbage from a 1.0g (who uses that
- * now?) OR raistlin being evil :) */
- fake_alert(idx, "direction", bot);
- return;
- }
- u = get_user_by_handle(userlist, nick);
- if (u) {
- sprintf(TBUF, "@%s", bot);
- touch_laston(u, TBUF, now);
- }
- i = addparty(bot, nick, chan, y[0], sock, par, &i2);
- botnet_send_join_party(idx, linking, i2, i);
- if (i != chan) {
- if (i >= 0) {
- if (b_numver(idx) >= NEAT_BOTNET)
- chanout_but(-1, i, "*** (%s) %s %s %s.\n", bot, nick, NET_LEFTTHE,
- i ? "channel" : "party line");
- check_tcl_chpt(bot, nick, sock, i);
- }
- if ((b_numver(idx) >= NEAT_BOTNET) && !linking)
- chanout_but(-1, chan, "*** (%s) %s %s %s.\n", bot, nick, NET_JOINEDTHE,
- chan ? "channel" : "party line");
- check_tcl_chjn(bot, nick, chan, y[0], sock, par);
- }
- }
- /* part <bot> <nick> <sock> [etc..]
- */
- static void bot_part(int idx, char *par)
- {
- char *bot, *nick, *etc;
- struct userrec *u;
- int sock, partyidx;
- int silent = 0;
- if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
- return;
- bot = newsplit(&par);
- if (bot[0] == '!') {
- silent = 1;
- bot++;
- }
- nick = newsplit(&par);
- etc = newsplit(&par);
- sock = base64_to_int(etc);
- if (sock == 0)
- sock = partysock(bot, nick);
- u = get_user_by_handle(userlist, nick);
- if (u) {
- sprintf(TBUF, "@%s", bot);
- touch_laston(u, TBUF, now);
- }
- if ((partyidx = getparty(bot, sock)) != -1) {
- if (party[partyidx].chan >= 0)
- check_tcl_chpt(bot, nick, sock, party[partyidx].chan);
- if ((b_numver(idx) >= NEAT_BOTNET) && !silent) {
- register int chan = party[partyidx].chan;
- if (par[0])
- chanout_but(-1, chan, "*** (%s) %s %s %s (%s).\n", bot, nick,
- NET_LEFTTHE,
- chan ? "channel" : "party line", par);
- else
- chanout_but(-1, chan, "*** (%s) %s %s %s.\n", bot, nick,
- NET_LEFTTHE,
- chan ? "channel" : "party line");
- }
- botnet_send_part_party(idx, partyidx, par, silent);
- remparty(bot, sock);
- }
- }
- /* away <bot> <sock> <message>
- * null message = unaway
- */
- static void bot_away(int idx, char *par)
- {
- char *bot, *etc;
- int sock, partyidx, linking = 0;
- if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
- return;
- bot = newsplit(&par);
- if (bot[0] == '!') {
- linking = 1;
- bot++;
- }
- if (b_status(idx) & STAT_LINKING) {
- linking = 1;
- }
- etc = newsplit(&par);
- sock = base64_to_int(etc);
- if (sock == 0)
- sock = partysock(bot, etc);
- check_tcl_away(bot, sock, par);
- if (par[0]) {
- partystat(bot, sock, PLSTAT_AWAY, 0);
- partyaway(bot, sock, par);
- } else {
- partystat(bot, sock, 0, PLSTAT_AWAY);
- }
- partyidx = getparty(bot, sock);
- if ((b_numver(idx) >= NEAT_BOTNET) && !linking) {
- if (par[0])
- chanout_but(-1, party[partyidx].chan,
- "*** (%s) %s %s: %s.\n", bot,
- party[partyidx].nick, NET_AWAY, par);
- else
- chanout_but(-1, party[partyidx].chan,
- "*** (%s) %s %s.\n", bot,
- party[partyidx].nick, NET_UNAWAY);
- }
- botnet_send_away(idx, bot, sock, par, linking);
- }
- /* (a courtesy info to help during connect bursts)
- * idle <bot> <sock> <#secs> [away msg]
- */
- static void bot_idle(int idx, char *par)
- {
- char *bot, *work;
- int sock, idle;
- if (bot_flags(dcc[idx].user) & BOT_ISOLATE)
- return;
- bot = newsplit(&par);
- work = newsplit(&par);
- sock = base64_to_int(work);
- if (sock == 0)
- sock = partysock(bot, work);
- work = newsplit(&par);
- idle = base64_to_int(work);
- partysetidle(bot, sock, idle);
- if (par[0]) {
- partystat(bot, sock, PLSTAT_AWAY, 0);
- partyaway(bot, sock, par);
- }
- botnet_send_idle(idx, bot, sock, idle, par);
- }
- void bot_share(int idx, char *par)
- {
- sharein(idx, par);
- }
- void bot_shareupdate(int idx, char *par)
- {
- shareupdatein(idx, par);
- }
- /* v <frombot> <tobot> <idx:nick>
- */
- static void bot_versions(int sock, char *par)
- {
- char *frombot = newsplit(&par), *tobot, *from;
- module_entry *me;
- if (nextbot(frombot) != sock)
- fake_alert(sock, "versions-direction", frombot);
- else if (egg_strcasecmp(tobot = newsplit(&par), botnetnick)) {
- if ((sock = nextbot(tobot)) >= 0)
- dprintf(sock, "v %s %s %s\n", frombot, tobot, par);
- } else {
- from = newsplit(&par);
- botnet_send_priv(sock, botnetnick, from, frombot, "Modules loaded:\n");
- for (me = module_list; me; me = me->next)
- botnet_send_priv(sock, botnetnick, from, frombot, " Module: %s (v%d.%d)\n",
- me->name, me->major, me->minor);
- botnet_send_priv(sock, botnetnick, from, frombot, "End of module list.\n");
- }
- }
- /* BOT COMMANDS
- *
- * function call should be:
- * int bot_whatever(idx,"parameters");
- *
- * SORT these, dcc_bot uses a shortcut which requires them sorted
- *
- * yup, those are tokens there to allow a more efficient botnet as
- * time goes on (death to slowly upgrading llama's)
- */
- botcmd_t C_bot[] =
- {
- {"a", (Function) bot_actchan},
- {"aw", (Function) bot_away},
- {"away", (Function) bot_away},
- {"bye", (Function) bot_bye},
- {"c", (Function) bot_chan2},
- {"cg", (Function) bot_config},
- #ifdef S_DCCPASS
- {"cp", (Function) bot_cmdpass},
- #endif
- {"ct", (Function) bot_chat},
- {"e", (Function) bot_error},
- {"el", (Function) bot_endlink},
- {"f!", (Function) bot_filereject},
- {"fr", (Function) bot_filereq},
- {"fs", (Function) bot_filesend},
- {"hs", (Function) bot_handshake},
- {"i", (Function) bot_idle},
- {"i?", (Function) bot_infoq},
- {"j", (Function) bot_join},
- {"l", (Function) bot_link},
- {"n", (Function) bot_nlinked},
- {"nc", (Function) bot_nickchange},
- {"p", (Function) bot_priv},
- {"pi", (Function) bot_ping},
- {"po", (Function) bot_pong},
- {"pt", (Function) bot_part},
- {"r", (Function) bot_reject},
- {"rc", (Function) bot_remotecmd},
- {"rr", (Function) bot_remotereply},
- {"s", (Function) bot_share},
- {"sb", (Function) bot_shareupdate},
- {"t", (Function) bot_trace},
- {"tb", (Function) bot_thisbot},
- {"td", (Function) bot_traced},
- {"ts", (Function) bot_timesync},
- {"u", (Function) bot_update},
- {"ul", (Function) bot_unlink},
- {"un", (Function) bot_unlinked},
- {"v", (Function) bot_versions},
- {"vs", (Function) bot_sysname},
- {"w", (Function) bot_who},
- {"z", (Function) bot_zapf},
- {"zb", (Function) bot_zapfbroad},
- {NULL, NULL}
- };
- void send_remote_simul(int idx, char *bot, char *cmd, char *par)
- {
- char msg[SGRAB-110];
- snprintf(msg, sizeof msg, "r-s %d %s %d %s %s %s", idx, dcc[idx].nick, dcc[idx].u.chat->con_flags, dcc[idx].u.chat->con_chan, cmd, par);
- putbot(bot, msg);
- }
- /* idx nick conmask cmd par */
- static void bot_rsim(char *botnick, char *code, char *par)
- {
- int ridx = -1, idx = -1, i = 0, rconmask;
- char *nick = NULL, *cmd = NULL, *rconchan = NULL, buf[UHOSTMAX];
- ridx = atoi(newsplit(&par));
- nick = newsplit(&par);
- rconmask = atoi(newsplit(&par));
- rconchan = newsplit(&par);
- cmd = newsplit(&par);
- if (ridx < 0 || !nick || !cmd)
- return;
- for (i = 0; i < dcc_total; i++) {
- if (dcc[i].simul == ridx) {
- putlog(LOG_DEBUG, "*", "Simul found old idx for %s: %d (ridx: %d)", nick, i, ridx);
- dcc[i].simultime = now;
- idx = i;
- break;
- }
- }
- if (idx < 0) {
- idx = new_dcc(&DCC_CHAT, sizeof(struct chat_info));
- putlog(LOG_DEBUG, "*", "Making new idx for %s@%s: %d ridx: %d", nick, botnick, idx, ridx);
- /* dcc[idx].sock = 666; */
- dcc[idx].timeval = now;
- dcc[idx].simultime = now;
- dcc[idx].simul = ridx;
- strcpy(dcc[idx].simulbot, botnick);
- dcc[idx].status = STAT_ECHO;
- dcc[idx].u.chat->con_flags = rconmask;
- strcpy(dcc[idx].u.chat->con_chan, rconchan);
- dcc[idx].u.chat->strip_flags = STRIP_ALL;
- strcpy(dcc[idx].nick, nick);
- snprintf(buf, sizeof buf, "%s@%s", nick, botnick);
- strcpy(dcc[idx].host, buf);
- dcc[idx].addr = 0;
- dcc[idx].user = get_user_by_handle(userlist, nick);
- }
- check_tcl_dcc(cmd, idx, par);
- }
- void bounce_simul(int idx, char *buf)
- {
- char rmsg[SGRAB-110];
- if (!buf || !buf[0] || !dcc[idx].simulbot || !dcc[idx].simulbot[0] || idx < 0) {
- return;
- }
- snprintf(rmsg, sizeof rmsg, "r-sr %d %s", dcc[idx].simul, buf); /* remote-simul[r]eturn idx buf */
- putbot(dcc[idx].simulbot, rmsg);
- }
- #ifdef HUB
- static void bot_rsimr(char *botnick, char *code, char *par)
- {
- int idx;
- idx = atoi(newsplit(&par));
- if (!par[0])
- return;
- dprintf(idx, "[%s] %s\n", botnick, par);
- }
- #endif /* HUB */
- static cmd_t my_bot[] =
- {
- {"hl", "", (Function) bot_hublog, NULL},
- {"mt", "", (Function) bot_mtcl, NULL},
- {"r_mt", "", (Function) bot_rmtcl, NULL},
- #ifdef HUB /* This will only allow hubs to read the return text */
- {"r-sr", "", (Function) bot_rsimr, NULL},
- #endif /* HUB */
- {"r-s", "", (Function) bot_rsim, NULL},
- {NULL, NULL, NULL, NULL}
- };
- void init_botcmd()
- {
- add_builtins(H_bot, my_bot);
- }
|