Add ExtensionItem::OnSync which is called when an ext is synchronised.

This commit is contained in:
Sadie Powell 2024-07-21 11:30:39 +01:00
parent 62f3278a4a
commit b514f826a9
4 changed files with 24 additions and 0 deletions

View File

@ -48,6 +48,13 @@ public:
*/
virtual void FromNetwork(Extensible* container, const std::string& value) noexcept;
/** Called when a value for this extension is synchronised across the network.
* @param container The container that this extension is set on.
* @param item The value that is set on the container.
* @param server The server which is being synchronised to or nullptr for a broadcast.
*/
virtual void OnSync(const Extensible* container, void* item, Server* server);
/** @copydoc ServiceProvider::RegisterService */
void RegisterService() override;

View File

@ -96,6 +96,10 @@ ExtensionItem::ExtensionItem(Module* mod, const std::string& Key, ExtensionType
{
}
void ExtensionItem::OnSync(const Extensible* container, void* item, Server* server)
{
}
void ExtensionItem::RegisterService()
{
if (!ServerInstance->Extensions.Register(this))
@ -138,6 +142,7 @@ void ExtensionItem::Sync(const Extensible* container, void* item)
const std::string networkstr = item ? ToNetwork(container, item) : "";
if (!networkstr.empty())
ServerInstance->PI->SendMetadata(container, name, networkstr);
OnSync(container, item, nullptr);
}
void ExtensionItem::FromInternal(Extensible* container, const std::string& value) noexcept

View File

@ -512,7 +512,10 @@ void ModuleSpanningTree::OnUserConnect(LocalUser* user)
{
const std::string value = item->ToNetwork(user, obj);
if (!value.empty())
{
ServerInstance->PI->SendMetadata(user, item->name, value);
item->OnSync(user, obj, nullptr);
}
}
Utils->TreeRoot->UserCount++;

View File

@ -242,7 +242,10 @@ void TreeSocket::SyncChannel(Channel* chan, TreeServer* s)
{
const std::string valuestr = item->ToNetwork(chan, value);
if (!valuestr.empty())
{
this->WriteLine(CommandMetadata::Builder(chan, item->name, valuestr));
item->OnSync(chan, value, s);
}
}
for (const auto& [_, memb] : chan->GetUsers())
@ -251,7 +254,10 @@ void TreeSocket::SyncChannel(Channel* chan, TreeServer* s)
{
const std::string valuestr = item->ToNetwork(memb, value);
if (!valuestr.empty())
{
this->WriteLine(CommandMetadata::Builder(memb, item->name, valuestr));
item->OnSync(memb, value, s);
}
}
}
@ -282,7 +288,10 @@ void TreeSocket::SendUsers(TreeServer* s)
{
const std::string value = item->ToNetwork(user, obj);
if (!value.empty())
{
this->WriteLine(CommandMetadata::Builder(user, item->name, value));
item->OnSync(user, obj, s);
}
}
Utils->Creator->synceventprov.Call(&ServerProtocol::SyncEventListener::OnSyncUser, user, *s);