Skip to content

Commit

Permalink
omp user detection & server to client encryption for omp users (#1026)
Browse files Browse the repository at this point in the history
* omp user detection & server to client encryption for omp users

* sync raknet

* send bits to RakServer::Send instead of bytes

* sync raknet

* add use_omp_encryption

* sync raknet (one map for encryption data)

* fix abi i guess

* configure omp user even if encryption is disabled
  • Loading branch information
AmyrAhmady authored Jan 5, 2025
1 parent 8e9a310 commit 6191a2d
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion SDK
13 changes: 10 additions & 3 deletions Server/Components/LegacyNetwork/legacy_network_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ enum LegacyClientVersion
LegacyClientVersion_03DL = 4062
};

IPlayer* RakNetLegacyNetwork::OnPeerConnect(RakNet::RPCParameters* rpcParams, bool isNPC, StringView serial, uint32_t version, StringView versionName, uint32_t challenge, StringView name, bool isUsingOfficialClient)
IPlayer* RakNetLegacyNetwork::OnPeerConnect(RakNet::RPCParameters* rpcParams, bool isNPC, StringView serial, uint32_t version, StringView versionName, uint32_t challenge, StringView name, bool isUsingOmp, bool isUsingOfficialClient)
{
const RakNet::PlayerID rid = rpcParams->sender;

Expand Down Expand Up @@ -344,6 +344,7 @@ IPlayer* RakNetLegacyNetwork::OnPeerConnect(RakNet::RPCParameters* rpcParams, bo
params.bot = isNPC;
params.serial = serial;
params.isUsingOfficialClient = isUsingOfficialClient;
params.isUsingOmp = isUsingOmp;
newConnectionResult = core->getPlayers().requestPlayer(netData, params);
}
else
Expand Down Expand Up @@ -425,7 +426,13 @@ void RakNetLegacyNetwork::OnPlayerConnect(RakNet::RPCParameters* rpcParams, void
return;
}

IPlayer* newPeer = network->OnPeerConnect(rpcParams, false, serial, playerConnectRPC.VersionNumber, playerConnectRPC.VersionString, playerConnectRPC.ChallengeResponse, playerConnectRPC.Name, playerConnectRPC.IsUsingOfficialClient);
bool isUsingOmp = SAMPRakNet::IsPlayerUsingOmp(rpcParams->sender);
if (isUsingOmp)
{
SAMPRakNet::SetPlayerOmpVersion(rpcParams->sender, playerConnectRPC.OmpVersion);
}

IPlayer* newPeer = network->OnPeerConnect(rpcParams, false, serial, playerConnectRPC.VersionNumber, playerConnectRPC.VersionString, playerConnectRPC.ChallengeResponse, playerConnectRPC.Name, isUsingOmp, playerConnectRPC.IsUsingOfficialClient);
if (!newPeer)
{
network->rakNetServer.Kick(rpcParams->sender);
Expand Down Expand Up @@ -474,7 +481,7 @@ void RakNetLegacyNetwork::OnNPCConnect(RakNet::RPCParameters* rpcParams, void* e
NetCode::RPC::NPCConnect NPCConnectRPC;
if (NPCConnectRPC.read(bs))
{
IPlayer* newPeer = network->OnPeerConnect(rpcParams, true, "", NPCConnectRPC.VersionNumber, "npc", NPCConnectRPC.ChallengeResponse, NPCConnectRPC.Name);
IPlayer* newPeer = network->OnPeerConnect(rpcParams, true, "", NPCConnectRPC.VersionNumber, "npc", NPCConnectRPC.ChallengeResponse, NPCConnectRPC.Name, false);
if (newPeer)
{
if (!network->inEventDispatcher.stopAtFalse(
Expand Down
12 changes: 6 additions & 6 deletions Server/Components/LegacyNetwork/legacy_network_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class RakNetLegacyNetwork final : public Network, public CoreEventHandler, publi
ICore* core = nullptr;
Query query;
RakNet::RakServerInterface& rakNetServer;
std::array<IPlayer*, PLAYER_POOL_SIZE> playerFromRakIndex;
std::array<RakNet::RakPeer::RemoteSystemStruct*, PLAYER_POOL_SIZE> playerRemoteSystem;
StaticArray<IPlayer*, PLAYER_POOL_SIZE> playerFromRakIndex;
StaticArray<RakNet::RakPeer::RemoteSystemStruct*, PLAYER_POOL_SIZE> playerRemoteSystem;
Milliseconds cookieSeedTime;
TimePoint lastCookieSeed;

Expand Down Expand Up @@ -130,11 +130,11 @@ class RakNetLegacyNetwork final : public Network, public CoreEventHandler, publi
const PeerNetworkData::NetworkID& nid = netData.networkID;
const RakNet::PlayerID rid { unsigned(nid.address.v4), nid.port };

return rakNetServer.Send((const char*)bs.GetData(), bs.GetNumberOfUnreadBits(), RakNet::HIGH_PRIORITY, reliability, channel, rid, true);
return rakNetServer.Send((const char*)bs.GetData(), bs.GetNumberOfBitsUsed(), RakNet::HIGH_PRIORITY, reliability, channel, rid, true);
}
}

return rakNetServer.Send((const char*)bs.GetData(), bs.GetNumberOfUnreadBits(), RakNet::HIGH_PRIORITY, reliability, channel, RakNet::UNASSIGNED_PLAYER_ID, true);
return rakNetServer.Send((const char*)bs.GetData(), bs.GetNumberOfBitsUsed(), RakNet::HIGH_PRIORITY, reliability, channel, RakNet::UNASSIGNED_PLAYER_ID, true);
}

bool sendPacket(IPlayer& peer, Span<uint8_t> data, int channel, bool dispatchEvents) override
Expand Down Expand Up @@ -177,7 +177,7 @@ class RakNetLegacyNetwork final : public Network, public CoreEventHandler, publi
const PeerNetworkData::NetworkID& nid = netData.networkID;
const RakNet::PlayerID rid { unsigned(nid.address.v4), nid.port };
const RakNet::PacketReliability reliability = (channel == OrderingChannel_Reliable) ? RakNet::RELIABLE : ((channel == OrderingChannel_Unordered) ? RakNet::UNRELIABLE : RakNet::UNRELIABLE_SEQUENCED);
return rakNetServer.Send((const char*)bs.GetData(), bs.GetNumberOfBytesUsed(), RakNet::HIGH_PRIORITY, reliability, channel, rid, false);
return rakNetServer.Send((const char*)bs.GetData(), bs.GetNumberOfBitsUsed(), RakNet::HIGH_PRIORITY, reliability, channel, rid, false);
}

bool broadcastRPC(int id, Span<uint8_t> data, int channel, const IPlayer* exceptPeer, bool dispatchEvents) override
Expand Down Expand Up @@ -275,7 +275,7 @@ class RakNetLegacyNetwork final : public Network, public CoreEventHandler, publi
static void OnPlayerConnect(RakNet::RPCParameters* rpcParams, void* extra);
static void OnNPCConnect(RakNet::RPCParameters* rpcParams, void* extra);

IPlayer* OnPeerConnect(RakNet::RPCParameters* rpcParams, bool isNPC, StringView serial, uint32_t version, StringView versionName, uint32_t challenge, StringView name, bool isUsingOfficialClient = false);
IPlayer* OnPeerConnect(RakNet::RPCParameters* rpcParams, bool isNPC, StringView serial, uint32_t version, StringView versionName, uint32_t challenge, StringView name, bool isUsingOmp, bool isUsingOfficialClient = false);
template <size_t ID>
static void RPCHook(RakNet::RPCParameters* rpcParams, void* extra);
void onTick(Microseconds elapsed, TimePoint now) override;
Expand Down
7 changes: 6 additions & 1 deletion Server/Components/Pawn/Scripting/Player/Natives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ SCRIPT_API(ArePlayerWeaponsAllowed, bool(IPlayer& player))
return player.areWeaponsAllowed();
}

SCRIPT_API(IsPlayerUsingOfficialClient, int(IPlayer& player))
SCRIPT_API(IsPlayerUsingOfficialClient, bool(IPlayer& player))
{
return player.isUsingOfficialClient();
}
Expand Down Expand Up @@ -1195,3 +1195,8 @@ SCRIPT_API(IsPlayerCuffed, bool(IPlayer& player))
}
return false;
}

