上传YomovSDK

This commit is contained in:
Sora丶kong
2026-03-03 03:15:46 +08:00
parent 9096da7e6c
commit eb97f31065
6477 changed files with 1932208 additions and 3 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fa7c8a088aea3f04580b62c8e2a388ec
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1 @@
This software uses the license for Fish-Networking: https://github.com/FirstGearGames/FishNet/blob/main/LICENSE.md

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: ff1ecc2a24fd9684a862c4b99cfc2fcd
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 06703c0fac6f21140ab99ef3eeb8a4f7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,54 @@
using FishNet.Object;
using UnityEngine;
namespace FishNet.Component.ColliderRollback
{
public class ColliderRollback : NetworkBehaviour
{
#region Types.
internal enum BoundingBoxType
{
/// <summary>
/// Disable this feature.
/// </summary>
Disabled,
/// <summary>
/// Manually specify the dimensions of a bounding box.
/// </summary>
Manual,
}
#endregion
#region Serialized.
/// <summary>
/// How to configure the bounding box check.
/// </summary>
[Tooltip("How to configure the bounding box check.")]
[SerializeField]
private BoundingBoxType _boundingBox = BoundingBoxType.Disabled;
/// <summary>
/// Physics type to generate a bounding box for.
/// </summary>
[Tooltip("Physics type to generate a bounding box for.")]
[SerializeField]
private RollbackPhysicsType _physicsType = RollbackPhysicsType.Physics;
/// <summary>
/// Size for the bounding box. This is only used when BoundingBox is set to Manual.
/// </summary>
[Tooltip("Size for the bounding box.. This is only used when BoundingBox is set to Manual.")]
[SerializeField]
private Vector3 _boundingBoxSize = new Vector3(3f, 3f, 3f);
/// <summary>
/// Objects holding colliders which can rollback.
/// </summary>
[Tooltip("Objects holding colliders which can rollback.")]
[SerializeField]
private GameObject[] _colliderParents = new GameObject[0];
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 01a271dd97d875347b0cea860df29a9d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: bf9191e2e07d29749bca3a1ae44e4bc8, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,54 @@
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
using static FishNet.Component.ColliderRollback.ColliderRollback;
namespace FishNet.Component.ColliderRollback
{
[CustomEditor(typeof(ColliderRollback), true)]
[CanEditMultipleObjects]
public class ColliderRollbackEditor : Editor
{
private SerializedProperty _boundingBox;
private SerializedProperty _physicsType;
private SerializedProperty _boundingBoxSize;
private SerializedProperty _colliderParents;
protected virtual void OnEnable()
{
_boundingBox = serializedObject.FindProperty(nameof(_boundingBox));
_physicsType = serializedObject.FindProperty(nameof(_physicsType));
_boundingBoxSize = serializedObject.FindProperty(nameof(_boundingBoxSize));
_colliderParents = serializedObject.FindProperty(nameof(_colliderParents));
}
public override void OnInspectorGUI()
{
serializedObject.Update();
ColliderRollback nob = (ColliderRollback)target;
GUI.enabled = false;
EditorGUILayout.ObjectField("Script:", MonoScript.FromMonoBehaviour(nob), typeof(ColliderRollback), false);
GUI.enabled = true;
EditorGUILayout.PropertyField(_boundingBox, new GUIContent("Bounding Box (experimental)"));
if ((BoundingBoxType)_boundingBox.intValue != BoundingBoxType.Disabled)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(_physicsType);
EditorGUILayout.PropertyField(_boundingBoxSize);
EditorGUI.indentLevel--;
}
EditorGUILayout.PropertyField(_colliderParents);
serializedObject.ApplyModifiedProperties();
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b0fd7d7c980dbbc49b3ab071b1974d33
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,213 @@
using FishNet.Connection;
using FishNet.Managing;
using FishNet.Managing.Scened;
using FishNet.Managing.Timing;
using FishNet.Transporting;
using GameKit.Utilities;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace FishNet.Component.ColliderRollback
{
public class RollbackManager : MonoBehaviour
{
#region Types.
[System.Serializable, System.Flags] //Remove on 2024/01/01, replace with PhysicsType that is not part of RollbackManager.
public enum PhysicsType : byte
{
TwoDimensional = 1,
ThreeDimensional = 2,
Both = 4
}
#endregion
#region Internal.
/// <summary>
/// Cached value for bounding box layermask.
/// </summary>
internal int? BoundingBoxLayerNumber
{
get
{
if (_boundingBoxLayerNumber == null)
{
for (int i = 0; i < 32; i++)
{
if ((1 << i) == BoundingBoxLayer.value)
{
_boundingBoxLayerNumber = i;
break;
}
}
}
return _boundingBoxLayerNumber;
}
}
private int? _boundingBoxLayerNumber;
#endregion
#region Serialized.
/// <summary>
///
/// </summary>
[Tooltip("Layer to use when creating and checking against bounding boxes. This should be different from any layer used.")]
[SerializeField]
private LayerMask _boundingBoxLayer = 0;
/// <summary>
/// Layer to use when creating and checking against bounding boxes. This should be different from any layer used.
/// </summary>
internal LayerMask BoundingBoxLayer => _boundingBoxLayer;
/// <summary>
///
/// </summary>
[Tooltip("Maximum time in the past colliders can be rolled back to.")]
[SerializeField]
private float _maximumRollbackTime = 1.25f;
/// <summary>
/// Maximum time in the past colliders can be rolled back to.
/// </summary>
internal float MaximumRollbackTime => _maximumRollbackTime;
/// <summary>
///
/// </summary>
[Tooltip("Interpolation value for the NetworkTransforms or objects being rolled back.")]
[Range(0, 250)]
[SerializeField]
internal ushort Interpolation = 2;
#endregion
/// <summary>
/// Initializes this script for use.
/// </summary>
/// <param name="manager"></param>
internal void InitializeOnce_Internal(NetworkManager manager)
{
}
/// <summary>
/// Rolls back all colliders.
/// </summary>
/// <param name="pt">Precise tick received from the client.</param>
/// <param name="physicsType">Type of physics to rollback; this is often what your casts will use.</param>
/// <param name="asOwner">True if IsOwner of the object the raycast is for. This can be ignored and only provides more accurate results for clientHost.</param>
[Obsolete("Use Rollback(PreciseTick, RollbackPhysicsType, bool")] //Remove on 2024/01/01.
public void Rollback(PreciseTick pt, PhysicsType physicsType, bool asOwner = false)
{
}
/// <summary>
/// Rolls back all colliders.
/// </summary>
/// <param name="pt">Precise tick received from the client.</param>
/// <param name="physicsType">Type of physics to rollback; this is often what your casts will use.</param>
/// <param name="asOwner">True if IsOwner of the object the raycast is for. This can be ignored and only provides more accurate results for clientHost.</param>
public void Rollback(PreciseTick pt, RollbackPhysicsType physicsType, bool asOwner = false)
{
}
/// <summary>
/// Rolls back all colliders.
/// </summary>
/// <param name="pt">Precise tick received from the client.</param>
/// <param name="physicsType">Type of physics to rollback; this is often what your casts will use.</param>
/// <param name="asOwner">True if IsOwner of the object the raycast is for. This can be ignored and only provides more accurate results for clientHost.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Rollback(Scene scene, PreciseTick pt, RollbackPhysicsType physicsType, bool asOwner = false)
{
}
/// <summary>
/// Rolls back all colliders.
/// </summary>
/// <param name="pt">Precise tick received from the client.</param>
/// <param name="physicsType">Type of physics to rollback; this is often what your casts will use.</param>
/// <param name="asOwner">True if IsOwner of the object the raycast is for. This can be ignored and only provides more accurate results for clientHost.</param>
public void Rollback(int sceneHandle, PreciseTick pt, RollbackPhysicsType physicsType, bool asOwner = false)
{
}
/// <summary>
/// Rolls back all 3d colliders hit by a test cast against bounding boxes.
/// </summary>
/// <param name="origin">Ray origin.</param>
/// <param name="normalizedDirection">Direction to cast.</param>
/// <param name="distance">Distance of cast.</param>
/// <param name="pt">Precise tick received from the client.</param>
/// <param name="asOwner">True if IsOwner of the object the raycast is for. This can be ignored and only provides more accurate results for clientHost.</param>
public void Rollback(Vector3 origin, Vector3 normalizedDirection, float distance, PreciseTick pt, bool asOwner = false)
{
}
/// <summary>
/// Rolls back all 3d colliders hit by a test cast against bounding boxes.
/// </summary>
/// <param name="origin">Ray origin.</param>
/// <param name="normalizedDirection">Direction to cast.</param>
/// <param name="distance">Distance of cast.</param>
/// <param name="pt">Precise tick received from the client.</param>
/// <param name="asOwner">True if IsOwner of the object the raycast is for. This can be ignored and only provides more accurate results for clientHost.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Rollback(Scene scene, Vector3 origin, Vector3 normalizedDirection, float distance, PreciseTick pt, bool asOwner = false)
{
}
/// <summary>
/// Rolls back all 3d colliders hit by a test cast against bounding boxes.
/// </summary>
/// <param name="origin">Ray origin.</param>
/// <param name="normalizedDirection">Direction to cast.</param>
/// <param name="distance">Distance of cast.</param>
/// <param name="pt">Precise tick received from the client.</param>
/// <param name="asOwner">True if IsOwner of the object the raycast is for. This can be ignored and only provides more accurate results for clientHost.</param>
public void Rollback(int sceneHandle, Vector3 origin, Vector3 normalizedDirection, float distance, PreciseTick pt, bool asOwner = false)
{
}
/// <summary>
/// Rolls back all 3d colliders hit by a test cast against bounding boxes.
/// </summary>
/// <param name="origin">Ray origin.</param>
/// <param name="normalizedDirection">Direction to cast.</param>
/// <param name="distance">Distance of cast.</param>
/// <param name="pt">Precise tick received from the client.</param>
/// <param name="asOwner">True if IsOwner of the object the raycast is for. This can be ignored and only provides more accurate results for clientHost.</param>
public void Rollback(Vector2 origin, Vector2 normalizedDirection, float distance, PreciseTick pt, bool asOwner = false)
{
}
/// <summary>
/// Returns all ColliderRollback objects back to their original position.
/// </summary>
public void Return()
{
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b185516acd802904383e2a5f1a666750
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: bf9191e2e07d29749bca3a1ae44e4bc8, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
namespace FishNet.Component.ColliderRollback
{
/// <summary>
/// Which physics to apply after rolling back colliders.
/// </summary>
[System.Serializable]
public enum RollbackPhysicsType
{
Physics = 1,
Physics2D = 2,
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 82b31e74d64a0c44d8fa2f3b6b08ebca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: db8731a93272f9a48b7fc3d035e88bfa
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,2 @@
1.0.0
- Initial release.

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 65389c57cd9accf47967cc3e6cb7ac1b
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3b79a48228ccfcd4cbf0a0514295abeb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,152 @@
//PROSTART
using FishNet.Transporting.Yak.Server;
using System;
using System.Collections.Generic;
namespace FishNet.Transporting.Yak.Client
{
/// <summary>
/// Creates a fake client connection to interact with the ServerSocket.
/// </summary>
public class ClientSocket : CommonSocket
{
#region Private.
/// <summary>
/// Socket for the server.
/// </summary>
private ServerSocket _server;
/// <summary>
/// Incomimg data.
/// </summary>
private Queue<LocalPacket> _incoming = new Queue<LocalPacket>();
#endregion
/// <summary>
/// Initializes this for use.
/// </summary>
internal override void Initialize(Transport t, CommonSocket socket)
{
base.Initialize(t, socket);
_server = (ServerSocket)socket;
}
/// <summary>
/// Starts the client connection.
/// </summary>
internal bool StartConnection()
{
//Already starting/started, or stopping.
if (base.GetLocalConnectionState() != LocalConnectionState.Stopped)
return false;
SetLocalConnectionState(LocalConnectionState.Starting, false);
/* Certain conditions need the client state to change as well.
* Such as, if the server state is stopping then the client should
* also be stopping, rather than starting. Or if the server state
* is already started then client should immediately be set started
* rather than waiting for server started callback. */
LocalConnectionState serverState = _server.GetLocalConnectionState();
if (serverState == LocalConnectionState.Stopping || serverState == LocalConnectionState.Started)
OnLocalServerConnectionState(_server.GetLocalConnectionState());
return true;
}
/// <summary>
/// Sets a new connection state.
/// </summary>
protected override void SetLocalConnectionState(LocalConnectionState connectionState, bool server)
{
base.SetLocalConnectionState(connectionState, server);
if (connectionState == LocalConnectionState.Started || connectionState == LocalConnectionState.Stopped)
_server.OnLocalClientConnectionState(connectionState);
}
/// <summary>
/// Stops the local socket.
/// </summary>
internal bool StopConnection()
{
if (base.GetLocalConnectionState() == LocalConnectionState.Stopped || base.GetLocalConnectionState() == LocalConnectionState.Stopping)
return false;
base.ClearQueue(ref _incoming);
//Immediately set stopped since no real connection exists.
SetLocalConnectionState(LocalConnectionState.Stopping, false);
SetLocalConnectionState(LocalConnectionState.Stopped, false);
return true;
}
/// <summary>
/// Iterations data received.
/// </summary>
internal void IterateIncoming()
{
if (base.GetLocalConnectionState() != LocalConnectionState.Started)
return;
while (_incoming.Count > 0)
{
LocalPacket packet = _incoming.Dequeue();
ArraySegment<byte> segment = new ArraySegment<byte>(packet.Data, 0, packet.Length);
ClientReceivedDataArgs dataArgs = new ClientReceivedDataArgs(segment, (Channel)packet.Channel, base.Transport.Index);
base.Transport.HandleClientReceivedDataArgs(dataArgs);
packet.Dispose();
}
}
/// <summary>
/// Called when the server sends the local client data.
/// </summary>
internal void ReceivedFromLocalServer(LocalPacket packet)
{
_incoming.Enqueue(packet);
}
/// <summary>
/// Queues data to be sent to server.
/// </summary>
internal void SendToServer(byte channelId, ArraySegment<byte> segment)
{
if (base.GetLocalConnectionState() != LocalConnectionState.Started)
return;
if (_server.GetLocalConnectionState() != LocalConnectionState.Started)
return;
LocalPacket packet = new LocalPacket(segment, channelId);
_server.ReceivedFromLocalClient(packet);
}
#region Local server.
/// <summary>
/// Called when the local server starts or stops.
/// </summary>
internal void OnLocalServerConnectionState(LocalConnectionState state)
{
//Server started.
if (state == LocalConnectionState.Started &&
base.GetLocalConnectionState() == LocalConnectionState.Starting)
{
SetLocalConnectionState(LocalConnectionState.Started, false);
}
//Server not started.
else
{
//If stopped or stopping then disconnect client if also not stopped or stopping.
if ((state == LocalConnectionState.Stopping || state == LocalConnectionState.Stopped) &&
(base.GetLocalConnectionState() == LocalConnectionState.Started ||
base.GetLocalConnectionState() == LocalConnectionState.Starting)
)
{
SetLocalConnectionState(LocalConnectionState.Stopping, false);
SetLocalConnectionState(LocalConnectionState.Stopped, false);
}
}
}
#endregion
}
}
//PROEND

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 26269fe7187f5da4e957080519ea0f13
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,72 @@
//PROSTART
using FishNet.Transporting;
using System.Collections.Generic;
namespace FishNet.Transporting.Yak
{
public abstract class CommonSocket
{
#region Public.
/// <summary>
/// Current ConnectionState.
/// </summary>
private LocalConnectionState _connectionState = LocalConnectionState.Stopped;
/// <summary>
/// Returns the current ConnectionState.
/// </summary>
/// <returns></returns>
internal LocalConnectionState GetLocalConnectionState()
{
return _connectionState;
}
/// <summary>
/// Sets a new connection state.
/// </summary>
/// <param name="connectionState"></param>
protected virtual void SetLocalConnectionState(LocalConnectionState connectionState, bool server)
{
//If state hasn't changed.
if (connectionState == _connectionState)
return;
_connectionState = connectionState;
if (server)
Transport.HandleServerConnectionState(new ServerConnectionStateArgs(connectionState, Transport.Index));
else
Transport.HandleClientConnectionState(new ClientConnectionStateArgs(connectionState, Transport.Index));
}
#endregion
#region Protected.
/// <summary>
/// Transport controlling this socket.
/// </summary>
protected Transport Transport = null;
#endregion
/// <summary>
/// Initializes this for use.
/// </summary>
internal virtual void Initialize(Transport t, CommonSocket socket)
{
Transport = t;
}
/// <summary>
/// Clears a queue.
/// </summary>
internal void ClearQueue(ref Queue<LocalPacket> queue)
{
while (queue.Count > 0)
{
LocalPacket lp = queue.Dequeue();
lp.Dispose();
}
}
}
}
//PROEND

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 63afa30fa0251df44b9496aded55d795
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
//PROSTART
using FishNet.Utility.Performance;
using System;
namespace FishNet.Transporting.Yak
{
internal struct LocalPacket
{
public byte[] Data;
public int Length;
public byte Channel;
public LocalPacket(ArraySegment<byte> data, byte channel)
{
Data = ByteArrayPool.Retrieve(data.Count);
Length = data.Count;
Buffer.BlockCopy(data.Array, data.Offset, Data, 0, Length);
Channel = channel;
}
public void Dispose()
{
ByteArrayPool.Store(Data);
}
}
}
//PROEND

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f52ce359669f91c4d981dc605a8875b7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,167 @@
//PROSTART
using FishNet.Transporting;
using FishNet.Transporting.Yak.Client;
using System;
using System.Collections.Generic;
namespace FishNet.Transporting.Yak.Server
{
/// <summary>
/// Creates a fake socket acting as server.
/// </summary>
public class ServerSocket : CommonSocket
{
#region Public.
/// <summary>
/// Gets the current ConnectionState of a remote client on the server.
/// </summary>
/// <param name="connectionId">ConnectionId to get ConnectionState for.</param>
internal RemoteConnectionState GetConnectionState(int connectionId)
{
if (connectionId != Yak.CLIENT_HOST_ID)
return RemoteConnectionState.Stopped;
LocalConnectionState state = _client.GetLocalConnectionState();
return (state == LocalConnectionState.Started) ? RemoteConnectionState.Started :
RemoteConnectionState.Stopped;
}
#endregion
#region Private.
/// <summary>
/// Packets received from local client.
/// </summary>
private Queue<LocalPacket> _incoming = new Queue<LocalPacket>();
/// <summary>
/// Socket for client.
/// </summary>
private ClientSocket _client;
#endregion
/// <summary>
/// Initializes this for use.
/// </summary>
internal override void Initialize(Transport t, CommonSocket socket)
{
base.Initialize(t, socket);
_client = (ClientSocket)socket;
}
/// <summary>
/// Starts the server.
/// </summary>
internal bool StartConnection()
{
SetLocalConnectionState(LocalConnectionState.Starting, true);
SetLocalConnectionState(LocalConnectionState.Started, true);
return true;
}
/// <summary>
/// Sets a new connection state.
/// </summary>
protected override void SetLocalConnectionState(LocalConnectionState connectionState, bool server)
{
base.SetLocalConnectionState(connectionState, server);
_client.OnLocalServerConnectionState(connectionState);
}
/// <summary>
/// Stops the local socket.
/// </summary>
internal bool StopConnection()
{
if (base.GetLocalConnectionState() == LocalConnectionState.Stopped)
return false;
base.ClearQueue(ref _incoming);
SetLocalConnectionState(LocalConnectionState.Stopping, true);
SetLocalConnectionState(LocalConnectionState.Stopped, true);
return true;
}
/// <summary>
/// Stops a remote client from the server, disconnecting the client.
/// </summary>
/// <param name="connectionId">ConnectionId of the client to disconnect.</param>
internal bool StopConnection(int connectionId)
{
if (connectionId != Yak.CLIENT_HOST_ID)
return false;
_client.StopConnection();
return true;
}
/// <summary>
/// Iterates the Incoming queue.
/// </summary>
/// <param name="transport"></param>
internal void IterateIncoming()
{
if (base.GetLocalConnectionState() != LocalConnectionState.Started)
return;
//Iterate local client packets first.
while (_incoming.Count > 0)
{
LocalPacket packet = _incoming.Dequeue();
ArraySegment<byte> segment = new ArraySegment<byte>(packet.Data, 0, packet.Length);
ServerReceivedDataArgs args = new ServerReceivedDataArgs(segment, (Channel)packet.Channel, Yak.CLIENT_HOST_ID, base.Transport.Index);
base.Transport.HandleServerReceivedDataArgs(args);
}
}
/// <summary>
/// Sends data to a client.
/// </summary>
/// <param name="channelId"></param>
/// <param name="segment"></param>
/// <param name="connectionId"></param>
internal void SendToClient(byte channelId, ArraySegment<byte> segment, int connectionId)
{
if (base.GetLocalConnectionState() != LocalConnectionState.Started)
return;
if (connectionId != Yak.CLIENT_HOST_ID)
return;
LocalPacket packet = new LocalPacket(segment, channelId);
_client.ReceivedFromLocalServer(packet);
}
#region Local client.
/// <summary>
/// Called when the local client starts or stops.
/// </summary>
internal void OnLocalClientConnectionState(LocalConnectionState state)
{
//If not started flush incoming from local client.
if (state != LocalConnectionState.Started)
{
base.ClearQueue(ref _incoming);
//If stopped then send stopped event as well.
if (state == LocalConnectionState.Stopped)
base.Transport.HandleRemoteConnectionState(new RemoteConnectionStateArgs(RemoteConnectionState.Stopped, Yak.CLIENT_HOST_ID, base.Transport.Index));
}
else
{
base.Transport.HandleRemoteConnectionState(new RemoteConnectionStateArgs(RemoteConnectionState.Started, Yak.CLIENT_HOST_ID, base.Transport.Index));
}
}
/// <summary>
/// Queues a received packet from the local client.
/// </summary>
internal void ReceivedFromLocalClient(LocalPacket packet)
{
if (_client.GetLocalConnectionState() != LocalConnectionState.Started)
return;
_incoming.Enqueue(packet);
}
#endregion
}
}
//PROEND

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9181ba25449c96446b966d0bd62e5813
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1 @@
1.0.0

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 3f0e4449aaa7cf0499df1847fdbd5377
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,349 @@
//PROSTART
using FishNet.Managing;
using FishNet.Managing.Logging;
using System;
using UnityEngine;
namespace FishNet.Transporting.Yak
{
[AddComponentMenu("FishNet/Transport/Yak")]
public class Yak : Transport
{
#region Private.
/// <summary>
/// Client when acting as host.
/// </summary>
private Client.ClientSocket _client;
/// <summary>
/// Server for the transport.
/// </summary>
private Server.ServerSocket _server;
#endregion
#region Const.
/// <summary>
/// Id to use for client when acting as host.
/// </summary>
internal const int CLIENT_HOST_ID = short.MaxValue;
private const int MTU = 5000;
#endregion
public override void Initialize(NetworkManager networkManager, int transportIndex)
{
base.Initialize(networkManager, transportIndex);
_client = new Client.ClientSocket();
_server = new Server.ServerSocket();
_client.Initialize(this, _server);
_server.Initialize(this, _client);
}
private void OnDestroy()
{
Shutdown();
}
#region ConnectionStates.
/// <summary>
/// Gets the IP address of a remote connection Id.
/// </summary>
/// <param name="connectionId"></param>
/// <returns></returns>
public override string GetConnectionAddress(int connectionId)
{
return String.Empty;
}
/// <summary>
/// Called when a connection state changes for the local client.
/// </summary>
public override event Action<ClientConnectionStateArgs> OnClientConnectionState;
/// <summary>
/// Called when a connection state changes for the local server.
/// </summary>
public override event Action<ServerConnectionStateArgs> OnServerConnectionState;
/// <summary>
/// Called when a connection state changes for a remote client.
/// </summary>
public override event Action<RemoteConnectionStateArgs> OnRemoteConnectionState;
/// <summary>
/// Gets the current local ConnectionState.
/// </summary>
/// <param name="server">True if getting ConnectionState for the server.</param>
public override LocalConnectionState GetConnectionState(bool server)
{
if (server)
return _server.GetLocalConnectionState();
else
return _client.GetLocalConnectionState();
}
/// <summary>
/// Gets the current ConnectionState of a remote client on the server.
/// </summary>
/// <param name="connectionId">ConnectionId to get ConnectionState for.</param>
public override RemoteConnectionState GetConnectionState(int connectionId)
{
return _server.GetConnectionState(connectionId);
}
/// <summary>
/// Handles a ConnectionStateArgs for the local client.
/// </summary>
/// <param name="connectionStateArgs"></param>
public override void HandleClientConnectionState(ClientConnectionStateArgs connectionStateArgs)
{
OnClientConnectionState?.Invoke(connectionStateArgs);
}
/// <summary>
/// Handles a ConnectionStateArgs for the local server.
/// </summary>
/// <param name="connectionStateArgs"></param>
public override void HandleServerConnectionState(ServerConnectionStateArgs connectionStateArgs)
{
OnServerConnectionState?.Invoke(connectionStateArgs);
}
/// <summary>
/// Handles a ConnectionStateArgs for a remote client.
/// </summary>
/// <param name="connectionStateArgs"></param>
public override void HandleRemoteConnectionState(RemoteConnectionStateArgs connectionStateArgs)
{
OnRemoteConnectionState?.Invoke(connectionStateArgs);
}
#endregion
#region Iterating.
/// <summary>
/// Processes data received by the socket.
/// </summary>
/// <param name="server">True to process data received on the server.</param>
public override void IterateIncoming(bool server)
{
if (server)
_server.IterateIncoming();
else
_client.IterateIncoming();
}
/// <summary>
/// Processes data to be sent by the socket.
/// </summary>
/// <param name="server">True to process data received on the server.</param>
public override void IterateOutgoing(bool server) { }
#endregion
#region ReceivedData.
/// <summary>
/// Called when client receives data.
/// </summary>
public override event Action<ClientReceivedDataArgs> OnClientReceivedData;
/// <summary>
/// Handles a ClientReceivedDataArgs.
/// </summary>
/// <param name="receivedDataArgs"></param>
public override void HandleClientReceivedDataArgs(ClientReceivedDataArgs receivedDataArgs)
{
OnClientReceivedData?.Invoke(receivedDataArgs);
}
/// <summary>
/// Called when server receives data.
/// </summary>
public override event Action<ServerReceivedDataArgs> OnServerReceivedData;
/// <summary>
/// Handles a ClientReceivedDataArgs.
/// </summary>
/// <param name="receivedDataArgs"></param>
public override void HandleServerReceivedDataArgs(ServerReceivedDataArgs receivedDataArgs)
{
OnServerReceivedData?.Invoke(receivedDataArgs);
}
#endregion
#region Sending.
/// <summary>
/// Sends to the server or all clients.
/// </summary>
/// <param name="channelId">Channel to use.</param>
/// /// <param name="segment">Data to send.</param>
public override void SendToServer(byte channelId, ArraySegment<byte> segment)
{
_client.SendToServer(channelId, segment);
}
/// <summary>
/// Sends data to a client.
/// </summary>
/// <param name="channelId"></param>
/// <param name="segment"></param>
/// <param name="connectionId"></param>
public override void SendToClient(byte channelId, ArraySegment<byte> segment, int connectionId)
{
_server.SendToClient(channelId, segment, connectionId);
}
#endregion
#region Configuration.
/// <summary>
/// Returns if the transport is a local transport.
/// While true several security checks are disabled.
/// </summary>
public override bool IsLocalTransport(int connectionId) => true;
/// <summary>
/// Returns the maximum number of clients allowed to connect to the server. If the transport does not support this method the value -1 is returned.
/// </summary>
/// <returns></returns>
public override int GetMaximumClients()
{
return short.MaxValue;
}
/// <summary>
/// Sets maximum number of clients allowed to connect to the server. If applied at runtime and clients exceed this value existing clients will stay connected but new clients may not connect.
/// </summary>
/// <param name="value"></param>
public override void SetMaximumClients(int value) { }
/// <summary>
/// Sets which address the client will connect to.
/// </summary>
/// <param name="address"></param>
public override void SetClientAddress(string address) { }
/// <summary>
/// Sets which address the server will bind to.
/// </summary>
/// <param name="address"></param>
public override void SetServerBindAddress(string address, IPAddressType addressType) { }
/// <summary>
/// Sets which port to use.
/// </summary>
/// <param name="port"></param>
public override void SetPort(ushort port) { }
#endregion
#region Start and stop.
/// <summary>
/// Starts the local server or client using configured settings.
/// </summary>
/// <param name="server">True to start server.</param>
public override bool StartConnection(bool server)
{
if (server)
return StartServer();
else
return StartClient();
}
/// <summary>
/// Stops the local server or client.
/// </summary>
/// <param name="server">True to stop server.</param>
public override bool StopConnection(bool server)
{
if (server)
return StopServer();
else
return StopClient();
}
/// <summary>
/// Stops a remote client from the server, disconnecting the client.
/// </summary>
/// <param name="connectionId">ConnectionId of the client to disconnect.</param>
/// <param name="immediately">True to abrutly stp the client socket without waiting socket thread.</param>
public override bool StopConnection(int connectionId, bool immediately)
{
return StopClient(connectionId, immediately);
}
/// <summary>
/// Stops both client and server.
/// </summary>
public override void Shutdown()
{
//Stops client then server connections.
StopConnection(false);
StopConnection(true);
}
#region Privates.
/// <summary>
/// Starts server.
/// </summary>
/// <returns>True if there were no blocks. A true response does not promise a socket will or has connected.</returns>
private bool StartServer()
{
if (_server.GetLocalConnectionState() != LocalConnectionState.Stopped)
{
if (NetworkManager.CanLog(LoggingType.Error))
Debug.LogError("Server is already running.");
return false;
}
bool result = _server.StartConnection();
return result;
}
/// <summary>
/// Stops server.
/// </summary>
private bool StopServer()
{
if (_server != null)
return _server.StopConnection();
return false;
}
/// <summary>
/// Starts the client.
/// </summary>
/// <param name="address"></param>
/// <returns>True if there were no blocks. A true response does not promise a socket will or has connected.</returns>
private bool StartClient()
{
if (_client.GetLocalConnectionState() != LocalConnectionState.Stopped)
{
if (NetworkManager.CanLog(LoggingType.Error))
Debug.LogError("Client is already running.");
return false;
}
_client.StartConnection();
return true;
}
/// <summary>
/// Stops the client.
/// </summary>
private bool StopClient()
{
if (_client != null)
return _client.StopConnection();
return false;
}
/// <summary>
/// Stops a remote client on the server.
/// </summary>
/// <param name="connectionId"></param>
/// <param name="immediately">True to abrutly stp the client socket without waiting socket thread.</param>
private bool StopClient(int connectionId, bool immediately)
{
return _server.StopConnection(connectionId);
}
#endregion
#endregion
#region Channels.
/// <summary>
/// Gets the MTU for a channel. This should take header size into consideration.
/// For example, if MTU is 1200 and a packet header for this channel is 10 in size, this method should return 1190.
/// </summary>
/// <param name="channel"></param>
/// <returns></returns>
public override int GetMTU(byte channel)
{
return MTU;
}
#endregion
}
}
//PROEND

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 91f4cf5273666764789e6f8bada05e3e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: bf9191e2e07d29749bca3a1ae44e4bc8, type: 3}
userData:
assetBundleName:
assetBundleVariant: