summaryrefslogtreecommitdiff
path: root/modules/database/db_flatfile.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-03-16 20:08:39 -0500
committerAdam <Adam@anope.org>2013-03-16 20:08:39 -0500
commit810685cb739dc32690bd571492629293b4a0e1fd (patch)
tree64829c1d9ca668ed97b59cf18acd9bbca856783d /modules/database/db_flatfile.cpp
parent1a0e6b0be3f901462d4376c882f1dc7304bedaf9 (diff)
Have db_flatfile store object ids if they are set, even though it doesn't use them, so that if other database modules that use them are loaded they can keep track of objects properly
Diffstat (limited to 'modules/database/db_flatfile.cpp')
-rw-r--r--modules/database/db_flatfile.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/modules/database/db_flatfile.cpp b/modules/database/db_flatfile.cpp
index 09fde3242..a7e65f1cb 100644
--- a/modules/database/db_flatfile.cpp
+++ b/modules/database/db_flatfile.cpp
@@ -36,11 +36,12 @@ 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), read(false) { }
+ LoadData() : fs(NULL), id(0), read(false) { }
std::iostream& operator[](const Anope::string &key) anope_override
{
@@ -48,7 +49,17 @@ class LoadData : public Serialize::Data
{
for (Anope::string token; std::getline(*this->fs, token.str());)
{
- if (token.find("DATA ") != 0)
+ 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
@@ -83,6 +94,7 @@ class LoadData : public Serialize::Data
void Reset()
{
+ id = 0;
read = false;
data.clear();
}
@@ -225,7 +237,9 @@ class DBFlatFile : public Module, public Pipe
fd.clear();
fd.seekg(pos[j]);
- stype->Unserialize(NULL, ld);
+ Serializable *obj = stype->Unserialize(NULL, ld);
+ if (obj != NULL)
+ obj->id = ld.id;
ld.Reset();
}
}
@@ -292,6 +306,8 @@ class DBFlatFile : public Module, public Pipe
continue;
*data.fs << "OBJECT " << s_type->GetName();
+ if (base->id)
+ *data.fs << "\nID " << base->id;
base->Serialize(data);
*data.fs << "\nEND\n";
}