diff options
| author | Adam <Adam@anope.org> | 2014-11-24 14:27:23 -0500 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2014-11-24 14:27:23 -0500 |
| commit | 42238034490fb5479d787bd1695750387d508200 (patch) | |
| tree | c93c62e0e1c936e656ae5b9ee1b62380ce2a194c /modules/database | |
| parent | d492923610d9c9146b2a2b63de38deab2cfd4ca7 (diff) | |
Rewrite serializable to have field level granularity
Represent serializable objects in a digraph, and as a result made most
object relationships implicitly defined, and use the graph to trace
references between objects to determine relationships. Edges may
also be marked as having a dependency of the object they point to,
which allows for automatic cleanup and deletion of most objects when
no longer needed.
Additionally, this allows not having to require in-memory copies of
everything when using external databases. db_sql has been rewritten
for this and now always requires a database to function. db_sql with
MySQL now requires InnoDB to make use of transactions and foreign
key constraints.
Diffstat (limited to 'modules/database')
| -rw-r--r-- | modules/database/db_flatfile.cpp | 368 | ||||
| -rw-r--r-- | modules/database/db_old.cpp | 468 | ||||
| -rw-r--r-- | modules/database/db_redis.cpp | 703 | ||||
| -rw-r--r-- | modules/database/db_sql.cpp | 488 | ||||
| -rw-r--r-- | modules/database/db_sql_live.cpp | 268 |
5 files changed, 860 insertions, 1435 deletions
diff --git a/modules/database/db_flatfile.cpp b/modules/database/db_flatfile.cpp index a2226a0ef..91e43e14e 100644 --- a/modules/database/db_flatfile.cpp +++ b/modules/database/db_flatfile.cpp @@ -10,104 +10,9 @@ #include "module.h" -#ifndef _WIN32 -#include <sys/wait.h> -#endif - -class SaveData : public Serialize::Data -{ - public: - Anope::string last; - std::fstream *fs; - - SaveData() : fs(NULL) { } - - std::iostream& operator[](const Anope::string &key) override - { - if (key != last) - { - *fs << "\nDATA " << key << " "; - last = key; - } - - return *fs; - } -}; - -class LoadData : public Serialize::Data -{ - public: - std::fstream *fs; - unsigned int id; - std::map<Anope::string, Anope::string> data; - std::stringstream ss; - bool read; - - LoadData() : fs(NULL), id(0), read(false) { } - - std::iostream& operator[](const Anope::string &key) override - { - if (!read) - { - for (Anope::string token; std::getline(*this->fs, token.str());) - { - if (token.find("ID ") == 0) - { - try - { - this->id = convertTo<unsigned int>(token.substr(3)); - } - catch (const ConvertException &) { } - - continue; - } - else if (token.find("DATA ") != 0) - break; - - size_t sp = token.find(' ', 5); // Skip DATA - if (sp != Anope::string::npos) - data[token.substr(5, sp - 5)] = token.substr(sp + 1); - } - - read = true; - } - - ss.clear(); - this->ss << this->data[key]; - return this->ss; - } - - std::set<Anope::string> KeySet() const override - { - std::set<Anope::string> keys; - for (std::map<Anope::string, Anope::string>::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it) - keys.insert(it->first); - return keys; - } - - size_t Hash() const override - { - size_t hash = 0; - for (std::map<Anope::string, Anope::string>::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it) - if (!it->second.empty()) - hash ^= Anope::hash_cs()(it->second); - return hash; - } - - void Reset() - { - id = 0; - read = false; - data.clear(); - } -}; - -class DBFlatFile : public Module, public Pipe - , public EventHook<Event::Restart> - , public EventHook<Event::Shutdown> +class DBFlatFile : public Module , public EventHook<Event::LoadDatabase> , public EventHook<Event::SaveDatabase> - , public EventHook<Event::SerializeTypeCreate> { /* Day the last backup was on */ int last_day; @@ -115,8 +20,6 @@ class DBFlatFile : public Module, public Pipe std::map<Anope::string, std::list<Anope::string> > backups; bool loaded; - int child_pid; - void BackupDatabase() { tm *tm = localtime(&Anope::CurTime); @@ -125,16 +28,16 @@ class DBFlatFile : public Module, public Pipe { last_day = tm->tm_mday; - const std::vector<Anope::string> &type_order = Serialize::Type::GetTypeOrder(); + const std::map<Anope::string, Serialize::TypeBase *> &types = Serialize::TypeBase::GetTypes(); std::set<Anope::string> dbs; dbs.insert(Config->GetModule(this)->Get<const Anope::string>("database", "anope.db")); - for (unsigned i = 0; i < type_order.size(); ++i) + for (const std::pair<Anope::string, Serialize::TypeBase *> &p : types) { - Serialize::Type *stype = Serialize::Type::Find(type_order[i]); + Serialize::TypeBase *stype = p.second; - if (stype && stype->GetOwner()) + if (stype->GetOwner()) dbs.insert("module_" + stype->GetOwner()->name + ".db"); } @@ -177,66 +80,17 @@ class DBFlatFile : public Module, public Pipe public: DBFlatFile(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR) - , EventHook<Event::Restart>("OnRestart") - , EventHook<Event::Shutdown>("OnShutdown") , EventHook<Event::LoadDatabase>("OnLoadDatabase") , EventHook<Event::SaveDatabase>("OnSaveDatabase") - , EventHook<Event::SerializeTypeCreate>("OnSerializeTypeCreate") , last_day(0) , loaded(false) - , child_pid(-1) { } -#ifndef _WIN32 - void OnRestart() override - { - OnShutdown(); - } - - void OnShutdown() override - { - if (child_pid > -1) - { - Log(this) << "Waiting for child to exit..."; - - int status; - waitpid(child_pid, &status, 0); - - Log(this) << "Done"; - } - } -#endif - - void OnNotify() override - { - char buf[512]; - int i = this->Read(buf, sizeof(buf) - 1); - if (i <= 0) - return; - buf[i] = 0; - - child_pid = -1; - - if (!*buf) - { - Log(this) << "Finished saving databases"; - return; - } - - Log(this) << "Error saving databases: " << buf; - - if (!Config->GetModule(this)->Get<bool>("nobackupok")) - Anope::Quitting = true; - } - EventReturn OnLoadDatabase() override { - const std::vector<Anope::string> &type_order = Serialize::Type::GetTypeOrder(); - std::set<Anope::string> tried_dbs; - - const Anope::string &db_name = Anope::DataDir + "/" + Config->GetModule(this)->Get<const Anope::string>("database", "anope.db"); + const Anope::string &db_name = Anope::DataDir + "/" + Config->GetModule(this)->Get<Anope::string>("database", "anope.db"); std::fstream fd(db_name.c_str(), std::ios_base::in | std::ios_base::binary); if (!fd.is_open()) @@ -245,32 +99,58 @@ class DBFlatFile : public Module, public Pipe return EVENT_STOP; } - std::map<Anope::string, std::vector<std::streampos> > positions; - + Serialize::TypeBase *type = nullptr; + Serialize::Object *obj = nullptr; for (Anope::string buf; std::getline(fd, buf.str());) + { + Log() << buf; if (buf.find("OBJECT ") == 0) - positions[buf.substr(7)].push_back(fd.tellg()); + { + Anope::string t = buf.substr(7); + if (obj) + Log(LOG_DEBUG) << "obj != null but got OBJECT"; + if (type) + Log(LOG_DEBUG) << "type != null but got OBJECT"; + type = Serialize::TypeBase::Find(t); + obj = nullptr; + } + else if (buf.find("ID ") == 0) + { + if (!type || obj) + continue; - LoadData ld; - ld.fs = &fd; + try + { + Serialize::ID id = convertTo<Serialize::ID>(buf.substr(3)); + obj = type->Require(id); + } + catch (const ConvertException &) + { + Log(LOG_DEBUG) << "Unable to parse object id " << buf.substr(3); + } + } + else if (buf.find("DATA ") == 0) + { + if (!type) + continue; - for (unsigned i = 0; i < type_order.size(); ++i) - { - Serialize::Type *stype = Serialize::Type::Find(type_order[i]); - if (!stype || stype->GetOwner()) - continue; + if (!obj) + obj = type->Create(); - std::vector<std::streampos> &pos = positions[stype->GetName()]; + size_t sp = buf.find(' ', 5); // Skip DATA + if (sp == Anope::string::npos) + continue; - for (unsigned j = 0; j < pos.size(); ++j) - { - fd.clear(); - fd.seekg(pos[j]); + Anope::string key = buf.substr(5, sp - 5), value = buf.substr(sp + 1); - Serializable *obj = stype->Unserialize(NULL, ld); - if (obj != NULL) - obj->id = ld.id; - ld.Reset(); + Serialize::FieldBase *field = type->GetField(key); + if (field) + field->UnserializeFromString(obj, value); + } + else if (buf.find("END") == 0) + { + type = nullptr; + obj = nullptr; } } @@ -283,142 +163,44 @@ class DBFlatFile : public Module, public Pipe void OnSaveDatabase() override { - if (child_pid > -1) - { - Log(this) << "Database save is already in progress!"; - return; - } - BackupDatabase(); - int i = -1; -#ifndef _WIN32 - if (!Anope::Quitting && Config->GetModule(this)->Get<bool>("fork")) - { - i = fork(); - if (i > 0) - { - child_pid = i; - return; - } - else if (i < 0) - Log(this) << "Unable to fork for database save"; - } -#endif + Anope::string db_name = Anope::DataDir + "/" + Config->GetModule(this)->Get<Anope::string>("database", "anope.db"); - try - { - std::map<Module *, std::fstream *> databases; - - /* First open the databases of all of the registered types. This way, if we have a type with 0 objects, that database will be properly cleared */ - for (std::map<Anope::string, Serialize::Type *>::const_iterator it = Serialize::Type::GetTypes().begin(), it_end = Serialize::Type::GetTypes().end(); it != it_end; ++it) - { - Serialize::Type *s_type = it->second; - - if (databases[s_type->GetOwner()]) - continue; + if (Anope::IsFile(db_name)) + rename(db_name.c_str(), (db_name + ".tmp").c_str()); - Anope::string db_name; - if (s_type->GetOwner()) - db_name = Anope::DataDir + "/module_" + s_type->GetOwner()->name + ".db"; - else - db_name = Anope::DataDir + "/" + Config->GetModule(this)->Get<const Anope::string>("database", "anope.db"); - - if (Anope::IsFile(db_name)) - rename(db_name.c_str(), (db_name + ".tmp").c_str()); - - std::fstream *fs = databases[s_type->GetOwner()] = new std::fstream(db_name.c_str(), std::ios_base::out | std::ios_base::trunc | std::ios_base::binary); - - if (!fs->is_open()) - Log(this) << "Unable to open " << db_name << " for writing"; - } - - SaveData data; - const std::list<Serializable *> &items = Serializable::GetItems(); - for (std::list<Serializable *>::const_iterator it = items.begin(), it_end = items.end(); it != it_end; ++it) - { - Serializable *base = *it; - Serialize::Type *s_type = base->GetSerializableType(); - - data.fs = databases[s_type->GetOwner()]; - if (!data.fs || !data.fs->is_open()) - continue; + std::fstream f(db_name.c_str(), std::ios_base::out | std::ios_base::trunc | std::ios_base::binary); - *data.fs << "OBJECT " << s_type->GetName(); - if (base->id) - *data.fs << "\nID " << base->id; - base->Serialize(data); - *data.fs << "\nEND\n"; - } - - for (std::map<Module *, std::fstream *>::iterator it = databases.begin(), it_end = databases.end(); it != it_end; ++it) - { - std::fstream *f = it->second; - const Anope::string &db_name = Anope::DataDir + "/" + (it->first ? (it->first->name + ".db") : Config->GetModule(this)->Get<const Anope::string>("database", "anope.db")); - - if (!f->is_open() || !f->good()) - { - this->Write("Unable to write database " + db_name); - - f->close(); - - if (Anope::IsFile((db_name + ".tmp").c_str())) - rename((db_name + ".tmp").c_str(), db_name.c_str()); - } - else - { - f->close(); - unlink((db_name + ".tmp").c_str()); - } - - delete f; - } - } - catch (...) + if (!f.is_open()) { - if (i) - throw; + Log(this) << "Unable to open " << db_name << " for writing"; } - - if (!i) + else { - this->Notify(); - exit(0); + for (std::pair<Serialize::ID, Serialize::Object *> p : Serialize::objects) + { + Serialize::Object *object = p.second; + Serialize::TypeBase *s_type = object->GetSerializableType(); + + f << "OBJECT " << s_type->GetName() << "\n"; + f << "ID " << object->id << "\n"; + for (Serialize::FieldBase *field : s_type->fields) + f << "DATA " << field->GetName() << " " << field->SerializeToString(object) << "\n"; + f << "END\n"; + } } - } - - /* Load just one type. Done if a module is reloaded during runtime */ - void OnSerializeTypeCreate(Serialize::Type *stype) override - { - if (!loaded) - return; - - Anope::string db_name; - if (stype->GetOwner()) - db_name = Anope::DataDir + "/module_" + stype->GetOwner()->name + ".db"; - else - db_name = Anope::DataDir + "/" + Config->GetModule(this)->Get<const Anope::string>("database", "anope.db"); - std::fstream fd(db_name.c_str(), std::ios_base::in | std::ios_base::binary); - if (!fd.is_open()) + if (!f.is_open() || !f.good()) { - Log(this) << "Unable to open " << db_name << " for reading!"; - return; + f.close(); + rename((db_name + ".tmp").c_str(), db_name.c_str()); } - - LoadData ld; - ld.fs = &fd; - - for (Anope::string buf; std::getline(fd, buf.str());) + else { - if (buf == "OBJECT " + stype->GetName()) - { - stype->Unserialize(NULL, ld); - ld.Reset(); - } + f.close(); + unlink((db_name + ".tmp").c_str()); } - - fd.close(); } }; diff --git a/modules/database/db_old.cpp b/modules/database/db_old.cpp index 587a8f227..fe7a47dc7 100644 --- a/modules/database/db_old.cpp +++ b/modules/database/db_old.cpp @@ -14,9 +14,12 @@ #include "modules/cs_mode.h" #include "modules/bs_badwords.h" #include "modules/os_news.h" -#include "modules/suspend.h" #include "modules/os_forbid.h" #include "modules/cs_entrymsg.h" +#include "modules/ns_suspend.h" +#include "modules/cs_suspend.h" +#include "modules/cs_access.h" +#include "modules/ns_access.h" #define READ(x) \ if (true) \ @@ -93,6 +96,18 @@ else \ #define OLD_NEWS_OPER 1 #define OLD_NEWS_RANDOM 2 +enum +{ + TTB_BOLDS, + TTB_COLORS, + TTB_REVERSES, + TTB_UNDERLINES, + TTB_BADWORDS, + TTB_CAPS, + TTB_FLOOD, + TTB_REPEAT, +}; + static struct mlock_info { char c; @@ -144,19 +159,21 @@ enum static void process_mlock(ChanServ::Channel *ci, uint32_t lock, bool status, uint32_t *limit, Anope::string *key) { - ModeLocks *ml = ci->Require<ModeLocks>("modelocks"); + if (!mlocks) + return; + 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 && ml) + if (cm) { if (limit && mlock_infos[i].c == 'l') - ml->SetMLock(cm, status, stringify(*limit)); + mlocks->SetMLock(ci, cm, status, stringify(*limit)); else if (key && mlock_infos[i].c == 'k') - ml->SetMLock(cm, status, *key); + mlocks->SetMLock(ci, cm, status, *key); else - ml->SetMLock(cm, status); + mlocks->SetMLock(ci, cm, status); } } } @@ -436,7 +453,6 @@ static void LoadNicks() { if (!NickServ::service) return; - ServiceReference<ForbidService> forbid("ForbidService", "forbid"); dbFILE *f = open_db_read("NickServ", "nick.db", 14); if (f == NULL) return; @@ -446,27 +462,33 @@ static void LoadNicks() Anope::string buffer; READ(read_string(buffer, f)); - NickServ::Account *nc = NickServ::service->CreateAccount(buffer); + + NickServ::Account *nc = NickServ::account.Create(); + nc->SetDisplay(buffer); const Anope::string settings[] = { "killprotect", "kill_quick", "ns_secure", "ns_private", "hide_email", "hide_mask", "hide_quit", "memo_signon", "memo_receive", "autoop", "msg", "ns_keepmodes" }; for (unsigned j = 0; j < sizeof(settings) / sizeof(Anope::string); ++j) - nc->Shrink<bool>(settings[j].upper()); + nc->UnsetS<bool>(settings[j].upper()); char pwbuf[32]; READ(read_buffer(pwbuf, f)); if (hashm == "plain") - my_b64_encode(pwbuf, nc->pass); + { + Anope::string p; + my_b64_encode(pwbuf, p); + nc->SetPassword(p); + } else if (hashm == "md5" || hashm == "oldmd5") - nc->pass = Hex(pwbuf, 16); + nc->SetPassword(Hex(pwbuf, 16)); else if (hashm == "sha1") - nc->pass = Hex(pwbuf, 20); + nc->SetPassword(Hex(pwbuf, 20)); else - nc->pass = Hex(pwbuf, strlen(pwbuf)); - nc->pass = hashm + ":" + nc->pass; + nc->SetPassword(Hex(pwbuf, strlen(pwbuf))); + nc->SetPassword(hashm + ":" + nc->GetPassword()); READ(read_string(buffer, f)); - nc->email = buffer; + nc->SetEmail(buffer); READ(read_string(buffer, f)); if (!buffer.empty()) @@ -481,103 +503,111 @@ static void LoadNicks() READ(read_uint32(&u32, f)); if (u32 & OLD_NI_KILLPROTECT) - nc->Extend<bool>("KILLPROTECT"); + nc->SetS<bool>("KILLPROTECT", true); if (u32 & OLD_NI_SECURE) - nc->Extend<bool>("NS_SECURE"); + nc->SetS<bool>("NS_SECURE", true); if (u32 & OLD_NI_MSG) - nc->Extend<bool>("MSG"); + nc->SetS<bool>("MSG", true); if (u32 & OLD_NI_MEMO_HARDMAX) - nc->Extend<bool>("MEMO_HARDMAX"); + nc->SetS<bool>("MEMO_HARDMAX", true); if (u32 & OLD_NI_MEMO_SIGNON) - nc->Extend<bool>("MEMO_SIGNON"); + nc->SetS<bool>("MEMO_SIGNON", true); if (u32 & OLD_NI_MEMO_RECEIVE) - nc->Extend<bool>("MEMO_RECEIVE"); + nc->SetS<bool>("MEMO_RECEIVE", true); if (u32 & OLD_NI_PRIVATE) - nc->Extend<bool>("NS_PRIVATE"); + nc->SetS<bool>("NS_PRIVATE", true); if (u32 & OLD_NI_HIDE_EMAIL) - nc->Extend<bool>("HIDE_EMAIL"); + nc->SetS<bool>("HIDE_EMAIL", true); if (u32 & OLD_NI_HIDE_MASK) - nc->Extend<bool>("HIDE_MASK"); + nc->SetS<bool>("HIDE_MASK", true); if (u32 & OLD_NI_HIDE_QUIT) - nc->Extend<bool>("HIDE_QUIT"); + nc->SetS<bool>("HIDE_QUIT", true); if (u32 & OLD_NI_KILL_QUICK) - nc->Extend<bool>("KILL_QUICK"); + nc->SetS<bool>("KILL_QUICK", true); if (u32 & OLD_NI_KILL_IMMED) - nc->Extend<bool>("KILL_IMMED"); + nc->SetS<bool>("KILL_IMMED", true); if (u32 & OLD_NI_MEMO_MAIL) - nc->Extend<bool>("MEMO_MAIL"); + nc->SetS<bool>("MEMO_MAIL", true); if (u32 & OLD_NI_HIDE_STATUS) - nc->Extend<bool>("HIDE_STATUS"); + nc->SetS<bool>("HIDE_STATUS", true); if (u32 & OLD_NI_SUSPENDED) { - SuspendInfo si; - si.what = nc->display; - si.when = si.expires = 0; - nc->Extend("NS_SUSPENDED", si); + if (nssuspendinfo) + { + NSSuspendInfo *si = nssuspendinfo.Create(); + si->SetAccount(nc); + } } if (!(u32 & OLD_NI_AUTOOP)) - nc->Extend<bool>("AUTOOP"); + nc->SetS<bool>("AUTOOP", true); uint16_t u16; READ(read_uint16(&u16, f)); switch (u16) { case LANG_ES: - nc->language = "es_ES"; + nc->SetLanguage("es_ES"); break; case LANG_PT: - nc->language = "pt_PT"; + nc->SetLanguage("pt_PT"); break; case LANG_FR: - nc->language = "fr_FR"; + nc->SetLanguage("fr_FR"); break; case LANG_TR: - nc->language = "tr_TR"; + nc->SetLanguage("tr_TR"); break; case LANG_IT: - nc->language = "it_IT"; + nc->SetLanguage("it_IT"); break; case LANG_DE: - nc->language = "de_DE"; + nc->SetLanguage("de_DE"); break; case LANG_CAT: - nc->language = "ca_ES"; // yes, iso639 defines catalan as CA + nc->SetLanguage("ca_ES"); // yes, iso639 defines catalan as CA break; case LANG_GR: - nc->language = "el_GR"; + nc->SetLanguage("el_GR"); break; case LANG_NL: - nc->language = "nl_NL"; + nc->SetLanguage("nl_NL"); break; case LANG_RU: - nc->language = "ru_RU"; + nc->SetLanguage("ru_RU"); break; case LANG_HUN: - nc->language = "hu_HU"; + nc->SetLanguage("hu_HU"); break; case LANG_PL: - nc->language = "pl_PL"; + nc->SetLanguage("pl_PL"); break; case LANG_EN_US: case LANG_JA_JIS: case LANG_JA_EUC: case LANG_JA_SJIS: // these seem to be unused default: - nc->language = "en"; + nc->SetLanguage("en"); } READ(read_uint16(&u16, f)); for (uint16_t j = 0; j < u16; ++j) { READ(read_string(buffer, f)); - nc->access.push_back(buffer); + + if (nsaccess) + { + NickAccess *a = nsaccess.Create(); + a->SetAccount(nc); + a->SetMask(buffer); + } } int16_t i16; READ(read_int16(&i16, f)); READ(read_int16(&i16, f)); - if (nc->memos) - nc->memos->memomax = i16; + MemoServ::MemoInfo *mi = nc->GetMemos(); + if (mi) + mi->SetMemoMax(i16); for (int16_t j = 0; j < i16; ++j) { MemoServ::Memo *m = MemoServ::service ? MemoServ::service->CreateMemo() : nullptr; @@ -587,26 +617,20 @@ static void LoadNicks() int32_t tmp32; READ(read_int32(&tmp32, f)); if (m) - m->time = tmp32; + m->SetTime(tmp32); char sbuf[32]; READ(read_buffer(sbuf, f)); if (m) - m->sender = sbuf; + m->SetSender(sbuf); Anope::string text; READ(read_string(text, f)); if (m) - m->text = text; - if (m) - m->owner = nc->display; - if (nc->memos && m) - nc->memos->memos->push_back(m); - else - delete m; + m->SetText(text); } READ(read_uint16(&u16, f)); READ(read_int16(&i16, f)); - Log(LOG_DEBUG) << "Loaded NickServ::Account " << nc->display; + Log(LOG_DEBUG) << "Loaded NickServ::Account " << nc->GetDisplay(); } for (int i = 0; i < 1024; ++i) @@ -640,41 +664,40 @@ static void LoadNicks() if (tmpu16 & OLD_NS_VERBOTEN) { - if (!forbid) + if (!forbiddata) { delete nc; continue; } - if (nc->display.find_first_of("?*") != Anope::string::npos) + if (nc->GetDisplay().find_first_of("?*") != Anope::string::npos) { delete nc; continue; } - ForbidData *d = forbid->CreateForbid(); - d->mask = nc->display; - d->creator = last_usermask; - d->reason = last_realname; - d->expires = 0; - d->created = 0; - d->type = FT_NICK; + ForbidData *d = forbiddata.Create(); + d->SetMask(nc->GetDisplay()); + d->SetCreator(last_usermask); + d->SetReason(last_realname); + d->SetType(FT_NICK); delete nc; - forbid->AddForbid(d); continue; } - NickServ::Nick *na = NickServ::service->CreateNick(nick, nc); - na->last_usermask = last_usermask; - na->last_realname = last_realname; - na->last_quit = last_quit; - na->time_registered = time_registered; - na->last_seen = last_seen; + NickServ::Nick *na = NickServ::nick.Create(); + na->SetNick(nick); + na->SetAccount(nc); + na->SetLastUsermask(last_usermask); + na->SetLastRealname(last_realname); + na->SetLastQuit(last_quit); + na->SetTimeRegistered(time_registered); + na->SetLastSeen(last_seen); if (tmpu16 & OLD_NS_NO_EXPIRE) - na->Extend<bool>("NS_NO_EXPIRE"); + na->SetS<bool>("NS_NO_EXPIRE", true); - Log(LOG_DEBUG) << "Loaded NickServ::Nick " << na->nick; + Log(LOG_DEBUG) << "Loaded NickServ::Nick " << na->GetNick(); } close_db(f); /* End of section Ia */ @@ -706,7 +729,7 @@ static void LoadVHosts() na->SetVhost(ident, host, creator, vtime); - Log() << "Loaded vhost for " << na->nick; + Log() << "Loaded vhost for " << na->GetNick(); } close_db(f); @@ -732,13 +755,14 @@ static void LoadBots() READ(read_int32(&created, f)); READ(read_int16(&chancount, f)); - BotInfo *bi = BotInfo::Find(nick, true); - if (!bi) - bi = new BotInfo(nick, user, host, real); - bi->created = created; + ServiceBot *bi = ServiceBot::Find(nick, true); + //XXX + // if (!bi) + // bi = new ServiceBot(nick, user, host, real); + bi->bi->SetCreated(created); if (flags & OLD_BI_PRIVATE) - bi->oper_only = true; + bi->bi->SetOperOnly(true); Log(LOG_DEBUG) << "Loaded bot " << bi->nick; } @@ -762,12 +786,13 @@ static void LoadChannels() Anope::string buffer; char namebuf[64]; READ(read_buffer(namebuf, f)); - ChanServ::Channel *ci = ChanServ::service->Create(namebuf); + ChanServ::Channel *ci = ChanServ::channel.Create(); + ci->SetName(namebuf); const Anope::string settings[] = { "keeptopic", "peace", "cs_private", "restricted", "cs_secure", "secureops", "securefounder", "signkick", "signkick_level", "topiclock", "persist", "noautoop", "cs_keepmodes" }; for (unsigned j = 0; j < sizeof(settings) / sizeof(Anope::string); ++j) - ci->Shrink<bool>(settings[j].upper()); + ci->UnsetS<bool>(settings[j].upper()); READ(read_string(buffer, f)); ci->SetFounder(NickServ::FindAccount(buffer)); @@ -778,71 +803,75 @@ static void LoadChannels() char pwbuf[32]; READ(read_buffer(pwbuf, f)); - READ(read_string(ci->desc, f)); + Anope::string desc; + READ(read_string(desc, f)); + ci->SetDesc(desc); READ(read_string(buffer, f)); READ(read_string(buffer, f)); int32_t tmp32; READ(read_int32(&tmp32, f)); - ci->time_registered = tmp32; + ci->SetTimeRegistered(tmp32); READ(read_int32(&tmp32, f)); - ci->last_used = tmp32; + ci->SetLastUsed(tmp32); - READ(read_string(ci->last_topic, f)); + Anope::string last_topic; + READ(read_string(last_topic, f)); + ci->SetLastTopic(last_topic); READ(read_buffer(pwbuf, f)); - ci->last_topic_setter = pwbuf; + ci->SetLastTopicSetter(pwbuf); READ(read_int32(&tmp32, f)); - ci->last_topic_time = tmp32; + ci->SetLastTopicTime(tmp32); uint32_t tmpu32; READ(read_uint32(&tmpu32, f)); // Temporary flags cleanup tmpu32 &= ~0x80000000; if (tmpu32 & OLD_CI_KEEPTOPIC) - ci->Extend<bool>("KEEPTOPIC"); + ci->SetS<bool>("KEEPTOPIC", true); if (tmpu32 & OLD_CI_SECUREOPS) - ci->Extend<bool>("SECUREOPS"); + ci->SetS<bool>("SECUREOPS", true); if (tmpu32 & OLD_CI_PRIVATE) - ci->Extend<bool>("CS_PRIVATE"); + ci->SetS<bool>("CS_PRIVATE", true); if (tmpu32 & OLD_CI_TOPICLOCK) - ci->Extend<bool>("TOPICLOCK"); + ci->SetS<bool>("TOPICLOCK", true); if (tmpu32 & OLD_CI_RESTRICTED) - ci->Extend<bool>("RESTRICTED"); + ci->SetS<bool>("RESTRICTED", true); if (tmpu32 & OLD_CI_PEACE) - ci->Extend<bool>("PEACE"); + ci->SetS<bool>("PEACE", true); if (tmpu32 & OLD_CI_SECURE) - ci->Extend<bool>("CS_SECURE"); + ci->SetS<bool>("CS_SECURE", true); if (tmpu32 & OLD_CI_NO_EXPIRE) - ci->Extend<bool>("CS_NO_EXPIRE"); + ci->SetS<bool>("CS_NO_EXPIRE", true); if (tmpu32 & OLD_CI_MEMO_HARDMAX) - ci->Extend<bool>("MEMO_HARDMAX"); + ci->SetS<bool>("MEMO_HARDMAX", true); if (tmpu32 & OLD_CI_SECUREFOUNDER) - ci->Extend<bool>("SECUREFOUNDER"); + ci->SetS<bool>("SECUREFOUNDER", true); if (tmpu32 & OLD_CI_SIGNKICK) - ci->Extend<bool>("SIGNKICK"); + ci->SetS<bool>("SIGNKICK", true); if (tmpu32 & OLD_CI_SIGNKICK_LEVEL) - ci->Extend<bool>("SIGNKICK_LEVEL"); + ci->SetS<bool>("SIGNKICK_LEVEL", true); Anope::string forbidby, forbidreason; READ(read_string(forbidby, f)); READ(read_string(forbidreason, f)); if (tmpu32 & OLD_CI_SUSPENDED) { - SuspendInfo si; - si.what = ci->name; - si.by = forbidby; - si.reason = forbidreason; - si.when = si.expires = 0; - ci->Extend("CS_SUSPENDED", si); + if (cssuspendinfo) + { + CSSuspendInfo *si = cssuspendinfo.Create(); + si->SetChannel(ci); + si->SetBy(forbidby); + } } bool forbid_chan = tmpu32 & OLD_CI_VERBOTEN; int16_t tmp16; READ(read_int16(&tmp16, f)); - ci->bantype = tmp16; + ci->SetBanType(tmp16); READ(read_int16(&tmp16, f)); if (tmp16 > 36) @@ -856,13 +885,12 @@ static void LoadChannels() level = ChanServ::ACCESS_FOUNDER; if (j == 10 && level < 0) // NOJOIN - ci->Shrink<bool>("RESTRICTED"); // If CSDefRestricted was enabled this can happen + ci->UnsetS<bool>("RESTRICTED"); // If CSDefRestricted was enabled this can happen ci->SetLevel(GetLevelName(j), level); } bool xop = tmpu32 & OLD_CI_XOP; - ServiceReference<ChanServ::AccessProvider> provider_access("AccessProvider", "access/access"), provider_xop("AccessProvider", "access/xop"); uint16_t tmpu16; READ(read_uint16(&tmpu16, f)); for (uint16_t j = 0; j < tmpu16; ++j) @@ -875,15 +903,17 @@ static void LoadChannels() if (xop) { - if (provider_xop) - access = provider_xop->Create(); + if (xopchanaccess) + access = xopchanaccess.Create(); } else - if (provider_access) - access = provider_access->Create(); + { + if (accesschanaccess) + access = accesschanaccess.Create(); + } if (access) - access->ci = ci; + access->SetChannel(ci); int16_t level; READ(read_int16(&level, f)); @@ -914,16 +944,19 @@ static void LoadChannels() Anope::string mask; READ(read_string(mask, f)); if (access) - access->SetMask(mask, ci); + { + access->SetMask(mask); + NickServ::Nick *na = NickServ::FindNick(mask); + if (na) + na->SetAccount(na->GetAccount()); + } READ(read_int32(&tmp32, f)); if (access) { - access->last_seen = tmp32; - access->creator = "Unknown"; - access->created = Anope::CurTime; - - ci->AddAccess(access); + access->SetLastSeen(tmp32); + access->SetCreator("Unknown"); + access->SetCreated(Anope::CurTime); } } } @@ -958,8 +991,9 @@ static void LoadChannels() READ(read_int16(&tmp16, f)); READ(read_int16(&tmp16, f)); - if (ci->memos) - ci->memos->memomax = tmp16; + MemoServ::MemoInfo *mi = ci->GetMemos(); + if (mi) + mi->SetMemoMax(tmp16); for (int16_t j = 0; j < tmp16; ++j) { READ(read_uint32(&tmpu32, f)); @@ -967,74 +1001,56 @@ static void LoadChannels() MemoServ::Memo *m = MemoServ::service ? MemoServ::service->CreateMemo() : nullptr; READ(read_int32(&tmp32, f)); if (m) - m->time = tmp32; + m->SetTime(tmp32); char sbuf[32]; READ(read_buffer(sbuf, f)); if (m) - m->sender = sbuf; + m->SetSender(sbuf); Anope::string text; READ(read_string(text, f)); if (m) - m->text = text; - if (m) - m->owner = ci->name; - if (ci->memos && m) - ci->memos->memos->push_back(m); - else - delete m; + m->SetText(text); } READ(read_string(buffer, f)); if (!buffer.empty()) { - EntryMessageList *eml = ci->Require<EntryMessageList>("entrymsg"); - if (eml) + if (entrymsg) { - EntryMsg *e = eml->Create(); - - e->chan = ci->name; - e->creator = "Unknown"; - e->message = buffer; - e->when = Anope::CurTime; - - (*eml)->push_back(e); + EntryMsg *e = entrymsg.Create(); + e->SetChannel(ci); + e->SetCreator("Unknown"); + e->SetMessage(buffer); + e->SetWhen(Anope::CurTime); } } READ(read_string(buffer, f)); - ci->bi = BotInfo::Find(buffer, true); + ci->SetBot(ServiceBot::Find(buffer, true)); READ(read_int32(&tmp32, f)); if (tmp32 & OLD_BS_DONTKICKOPS) - ci->Extend<bool>("BS_DONTKICKOPS"); + ci->SetS<bool>("BS_DONTKICKOPS", true); if (tmp32 & OLD_BS_DONTKICKVOICES) - ci->Extend<bool>("BS_DONTKICKVOICES"); |
