diff options
| author | Adam <Adam@anope.org> | 2013-07-01 22:17:52 -0400 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2013-07-01 22:17:52 -0400 |
| commit | 1a3d9a016d3adc49788bbff73aac9b3b5ea85b17 (patch) | |
| tree | c0ecf92ed768473bc82ff64a7fce827245f37ba9 /modules/database | |
| parent | 518182ac9204f815258b0de91b3f884d8efa1502 (diff) | |
Change extensible keys to require explicitly having a type defined for it. Completely modularize more features like bs_kick, entrymsg, log, mode, etc. Move fantasy to its own module. Move greet to its own module.
Diffstat (limited to 'modules/database')
| -rw-r--r-- | modules/database/db_old.cpp | 175 | ||||
| -rw-r--r-- | modules/database/db_plain.cpp | 339 |
2 files changed, 151 insertions, 363 deletions
diff --git a/modules/database/db_old.cpp b/modules/database/db_old.cpp index 053a49110..10b2d56e7 100644 --- a/modules/database/db_old.cpp +++ b/modules/database/db_old.cpp @@ -10,6 +10,9 @@ #include "module.h" #include "modules/os_session.h" +#include "modules/bs_kick.h" +#include "modules/cs_mode.h" +#include "modules/bs_badwords.h" #define READ(x) \ if (true) \ @@ -81,13 +84,6 @@ else \ #define OLD_BS_KICK_FLOOD 0x02000000 #define OLD_BS_KICK_REPEAT 0x01000000 -struct ExtensibleItemUint32 : ExtensibleItem -{ - uint32_t u; - ExtensibleItemUint32(uint32_t i) : u(i) { } -}; - - static struct mlock_info { char c; @@ -139,12 +135,13 @@ enum static void process_mlock(ChannelInfo *ci, uint32_t lock, bool status) { + ModeLocks *ml = ci->Require<ModeLocks>("modelocks"); for (unsigned i = 0; i < (sizeof(mlock_infos) / sizeof(mlock_info)); ++i) if (lock & mlock_infos[i].m) { ChannelMode *cm = ModeManager::FindChannelModeByChar(mlock_infos[i].c); - if (cm) - ci->SetMLock(cm, status); + if (cm && ml) + ml->SetMLock(cm, status); } } @@ -448,7 +445,7 @@ static void LoadNicks() nc->email = buffer; READ(read_string(buffer, f)); - nc->greet = buffer; + nc->Extend<Anope::string>("greet", buffer); uint32_t uint; READ(read_uint32(&uint, f)); @@ -459,37 +456,37 @@ static void LoadNicks() READ(read_uint32(&uint, f)); if (uint & OLD_NI_KILLPROTECT) - nc->ExtendMetadata("KILLPROTECT"); + nc->Extend<bool>("KILLPROTECT"); if (uint & OLD_NI_SECURE) - nc->ExtendMetadata("SECURE"); + nc->Extend<bool>("NS_SECURE"); if (uint & OLD_NI_MSG) - nc->ExtendMetadata("MSG"); + nc->Extend<bool>("MSG"); if (uint & OLD_NI_MEMO_HARDMAX) - nc->ExtendMetadata("MEMO_HARDMAX"); + nc->Extend<bool>("MEMO_HARDMAX"); if (uint & OLD_NI_MEMO_SIGNON) - nc->ExtendMetadata("MEMO_SIGNON"); + nc->Extend<bool>("MEMO_SIGNON"); if (uint & OLD_NI_MEMO_RECEIVE) - nc->ExtendMetadata("MEMO_RECEIVE"); + nc->Extend<bool>("MEMO_RECEIVE"); if (uint & OLD_NI_PRIVATE) - nc->ExtendMetadata("PRIVATE"); + nc->Extend<bool>("NS_PRIVATE"); if (uint & OLD_NI_HIDE_EMAIL) - nc->ExtendMetadata("HIDE_EMAIL"); + nc->Extend<bool>("HIDE_EMAIL"); if (uint & OLD_NI_HIDE_MASK) - nc->ExtendMetadata("HIDE_MASK"); + nc->Extend<bool>("HIDE_MASK"); if (uint & OLD_NI_HIDE_QUIT) - nc->ExtendMetadata("HIDE_QUIT"); + nc->Extend<bool>("HIDE_QUIT"); if (uint & OLD_NI_KILL_QUICK) - nc->ExtendMetadata("KILL_QUICK"); + nc->Extend<bool>("KILL_QUICK"); if (uint & OLD_NI_KILL_IMMED) - nc->ExtendMetadata("KILL_IMMED"); + nc->Extend<bool>("KILL_IMMED"); if (uint & OLD_NI_MEMO_MAIL) - nc->ExtendMetadata("MEMO_MAIL"); + nc->Extend<bool>("MEMO_MAIL"); if (uint & OLD_NI_HIDE_STATUS) - nc->ExtendMetadata("HIDE_STATUS"); + nc->Extend<bool>("HIDE_STATUS"); if (uint & OLD_NI_SUSPENDED) - nc->ExtendMetadata("SUSPENDED"); + nc->Extend<bool>("SUSPENDED"); if (!(uint & OLD_NI_AUTOOP)) - nc->ExtendMetadata("AUTOOP"); + nc->Extend<bool>("AUTOOP"); uint16_t u16; READ(read_uint16(&u16, f)); @@ -607,7 +604,7 @@ static void LoadNicks() na->last_seen = last_seen; if (tmpu16 & OLD_NS_NO_EXPIRE) - na->ExtendMetadata("NO_EXPIRE"); + na->Extend<bool>("NS_NO_EXPIRE"); Log(LOG_DEBUG) << "Loaded NickAlias " << na->nick; } @@ -728,31 +725,31 @@ static void LoadChannels() // Temporary flags cleanup tmpu32 &= ~0x80000000; if (tmpu32 & OLD_CI_KEEPTOPIC) - ci->ExtendMetadata("KEEPTOPIC"); + ci->Extend<bool>("KEEPTOPIC"); if (tmpu32 & OLD_CI_SECUREOPS) - ci->ExtendMetadata("SECUREOPS"); + ci->Extend<bool>("SECUREOPS"); if (tmpu32 & OLD_CI_PRIVATE) - ci->ExtendMetadata("PRIVATE"); + ci->Extend<bool>("CS_PRIVATE"); if (tmpu32 & OLD_CI_TOPICLOCK) - ci->ExtendMetadata("TOPICLOCK"); + ci->Extend<bool>("TOPICLOCK"); if (tmpu32 & OLD_CI_RESTRICTED) - ci->ExtendMetadata("RESTRICTED"); + ci->Extend<bool>("RESTRICTED"); if (tmpu32 & OLD_CI_PEACE) - ci->ExtendMetadata("PEACE"); + ci->Extend<bool>("PEACE"); if (tmpu32 & OLD_CI_SECURE) - ci->ExtendMetadata("SECURE"); + ci->Extend<bool>("CS_SECURE"); if (tmpu32 & OLD_CI_NO_EXPIRE) - ci->ExtendMetadata("NO_EXPIRE"); + ci->Extend<bool>("CI_NO_EXPIRE"); if (tmpu32 & OLD_CI_MEMO_HARDMAX) - ci->ExtendMetadata("MEMO_HARDMAX"); + ci->Extend<bool>("MEMO_HARDMAX"); if (tmpu32 & OLD_CI_SECUREFOUNDER) - ci->ExtendMetadata("SECUREFOUNDER"); + ci->Extend<bool>("SECUREFOUNDER"); if (tmpu32 & OLD_CI_SIGNKICK) - ci->ExtendMetadata("SIGNKICK"); + ci->Extend<bool>("SIGNKICK"); if (tmpu32 & OLD_CI_SIGNKICK_LEVEL) - ci->ExtendMetadata("SIGNKICK_LEVEL"); + ci->Extend<bool>("SIGNKICK_LEVEL"); if (tmpu32 & OLD_CI_SUSPENDED) - ci->ExtendMetadata("SUSPENDED"); + ci->Extend<bool>("SUSPENDED"); READ(read_string(buffer, f)); READ(read_string(buffer, f)); @@ -773,7 +770,7 @@ static void LoadChannels() level = ACCESS_FOUNDER; if (j == 10 && level < 0) // NOJOIN - ci->Shrink("RESTRICTED"); // If CSDefRestricted was enabled this can happen + ci->Shrink<bool>("RESTRICTED"); // If CSDefRestricted was enabled this can happen ci->SetLevel(GetLevelName(j), level); } @@ -831,9 +828,9 @@ static void LoadChannels() } READ(read_uint32(&tmpu32, f)); // mlock on - ci->Extend("mlock_on", new ExtensibleItemUint32(tmpu32)); + ci->Extend<uint32_t>("mlock_on", tmpu32); READ(read_uint32(&tmpu32, f)); // mlock off - ci->Extend("mlock_off", new ExtensibleItemUint32(tmpu32)); + ci->Extend<uint32_t>("mlock_off", tmpu32); READ(read_uint32(&tmpu32, f)); // mlock limit READ(read_string(buffer, f)); READ(read_string(buffer, f)); @@ -863,52 +860,63 @@ static void LoadChannels() READ(read_int32(&tmp32, f)); if (tmp32 & OLD_BS_DONTKICKOPS) - ci->ExtendMetadata("BS_DONTKICKOPS"); + ci->Extend<bool>("BS_DONTKICKOPS"); if (tmp32 & OLD_BS_DONTKICKVOICES) - ci->ExtendMetadata("BS_DONTKICKVOICES"); + ci->Extend<bool>("BS_DONTKICKVOICES"); if (tmp32 & OLD_BS_FANTASY) - ci->ExtendMetadata("BS_FANTASY"); + ci->Extend<bool>("BS_FANTASY"); if (tmp32 & OLD_BS_GREET) - ci->ExtendMetadata("BS_GREET"); + ci->Extend<bool>("BS_GREET"); if (tmp32 & OLD_BS_NOBOT) - ci->ExtendMetadata("BS_NOBOT"); - if (tmp32 & OLD_BS_KICK_BOLDS) - ci->ExtendMetadata("BS_KICK_BOLDS"); - if (tmp32 & OLD_BS_KICK_COLORS) - ci->ExtendMetadata("BS_KICK_COLORS"); - if (tmp32 & OLD_BS_KICK_REVERSES) - ci->ExtendMetadata("BS_KICK_REVERSES"); - if (tmp32 & OLD_BS_KICK_UNDERLINES) - ci->ExtendMetadata("BS_KICK_UNDERLINES"); - if (tmp32 & OLD_BS_KICK_BADWORDS) - ci->ExtendMetadata("BS_KICK_BADWORDS"); - if (tmp32 & OLD_BS_KICK_CAPS) - ci->ExtendMetadata("BS_KICK_CAPS"); - if (tmp32 & OLD_BS_KICK_FLOOD) - ci->ExtendMetadata("BS_KICK_FLOOD"); - if (tmp32 & OLD_BS_KICK_REPEAT) - ci->ExtendMetadata("BS_KICK_REPEAT"); + ci->Extend<bool>("BS_NOBOT"); + + KickerData *kd = ci->Require<KickerData>("kickerdata"); + if (kd) + { + if (tmp32 & OLD_BS_KICK_BOLDS) + kd->bolds = true; + if (tmp32 & OLD_BS_KICK_COLORS) + kd->colors = true; + if (tmp32 & OLD_BS_KICK_REVERSES) + kd->reverses = true; + if (tmp32 & OLD_BS_KICK_UNDERLINES) + kd->underlines = true; + if (tmp32 & OLD_BS_KICK_BADWORDS) + kd->badwords = true; + if (tmp32 & OLD_BS_KICK_CAPS) + kd->caps = true; + if (tmp32 & OLD_BS_KICK_FLOOD) + kd->flood = true; + if (tmp32 & OLD_BS_KICK_REPEAT) + kd->repeat = true; + } READ(read_int16(&tmp16, f)); for (int16_t j = 0; j < tmp16; ++j) { int16_t ttb; READ(read_int16(&ttb, f)); - if (j < TTB_SIZE) - ci->ttb[j] = ttb; + if (j < TTB_SIZE && kd) + kd->ttb[j] = ttb; } READ(read_int16(&tmp16, f)); - ci->capsmin = tmp16; + if (kd) + kd->capsmin = tmp16; READ(read_int16(&tmp16, f)); - ci->capspercent = tmp16; + if (kd) + kd->capspercent = tmp16; READ(read_int16(&tmp16, f)); - ci->floodlines = tmp16; + if (kd) + kd->floodlines = tmp16; READ(read_int16(&tmp16, f)); - ci->floodsecs = tmp16; + if (kd) + kd->floodsecs = tmp16; READ(read_int16(&tmp16, f)); - ci->repeattimes = tmp16; + if (kd) + kd->repeattimes = tmp16; + BadWords *bw = ci->Require<BadWords>("badwords"); READ(read_uint16(&tmpu16, f)); for (uint16_t j = 0; j < tmpu16; ++j) { @@ -928,7 +936,8 @@ static void LoadChannels() else if (type == 3) bwtype = BW_END; - ci->AddBadWord(buffer, bwtype); + if (bw) + bw->AddBadWord(buffer, bwtype); } } @@ -1089,8 +1098,11 @@ static void LoadExceptions() class DBOld : public Module { + PrimitiveExtensibleItem<uint32_t> mlock_on, mlock_off; + public: - DBOld(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR) + DBOld(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR), + mlock_on(this, "mlock_on"), mlock_off(this, "mlock_off") { @@ -1114,22 +1126,21 @@ class DBOld : public Module void OnUplinkSync(Server *s) anope_override { - ExtensibleItemUint32 *mlock; for (registered_channel_map::iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it) { ChannelInfo *ci = it->second; - if (ci->HasExt("mlock_on")) + + uint32_t *u = mlock_on.Get(ci); + if (u) { - mlock = ci->GetExt<ExtensibleItemUint32 *>("mlock_on"); - process_mlock(ci, mlock->u, true); - ci->Shrink("mlock_on"); + process_mlock(ci, *u, true); + mlock_on.Unset(ci); } - if (ci->HasExt("mlock_off")) + u = mlock_off.Get(ci); { - mlock = ci->GetExt<ExtensibleItemUint32 *>("mlock_off"); - process_mlock(ci, mlock->u, false); - ci->Shrink("mlock_off"); + process_mlock(ci, *u, false); + mlock_off.Unset(ci); } } } diff --git a/modules/database/db_plain.cpp b/modules/database/db_plain.cpp index 1e4586a11..62ecaaaa0 100644 --- a/modules/database/db_plain.cpp +++ b/modules/database/db_plain.cpp @@ -10,6 +10,11 @@ #include "module.h" #include "modules/os_session.h" +#include "modules/cs_suspend.h" +#include "modules/bs_kick.h" +#include "modules/cs_log.h" +#include "modules/cs_mode.h" +#include "modules/bs_badwords.h" Anope::string DatabaseFile; Anope::string BackupFile; @@ -71,15 +76,13 @@ EventReturn OnDatabaseReadMetadata(NickCore *nc, const Anope::string &key, const else if (key.equals_ci("EMAIL")) nc->email = params[0]; else if (key.equals_ci("GREET")) - nc->greet = params[0]; + nc->Extend<Anope::string>("greet", params[0]); else if (key.equals_ci("ACCESS")) nc->AddAccess(params[0]); - else if (key.equals_ci("CERT")) - nc->AddCert(params[0]); else if (key.equals_ci("FLAGS")) { for (unsigned i = 0; i < params.size(); ++i) - nc->ExtendMetadata(params[i]); + nc->Extend<bool>(params[i]); } else if (key.equals_ci("MI")) { @@ -118,7 +121,7 @@ EventReturn OnDatabaseReadMetadata(NickAlias *na, const Anope::string &key, cons na->last_quit = params[0]; else if (key.equals_ci("FLAGS")) for (unsigned i = 0; i < params.size(); ++i) - na->ExtendMetadata(params[i]); + na->Extend<bool>(params[i]); else if (key.equals_ci("VHOST")) na->SetVhost(params.size() > 3 ? params[3] : "", params[2], params[0], params[1].is_pos_number_only() ? convertTo<time_t>(params[1]) : 0); return EVENT_CONTINUE; @@ -131,6 +134,7 @@ EventReturn OnDatabaseReadMetadata(BotInfo *bi, const Anope::string &key, const EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const Anope::string &key, const std::vector<Anope::string> ¶ms) { + KickerData *kd = ci->GetExt<KickerData>("kickerdata"); try { if (key.equals_ci("BANTYPE")) @@ -153,7 +157,7 @@ EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const Anope::string &key, co } else if (key.equals_ci("FLAGS")) for (unsigned i = 0; i < params.size(); ++i) - ci->ExtendMetadata(params[i]); + ci->Extend<bool>(params[i]); else if (key.equals_ci("DESC")) ci->desc = params[0]; else if (key.equals_ci("TOPIC")) @@ -164,8 +168,9 @@ EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const Anope::string &key, co } else if (key.equals_ci("SUSPEND")) { - ci->ExtendMetadata("suspend:by", params[0]); - ci->ExtendMetadata("suspend:reason", params[1]); + CSSuspendInfo *si = ci->Extend<CSSuspendInfo>("suspend"); + si->by = params[0]; + si->reason = params[1]; } else if (key.equals_ci("ACCESS")) // Older access system, from Anope 1.9.4. { @@ -220,18 +225,22 @@ EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const Anope::string &key, co } else if (key.equals_ci("LOG")) { - LogSetting *l = new LogSetting(); - - l->ci = ci; - l->service_name = params[0]; - l->command_service = params[1]; - l->command_name = params[2]; - l->method = params[3]; - l->creator = params[4]; - l->created = params[5].is_pos_number_only() ? convertTo<time_t>(params[5]) : Anope::CurTime; - l->extra = params.size() > 6 ? params[6] : ""; - - ci->log_settings->push_back(l); + LogSettings *ls = ci->Require<LogSettings>("logsettings"); + if (ls) + { + LogSetting *l = ls->Create(); + + l->chan = ci->name; + l->service_name = params[0]; + l->command_service = params[1]; + l->command_name = params[2]; + l->method = params[3]; + l->creator = params[4]; + l->created = params[5].is_pos_number_only() ? convertTo<time_t>(params[5]) : Anope::CurTime; + l->extra = params.size() > 6 ? params[6] : ""; + + (*ls)->push_back(l); + } } else if (key.equals_ci("MLOCK")) { @@ -240,7 +249,9 @@ EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const Anope::string &key, co Anope::string setter = params[2]; time_t mcreated = params[3].is_pos_number_only() ? convertTo<time_t>(params[3]) : Anope::CurTime; Anope::string param = params.size() > 4 ? params[4] : ""; - ci->mode_locks->insert(std::make_pair(mode_name, new ModeLock(ci, set, mode_name, param, setter, mcreated))); + ModeLocks *ml = ci->Require<ModeLocks>("modelocks"); + if (ml) + ml->SetMLock(ModeManager::FindChannelModeByName(mode_name), set, param, setter, mcreated); } else if (key.equals_ci("MI")) { @@ -265,44 +276,44 @@ EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const Anope::string &key, co ci->bi = BotInfo::Find(params[1]); else if (params[0].equals_ci("FLAGS")) for (unsigned i = 0; i < params.size(); ++i) - ci->ExtendMetadata(params[i]); + ci->Extend<bool>(params[i]); else if (params[0].equals_ci("TTB")) { - for (unsigned j = 1, end = params.size(); j < end; j += 2) + for (unsigned j = 1, end = params.size(); j < end &&& kd; j += 2) { if (params[j].equals_ci("BOLDS")) - ci->ttb[0] = params[j + 1].is_pos_number_only() ? convertTo<int16_t>(params[j + 1]) : 0; + kd->ttb[0] = params[j + 1].is_pos_number_only() ? convertTo<int16_t>(params[j + 1]) : 0; else if (params[j].equals_ci("COLORS")) - ci->ttb[1] = params[j + 1].is_pos_number_only() ? convertTo<int16_t>(params[j + 1]) : 0; + kd->ttb[1] = params[j + 1].is_pos_number_only() ? convertTo<int16_t>(params[j + 1]) : 0; else if (params[j].equals_ci("REVERSES")) - ci->ttb[2] = params[j + 1].is_pos_number_only() ? convertTo<int16_t>(params[j + 1]) : 0; + kd->ttb[2] = params[j + 1].is_pos_number_only() ? convertTo<int16_t>(params[j + 1]) : 0; else if (params[j].equals_ci("UNDERLINES")) - ci->ttb[3] = params[j + 1].is_pos_number_only() ? convertTo<int16_t>(params[j + 1]) : 0; + kd->ttb[3] = params[j + 1].is_pos_number_only() ? convertTo<int16_t>(params[j + 1]) : 0; else if (params[j].equals_ci("BADWORDS")) - ci->ttb[4] = params[j + 1].is_pos_number_only() ? convertTo<int16_t>(params[j + 1]) : 0; + kd->ttb[4] = params[j + 1].is_pos_number_only() ? convertTo<int16_t>(params[j + 1]) : 0; else if (params[j].equals_ci("CAPS")) - ci->ttb[5] = params[j + 1].is_pos_number_only() ? convertTo<int16_t>(params[j + 1]) : 0; + kd->ttb[5] = params[j + 1].is_pos_number_only() ? convertTo<int16_t>(params[j + 1]) : 0; else if (params[j].equals_ci("FLOOD")) - ci->ttb[6] = params[j + 1].is_pos_number_only() ? convertTo<int16_t>(params[j + 1]) : 0; + kd->ttb[6] = params[j + 1].is_pos_number_only() ? convertTo<int16_t>(params[j + 1]) : 0; else if (params[j].equals_ci("REPEAT")) - ci->ttb[7] = params[j + 1].is_pos_number_only() ? convertTo<int16_t>(params[j + 1]) : 0; + kd->ttb[7] = params[j + 1].is_pos_number_only() ? convertTo<int16_t>(params[j + 1]) : 0; else if (params[j].equals_ci("ITALICS")) - ci->ttb[8] = params[j + 1].is_pos_number_only() ? convertTo<int16_t>(params[j + 1]) : 0; + kd->ttb[8] = params[j + 1].is_pos_number_only() ? convertTo<int16_t>(params[j + 1]) : 0; else if (params[j].equals_ci("AMSGS")) - ci->ttb[9] = params[j + 1].is_pos_number_only() ? convertTo<int16_t>(params[j + 1]) : 0; + kd->ttb[9] = params[j + 1].is_pos_number_only() ? convertTo<int16_t>(params[j + 1]) : 0; } } - else if (params[0].equals_ci("CAPSMIN")) - ci->capsmin = params[1].is_pos_number_only() ? convertTo<int16_t>(params[1]) : 0; - else if (params[0].equals_ci("CAPSPERCENT")) - ci->capspercent = params[1].is_pos_number_only() ? convertTo<int16_t>(params[1]) : 0; - else if (params[0].equals_ci("FLOODLINES")) - ci->floodlines = params[1].is_pos_number_only() ? convertTo<int16_t>(params[1]) : 0; - else if (params[0].equals_ci("FLOODSECS")) - ci->floodsecs = params[1].is_pos_number_only() ? convertTo<int16_t>(params[1]) : 0; - else if (params[0].equals_ci("REPEATTIMES")) - ci->repeattimes = params[1].is_pos_number_only() ? convertTo<int16_t>(params[1]) : 0; - else if (params[0].equals_ci("BADWORD")) + else if (kd && params[0].equals_ci("CAPSMIN")) + kd->capsmin = params[1].is_pos_number_only() ? convertTo<int16_t>(params[1]) : 0; + else if (kd && params[0].equals_ci("CAPSPERCENT")) + kd->capspercent = params[1].is_pos_number_only() ? convertTo<int16_t>(params[1]) : 0; + else if (kd && params[0].equals_ci("FLOODLINES")) + kd->floodlines = params[1].is_pos_number_only() ? convertTo<int16_t>(params[1]) : 0; + else if (kd && params[0].equals_ci("FLOODSECS")) + kd->floodsecs = params[1].is_pos_number_only() ? convertTo<int16_t>(params[1]) : 0; + else if (kd && params[0].equals_ci("REPEATTIMES")) + kd->repeattimes = params[1].is_pos_number_only() ? convertTo<int16_t>(params[1]) : 0; + else if (kd && params[0].equals_ci("BADWORD")) { BadWordType Type; if (params[1].equals_ci("SINGLE")) @@ -313,7 +324,9 @@ EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const Anope::string &key, co Type = BW_END; else Type = BW_ANY; - ci->AddBadWord(params[2], Type); + BadWords *bw = ci->Require<BadWords>("badwords"); + if (bw) + bw->AddBadWord(params[2], Type); } } } @@ -467,11 +480,6 @@ static void ReadDatabase(Module *m = NULL) static void LoadNickCore(const std::vector<Anope::string> ¶ms) { NickCore *nc = new NickCore(params[0]); - /* Clear default flags */ - std::deque<Anope::string> list; - nc->GetExtList(list); - for (unsigned i = 0; i < list.size(); ++i) - nc->Shrink(list[i]); nc->pass = params.size() > 1 ? params[1] : ""; @@ -512,13 +520,6 @@ static void LoadBotInfo(const std::vector<Anope::string> ¶ms) static void LoadChanInfo(const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = new ChannelInfo(params[0]); - /* CLear default mlock */ - ci->ClearMLock(); - /* Remove default channel flags */ - std::deque<Anope::string> list; - ci->GetExtList(list); - for (unsigned i = 0; i < list.size(); ++i) - ci->Shrink(list[i]); ci->time_registered = params[1].is_pos_number_only() ? convertTo<time_t>(params[1]) : 0; @@ -645,230 +646,6 @@ class DBPlain : public Module return EVENT_STOP; } - - - void OnSaveDatabase() anope_override - { - BackupDatabase(); - - db_buffer << "VER 2" << endl; - - for (nickcore_map::const_iterator nit = NickCoreList->begin(), nit_end = NickCoreList->end(); nit != nit_end; ++nit) - { - const NickCore *nc = nit->second; - - db_buffer << "NC " << nc->display << " " << nc->pass << endl; - - db_buffer << "MD MEMOMAX " << nc->memos.memomax << endl; - - if (!nc->language.empty()) - db_buffer << "MD LANGUAGE " << nc->language << endl; - if (!nc->email.empty()) - db_buffer << "MD EMAIL " << nc->email << endl; - if (!nc->greet.empty()) - db_buffer << "MD GREET :" << nc->greet << endl; - - if (!nc->access.empty()) - { - for (std::vector<Anope::string>::const_iterator it = nc->access.begin(), it_end = nc->access.end(); it != it_end; ++it) - db_buffer << "MD ACCESS " << *it << endl; - } - if (!nc->cert.empty()) - { - for (std::vector<Anope::string>::const_iterator it = nc->cert.begin(), it_end = nc->cert.end(); it != it_end; ++it) - db_buffer << "MD CERT " << *it << endl; - } - db_buffer << "MD FLAGS "; - std::deque<Anope::string> list; - nc->GetExtList(list); - for (unsigned i = 0; i < list.size(); ++i) - db_buffer << list[i] << " "; - db_buffer << std::endl; - const MemoInfo *mi = &nc->memos; - for (unsigned k = 0, end = mi->memos->size(); k < end; ++k) - { - const Memo *m = mi->GetMemo(k); - db_buffer << "MD MI " << m->time << " " << m->sender; - if (m->unread) - db_buffer << " UNREAD"; - if (m->receipt) - db_buffer << " RECEIPT"; - db_buffer << " :" << m->text << endl; - } - for (unsigned k = 0, end = mi->ignores.size(); k < end; ++k) - db_buffer << "MD MIG " << Anope::string(mi->ignores[k]) << endl; - //FOREACH_MOD(OnDatabaseWriteMetadata, (WriteMetadata, nc)); - } - - for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it) - { - const NickAlias *na = it->second; - - db_buffer << "NA " << na->nc->display << " " << na->nick << " " << na->time_registered << " " << na->last_seen << endl; - if (!na->last_usermask.empty()) - db_buffer << "MD LAST_USERMASK " << na->last_usermask << endl; - if (!na->last_realhost.empty()) - db_buffer << "MD LAST_REALHOST " << na->last_realhost << endl; - if (!na->last_realname.empty()) - db_buffer << "MD LAST_REALNAME :" << na->last_realname << endl; - if (!na->last_quit.empty()) - db_buffer << "MD LAST_QUIT :" << na->last_quit << endl; - db_buffer << "MD FLAGS "; - std::deque<Anope::string> list; - na->GetExtList(list); - for (unsigned i = 0; i < list.size(); ++i) - db_buffer << list[i] << " "; - db_buffer << std::endl; - if (na->HasVhost()) - db_buffer << "MD VHOST " << na->GetVhostCreator() << " " << na->GetVhostCreated() << " " << na->GetVhostHost() << " :" << na->GetVhostIdent() << endl; - - //FOREACH_MOD(OnDatabaseWriteMetadata, (WriteMetadata, na)); - } - - for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) - { - BotInfo *bi = it->second; - - if (bi->HasExt("CONF")) - continue; - - db_buffer << "BI " << bi->nick << " " << bi->GetIdent() << " " << bi->host << " " << bi->created << " " << bi->GetChannelCount() << " :" << bi->realname << endl; - db_buffer << "MD FLAGS "; - std::deque<Anope::string> list; - bi->GetExtList(list); - for (unsigned i = 0; i < list.size(); ++i) - db_buffer << list[i] << " "; - db_buffer << std::endl; - } - - for (registered_channel_map::const_iterator cit = RegisteredChannelList->begin(), cit_end = RegisteredChannelList->end(); cit != cit_end; ++cit) - { - const ChannelInfo *ci = cit->second; - - db_buffer << "CH " << ci->name << " " << ci->time_registered << " " << ci->last_used << endl; - db_buffer << "MD BANTYPE " << ci->bantype << endl; - db_buffer << "MD MEMOMAX " << ci->memos.memomax << endl; - if (ci->GetFounder()) - db_buffer << "MD FOUNDER " << ci->GetFounder()->display << endl; - if (ci->GetSuccessor()) - db_buffer << "MD SUCCESSOR " << ci->GetSuccessor()->display << endl; - if (!ci->desc.empty()) - db_buffer << "MD DESC :" << ci->desc << endl; - if (!ci->last_topic.empty()) - db_buffer << "MD TOPIC " << ci->last_topic_setter << " " << ci->last_topic_time << " :" << ci->last_topic << endl; - db_buffer << "MD LEVELS"; - const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges(); - for (unsigned i = 0; i < privs.size(); ++i) - { - const Privilege &p = privs[i]; - db_buffer << p.name << " " << ci->GetLevel(p.name); - } - db_buffer << endl; - std::deque<Anope::string> list; - ci->GetExtList(list); - for (unsigned i = 0; i < list.size(); ++i) - db_buffer << list[i]; - db_buffer << std::endl; - if (ci->HasExt("SUSPENDED")) - { - Anope::string *by = ci->GetExt<ExtensibleItemClass<Anope::string> *>("suspend_by"), *reason = ci->GetExt<ExtensibleItemClass<Anope::string> *>("suspend_reason"); - if (by && reason) - db_buffer << "MD SUSPEND " << *by << " :" << *reason << endl; - } - for (unsigned k = 0, end = ci->GetAccessCount(); k < end; ++k) - { - const ChanAccess *access = ci->GetAccess(k); - db_buffer << "MD ACCESS2 " << access->provider->name << " " << access->mask << " " << access->AccessSerialize() << " " << access->last_seen << " " << access->creator << " " << access->created << endl; - } - for (unsigned k = 0, end = ci->GetAkickCount(); k < end; ++k) - { - db_buffer << "MD AKICK 0 " << (ci->GetAkick(k)->nc ? "NICK " : "MASK ") << - (ci->GetAkick(k)->nc ? ci->GetAkick(k)->nc->display : ci->GetAkick(k)->mask) << " " << ci->GetAkick(k)->creator << " " << ci->GetAkick(k)->addtime << " " << ci->last_used << " :"; - if (!ci->GetAkick(k)->reason.empty()) - db_buffer << ci->GetAkick(k)->reason; - db_buffer << endl; - } - for (unsigned k = 0, end = ci->log_settings->size(); k < end; ++k) - { - const LogSetting &l = *ci->log_settings->at(k); - - db_buffer << "MD LOG " << l.service_name << " " << l.command_service << " " << l.command_name << " " << l.method << " " << l.creator << " " << l.created << " " << l.extra << endl; - } - for (ChannelInfo::ModeList::const_iterator it = ci->GetMLock().begin(), it_end = ci->GetMLock().end(); it != it_end; ++it) - { - const ModeLock &ml = *it->second; - ChannelMode *cm = ModeManager::FindChannelModeByName(ml.name); - if (cm != NULL) - db_buffer << "MD MLOCK " << (ml.set ? 1 : 0) << " " << cm->name << " " << ml.setter << " " << ml.created << " " << ml.param << endl; - } - const MemoInfo *memos = &ci->memos; - for (unsigned k = 0, end = memos->memos->size(); k < end; ++k) - { - const Memo *m = memos->GetMemo(k); - db_buffer << "MD MI " << m->time << " " << m->sender; - if (m->unread) - db_buffer << " UNREAD"; - if (m->receipt) - db_buffer << " RECEIPT"; - db_buffer << " :" << m->text << endl; - } - for (unsigned k = 0, end = memos->ignores.size(); k < end; ++k) - db_buffer << "MD MIG " << Anope::string(memos->ignores[k]) << endl; - if (ci->bi) - db_buffer << "MD BI NAME " << ci->bi->nick << endl; - db_buffer << "MD BI TTB BOLDS " << ci->ttb[0] << " COLORS " << ci->ttb[1] << " REVERSES " << ci->ttb[2] << " UNDERLINES " << ci->ttb[3] << " BADWORDS " << ci->ttb[4] << " CAPS " << ci->ttb[5] << " FLOOD " << ci->ttb[6] << " REPEAT " << ci->ttb[7] << " ITALICS " << ci->ttb[8] << " AMSGS " << ci->ttb[9] << endl; - if (ci->capsmin) - db_buffer << "MD BI CAPSMIN " << ci->capsmin << endl; - if (ci->capspercent) - db_buffer << "MD BI CAPSPERCENT " << ci->capspercent << endl; - if (ci->floodlines) - db_buffer << "MD BI FLOODLINES " << ci->floodlines << endl; - if (ci->floodsecs) - db_buffer << "MD BI FLOODSECS " << ci->floodsecs << endl; - if (ci->repeattimes) - db_buffer << "MD BI REPEATTIMES " << ci->repeattimes << endl; - for (unsigned k = 0, end = ci->GetBadWordCount(); k < end; ++k) - db_buffer << "MD BI BADWORD " << (ci->GetBadWord(k)->type == BW_ANY ? "ANY " : "") << (ci->GetBadWord(k)->type == BW_SINGLE ? "SINGLE " : "") << (ci->GetBadWord(k)->type == BW_START ? "START " : "") << - (ci->GetBadWord(k)->type == BW_END ? "END " : "") << ":" << ci->GetBadWord(k)->word << endl; - - //FOREACH_MOD(OnDatabaseWriteMetadata, (WriteMetadata, ci)); - } - - db_buffer << "OS STATS " << MaxUserCount << " " << MaxUserTime << endl; - - for (std::list<XLineManager *>::iterator it = XLineManager::XLineManagers.begin(), it_end = XLineManager::XLineManagers.end(); it != it_end; ++it) - { - XLineManager *xl = *it; - for (unsigned i = 0, end = xl->GetCount(); i < end; ++i) - { - const XLine *x = xl->GetEntry(i); - db_buffer << "OS SXLINE " << xl->Type() << " " << x->GetUser() << " " << x->GetHost() << " " << x->by << " " << x->created << " " << x->expires << " :" << x->reason << endl; - } - } - - if (session_service) - for (SessionService::ExceptionVector::iterator it = session_service->GetExceptions().begin(); it != session_service->GetExceptions().end(); ++it) - { - Exception *e = *it; - db_buffer << "OS EXCEPTION " << e->mask << " " << e->limit << " " << e->who << " " << e->time << " " << e->expires << " " << e->reason << endl; - } - - //FOREACH_MOD(OnDatabaseWrite, (Write)); - - std::fstream db; - db.open(DatabaseFile.c_str(), std::ios_base::out | std::ios_base::trunc); - - if (!db.is_open()) - { - IRCD->SendGlobops(NULL, "Unable to open %s for writing!", DatabaseFile.c_str()); - return; - } - - db << db_buffer.str(); - db_buffer.str(""); - - db.close(); - } }; MODULE_INIT(DBPlain) |
