| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473 |
- /*
- * share.c -- part of share.mod
- *
- */
- #include "src/common.h"
- #include "src/main.h"
- #include "src/rfc1459.h"
- #include "src/botmsg.h"
- #include "src/misc.h"
- #include "src/misc_file.h"
- #include "src/cmds.h"
- #include "src/chanprog.h"
- #include "src/users.h"
- #include "src/userrec.h"
- #include "src/botnet.h"
- #include "src/auth.h"
- #include "src/set.h"
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <sys/stat.h>
- #include <stdarg.h>
- #include "src/chan.h"
- #include "src/net.h"
- #include "src/users.h"
- #include "src/egg_timer.h"
- #include "src/mod/transfer.mod/transfer.h"
- #include "src/mod/channels.mod/channels.h"
- #include "src/mod/irc.mod/irc.h"
- #include "src/mod/server.mod/server.h"
- static struct flag_record fr = { 0, 0, 0, 0 };
- struct delay_mode {
- struct delay_mode *next;
- struct chanset_t *chan;
- int plsmns;
- int mode;
- int seconds;
- char *mask;
- };
- static struct delay_mode *start_delay = NULL;
- /* Prototypes */
- static void start_sending_users(int);
- static void shareout_but(int, const char *, ...) __attribute__ ((format(printf, 2, 3)));
- static void cancel_user_xfer(int, void *);
- #include "share.h"
- /*
- * Resync buffers
- */
- /* Store info for sharebots */
- struct share_msgq {
- struct share_msgq *next;
- char *msg;
- };
- typedef struct tandbuf_t {
- struct tandbuf_t *next;
- struct share_msgq *q;
- time_t timer;
- char bot[HANDLEN + 1];
- } tandbuf;
- tandbuf *tbuf = NULL;
- /* Create a tandem buffer for 'bot'.
- */
- static void new_tbuf(char *bot)
- {
- tandbuf **old = &tbuf, *newbuf = NULL;
- newbuf = (tandbuf *) my_calloc(1, sizeof(tandbuf));
- strcpy(newbuf->bot, bot);
- newbuf->q = NULL;
- newbuf->timer = now;
- newbuf->next = *old;
- *old = newbuf;
- putlog(LOG_BOTS, "*", "Creating resync buffer for %s", bot);
- }
- static void del_tbuf(tandbuf *goner)
- {
- struct share_msgq *q = NULL, *r = NULL;
- tandbuf *t = NULL, *old = NULL;
- for (t = tbuf; t; old = t, t = t->next) {
- if (t == goner) {
- if (old)
- old->next = t->next;
- else
- tbuf = t->next;
- for (q = t->q; q && q->msg[0]; q = r) {
- r = q->next;
- free(q->msg);
- free(q);
- }
- free(t);
- break;
- }
- }
- }
- /* Flush a certain bot's tbuf.
- */
- static bool flush_tbuf(char *bot)
- {
- tandbuf *t = NULL, *tnext = NULL;
- for (t = tbuf; t; t = tnext) {
- tnext = t->next;
- if (!egg_strcasecmp(t->bot, bot)) {
- del_tbuf(t);
- return 1;
- }
- }
- return 0;
- }
- static struct share_msgq *q_addmsg(struct share_msgq *qq, char *s)
- {
- struct share_msgq *q = NULL;
- int cnt;
- if (!qq) {
- q = (share_msgq *) my_calloc(1, sizeof *q);
- q->next = NULL;
- q->msg = (char *) my_calloc(1, strlen(s) + 1);
- strcpy(q->msg, s);
- return q;
- }
- cnt = 0;
- for (q = qq; q->next; q = q->next)
- cnt++;
- if (cnt > 1000)
- return NULL; /* Return null: did not alter queue */
- q->next = (share_msgq *) my_calloc(1, sizeof *q->next);
- q = q->next;
- q->next = NULL;
- q->msg = (char *) my_calloc(1, strlen(s) + 1);
- strcpy(q->msg, s);
- return qq;
- }
- /* Add stuff to a specific bot's tbuf.
- */
- static void q_tbuf(char *bot, char *s)
- {
- struct share_msgq *q = NULL;
- tandbuf *t = NULL;
- for (t = tbuf; t && t->bot[0]; t = t->next)
- if (!egg_strcasecmp(t->bot, bot)) {
- if ((q = q_addmsg(t->q, s)))
- t->q = q;
- break;
- }
- }
- /* Add stuff to the resync buffers.
- */
- static void q_resync(char *s)
- {
- struct share_msgq *q = NULL;
- tandbuf *t = NULL;
- for (t = tbuf; t && t->bot[0]; t = t->next) {
- if ((q = q_addmsg(t->q, s)))
- t->q = q;
- }
- }
- /* Dump the resync buffer for a bot.
- */
- void dump_resync(int idx)
- {
- struct share_msgq *q = NULL;
- tandbuf *t = NULL;
- for (t = tbuf; t && t->bot[0]; t = t->next)
- if (!egg_strcasecmp(dcc[idx].nick, t->bot)) {
- for (q = t->q; q && q->msg[0]; q = q->next) {
- dprintf(idx, "%s", q->msg);
- }
- flush_tbuf(dcc[idx].nick);
- break;
- }
- }
- /*
- * Sup's delay code
- */
- static void
- add_delay(struct chanset_t *chan, int plsmns, int mode, char *mask)
- {
- struct delay_mode *d = (struct delay_mode *) my_calloc(1, sizeof(struct delay_mode));
- d->chan = chan;
- d->plsmns = plsmns;
- d->mode = mode;
- d->mask = (char *) my_calloc(1, strlen(mask) + 1);
- strncpy(d->mask, mask, strlen(mask) + 1);
- d->seconds = (int) (now + randint(20));
- d->next = start_delay;
- start_delay = d;
- }
- static void
- del_delay(struct delay_mode *delay)
- {
- struct delay_mode *old = NULL;
- for (struct delay_mode *d = start_delay; d; old = d, d = d->next) {
- if (d == delay) {
- if (old)
- old->next = d->next;
- else
- start_delay = d->next;
- if (d->mask)
- free(d->mask);
- free(d);
- break;
- }
- }
- }
- static void
- check_delay()
- {
- struct delay_mode *dnext = NULL;
- for (struct delay_mode *d = start_delay; d; d = dnext) {
- dnext = d->next;
- if (d->seconds <= now) {
- add_mode(d->chan, d->plsmns, d->mode, d->mask);
- del_delay(d);
- }
- }
- }
- /*
- * Botnet commands
- */
- static void
- share_stick_mask(int idx, char *par)
- {
- if (dcc[idx].status & STAT_SHARE) {
- char *types = newsplit(&par);
- const char type = types[0];
- const char *str_type = (type == 'b' ? "ban" : type == 'e' ? "exempt" : "invite");
- char *host = NULL, *val = NULL;
- bool yn = 0;
- struct chanset_t *chan = NULL;
- maskrec *channel_list = NULL;
- host = newsplit(&par);
- val = newsplit(&par);
- yn = atoi(val);
- noshare = 1;
- if (!par[0]) { /* Global ban */
- channel_list = (type == 'b' ? global_bans : type == 'e' ? global_exempts : global_invites);
- if (u_setsticky_mask(NULL, channel_list, host, yn, type) > 0) {
- if (conf.bot->hub)
- putlog(LOG_CMDS, "@", "%s: %s %s %s", dcc[idx].nick, (yn) ? "stick" : "unstick", str_type, host);
- else
- for (chan = chanset; chan ; chan = chan->next)
- check_this_mask(type, chan, host, yn);
- shareout_but(idx, "ms %c %s %d\n", type, host, yn);
- }
- } else {
- if ((chan = findchan_by_dname(par))) {
- channel_list = (type == 'b' ? chan->bans : type == 'e' ? chan->exempts : chan->invites);
- if (u_setsticky_mask(chan, channel_list, host, yn, type) > 0) {
- if (conf.bot->hub)
- putlog(LOG_CMDS, "@", "%s: %s %s %s %s", dcc[idx].nick, (yn) ? "stick" : "unstick", str_type, host, par);
- else
- check_this_mask(type, chan, host, yn);
- shareout_but(idx, "ms %c %s %d %s\n", type, host, yn, chan->dname);
- noshare = 0;
- return;
- }
- }
- putlog(LOG_CMDS, "@", "Rejecting invalid sticky %s: %s on %s%s", host, par, yn ? "" : " (unstick)", str_type);
- }
- noshare = 0;
- }
- }
- static void
- share_chhand(int idx, char *par)
- {
- if (dcc[idx].status & STAT_SHARE) {
- char *hand = NULL;
- struct userrec *u = NULL;
- hand = newsplit(&par);
- u = get_user_by_handle(userlist, hand);
- if (u) {
- int value = 0;
- shareout_but(idx, "h %s %s\n", hand, par);
- noshare = 1;
- value = change_handle(u, par);
- noshare = 0;
- if (value && conf.bot->hub)
- putlog(LOG_CMDS, "@", "%s: handle %s->%s", dcc[idx].nick, hand, par);
- }
- }
- }
- static void
- share_chattr(int idx, char *par)
- {
- if (dcc[idx].status & STAT_SHARE) {
- char *hand = NULL, *atr = NULL, s[100] = "";
- struct chanset_t *cst = NULL;
- struct userrec *u = NULL;
- struct flag_record fr2;
- flag_t ofl;
- hand = newsplit(&par);
- u = get_user_by_handle(userlist, hand);
- if (u) {
- atr = newsplit(&par);
- cst = findchan_by_dname(par);
- if (!par[0] || cst) {
- if (!(dcc[idx].status & STAT_GETTING))
- shareout_but(idx, "a %s %s %s\n", hand, atr, par);
- noshare = 1;
- if (par[0] && cst) {
- fr.match = FR_CHAN;
- fr2.match = FR_CHAN;
- break_down_flags(atr, &fr, 0);
- get_user_flagrec(u, &fr2, par);
- set_user_flagrec(u, &fr, par);
- noshare = 0;
- check_dcc_chanattrs(u, par, fr.chan, fr2.chan);
- build_flags(s, &fr, 0);
- if (conf.bot->hub) {
- if (!(dcc[idx].status & STAT_GETTING))
- putlog(LOG_CMDS, "@", "%s: chattr %s %s %s", dcc[idx].nick, hand, s, par);
- } else
- recheck_channel(cst, 0);
- } else {
- fr.match = FR_GLOBAL;
- get_user_flagrec(dcc[idx].user, &fr, 0);
- /* Don't let bot flags be altered */
- ofl = fr.global;
- break_down_flags(atr, &fr, 0);
- fr.global = sanity_check(fr.global, u->bot);
- set_user_flagrec(u, &fr, 0);
- noshare = 0;
- check_dcc_attrs(u, ofl);
- build_flags(s, &fr, 0);
- fr.match = FR_CHAN;
- if (conf.bot->hub) {
- if (!(dcc[idx].status & STAT_GETTING))
- putlog(LOG_CMDS, "@", "%s: chattr %s %s", dcc[idx].nick, hand, s);
- } else {
- for (cst = chanset; cst; cst = cst->next)
- recheck_channel(cst, 0);
- }
- }
- noshare = 0;
- }
- if (conf.bot->hub)
- write_userfile(-1);
- }
- }
- }
- static void
- share_pls_chrec(int idx, char *par)
- {
- if (dcc[idx].status & STAT_SHARE) {
- char *user = NULL;
- struct chanset_t *chan = NULL;
- struct userrec *u = NULL;
- user = newsplit(&par);
- if ((u = get_user_by_handle(userlist, user))) {
- chan = findchan_by_dname(par);
- noshare = 1;
- shareout_but(idx, "+cr %s %s\n", user, par);
- if (!get_chanrec(u, par)) {
- add_chanrec(u, par);
- if (conf.bot->hub)
- putlog(LOG_CMDS, "@", "%s: +chrec %s %s", dcc[idx].nick, user, par);
- }
- noshare = 0;
- }
- }
- }
- static void
- share_mns_chrec(int idx, char *par)
- {
- if (dcc[idx].status & STAT_SHARE) {
- char *user = NULL;
- struct chanset_t *chan = NULL;
- struct userrec *u = NULL;
- user = newsplit(&par);
- if ((u = get_user_by_handle(userlist, user))) {
- chan = findchan_by_dname(par);
- noshare = 1;
- del_chanrec(u, par);
- shareout_but(idx, "-cr %s %s\n", user, par);
- noshare = 0;
- if (conf.bot->hub)
- putlog(LOG_CMDS, "@", "%s: -chrec %s %s", dcc[idx].nick, user, par);
- else
- recheck_channel(chan, 0);
- }
- }
- }
- static void
- share_newuser(int idx, char *par)
- {
- if (dcc[idx].status & STAT_SHARE) {
- char *nick = NULL, *host = NULL, *pass = NULL;
- bool isbot = 0;
- struct userrec *u = NULL;
- nick = newsplit(&par);
- host = newsplit(&par);
- pass = newsplit(&par);
-
- if (nick[0] == '-') {
- isbot = 1;
- nick++;
- }
- if (!(u = get_user_by_handle(userlist, nick))) {
- char s[100] = "";
- fr.global = 0;
- fr.match = FR_GLOBAL;
- break_down_flags(par, &fr, NULL);
- /* If user already exists, ignore command */
- shareout_but(idx, "n %s%s %s %s %s\n", isbot ? "-" : "", nick, host, pass, par);
- if (strlen(nick) > HANDLEN)
- nick[HANDLEN] = 0;
- fr.match = FR_GLOBAL;
- build_flags(s, &fr, 0);
- noshare = 1;
- userlist = adduser(userlist, nick, host, pass, 0, isbot);
- /* Support for userdefinedflag share - drummer */
- u = get_user_by_handle(userlist, nick);
- set_user_flagrec(u, &fr, 0);
- noshare = 0;
- if (conf.bot->hub)
- putlog(LOG_CMDS, "@", "%s: newuser %s %s", dcc[idx].nick, nick, s);
- }
- }
- }
- static void
- share_killuser(int idx, char *par)
- {
- struct userrec *u = NULL;
- /* If user is a share bot, ignore command */
- if ((dcc[idx].status & STAT_SHARE) && (u = get_user_by_handle(userlist, par))) {
- noshare = 1;
- if (deluser(par)) {
- shareout_but(idx, "k %s\n", par);
- if (conf.bot->hub)
- putlog(LOG_CMDS, "@", "%s: killuser %s", dcc[idx].nick, par);
- }
- noshare = 0;
- }
- }
- static void
- share_pls_host(int idx, char *par)
- {
- if (dcc[idx].status & STAT_SHARE) {
- char *hand = NULL;
- struct userrec *u = NULL;
- hand = newsplit(&par);
- if ((u = get_user_by_handle(userlist, hand))) {
- shareout_but(idx, "+h %s %s\n", hand, par);
- set_user(&USERENTRY_HOSTS, u, par);
- if (conf.bot->hub)
- putlog(LOG_CMDS, "@", "%s: +host %s %s", dcc[idx].nick, hand, par);
- else
- check_this_user(u->handle, 0, NULL);
- }
- }
- }
- static void
- share_pls_bothost(int idx, char *par)
- {
- if (dcc[idx].status & STAT_SHARE) {
- char *hand = NULL;
- struct userrec *u = NULL;
- hand = newsplit(&par);
- u = get_user_by_handle(userlist, hand);
- if (!(dcc[idx].status & STAT_GETTING))
- shareout_but(idx, "+bh %s %s\n", hand, par);
- /* Add bot to userlist if not there */
- if (u) {
- if (!u->bot)
- return; /* ignore */
- set_user(&USERENTRY_HOSTS, u, par);
- } else {
- userlist = adduser(userlist, hand, par, "-", 0, 1);
- }
- if (conf.bot->hub && !(dcc[idx].status & STAT_GETTING))
- putlog(LOG_CMDS, "@", "%s: +host %s %s", dcc[idx].nick, hand, par);
- }
- }
- static void
- share_mns_host(int idx, char *par)
- {
- if (dcc[idx].status & STAT_SHARE) {
- char *hand = NULL;
- struct userrec *u = NULL;
- hand = newsplit(&par);
- if ((u = get_user_by_handle(userlist, hand))) {
- shareout_but(idx, "-h %s %s\n", hand, par);
- noshare = 1;
- delhost_by_handle(hand, par);
- noshare = 0;
- if (conf.bot->hub)
- putlog(LOG_CMDS, "@", "%s: -host %s %s", dcc[idx].nick, hand, par);
- else
- check_this_user(hand, 2, par);
- }
- }
- }
- static void
- share_change(int idx, char *par)
- {
- if (dcc[idx].status & STAT_SHARE) {
- char *key = NULL, *hand = NULL;
- struct userrec *u = NULL;
- struct user_entry_type *uet = NULL;
- struct user_entry *e = NULL;
- key = newsplit(&par);
- hand = newsplit(&par);
- u = get_user_by_handle(userlist, hand);
- if (!(uet = find_entry_type(key)))
- /* If it's not a supported type, forget it */
- putlog(LOG_ERROR, "*", "Ignore ch %s from %s (unknown type)", key, dcc[idx].nick);
- else {
- if (!(dcc[idx].status & STAT_GETTING))
- shareout_but(idx, "c %s %s %s\n", key, hand, par);
- noshare = 1;
- if (!u && (uet == &USERENTRY_BOTADDR)) {
- char pass[30] = "";
- makepass(pass);
- userlist = adduser(userlist, hand, "none", pass, 0, 1);
- u = get_user_by_handle(userlist, hand);
- } else if (!u) {
- noshare = 0;
- return;
- }
- if (uet->got_share) {
- if (!(e = find_user_entry(uet, u))) {
- e = (struct user_entry *) my_calloc(1, sizeof(struct user_entry));
- e->type = uet;
- e->name = NULL;
- e->u.list = NULL;
- list_insert((&(u->entries)), e);
- }
- uet->got_share(u, e, par, idx);
- if (!e->u.list) {
- list_delete((struct list_type **) &(u->entries), (struct list_type *) e);
- free(e);
- }
- }
- noshare = 0;
- }
- }
- }
- static void
- share_chchinfo(int idx, char *par)
- {
- if (dcc[idx].status & STAT_SHARE) {
- char *hand = NULL, *chan = NULL;
- struct chanset_t *cst = NULL;
- struct userrec *u = NULL;
- hand = newsplit(&par);
- if ((u = get_user_by_handle(userlist, hand))) {
- chan = newsplit(&par);
- cst = findchan_by_dname(chan);
- shareout_but(idx, "chchinfo %s %s %s\n", hand, chan, par);
- noshare = 1;
- set_handle_chaninfo(userlist, hand, chan, par);
- noshare = 0;
- if (conf.bot->hub)
- putlog(LOG_CMDS, "@", "%s: change info %s %s", dcc[idx].nick, chan, hand);
- }
- }
- }
- static void share_mns_mask(int idx, char *par)
- {
- if (dcc[idx].status & STAT_SHARE) {
- char *types = newsplit(&par);
- const char type = types[0];
- shareout_but(idx, "-m %c %s\n", type, par);
- if (conf.bot->hub)
- putlog(LOG_CMDS, "@", "%s: cancel %s %s", dcc[idx].nick, type == 'b' ? "ban" : type == 'e' ? "exempt" : "invite", par);
- str_unescape(par, '\\');
- noshare = 1;
- if (u_delmask(type, NULL, par, 1) > 0) {
- if (!conf.bot->hub) {
- struct chanset_t *chan = NULL;
- masklist *channel_list = NULL;
-
- for (chan = chanset; chan; chan = chan->next) {
- channel_list = (type == 'b' ? chan->channel.ban : type == 'e' ?
- chan->channel.exempt : chan->channel.invite);
- if (channel_list && !ismasked(channel_list, par))
- add_delay(chan, '-', type, par);
- }
- }
- }
- noshare = 0;
- }
- }
- static void share_mns_maskchan(int idx, char *par)
- {
- if (dcc[idx].status & STAT_SHARE) {
- char *types = newsplit(&par);
- const char type = types[0];
- char *chname = NULL;
- struct chanset_t *chan = NULL;
- int value = 0;
- chname = newsplit(&par);
- chan = findchan_by_dname(chname);
- shareout_but(idx, "-mc %c %s %s\n", type, chname, par);
- if (conf.bot->hub)
- putlog(LOG_CMDS, "@", "%s: cancel %s %s on %s", dcc[idx].nick,
- type == 'b' ? "ban" : type == 'e' ? "exempt" : "invite", par, chname);
- str_unescape(par, '\\');
- noshare = 1;
- value = u_delmask(type, chan, par, 1);
- noshare = 0;
- if (!conf.bot->hub && value > 0)
- add_delay(chan, '-', type, par);
- }
- }
- static void share_pls_mask(int idx, char *par)
- {
- if (dcc[idx].status & STAT_SHARE) {
- char *types = newsplit(&par);
- const char type = types[0];
- const char *str_type = (type == 'b' ? "ban" : type == 'e' ? "exempt" : "invite");
- time_t expire_time;
- char *mask = NULL, *tm = NULL, *from = NULL;
- int flags = 0;
- bool stick = 0;
- shareout_but(idx, "+m %c %s\n", type, par);
- mask = newsplit(&par);
- str_unescape(mask, '\\');
- tm = newsplit(&par);
- from = newsplit(&par);
- if (strchr(from, 's')) {
- flags |= MASKREC_STICKY;
- stick = 1;
- }
- if (strchr(from, 'p'))
- flags |= MASKREC_PERM;
- from = newsplit(&par);
- expire_time = (time_t) atoi(tm);
- if (expire_time != 0L)
- expire_time += now;
- noshare = 1;
- u_addmask(type, NULL, mask, from, par, expire_time, flags);
- noshare = 0;
- if (conf.bot->hub)
- putlog(LOG_CMDS, "@", "%s: global %s %s (%s:%s)", dcc[idx].nick, str_type, mask, from, par);
- else {
- for (struct chanset_t *chan = chanset; chan != NULL; chan = chan->next)
- check_this_mask(type, chan, mask, stick);
- }
- }
- }
- static void share_pls_maskchan(int idx, char *par)
- {
- if (dcc[idx].status & STAT_SHARE) {
- char *types = newsplit(&par);
- const char type = types[0];
- const char *str_type = (type == 'b' ? "ban" : type == 'e' ? "exempt" : "invite");
- time_t expire_time;
- int flags = 0;
- char *mask = NULL, *tm = NULL, *chname = NULL, *from = NULL;
- bool stick = 0;
- struct chanset_t *chan = NULL;
- mask = newsplit(&par);
- tm = newsplit(&par);
- chname = newsplit(&par);
- chan = findchan_by_dname(chname);
- shareout_but(idx, "+mc %c %s %s %s %s\n", type, mask, tm, chname, par);
- str_unescape(mask, '\\');
- from = newsplit(&par);
- if (strchr(from, 's')) {
- flags |= MASKREC_STICKY;
- stick = 1;
- }
- if (strchr(from, 'p'))
- flags |= MASKREC_PERM;
- from = newsplit(&par);
- if (conf.bot->hub)
- putlog(LOG_CMDS, "@", "%s: %s %s on %s (%s:%s)", dcc[idx].nick, str_type, mask, chname, from, par);
- expire_time = (time_t) atoi(tm);
- if (expire_time != 0L)
- expire_time += now;
- noshare = 1;
- u_addmask(type, chan, mask, from, par, expire_time, flags);
- noshare = 0;
- if (!conf.bot->hub)
- check_this_mask(type, chan, mask, stick);
- }
- }
- static void
- share_mns_ignore(int idx, char *par)
- {
- if (dcc[idx].status & STAT_SHARE) {
- shareout_but(idx, "-i %s\n", par);
- if (conf.bot->hub)
- putlog(LOG_CMDS, "@", "%s: cancel ignore %s", dcc[idx].nick, par);
- str_unescape(par, '\\');
- noshare = 1;
- delignore(par);
- noshare = 0;
- }
- }
- /* +i <host> +<seconds-left> <from> <note>
- */
- static void
- share_pls_ignore(int idx, char *par)
- {
- if (dcc[idx].status & STAT_SHARE) {
- time_t expire_time;
- char *ign = NULL, *from = NULL, *ts = NULL;
- shareout_but(idx, "+i %s\n", par);
- ign = newsplit(&par);
- str_unescape(ign, '\\');
- ts = newsplit(&par);
- if (!atoi(ts))
- expire_time = 0L;
- else
- expire_time = now + atoi(ts);
- from = newsplit(&par);
- if (strchr(from, 'p'))
- expire_time = 0;
- from = newsplit(&par);
- if (strlen(from) > HANDLEN + 1)
- from[HANDLEN + 1] = 0;
- par[65] = 0;
- if (conf.bot->hub)
- putlog(LOG_CMDS, "@", "%s: ignore %s (%s: %s)", dcc[idx].nick, ign, from, par);
- noshare = 1;
- addignore(ign, from, (const char *) par, expire_time);
- noshare = 0;
- }
- }
- static void
- share_ufno(int idx, char *par)
- {
- putlog(LOG_BOTS, "@", "User file rejected by %s: %s", dcc[idx].nick, par);
- dcc[idx].status &= ~STAT_OFFERED;
- if (!(dcc[idx].status & STAT_GETTING))
- dcc[idx].status &= ~(STAT_SHARE | STAT_AGGRESSIVE);
- }
- static void
- share_ufyes(int idx, char *par)
- {
- if (dcc[idx].status & STAT_OFFERED) {
- dcc[idx].status &= ~STAT_OFFERED;
- dcc[idx].status |= STAT_SHARE;
- dcc[idx].status |= STAT_SENDING;
- dcc[idx].u.bot->uff_flags |= (UFF_OVERRIDE | UFF_INVITE | UFF_EXEMPT);
- dprintf(idx, "s feats overbots invites exempts\n");
- lower_bot_linked(idx);
- start_sending_users(idx);
- putlog(LOG_BOTS, "@", "Sending user file send request to %s", dcc[idx].nick);
- }
- }
- static void
- share_userfileq(int idx, char *par)
- {
- flush_tbuf(dcc[idx].nick);
- if (bot_aggressive_to(dcc[idx].user)) {
- putlog(LOG_ERRORS, "*", "%s offered user transfer - I'm supposed to be aggressive to it", dcc[idx].nick);
- dprintf(idx, "s un I have you marked for Agressive sharing.\n");
- botunlink(-2, dcc[idx].nick, "I'm aggressive to you");
- } else {
- bool ok = 1;
- for (int i = 0; i < dcc_total; i++)
- if (dcc[i].type && dcc[i].type->flags & DCT_BOT) {
- if ((dcc[i].status & STAT_SHARE) && (dcc[i].status & STAT_AGGRESSIVE) && (i != idx)) {
- ok = 0;
- break;
- }
- }
- if (!ok)
- dprintf(idx, "s un Already sharing.\n");
- else {
- dcc[idx].u.bot->uff_flags |= (UFF_OVERRIDE | UFF_INVITE | UFF_EXEMPT);
- dprintf(idx, "s uy overbots invites exempts\n");
- /* Set stat-getting to astatic void race condition (robey 23jun1996) */
- dcc[idx].status |= STAT_SHARE | STAT_GETTING | STAT_AGGRESSIVE;
- if (conf.bot->hub)
- putlog(LOG_BOTS, "*", "Downloading user file from %s", dcc[idx].nick);
- else
- putlog(LOG_BOTS, "*", "Downloading user file via uplink.");
- }
- }
- }
- /* us <ip> <port> <length>
- */
- static void
- share_ufsend(int idx, char *par)
- {
- char *port = NULL, *ip = NULL;
- char s[1024] = "";
- int i, sock;
- FILE *f = NULL;
- egg_snprintf(s, sizeof s, "%s.share.%s.%li.users", tempdir, conf.bot->nick, now);
- if (!(b_status(idx) & STAT_SHARE)) {
- dprintf(idx, "s e You didn't ask; you just started sending.\n");
- dprintf(idx, "s e Ask before sending the userfile.\n");
- zapfbot(idx);
- } else if (dcc_total == max_dcc) {
- putlog(LOG_MISC, "@", "NO MORE DCC CONNECTIONS -- can't grab userfile");
- dprintf(idx, "s e I can't open a DCC to you; I'm full.\n");
- zapfbot(idx);
- } else if (!(f = fopen(s, "wb"))) {
- putlog(LOG_MISC, "@", "CAN'T WRITE USERFILE DOWNLOAD FILE!");
- zapfbot(idx);
- } else {
- ip = newsplit(&par);
- port = newsplit(&par);
- #ifdef USE_IPV6
- // sock = getsock(SOCK_BINARY, hostprotocol(ip)); /* Don't buffer this -> mark binary. */
- sock = getsock(SOCK_BINARY, AF_INET);
- #else
- sock = getsock(SOCK_BINARY); /* Don't buffer this -> mark binary. */
- #endif /* USE_IPV6 */
- if (sock < 0 || open_telnet_dcc(sock, ip, port) < 0) {
- fclose(f);
- killsock(sock);
- putlog(LOG_BOTS, "@", "Asynchronous connection failed!");
- dprintf(idx, "s e Can't connect to you!\n");
- zapfbot(idx);
- } else {
- putlog(LOG_DEBUG, "@", "Connecting to %s:%s for userfile.", ip, port);
- i = new_dcc(&DCC_FORK_SEND, sizeof(struct xfer_info));
- dcc[i].addr = my_atoul(ip);
- dcc[i].port = atoi(port);
- strcpy(dcc[i].nick, "*users");
- dcc[i].u.xfer->filename = strdup(s);
- dcc[i].u.xfer->origname = dcc[i].u.xfer->filename;
- dcc[i].u.xfer->length = atoi(par);
- dcc[i].u.xfer->f = f;
- dcc[i].sock = sock;
- strcpy(dcc[i].host, dcc[idx].nick);
- dcc[idx].status |= STAT_GETTING;
- }
- }
- }
- static void
- share_version(int idx, char *par)
- {
- /* Cleanup any share flags */
- dcc[idx].status &= ~(STAT_SHARE | STAT_GETTING | STAT_SENDING | STAT_OFFERED | STAT_AGGRESSIVE);
- dcc[idx].u.bot->uff_flags |= (UFF_OVERRIDE | UFF_INVITE | UFF_EXEMPT);
- if (bot_aggressive_to(dcc[idx].user)) {
- dprintf(idx, "s u?\n");
- dcc[idx].status |= STAT_OFFERED;
- }
- // else higher_bot_linked(idx);
- }
- void
- hook_read_userfile()
- {
- if (!noshare) {
- for (int i = 0; i < dcc_total; i++) {
- if (dcc[i].type && (dcc[i].type->flags & DCT_BOT) && (dcc[i].status & STAT_SHARE) && !(dcc[i].status & STAT_AGGRESSIVE)
- && (1)) {
- /* Cancel any existing transfers */
- if (dcc[i].status & STAT_SENDING)
- cancel_user_xfer(-i, 0);
- dprintf(i, "s u?\n");
- dcc[i].status |= STAT_OFFERED;
- }
- }
- }
- }
- static void
- share_endstartup(int idx, char *par)
- {
- dcc[idx].status &= ~STAT_GETTING;
- /* Send to any other sharebots */
- if (conf.bot->hub)
- hook_read_userfile();
- }
- static void
- share_end(int idx, char *par)
- {
- putlog(LOG_BOTS, "*", "Ending sharing with %s (%s).", dcc[idx].nick, par);
- cancel_user_xfer(-idx, 0);
- dcc[idx].status &= ~(STAT_SHARE | STAT_GETTING | STAT_SENDING | STAT_OFFERED | STAT_AGGRESSIVE);
- dcc[idx].u.bot->uff_flags = 0;
- }
- /* Note: these MUST be sorted. */
- static botcmd_t C_share[] = {
- {"!", share_endstartup, 0},
- {"+bh", share_pls_bothost, 0},
- {"+cr", share_pls_chrec, 0},
- {"+h", share_pls_host, 0},
- {"+i", share_pls_ignore, 0},
- {"+m", share_pls_mask, 0},
- {"+mc", share_pls_maskchan, 0},
- {"-cr", share_mns_chrec, 0},
- {"-h", share_mns_host, 0},
- {"-i", share_mns_ignore, 0},
- {"-m", share_mns_mask, 0},
- {"-mc", share_mns_maskchan, 0},
- {"a", share_chattr, 0},
- {"c", share_change, 0},
- {"chchinfo", share_chchinfo, 0},
- {"e", share_end, 0},
- {"h", share_chhand, 0},
- {"k", share_killuser, 0},
- {"ms", share_stick_mask, 0},
- {"n", share_newuser, 0},
- {"u?", share_userfileq, 0},
- {"un", share_ufno, HUB},
- {"us", share_ufsend, 0},
- {"uy", share_ufyes, HUB},
- {"v", share_version, 0},
- {NULL, NULL, 0}
- };
- void
- sharein(int idx, char *msg)
- {
- char *code = newsplit(&msg);
- int y, f = 0, i = 0;
- for (f = 0, i = 0; C_share[i].name && !f; i++) {
- y = egg_strcasecmp(code, C_share[i].name);
- if (!y)
- /* Found a match */
- (C_share[i].func) (idx, msg);
- if (y < 0)
- f = 1;
- }
- }
- void
- shareout(const char *format, ...)
- {
- char s[601] = "";
- int l;
- va_list va;
- va_start(va, format);
- strcpy(s, "s ");
- if ((l = egg_vsnprintf(s + 2, 509, format, va)) < 0)
- s[2 + (l = 509)] = 0;
- va_end(va);
- for (int i = 0; i < dcc_total; i++) {
- if (dcc[i].type && (dcc[i].type->flags & DCT_BOT) &&
- (dcc[i].status & STAT_SHARE) && !(dcc[i].status & (STAT_GETTING | STAT_SENDING))) {
- tputs(dcc[i].sock, s, l + 2);
- }
- }
- q_resync(s);
- }
- void
- shareout_prot(struct userrec *u, const char *format, ...)
- {
- char s[601] = "";
- int l;
- va_list va;
- va_start(va, format);
- strcpy(s, "s ");
- if ((l = egg_vsnprintf(s + 2, 509, format, va)) < 0)
- s[2 + (l = 509)] = 0;
- va_end(va);
- for (int i = 0; i < dcc_total; i++) {
- if (dcc[i].type && (dcc[i].type->flags & DCT_BOT) &&
- (dcc[i].status & STAT_SHARE) && !(dcc[i].status & (STAT_GETTING | STAT_SENDING)) &&
- /* only send to hubs and to the same user */
- (dcc[i].hub || dcc[i].user == u)) {
- tputs(dcc[i].sock, s, l + 2);
- }
- }
- q_resync(s);
- }
- static void
- shareout_but(int x, const char *format, ...)
- {
- int l;
- char s[601] = "";
- va_list va;
- va_start(va, format);
- strcpy(s, "s ");
- if ((l = egg_vsnprintf(s + 2, 509, format, va)) < 0)
- s[2 + (l = 509)] = 0;
- va_end(va);
- for (int i = 0; i < dcc_total; i++) {
- if (dcc[i].type && (dcc[i].type->flags & DCT_BOT) && (i != x) &&
- (dcc[i].status & STAT_SHARE) && (!(dcc[i].status & STAT_GETTING)) &&
- (!(dcc[i].status & STAT_SENDING))) {
- tputs(dcc[i].sock, s, l + 2);
- }
- }
- q_resync(s);
- }
- /* Flush all tbufs older than 15 minutes.
- */
- static void
- check_expired_tbufs()
- {
- tandbuf *t = NULL, *tnext = NULL;
- for (t = tbuf; t; t = tnext) {
- tnext = t->next;
- if ((now - t->timer) > 300) {
- putlog(LOG_BOTS, "*", "Flushing resync buffer for clonebot %s.", t->bot);
- del_tbuf(t);
- }
- }
-
- /* Resend userfile requests */
- for (int i = 0; i < dcc_total; i++) {
- if (dcc[i].type && dcc[i].type->flags & DCT_BOT) {
- if (dcc[i].status & STAT_OFFERED) {
- if (now - dcc[i].timeval > 120) {
- if (dcc[i].user && bot_aggressive_to(dcc[i].user))
- dprintf(i, "s u?\n");
- /* ^ send it again in case they missed it */
- }
- /* If it's a share bot that hasnt been sharing, ask again */
- } else if (!(dcc[i].status & STAT_SHARE)) {
- if (dcc[i].user && bot_aggressive_to(dcc[i].user)) {
- dprintf(i, "s u?\n");
- dcc[i].status |= STAT_OFFERED;
- }
- }
- }
- }
- }
- static bool
- write_tmp_userfile(char *fn, const struct userrec *bu, int idx)
- {
- FILE *f = NULL;
- int ok = 0;
- if ((f = fopen(fn, "wb"))) {
- time_t tt = now;
- char s1[81] = "";
- fixmod(fn);
- strcpy(s1, ctime(&tt));
- lfprintf(f, "#4v: %s -- %s -- written %s", ver, conf.bot->nick, s1);
- ok += write_chans(f, idx);
- ok += write_vars_and_cmdpass(f, idx);
- ok += write_bans(f, idx);
- ok += write_exempts(f, idx);
- ok += write_invites(f, idx);
- if (ok != 5)
- ok = 0;
- for (struct userrec *u = (struct userrec *) bu; u && ok; u = u->next) {
- if (!write_user(u, f, idx))
- ok = 0;
- }
- fclose(f);
- }
- if (!ok)
- putlog(LOG_MISC, "*", "ERROR writing user file to transfer.");
- return ok;
- }
- /* Erase old user list, switch to new one.
- */
- void
- finish_share(int idx)
- {
- struct userrec *u = NULL, *ou = NULL;
- struct chanset_t *chan = NULL;
- int i, j = -1;
- for (i = 0; i < dcc_total; i++)
- if (dcc[i].type && !egg_strcasecmp(dcc[i].nick, dcc[idx].host) && (dcc[i].type->flags & DCT_BOT)) {
- j = i;
- break;
- }
- if (j == -1)
- return;
- /* compress.mod
- if (!uncompressfile(dcc[idx].u.xfer->filename)) {
- char xx[1024] = "";
- putlog(LOG_BOTS, "*", "A uff parsing function failed for the userfile!");
- unlink(dcc[idx].u.xfer->filename);
- dprintf(j, "bye\n");
- simple_snprintf(xx, sizeof xx, "Disconnected %s (uff error)", dcc[j].nick);
- botnet_send_unlinked(j, dcc[j].nick, xx);
- chatout("*** %s\n", xx);
- killsock(dcc[j].sock);
- lostdcc(j);
- return;
- }
- */
- /*
- * This is where we remove all global and channel bans/exempts/invites and
- * ignores since they will be replaced by what our hub gives us.
- */
- noshare = 1;
- while (global_bans)
- u_delmask('b', NULL, global_bans->mask, 1);
- while (global_ign)
- delignore(global_ign->igmask);
- while (global_invites)
- u_delmask('I', NULL, global_invites->mask, 1);
- while (global_exempts)
- u_delmask('e', NULL, global_exempts->mask, 1);
- for (chan = chanset; chan; chan = chan->next) {
- while (chan->bans)
- u_delmask('b', chan, chan->bans->mask, 1);
- while (chan->exempts)
- u_delmask('e', chan, chan->exempts->mask, 1);
- while (chan->invites)
- u_delmask('I', chan, chan->invites->mask, 1);
- }
- noshare = 0;
- ou = userlist; /* Save old user list */
- userlist = (struct userrec *) -1; /* Do this to prevent .user messups */
- /* Bot user pointers are updated to point to the new list, all others
- * are set to NULL. If our userfile will be overriden, just set _all_
- * to NULL directly.
- */
- for (i = 0; i < dcc_total; i++)
- if (dcc[i].type)
- dcc[i].user = NULL;
- Auth::NullUsers();
- if (conf.bot->u)
- conf.bot->u = NULL;
- /* Read the transferred userfile. Add entries to u, which already holds
- * the bot entries in non-override mode.
- */
- loading = 1;
- checkchans(0); /* flag all the channels.. */
- Context;
- if (!readuserfile(dcc[idx].u.xfer->filename, &u)) { /* read the userfile into 'u' */
- /* FAILURE */
- char xx[1024] = "";
- Context;
- unlink(dcc[idx].u.xfer->filename);
- clear_userlist(u); /* Clear new, obsolete, user list. */
- clear_chanlist(); /* Remove all user references from the
- * channel lists. */
- for (i = 0; i < dcc_total; i++)
- if (dcc[i].type)
- dcc[i].user = get_user_by_handle(ou, dcc[i].nick);
- conf.bot->u = get_user_by_handle(ou, conf.bot->nick);
- userlist = ou; /* Revert to old user list. */
- lastuser = NULL; /* Reset last accessed user ptr. */
- Auth::FillUsers();
- checkchans(2); /* un-flag the channels, we are keeping them.. */
- /* old userlist is now being used, safe to do this stuff... */
- loading = 0;
- putlog(LOG_MISC, "*", "%s", "CAN'T READ NEW USERFILE");
- dprintf(idx, "bye\n");
- simple_snprintf(xx, sizeof xx, "Disconnected %s (can't read userfile)", dcc[j].nick);
- botnet_send_unlinked(j, dcc[j].nick, xx);
- chatout("*** %s\n", xx);
- killsock(dcc[j].sock);
- lostdcc(j);
- return;
- }
- /* SUCCESS! */
- unlink(dcc[idx].u.xfer->filename);
- loading = 0;
- clear_chanlist(); /* Remove all user references from the
- * channel lists. */
- userlist = u; /* Set new user list. */
- lastuser = NULL; /* Reset last accessed user ptr. */
- putlog(LOG_BOTS, "*", "%s.", "Userlist transfer complete; switched over");
- /*
- * Migrate:
- * - unshared (got_share == 0) user entries
- */
- clear_userlist(ou);
- if (!conf.bot->u)
- conf.bot->u = get_user_by_handle(userlist, conf.bot->nick);
- /* Our hostmask may have been updated on connect, but the new userfile may not have it. */
- check_hostmask();
- /* copy over any auth users */
- Auth::FillUsers();
- checkchans(1); /* remove marked channels */
- var_parse_my_botset();
- reaffirm_owners(); /* Make sure my owners are +a */
- updatebot(-1, dcc[j].nick, '+', 0, 0, NULL);
- if (reset_chans) {
- reset_chans = 0;
- // putlog(LOG_DEBUG, "*", "Resetting channel info for all channels...");
- // for (chan = chanset; chan; chan = chan->next)
- // reset_chan_info(chan);
- join_chans();
- }
- }
- /* Begin the user transfer process.
- */
- static void
- start_sending_users(int idx)
- {
- char share_file[1024] = "";
- int i = 1, j = -1;
- egg_snprintf(share_file, sizeof share_file, "%s.share.%s.%li", tempdir, dcc[idx].nick, now);
- write_tmp_userfile(share_file, userlist, idx);
- /* compress.mod
- if (!compress_file(share_file, compress_level)) {
- unlink(share_file);
- dprintf(idx, "s e %s\n", "uff parsing failed");
- putlog(LOG_BOTS, "*", "uff parsing failed");
- dcc[idx].status &= ~(STAT_SHARE | STAT_SENDING | STAT_AGGRESSIVE);
- return;
- }
- */
- if ((i = raw_dcc_send(share_file, "*users", "(users)", share_file, &j)) > 0) {
- unlink(share_file);
- dprintf(idx, "s e %s\n", "Can't send userfile to you (internal error)");
- putlog(LOG_BOTS, "*", "%s -- can't send userfile",
- i == DCCSEND_FULL ? "NO MORE DCC CONNECTIONS" :
- i == DCCSEND_NOSOCK ? "CAN'T OPEN A LISTENING SOCKET" :
- i == DCCSEND_BADFN ? "BAD FILE" : i == DCCSEND_FEMPTY ? "EMPTY FILE" : "UNKNOWN REASON!");
- dcc[idx].status &= ~(STAT_SHARE | STAT_SENDING | STAT_AGGRESSIVE);
- } else {
- updatebot(-1, dcc[idx].nick, '+', 0, 0, NULL);
- dcc[idx].status |= STAT_SENDING;
- strcpy(dcc[j].host, dcc[idx].nick); /* Store bot's nick */
- dprintf(idx, "s us %lu %d %lu\n", iptolong(getmyip()), dcc[j].port, dcc[j].u.xfer->length);
- /* Start up a tbuf to queue outgoing changes for this bot until the
- * userlist is done transferring.
- */
- new_tbuf(dcc[idx].nick);
- /* override shit removed here */
- q_tbuf(dcc[idx].nick, "s !\n");
- /* Unlink the file. We don't really care whether this causes problems
- * for NFS setups. It's not worth the trouble.
- */
- unlink(share_file);
- }
- }
- static void (*def_dcc_bot_kill) (int, void *) = 0;
- static void
- cancel_user_xfer(int idx, void *x)
- {
- int i, j = -1, k = 0;
- if (idx < 0) {
- idx = -idx;
- k = 1;
- /* turn off sharing flag */
- updatebot(-1, dcc[idx].nick, '-', 0, 0, NULL);
- }
- flush_tbuf(dcc[idx].nick);
- if (dcc[idx].status & STAT_SHARE) {
- /* look for any transfers from this bot and kill them */
- if (dcc[idx].status & STAT_GETTING) {
- for (i = 0; i < dcc_total; i++)
- if (dcc[i].type && !egg_strcasecmp(dcc[i].host, dcc[idx].nick) &&
- ((dcc[i].type->flags & (DCT_FILETRAN | DCT_FILESEND)) == (DCT_FILETRAN | DCT_FILESEND))) {
- j = i;
- break;
- }
- if (j >= 0) {
- killsock(dcc[j].sock);
- unlink(dcc[j].u.xfer->filename);
- lostdcc(j);
- }
- putlog(LOG_BOTS, "*", "(Userlist download aborted.)");
- }
- /* look for any transfers we were sending them */
- if (dcc[idx].status & STAT_SENDING) {
- for (i = 0; i < dcc_total; i++)
- if (dcc[i].type && (!egg_strcasecmp(dcc[i].host, dcc[idx].nick)) &&
- ((dcc[i].type->flags & (DCT_FILETRAN | DCT_FILESEND)) == DCT_FILETRAN)) {
- j = i;
- break;
- }
- if (j >= 0) {
- killsock(dcc[j].sock);
- unlink(dcc[j].u.xfer->filename);
- lostdcc(j);
- }
- putlog(LOG_BOTS, "*", "(Userlist transmit aborted.)");
- }
- }
- if (!k)
- def_dcc_bot_kill(idx, x);
- }
- void
- share_report(int idx, int details)
- {
- int i, j;
- if (details) {
- for (i = 0; i < dcc_total; i++)
- if (dcc[i].type && dcc[i].type == &DCC_BOT) {
- if (dcc[i].status & STAT_GETTING) {
- int ok = 0;
- for (j = 0; j < dcc_total; j++)
- if (dcc[j].type && ((dcc[j].type->flags & (DCT_FILETRAN | DCT_FILESEND))
- == (DCT_FILETRAN | DCT_FILESEND)) && !egg_strcasecmp(dcc[j].host, dcc[i].nick)) {
- dprintf(idx, "Downloading userlist from %s (%d%% done)\n",
- dcc[i].nick, (int) (100.0 * ((float) dcc[j].status) / ((float) dcc[j].u.xfer->length)));
- ok = 1;
- break;
- }
- if (!ok)
- dprintf(idx, "Download userlist from %s (negotiating " "botentries)\n", dcc[i].nick);
- } else if (dcc[i].status & STAT_SENDING) {
- for (j = 0; j < dcc_total; j++) {
- if (dcc[j].type && ((dcc[j].type->flags & (DCT_FILETRAN | DCT_FILESEND))
- == DCT_FILETRAN)
- && !egg_strcasecmp(dcc[j].host, dcc[i].nick)) {
- if (dcc[j].type == &DCC_GET)
- dprintf(idx, "Sending userlist to %s (%d%% done)\n",
- dcc[i].nick,
- (int) (100.0 * ((float) dcc[j].status) / ((float) dcc[j].u.xfer->length)));
- else
- dprintf(idx, "Sending userlist to %s (waiting for connect)\n", dcc[i].nick);
- }
- }
- } else if (dcc[i].status & STAT_AGGRESSIVE) {
- dprintf(idx, " Passively sharing with %s.\n", dcc[i].nick);
- } else if (dcc[i].status & STAT_SHARE) {
- dprintf(idx, " Aggressively sharing with %s.\n", dcc[i].nick);
- }
- }
- }
- }
- void
- share_init()
- {
- if (conf.bot->hub)
- timer_create_secs(60, "check_expired_tbufs", (Function) check_expired_tbufs);
- else
- timer_create_secs(1, "check_delay", (Function) check_delay);
- def_dcc_bot_kill = DCC_BOT.kill;
- DCC_BOT.kill = cancel_user_xfer;
- }
|