Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions Server/Components/LegacyNetwork/legacy_network_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@ RakNetLegacyNetwork::~RakNetLegacyNetwork()
core->getPlayers().getPlayerChangeDispatcher().removeEventHandler(this);
core->getPlayers().getPlayerConnectDispatcher().removeEventHandler(this);
}

if (npcComponent)
{
npcComponent->getPoolEventDispatcher().removeEventHandler(this);
}

rakNetServer.Disconnect(300);
RakNet::RakNetworkFactory::DestroyRakServerInterface(&rakNetServer);
}
Expand Down
30 changes: 29 additions & 1 deletion Server/Components/LegacyNetwork/legacy_network_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <raknet/RakNetworkFactory.h>
#include <raknet/RakServerInterface.h>
#include <raknet/StringCompressor.h>
#include <Server/Components/NPCs/npcs.hpp>

using namespace Impl;

Expand All @@ -34,7 +35,7 @@ static const StaticArray<StringView, 2> ProtectedRules = {

class Core;

class RakNetLegacyNetwork final : public Network, public CoreEventHandler, public PlayerConnectEventHandler, public PlayerChangeEventHandler, public INetworkQueryExtension
class RakNetLegacyNetwork final : public Network, public CoreEventHandler, public PlayerConnectEventHandler, public PlayerChangeEventHandler, public INetworkQueryExtension, public PoolEventHandler<INPC>
{
private:
ICore* core = nullptr;
Expand All @@ -44,8 +45,19 @@ class RakNetLegacyNetwork final : public Network, public CoreEventHandler, publi
StaticArray<RakNet::RakPeer::RemoteSystemStruct*, PLAYER_POOL_SIZE> playerRemoteSystem;
Milliseconds cookieSeedTime;
TimePoint lastCookieSeed;
INPCComponent* npcComponent = nullptr;

public:
inline void setNPCComponent(INPCComponent* comp)
{
npcComponent = comp;

if (npcComponent)
{
npcComponent->getPoolEventDispatcher().addEventHandler(this);
}
}

inline void setQueryConsole(IConsoleComponent* console)
{
query.setConsole(console);
Expand Down Expand Up @@ -309,6 +321,22 @@ class RakNetLegacyNetwork final : public Network, public CoreEventHandler, publi
query.buildPlayerDependentBuffers(&player);
}

void onPoolEntryCreated(INPC& npc) override
{
if (npcComponent)
{
rakNetServer.ReserveSlots(npcComponent->count());
}
}

void onPoolEntryDestroyed(INPC& npc) override
{
if (npcComponent)
{
rakNetServer.ReserveSlots(npcComponent->count());
}
}

bool addRule(StringView rule, StringView value) override
{
if (isRuleProtected(rule))
Expand Down
1 change: 1 addition & 0 deletions Server/Components/LegacyNetwork/legacy_network_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class RakNetLegacyNetworkComponent final : public INetworkComponent
void onInit(IComponentList* components) override
{
legacyNetwork.setQueryConsole(components->queryComponent<IConsoleComponent>());
legacyNetwork.setNPCComponent(components->queryComponent<INPCComponent>());
}

void onFree(IComponent* component) override
Expand Down