summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2016-10-15 16:25:57 -0400
committerAdam <Adam@anope.org>2016-10-15 16:25:57 -0400
commit1ba242179fee46583098f48421af39ce9a8985a1 (patch)
treea276cd7bd53e7270c86ab3744bd6a568a016501b /include
parent696239e93391f3dfd6459857fb02a6006048093a (diff)
Various improvements/bugfixes to extdb stuff
Diffstat (limited to 'include')
-rw-r--r--include/config.h8
-rw-r--r--include/modules/sql.h4
-rw-r--r--include/serialize.h76
-rw-r--r--include/users.h1
-rw-r--r--include/xline.h2
5 files changed, 59 insertions, 32 deletions
diff --git a/include/config.h b/include/config.h
index dccadbe79..b6b36b726 100644
--- a/include/config.h
+++ b/include/config.h
@@ -102,8 +102,9 @@ namespace Configuration
struct Usermode;
struct Channelmode;
- struct CoreExport Conf : Block
+ class CoreExport Conf : public Block
{
+ public:
/* options:readtimeout */
time_t ReadTimeout;
/* options:useprivmsg */
@@ -162,6 +163,11 @@ namespace Configuration
ServiceBot *GetClient(const Anope::string &name);
Block *GetCommand(CommandSource &);
+
+ void LoadBots();
+ void ApplyBots();
+
+ void LoadOpers();
};
struct Uplink
diff --git a/include/modules/sql.h b/include/modules/sql.h
index 2e84db152..6770f407e 100644
--- a/include/modules/sql.h
+++ b/include/modules/sql.h
@@ -202,8 +202,8 @@ namespace SQL
virtual std::vector<Query> InitSchema(const Anope::string &prefix) anope_abstract;
virtual std::vector<Query> Replace(const Anope::string &table, const Query &, const std::set<Anope::string> &) anope_abstract;
- virtual std::vector<Query> CreateTable(const Anope::string &prefix, const Anope::string &table) anope_abstract;
- virtual std::vector<Query> AlterTable(const Anope::string &, const Anope::string &table, const Anope::string &field, bool object) anope_abstract;
+ virtual std::vector<Query> CreateTable(const Anope::string &prefix, Serialize::TypeBase *) anope_abstract;
+ virtual std::vector<Query> AlterTable(const Anope::string &, Serialize::TypeBase *, Serialize::FieldBase *) anope_abstract;
virtual std::vector<Query> CreateIndex(const Anope::string &table, const Anope::string &field) anope_abstract;
virtual Query BeginTransaction() anope_abstract;
diff --git a/include/serialize.h b/include/serialize.h
index 1d0fb9400..8f35e61c6 100644
--- a/include/serialize.h
+++ b/include/serialize.h
@@ -49,6 +49,9 @@ namespace Serialize
inline T GetObject();
template<typename T>
+ inline std::vector<T> GetObjects_(TypeBase *);
+
+ template<typename T>
inline std::vector<T> GetObjects(const Anope::string &name);
template<typename T>
@@ -235,29 +238,6 @@ class CoreExport Serialize::TypeBase : public Service
*/
const Anope::string &GetName() { return this->name; }
- /**
- * Get all objects of the given type
- */
- template<typename T>
- std::vector<T> List()
- {
- std::vector<ID> ids;
- EventReturn result = EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeList, this, ids);
- if (result == EVENT_ALLOW)
- {
- std::vector<T> o;
- for (ID id : ids)
- {
- Object *s = Require(id);
- if (s)
- o.push_back(anope_dynamic_static_cast<T>(s));
- }
- return o;
- }
-
- return GetObjects<T>();
- }
-
/** Create a new object of this type.
*/
virtual Object *Create() anope_abstract;
@@ -306,7 +286,10 @@ class Serialize::Type : public Base
return new T(this, id);
if (s->GetSerializableType() != this)
+ {
+ Log(LOG_DEBUG) << "Mismatch for required id " << id << ", is of type " << s->GetSerializableType()->GetName() << " but wants " << this->GetName();
return nullptr;
+ }
return static_cast<T *>(s);
}
@@ -387,6 +370,8 @@ class Serialize::FieldBase : public Service
*/
bool depends;
+ bool object = false;
+
FieldBase(Module *, const Anope::string &, const Anope::string &, bool);
virtual ~FieldBase();
void Unregister();
@@ -592,7 +577,10 @@ class Serialize::Field : public CommonFieldBase<TypeImpl, T>
// module returned us data, so we unserialize it
T t2 = this->Unserialize(value);
+ // should cache the default value somehow, but can't differentiate not cached from cached and default
+
// Cache
+ OnSet(s, t2);
this->Set_(s, t2);
return t2;
@@ -609,11 +597,18 @@ class Serialize::Field : public CommonFieldBase<TypeImpl, T>
SetField(this->Upcast(s), value);
}
- virtual void SetField(TypeImpl *s, const T &value)
+ /**
+ * Override to hook to changes in the internally
+ * cached value
+ */
+ virtual void OnSet(TypeImpl *s, const T &value) { }
+
+ void SetField(TypeImpl *s, const T &value)
{
Anope::string strvalue = this->Serialize(value);
EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeSet, s, this, strvalue);
+ OnSet(s, value);
this->Set_(s, value);
}
@@ -697,10 +692,12 @@ class Serialize::ObjectField : public CommonFieldBase<TypeImpl, T>
public:
ObjectField(TypeBase *t, const Anope::string &n, bool d = false) : CommonFieldBase<TypeImpl, T>(t, n, d)
{
+ this->object = true;
}
ObjectField(TypeBase *t, const Anope::string &n, T TypeImpl::*field, bool d = false) : CommonFieldBase<TypeImpl, T>(t, n, field, d)
{
+ this->object = true;
}
T GetField(TypeImpl *s)
@@ -723,6 +720,7 @@ class Serialize::ObjectField : public CommonFieldBase<TypeImpl, T>
T t2 = result == EVENT_ALLOW ? static_cast<T>(base->Require(sid)) : nullptr;
+ OnSet(s, t2);
this->Set_(s, t2);
return t2;
@@ -739,7 +737,9 @@ class Serialize::ObjectField : public CommonFieldBase<TypeImpl, T>
SetField(this->Upcast(s), value);
}
- virtual void SetField(TypeImpl *s, T value)
+ virtual void OnSet(TypeImpl *s, T value) { }
+
+ void SetField(TypeImpl *s, T value)
{
EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeSetSerializable, s, this, value);
@@ -747,6 +747,7 @@ class Serialize::ObjectField : public CommonFieldBase<TypeImpl, T>
if (old != nullptr && *old != nullptr)
s->RemoveEdge(*old, this);
+ OnSet(s, value);
this->Set_(s, value);
if (value != nullptr)
@@ -812,13 +813,34 @@ T Serialize::GetObject()
}
template<typename T>
+std::vector<T> Serialize::GetObjects_(TypeBase *type)
+{
+ std::vector<T> o;
+ std::vector<ID> ids;
+ EventReturn result = EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeList, type, ids);
+ if (result == EVENT_ALLOW)
+ {
+ for (ID id : ids)
+ {
+ Object *s = type->Require(id);
+ if (s)
+ o.push_back(anope_dynamic_static_cast<T>(s));
+ }
+ return o;
+ }
+
+ std::transform(type->objects.begin(), type->objects.end(), std::back_inserter(o), [](Object *e) { return anope_dynamic_static_cast<T>(e); });
+ return o;
+}
+
+template<typename T>
std::vector<T> Serialize::GetObjects(const Anope::string &name)
{
std::vector<T> objs;
for (TypeBase *t : GetTypes(name))
- for (Object *s : t->objects)
- objs.push_back(anope_dynamic_static_cast<T>(s));
+ for (T obj : GetObjects_<T>(t))
+ objs.push_back(obj);
return objs;
}
diff --git a/include/users.h b/include/users.h
index dacb7045e..be4ee2a39 100644
--- a/include/users.h
+++ b/include/users.h
@@ -38,7 +38,6 @@ extern CoreExport int OperCount;
enum class UserType
{
USER,
- //LOCAL_USER,
BOT
};
diff --git a/include/xline.h b/include/xline.h
index 87b64d1da..05ddbe2d3 100644
--- a/include/xline.h
+++ b/include/xline.h
@@ -87,7 +87,7 @@ class XLineType : public Serialize::Type<XLine>
{
using Serialize::Field<XLine, Anope::string>::Field;
- void SetField(XLine *s, const Anope::string &value) override;
+ void OnSet(XLine *s, const Anope::string &value) override;
} mask;
Serialize::Field<XLine, Anope::string> by, reason, id;
Serialize::Field<XLine, time_t> created, expires;