From a51d044c82d2e39a2d9a79dd2ce181ef7bd32b02 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Fri, 21 Jan 2022 15:53:04 +0000 Subject: Fix various edge cases in extensible synchronisation. - Fix not forwarding the accountid extensible if it is set. - Rename the variadic Set() overload to SetFwd(). - Re-add the `const T&` overload of Set(). - Move `bool synced` to SimpleExtItem from StringExtItem. - Only sync extensibles if their instance is marked as syncable. --- include/extensible.h | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'include/extensible.h') diff --git a/include/extensible.h b/include/extensible.h index a416f91a4..0e86f8272 100644 --- a/include/extensible.h +++ b/include/extensible.h @@ -191,14 +191,20 @@ template > class SimpleExtItem : public ExtensionItem { + protected: + /** Whether to sync this StringExtItem across the network. */ + bool synced; + public: /** Initializes an instance of the SimpleExtItem class. * @param parent The module which created this SimpleExtItem. * @param Key The name of the extension item (e.g. foo_bar). * @param exttype The type of Extensible that this SimpleExtItem applies to. + * @param sync Whether this SimpleExtItem should be broadcast to other servers. */ - SimpleExtItem(Module* parent, const std::string& Key, ExtensionType exttype) + SimpleExtItem(Module* parent, const std::string& Key, ExtensionType exttype, bool sync = false) : ExtensionItem(parent, Key, exttype) + , synced(sync) { } @@ -211,20 +217,28 @@ class SimpleExtItem { T* old = static_cast(SetRaw(container, value)); Delete(container, old); - if (sync) + if (sync && synced) Sync(container, value); } + inline void Set(Extensible* container, const T& value, bool sync = true) + { + Set(container, new T(value), sync); + } + template - inline void Set(Extensible* container, Args&&... args) + inline void SetFwd(Extensible* container, Args&&... args) { - Set(container, new T(std::forward(args)...)); + // Forwarded arguments are for complex types which are assumed to not + // be synced across the network. You can manually call Sync() if this + // is not the case. + Set(container, new T(std::forward(args)...), false); } inline void Unset(Extensible* container, bool sync = true) { Delete(container, UnsetRaw(container)); - if (sync) + if (synced && sync) Sync(container, nullptr); } @@ -239,10 +253,6 @@ class SimpleExtItem class CoreExport StringExtItem : public SimpleExtItem { - protected: - /** Whether to sync this StringExtItem across the network. */ - bool synced; - public: /** Initializes an instance of the StringExtItem class. * @param owner The module which created this StringExtItem. @@ -300,7 +310,7 @@ class CoreExport IntExtItem /** Sets a value for this IntExtItem. * @param container A container that the IntExtItem should be set on. * @param value The new value for this IntExtItem. - * @param sync Whether to sync this value to other servers. + * @param sync If syncable then whether to sync this value to other servers. */ void Set(Extensible* container, intptr_t value, bool sync = true); @@ -312,7 +322,7 @@ class CoreExport IntExtItem /** Removes the value for this IntExtItem. * @param container A container the ExtensionItem should be removed from. - * @param sync Whether to sync this unset to the network. + * @param sync If syncable then whether to sync this unset to the network. */ void Unset(Extensible* container, bool sync = true); }; @@ -360,13 +370,13 @@ class CoreExport BoolExtItem /** Sets a value for this BoolExtItem. * @param container A container that the BoolExtItem should be set on. - * @param sync Whether to sync this set to the network. + * @param sync If syncable then whether to sync this set to the network. */ void Set(Extensible* container, bool sync = true); /** Removes the value for this BoolExtItem. * @param container A container the ExtensionItem should be removed from. - * @param sync Whether to sync this unset to the network. + * @param sync If syncable then whether to sync this unset to the network. */ void Unset(Extensible* container, bool sync = true); }; -- cgit v1.3.1-10-gc9f91