Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix object data initialization and event priority conflict with pawn #731

Merged
merged 2 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Server/Components/Objects/objects_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions Server/Components/Objects/objects_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlayerObjectData*>(queryExtension<IPlayerObjectData>(player));
if (playerData)
{
Object* obj = static_cast<Object*>(o);
obj->createForPlayer(player);
playerData->setStreamedGlobalObjects(true);
for (IObject* o : storage)
{
Object* obj = static_cast<Object*>(o);
obj->createForPlayer(player);
}
}
}

Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Server/Components/Pawn/Scripting/Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down