Skip to content

Commit

Permalink
Merge branch 'openmultiplayer:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
NexiusTailer authored Oct 8, 2024
2 parents 1d34d1d + a672484 commit 880f914
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
13 changes: 7 additions & 6 deletions Server/Components/LegacyNetwork/legacy_network_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,14 @@ RakNetLegacyNetwork::~RakNetLegacyNetwork()

static NetworkBitStream GetBitStream(RakNet::RPCParameters& rpcParams)
{
unsigned int
const unsigned int
bits
= rpcParams.numberOfBitsOfData;
if (bits == 0)
return NetworkBitStream();
unsigned int
bytes
= (bits - 1) / 8 + 1;
return NetworkBitStream(rpcParams.input, bytes, false);
NetworkBitStream bs(rpcParams.input, bitsToBytes(bits), false /* copyData */);
bs.SetWriteOffset(bits);
return bs;
}

enum LegacyClientVersion
Expand Down Expand Up @@ -906,7 +905,9 @@ void RakNetLegacyNetwork::onTick(Microseconds elapsed, TimePoint now)

if (player)
{
NetworkBitStream bs(pkt->data, pkt->length, false);
const unsigned int bits = pkt->bitSize;
NetworkBitStream bs(pkt->data, bitsToBytes(bits), false);
bs.SetWriteOffset(bits);
uint8_t type;
if (bs.readUINT8(type))
{
Expand Down
24 changes: 8 additions & 16 deletions Server/Components/LegacyNetwork/legacy_network_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,9 @@ class RakNetLegacyNetwork final : public Network, public CoreEventHandler, publi

bool broadcastPacket(Span<uint8_t> data, int channel, const IPlayer* exceptPeer, bool dispatchEvents) override
{
// Don't use constructor because it takes bytes; we want bits
NetworkBitStream bs;
bs.SetData(data.data());
// We want exact bits - set the write offset with bit granularity
NetworkBitStream bs(data.data(), bitsToBytes(data.size()), false /* copyData */);
bs.SetWriteOffset(data.size());
bs.SetReadOffset(0);

if (dispatchEvents)
{
Expand Down Expand Up @@ -147,11 +145,9 @@ class RakNetLegacyNetwork final : public Network, public CoreEventHandler, publi
return false;
}

// Don't use constructor because it takes bytes; we want bits
NetworkBitStream bs;
bs.SetData(data.data());
// We want exact bits - set the write offset with bit granularity
NetworkBitStream bs(data.data(), bitsToBytes(data.size()), false /* copyData */);
bs.SetWriteOffset(data.size());
bs.SetReadOffset(0);

if (dispatchEvents)
{
Expand Down Expand Up @@ -191,11 +187,9 @@ class RakNetLegacyNetwork final : public Network, public CoreEventHandler, publi
return false;
}

// Don't use constructor because it takes bytes; we want bits
NetworkBitStream bs;
bs.SetData(data.data());
// We want exact bits - set the write offset with bit granularity
NetworkBitStream bs(data.data(), bitsToBytes(data.size()), false /* copyData */);
bs.SetWriteOffset(data.size());
bs.SetReadOffset(0);

if (dispatchEvents)
{
Expand Down Expand Up @@ -247,11 +241,9 @@ class RakNetLegacyNetwork final : public Network, public CoreEventHandler, publi
return false;
}

// Don't use constructor because it takes bytes; we want bits
NetworkBitStream bs;
bs.SetData(data.data());
// We want exact bits - set the write offset with bit granularity
NetworkBitStream bs(data.data(), bitsToBytes(data.size()), false /* copyData */);
bs.SetWriteOffset(data.size());
bs.SetReadOffset(0);

if (dispatchEvents)
{
Expand Down

0 comments on commit 880f914

Please sign in to comment.