Skip to content

Commit

Permalink
Change packets to long from float
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-r-elp committed Dec 17, 2023
1 parent 2064fc8 commit 6763bfa
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
using BeatTogether.LiteNetLib.Abstractions;
using BeatTogether.Extensions;
using BeatTogether.LiteNetLib.Abstractions;
using BeatTogether.LiteNetLib.Util;

namespace BeatTogether.DedicatedServer.Messaging.Abstractions
{
public abstract class BaseRpcPacket : INetSerializable
{
public float SyncTime { get; set; }
public long SyncTime { get; set; }

public virtual void ReadFrom(ref SpanBuffer reader)
{
SyncTime = reader.ReadFloat32();
SyncTime = (long)reader.ReadVarULong();
}

public virtual void WriteTo(ref SpanBuffer writer)
{
writer.WriteFloat32(SyncTime);
writer.WriteVarULong((ulong)SyncTime);
}
public virtual void ReadFrom(ref MemoryBuffer reader)
{
SyncTime = reader.ReadFloat32();
SyncTime = (long)reader.ReadVarULong();
}

public virtual void WriteTo(ref MemoryBuffer writer)
{
writer.WriteFloat32(SyncTime);
writer.WriteVarULong((ulong)SyncTime);
}
}
}
9 changes: 5 additions & 4 deletions BeatTogether.DedicatedServer.Messaging/Packets/PingPacket.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
using BeatTogether.LiteNetLib.Abstractions;
using BeatTogether.Extensions;
using BeatTogether.LiteNetLib.Abstractions;
using BeatTogether.LiteNetLib.Util;

namespace BeatTogether.DedicatedServer.Messaging.Packets
{
public sealed class PingPacket : INetSerializable
{
public float PingTime { get; set; }
public long PingTime { get; set; }

public void WriteTo(ref SpanBuffer writer)
{
writer.WriteFloat32(PingTime);
writer.WriteVarULong((ulong)PingTime);
}

public void ReadFrom(ref SpanBuffer reader)
{
PingTime = reader.ReadFloat32();
PingTime = (long)reader.ReadVarULong();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BeatTogether.LiteNetLib.Abstractions;
using BeatTogether.Extensions;
using BeatTogether.LiteNetLib.Abstractions;
using BeatTogether.LiteNetLib.Util;

namespace BeatTogether.DedicatedServer.Messaging.Packets
Expand All @@ -9,12 +10,12 @@ public sealed class PlayerLatencyPacket : INetSerializable

public void ReadFrom(ref SpanBuffer reader)
{
Latency = (long)reader.ReadUInt64();
Latency = (long)reader.ReadVarULong();
}

public void WriteTo(ref SpanBuffer writer)
{
writer.WriteUInt64((ulong)Latency);
writer.WriteVarULong((ulong)Latency);
}
}
}
9 changes: 5 additions & 4 deletions BeatTogether.DedicatedServer.Messaging/Packets/PongPacket.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
using BeatTogether.LiteNetLib.Abstractions;
using BeatTogether.Extensions;
using BeatTogether.LiteNetLib.Abstractions;
using BeatTogether.LiteNetLib.Util;

namespace BeatTogether.DedicatedServer.Messaging.Packets
{
public sealed class PongPacket : INetSerializable
{
public float PingTime { get; set; }
public long PingTime { get; set; }

public void WriteTo(ref SpanBuffer writer)
{
writer.WriteFloat32(PingTime);
writer.WriteVarULong((ulong)PingTime);
}

public void ReadFrom(ref SpanBuffer reader)
{
PingTime = reader.ReadFloat32();
PingTime = (long)reader.ReadVarULong();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BeatTogether.LiteNetLib.Abstractions;
using BeatTogether.Extensions;
using BeatTogether.LiteNetLib.Abstractions;
using BeatTogether.LiteNetLib.Util;

namespace BeatTogether.DedicatedServer.Messaging.Packets
Expand All @@ -9,12 +10,12 @@ public sealed class SyncTimePacket : INetSerializable

public void WriteTo(ref SpanBuffer writer)
{
writer.WriteUInt64((ulong)SyncTime);
writer.WriteVarULong((ulong)SyncTime);
}

public void ReadFrom(ref SpanBuffer reader)
{
SyncTime = (long)reader.ReadUInt64();
SyncTime = (long)reader.ReadVarULong();
}
}
}

0 comments on commit 6763bfa

Please sign in to comment.