From 40a8127cbadbbb5ad081b78cbf9172fd6ac6a51e Mon Sep 17 00:00:00 2001 From: iAmir Date: Sat, 7 Oct 2023 17:43:53 +0330 Subject: [PATCH 1/2] remove pawn comp player connect event priority Because now there are issues with Objects components sending CreateObject RPCs on connect sooner than Pawn calling RemoveBuildingForPlayer This way, created objects are again removed with game mechanis after receiving RemoveBuildingForPlayer --- Server/Components/Pawn/Scripting/Impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/Components/Pawn/Scripting/Impl.cpp b/Server/Components/Pawn/Scripting/Impl.cpp index ce1e554ff..4ccde9462 100644 --- a/Server/Components/Pawn/Scripting/Impl.cpp +++ b/Server/Components/Pawn/Scripting/Impl.cpp @@ -98,7 +98,7 @@ void Scripting::addEvents() const if (mgr->players) { mgr->players->getPlayerSpawnDispatcher().addEventHandler(PlayerEvents::Get()); - mgr->players->getPlayerConnectDispatcher().addEventHandler(PlayerEvents::Get(), EventPriority_FairlyLow); + mgr->players->getPlayerConnectDispatcher().addEventHandler(PlayerEvents::Get()); mgr->players->getPlayerStreamDispatcher().addEventHandler(PlayerEvents::Get()); mgr->players->getPlayerTextDispatcher().addEventHandler(PlayerEvents::Get()); mgr->players->getPlayerShotDispatcher().addEventHandler(PlayerEvents::Get()); From e8d636a52501e9c16af7a23f230ef1506e6f0ff0 Mon Sep 17 00:00:00 2001 From: iAmir Date: Sat, 7 Oct 2023 17:43:59 +0330 Subject: [PATCH 2/2] initialize player object data on player pool entry create --- Server/Components/Objects/objects_impl.hpp | 2 ++ Server/Components/Objects/objects_main.cpp | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Server/Components/Objects/objects_impl.hpp b/Server/Components/Objects/objects_impl.hpp index 7def53c4c..edb38418f 100644 --- a/Server/Components/Objects/objects_impl.hpp +++ b/Server/Components/Objects/objects_impl.hpp @@ -417,6 +417,8 @@ class ObjectComponent final : public IObjectsComponent, public CoreEventHandler, void onPoolEntryDestroyed(IPlayer& player) override; + void onPoolEntryCreated(IPlayer& player) override; + void onPlayerStreamIn(IPlayer& player, IPlayer& forPlayer) override; // Pre-spawn so you can safely attach onPlayerSpawn diff --git a/Server/Components/Objects/objects_main.cpp b/Server/Components/Objects/objects_main.cpp index 92e0ffa8b..ce2a21ce7 100644 --- a/Server/Components/Objects/objects_main.cpp +++ b/Server/Components/Objects/objects_main.cpp @@ -33,20 +33,21 @@ void ObjectComponent::onTick(Microseconds elapsed, TimePoint now) void ObjectComponent::onPlayerConnect(IPlayer& player) { - auto player_data = new PlayerObjectData(*this, player); - player.addExtension(player_data, true); - // If client is using 0.3.7 or artwork isn't enabled we can create objects right on connect. // If not we need to wait for client to download custom models before creating objects. static bool artwork = (core->getConfig().getBool("artwork.enable")) ? (*core->getConfig().getBool("artwork.enable")) : false; if (artwork && player.getClientVersion() == ClientVersion::ClientVersion_SAMP_03DL) return; - player_data->setStreamedGlobalObjects(true); - for (IObject* o : storage) + auto playerData = reinterpret_cast(queryExtension(player)); + if (playerData) { - Object* obj = static_cast(o); - obj->createForPlayer(player); + playerData->setStreamedGlobalObjects(true); + for (IObject* o : storage) + { + Object* obj = static_cast(o); + obj->createForPlayer(player); + } } } @@ -168,6 +169,12 @@ void ObjectComponent::onPoolEntryDestroyed(IPlayer& player) } } +void ObjectComponent::onPoolEntryCreated(IPlayer& player) +{ + auto playerData = new PlayerObjectData(*this, player); + player.addExtension(playerData, true); +} + COMPONENT_ENTRY_POINT() { return new ObjectComponent();