mirror of
https://github.com/anope/anope.git
synced 2026-06-29 12:16:38 +02:00
Allow modules to store data in their own databases.
This commit is contained in:
@@ -73,7 +73,6 @@ class CoreExport ChanAccess : public Serializable
|
||||
ChanAccess(AccessProvider *p);
|
||||
virtual ~ChanAccess();
|
||||
|
||||
const Anope::string serialize_name() const anope_override;
|
||||
Serialize::Data serialize() const anope_override;
|
||||
static Serializable* unserialize(Serializable *obj, Serialize::Data &);
|
||||
|
||||
|
||||
@@ -134,7 +134,6 @@ class CoreExport NickAlias : public Extensible, public Flags<NickNameFlag, NS_EN
|
||||
time_t last_seen; /* When it was seen online for the last time */
|
||||
serialize_obj<NickCore> nc; /* I'm an alias of this */
|
||||
|
||||
const Anope::string serialize_name() const anope_override;
|
||||
Serialize::Data serialize() const anope_override;
|
||||
static Serializable* unserialize(Serializable *obj, Serialize::Data &);
|
||||
|
||||
@@ -218,7 +217,6 @@ class CoreExport NickCore : public Extensible, public Flags<NickCoreFlag, NI_END
|
||||
time_t lastmail; /* Last time this nick record got a mail */
|
||||
std::list<serialize_obj<NickAlias> > aliases; /* List of aliases */
|
||||
|
||||
const Anope::string serialize_name() const anope_override;
|
||||
Serialize::Data serialize() const anope_override;
|
||||
static Serializable* unserialize(Serializable *obj, Serialize::Data &);
|
||||
|
||||
|
||||
@@ -62,7 +62,6 @@ class CoreExport BotInfo : public User, public Flags<BotFlag, BI_END>, public Se
|
||||
*/
|
||||
virtual ~BotInfo();
|
||||
|
||||
const Anope::string serialize_name() const;
|
||||
Serialize::Data serialize() const;
|
||||
static Serializable* unserialize(Serializable *obj, Serialize::Data &);
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ class CoreExport Memo : public Flags<MemoFlag>, public Serializable
|
||||
public:
|
||||
Memo();
|
||||
|
||||
const Anope::string serialize_name() const anope_override;
|
||||
Serialize::Data serialize() const anope_override;
|
||||
static Serializable* unserialize(Serializable *obj, Serialize::Data &);
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ class CoreExport XLine : public Serializable
|
||||
bool HasNickOrReal() const;
|
||||
bool IsRegex() const;
|
||||
|
||||
const Anope::string serialize_name() const anope_override;
|
||||
Serialize::Data serialize() const anope_override;
|
||||
static Serializable* unserialize(Serializable *obj, Serialize::Data &data);
|
||||
};
|
||||
|
||||
@@ -95,7 +95,7 @@ struct CoreExport BadWord : Serializable
|
||||
Anope::string word;
|
||||
BadWordType type;
|
||||
|
||||
const Anope::string serialize_name() const anope_override;
|
||||
BadWord() : Serializable("BadWord") { }
|
||||
Serialize::Data serialize() const anope_override;
|
||||
static Serializable* unserialize(Serializable *obj, Serialize::Data &);
|
||||
};
|
||||
@@ -125,7 +125,6 @@ class CoreExport AutoKick : public Flags<AutoKickFlag>, public Serializable
|
||||
time_t addtime;
|
||||
time_t last_used;
|
||||
|
||||
const Anope::string serialize_name() const anope_override;
|
||||
Serialize::Data serialize() const anope_override;
|
||||
static Serializable* unserialize(Serializable *obj, Serialize::Data &);
|
||||
};
|
||||
@@ -142,7 +141,6 @@ struct CoreExport ModeLock : Serializable
|
||||
|
||||
ModeLock(ChannelInfo *ch, bool s, ChannelModeName n, const Anope::string &p, const Anope::string &se = "", time_t c = Anope::CurTime);
|
||||
|
||||
const Anope::string serialize_name() const anope_override;
|
||||
Serialize::Data serialize() const anope_override;
|
||||
static Serializable* unserialize(Serializable *obj, Serialize::Data &);
|
||||
};
|
||||
@@ -160,7 +158,7 @@ struct CoreExport LogSetting : Serializable
|
||||
Anope::string creator;
|
||||
time_t created;
|
||||
|
||||
const Anope::string serialize_name() const anope_override;
|
||||
LogSetting() : Serializable("LogSetting") { }
|
||||
Serialize::Data serialize() const anope_override;
|
||||
static Serializable* unserialize(Serializable *obj, Serialize::Data &);
|
||||
};
|
||||
@@ -219,7 +217,6 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
|
||||
int16_t floodlines, floodsecs; /* For FLOOD kicker */
|
||||
int16_t repeattimes; /* For REPEAT kicker */
|
||||
|
||||
const Anope::string serialize_name() const anope_override;
|
||||
Serialize::Data serialize() const anope_override;
|
||||
static Serializable* unserialize(Serializable *obj, Serialize::Data &);
|
||||
|
||||
|
||||
+19
-5
@@ -62,18 +62,22 @@ namespace Serialize
|
||||
|
||||
extern void RegisterTypes();
|
||||
|
||||
class SerializeType;
|
||||
|
||||
class CoreExport Serializable : public virtual Base
|
||||
{
|
||||
private:
|
||||
static std::list<Serializable *> *serializable_items;
|
||||
|
||||
SerializeType *s_type;
|
||||
private:
|
||||
std::list<Serializable *>::iterator s_iter;
|
||||
std::list<Serializable *>::iterator s_iter; // Iterator into serializable_items
|
||||
|
||||
Serialize::Data last_commit;
|
||||
time_t last_commit_time;
|
||||
|
||||
protected:
|
||||
Serializable();
|
||||
protected:
|
||||
Serializable(const Anope::string &serialize_type);
|
||||
Serializable(const Serializable &);
|
||||
|
||||
virtual ~Serializable();
|
||||
@@ -93,7 +97,8 @@ class CoreExport Serializable : public virtual Base
|
||||
bool IsTSCached();
|
||||
void UpdateTS();
|
||||
|
||||
virtual const Anope::string serialize_name() const = 0;
|
||||
SerializeType* GetSerializableType() const;
|
||||
|
||||
virtual Serialize::Data serialize() const = 0;
|
||||
|
||||
static const std::list<Serializable *> &GetItems();
|
||||
@@ -108,12 +113,19 @@ class CoreExport SerializeType
|
||||
|
||||
Anope::string name;
|
||||
unserialize_func unserialize;
|
||||
Module *owner;
|
||||
|
||||
time_t timestamp;
|
||||
|
||||
public:
|
||||
std::map<unsigned int, Serializable *> objects;
|
||||
|
||||
SerializeType(const Anope::string &n, unserialize_func f);
|
||||
/** Creates a new serializable type
|
||||
* @param n Type name
|
||||
* @param f Func to unserialize objects
|
||||
* @param owner Owner of this type. Leave NULL for the core.
|
||||
*/
|
||||
SerializeType(const Anope::string &n, unserialize_func f, Module *owner = NULL);
|
||||
~SerializeType();
|
||||
|
||||
const Anope::string &GetName();
|
||||
@@ -125,6 +137,8 @@ class CoreExport SerializeType
|
||||
time_t GetTimestamp() const;
|
||||
void UpdateTimestamp();
|
||||
|
||||
Module* GetOwner() const;
|
||||
|
||||
static SerializeType *Find(const Anope::string &name);
|
||||
|
||||
static const std::vector<Anope::string> &GetTypeOrder();
|
||||
|
||||
@@ -20,7 +20,7 @@ struct EntryMsg : Serializable
|
||||
Anope::string message;
|
||||
time_t when;
|
||||
|
||||
EntryMsg(ChannelInfo *c, const Anope::string &cname, const Anope::string &cmessage, time_t ct = Anope::CurTime)
|
||||
EntryMsg(ChannelInfo *c, const Anope::string &cname, const Anope::string &cmessage, time_t ct = Anope::CurTime) : Serializable("EntryMsg")
|
||||
{
|
||||
this->ci = c;
|
||||
this->creator = cname;
|
||||
@@ -28,11 +28,6 @@ struct EntryMsg : Serializable
|
||||
this->when = ct;
|
||||
}
|
||||
|
||||
const Anope::string serialize_name() const anope_override
|
||||
{
|
||||
return "EntryMsg";
|
||||
}
|
||||
|
||||
Serialize::Data serialize() const anope_override
|
||||
{
|
||||
Serialize::Data data;
|
||||
|
||||
@@ -33,15 +33,10 @@ struct SeenInfo : Serializable
|
||||
Anope::string message; // for part/kick/quit
|
||||
time_t last; // the time when the user was last seen
|
||||
|
||||
SeenInfo()
|
||||
SeenInfo() : Serializable("SeenInfo")
|
||||
{
|
||||
}
|
||||
|
||||
const Anope::string serialize_name() const anope_override
|
||||
{
|
||||
return "SeenInfo";
|
||||
}
|
||||
|
||||
Serialize::Data serialize() const anope_override
|
||||
{
|
||||
Serialize::Data data;
|
||||
|
||||
@@ -18,15 +18,10 @@ struct CSMiscData : ExtensibleItem, Serializable
|
||||
Anope::string name;
|
||||
Anope::string data;
|
||||
|
||||
CSMiscData(ChannelInfo *c, const Anope::string &n, const Anope::string &d) : ci(c), name(n), data(d)
|
||||
CSMiscData(ChannelInfo *c, const Anope::string &n, const Anope::string &d) : Serializable("CSMiscData"), ci(c), name(n), data(d)
|
||||
{
|
||||
}
|
||||
|
||||
const Anope::string serialize_name() const anope_override
|
||||
{
|
||||
return "CSMiscData";
|
||||
}
|
||||
|
||||
Serialize::Data serialize() const anope_override
|
||||
{
|
||||
Serialize::Data sdata;
|
||||
|
||||
@@ -18,15 +18,10 @@ struct ChanSuspend : ExtensibleItem, Serializable
|
||||
Anope::string chan;
|
||||
time_t when;
|
||||
|
||||
ChanSuspend()
|
||||
ChanSuspend() : Serializable("ChanSuspend")
|
||||
{
|
||||
}
|
||||
|
||||
const Anope::string serialize_name() const
|
||||
{
|
||||
return "ChanSuspend";
|
||||
}
|
||||
|
||||
Serialize::Data serialize() const anope_override
|
||||
{
|
||||
Serialize::Data sd;
|
||||
|
||||
@@ -30,10 +30,7 @@ struct HostRequest : ExtensibleItem, Serializable
|
||||
Anope::string host;
|
||||
time_t time;
|
||||
|
||||
const Anope::string serialize_name() const anope_override
|
||||
{
|
||||
return "HostRequest";
|
||||
}
|
||||
HostRequest() : Serializable("HostRequest") { }
|
||||
|
||||
Serialize::Data serialize() const anope_override
|
||||
{
|
||||
|
||||
@@ -26,10 +26,7 @@ struct AJoinEntry : Serializable
|
||||
Anope::string channel;
|
||||
Anope::string key;
|
||||
|
||||
const Anope::string serialize_name() const anope_override
|
||||
{
|
||||
return "AJoinEntry";
|
||||
}
|
||||
AJoinEntry() : Serializable("AJoinEntry") { }
|
||||
|
||||
Serialize::Data serialize() const anope_override
|
||||
{
|
||||
|
||||
@@ -19,15 +19,10 @@ struct NSMiscData : ExtensibleItem, Serializable
|
||||
Anope::string name;
|
||||
Anope::string data;
|
||||
|
||||
NSMiscData(NickCore *ncore, const Anope::string &n, const Anope::string &d) : nc(ncore), name(n), data(d)
|
||||
NSMiscData(NickCore *ncore, const Anope::string &n, const Anope::string &d) : Serializable("NSMiscData"), nc(ncore), name(n), data(d)
|
||||
{
|
||||
}
|
||||
|
||||
const Anope::string serialize_name() const anope_override
|
||||
{
|
||||
return "NSMiscData";
|
||||
}
|
||||
|
||||
Serialize::Data serialize() const anope_override
|
||||
{
|
||||
Serialize::Data sdata;
|
||||
|
||||
@@ -18,15 +18,10 @@ struct NickSuspend : ExtensibleItem, Serializable
|
||||
Anope::string nick;
|
||||
time_t when;
|
||||
|
||||
NickSuspend()
|
||||
NickSuspend() : Serializable("NickSuspend")
|
||||
{
|
||||
}
|
||||
|
||||
const Anope::string serialize_name() const
|
||||
{
|
||||
return "NickSuspend";
|
||||
}
|
||||
|
||||
Serialize::Data serialize() const anope_override
|
||||
{
|
||||
Serialize::Data sd;
|
||||
|
||||
@@ -18,7 +18,7 @@ struct ForbidData : Serializable
|
||||
time_t expires;
|
||||
ForbidType type;
|
||||
|
||||
const Anope::string serialize_name() const anope_override { return "ForbidData"; }
|
||||
ForbidData() : Serializable("ForbidData") { }
|
||||
Serialize::Data serialize() const anope_override;
|
||||
static Serializable* unserialize(Serializable *obj, Serialize::Data &data);
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@ struct IgnoreData : Serializable
|
||||
Anope::string reason;
|
||||
time_t time; /* When do we stop ignoring them? */
|
||||
|
||||
const Anope::string serialize_name() const anope_override { return "IgnoreData"; }
|
||||
IgnoreData() : Serializable("IgnoreData") { }
|
||||
Serialize::Data serialize() const anope_override;
|
||||
static Serializable* unserialize(Serializable *obj, Serialize::Data &data);
|
||||
};
|
||||
|
||||
@@ -22,7 +22,7 @@ struct NewsItem : Serializable
|
||||
Anope::string who;
|
||||
time_t time;
|
||||
|
||||
const Anope::string serialize_name() const anope_override { return "NewsItem"; }
|
||||
NewsItem() : Serializable("NewsItem") { }
|
||||
Serialize::Data serialize() const anope_override;
|
||||
static Serializable* unserialize(Serializable *obj, Serialize::Data &data);
|
||||
};
|
||||
|
||||
@@ -15,12 +15,7 @@
|
||||
|
||||
struct MyOper : Oper, Serializable
|
||||
{
|
||||
MyOper(const Anope::string &n, OperType *o) : Oper(n, o) { }
|
||||
|
||||
const Anope::string serialize_name() const anope_override
|
||||
{
|
||||
return "Oper";
|
||||
}
|
||||
MyOper(const Anope::string &n, OperType *o) : Oper(n, o), Serializable("Oper") { }
|
||||
|
||||
Serialize::Data serialize() const anope_override
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@ struct Exception : Serializable
|
||||
time_t time; /* When this exception was added */
|
||||
time_t expires; /* Time when it expires. 0 == no expiry */
|
||||
|
||||
const Anope::string serialize_name() const anope_override { return "Exception"; }
|
||||
Exception() : Serializable("Exception") { }
|
||||
Serialize::Data serialize() const anope_override;
|
||||
static Serializable* unserialize(Serializable *obj, Serialize::Data &data);
|
||||
};
|
||||
|
||||
@@ -15,10 +15,7 @@
|
||||
|
||||
struct Stats : Serializable
|
||||
{
|
||||
const Anope::string serialize_name() const
|
||||
{
|
||||
return "Stats";
|
||||
}
|
||||
Stats() : Serializable("Stats") { }
|
||||
|
||||
Serialize::Data serialize() const anope_override
|
||||
{
|
||||
|
||||
@@ -82,42 +82,58 @@ class DBFlatFile : public Module
|
||||
|
||||
EventReturn OnLoadDatabase() anope_override
|
||||
{
|
||||
std::fstream db;
|
||||
db.open(DatabaseFile.c_str(), std::ios_base::in);
|
||||
std::map<Module *, std::fstream *> databases;
|
||||
databases[NULL] = new std::fstream(DatabaseFile.c_str(), std::ios_base::in);
|
||||
|
||||
if (!db.is_open())
|
||||
if (!databases[NULL]->is_open())
|
||||
{
|
||||
delete databases[NULL];
|
||||
Log() << "Unable to open " << DatabaseFile << " for reading!";
|
||||
return EVENT_CONTINUE;
|
||||
}
|
||||
|
||||
SerializeType *st = NULL;
|
||||
Serialize::Data data;
|
||||
std::multimap<SerializeType *, Serialize::Data> objects;
|
||||
for (Anope::string buf, token; std::getline(db, buf.str());)
|
||||
const std::vector<Anope::string> type_order = SerializeType::GetTypeOrder();
|
||||
|
||||
for (unsigned i = 0; i < type_order.size(); ++i)
|
||||
{
|
||||
spacesepstream sep(buf);
|
||||
|
||||
if (!sep.GetToken(token))
|
||||
continue;
|
||||
|
||||
if (token == "OBJECT" && sep.GetToken(token))
|
||||
SerializeType *stype = SerializeType::Find(type_order[i]);
|
||||
if (stype && !databases.count(stype->GetOwner()))
|
||||
{
|
||||
st = SerializeType::Find(token);
|
||||
data.clear();
|
||||
}
|
||||
else if (token == "DATA" && st != NULL && sep.GetToken(token))
|
||||
data[token] << sep.GetRemaining();
|
||||
else if (token == "END" && st != NULL)
|
||||
{
|
||||
objects.insert(std::make_pair(st, data));
|
||||
|
||||
st = NULL;
|
||||
data.clear();
|
||||
Anope::string db_name = db_dir + "/module_" + stype->GetOwner()->name + ".db";
|
||||
databases[stype->GetOwner()] = new std::fstream(db_name.c_str(), std::ios_base::in);
|
||||
}
|
||||
}
|
||||
|
||||
std::multimap<SerializeType *, Serialize::Data> objects;
|
||||
for (std::map<Module *, std::fstream *>::iterator it = databases.begin(), it_end = databases.end(); it != it_end; ++it)
|
||||
{
|
||||
std::fstream *db = it->second;
|
||||
SerializeType *st = NULL;
|
||||
Serialize::Data data;
|
||||
for (Anope::string buf, token; std::getline(*db, buf.str());)
|
||||
{
|
||||
spacesepstream sep(buf);
|
||||
|
||||
if (!sep.GetToken(token))
|
||||
continue;
|
||||
|
||||
if (token == "OBJECT" && sep.GetToken(token))
|
||||
{
|
||||
st = SerializeType::Find(token);
|
||||
data.clear();
|
||||
}
|
||||
else if (token == "DATA" && st != NULL && sep.GetToken(token))
|
||||
data[token] << sep.GetRemaining();
|
||||
else if (token == "END" && st != NULL)
|
||||
{
|
||||
objects.insert(std::make_pair(st, data));
|
||||
|
||||
st = NULL;
|
||||
data.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<Anope::string> type_order = SerializeType::GetTypeOrder();
|
||||
for (unsigned i = 0; i < type_order.size(); ++i)
|
||||
{
|
||||
SerializeType *stype = SerializeType::Find(type_order[i]);
|
||||
@@ -129,7 +145,11 @@ class DBFlatFile : public Module
|
||||
it->first->Unserialize(NULL, it->second);
|
||||
}
|
||||
|
||||
db.close();
|
||||
for (std::map<Module *, std::fstream *>::iterator it = databases.begin(), it_end = databases.end(); it != it_end; ++it)
|
||||
{
|
||||
it->second->close();
|
||||
delete it->second;
|
||||
}
|
||||
|
||||
return EVENT_STOP;
|
||||
}
|
||||
@@ -143,9 +163,11 @@ class DBFlatFile : public Module
|
||||
if (IsFile(DatabaseFile))
|
||||
rename(DatabaseFile.c_str(), tmp_db.c_str());
|
||||
|
||||
std::fstream db(DatabaseFile.c_str(), std::ios_base::out | std::ios_base::trunc);
|
||||
if (!db.is_open())
|
||||
std::map<Module *, std::fstream *> databases;
|
||||
databases[NULL] = new std::fstream(DatabaseFile.c_str(), std::ios_base::out | std::ios_base::trunc);
|
||||
if (!databases[NULL]->is_open())
|
||||
{
|
||||
delete databases[NULL];
|
||||
Log() << "Unable to open " << DatabaseFile << " for writing";
|
||||
if (IsFile(tmp_db))
|
||||
rename(tmp_db.c_str(), DatabaseFile.c_str());
|
||||
@@ -156,19 +178,30 @@ class DBFlatFile : public Module
|
||||
for (std::list<Serializable *>::const_iterator it = items.begin(), it_end = items.end(); it != it_end; ++it)
|
||||
{
|
||||
Serializable *base = *it;
|
||||
SerializeType *s_type = base->GetSerializableType();
|
||||
|
||||
if (!s_type)
|
||||
continue;
|
||||
|
||||
Serialize::Data data = base->serialize();
|
||||
|
||||
if (!databases.count(s_type->GetOwner()))
|
||||
{
|
||||
Anope::string db_name = db_dir + "/module_" + s_type->GetOwner()->name + ".db";
|
||||
databases[s_type->GetOwner()] = new std::fstream(db_name.c_str(), std::ios_base::out | std::ios_base::trunc);
|
||||
}
|
||||
std::fstream *fd = databases[s_type->GetOwner()];
|
||||
|
||||
db << "OBJECT " << base->serialize_name() << "\n";
|
||||
*fd << "OBJECT " << s_type->GetName() << "\n";
|
||||
for (Serialize::Data::iterator dit = data.begin(), dit_end = data.end(); dit != dit_end; ++dit)
|
||||
db << "DATA " << dit->first << " " << dit->second.astr() << "\n";
|
||||
db << "END\n";
|
||||
*fd << "DATA " << dit->first << " " << dit->second.astr() << "\n";
|
||||
*fd << "END\n";
|
||||
}
|
||||
|
||||
db.close();
|
||||
|
||||
if (db.good() == false)
|
||||
if (databases[NULL]->good() == false)
|
||||
{
|
||||
Log() << "Unable to write database";
|
||||
databases[NULL]->close();
|
||||
if (!Config->NoBackupOkay)
|
||||
quitting = true;
|
||||
if (IsFile(tmp_db))
|
||||
@@ -177,6 +210,12 @@ class DBFlatFile : public Module
|
||||
else
|
||||
unlink(tmp_db.c_str());
|
||||
|
||||
for (std::map<Module *, std::fstream *>::iterator it = databases.begin(), it_end = databases.end(); it != it_end; ++it)
|
||||
{
|
||||
it->second->close();
|
||||
delete it->second;
|
||||
}
|
||||
|
||||
return EVENT_CONTINUE;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -105,13 +105,17 @@ class DBSQL : public Module, public Pipe
|
||||
continue;
|
||||
obj->UpdateCache();
|
||||
|
||||
SerializeType *s_type = obj->GetSerializableType();
|
||||
if (!s_type)
|
||||
continue;
|
||||
|
||||
Serialize::Data data = obj->serialize();
|
||||
|
||||
std::vector<SQLQuery> create = this->sql->CreateTable(this->prefix + obj->serialize_name(), data);
|
||||
std::vector<SQLQuery> create = this->sql->CreateTable(this->prefix + s_type->GetName(), data);
|
||||
for (unsigned i = 0; i < create.size(); ++i)
|
||||
this->RunBackground(create[i]);
|
||||
|
||||
SQLQuery insert = this->sql->BuildInsert(this->prefix + obj->serialize_name(), obj->id, data);
|
||||
SQLQuery insert = this->sql->BuildInsert(this->prefix + s_type->GetName(), obj->id, data);
|
||||
this->RunBackground(insert, new ResultSQLSQLInterface(this, obj));
|
||||
}
|
||||
}
|
||||
@@ -188,7 +192,9 @@ class DBSQL : public Module, public Pipe
|
||||
|
||||
void OnSerializableDestruct(Serializable *obj) anope_override
|
||||
{
|
||||
this->RunBackground("DELETE FROM `" + this->prefix + obj->serialize_name() + "` WHERE `id` = " + stringify(obj->id));
|
||||
SerializeType *s_type = obj->GetSerializableType();
|
||||
if (s_type)
|
||||
this->RunBackground("DELETE FROM `" + this->prefix + s_type->GetName() + "` WHERE `id` = " + stringify(obj->id));
|
||||
}
|
||||
|
||||
void OnSerializableUpdate(Serializable *obj) anope_override
|
||||
|
||||
@@ -95,18 +95,20 @@ class DBMySQL : public Module, public Pipe
|
||||
continue;
|
||||
obj->UpdateCache();
|
||||
|
||||
SerializeType *s_type = obj->GetSerializableType();
|
||||
if (!s_type)
|
||||
continue;
|
||||
|
||||
Serialize::Data data = obj->serialize();
|
||||
|
||||
std::vector<SQLQuery> create = this->SQL->CreateTable(this->prefix + obj->serialize_name(), data);
|
||||
std::vector<SQLQuery> create = this->SQL->CreateTable(this->prefix + s_type->GetName(), data);
|
||||
for (unsigned i = 0; i < create.size(); ++i)
|
||||
this->RunQueryResult(create[i]);
|
||||
|
||||
SQLResult res = this->RunQueryResult(this->SQL->BuildInsert(this->prefix + obj->serialize_name(), obj->id, data));
|
||||
SQLResult res = this->RunQueryResult(this->SQL->BuildInsert(this->prefix + s_type->GetName(), obj->id, data));
|
||||
if (res.GetID() > 0)
|
||||
obj->id = res.GetID();
|
||||
SerializeType *stype = SerializeType::Find(obj->serialize_name());
|
||||
if (stype)
|
||||
stype->objects.erase(obj->id);
|
||||
s_type->objects.erase(obj->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,15 +146,16 @@ class DBMySQL : public Module, public Pipe
|
||||
{
|
||||
if (!this->CheckInit())
|
||||
return;
|
||||
this->RunQuery("DELETE FROM `" + this->prefix + obj->serialize_name() + "` WHERE `id` = " + stringify(obj->id));
|
||||
SerializeType *stype = SerializeType::Find(obj->serialize_name());
|
||||
if (stype)
|
||||
stype->objects.erase(obj->id);
|
||||
SerializeType *s_type = obj->GetSerializableType();
|
||||
if (!s_type)
|
||||
return;
|
||||
this->RunQuery("DELETE FROM `" + this->prefix + s_type->GetName() + "` WHERE `id` = " + stringify(obj->id));
|
||||
s_type->objects.erase(obj->id);
|
||||
}
|
||||
|
||||
void OnSerializePtrAssign(Serializable *obj) anope_override
|
||||
{
|
||||
SerializeType *stype = SerializeType::Find(obj->serialize_name());
|
||||
SerializeType *stype = obj->GetSerializableType();
|
||||
if (stype == NULL || !this->CheckInit() || stype->GetTimestamp() == Anope::CurTime)
|
||||
return;
|
||||
|
||||
@@ -160,7 +163,7 @@ class DBMySQL : public Module, public Pipe
|
||||
return;
|
||||
obj->UpdateCache();
|
||||
|
||||
SQLResult res = this->RunQueryResult("SELECT * FROM `" + this->prefix + obj->serialize_name() + "` WHERE `id` = " + stringify(obj->id));
|
||||
SQLResult res = this->RunQueryResult("SELECT * FROM `" + this->prefix + stype->GetName() + "` WHERE `id` = " + stringify(obj->id));
|
||||
|
||||
if (res.Rows() == 0)
|
||||
obj->destroy();
|
||||
|
||||
@@ -875,7 +875,7 @@ struct IRCDMessageRSQuit : IRCDMessage
|
||||
else
|
||||
s = Server::Find(params[0]);
|
||||
|
||||
source.GetServer()->Delete(source.GetServer()->GetName() + " " + source.GetServer()->GetUplink()->GetName());
|
||||
source.GetServer()->Delete(source.GetServer()->GetName() + " " + (s ? s->GetName() : "<unknown>"));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+1
-6
@@ -90,7 +90,7 @@ const std::list<AccessProvider *>& AccessProvider::GetProviders()
|
||||
return providers;
|
||||
}
|
||||
|
||||
ChanAccess::ChanAccess(AccessProvider *p) : provider(p)
|
||||
ChanAccess::ChanAccess(AccessProvider *p) : Serializable("ChanAccess"), provider(p)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -98,11 +98,6 @@ ChanAccess::~ChanAccess()
|
||||
{
|
||||
}
|
||||
|
||||
const Anope::string ChanAccess::serialize_name() const
|
||||
{
|
||||
return "ChanAccess";
|
||||
}
|
||||
|
||||
Serialize::Data ChanAccess::serialize() const
|
||||
{
|
||||
Serialize::Data data;
|
||||
|
||||
+1
-6
@@ -21,7 +21,7 @@
|
||||
serialize_checker<botinfo_map> BotListByNick("BotInfo");
|
||||
serialize_checker<botinfouid_map> BotListByUID("BotInfo");
|
||||
|
||||
BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", ts6_uid_retrieve()), Flags<BotFlag, BI_END>(BotFlagString), botmodes(bmodes)
|
||||
BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", ts6_uid_retrieve()), Flags<BotFlag, BI_END>(BotFlagString), Serializable("BotInfo"), botmodes(bmodes)
|
||||
{
|
||||
this->lastmsg = this->created = Anope::CurTime;
|
||||
this->introduced = false;
|
||||
@@ -71,11 +71,6 @@ BotInfo::~BotInfo()
|
||||
BotListByUID->erase(this->uid);
|
||||
}
|
||||
|
||||
const Anope::string BotInfo::serialize_name() const
|
||||
{
|
||||
return "BotInfo";
|
||||
}
|
||||
|
||||
Serialize::Data BotInfo::serialize() const
|
||||
{
|
||||
Serialize::Data data;
|
||||
|
||||
+1
-6
@@ -18,12 +18,7 @@
|
||||
#include "users.h"
|
||||
#include "account.h"
|
||||
|
||||
Memo::Memo() : Flags<MemoFlag>(MemoFlagStrings) { }
|
||||
|
||||
const Anope::string Memo::serialize_name() const
|
||||
{
|
||||
return "Memo";
|
||||
}
|
||||
Memo::Memo() : Flags<MemoFlag>(MemoFlagStrings), Serializable("Memo") { }
|
||||
|
||||
Serialize::Data Memo::serialize() const
|
||||
{
|
||||
|
||||
+1
-6
@@ -29,7 +29,7 @@ static nickservheld_map NickServHelds;
|
||||
* @param nick The nick
|
||||
* @param nickcore The nickcore for this nick
|
||||
*/
|
||||
NickAlias::NickAlias(const Anope::string &nickname, NickCore* nickcore) : Flags<NickNameFlag, NS_END>(NickNameFlagStrings)
|
||||
NickAlias::NickAlias(const Anope::string &nickname, NickCore* nickcore) : Flags<NickNameFlag, NS_END>(NickNameFlagStrings), Serializable("NickAlias")
|
||||
{
|
||||
if (nickname.empty())
|
||||
throw CoreException("Empty nick passed to NickAlias constructor");
|
||||
@@ -240,11 +240,6 @@ time_t NickAlias::GetVhostCreated() const
|
||||
return this->vhost_created;
|
||||
}
|
||||
|
||||
const Anope::string NickAlias::serialize_name() const
|
||||
{
|
||||
return "NickAlias";
|
||||
}
|
||||
|
||||
Serialize::Data NickAlias::serialize() const
|
||||
{
|
||||
Serialize::Data data;
|
||||
|
||||
+1
-6
@@ -19,7 +19,7 @@ serialize_checker<nickcore_map> NickCoreList("NickCore");
|
||||
/** Default constructor
|
||||
* @param display The display nick
|
||||
*/
|
||||
NickCore::NickCore(const Anope::string &coredisplay) : Flags<NickCoreFlag, NI_END>(NickCoreFlagStrings)
|
||||
NickCore::NickCore(const Anope::string &coredisplay) : Flags<NickCoreFlag, NI_END>(NickCoreFlagStrings), Serializable("NickCore")
|
||||
{
|
||||
if (coredisplay.empty())
|
||||
throw CoreException("Empty display passed to NickCore constructor");
|
||||
@@ -60,11 +60,6 @@ NickCore::~NickCore()
|
||||
}
|
||||
}
|
||||
|
||||
const Anope::string NickCore::serialize_name() const
|
||||
{
|
||||
return "NickCore";
|
||||
}
|
||||
|
||||
Serialize::Data NickCore::serialize() const
|
||||
{
|
||||
Serialize::Data data;
|
||||
|
||||
+2
-7
@@ -45,7 +45,7 @@ void XLine::InitRegex()
|
||||
}
|
||||
}
|
||||
|
||||
XLine::XLine(const Anope::string &mask, const Anope::string &reason, const Anope::string &uid) : Mask(mask), Created(0), Expires(0), Reason(reason), UID(uid)
|
||||
XLine::XLine(const Anope::string &mask, const Anope::string &reason, const Anope::string &uid) : Serializable("XLine"), Mask(mask), Created(0), Expires(0), Reason(reason), UID(uid)
|
||||
{
|
||||
regex = NULL;
|
||||
manager = NULL;
|
||||
@@ -53,7 +53,7 @@ XLine::XLine(const Anope::string &mask, const Anope::string &reason, const Anope
|
||||
this->InitRegex();
|
||||
}
|
||||
|
||||
XLine::XLine(const Anope::string &mask, const Anope::string &by, const time_t expires, const Anope::string &reason, const Anope::string &uid) : Mask(mask), By(by), Created(Anope::CurTime), Expires(expires), Reason(reason), UID(uid)
|
||||
XLine::XLine(const Anope::string &mask, const Anope::string &by, const time_t expires, const Anope::string &reason, const Anope::string &uid) : Serializable("XLine"), Mask(mask), By(by), Created(Anope::CurTime), Expires(expires), Reason(reason), UID(uid)
|
||||
{
|
||||
regex = NULL;
|
||||
manager = NULL;
|
||||
@@ -138,11 +138,6 @@ bool XLine::IsRegex() const
|
||||
return !this->Mask.empty() && this->Mask[0] == '/' && this->Mask[this->Mask.length() - 1] == '/';
|
||||
}
|
||||
|
||||
const Anope::string XLine::serialize_name() const
|
||||
{
|
||||
return "XLine";
|
||||
}
|
||||
|
||||
Serialize::Data XLine::serialize() const
|
||||
{
|
||||
Serialize::Data data;
|
||||
|
||||
+6
-29
@@ -23,11 +23,6 @@
|
||||
|
||||
serialize_checker<registered_channel_map> RegisteredChannelList("ChannelInfo");
|
||||
|
||||
const Anope::string BadWord::serialize_name() const
|
||||
{
|
||||
return "BadWord";
|
||||
}
|
||||
|
||||
Serialize::Data BadWord::serialize() const
|
||||
{
|
||||
Serialize::Data data;
|
||||
@@ -61,15 +56,10 @@ Serializable* BadWord::unserialize(Serializable *obj, Serialize::Data &data)
|
||||
return bw;
|
||||
}
|
||||
|
||||
AutoKick::AutoKick() : Flags<AutoKickFlag>(AutoKickFlagString)
|
||||
AutoKick::AutoKick() : Flags<AutoKickFlag>(AutoKickFlagString), Serializable("AutoKick")
|
||||
{
|
||||
}
|
||||
|
||||
const Anope::string AutoKick::serialize_name() const
|
||||
{
|
||||
return "AutoKick";
|
||||
}
|
||||
|
||||
Serialize::Data AutoKick::serialize() const
|
||||
{
|
||||
Serialize::Data data;
|
||||
@@ -121,15 +111,10 @@ Serializable* AutoKick::unserialize(Serializable *obj, Serialize::Data &data)
|
||||
return ak;
|
||||
}
|
||||
|
||||
ModeLock::ModeLock(ChannelInfo *ch, bool s, ChannelModeName n, const Anope::string &p, const Anope::string &se, time_t c) : ci(ch), set(s), name(n), param(p), setter(se), created(c)
|
||||
ModeLock::ModeLock(ChannelInfo *ch, bool s, ChannelModeName n, const Anope::string &p, const Anope::string &se, time_t c) : Serializable("ModeLock"), ci(ch), set(s), name(n), param(p), setter(se), created(c)
|
||||
{
|
||||
}
|
||||
|
||||
const Anope::string ModeLock::serialize_name() const
|
||||
{
|
||||
return "ModeLock";
|
||||
}
|
||||
|
||||
Serialize::Data ModeLock::serialize() const
|
||||
{
|
||||
Serialize::Data data;
|
||||
@@ -192,11 +177,6 @@ Serializable* ModeLock::unserialize(Serializable *obj, Serialize::Data &data)
|
||||
}
|
||||
}
|
||||
|
||||
const Anope::string LogSetting::serialize_name() const
|
||||
{
|
||||
return "LogSetting";
|
||||
}
|
||||
|
||||
Serialize::Data LogSetting::serialize() const
|
||||
{
|
||||
Serialize::Data data;
|
||||
@@ -246,7 +226,8 @@ Serializable* LogSetting::unserialize(Serializable *obj, Serialize::Data &data)
|
||||
/** Default constructor
|
||||
* @param chname The channel name
|
||||
*/
|
||||
ChannelInfo::ChannelInfo(const Anope::string &chname) : Flags<ChannelInfoFlag, CI_END>(ChannelInfoFlagStrings), access("ChanAccess"), akick("AutoKick"),
|
||||
ChannelInfo::ChannelInfo(const Anope::string &chname) : Flags<ChannelInfoFlag, CI_END>(ChannelInfoFlagStrings), Serializable("ChannelInfo"),
|
||||
access("ChanAccess"), akick("AutoKick"),
|
||||
badwords("BadWord"), mode_locks("ModeLock"), log_settings("LogSetting"), botflags(BotServFlagStrings)
|
||||
{
|
||||
if (chname.empty())
|
||||
@@ -291,7 +272,8 @@ ChannelInfo::ChannelInfo(const Anope::string &chname) : Flags<ChannelInfoFlag, C
|
||||
/** Copy constructor
|
||||
* @param ci The ChannelInfo to copy settings to
|
||||
*/
|
||||
ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Flags<ChannelInfoFlag, CI_END>(ChannelInfoFlagStrings), access("ChanAccess"), akick("AutoKick"),
|
||||
ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Flags<ChannelInfoFlag, CI_END>(ChannelInfoFlagStrings), Serializable("ChannelInfo"),
|
||||
access("ChanAccess"), akick("AutoKick"),
|
||||
badwords("BadWord"), mode_locks("ModeLock"), log_settings("LogSetting"), botflags(BotServFlagStrings)
|
||||
{
|
||||
*this = ci;
|
||||
@@ -384,11 +366,6 @@ ChannelInfo::~ChannelInfo()
|
||||
--this->founder->channelcount;
|
||||
}
|
||||
|
||||
const Anope::string ChannelInfo::serialize_name() const
|
||||
{
|
||||
return "ChannelInfo";
|
||||
}
|
||||
|
||||
Serialize::Data ChannelInfo::serialize() const
|
||||
{
|
||||
Serialize::Data data;
|
||||
|
||||
+21
-2
@@ -71,23 +71,32 @@ unsigned stringstream::getMax() const
|
||||
}
|
||||
|
||||
Serializable::Serializable() : last_commit_time(0), id(0)
|
||||
{
|
||||
throw CoreException("Default Serializable constructor?");
|
||||
}
|
||||
|
||||
Serializable::Serializable(const Anope::string &serialize_type) : last_commit_time(0), id(0)
|
||||
{
|
||||
if (serializable_items == NULL)
|
||||
serializable_items = new std::list<Serializable *>();
|
||||
serializable_items->push_back(this);
|
||||
|
||||
this->s_type = SerializeType::Find(serialize_type);
|
||||
|
||||
this->s_iter = serializable_items->end();
|
||||
--this->s_iter;
|
||||
|
||||
FOREACH_MOD(I_OnSerializableConstruct, OnSerializableConstruct(this));
|
||||
}
|
||||
|
||||
Serializable::Serializable(const Serializable &) : last_commit_time(0), id(0)
|
||||
Serializable::Serializable(const Serializable &other) : last_commit_time(0), id(0)
|
||||
{
|
||||
serializable_items->push_back(this);
|
||||
this->s_iter = serializable_items->end();
|
||||
--this->s_iter;
|
||||
|
||||
this->s_type = other.s_type;
|
||||
|
||||
FOREACH_MOD(I_OnSerializableConstruct, OnSerializableConstruct(this));
|
||||
}
|
||||
|
||||
@@ -136,12 +145,17 @@ void Serializable::UpdateTS()
|
||||
this->last_commit_time = Anope::CurTime;
|
||||
}
|
||||
|
||||
SerializeType* Serializable::GetSerializableType() const
|
||||
{
|
||||
return this->s_type;
|
||||
}
|
||||
|
||||
const std::list<Serializable *> &Serializable::GetItems()
|
||||
{
|
||||
return *serializable_items;
|
||||
}
|
||||
|
||||
SerializeType::SerializeType(const Anope::string &n, unserialize_func f) : name(n), unserialize(f), timestamp(0)
|
||||
SerializeType::SerializeType(const Anope::string &n, unserialize_func f, Module *o) : name(n), unserialize(f), owner(o), timestamp(0)
|
||||
{
|
||||
type_order.push_back(this->name);
|
||||
types[this->name] = this;
|
||||
@@ -180,6 +194,11 @@ void SerializeType::UpdateTimestamp()
|
||||
this->timestamp = Anope::CurTime;
|
||||
}
|
||||
|
||||
Module* SerializeType::GetOwner() const
|
||||
{
|
||||
return this->owner;
|
||||
}
|
||||
|
||||
SerializeType *SerializeType::Find(const Anope::string &name)
|
||||
{
|
||||
Anope::map<SerializeType *>::iterator it = types.find(name);
|
||||
|
||||
Reference in New Issue
Block a user