Skip to content

Commit

Permalink
feat: session state token
Browse files Browse the repository at this point in the history
  • Loading branch information
DSchroer committed Feb 5, 2025
1 parent 05c64fa commit 4095475
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using Unity.Collections;
using UnityEngine;

namespace Unity.Netcode
{
Expand Down Expand Up @@ -43,11 +44,13 @@ public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReade

internal struct ConnectionApprovedMessage : INetworkMessage
{
private const int k_AddSessionStateToken = 3;
private const int k_AddCMBServiceConfig = 2;
private const int k_VersionAddClientIds = 1;
public int Version => k_AddCMBServiceConfig;
public int Version => k_AddSessionStateToken;

public ulong OwnerClientId;
public ulong SessionStateToken;
public int NetworkTick;
// The cloud state service should set this if we are restoring a session
public ServiceConfig ServiceConfig;
Expand Down Expand Up @@ -108,6 +111,10 @@ public void Serialize(FastBufferWriter writer, int targetVersion)
// ============================================================

BytePacker.WriteValueBitPacked(writer, OwnerClientId);
if (targetVersion >= k_AddSessionStateToken)
{
writer.WriteValueSafe(SessionStateToken);
}
BytePacker.WriteValueBitPacked(writer, NetworkTick);
if (IsDistributedAuthority)
{
Expand Down Expand Up @@ -199,6 +206,10 @@ public bool Deserialize(FastBufferReader reader, ref NetworkContext context, int
// ============================================================
m_ReceiveMessageVersion = receivedMessageVersion;
ByteUnpacker.ReadValueBitPacked(reader, out OwnerClientId);
if (receivedMessageVersion >= k_AddSessionStateToken)
{
reader.ReadValueSafe(out SessionStateToken);
}
ByteUnpacker.ReadValueBitPacked(reader, out NetworkTick);
if (networkManager.DistributedAuthorityMode)
{
Expand Down

0 comments on commit 4095475

Please sign in to comment.