mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-03-10 07:14:27 +00:00
client open and close test
This commit is contained in:
parent
4ebf9ea5ae
commit
8d239a41b5
@ -1,7 +1,7 @@
|
||||
using HarmonyLib;
|
||||
using Mirror;
|
||||
using Mirror;
|
||||
using Steamworks;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SteamTransport;
|
||||
|
||||
@ -58,7 +58,19 @@ public class Client
|
||||
}
|
||||
|
||||
_transport.Log($"connecting to {address}");
|
||||
_conn = SteamNetworkingSockets.ConnectByIPAddress(ref steamAddr, 0, new SteamNetworkingConfigValue_t[0]);
|
||||
var options = new SteamNetworkingConfigValue_t[]
|
||||
{
|
||||
new SteamNetworkingConfigValue_t
|
||||
{
|
||||
m_eValue = ESteamNetworkingConfigValue.k_ESteamNetworkingConfig_IP_AllowWithoutAuth,
|
||||
m_eDataType = ESteamNetworkingConfigDataType.k_ESteamNetworkingConfig_Int32,
|
||||
m_val = new SteamNetworkingConfigValue_t.OptionValue
|
||||
{
|
||||
m_int32 = 1,
|
||||
}
|
||||
}
|
||||
};
|
||||
_conn = SteamNetworkingSockets.ConnectByIPAddress(ref steamAddr, options.Length, options);
|
||||
}
|
||||
|
||||
public void Send(ArraySegment<byte> segment, int channelId)
|
||||
@ -77,10 +89,10 @@ public class Client
|
||||
unsafe
|
||||
{
|
||||
var msg = *(SteamNetworkingMessage_t*)ppOutMessage; // probably not gonna work
|
||||
var data = new ArraySegment<byte>(new Span<byte>((byte*)msg.m_pData, msg.m_cbSize).ToArray());
|
||||
var data = new byte[msg.m_cbSize];
|
||||
Marshal.Copy(msg.m_pData, data, 0, data.Length);
|
||||
var channel = Util.SendFlag2MirrorChannel(msg.m_nFlags);
|
||||
_transport.Log($"received data {data.Join()}");
|
||||
_transport.OnClientDataReceived(data, channel);
|
||||
_transport.OnClientDataReceived(new ArraySegment<byte>(data), channel);
|
||||
msg.Release();
|
||||
}
|
||||
}
|
||||
@ -93,7 +105,7 @@ public class Client
|
||||
|
||||
public void Close()
|
||||
{
|
||||
// SteamNetworkingSockets.CloseConnection(_conn, )
|
||||
SteamNetworkingSockets.CloseConnection(_conn, 0, "client closed connection", false);
|
||||
|
||||
_onStatusChanged.Dispose();
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
using Steamworks;
|
||||
using HarmonyLib;
|
||||
using Steamworks;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
|
||||
@ -78,6 +80,7 @@ public static class Program
|
||||
while (true)
|
||||
{
|
||||
transport.ServerEarlyUpdate();
|
||||
SteamAPI.RunCallbacks();
|
||||
transport.ServerLateUpdate();
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
@ -92,17 +95,23 @@ public static class Program
|
||||
{
|
||||
var transport = new SteamTransport();
|
||||
transport.Log = Console.WriteLine;
|
||||
transport.OnClientError = (error, s) => Console.Error.WriteLine(s);
|
||||
transport.OnClientDataReceived = (bytes, i) => Console.WriteLine($"recv {bytes.Join()}");
|
||||
transport.UseLocalhost = true;
|
||||
|
||||
transport.ClientConnect("unused");
|
||||
|
||||
try
|
||||
{
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
while (true)
|
||||
{
|
||||
transport.ClientEarlyUpdate();
|
||||
SteamAPI.RunCallbacks();
|
||||
transport.ClientLateUpdate();
|
||||
Thread.Sleep(10);
|
||||
|
||||
if (stopwatch.ElapsedMilliseconds > 10 * 1000) break;
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
@ -28,6 +28,11 @@ public class Server
|
||||
// ignore max connections for now
|
||||
SteamNetworkingSockets.AcceptConnection(t.m_hConn);
|
||||
break;
|
||||
case ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_Connected:
|
||||
break;
|
||||
case ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_ClosedByPeer:
|
||||
case ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_ProblemDetectedLocally:
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
|
||||
<OutputType>Exe</OutputType>
|
||||
<AssemblyTitle>Steam Transport</AssemblyTitle>
|
||||
<Product>Steam Transport</Product>
|
||||
|
BIN
SteamTransport/standaloneLibs/0Harmony.dll
Normal file
BIN
SteamTransport/standaloneLibs/0Harmony.dll
Normal file
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user