Skip to content

Commit 3420cf3

Browse files
authored
Merge pull request #1075 from openmultiplayer/ksn/npc_ids
Reverse search for NPC id in player pool
2 parents ba46dd0 + 82a2288 commit 3420cf3

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Server/Source/player_pool.hpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,26 @@ struct PlayerPool final : public IPlayerPool, public NetworkEventHandler, public
16941694
return { NewConnectionResult_BadName, nullptr };
16951695
}
16961696

1697-
Player* result = storage.emplace(*this, netData, params, useAllAnimations_, validateAnimations_, allowInteriorWeapons_, fixesComponent_);
1697+
Player* result = nullptr;
1698+
1699+
if (params.bot)
1700+
{
1701+
static const auto maxPlayers = core.getConfig().getInt("max_players");
1702+
for (auto index = *maxPlayers - 1; index >= 0; --index)
1703+
{
1704+
if (storage.get(index) == nullptr)
1705+
{
1706+
storage.claimHint(index, *this, netData, params, useAllAnimations_, validateAnimations_, allowInteriorWeapons_, fixesComponent_);
1707+
result = storage.get(index);
1708+
break;
1709+
}
1710+
}
1711+
}
1712+
else
1713+
{
1714+
result = storage.emplace(*this, netData, params, useAllAnimations_, validateAnimations_, allowInteriorWeapons_, fixesComponent_);
1715+
}
1716+
16981717
if (!result)
16991718
{
17001719
return { NewConnectionResult_NoPlayerSlot, nullptr };

0 commit comments

Comments
 (0)