Send order queue length in ping responses.

This commit is contained in:
Paul Chote
2021-09-25 15:31:04 +01:00
committed by abcdefg30
parent 2d08f2bbfd
commit defaf92752
6 changed files with 30 additions and 17 deletions

View File

@@ -93,6 +93,16 @@ namespace OpenRA.Network
return ms.GetBuffer();
}
public static byte[] SerializePingResponse(long timestamp, byte queueLength)
{
var ms = new MemoryStream(14);
ms.WriteArray(BitConverter.GetBytes(0));
ms.WriteByte((byte)OrderType.Ping);
ms.WriteArray(BitConverter.GetBytes(timestamp));
ms.WriteByte(queueLength);
return ms.GetBuffer();
}
public static bool TryParseDisconnect((int FromClient, byte[] Data) packet, out (int Frame, int ClientId) disconnect)
{
// Valid Disconnect packets are only ever generated by the server
@@ -123,24 +133,24 @@ namespace OpenRA.Network
return true;
}
public static bool TryParsePing(int fromClient, byte[] packet, out byte[] ping)
public static bool TryParsePingRequest((int FromClient, byte[] Data) packet, out long timestamp)
{
// Valid Ping packets are only ever generated by the server
if (fromClient != 0 || packet.Length != 13 || packet[4] != (byte)OrderType.Ping)
// Valid Ping requests are only ever generated by the server
if (packet.FromClient != 0 || packet.Data.Length != 13 || packet.Data[4] != (byte)OrderType.Ping)
{
ping = null;
timestamp = 0;
return false;
}
// Valid Ping packets always have frame 0
var frame = BitConverter.ToInt32(packet, 0);
var frame = BitConverter.ToInt32(packet.Data, 0);
if (frame != 0)
{
ping = null;
timestamp = 0;
return false;
}
ping = packet;
timestamp = BitConverter.ToInt64(packet.Data, 5);
return true;
}