mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-21 18:40:03 +00:00
Revert "Revert "cleanup fizzyfacepunch""
This reverts commit c049b94527a16c3ae0f04c644362cf5b3f3f114b.
This commit is contained in:
parent
c049b94527
commit
f7ed57a787
@ -5,8 +5,8 @@ namespace Mirror.FizzySteam
|
|||||||
{
|
{
|
||||||
public class BidirectionalDictionary<T1, T2> : IEnumerable
|
public class BidirectionalDictionary<T1, T2> : IEnumerable
|
||||||
{
|
{
|
||||||
private Dictionary<T1, T2> t1ToT2Dict = new Dictionary<T1, T2>();
|
private readonly Dictionary<T1, T2> t1ToT2Dict = new Dictionary<T1, T2>();
|
||||||
private Dictionary<T2, T1> t2ToT1Dict = new Dictionary<T2, T1>();
|
private readonly Dictionary<T2, T1> t2ToT1Dict = new Dictionary<T2, T1>();
|
||||||
|
|
||||||
public IEnumerable<T1> FirstTypes => t1ToT2Dict.Keys;
|
public IEnumerable<T1> FirstTypes => t1ToT2Dict.Keys;
|
||||||
public IEnumerable<T2> SecondTypes => t2ToT1Dict.Keys;
|
public IEnumerable<T2> SecondTypes => t2ToT1Dict.Keys;
|
||||||
@ -43,7 +43,7 @@ namespace Mirror.FizzySteam
|
|||||||
{
|
{
|
||||||
if (Contains(key))
|
if (Contains(key))
|
||||||
{
|
{
|
||||||
T2 val = t1ToT2Dict[key];
|
var val = t1ToT2Dict[key];
|
||||||
t1ToT2Dict.Remove(key);
|
t1ToT2Dict.Remove(key);
|
||||||
t2ToT1Dict.Remove(val);
|
t2ToT1Dict.Remove(val);
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ namespace Mirror.FizzySteam
|
|||||||
{
|
{
|
||||||
if (Contains(key))
|
if (Contains(key))
|
||||||
{
|
{
|
||||||
T1 val = t2ToT1Dict[key];
|
var val = t2ToT1Dict[key];
|
||||||
t1ToT2Dict.Remove(val);
|
t1ToT2Dict.Remove(val);
|
||||||
t2ToT1Dict.Remove(key);
|
t2ToT1Dict.Remove(key);
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,5 @@ public class FizzyConnectionManager : ConnectionManager
|
|||||||
{
|
{
|
||||||
public Action<IntPtr, int> ForwardMessage;
|
public Action<IntPtr, int> ForwardMessage;
|
||||||
|
|
||||||
public override void OnMessage(IntPtr data, int size, long messageNum, long recvTime, int channel)
|
public override void OnMessage(IntPtr data, int size, long messageNum, long recvTime, int channel) => ForwardMessage(data, size);
|
||||||
{
|
|
||||||
ForwardMessage(data, size);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
using Steamworks;
|
using Steamworks;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@ -41,7 +40,7 @@ namespace Mirror.FizzySteam
|
|||||||
const string fileName = "steam_appid.txt";
|
const string fileName = "steam_appid.txt";
|
||||||
if (File.Exists(fileName))
|
if (File.Exists(fileName))
|
||||||
{
|
{
|
||||||
string content = File.ReadAllText(fileName);
|
var content = File.ReadAllText(fileName);
|
||||||
if (content != SteamAppID)
|
if (content != SteamAppID)
|
||||||
{
|
{
|
||||||
File.WriteAllText(fileName, SteamAppID.ToString());
|
File.WriteAllText(fileName, SteamAppID.ToString());
|
||||||
@ -137,14 +136,16 @@ namespace Mirror.FizzySteam
|
|||||||
public override void ClientConnect(Uri uri)
|
public override void ClientConnect(Uri uri)
|
||||||
{
|
{
|
||||||
if (uri.Scheme != STEAM_SCHEME)
|
if (uri.Scheme != STEAM_SCHEME)
|
||||||
|
{
|
||||||
throw new ArgumentException($"Invalid url {uri}, use {STEAM_SCHEME}://SteamID instead", nameof(uri));
|
throw new ArgumentException($"Invalid url {uri}, use {STEAM_SCHEME}://SteamID instead", nameof(uri));
|
||||||
|
}
|
||||||
|
|
||||||
ClientConnect(uri.Host);
|
ClientConnect(uri.Host);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ClientSend(ArraySegment<byte> segment, int channelId)
|
public override void ClientSend(ArraySegment<byte> segment, int channelId)
|
||||||
{
|
{
|
||||||
byte[] data = new byte[segment.Count];
|
var data = new byte[segment.Count];
|
||||||
Array.Copy(segment.Array, segment.Offset, data, 0, segment.Count);
|
Array.Copy(segment.Array, segment.Offset, data, 0, segment.Count);
|
||||||
client.Send(data, channelId);
|
client.Send(data, channelId);
|
||||||
}
|
}
|
||||||
@ -211,7 +212,7 @@ namespace Mirror.FizzySteam
|
|||||||
{
|
{
|
||||||
if (ServerActive())
|
if (ServerActive())
|
||||||
{
|
{
|
||||||
byte[] data = new byte[segment.Count];
|
var data = new byte[segment.Count];
|
||||||
Array.Copy(segment.Array, segment.Offset, data, 0, segment.Count);
|
Array.Copy(segment.Array, segment.Offset, data, 0, segment.Count);
|
||||||
server.Send(connectionId, data, channelId);
|
server.Send(connectionId, data, channelId);
|
||||||
}
|
}
|
||||||
@ -295,9 +296,6 @@ namespace Mirror.FizzySteam
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
private void OnDestroy() => Shutdown();
|
||||||
{
|
|
||||||
Shutdown();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,8 +6,5 @@ public class FizzySocketManager : SocketManager
|
|||||||
{
|
{
|
||||||
public Action<Connection, IntPtr, int> ForwardMessage;
|
public Action<Connection, IntPtr, int> ForwardMessage;
|
||||||
|
|
||||||
public override void OnMessage(Connection connection, NetIdentity identity, IntPtr data, int size, long messageNum, long recvTime, int channel)
|
public override void OnMessage(Connection connection, NetIdentity identity, IntPtr data, int size, long messageNum, long recvTime, int channel) => ForwardMessage(connection, data, size);
|
||||||
{
|
|
||||||
ForwardMessage(connection, data, size);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -21,14 +21,11 @@ namespace Mirror.FizzySteam
|
|||||||
private TaskCompletionSource<Task> connectedComplete;
|
private TaskCompletionSource<Task> connectedComplete;
|
||||||
private CancellationTokenSource cancelToken;
|
private CancellationTokenSource cancelToken;
|
||||||
|
|
||||||
private LegacyClient(FizzyFacepunch transport) : base(transport)
|
private LegacyClient(FizzyFacepunch transport) : base(transport) => ConnectionTimeout = TimeSpan.FromSeconds(Math.Max(1, transport.Timeout));
|
||||||
{
|
|
||||||
ConnectionTimeout = TimeSpan.FromSeconds(Math.Max(1, transport.Timeout));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static LegacyClient CreateClient(FizzyFacepunch transport, string host)
|
public static LegacyClient CreateClient(FizzyFacepunch transport, string host)
|
||||||
{
|
{
|
||||||
LegacyClient c = new LegacyClient(transport);
|
var c = new LegacyClient(transport);
|
||||||
|
|
||||||
c.OnConnected += () => transport.OnClientConnected.Invoke();
|
c.OnConnected += () => transport.OnClientConnected.Invoke();
|
||||||
c.OnDisconnected += () => transport.OnClientDisconnected.Invoke();
|
c.OnDisconnected += () => transport.OnClientDisconnected.Invoke();
|
||||||
@ -58,7 +55,7 @@ namespace Mirror.FizzySteam
|
|||||||
OnConnected += SetConnectedComplete;
|
OnConnected += SetConnectedComplete;
|
||||||
SendInternal(hostSteamID, InternalMessages.CONNECT);
|
SendInternal(hostSteamID, InternalMessages.CONNECT);
|
||||||
Task connectedCompleteTask = connectedComplete.Task;
|
Task connectedCompleteTask = connectedComplete.Task;
|
||||||
Task timeOutTask = Task.Delay(ConnectionTimeout, cancelToken.Token);
|
var timeOutTask = Task.Delay(ConnectionTimeout, cancelToken.Token);
|
||||||
|
|
||||||
if (await Task.WhenAny(connectedCompleteTask, timeOutTask) != connectedCompleteTask)
|
if (await Task.WhenAny(connectedCompleteTask, timeOutTask) != connectedCompleteTask)
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,7 @@ namespace Mirror.FizzySteam
|
|||||||
{
|
{
|
||||||
public abstract class LegacyCommon
|
public abstract class LegacyCommon
|
||||||
{
|
{
|
||||||
private P2PSend[] channels;
|
private readonly P2PSend[] channels;
|
||||||
private int internal_ch => channels.Length;
|
private int internal_ch => channels.Length;
|
||||||
|
|
||||||
protected enum InternalMessages : byte
|
protected enum InternalMessages : byte
|
||||||
@ -91,7 +91,7 @@ namespace Mirror.FizzySteam
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
while (transport.enabled && Receive(out SteamId clientSteamID, out byte[] internalMessage, internal_ch))
|
while (transport.enabled && Receive(out var clientSteamID, out var internalMessage, internal_ch))
|
||||||
{
|
{
|
||||||
if (internalMessage.Length == 1)
|
if (internalMessage.Length == 1)
|
||||||
{
|
{
|
||||||
@ -104,9 +104,9 @@ namespace Mirror.FizzySteam
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int chNum = 0; chNum < channels.Length; chNum++)
|
for (var chNum = 0; chNum < channels.Length; chNum++)
|
||||||
{
|
{
|
||||||
while (transport.enabled && Receive(out SteamId clientSteamID, out byte[] receiveBuffer, chNum))
|
while (transport.enabled && Receive(out var clientSteamID, out var receiveBuffer, chNum))
|
||||||
{
|
{
|
||||||
OnReceiveData(receiveBuffer, clientSteamID, chNum);
|
OnReceiveData(receiveBuffer, clientSteamID, chNum);
|
||||||
}
|
}
|
||||||
|
@ -12,13 +12,13 @@ namespace Mirror.FizzySteam
|
|||||||
private event Action<int> OnDisconnected;
|
private event Action<int> OnDisconnected;
|
||||||
private event Action<int, Exception> OnReceivedError;
|
private event Action<int, Exception> OnReceivedError;
|
||||||
|
|
||||||
private BidirectionalDictionary<SteamId, int> steamToMirrorIds;
|
private readonly BidirectionalDictionary<SteamId, int> steamToMirrorIds;
|
||||||
private int maxConnections;
|
private readonly int maxConnections;
|
||||||
private int nextConnectionID;
|
private int nextConnectionID;
|
||||||
|
|
||||||
public static LegacyServer CreateServer(FizzyFacepunch transport, int maxConnections)
|
public static LegacyServer CreateServer(FizzyFacepunch transport, int maxConnections)
|
||||||
{
|
{
|
||||||
LegacyServer s = new LegacyServer(transport, maxConnections);
|
var s = new LegacyServer(transport, maxConnections);
|
||||||
|
|
||||||
s.OnConnected += (id) => transport.OnServerConnected.Invoke(id);
|
s.OnConnected += (id) => transport.OnServerConnected.Invoke(id);
|
||||||
s.OnDisconnected += (id) => transport.OnServerDisconnected.Invoke(id);
|
s.OnDisconnected += (id) => transport.OnServerDisconnected.Invoke(id);
|
||||||
@ -61,13 +61,13 @@ namespace Mirror.FizzySteam
|
|||||||
|
|
||||||
SendInternal(clientSteamID, InternalMessages.ACCEPT_CONNECT);
|
SendInternal(clientSteamID, InternalMessages.ACCEPT_CONNECT);
|
||||||
|
|
||||||
int connectionId = nextConnectionID++;
|
var connectionId = nextConnectionID++;
|
||||||
steamToMirrorIds.Add(clientSteamID, connectionId);
|
steamToMirrorIds.Add(clientSteamID, connectionId);
|
||||||
OnConnected.Invoke(connectionId);
|
OnConnected.Invoke(connectionId);
|
||||||
Debug.LogError($"Client with SteamID {clientSteamID} connected. Assigning connection id {connectionId}");
|
Debug.LogError($"Client with SteamID {clientSteamID} connected. Assigning connection id {connectionId}");
|
||||||
break;
|
break;
|
||||||
case InternalMessages.DISCONNECT:
|
case InternalMessages.DISCONNECT:
|
||||||
if (steamToMirrorIds.TryGetValue(clientSteamID, out int connId))
|
if (steamToMirrorIds.TryGetValue(clientSteamID, out var connId))
|
||||||
{
|
{
|
||||||
OnDisconnected.Invoke(connId);
|
OnDisconnected.Invoke(connId);
|
||||||
CloseP2PSessionWithUser(clientSteamID);
|
CloseP2PSessionWithUser(clientSteamID);
|
||||||
@ -88,7 +88,7 @@ namespace Mirror.FizzySteam
|
|||||||
|
|
||||||
protected override void OnReceiveData(byte[] data, SteamId clientSteamID, int channel)
|
protected override void OnReceiveData(byte[] data, SteamId clientSteamID, int channel)
|
||||||
{
|
{
|
||||||
if (steamToMirrorIds.TryGetValue(clientSteamID, out int connectionId))
|
if (steamToMirrorIds.TryGetValue(clientSteamID, out var connectionId))
|
||||||
{
|
{
|
||||||
OnReceivedData.Invoke(connectionId, data, channel);
|
OnReceivedData.Invoke(connectionId, data, channel);
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ namespace Mirror.FizzySteam
|
|||||||
|
|
||||||
public void Disconnect(int connectionId)
|
public void Disconnect(int connectionId)
|
||||||
{
|
{
|
||||||
if (steamToMirrorIds.TryGetValue(connectionId, out SteamId steamID))
|
if (steamToMirrorIds.TryGetValue(connectionId, out var steamID))
|
||||||
{
|
{
|
||||||
SendInternal(steamID, InternalMessages.DISCONNECT);
|
SendInternal(steamID, InternalMessages.DISCONNECT);
|
||||||
steamToMirrorIds.Remove(connectionId);
|
steamToMirrorIds.Remove(connectionId);
|
||||||
@ -128,7 +128,7 @@ namespace Mirror.FizzySteam
|
|||||||
|
|
||||||
public void Send(int connectionId, byte[] data, int channelId)
|
public void Send(int connectionId, byte[] data, int channelId)
|
||||||
{
|
{
|
||||||
if (steamToMirrorIds.TryGetValue(connectionId, out SteamId steamId))
|
if (steamToMirrorIds.TryGetValue(connectionId, out var steamId))
|
||||||
{
|
{
|
||||||
Send(steamId, data, channelId);
|
Send(steamId, data, channelId);
|
||||||
}
|
}
|
||||||
@ -141,7 +141,7 @@ namespace Mirror.FizzySteam
|
|||||||
|
|
||||||
public string ServerGetClientAddress(int connectionId)
|
public string ServerGetClientAddress(int connectionId)
|
||||||
{
|
{
|
||||||
if (steamToMirrorIds.TryGetValue(connectionId, out SteamId steamId))
|
if (steamToMirrorIds.TryGetValue(connectionId, out var steamId))
|
||||||
{
|
{
|
||||||
return steamId.ToString();
|
return steamId.ToString();
|
||||||
}
|
}
|
||||||
@ -155,7 +155,7 @@ namespace Mirror.FizzySteam
|
|||||||
|
|
||||||
protected override void OnConnectionFailed(SteamId remoteId)
|
protected override void OnConnectionFailed(SteamId remoteId)
|
||||||
{
|
{
|
||||||
int connectionId = steamToMirrorIds.TryGetValue(remoteId, out int connId) ? connId : nextConnectionID++;
|
var connectionId = steamToMirrorIds.TryGetValue(remoteId, out var connId) ? connId : nextConnectionID++;
|
||||||
OnDisconnected.Invoke(connectionId);
|
OnDisconnected.Invoke(connectionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ namespace Mirror.FizzySteam
|
|||||||
private SteamId hostSteamID = 0;
|
private SteamId hostSteamID = 0;
|
||||||
private FizzyConnectionManager HostConnectionManager;
|
private FizzyConnectionManager HostConnectionManager;
|
||||||
private Connection HostConnection => HostConnectionManager.Connection;
|
private Connection HostConnection => HostConnectionManager.Connection;
|
||||||
private List<Action> BufferedData;
|
private readonly List<Action> BufferedData;
|
||||||
|
|
||||||
private NextClient(FizzyFacepunch transport)
|
private NextClient(FizzyFacepunch transport)
|
||||||
{
|
{
|
||||||
@ -35,7 +35,7 @@ namespace Mirror.FizzySteam
|
|||||||
|
|
||||||
public static NextClient CreateClient(FizzyFacepunch transport, string host)
|
public static NextClient CreateClient(FizzyFacepunch transport, string host)
|
||||||
{
|
{
|
||||||
NextClient c = new NextClient(transport);
|
var c = new NextClient(transport);
|
||||||
|
|
||||||
c.OnConnected += () => transport.OnClientConnected.Invoke();
|
c.OnConnected += () => transport.OnClientConnected.Invoke();
|
||||||
c.OnDisconnected += () => transport.OnClientDisconnected.Invoke();
|
c.OnDisconnected += () => transport.OnClientDisconnected.Invoke();
|
||||||
@ -63,13 +63,13 @@ namespace Mirror.FizzySteam
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
hostSteamID = UInt64.Parse(host);
|
hostSteamID = ulong.Parse(host);
|
||||||
connectedComplete = new TaskCompletionSource<Task>();
|
connectedComplete = new TaskCompletionSource<Task>();
|
||||||
OnConnected += SetConnectedComplete;
|
OnConnected += SetConnectedComplete;
|
||||||
HostConnectionManager = SteamNetworkingSockets.ConnectRelay<FizzyConnectionManager>(hostSteamID);
|
HostConnectionManager = SteamNetworkingSockets.ConnectRelay<FizzyConnectionManager>(hostSteamID);
|
||||||
HostConnectionManager.ForwardMessage = OnMessageReceived;
|
HostConnectionManager.ForwardMessage = OnMessageReceived;
|
||||||
Task connectedCompleteTask = connectedComplete.Task;
|
Task connectedCompleteTask = connectedComplete.Task;
|
||||||
Task timeOutTask = Task.Delay(ConnectionTimeout, cancelToken.Token);
|
var timeOutTask = Task.Delay(ConnectionTimeout, cancelToken.Token);
|
||||||
|
|
||||||
if (await Task.WhenAny(connectedCompleteTask, timeOutTask) != connectedCompleteTask)
|
if (await Task.WhenAny(connectedCompleteTask, timeOutTask) != connectedCompleteTask)
|
||||||
{
|
{
|
||||||
@ -116,7 +116,7 @@ namespace Mirror.FizzySteam
|
|||||||
|
|
||||||
private void OnMessageReceived(IntPtr dataPtr, int size)
|
private void OnMessageReceived(IntPtr dataPtr, int size)
|
||||||
{
|
{
|
||||||
(byte[] data, int ch) = ProcessMessage(dataPtr, size);
|
(var data, var ch) = ProcessMessage(dataPtr, size);
|
||||||
if (Connected)
|
if (Connected)
|
||||||
{
|
{
|
||||||
OnReceivedData(data, ch);
|
OnReceivedData(data, ch);
|
||||||
@ -140,7 +140,7 @@ namespace Mirror.FizzySteam
|
|||||||
{
|
{
|
||||||
Debug.LogError($"{BufferedData.Count} received before connection was established. Processing now.");
|
Debug.LogError($"{BufferedData.Count} received before connection was established. Processing now.");
|
||||||
{
|
{
|
||||||
foreach (Action a in BufferedData)
|
foreach (var a in BufferedData)
|
||||||
{
|
{
|
||||||
a();
|
a();
|
||||||
}
|
}
|
||||||
@ -174,14 +174,11 @@ namespace Mirror.FizzySteam
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReceiveData()
|
public void ReceiveData() => HostConnectionManager.Receive(MAX_MESSAGES);
|
||||||
{
|
|
||||||
HostConnectionManager.Receive(MAX_MESSAGES);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Send(byte[] data, int channelId)
|
public void Send(byte[] data, int channelId)
|
||||||
{
|
{
|
||||||
Result res = SendSocket(HostConnection, data, channelId);
|
var res = SendSocket(HostConnection, data, channelId);
|
||||||
|
|
||||||
if (res != Result.OK)
|
if (res != Result.OK)
|
||||||
{
|
{
|
||||||
@ -191,9 +188,6 @@ namespace Mirror.FizzySteam
|
|||||||
|
|
||||||
private void SetConnectedComplete() => connectedComplete.SetResult(connectedComplete.Task);
|
private void SetConnectedComplete() => connectedComplete.SetResult(connectedComplete.Task);
|
||||||
private void OnConnectionFailed() => OnDisconnected.Invoke();
|
private void OnConnectionFailed() => OnDisconnected.Invoke();
|
||||||
public void FlushData()
|
public void FlushData() => HostConnection.Flush();
|
||||||
{
|
|
||||||
HostConnection.Flush();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,10 +14,10 @@ public abstract class NextCommon
|
|||||||
Array.Resize(ref data, data.Length + 1);
|
Array.Resize(ref data, data.Length + 1);
|
||||||
data[data.Length - 1] = (byte)channelId;
|
data[data.Length - 1] = (byte)channelId;
|
||||||
|
|
||||||
GCHandle pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned);
|
var pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned);
|
||||||
IntPtr pData = pinnedArray.AddrOfPinnedObject();
|
var pData = pinnedArray.AddrOfPinnedObject();
|
||||||
SendType sendFlag = channelId == Channels.Unreliable ? SendType.Unreliable : SendType.Reliable;
|
var sendFlag = channelId == Channels.Unreliable ? SendType.Unreliable : SendType.Reliable;
|
||||||
Result res = conn.SendMessage(pData, data.Length, sendFlag);
|
var res = conn.SendMessage(pData, data.Length, sendFlag);
|
||||||
if (res != Result.OK)
|
if (res != Result.OK)
|
||||||
{
|
{
|
||||||
Debug.LogWarning($"Send issue: {res}");
|
Debug.LogWarning($"Send issue: {res}");
|
||||||
@ -29,7 +29,7 @@ public abstract class NextCommon
|
|||||||
|
|
||||||
protected (byte[], int) ProcessMessage(IntPtr ptrs, int size)
|
protected (byte[], int) ProcessMessage(IntPtr ptrs, int size)
|
||||||
{
|
{
|
||||||
byte[] managedArray = new byte[size];
|
var managedArray = new byte[size];
|
||||||
Marshal.Copy(ptrs, managedArray, 0, size);
|
Marshal.Copy(ptrs, managedArray, 0, size);
|
||||||
int channel = managedArray[managedArray.Length - 1];
|
int channel = managedArray[managedArray.Length - 1];
|
||||||
Array.Resize(ref managedArray, managedArray.Length - 1);
|
Array.Resize(ref managedArray, managedArray.Length - 1);
|
||||||
|
@ -12,9 +12,9 @@ namespace Mirror.FizzySteam
|
|||||||
private event Action<int> OnDisconnected;
|
private event Action<int> OnDisconnected;
|
||||||
private event Action<int, Exception> OnReceivedError;
|
private event Action<int, Exception> OnReceivedError;
|
||||||
|
|
||||||
private BidirectionalDictionary<Connection, int> connToMirrorID;
|
private readonly BidirectionalDictionary<Connection, int> connToMirrorID;
|
||||||
private BidirectionalDictionary<SteamId, int> steamIDToMirrorID;
|
private readonly BidirectionalDictionary<SteamId, int> steamIDToMirrorID;
|
||||||
private int maxConnections;
|
private readonly int maxConnections;
|
||||||
private int nextConnectionID;
|
private int nextConnectionID;
|
||||||
|
|
||||||
private FizzySocketManager listenSocket;
|
private FizzySocketManager listenSocket;
|
||||||
@ -30,7 +30,7 @@ namespace Mirror.FizzySteam
|
|||||||
|
|
||||||
public static NextServer CreateServer(FizzyFacepunch transport, int maxConnections)
|
public static NextServer CreateServer(FizzyFacepunch transport, int maxConnections)
|
||||||
{
|
{
|
||||||
NextServer s = new NextServer(maxConnections);
|
var s = new NextServer(maxConnections);
|
||||||
|
|
||||||
s.OnConnected += (id) => transport.OnServerConnected.Invoke(id);
|
s.OnConnected += (id) => transport.OnServerConnected.Invoke(id);
|
||||||
s.OnDisconnected += (id) => transport.OnServerDisconnected.Invoke(id);
|
s.OnDisconnected += (id) => transport.OnServerDisconnected.Invoke(id);
|
||||||
@ -78,7 +78,7 @@ namespace Mirror.FizzySteam
|
|||||||
}
|
}
|
||||||
else if (info.State == ConnectionState.Connected)
|
else if (info.State == ConnectionState.Connected)
|
||||||
{
|
{
|
||||||
int connectionId = nextConnectionID++;
|
var connectionId = nextConnectionID++;
|
||||||
connToMirrorID.Add(conn, connectionId);
|
connToMirrorID.Add(conn, connectionId);
|
||||||
steamIDToMirrorID.Add(clientSteamID, connectionId);
|
steamIDToMirrorID.Add(clientSteamID, connectionId);
|
||||||
OnConnected.Invoke(connectionId);
|
OnConnected.Invoke(connectionId);
|
||||||
@ -86,7 +86,7 @@ namespace Mirror.FizzySteam
|
|||||||
}
|
}
|
||||||
else if (info.State == ConnectionState.ClosedByPeer)
|
else if (info.State == ConnectionState.ClosedByPeer)
|
||||||
{
|
{
|
||||||
if (connToMirrorID.TryGetValue(conn, out int connId))
|
if (connToMirrorID.TryGetValue(conn, out var connId))
|
||||||
{
|
{
|
||||||
InternalDisconnect(connId, conn);
|
InternalDisconnect(connId, conn);
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ namespace Mirror.FizzySteam
|
|||||||
|
|
||||||
public void Disconnect(int connectionId)
|
public void Disconnect(int connectionId)
|
||||||
{
|
{
|
||||||
if (connToMirrorID.TryGetValue(connectionId, out Connection conn))
|
if (connToMirrorID.TryGetValue(connectionId, out var conn))
|
||||||
{
|
{
|
||||||
Debug.LogError($"Connection id {connectionId} disconnected.");
|
Debug.LogError($"Connection id {connectionId} disconnected.");
|
||||||
conn.Close(false, 0, "Disconnected by server");
|
conn.Close(false, 0, "Disconnected by server");
|
||||||
@ -124,28 +124,25 @@ namespace Mirror.FizzySteam
|
|||||||
|
|
||||||
public void FlushData()
|
public void FlushData()
|
||||||
{
|
{
|
||||||
foreach (Connection conn in connToMirrorID.FirstTypes)
|
foreach (var conn in connToMirrorID.FirstTypes)
|
||||||
{
|
{
|
||||||
conn.Flush();
|
conn.Flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReceiveData()
|
public void ReceiveData() => listenSocket.Receive(MAX_MESSAGES);
|
||||||
{
|
|
||||||
listenSocket.Receive(MAX_MESSAGES);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnMessageReceived(Connection conn, IntPtr dataPtr, int size)
|
private void OnMessageReceived(Connection conn, IntPtr dataPtr, int size)
|
||||||
{
|
{
|
||||||
(byte[] data, int ch) = ProcessMessage(dataPtr, size);
|
(var data, var ch) = ProcessMessage(dataPtr, size);
|
||||||
OnReceivedData(connToMirrorID[conn], data, ch);
|
OnReceivedData(connToMirrorID[conn], data, ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Send(int connectionId, byte[] data, int channelId)
|
public void Send(int connectionId, byte[] data, int channelId)
|
||||||
{
|
{
|
||||||
if (connToMirrorID.TryGetValue(connectionId, out Connection conn))
|
if (connToMirrorID.TryGetValue(connectionId, out var conn))
|
||||||
{
|
{
|
||||||
Result res = SendSocket(conn, data, channelId);
|
var res = SendSocket(conn, data, channelId);
|
||||||
|
|
||||||
if (res == Result.NoConnection || res == Result.InvalidParam)
|
if (res == Result.NoConnection || res == Result.InvalidParam)
|
||||||
{
|
{
|
||||||
@ -166,7 +163,7 @@ namespace Mirror.FizzySteam
|
|||||||
|
|
||||||
public string ServerGetClientAddress(int connectionId)
|
public string ServerGetClientAddress(int connectionId)
|
||||||
{
|
{
|
||||||
if (steamIDToMirrorID.TryGetValue(connectionId, out SteamId steamId))
|
if (steamIDToMirrorID.TryGetValue(connectionId, out var steamId))
|
||||||
{
|
{
|
||||||
return steamId.ToString();
|
return steamId.ToString();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user