aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Sadie Powell2021-03-17 16:07:33 +0000
committerGravatar Sadie Powell2021-03-17 21:13:10 +0000
commita4e9ebfda34afcf6eb7602381c2f9313ab1b8b78 (patch)
tree4f3884cc3415e3c7ef3ce4ebf30150a1dd166e20 /src
parentMove extensible code from base.cpp to extensible.cpp and cleanup. (diff)
Implement support for automatically syncing extension items.
Diffstat (limited to 'src')
-rw-r--r--src/extensible.cpp38
-rw-r--r--src/modules/m_customtitle.cpp2
-rw-r--r--src/modules/m_dccallow.cpp2
-rw-r--r--src/modules/m_silence.cpp2
-rw-r--r--src/modules/m_sslinfo.cpp7
-rw-r--r--src/modules/m_swhois.cpp10
6 files changed, 40 insertions, 21 deletions
diff --git a/src/extensible.cpp b/src/extensible.cpp
index e44f6cb6b..21d064ad1 100644
--- a/src/extensible.cpp
+++ b/src/extensible.cpp
@@ -128,6 +128,29 @@ void* ExtensionItem::UnsetRaw(Extensible* container)
return result;
}
+void ExtensionItem::Sync(const Extensible* container, void* item)
+{
+ const std::string networkstr = ToNetwork(container, item);
+ if (networkstr.empty())
+ return;
+
+ switch (type)
+ {
+ case ExtensionItem::EXT_CHANNEL:
+ ServerInstance->PI->SendMetaData((Channel*)container, name, networkstr);
+ break;
+
+ case ExtensionItem::EXT_MEMBERSHIP:
+ // TODO: Implement support for networking membership metadata.
+ // ServerInstance->PI->SendMetaData((Membership*)container, name, networkstr);
+ break;
+
+ case ExtensionItem::EXT_USER:
+ ServerInstance->PI->SendMetaData((User*)container, name, networkstr);
+ break;
+ }
+}
+
void ExtensionItem::FromInternal(Extensible* container, const std::string& value) noexcept
{
FromNetwork(container, value);
@@ -172,7 +195,7 @@ void IntExtItem::Delete(Extensible* container, void* item)
void IntExtItem::FromInternal(Extensible* container, const std::string& value) noexcept
{
- Set(container, ConvToNum<intptr_t>(value));
+ Set(container, ConvToNum<intptr_t>(value), false);
}
void IntExtItem::FromNetwork(Extensible* container, const std::string& value) noexcept
@@ -186,12 +209,15 @@ intptr_t IntExtItem::Get(const Extensible* container) const
return reinterpret_cast<intptr_t>(GetRaw(container));
}
-void IntExtItem::Set(Extensible* container, intptr_t value)
+void IntExtItem::Set(Extensible* container, intptr_t value, bool sync)
{
if (value)
SetRaw(container, reinterpret_cast<void*>(value));
else
UnsetRaw(container);
+
+ if (sync && synced)
+ Sync(container, GetRaw(container));
}
std::string IntExtItem::ToInternal(const Extensible* container, void* item) const noexcept
@@ -204,9 +230,11 @@ std::string IntExtItem::ToNetwork(const Extensible* container, void* item) const
return synced ? ToInternal(container, item) : std::string();
}
-void IntExtItem::Unset(Extensible* container)
+void IntExtItem::Unset(Extensible* container, bool sync)
{
UnsetRaw(container);
+ if (sync && synced)
+ Sync(container, nullptr);
}
StringExtItem::StringExtItem(Module* owner, const std::string& key, ExtensibleType exttype, bool sync)
@@ -218,9 +246,9 @@ StringExtItem::StringExtItem(Module* owner, const std::string& key, ExtensibleTy
void StringExtItem::FromInternal(Extensible* container, const std::string& value) noexcept
{
if (value.empty())
- Unset(container);
+ Unset(container, false);
else
- Set(container, value);
+ Set(container, value, false);
}
void StringExtItem::FromNetwork(Extensible* container, const std::string& value) noexcept
diff --git a/src/modules/m_customtitle.cpp b/src/modules/m_customtitle.cpp
index 0f7f2fdf0..14f4bc21f 100644
--- a/src/modules/m_customtitle.cpp
+++ b/src/modules/m_customtitle.cpp
@@ -90,8 +90,6 @@ class CommandTitle : public Command
{
ctitle.Set(user, config.title);
- ServerInstance->PI->SendMetaData(user, "ctitle", config.title);
-
if (!config.vhost.empty())
user->ChangeDisplayedHost(config.vhost);
diff --git a/src/modules/m_dccallow.cpp b/src/modules/m_dccallow.cpp
index b2f9d644b..4c09063b6 100644
--- a/src/modules/m_dccallow.cpp
+++ b/src/modules/m_dccallow.cpp
@@ -122,7 +122,7 @@ class DCCAllowExt : public SimpleExtItem<dccallowlist>
return;
// Remove the old list and create a new one.
- Unset(user);
+ Unset(user, false);
dccallowlist* list = new dccallowlist();
irc::spacesepstream ts(value);
diff --git a/src/modules/m_silence.cpp b/src/modules/m_silence.cpp
index b670182d4..edc81be40 100644
--- a/src/modules/m_silence.cpp
+++ b/src/modules/m_silence.cpp
@@ -201,7 +201,7 @@ class SilenceExtItem : public SimpleExtItem<SilenceList>
return;
// Remove the old list and create a new one.
- Unset(user);
+ Unset(user, false);
SilenceList* list = new SilenceList();
irc::spacesepstream ts(value);
diff --git a/src/modules/m_sslinfo.cpp b/src/modules/m_sslinfo.cpp
index e08a11e03..8537c57e9 100644
--- a/src/modules/m_sslinfo.cpp
+++ b/src/modules/m_sslinfo.cpp
@@ -53,12 +53,15 @@ class SSLCertExt : public ExtensionItem
return static_cast<ssl_cert*>(GetRaw(item));
}
- void Set(Extensible* item, ssl_cert* value)
+ void Set(Extensible* item, ssl_cert* value, bool sync = true)
{
value->refcount_inc();
ssl_cert* old = static_cast<ssl_cert*>(SetRaw(item, value));
if (old && old->refcount_dec())
delete old;
+
+ if (sync)
+ Sync(item, value);
}
void Unset(Extensible* container)
@@ -74,7 +77,7 @@ class SSLCertExt : public ExtensionItem
void FromNetwork(Extensible* container, const std::string& value) noexcept override
{
ssl_cert* cert = new ssl_cert;
- Set(container, cert);
+ Set(container, cert, false);
std::stringstream s(value);
std::string v;
diff --git a/src/modules/m_swhois.cpp b/src/modules/m_swhois.cpp
index 2b14def9d..562c4a312 100644
--- a/src/modules/m_swhois.cpp
+++ b/src/modules/m_swhois.cpp
@@ -80,14 +80,6 @@ class CommandSwhois : public Command
else
swhois.Set(dest, parameters[1]);
- /* Bug #376 - feature request -
- * To cut down on the amount of commands services etc have to recognise, this only sends METADATA across the network now
- * not an actual SWHOIS command. Any SWHOIS command sent from services will be automatically translated to METADATA by this.
- * Sorry w00t i know this was your fix, but i got bored and wanted to clear down the tracker :)
- * -- Brain
- */
- ServerInstance->PI->SendMetaData(dest, "swhois", parameters[1]);
-
return CmdResult::SUCCESS;
}
@@ -138,7 +130,6 @@ class ModuleSWhois
cmd.operblock.Set(user, 1);
cmd.swhois.Set(user, swhois);
- ServerInstance->PI->SendMetaData(user, "swhois", swhois);
}
void OnPostDeoper(User* user) override
@@ -152,7 +143,6 @@ class ModuleSWhois
cmd.operblock.Unset(user);
cmd.swhois.Unset(user);
- ServerInstance->PI->SendMetaData(user, "swhois", "");
}
void OnDecodeMetaData(Extensible* target, const std::string& extname, const std::string&) override