diff options
Diffstat (limited to 'src/chanserv.c')
-rw-r--r-- | src/chanserv.c | 471 |
1 files changed, 0 insertions, 471 deletions
diff --git a/src/chanserv.c b/src/chanserv.c index b09f9e808..c85efc259 100644 --- a/src/chanserv.c +++ b/src/chanserv.c @@ -303,477 +303,6 @@ void chanserv(User * u, char *buf) /*************************************************************************/ -/* Load/save data files. */ - - -#define SAFE(x) do { \ - if ((x) < 0) { \ - if (!forceload) \ - fatal("Read error on %s", Config.ChanDBName); \ - failed = 1; \ - break; \ - } \ -} while (0) - -void load_cs_dbase() -{ - dbFILE *f; - int ver, c; - unsigned i, j; - ChannelInfo *ci, **last, *prev; - int failed = 0; - - if (!(f = open_db(Config.s_ChanServ, Config.ChanDBName, "r", CHAN_VERSION))) - return; - - ver = get_file_version(f); - - if (ver != 16) - fatal("Invalid database version! (I only understand %d)", CHAN_VERSION); - - for (i = 0; i < 256 && !failed; i++) { - uint16 tmp16; - uint32 tmp32; - unsigned int read; - int n_levels; - char *s; - NickAlias *na; - - last = &chanlists[i]; - prev = NULL; - while ((c = getc_db(f)) != 0) { - if (c != 1) - fatal("Invalid format in %s", Config.ChanDBName); - char channame[CHANMAX]; - SAFE(read = read_buffer(channame, f)); - ci = new ChannelInfo(channame); - *last = ci; - last = &ci->next; - ci->prev = prev; - prev = ci; - SAFE(read_string(&s, f)); - if (s) { - ci->founder = findcore(s); - delete [] s; - } else - ci->founder = NULL; - if (ver >= 7) { - SAFE(read_string(&s, f)); - if (s) { - if (ver >= 13) - ci->successor = findcore(s); - else { - na = findnick(s); - if (na) - ci->successor = na->nc; - else - ci->successor = NULL; - } - delete [] s; - } else - ci->successor = NULL; - } else { - ci->successor = NULL; - } - - char nothing[PASSMAX]; - SAFE(read = read_buffer(nothing, f)); // XXX founder pass was removed.. just here so it works - - SAFE(read_string(&ci->desc, f)); - if (!ci->desc) - ci->desc = sstrdup(""); - SAFE(read_string(&ci->url, f)); - SAFE(read_string(&ci->email, f)); - SAFE(read_int32(&tmp32, f)); - ci->time_registered = tmp32; - SAFE(read_int32(&tmp32, f)); - ci->last_used = tmp32; - SAFE(read_string(&ci->last_topic, f)); - SAFE(read = read_buffer(ci->last_topic_setter, f)); - SAFE(read_int32(&tmp32, f)); - ci->last_topic_time = tmp32; - //SAFE(read_int32(&ci->flags, f)); - SAFE(read_int32(&tmp32, f)); - - /* Leaveops cleanup */ -// if (ver <= 13 && (ci->HasFlag()0x00000020)) -// ci->UnsetFlag()0x00000020; - /* Temporary flags cleanup */ - ci->UnsetFlag(CI_INHABIT); - - SAFE(read_string(&ci->forbidby, f)); - SAFE(read_string(&ci->forbidreason, f)); - SAFE(read_int16(&tmp16, f)); - ci->bantype = tmp16; - SAFE(read_int16(&tmp16, f)); - n_levels = tmp16; - ci->levels = new int16[CA_SIZE]; - reset_levels(ci); - for (j = 0; j < n_levels; j++) { - SAFE(read_int16(&tmp16, f)); - if (j < CA_SIZE) - ci->levels[j] = static_cast<int16>(tmp16); - } - - uint16 accesscount = 0; - SAFE(read_int16(&accesscount, f)); - if (accesscount) { - for (j = 0; j < accesscount; j++) { - uint16 in_use = 0; - SAFE(read_int16(&in_use, f)); - if (in_use) { - uint16 level; - SAFE(read_int16(&level, f)); - NickCore *nc; - SAFE(read_string(&s, f)); - if (s) { - nc = findcore(s); - delete [] s; - } - else - nc = NULL; - uint32 last_seen; - SAFE(read_int32(&last_seen, f)); - //SAFE(read_string(&s, f)); - if (nc) - { - //std::string creator = s ? s : ""; - std::string creator = ""; - ci->AddAccess(nc, level, creator, last_seen); - } - } - } - } - - uint16 akickcount = 0; - NickCore *nc; - SAFE(read_int16(&akickcount, f)); - if (akickcount) { - for (j = 0; j < akickcount; ++j) - { - uint16 flags; - SAFE(read_int16(&flags, f)); - SAFE(read_string(&s, f)); - char *akickreason; - SAFE(read_string(&akickreason, f)); - char *akickcreator; - SAFE(read_string(&akickcreator, f)); - SAFE(read_int32(&tmp32, f)); - - if (flags & AK_ISNICK) - { - nc = findcore(s); - if (!nc) - continue; - ci->AddAkick(akickcreator, nc, akickreason ? akickreason : "", tmp32); - } - else - ci->AddAkick(akickcreator, s, akickreason ? akickreason : "", tmp32); - } - } - - //SAFE(read_int32(&ci->mlock_on, f)); - //SAFE(read_int32(&ci->mlock_off, f)); - // Clearly this doesn't work - SAFE(read_int32(&tmp32, f)); - SAFE(read_int32(&tmp32, f)); - - SAFE(read_int32(&tmp32, f)); - if (tmp32) - { - std::ostringstream limit; - limit << tmp32; - ci->SetMLock(CMODE_LIMIT, true, limit.str()); - } - - SAFE(read_string(&s, f)); - if (s) - { - ci->SetMLock(CMODE_KEY, true, std::string(s)); - delete [] s; - } - - SAFE(read_string(&s, f)); - if (s) - { - ci->SetMLock(CMODE_FLOOD, true, std::string(s)); - delete [] s; - } - - SAFE(read_string(&s, f)); - if (s) - { - ci->SetMLock(CMODE_REDIRECT, true, std::string(s)); - delete [] s; - } - - SAFE(read_int16(&tmp16, f)); - if (tmp16) ci->memos.memos.resize(tmp16); - SAFE(read_int16(&tmp16, f)); - ci->memos.memomax = static_cast<int16>(tmp16); - if (!ci->memos.memos.empty()) { - for (j = 0; j < ci->memos.memos.size(); j++) { - ci->memos.memos[j] = new Memo; - Memo *memo = ci->memos.memos[j]; - SAFE(read_int32(&memo->number, f)); - //SAFE(read_int16(&memo->flags, f)); - SAFE(read_int16(&tmp16, f)); - SAFE(read_int32(&tmp32, f)); - memo->time = tmp32; - SAFE(read = read_buffer(memo->sender, f)); - SAFE(read_string(&memo->text, f)); - } - } - - SAFE(read_string(&ci->entry_message, f)); - - ci->c = NULL; - - /* BotServ options */ - int n_ttb; - - SAFE(read_string(&s, f)); - if (s) { - ci->bi = findbot(s); - delete [] s; - } else - ci->bi = NULL; - - SAFE(read_int32(&tmp32, f)); - //ci->botflags = tmp32; - SAFE(read_int16(&tmp16, f)); - n_ttb = tmp16; - ci->ttb = new int16[2 * TTB_SIZE]; - for (j = 0; j < n_ttb; j++) { - SAFE(read_int16(&tmp16, f)); - if (j < TTB_SIZE) - ci->ttb[j] = static_cast<int16>(tmp16); - } - for (j = n_ttb; j < TTB_SIZE; j++) - ci->ttb[j] = 0; - SAFE(read_int16(&tmp16, f)); - ci->capsmin = tmp16; - SAFE(read_int16(&tmp16, f)); - ci->capspercent = tmp16; - SAFE(read_int16(&tmp16, f)); - ci->floodlines = tmp16; - SAFE(read_int16(&tmp16, f)); - ci->floodsecs = tmp16; - SAFE(read_int16(&tmp16, f)); - ci->repeattimes = tmp16; - - SAFE(read_int16(&tmp16, f)); - if (tmp16) { - for (j = 0; j < tmp16; j++) { - uint16 inuse; - SAFE(read_int16(&inuse, f)); - //if (ci->badwords[j].in_use) { - char *badword; - SAFE(read_string(&badword, f)); - //SAFE(read_int16(&ci->badwords[j].type, f)); - SAFE(read_int16(&tmp16, f)); - //ci->badwords[j].type = BW_ANY; // for now - ci->AddBadWord(badword, BW_ANY); - delete [] badword; - // } - } - } - } /* while (getc_db(f) != 0) */ - - *last = NULL; - - } /* for (i) */ - - close_db(f); - - /* Check for non-forbidden channels with no founder. - Makes also other essential tasks. */ - for (i = 0; i < 256; i++) { - ChannelInfo *next; - for (ci = chanlists[i]; ci; ci = next) { - next = ci->next; - if (!(ci->HasFlag(CI_FORBIDDEN)) && !ci->founder) { - alog("%s: database load: Deleting founderless channel %s", - Config.s_ChanServ, ci->name); - delete ci; - continue; - } - } - } -} - -#undef SAFE - -/*************************************************************************/ - -#define SAFE(x) do { \ - if ((x) < 0) { \ - restore_db(f); \ - log_perror("Write error on %s", Config.ChanDBName); \ - if (time(NULL) - lastwarn > Config.WarningTimeout) { \ - ircdproto->SendGlobops(NULL, "Write error on %s: %s", Config.ChanDBName, \ - strerror(errno)); \ - lastwarn = time(NULL); \ - } \ - return; \ - } \ -} while (0) - -void save_cs_dbase() -{ - dbFILE *f; - unsigned i, j; - ChannelInfo *ci; - static time_t lastwarn = 0; - std::string param; - - if (!(f = open_db(Config.s_ChanServ, Config.ChanDBName, "w", CHAN_VERSION))) - return; - - for (i = 0; i < 256; i++) { - int16 tmp16; - unsigned int written; - - for (ci = chanlists[i]; ci; ci = ci->next) { - SAFE(write_int8(1, f)); - SAFE(written = write_buffer(ci->name, f)); - if (ci->founder) - SAFE(write_string(ci->founder->display, f)); - else - SAFE(write_string(NULL, f)); - if (ci->successor) - SAFE(write_string(ci->successor->display, f)); - else - SAFE(write_string(NULL, f)); - - char nothing[PASSMAX]; /* founder passwords were removed! */ - strcpy(nothing, "nothing\0"); - SAFE(written = write_buffer(nothing, f)); - - SAFE(write_string(ci->desc, f)); - SAFE(write_string(ci->url, f)); - SAFE(write_string(ci->email, f)); - SAFE(write_int32(ci->time_registered, f)); - SAFE(write_int32(ci->last_used, f)); - SAFE(write_string(ci->last_topic, f)); - SAFE(written = write_buffer(ci->last_topic_setter, f)); - SAFE(write_int32(ci->last_topic_time, f)); - //SAFE(write_int32(ci->flags, f)); - SAFE(write_int32(0, f)); - SAFE(write_string(ci->forbidby, f)); - SAFE(write_string(ci->forbidreason, f)); - SAFE(write_int16(ci->bantype, f)); - - tmp16 = CA_SIZE; - SAFE(write_int16(tmp16, f)); - for (j = 0; j < CA_SIZE; j++) - SAFE(write_int16(ci->levels[j], f)); - - SAFE(write_int16(ci->GetAccessCount(), f)); - for (j = 0; j < ci->GetAccessCount(); j++) { - ChanAccess *access = ci->GetAccess(j); - if (!access->in_use) - continue; - SAFE(write_int16(access->in_use, f)); - SAFE(write_int16(access->level, f)); - SAFE(write_string(access->nc->display, f)); - SAFE(write_int32(access->last_seen, f)); - //SAFE(write_string(access->creator.c_str(), f)); - } - - SAFE(write_int16(ci->GetAkickCount(), f)); - for (j = 0; j < ci->GetAkickCount(); ++j) - { - AutoKick *akick = ci->GetAkick(j); - //SAFE(write_int16(akick->flags, f)); - SAFE(write_int16(0, f)); - if (akick->HasFlag(AK_ISNICK)) - SAFE(write_string(akick->nc->display, f)); - else - SAFE(write_string(akick->mask.c_str(), f)); - SAFE(write_string(akick->reason.c_str(), f)); - SAFE(write_string(akick->creator.c_str(), f)); - SAFE(write_int32(akick->addtime, f)); - } - - //SAFE(write_int32(ci->mlock_on, f)); - //SAFE(write_int32(ci->mlock_off, f)); - // Clearly this doesnt work - SAFE(write_int32(NULL, f)); - SAFE(write_int32(NULL, f)); - - ci->GetParam(CMODE_LIMIT, ¶m); - SAFE(write_int32(param.empty() ? NULL : atoi(param.c_str()), f)); - - ci->GetParam(CMODE_KEY, ¶m); - SAFE(write_string(param.empty() ? NULL : param.c_str(), f)); - - ci->GetParam(CMODE_FLOOD, ¶m); - SAFE(write_string(param.empty() ? NULL : param.c_str(), f)); - - ci->GetParam(CMODE_REDIRECT, ¶m); - SAFE(write_string(param.empty() ? NULL : param.c_str(), f)); - - SAFE(write_int16(ci->memos.memos.size(), f)); - SAFE(write_int16(ci->memos.memomax, f)); - for (j = 0; j < ci->memos.memos.size(); j++) { - Memo *memo = ci->memos.memos[j]; - SAFE(write_int32(memo->number, f)); - SAFE(write_int16(0, f)); - //SAFE(write_int16(memo->flags, f)); - SAFE(write_int32(memo->time, f)); - SAFE(written = write_buffer(memo->sender, f)); - SAFE(write_string(memo->text, f)); - } - - SAFE(write_string(ci->entry_message, f)); - - if (ci->bi) - SAFE(write_string(ci->bi->nick, f)); - else - SAFE(write_string(NULL, f)); - - //SAFE(write_int32(ci->botflags, f)); - SAFE(write_int32(0, f)); - - tmp16 = TTB_SIZE; - SAFE(write_int16(tmp16, f)); - for (j = 0; j < TTB_SIZE; j++) - SAFE(write_int16(ci->ttb[j], f)); - - SAFE(write_int16(ci->capsmin, f)); - SAFE(write_int16(ci->capspercent, f)); - SAFE(write_int16(ci->floodlines, f)); - SAFE(write_int16(ci->floodsecs, f)); - SAFE(write_int16(ci->repeattimes, f)); - - //SAFE(write_int16(ci->bwcount, f)); - SAFE(write_int16(ci->GetBadWordCount(), f)); - for (j = 0; j < ci->GetBadWordCount(); j++) { - BadWord *bw = ci->GetBadWord(j); - /*SAFE(write_int16(ci->badwords[j].in_use, f)); - if (ci->badwords[j].in_use) { - SAFE(write_string(ci->badwords[j].word, f)); - SAFE(write_int16(ci->badwords[j].type, f)); - }*/ - SAFE(write_int16(1, f)); - SAFE(write_string(bw->word.c_str(), f)); - SAFE(write_int16(0, f)); - } - } /* for (chanlists[i]) */ - - SAFE(write_int8(0, f)); - - } /* for (i) */ - - close_db(f); - -} - -#undef SAFE - -/*************************************************************************/ - /* Check the current modes on a channel; if they conflict with a mode lock, * fix them. */ |