disconnect with ctrl c

This commit is contained in:
JohnCorby 2025-02-24 14:08:22 -08:00
parent 8d239a41b5
commit d03ad707cd
3 changed files with 18 additions and 29 deletions

View File

@ -58,19 +58,7 @@ public class Client
} }
_transport.Log($"connecting to {address}"); _transport.Log($"connecting to {address}");
var options = new SteamNetworkingConfigValue_t[] _conn = SteamNetworkingSockets.ConnectByIPAddress(ref steamAddr, 0, new SteamNetworkingConfigValue_t[0]);
{
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) public void Send(ArraySegment<byte> segment, int channelId)

View File

@ -1,8 +1,6 @@
using HarmonyLib; using HarmonyLib;
using Steamworks; using Steamworks;
using System; using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
namespace SteamTransport; namespace SteamTransport;
@ -77,7 +75,13 @@ public static class Program
try try
{ {
while (true) var running = true;
Console.CancelKeyPress += (sender, args) =>
{
args.Cancel = true;
running = false;
};
while (running)
{ {
transport.ServerEarlyUpdate(); transport.ServerEarlyUpdate();
SteamAPI.RunCallbacks(); SteamAPI.RunCallbacks();
@ -103,15 +107,18 @@ public static class Program
try try
{ {
var stopwatch = Stopwatch.StartNew(); var running = true;
while (true) Console.CancelKeyPress += (sender, args) =>
{
args.Cancel = true;
running = false;
};
while (running)
{ {
transport.ClientEarlyUpdate(); transport.ClientEarlyUpdate();
SteamAPI.RunCallbacks(); SteamAPI.RunCallbacks();
transport.ClientLateUpdate(); transport.ClientLateUpdate();
Thread.Sleep(10); Thread.Sleep(10);
if (stopwatch.ElapsedMilliseconds > 10 * 1000) break;
} }
} }
finally finally

View File

@ -52,17 +52,11 @@ public class Server
public void Send(int connectionId, ArraySegment<byte> segment, int channelId) { } public void Send(int connectionId, ArraySegment<byte> segment, int channelId) { }
public void RecieveData() public void RecieveData() { }
{
}
public void Flush() public void Flush() { }
{
}
public void Disconnect(int connectionId) public void Disconnect(int connectionId) { }
{
}
public void Close() public void Close()
{ {