Skip to content

Commit 3471648

Browse files
committed
Fixed bit writing of security flags
1 parent 88938ca commit 3471648

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

MLAPI/NetworkingManagerComponents/Core/InternalMessageHandler.Send.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ internal static void Send(uint clientId, byte messageType, string channelName, S
2424
{
2525
writer.WritePadBits();
2626

27+
long hmacPosition = stream.Position; // Save the position where the HMAC should be written.
2728
if (authenticated) stream.Position += 32; // Skip 32 bytes. These will be replaced later on by the HMAC.
2829

2930
if (encrypted)
@@ -52,7 +53,7 @@ internal static void Send(uint clientId, byte messageType, string channelName, S
5253
{
5354
if (!encrypted) writer.WriteByte(messageType); // If we are not using encryption, write the byte. Note that the current position in the stream is just after the HMAC.
5455

55-
stream.Position = 1; // First byte is the security flags. The HMAC will now be written after that
56+
stream.Position = hmacPosition; // Set the position to where the HMAC should be written.
5657
using (HMACSHA256 hmac = new HMACSHA256(netManager.isServer ? netManager.ConnectedClients[clientId].AesKey : netManager.clientAesKey))
5758
{
5859
writer.WriteByteArray(hmac.ComputeHash(stream.GetBuffer(), (32 + 1), (int)stream.Length - (32 + 1)), 32);
@@ -95,7 +96,10 @@ internal static void Send(byte messageType, string channelName, Stream messageSt
9596
{
9697
using (PooledBitWriter writer = PooledBitWriter.Get(stream))
9798
{
98-
writer.WriteByte(messageType);
99+
writer.WriteBool(false); // Encryption
100+
writer.WriteBool(false); // Authentication
101+
102+
writer.WriteBits(messageType, 6);
99103
stream.CopyFrom(messageStream);
100104

101105
NetworkProfiler.StartEvent(TickType.Send, (uint)stream.Length, channelName, MLAPIConstants.MESSAGE_NAMES[messageType]);
@@ -129,7 +133,10 @@ internal static void Send(byte messageType, string channelName, uint clientIdToI
129133
{
130134
using (PooledBitWriter writer = PooledBitWriter.Get(stream))
131135
{
132-
writer.WriteByte(messageType);
136+
writer.WriteBool(false); // Encryption
137+
writer.WriteBool(false); // Authentication
138+
139+
writer.WriteBits(messageType, 6);
133140
stream.CopyFrom(messageStream);
134141

135142
NetworkProfiler.StartEvent(TickType.Send, (uint)stream.Length, channelName, MLAPIConstants.MESSAGE_NAMES[messageType]);

0 commit comments

Comments
 (0)