SCRIPT_API(IsPlayerUsingOmp, bool(IPlayer& player))
{
return player.isUsingOmp();
}
1 change: 1 addition & 0 deletions Server/Source/core_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ static const std::map<String, ConfigStorage> Defaults {
{ "network.use_lan_mode", false },
{ "network.allow_037_clients", true },
{ "network.grace_period", 5000 },
{ "network.use_omp_encryption", false },
// rcon
{ "rcon.allow_teleport", false },
{ "rcon.enable", false },
Expand Down
7 changes: 7 additions & 0 deletions Server/Source/player_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ struct Player final : public IPlayer, public PoolIDProvider, public NoCopy
bool allowWeapons_;
bool allowTeleport_;
bool isUsingOfficialClient_;
bool isUsingOmp_;

PrimarySyncUpdateType primarySyncUpdateType_;
int secondarySyncUpdateType_;
Expand Down Expand Up @@ -259,6 +260,7 @@ struct Player final : public IPlayer, public PoolIDProvider, public NoCopy
, allowWeapons_(true)
, allowTeleport_(false)
, isUsingOfficialClient_(params.isUsingOfficialClient)
, isUsingOmp_(params.isUsingOmp)
, primarySyncUpdateType_(PrimarySyncUpdateType::None)
, secondarySyncUpdateType_(0)
, lastScoresAndPings_(Time::now())
Expand Down Expand Up @@ -321,6 +323,11 @@ struct Player final : public IPlayer, public PoolIDProvider, public NoCopy
return isUsingOfficialClient_;
}

bool isUsingOmp() const override
{
return isUsingOmp_;
}

void setState(PlayerState state, bool dispatchEvents = true);

PlayerState getState() const override
Expand Down
2 changes: 2 additions & 0 deletions Shared/NetCode/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace RPC
HybridString<16> Key;
HybridString<16> VersionString;
bool IsUsingOfficialClient;
uint32_t OmpVersion;

bool read(NetworkBitStream& bs)
{
Expand All @@ -51,6 +52,7 @@ namespace RPC

uint32_t dummyVar = 0;
IsUsingOfficialClient = bs.readUINT32(dummyVar);
OmpVersion = dummyVar;

return readFailed;
}
Expand Down

0 comments on commit 6191a2d

Please sign in to comment.