public async Task SetupAsync() { ConfigureServices(); Logger logger = ServiceProvider.GetService <ILoggerProvider>() .GetLogger("Server"); logger.LogInformation("Starting server"); ServerConfig config = ServiceProvider.GetService <IConfigProvider>().Config; SteamServerInit init = new SteamServerInit { GamePort = config.Port, Secure = true, QueryPort = (ushort)(config.Port + 1), SteamPort = (ushort)(config.Port + 2), VersionString = "0.1", DedicatedServer = true, IpAddress = IPAddress.Parse(config.IpAddress), ModDir = "pf", GameDescription = "Pony Forest" }; try { SteamServer.Init(1026040, init); SteamServer.ServerName = config.Name; SteamServer.AutomaticHeartbeats = true; SteamServer.DedicatedServer = true; SteamServer.Passworded = false; SteamServer.MaxPlayers = config.MaxPlayers; SteamServer.LogOnAnonymous(); NetAddress address = NetAddress.From(config.IpAddress, config.Port); _serverCore = SteamNetworkingSockets.CreateNormalSocket <ServerCore>(address); } catch (Exception e) { logger.LogFailure($"Can't start server: {Environment.NewLine + e}"); } try { IMessageRouter messageRouter = ServiceProvider.GetService <IMessageRouter>(); logger.LogInformation("Server started"); _serverCore.OnMessageReceived = messageRouter.Route; IMessageListener messageListener = ServiceProvider.GetService <IMessageListener>(); await messageListener.StartListening(_serverCore); } catch (Exception e) { logger.LogFailure($"Error while running server: {Environment.NewLine + e}"); } }
public ConnectionManager JoinSession(string ip, string port) { Client = SteamNetworkingSockets.ConnectNormal <MaydayClient>(NetAddress.From(ip, ushort.Parse(port))); ((MaydayClient)Client).NetworkManager = this; return(Client); }
/// <summary> /// Return info about the FakeIP and port that we have been assigned, if any. /// /// </summary> public static Result GetFakeIP(int fakePortIndex, out NetAddress address) { var pInfo = default(SteamNetworkingFakeIPResult_t); Internal.GetFakeIP(0, ref pInfo); address = NetAddress.From(Utility.Int32ToIp(pInfo.IP), pInfo.Ports[fakePortIndex]); return(pInfo.Result); }
public override void ClientConnect(string address) { if (useRelay) { Client = SteamNetworkingSockets.ConnectRelay <ClientManager>(targetSteamId); } else { Client = SteamNetworkingSockets.ConnectNormal <ClientManager>(NetAddress.From(address, port)); } }
public void NetAddressTest() { { var n = NetAddress.From("127.0.0.1", 12445); Assert.AreEqual(n.ToString(), "127.0.0.1:12445"); } { var n = NetAddress.AnyIp(5543); Assert.AreEqual(n.ToString(), "[::]:5543"); } }
private static void FakeIPResult(SteamNetworkingFakeIPResult_t data) { foreach (var port in data.Ports) { if (port == 0) { continue; } var address = NetAddress.From(Utility.Int32ToIp(data.IP), port); OnFakeIPResult?.Invoke(address); } }
public Client(SteamSockets transport, string address, SteamSockets.SocketMode socketMode) { if (transport.debug) { Debug.Log($"SteamSockets.Client: Starting"); } if (transport.debug) { Debug.Log($"Creating connection manager ({socketMode})"); } switch (socketMode) { case SteamSockets.SocketMode.P2P: if (transport.debug) { Debug.Log($"Connecting to P2P server steamid {address}"); } SteamId connectSteamId = new SteamId(); connectSteamId.Value = Convert.ToUInt64(address); connectionManager = SteamNetworkingSockets.ConnectRelay <FPConnectionManager>(connectSteamId); break; case SteamSockets.SocketMode.UDP: string[] ipPort = address.Split(':'); NetAddress netAddress = NetAddress.From(ipPort[0], Convert.ToUInt16(ipPort[1])); if (transport.debug) { Debug.Log($"Connecting to UDP server {netAddress}"); } connectionManager = SteamNetworkingSockets.ConnectNormal <FPConnectionManager>(netAddress); break; } connectionManager.transport = transport; if (transport.debug) { Debug.Log($"Connecting: {connectionManager.Connecting} Connected: {connectionManager.Connected}"); } }
public async Task NormalEndtoEnd() { SteamNetworkingUtils.DebugLevel = NetDebugOutput.Everything; SteamNetworkingUtils.OnDebugOutput += DebugOutput; // For some reason giving steam a couple of seconds here // seems to prevent it returning null connections from ConnectNormal await Task.Delay(2000); // // Start the server // Console.WriteLine("CreateNormalSocket"); var socket = SteamNetworkingSockets.CreateNormalSocket <TestSocketInterface>(NetAddress.AnyIp(12445)); var server = socket.RunAsync(); // // Start the client // Console.WriteLine("ConnectNormal"); var connection = SteamNetworkingSockets.ConnectNormal <TestConnectionInterface>(NetAddress.From("127.0.0.1", 12445)); var client = connection.RunAsync(); await Task.WhenAll(server, client); }
public async Task NormalEndtoEnd() { var socket = SteamNetworkingSockets.CreateNormalSocket <TestSocketInterface>(NetAddress.AnyIp(12445)); var server = socket.RunAsync(); await Task.Delay(1000); var connection = SteamNetworkingSockets.ConnectNormal <TestConnectionInterface>(NetAddress.From(System.Net.IPAddress.Parse("127.0.0.1"), 12445)); var client = connection.RunAsync(); await Task.WhenAll(server, client); }