Skip to content

Commit

Permalink
fix flatbuffers not handled correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
belettee committed Apr 21, 2024
1 parent f5142a2 commit ab3f5bb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,13 @@ private IEnumerator SendPlayerStatePacket()

builder.Finish(packetOffset.Value);

// NOTE(belette) Abstraction zealots in shambles, we never needed inheritance, we had if and switch all along, we can see what's happening inline IDONTWANNAHEARIT
if (Singleton<ISITGame>.Instance.GameClient is GameClientUDP udp)
{
var seg = builder.DataBuffer.ToArraySegment(builder.DataBuffer.Position, builder.DataBuffer.Length - builder.DataBuffer.Position);
udp.SendData(seg.Array, seg.Offset, seg.Count, SITGameServerClientDataProcessing.FLATBUFFER_CHANNEL_NUM, LiteNetLib.DeliveryMethod.Sequenced);
}
else if (Singleton<ISITGame>.Instance.GameClient is GameClientTCPRelay relay)
else if (Singleton<ISITGame>.Instance.GameClient is GameClientTCPRelay)
{
// TODO(belette) fix TCP Relay recipient side to detect FlatBuffers and process as such
GameClient.SendData(builder.SizedByteArray());
}
}
Expand Down
14 changes: 9 additions & 5 deletions Source/Networking/GameClientUDP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,15 @@ public void ResetStats()

void INetEventListener.OnNetworkReceive(NetPeer peer, NetPacketReader reader, byte channelNumber, DeliveryMethod deliveryMethod)
{
var bytes = reader.GetRemainingBytes();
Singleton<SITGameServerClientDataProcessing>.Instance.ProcessPacketBytes(bytes);
if (channelNumber == SITGameServerClientDataProcessing.FLATBUFFER_CHANNEL_NUM)
{
Singleton<SITGameServerClientDataProcessing>.Instance.ProcessFlatBuffer(reader.GetRemainingBytes());
}
else
{
var bytes = reader.GetRemainingBytes();
Singleton<SITGameServerClientDataProcessing>.Instance.ProcessPacketBytes(bytes);
}
}

void OnDestroy()
Expand Down Expand Up @@ -282,9 +289,6 @@ public void SendData(byte[] data)
SendData(data, 0, data.Length, 0, LiteNetLib.DeliveryMethod.ReliableOrdered);
}


// Send(byte[] data, int start, int length, byte channelNumber, DeliveryMethod deliveryMethod)

public void SendData<T>(ref T packet) where T : BasePacket
{
using NetDataWriter writer = new NetDataWriter();
Expand Down
3 changes: 0 additions & 3 deletions Source/Networking/SITGameServerClientDataProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ namespace StayInTarkov.Networking
{
public class SITGameServerClientDataProcessing : NetworkBehaviour
{
public const string PACKET_TAG_METHOD = "m";
public const string PACKET_TAG_SERVERID = "serverId";
public const string PACKET_TAG_DATA = "data";
public const byte FLATBUFFER_CHANNEL_NUM = 1;
public event Action<ushort> OnLatencyUpdated;

Check warning on line 29 in Source/Networking/SITGameServerClientDataProcessing.cs

View workflow job for this annotation

GitHub Actions / Build-SIT (Debug)

The event 'SITGameServerClientDataProcessing.OnLatencyUpdated' is never used
private SITGameComponent SITGameComponent { get; set; }
Expand Down

0 comments on commit ab3f5bb

Please sign in to comment.