1
0
mirror of https://github.com/anope/anope.git synced 2026-06-29 00:46:39 +02:00

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

This commit is contained in:
Adam
2013-03-16 20:08:39 -05:00
parent 1a0e6b0be3
commit 810685cb73
2 changed files with 30 additions and 8 deletions
+19 -3
View File
@@ -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";
}