Skip to content

Commit

Permalink
handle internal immediate forced disconnects
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady committed Apr 1, 2024
1 parent 2b6eb99 commit fcdc806
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Server/Components/LegacyNetwork/legacy_network_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,12 @@ void RakNetLegacyNetwork::OnRakNetDisconnect(RakNet::PlayerIndex rid, PeerDiscon
networkEventDispatcher.dispatch(&NetworkEventHandler::onPeerDisconnect, *player, reason);
}

void RakNetLegacyNetwork::OnCloseConnection(RakNet::RakPeerInterface* peer, RakNet::PlayerID playerId)
{
auto playerIndex = peer->GetIndexFromPlayerID(playerId);
OnRakNetDisconnect(playerIndex, PeerDisconnectReason_Kicked);
}

template <size_t ID>
void RakNetLegacyNetwork::RPCHook(RakNet::RPCParameters* rpcParams, void* extra)
{
Expand Down Expand Up @@ -870,6 +876,8 @@ void RakNetLegacyNetwork::start()
const String get = "https://api.open.mp/0.3.7/announce/" + std::to_string(port);
core->requestHTTP4(new AnnounceHTTPResponseHandler(core), HTTPRequestType::HTTPRequestType_Get, get.data());
}

rakNetServer.AttachPlugin(this);
}

rakNetServer.StartOccasionalPing();
Expand Down
4 changes: 3 additions & 1 deletion Server/Components/LegacyNetwork/legacy_network_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <raknet/GetTime.h>
#include <raknet/RakNetworkFactory.h>
#include <raknet/RakServerInterface.h>
#include <raknet/PluginInterface.h>
#include <raknet/StringCompressor.h>

using namespace Impl;
Expand All @@ -31,7 +32,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 RakNet::PluginInterface
{
private:
ICore* core = nullptr;
Expand Down Expand Up @@ -290,6 +291,7 @@ class RakNetLegacyNetwork final : public Network, public CoreEventHandler, publi
void start();

void OnRakNetDisconnect(RakNet::PlayerIndex rid, PeerDisconnectReason reason);
void OnCloseConnection(RakNet::RakPeerInterface* peer, RakNet::PlayerID playerId) override;

void onPlayerScoreChange(IPlayer& player, int score) override
{
Expand Down

0 comments on commit fcdc806

Please sign in to comment.