mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-04 21:39:49 +00:00
remove fizzy and patcher
This commit is contained in:
parent
0a6b56179e
commit
ea808fb344
@ -1,81 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Mirror.FizzySteam
|
||||
{
|
||||
public class BidirectionalDictionary<T1, T2> : IEnumerable
|
||||
{
|
||||
private readonly Dictionary<T1, T2> t1ToT2Dict = new Dictionary<T1, T2>();
|
||||
private readonly Dictionary<T2, T1> t2ToT1Dict = new Dictionary<T2, T1>();
|
||||
|
||||
public IEnumerable<T1> FirstTypes => t1ToT2Dict.Keys;
|
||||
public IEnumerable<T2> SecondTypes => t2ToT1Dict.Keys;
|
||||
|
||||
public IEnumerator GetEnumerator() => t1ToT2Dict.GetEnumerator();
|
||||
|
||||
public int Count => t1ToT2Dict.Count;
|
||||
|
||||
public void Add(T1 key, T2 value)
|
||||
{
|
||||
t1ToT2Dict[key] = value;
|
||||
t2ToT1Dict[value] = key;
|
||||
}
|
||||
|
||||
public void Add(T2 key, T1 value)
|
||||
{
|
||||
t2ToT1Dict[key] = value;
|
||||
t1ToT2Dict[value] = key;
|
||||
}
|
||||
|
||||
public T2 Get(T1 key) => t1ToT2Dict[key];
|
||||
|
||||
public T1 Get(T2 key) => t2ToT1Dict[key];
|
||||
|
||||
public bool TryGetValue(T1 key, out T2 value) => t1ToT2Dict.TryGetValue(key, out value);
|
||||
|
||||
public bool TryGetValue(T2 key, out T1 value) => t2ToT1Dict.TryGetValue(key, out value);
|
||||
|
||||
public bool Contains(T1 key) => t1ToT2Dict.ContainsKey(key);
|
||||
|
||||
public bool Contains(T2 key) => t2ToT1Dict.ContainsKey(key);
|
||||
|
||||
public void Remove(T1 key)
|
||||
{
|
||||
if (Contains(key))
|
||||
{
|
||||
var val = t1ToT2Dict[key];
|
||||
t1ToT2Dict.Remove(key);
|
||||
t2ToT1Dict.Remove(val);
|
||||
}
|
||||
}
|
||||
public void Remove(T2 key)
|
||||
{
|
||||
if (Contains(key))
|
||||
{
|
||||
var val = t2ToT1Dict[key];
|
||||
t1ToT2Dict.Remove(val);
|
||||
t2ToT1Dict.Remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
public T1 this[T2 key]
|
||||
{
|
||||
get => t2ToT1Dict[key];
|
||||
set
|
||||
{
|
||||
t2ToT1Dict[key] = value;
|
||||
t1ToT2Dict[value] = key;
|
||||
}
|
||||
}
|
||||
|
||||
public T2 this[T1 key]
|
||||
{
|
||||
get => t1ToT2Dict[key];
|
||||
set
|
||||
{
|
||||
t1ToT2Dict[key] = value;
|
||||
t2ToT1Dict[value] = key;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
using Steamworks;
|
||||
using System;
|
||||
|
||||
public class FizzyConnectionManager : ConnectionManager
|
||||
{
|
||||
public Action<IntPtr, int> ForwardMessage;
|
||||
|
||||
public override void OnMessage(IntPtr data, int size, long messageNum, long recvTime, int channel) => ForwardMessage(data, size);
|
||||
}
|
@ -1,301 +0,0 @@
|
||||
using Steamworks;
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.FizzySteam
|
||||
{
|
||||
[HelpURL("https://github.com/Chykary/FizzyFacepunch")]
|
||||
public class FizzyFacepunch : Transport
|
||||
{
|
||||
private const string STEAM_SCHEME = "steam";
|
||||
|
||||
private static IClient client;
|
||||
private static IServer server;
|
||||
|
||||
[SerializeField]
|
||||
public P2PSend[] Channels = new P2PSend[2] { P2PSend.Reliable, P2PSend.UnreliableNoDelay };
|
||||
|
||||
[Tooltip("Timeout for connecting in seconds.")]
|
||||
public int Timeout = 25;
|
||||
[Tooltip("The Steam ID for your application.")]
|
||||
public string SteamAppID = "480";
|
||||
[Tooltip("Allow or disallow P2P connections to fall back to being relayed through the Steam servers if a direct connection or NAT-traversal cannot be established.")]
|
||||
public bool AllowSteamRelay = true;
|
||||
|
||||
[Tooltip("Use SteamSockets instead of the (deprecated) SteamNetworking. This will always use Relay.")]
|
||||
public bool UseNextGenSteamNetworking = true;
|
||||
|
||||
[Tooltip("Check this if you want the transport to initialise Facepunch.")]
|
||||
public bool InitFacepunch = true;
|
||||
|
||||
[Header("Info")]
|
||||
[Tooltip("This will display your Steam User ID when you start or connect to a server.")]
|
||||
public ulong SteamUserID;
|
||||
|
||||
public Action<string> SetTransportError;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
const string fileName = "steam_appid.txt";
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
var content = File.ReadAllText(fileName);
|
||||
if (content != SteamAppID)
|
||||
{
|
||||
File.WriteAllText(fileName, SteamAppID.ToString());
|
||||
Debug.Log($"Updating {fileName}. Previous: {content}, new SteamAppID {SteamAppID}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
File.WriteAllText(fileName, SteamAppID.ToString());
|
||||
Debug.Log($"New {fileName} written with SteamAppID {SteamAppID}");
|
||||
}
|
||||
|
||||
Debug.Assert(Channels != null && Channels.Length > 0, "No channel configured for FizzySteamworks.");
|
||||
|
||||
if (InitFacepunch)
|
||||
{
|
||||
SteamClient.Init(uint.Parse(SteamAppID), true);
|
||||
}
|
||||
|
||||
Invoke(nameof(FetchSteamID), 1f);
|
||||
}
|
||||
|
||||
public override void ClientEarlyUpdate()
|
||||
{
|
||||
if (enabled && client != null && !client.Error)
|
||||
{
|
||||
client?.ReceiveData();
|
||||
}
|
||||
}
|
||||
|
||||
public override void ServerEarlyUpdate()
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
server?.ReceiveData();
|
||||
}
|
||||
}
|
||||
|
||||
public override void ClientLateUpdate()
|
||||
{
|
||||
if (enabled && client != null && !client.Error)
|
||||
{
|
||||
client?.FlushData();
|
||||
}
|
||||
}
|
||||
|
||||
public override void ServerLateUpdate()
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
server?.FlushData();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool ClientConnected() => ClientActive() && client.Connected;
|
||||
public override void ClientConnect(string address)
|
||||
{
|
||||
if (!SteamClient.IsValid)
|
||||
{
|
||||
Debug.LogError("SteamWorks not initialized. Client could not be started.");
|
||||
OnClientDisconnected.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
FetchSteamID();
|
||||
|
||||
if (ServerActive())
|
||||
{
|
||||
Debug.LogError("Transport already running as server!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ClientActive() || client.Error)
|
||||
{
|
||||
if (UseNextGenSteamNetworking)
|
||||
{
|
||||
Debug.Log($"Starting client [SteamSockets], target address {address}.");
|
||||
client = NextClient.CreateClient(this, address);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"Starting client [DEPRECATED SteamNetworking], target address {address}. Relay enabled: {AllowSteamRelay}");
|
||||
SteamNetworking.AllowP2PPacketRelay(AllowSteamRelay);
|
||||
client = LegacyClient.CreateClient(this, address);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Client already running!");
|
||||
}
|
||||
}
|
||||
|
||||
public override void ClientConnect(Uri uri)
|
||||
{
|
||||
if (uri.Scheme != STEAM_SCHEME)
|
||||
{
|
||||
throw new ArgumentException($"Invalid url {uri}, use {STEAM_SCHEME}://SteamID instead", nameof(uri));
|
||||
}
|
||||
|
||||
ClientConnect(uri.Host);
|
||||
}
|
||||
|
||||
public override void ClientSend(ArraySegment<byte> segment, int channelId)
|
||||
{
|
||||
var data = new byte[segment.Count];
|
||||
Array.Copy(segment.Array, segment.Offset, data, 0, segment.Count);
|
||||
client.Send(data, channelId);
|
||||
}
|
||||
|
||||
public override void ClientDisconnect()
|
||||
{
|
||||
if (ClientActive())
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
}
|
||||
public bool ClientActive() => client != null;
|
||||
|
||||
|
||||
public override bool ServerActive() => server != null;
|
||||
public override void ServerStart()
|
||||
{
|
||||
if (!SteamClient.IsValid)
|
||||
{
|
||||
Debug.LogError("SteamWorks not initialized. Server could not be started.");
|
||||
return;
|
||||
}
|
||||
|
||||
FetchSteamID();
|
||||
|
||||
if (ClientActive())
|
||||
{
|
||||
Debug.LogError("Transport already running as client!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ServerActive())
|
||||
{
|
||||
if (UseNextGenSteamNetworking)
|
||||
{
|
||||
Debug.Log($"Starting server [SteamSockets].");
|
||||
server = NextServer.CreateServer(this, NetworkManager.singleton.maxConnections);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"Starting server [DEPRECATED SteamNetworking]. Relay enabled: {AllowSteamRelay}");
|
||||
SteamNetworking.AllowP2PPacketRelay(AllowSteamRelay);
|
||||
server = LegacyServer.CreateServer(this, NetworkManager.singleton.maxConnections);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Server already started!");
|
||||
}
|
||||
}
|
||||
|
||||
public override Uri ServerUri()
|
||||
{
|
||||
var steamBuilder = new UriBuilder
|
||||
{
|
||||
Scheme = STEAM_SCHEME,
|
||||
Host = SteamClient.SteamId.Value.ToString()
|
||||
};
|
||||
|
||||
return steamBuilder.Uri;
|
||||
}
|
||||
|
||||
public override void ServerSend(int connectionId, ArraySegment<byte> segment, int channelId)
|
||||
{
|
||||
if (ServerActive())
|
||||
{
|
||||
var data = new byte[segment.Count];
|
||||
Array.Copy(segment.Array, segment.Offset, data, 0, segment.Count);
|
||||
server.Send(connectionId, data, channelId);
|
||||
}
|
||||
}
|
||||
public override void ServerDisconnect(int connectionId)
|
||||
{
|
||||
if (ServerActive())
|
||||
{
|
||||
server.Disconnect(connectionId);
|
||||
}
|
||||
}
|
||||
public override string ServerGetClientAddress(int connectionId) => ServerActive() ? server.ServerGetClientAddress(connectionId) : string.Empty;
|
||||
public override void ServerStop()
|
||||
{
|
||||
if (ServerActive())
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
if (server != null)
|
||||
{
|
||||
server.Shutdown();
|
||||
server = null;
|
||||
Debug.Log("Transport shut down - was server.");
|
||||
}
|
||||
|
||||
if (client != null)
|
||||
{
|
||||
client.Disconnect();
|
||||
client = null;
|
||||
Debug.Log("Transport shut down - was client.");
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetMaxPacketSize(int channelId)
|
||||
{
|
||||
if (channelId >= Channels.Length)
|
||||
{
|
||||
Debug.LogError("Channel Id exceeded configured channels! Please configure more channels.");
|
||||
return 1200;
|
||||
}
|
||||
|
||||
switch (Channels[channelId])
|
||||
{
|
||||
case P2PSend.Unreliable:
|
||||
case P2PSend.UnreliableNoDelay:
|
||||
return 1200;
|
||||
case P2PSend.Reliable:
|
||||
case P2PSend.ReliableWithBuffering:
|
||||
return 1048576;
|
||||
default:
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Available()
|
||||
{
|
||||
try
|
||||
{
|
||||
return SteamClient.IsValid;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void FetchSteamID()
|
||||
{
|
||||
if (SteamClient.IsValid)
|
||||
{
|
||||
if (UseNextGenSteamNetworking)
|
||||
{
|
||||
SteamNetworkingUtils.InitRelayNetworkAccess();
|
||||
}
|
||||
|
||||
SteamUserID = SteamClient.SteamId;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy() => Shutdown();
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<RootNamespace>Mirror.FizzySteam</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Facepunch.Steamworks" Version="2.3.3" />
|
||||
<Reference Include="../Mirror/*.dll" />
|
||||
<Reference Include="../UnityEngine/UnityEngine.CoreModule.dll" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -1,10 +0,0 @@
|
||||
using Steamworks;
|
||||
using Steamworks.Data;
|
||||
using System;
|
||||
|
||||
public class FizzySocketManager : SocketManager
|
||||
{
|
||||
public Action<Connection, IntPtr, int> ForwardMessage;
|
||||
|
||||
public override void OnMessage(Connection connection, NetIdentity identity, IntPtr data, int size, long messageNum, long recvTime, int channel) => ForwardMessage(connection, data, size);
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
namespace Mirror.FizzySteam
|
||||
{
|
||||
public interface IClient
|
||||
{
|
||||
bool Connected { get; }
|
||||
bool Error { get; }
|
||||
void ReceiveData();
|
||||
void Disconnect();
|
||||
void FlushData();
|
||||
void Send(byte[] data, int channelId);
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
namespace Mirror.FizzySteam
|
||||
{
|
||||
public interface IServer
|
||||
{
|
||||
void ReceiveData();
|
||||
void Send(int connectionId, byte[] data, int channelId);
|
||||
void Disconnect(int connectionId);
|
||||
void FlushData();
|
||||
string ServerGetClientAddress(int connectionId);
|
||||
void Shutdown();
|
||||
}
|
||||
}
|
@ -1,161 +0,0 @@
|
||||
using Steamworks;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.FizzySteam
|
||||
{
|
||||
public class LegacyClient : LegacyCommon, IClient
|
||||
{
|
||||
public bool Error { get; private set; }
|
||||
public bool Connected { get; private set; }
|
||||
|
||||
private event Action<byte[], int> OnReceivedData;
|
||||
private event Action OnConnected;
|
||||
private event Action OnDisconnected;
|
||||
|
||||
private TimeSpan ConnectionTimeout;
|
||||
|
||||
private SteamId hostSteamID = 0;
|
||||
private TaskCompletionSource<Task> connectedComplete;
|
||||
private CancellationTokenSource cancelToken;
|
||||
|
||||
private LegacyClient(FizzyFacepunch transport) : base(transport) => ConnectionTimeout = TimeSpan.FromSeconds(Math.Max(1, transport.Timeout));
|
||||
|
||||
public static LegacyClient CreateClient(FizzyFacepunch transport, string host)
|
||||
{
|
||||
var c = new LegacyClient(transport);
|
||||
|
||||
c.OnConnected += () => transport.OnClientConnected.Invoke();
|
||||
c.OnDisconnected += () => transport.OnClientDisconnected.Invoke();
|
||||
c.OnReceivedData += (data, channel) => transport.OnClientDataReceived.Invoke(new ArraySegment<byte>(data), channel);
|
||||
|
||||
if (SteamClient.IsValid)
|
||||
{
|
||||
c.Connect(host);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("SteamWorks not initialized.");
|
||||
c.OnConnectionFailed(new SteamId());
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
private async void Connect(string host)
|
||||
{
|
||||
cancelToken = new CancellationTokenSource();
|
||||
try
|
||||
{
|
||||
hostSteamID = ulong.Parse(host);
|
||||
connectedComplete = new TaskCompletionSource<Task>();
|
||||
|
||||
OnConnected += SetConnectedComplete;
|
||||
SendInternal(hostSteamID, InternalMessages.CONNECT);
|
||||
Task connectedCompleteTask = connectedComplete.Task;
|
||||
var timeOutTask = Task.Delay(ConnectionTimeout, cancelToken.Token);
|
||||
|
||||
if (await Task.WhenAny(connectedCompleteTask, timeOutTask) != connectedCompleteTask)
|
||||
{
|
||||
if (cancelToken.IsCancellationRequested)
|
||||
{
|
||||
Debug.LogError($"The connection attempt was cancelled.");
|
||||
}
|
||||
else if (timeOutTask.IsCompleted)
|
||||
{
|
||||
Debug.LogError($"Connection to {host} timed out.");
|
||||
}
|
||||
OnConnected -= SetConnectedComplete;
|
||||
Debug.LogError("Connection timed out.");
|
||||
OnConnectionFailed(hostSteamID);
|
||||
}
|
||||
|
||||
OnConnected -= SetConnectedComplete;
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
Debug.LogError($"Connection string was not in the right format. Did you enter a SteamId?");
|
||||
Error = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError(ex.Message);
|
||||
Error = true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (Error)
|
||||
{
|
||||
OnConnectionFailed(new SteamId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
Debug.LogError("Sending Disconnect message");
|
||||
SendInternal(hostSteamID, InternalMessages.DISCONNECT);
|
||||
Dispose();
|
||||
cancelToken?.Cancel();
|
||||
|
||||
WaitForClose(hostSteamID);
|
||||
}
|
||||
|
||||
private void SetConnectedComplete() => connectedComplete.SetResult(connectedComplete.Task);
|
||||
|
||||
protected override void OnReceiveData(byte[] data, SteamId clientSteamID, int channel)
|
||||
{
|
||||
if (clientSteamID != hostSteamID)
|
||||
{
|
||||
Debug.LogError("Received a message from an unknown");
|
||||
return;
|
||||
}
|
||||
|
||||
OnReceivedData.Invoke(data, channel);
|
||||
}
|
||||
|
||||
protected override void OnNewConnection(SteamId id)
|
||||
{
|
||||
if (hostSteamID == id)
|
||||
{
|
||||
SteamNetworking.AcceptP2PSessionWithUser(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("P2P Acceptance Request from unknown host ID.");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnReceiveInternalData(InternalMessages type, SteamId clientSteamID)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case InternalMessages.ACCEPT_CONNECT:
|
||||
if (!Connected)
|
||||
{
|
||||
Connected = true;
|
||||
Debug.LogError("Connection established.");
|
||||
OnConnected.Invoke();
|
||||
}
|
||||
break;
|
||||
case InternalMessages.DISCONNECT:
|
||||
if (Connected)
|
||||
{
|
||||
Connected = false;
|
||||
Debug.LogError("Disconnected.");
|
||||
OnDisconnected.Invoke();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Debug.LogError("Received unknown message type");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Send(byte[] data, int channelId) => Send(hostSteamID, data, channelId);
|
||||
protected override void OnConnectionFailed(SteamId remoteId) => OnDisconnected.Invoke();
|
||||
public void FlushData() { }
|
||||
}
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
using Steamworks;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.FizzySteam
|
||||
{
|
||||
public abstract class LegacyCommon
|
||||
{
|
||||
private readonly P2PSend[] channels;
|
||||
private int internal_ch => channels.Length;
|
||||
|
||||
protected enum InternalMessages : byte
|
||||
{
|
||||
CONNECT,
|
||||
ACCEPT_CONNECT,
|
||||
DISCONNECT
|
||||
}
|
||||
|
||||
protected readonly FizzyFacepunch transport;
|
||||
|
||||
protected LegacyCommon(FizzyFacepunch transport)
|
||||
{
|
||||
channels = transport.Channels;
|
||||
|
||||
SteamNetworking.OnP2PSessionRequest += OnNewConnection;
|
||||
SteamNetworking.OnP2PConnectionFailed += OnConnectFail;
|
||||
|
||||
this.transport = transport;
|
||||
}
|
||||
|
||||
protected void WaitForClose(SteamId cSteamID) => transport.StartCoroutine(DelayedClose(cSteamID));
|
||||
private IEnumerator DelayedClose(SteamId cSteamID)
|
||||
{
|
||||
yield return null;
|
||||
CloseP2PSessionWithUser(cSteamID);
|
||||
}
|
||||
|
||||
protected void Dispose()
|
||||
{
|
||||
SteamNetworking.OnP2PSessionRequest -= OnNewConnection;
|
||||
SteamNetworking.OnP2PConnectionFailed -= OnConnectFail;
|
||||
}
|
||||
|
||||
protected abstract void OnNewConnection(SteamId steamID);
|
||||
|
||||
private void OnConnectFail(SteamId id, P2PSessionError err)
|
||||
{
|
||||
OnConnectionFailed(id);
|
||||
CloseP2PSessionWithUser(id);
|
||||
|
||||
switch (err)
|
||||
{
|
||||
case P2PSessionError.NotRunningApp:
|
||||
throw new Exception("Connection failed: The target user is not running the same game.");
|
||||
case P2PSessionError.NoRightsToApp:
|
||||
throw new Exception("Connection failed: The local user doesn't own the app that is running.");
|
||||
case P2PSessionError.DestinationNotLoggedIn:
|
||||
throw new Exception("Connection failed: Target user isn't connected to Steam.");
|
||||
case P2PSessionError.Timeout:
|
||||
throw new Exception("Connection failed: The connection timed out because the target user didn't respond.");
|
||||
default:
|
||||
throw new Exception("Connection failed: Unknown error.");
|
||||
}
|
||||
}
|
||||
|
||||
protected bool SendInternal(SteamId target, InternalMessages type) => SteamNetworking.SendP2PPacket(target, new byte[] { (byte)type }, 1, internal_ch);
|
||||
protected void Send(SteamId host, byte[] msgBuffer, int channel) => SteamNetworking.SendP2PPacket(host, msgBuffer, msgBuffer.Length, channel, channels[Mathf.Min(channel, channels.Length - 1)]);
|
||||
private bool Receive(out SteamId clientSteamID, out byte[] receiveBuffer, int channel)
|
||||
{
|
||||
if (SteamNetworking.IsP2PPacketAvailable(channel))
|
||||
{
|
||||
var data = SteamNetworking.ReadP2PPacket(channel);
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
receiveBuffer = data.Value.Data;
|
||||
clientSteamID = data.Value.SteamId;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
receiveBuffer = null;
|
||||
clientSteamID = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void CloseP2PSessionWithUser(SteamId clientSteamID) => SteamNetworking.CloseP2PSessionWithUser(clientSteamID);
|
||||
|
||||
public void ReceiveData()
|
||||
{
|
||||
try
|
||||
{
|
||||
while (transport.enabled && Receive(out var clientSteamID, out var internalMessage, internal_ch))
|
||||
{
|
||||
if (internalMessage.Length == 1)
|
||||
{
|
||||
OnReceiveInternalData((InternalMessages)internalMessage[0], clientSteamID);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Incorrect package length on internal channel.");
|
||||
}
|
||||
}
|
||||
|
||||
for (var chNum = 0; chNum < channels.Length; chNum++)
|
||||
{
|
||||
while (transport.enabled && Receive(out var clientSteamID, out var receiveBuffer, chNum))
|
||||
{
|
||||
OnReceiveData(receiveBuffer, clientSteamID, chNum);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void OnReceiveInternalData(InternalMessages type, SteamId clientSteamID);
|
||||
protected abstract void OnReceiveData(byte[] data, SteamId clientSteamID, int channel);
|
||||
protected abstract void OnConnectionFailed(SteamId remoteId);
|
||||
}
|
||||
}
|
@ -1,164 +0,0 @@
|
||||
using Steamworks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.FizzySteam
|
||||
{
|
||||
public class LegacyServer : LegacyCommon, IServer
|
||||
{
|
||||
private event Action<int> OnConnected;
|
||||
private event Action<int, byte[], int> OnReceivedData;
|
||||
private event Action<int> OnDisconnected;
|
||||
private event Action<int, Exception> OnReceivedError;
|
||||
|
||||
private readonly BidirectionalDictionary<SteamId, int> steamToMirrorIds;
|
||||
private readonly int maxConnections;
|
||||
private int nextConnectionID;
|
||||
|
||||
public static LegacyServer CreateServer(FizzyFacepunch transport, int maxConnections)
|
||||
{
|
||||
var s = new LegacyServer(transport, maxConnections);
|
||||
|
||||
s.OnConnected += (id) => transport.OnServerConnected.Invoke(id);
|
||||
s.OnDisconnected += (id) => transport.OnServerDisconnected.Invoke(id);
|
||||
s.OnReceivedData += (id, data, channel) => transport.OnServerDataReceived.Invoke(id, new ArraySegment<byte>(data), channel);
|
||||
s.OnReceivedError += (id, exception) => transport.OnServerError.Invoke(id, exception);
|
||||
|
||||
SteamNetworking.OnP2PSessionRequest = (steamid) =>
|
||||
{
|
||||
Debug.LogError($"Incoming request from SteamId {steamid}.");
|
||||
SteamNetworking.AcceptP2PSessionWithUser(steamid);
|
||||
};
|
||||
|
||||
if (!SteamClient.IsValid)
|
||||
{
|
||||
Debug.LogError("SteamWorks not initialized.");
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
private LegacyServer(FizzyFacepunch transport, int maxConnections) : base(transport)
|
||||
{
|
||||
this.maxConnections = maxConnections;
|
||||
steamToMirrorIds = new BidirectionalDictionary<SteamId, int>();
|
||||
nextConnectionID = 1;
|
||||
}
|
||||
|
||||
protected override void OnNewConnection(SteamId id) => SteamNetworking.AcceptP2PSessionWithUser(id);
|
||||
|
||||
protected override void OnReceiveInternalData(InternalMessages type, SteamId clientSteamID)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case InternalMessages.CONNECT:
|
||||
if (steamToMirrorIds.Count >= maxConnections)
|
||||
{
|
||||
SendInternal(clientSteamID, InternalMessages.DISCONNECT);
|
||||
return;
|
||||
}
|
||||
|
||||
SendInternal(clientSteamID, InternalMessages.ACCEPT_CONNECT);
|
||||
|
||||
var connectionId = nextConnectionID++;
|
||||
steamToMirrorIds.Add(clientSteamID, connectionId);
|
||||
OnConnected.Invoke(connectionId);
|
||||
Debug.LogError($"Client with SteamID {clientSteamID} connected. Assigning connection id {connectionId}");
|
||||
break;
|
||||
case InternalMessages.DISCONNECT:
|
||||
if (steamToMirrorIds.TryGetValue(clientSteamID, out var connId))
|
||||
{
|
||||
OnDisconnected.Invoke(connId);
|
||||
CloseP2PSessionWithUser(clientSteamID);
|
||||
steamToMirrorIds.Remove(clientSteamID);
|
||||
Debug.LogError($"Client with SteamID {clientSteamID} disconnected.");
|
||||
}
|
||||
else
|
||||
{
|
||||
OnReceivedError.Invoke(-1, new Exception("ERROR Unknown SteamID while receiving disconnect message."));
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
Debug.LogError("Received unknown message type");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnReceiveData(byte[] data, SteamId clientSteamID, int channel)
|
||||
{
|
||||
if (steamToMirrorIds.TryGetValue(clientSteamID, out var connectionId))
|
||||
{
|
||||
OnReceivedData.Invoke(connectionId, data, channel);
|
||||
}
|
||||
else
|
||||
{
|
||||
CloseP2PSessionWithUser(clientSteamID);
|
||||
Debug.LogError("Data received from steam client thats not known " + clientSteamID);
|
||||
OnReceivedError.Invoke(-1, new Exception("ERROR Unknown SteamID"));
|
||||
}
|
||||
}
|
||||
|
||||
public void Disconnect(int connectionId)
|
||||
{
|
||||
if (steamToMirrorIds.TryGetValue(connectionId, out var steamID))
|
||||
{
|
||||
SendInternal(steamID, InternalMessages.DISCONNECT);
|
||||
steamToMirrorIds.Remove(connectionId);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("Trying to disconnect unknown connection id: " + connectionId);
|
||||
}
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
foreach (KeyValuePair<SteamId, int> client in steamToMirrorIds)
|
||||
{
|
||||
Disconnect(client.Value);
|
||||
WaitForClose(client.Key);
|
||||
}
|
||||
|
||||
SteamNetworking.OnP2PSessionRequest = null;
|
||||
Dispose();
|
||||
}
|
||||
|
||||
|
||||
public void Send(int connectionId, byte[] data, int channelId)
|
||||
{
|
||||
if (steamToMirrorIds.TryGetValue(connectionId, out var steamId))
|
||||
{
|
||||
Send(steamId, data, channelId);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Trying to send on unknown connection: " + connectionId);
|
||||
OnReceivedError.Invoke(connectionId, new Exception("ERROR Unknown Connection"));
|
||||
}
|
||||
}
|
||||
|
||||
public string ServerGetClientAddress(int connectionId)
|
||||
{
|
||||
if (steamToMirrorIds.TryGetValue(connectionId, out var steamId))
|
||||
{
|
||||
return steamId.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Trying to get info on unknown connection: " + connectionId);
|
||||
OnReceivedError.Invoke(connectionId, new Exception("ERROR Unknown Connection"));
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnConnectionFailed(SteamId remoteId)
|
||||
{
|
||||
var connectionId = steamToMirrorIds.TryGetValue(remoteId, out var connId) ? connId : nextConnectionID++;
|
||||
OnDisconnected.Invoke(connectionId);
|
||||
}
|
||||
|
||||
public void FlushData() { }
|
||||
}
|
||||
}
|
@ -1,193 +0,0 @@
|
||||
using Steamworks;
|
||||
using Steamworks.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.FizzySteam
|
||||
{
|
||||
public class NextClient : NextCommon, IClient
|
||||
{
|
||||
public bool Connected { get; private set; }
|
||||
public bool Error { get; private set; }
|
||||
|
||||
private TimeSpan ConnectionTimeout;
|
||||
|
||||
private event Action<byte[], int> OnReceivedData;
|
||||
private event Action OnConnected;
|
||||
private event Action OnDisconnected;
|
||||
private Action<string> SetTransportError;
|
||||
|
||||
private CancellationTokenSource cancelToken;
|
||||
private TaskCompletionSource<Task> connectedComplete;
|
||||
private SteamId hostSteamID = 0;
|
||||
private FizzyConnectionManager HostConnectionManager;
|
||||
private Connection HostConnection => HostConnectionManager.Connection;
|
||||
private readonly List<Action> BufferedData;
|
||||
|
||||
private NextClient(FizzyFacepunch transport)
|
||||
{
|
||||
ConnectionTimeout = TimeSpan.FromSeconds(Math.Max(1, transport.Timeout));
|
||||
BufferedData = new List<Action>();
|
||||
}
|
||||
|
||||
public static NextClient CreateClient(FizzyFacepunch transport, string host)
|
||||
{
|
||||
var c = new NextClient(transport);
|
||||
|
||||
c.OnConnected += () => transport.OnClientConnected.Invoke();
|
||||
c.OnDisconnected += () => transport.OnClientDisconnected.Invoke();
|
||||
c.OnReceivedData += (data, ch) => transport.OnClientDataReceived.Invoke(new ArraySegment<byte>(data), ch);
|
||||
c.SetTransportError = transport.SetTransportError;
|
||||
|
||||
if (SteamClient.IsValid)
|
||||
{
|
||||
c.Connect(host);
|
||||
}
|
||||
else
|
||||
{
|
||||
c.SetTransportError("SteamWorks not initialized");
|
||||
Debug.LogError("SteamWorks not initialized");
|
||||
c.OnConnectionFailed();
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
private async void Connect(string host)
|
||||
{
|
||||
cancelToken = new CancellationTokenSource();
|
||||
SteamNetworkingSockets.OnConnectionStatusChanged += OnConnectionStatusChanged;
|
||||
|
||||
try
|
||||
{
|
||||
hostSteamID = ulong.Parse(host);
|
||||
connectedComplete = new TaskCompletionSource<Task>();
|
||||
OnConnected += SetConnectedComplete;
|
||||
HostConnectionManager = SteamNetworkingSockets.ConnectRelay<FizzyConnectionManager>(hostSteamID);
|
||||
HostConnectionManager.ForwardMessage = OnMessageReceived;
|
||||
Task connectedCompleteTask = connectedComplete.Task;
|
||||
var timeOutTask = Task.Delay(ConnectionTimeout, cancelToken.Token);
|
||||
|
||||
if (await Task.WhenAny(connectedCompleteTask, timeOutTask) != connectedCompleteTask)
|
||||
{
|
||||
if (cancelToken.IsCancellationRequested)
|
||||
{
|
||||
SetTransportError("The connection attempt was cancelled.");
|
||||
Debug.LogError($"The connection attempt was cancelled.");
|
||||
}
|
||||
else if (timeOutTask.IsCompleted)
|
||||
{
|
||||
SetTransportError($"Connection to {host} timed out.");
|
||||
Debug.LogError($"Connection to {host} timed out.");
|
||||
}
|
||||
|
||||
OnConnected -= SetConnectedComplete;
|
||||
OnConnectionFailed();
|
||||
}
|
||||
|
||||
OnConnected -= SetConnectedComplete;
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
SetTransportError("Connection string was not in the right format. Did you enter a SteamId?");
|
||||
Debug.LogError($"Connection string was not in the right format. Did you enter a SteamId?");
|
||||
Error = true;
|
||||
OnConnectionFailed();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SetTransportError(ex.Message);
|
||||
Debug.LogError(ex.Message);
|
||||
Error = true;
|
||||
OnConnectionFailed();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (Error)
|
||||
{
|
||||
Debug.LogError("Connection failed.");
|
||||
OnConnectionFailed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMessageReceived(IntPtr dataPtr, int size)
|
||||
{
|
||||
(var data, var ch) = ProcessMessage(dataPtr, size);
|
||||
if (Connected)
|
||||
{
|
||||
OnReceivedData(data, ch);
|
||||
}
|
||||
else
|
||||
{
|
||||
BufferedData.Add(() => OnReceivedData(data, ch));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnConnectionStatusChanged(Connection conn, ConnectionInfo info)
|
||||
{
|
||||
ulong clientSteamID = info.Identity.SteamId;
|
||||
if (info.State == ConnectionState.Connected)
|
||||
{
|
||||
Connected = true;
|
||||
OnConnected.Invoke();
|
||||
Debug.LogError("Connection established.");
|
||||
|
||||
if (BufferedData.Count > 0)
|
||||
{
|
||||
Debug.LogError($"{BufferedData.Count} received before connection was established. Processing now.");
|
||||
{
|
||||
foreach (var a in BufferedData)
|
||||
{
|
||||
a();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (info.State == ConnectionState.ClosedByPeer)
|
||||
{
|
||||
SetTransportError("connection closed by peer");
|
||||
Connected = false;
|
||||
OnDisconnected.Invoke();
|
||||
Debug.LogError("Disconnected.");
|
||||
conn.Close(false, 0, "Disconnected");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Connection state changed: {info.State.ToString()}");
|
||||
}
|
||||
}
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
cancelToken?.Cancel();
|
||||
SteamNetworkingSockets.OnConnectionStatusChanged -= OnConnectionStatusChanged;
|
||||
|
||||
if (HostConnectionManager != null)
|
||||
{
|
||||
Debug.LogError("Sending Disconnect message");
|
||||
HostConnection.Close(false, 0, "Graceful disconnect");
|
||||
HostConnectionManager = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void ReceiveData() => HostConnectionManager.Receive(MAX_MESSAGES);
|
||||
|
||||
public void Send(byte[] data, int channelId)
|
||||
{
|
||||
var res = SendSocket(HostConnection, data, channelId);
|
||||
|
||||
if (res != Result.OK)
|
||||
{
|
||||
Debug.LogError($"Could not send: {res.ToString()}");
|
||||
}
|
||||
}
|
||||
|
||||
private void SetConnectedComplete() => connectedComplete.SetResult(connectedComplete.Task);
|
||||
private void OnConnectionFailed() => OnDisconnected.Invoke();
|
||||
public void FlushData() => HostConnection.Flush();
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
using Mirror;
|
||||
using Steamworks;
|
||||
using Steamworks.Data;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class NextCommon
|
||||
{
|
||||
protected const int MAX_MESSAGES = 256;
|
||||
|
||||
protected Result SendSocket(Connection conn, byte[] data, int channelId)
|
||||
{
|
||||
Array.Resize(ref data, data.Length + 1);
|
||||
data[data.Length - 1] = (byte)channelId;
|
||||
|
||||
var pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned);
|
||||
var pData = pinnedArray.AddrOfPinnedObject();
|
||||
var sendFlag = channelId == Channels.Unreliable ? SendType.Unreliable : SendType.Reliable;
|
||||
var res = conn.SendMessage(pData, data.Length, sendFlag);
|
||||
if (res != Result.OK)
|
||||
{
|
||||
Debug.LogWarning($"Send issue: {res}");
|
||||
}
|
||||
|
||||
pinnedArray.Free();
|
||||
return res;
|
||||
}
|
||||
|
||||
protected (byte[], int) ProcessMessage(IntPtr ptrs, int size)
|
||||
{
|
||||
var managedArray = new byte[size];
|
||||
Marshal.Copy(ptrs, managedArray, 0, size);
|
||||
int channel = managedArray[managedArray.Length - 1];
|
||||
Array.Resize(ref managedArray, managedArray.Length - 1);
|
||||
return (managedArray, channel);
|
||||
}
|
||||
}
|
@ -1,187 +0,0 @@
|
||||
using Steamworks;
|
||||
using Steamworks.Data;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.FizzySteam
|
||||
{
|
||||
public class NextServer : NextCommon, IServer
|
||||
{
|
||||
private event Action<int> OnConnected;
|
||||
private event Action<int, byte[], int> OnReceivedData;
|
||||
private event Action<int> OnDisconnected;
|
||||
private event Action<int, Exception> OnReceivedError;
|
||||
|
||||
private readonly BidirectionalDictionary<Connection, int> connToMirrorID;
|
||||
private readonly BidirectionalDictionary<SteamId, int> steamIDToMirrorID;
|
||||
private readonly int maxConnections;
|
||||
private int nextConnectionID;
|
||||
|
||||
private FizzySocketManager listenSocket;
|
||||
|
||||
private NextServer(int maxConnections)
|
||||
{
|
||||
this.maxConnections = maxConnections;
|
||||
connToMirrorID = new BidirectionalDictionary<Connection, int>();
|
||||
steamIDToMirrorID = new BidirectionalDictionary<SteamId, int>();
|
||||
nextConnectionID = 1;
|
||||
SteamNetworkingSockets.OnConnectionStatusChanged += OnConnectionStatusChanged;
|
||||
}
|
||||
|
||||
public static NextServer CreateServer(FizzyFacepunch transport, int maxConnections)
|
||||
{
|
||||
var s = new NextServer(maxConnections);
|
||||
|
||||
s.OnConnected += (id) => transport.OnServerConnected.Invoke(id);
|
||||
s.OnDisconnected += (id) => transport.OnServerDisconnected.Invoke(id);
|
||||
s.OnReceivedData += (id, data, ch) => transport.OnServerDataReceived.Invoke(id, new ArraySegment<byte>(data), ch);
|
||||
s.OnReceivedError += (id, exception) => transport.OnServerError.Invoke(id, exception);
|
||||
|
||||
if (!SteamClient.IsValid)
|
||||
{
|
||||
Debug.LogError("SteamWorks not initialized.");
|
||||
}
|
||||
|
||||
s.Host();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
private void Host()
|
||||
{
|
||||
listenSocket = SteamNetworkingSockets.CreateRelaySocket<FizzySocketManager>();
|
||||
listenSocket.ForwardMessage = OnMessageReceived;
|
||||
}
|
||||
|
||||
private void OnConnectionStatusChanged(Connection conn, ConnectionInfo info)
|
||||
{
|
||||
ulong clientSteamID = info.Identity.SteamId;
|
||||
if (info.State == ConnectionState.Connecting)
|
||||
{
|
||||
if (connToMirrorID.Count >= maxConnections)
|
||||
{
|
||||
Debug.LogError($"Incoming connection {clientSteamID} would exceed max connection count. Rejecting.");
|
||||
conn.Close(false, 0, "Max Connection Count");
|
||||
return;
|
||||
}
|
||||
|
||||
Result res;
|
||||
|
||||
if ((res = conn.Accept()) == Result.OK)
|
||||
{
|
||||
Debug.LogError($"Accepting connection {clientSteamID}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Connection {clientSteamID} could not be accepted: {res.ToString()}");
|
||||
}
|
||||
}
|
||||
else if (info.State == ConnectionState.Connected)
|
||||
{
|
||||
var connectionId = nextConnectionID++;
|
||||
connToMirrorID.Add(conn, connectionId);
|
||||
steamIDToMirrorID.Add(clientSteamID, connectionId);
|
||||
OnConnected.Invoke(connectionId);
|
||||
Debug.LogError($"Client with SteamID {clientSteamID} connected. Assigning connection id {connectionId}");
|
||||
}
|
||||
else if (info.State == ConnectionState.ClosedByPeer)
|
||||
{
|
||||
if (connToMirrorID.TryGetValue(conn, out var connId))
|
||||
{
|
||||
InternalDisconnect(connId, conn);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Connection {clientSteamID} state changed: {info.State.ToString()}");
|
||||
}
|
||||
}
|
||||
|
||||
private void InternalDisconnect(int connId, Connection socket)
|
||||
{
|
||||
OnDisconnected.Invoke(connId);
|
||||
socket.Close(false, 0, "Graceful disconnect");
|
||||
connToMirrorID.Remove(connId);
|
||||
steamIDToMirrorID.Remove(connId);
|
||||
Debug.LogError($"Client with SteamID {connId} disconnected.");
|
||||
}
|
||||
|
||||
public void Disconnect(int connectionId)
|
||||
{
|
||||
if (connToMirrorID.TryGetValue(connectionId, out var conn))
|
||||
{
|
||||
Debug.LogError($"Connection id {connectionId} disconnected.");
|
||||
conn.Close(false, 0, "Disconnected by server");
|
||||
steamIDToMirrorID.Remove(connectionId);
|
||||
connToMirrorID.Remove(connectionId);
|
||||
OnDisconnected(connectionId);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("Trying to disconnect unknown connection id: " + connectionId);
|
||||
}
|
||||
}
|
||||
|
||||
public void FlushData()
|
||||
{
|
||||
foreach (var conn in connToMirrorID.FirstTypes)
|
||||
{
|
||||
conn.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
public void ReceiveData() => listenSocket.Receive(MAX_MESSAGES);
|
||||
|
||||
private void OnMessageReceived(Connection conn, IntPtr dataPtr, int size)
|
||||
{
|
||||
(var data, var ch) = ProcessMessage(dataPtr, size);
|
||||
OnReceivedData(connToMirrorID[conn], data, ch);
|
||||
}
|
||||
|
||||
public void Send(int connectionId, byte[] data, int channelId)
|
||||
{
|
||||
if (connToMirrorID.TryGetValue(connectionId, out var conn))
|
||||
{
|
||||
var res = SendSocket(conn, data, channelId);
|
||||
|
||||
if (res == Result.NoConnection || res == Result.InvalidParam)
|
||||
{
|
||||
Debug.LogError($"Connection to {connectionId} was lost.");
|
||||
InternalDisconnect(connectionId, conn);
|
||||
}
|
||||
else if (res != Result.OK)
|
||||
{
|
||||
Debug.LogError($"Could not send: {res.ToString()}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Trying to send on unknown connection: " + connectionId);
|
||||
OnReceivedError.Invoke(connectionId, new Exception("ERROR Unknown Connection"));
|
||||
}
|
||||
}
|
||||
|
||||
public string ServerGetClientAddress(int connectionId)
|
||||
{
|
||||
if (steamIDToMirrorID.TryGetValue(connectionId, out var steamId))
|
||||
{
|
||||
return steamId.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Trying to get info on unknown connection: " + connectionId);
|
||||
OnReceivedError.Invoke(connectionId, new Exception("ERROR Unknown Connection"));
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
if (listenSocket != null)
|
||||
{
|
||||
SteamNetworkingSockets.OnConnectionStatusChanged -= OnConnectionStatusChanged;
|
||||
listenSocket.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
12
QSB.sln
12
QSB.sln
@ -16,10 +16,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MirrorWeaver", "MirrorWeaver\MirrorWeaver.csproj", "{DA8A467E-15BA-456C-9034-6EB80BAF1FF9}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FizzyFacepunch", "FizzyFacepunch\FizzyFacepunch.csproj", "{C533C95D-F634-4221-99F6-3E59C2A45F90}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QSBPatcher", "QSBPatcher\QSBPatcher.csproj", "{86CE49AB-487A-466A-98F3-3DCAF9BE66D3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EpicOnlineTransport", "EpicOnlineTransport\EpicOnlineTransport.csproj", "{971AA4A1-6729-40DE-AADF-2754F1E8783A}"
|
||||
EndProject
|
||||
Global
|
||||
@ -40,14 +36,6 @@ Global
|
||||
{DA8A467E-15BA-456C-9034-6EB80BAF1FF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DA8A467E-15BA-456C-9034-6EB80BAF1FF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DA8A467E-15BA-456C-9034-6EB80BAF1FF9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C533C95D-F634-4221-99F6-3E59C2A45F90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C533C95D-F634-4221-99F6-3E59C2A45F90}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C533C95D-F634-4221-99F6-3E59C2A45F90}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C533C95D-F634-4221-99F6-3E59C2A45F90}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{86CE49AB-487A-466A-98F3-3DCAF9BE66D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{86CE49AB-487A-466A-98F3-3DCAF9BE66D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{86CE49AB-487A-466A-98F3-3DCAF9BE66D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{86CE49AB-487A-466A-98F3-3DCAF9BE66D3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{971AA4A1-6729-40DE-AADF-2754F1E8783A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{971AA4A1-6729-40DE-AADF-2754F1E8783A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{971AA4A1-6729-40DE-AADF-2754F1E8783A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
|
@ -1,6 +1,5 @@
|
||||
{
|
||||
"filename": "QSB.dll",
|
||||
"patcher": "QSBPatcher.exe",
|
||||
"author": "Nebula, John, Alek, & Rai",
|
||||
"name": "Quantum Space Buddies",
|
||||
"warning": {
|
||||
|
@ -1,49 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace QSBPatcher
|
||||
{
|
||||
public static class PatchSteamFiles
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var basePath = args.Length > 0 ? args[0] : ".";
|
||||
var gamePath = AppDomain.CurrentDomain.BaseDirectory;
|
||||
|
||||
var dataPath = GetDataPath(gamePath);
|
||||
var pluginsPath = Path.Combine(dataPath, @"Plugins\x86_64");
|
||||
|
||||
var dir = new DirectoryInfo(Path.Combine(basePath, "SteamAPI"));
|
||||
var files = dir.GetFiles();
|
||||
foreach (var file in files)
|
||||
{
|
||||
var tempPath = Path.Combine(pluginsPath, file.Name);
|
||||
file.CopyTo(tempPath, true);
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetExecutableName(string gamePath)
|
||||
{
|
||||
var executableNames = new[] { "Outer Wilds.exe", "OuterWilds.exe" };
|
||||
foreach (var executableName in executableNames)
|
||||
{
|
||||
var executablePath = Path.Combine(gamePath, executableName);
|
||||
if (File.Exists(executablePath))
|
||||
{
|
||||
return Path.GetFileNameWithoutExtension(executablePath);
|
||||
}
|
||||
}
|
||||
|
||||
throw new FileNotFoundException($"Outer Wilds exe file not found in {gamePath}");
|
||||
}
|
||||
|
||||
private static string GetDataDirectoryName()
|
||||
{
|
||||
var gamePath = AppDomain.CurrentDomain.BaseDirectory;
|
||||
return $"{GetExecutableName(gamePath)}_Data";
|
||||
}
|
||||
|
||||
private static string GetDataPath(string gamePath)
|
||||
=> Path.Combine(gamePath, $"{GetDataDirectoryName()}");
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Update="SteamAPI\*">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user