diff options
author | Adam <Adam@anope.org> | 2012-12-25 15:52:58 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2012-12-25 15:52:58 -0500 |
commit | 392b591d09509ae788f59b1b63a947ed7d8ad562 (patch) | |
tree | fb34d59492895d676e07c47b364829ec9eeb1a14 /modules/database/db_flatfile.cpp | |
parent | 556a4375e226760169150179b5bcaa659aaf055e (diff) |
Allow modules loaded after startup to magically reobtain their database objects. Fix os_dns for sql(live)
Diffstat (limited to 'modules/database/db_flatfile.cpp')
-rw-r--r-- | modules/database/db_flatfile.cpp | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/modules/database/db_flatfile.cpp b/modules/database/db_flatfile.cpp index 66715b9f8..3aaadd7c0 100644 --- a/modules/database/db_flatfile.cpp +++ b/modules/database/db_flatfile.cpp @@ -73,6 +73,7 @@ class DBFlatFile : public Module, public Pipe /* Backup file names */ std::map<Anope::string, std::list<Anope::string> > backups; bool use_fork; + bool loaded; void BackupDatabase() { @@ -128,11 +129,11 @@ class DBFlatFile : public Module, public Pipe } public: - DBFlatFile(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE), last_day(0), use_fork(false) + DBFlatFile(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE), last_day(0), use_fork(false), loaded(false) { this->SetAuthor("Anope"); - Implementation i[] = { I_OnReload, I_OnLoadDatabase, I_OnSaveDatabase }; + Implementation i[] = { I_OnReload, I_OnLoadDatabase, I_OnSaveDatabase, I_OnSerializeTypeCreate }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); OnReload(); @@ -208,6 +209,7 @@ class DBFlatFile : public Module, public Pipe fd.close(); + loaded = true; return EVENT_STOP; } @@ -306,6 +308,40 @@ class DBFlatFile : public Module, public Pipe return EVENT_CONTINUE; } + + /* Load just one type. Done if a module is reloaded during runtime */ + void OnSerializeTypeCreate(Serialize::Type *stype) anope_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 + "/" + database_file; + + std::fstream fd(db_name.c_str(), std::ios_base::in); + if (!fd.is_open()) + { + Log(this) << "Unable to open " << db_name << " for reading!"; + return; + } + + LoadData ld; + ld.fs = &fd; + + for (Anope::string buf; std::getline(fd, buf.str());) + { + if (buf == "OBJECT " + stype->GetName()) + { + stype->Unserialize(NULL, ld); + ld.Reset(); + } + } + + fd.close(); + } }; MODULE_INIT(DBFlatFile) |