Skip to content

Commit f15df3a

Browse files
committed
fix kicking NPCs crashing in certain situations
1 parent db50635 commit f15df3a

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

Server/Source/player.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,21 @@ void Player::streamOutForPlayer(IPlayer& other)
361361
}
362362
}
363363

364+
void Player::kick()
365+
{
366+
if (pool_.npcsComponent_ && pool_.npcsComponent_->get(poolID))
367+
{
368+
// Don't set kick status to true if they're our native NPCs, so we can handle it in NPC component instead.
369+
kicked_ = false;
370+
}
371+
else
372+
{
373+
kicked_ = true;
374+
}
375+
376+
netData_.network->disconnect(*this);
377+
}
378+
364379
void Player::ban(StringView reason)
365380
{
366381
PeerAddress::AddressString address;

Server/Source/player_impl.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ struct Player final : public IPlayer, public PoolIDProvider, public NoCopy
276276

277277
void ban(StringView reason) override;
278278

279+
void kick() override;
280+
279281
void spawn() override
280282
{
281283
// Remove from vehicle.
@@ -920,12 +922,6 @@ struct Player final : public IPlayer, public PoolIDProvider, public NoCopy
920922
return fightingStyle_;
921923
}
922924

923-
void kick() override
924-
{
925-
kicked_ = true;
926-
netData_.network->disconnect(*this);
927-
}
928-
929925
void setSkillLevel(PlayerWeaponSkill skill, int level) override
930926
{
931927
if (skill != PlayerWeaponSkill_Invalid && skill < skillLevels_.size())

Server/Source/player_pool.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "player_impl.hpp"
1212
#include <Server/Components/Console/console.hpp>
13+
#include <Server/Components/NPCs/npcs.hpp>
1314
#include <utils.hpp>
1415

1516
struct PlayerPool final : public IPlayerPool, public NetworkEventHandler, public PlayerUpdateEventHandler, public CoreEventHandler
@@ -35,6 +36,7 @@ struct PlayerPool final : public IPlayerPool, public NetworkEventHandler, public
3536
IFixesComponent* fixesComponent = nullptr;
3637
ICustomModelsComponent* modelsComponent = nullptr;
3738
IFixesComponent* fixesComponent_ = nullptr;
39+
INPCComponent* npcsComponent_ = nullptr;
3840
StreamConfigHelper streamConfigHelper;
3941
int* markersShow;
4042
int* markersUpdateRate;
@@ -2080,6 +2082,7 @@ struct PlayerPool final : public IPlayerPool, public NetworkEventHandler, public
20802082
actorsComponent = components.queryComponent<IActorsComponent>();
20812083
modelsComponent = components.queryComponent<ICustomModelsComponent>();
20822084
fixesComponent = components.queryComponent<IFixesComponent>();
2085+
npcsComponent_ = components.queryComponent<INPCComponent>();
20832086
}
20842087

20852088
bool onPlayerUpdate(IPlayer& p, TimePoint now) override

0 commit comments

Comments
 (0)