Skip to content

Commit

Permalink
id testing complete works
Browse files Browse the repository at this point in the history
  • Loading branch information
dooly123 committed Jan 17, 2025
1 parent a35fe2e commit f6d904c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ public static class BasisNetworkNetIDConversion

public static void RequestId(string NetworkId)
{
if (NetworkIds.TryGetValue(NetworkId,out ushort Value))
if (NetworkIds.TryGetValue(NetworkId, out ushort Value))
{
OnNetworkIdAdded?.Invoke(NetworkId, Value);
}
else
{
NetDataWriter netDataWriter = new NetDataWriter();

BasisNetworkManagement.LocalPlayerPeer.Send(netDataWriter,BasisNetworkCommons.netIDAssign, LiteNetLib.DeliveryMethod.ReliableSequenced);
NetIDMessage ServerUniqueIDMessage = new NetIDMessage();
ServerUniqueIDMessage.UniqueID = NetworkId;
ServerUniqueIDMessage.Serialize(netDataWriter);
BasisNetworkManagement.LocalPlayerPeer.Send(netDataWriter, BasisNetworkCommons.netIDAssign, LiteNetLib.DeliveryMethod.ReliableSequenced);
//request new one from server
}
}

public static void AddNetworkId(ServerNetIDMessage ServerNetIDMessage)
{
// Attempt to add the new network ID
Expand Down
12 changes: 10 additions & 2 deletions Basis/Packages/com.basis.tests/BasisTestNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Basis.Scripts.Networking;
using Basis.Scripts.Networking.NetworkedAvatar;
using LiteNetLib;
using System;
using UnityEngine;

public class BasisTestNetwork : MonoBehaviour
Expand All @@ -12,6 +13,7 @@ public class BasisTestNetwork : MonoBehaviour
public DeliveryMethod Method = DeliveryMethod.ReliableSequenced;
public bool Send = false;
public ushort[] Players;
public string UniqueID = "test";
public void OnEnable()
{
avatar = BasisLocalPlayer.Instance.BasisAvatar;
Expand All @@ -28,6 +30,8 @@ public void OnEnable()
}
}
BasisScene.OnNetworkMessageReceived += OnNetworkMessageReceived;
BasisNetworkNetIDConversion.RequestId(UniqueID);
BasisNetworkNetIDConversion.OnNetworkIdAdded += OnNetworkIdAdded;
}
public void OnDisable()
{
Expand All @@ -53,11 +57,11 @@ public void LateUpdate()
{
// ushort[] Players = BasisNetworkManagement.RemotePlayers.Keys.ToArray();
byte[] Bytes = new byte[16];
Debug.Log("sending Avatar");
// Debug.Log("sending Avatar");

// avatar.NetworkMessageSend(1, Method);
// avatar.NetworkMessageSend(2, null, Method);
avatar.ServerReductionSystemMessageSend(3, SendingOutBytes);
// avatar.ServerReductionSystemMessageSend(3, SendingOutBytes);

// avatar.NetworkMessageSend(4, null, Method, null);

Expand All @@ -79,6 +83,10 @@ public void LateUpdate()
Send = false;
}
}
private void OnNetworkIdAdded(string uniqueId, ushort ushortId)
{
Debug.Log($"uniqueId: {uniqueId} Mapped to {ushortId} By Server");
}
private void OnNetworkMessageReceived(ushort PlayerID, ushort MessageIndex, byte[] buffer, DeliveryMethod Method = DeliveryMethod.ReliableSequenced)
{
string bufferLength = buffer != null ? buffer.Length.ToString() : "null";
Expand Down

0 comments on commit f6d904c

Please sign in to comment.