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");
            }
        }
 public override void ServerStart()
 {
     if (useRelay)
     {
         Server = SteamNetworkingSockets.CreateRelaySocket <ServerManager>();
     }
     else
     {
         Server = SteamNetworkingSockets.CreateNormalSocket <ServerManager>(NetAddress.AnyIp(port));
     }
     serverActive = true;
 }
Beispiel #3
0
        public SocketManager CreateSession(string port)
        {
            var netAddress = NetAddress.AnyIp(ushort.Parse(port));

            Server = SteamNetworkingSockets.CreateNormalSocket <MaydayServer>(netAddress);

            ((MaydayServer)Server).NetworkManager = this;

            SteamMatchmaking.OnLobbyCreated += (result, lobby) => OnLobbyCreated(result, lobby, port);
            SteamMatchmaking.CreateLobbyAsync();

            return(Server);
        }
    private IEnumerator StartServerRoutine()
    {
        yield return(new WaitUntil(() => SteamServer.IsValid));

        if (useRelay)
        {
            Server = SteamNetworkingSockets.CreateRelaySocket <ServerInterface>();
        }
        else
        {
            Server = SteamNetworkingSockets.CreateNormalSocket <ServerInterface>(NetAddress.AnyIp(port));
        }
        serverActive = true;
    }
Beispiel #5
0
        private async void StartSteamServer(CancellationTokenSource source)
        {
            var token = source.Token;

            void InitializeSteamServer()
            {
                const int GAME_PORT  = 30001;
                const int APP_ID     = 480;
                const int QUERY_PORT = GAME_PORT + 1;

                Console.WriteLine($"########### STARTING STEAM SREVER ##################");
                SteamServerInit serverInit = new SteamServerInit("TestInitSteamServer", "TestInitSteamServer TEST")
                {
                    GamePort      = GAME_PORT,
                    Secure        = true,
                    QueryPort     = QUERY_PORT,
                    VersionString = "0.0.0.1"
                };

                try
                {
                    //SteamServer.DedicatedServer = true;

                    SteamServer.OnCallbackException          += OnCallbackException;
                    SteamServer.OnSteamServerConnectFailure  += OnSteamServerConnectFailure;
                    SteamServer.OnSteamServersConnected      += OnSteamServersConnected;
                    SteamServer.OnSteamServersDisconnected   += OnSteamServersDisconnected;
                    SteamServer.OnValidateAuthTicketResponse += OnValidateAuthTicketResponse;
                    SteamServer.Init(APP_ID, serverInit);
                    SteamServer.DedicatedServer = true;
                    SteamServer.LogOnAnonymous();
                    SocketInterface socket = SteamNetworkingSockets.CreateNormalSocket <SocketInterface>(NetAddress.AnyIp(GAME_PORT));
                }
                catch (System.Exception e)
                {
                    Console.WriteLine($"#### SteamServer e:{e.Message}\n:{e.StackTrace}");
                    // Couldn't init for some reason (dll errors, blocked ports)
                    SteamServer.Shutdown();
                }
                Console.WriteLine($"#### SteamServer IsValid:{SteamServer.IsValid} IsLogedOn:{SteamServer.LoggedOn}");
            }

            void UpdateSteamServerCallbacks()
            {
                const long UPDATE_INTERVAL_IN_MS = 1000;
                long       lastTimeInMs          = long.MinValue;
                long       currentTimeInMs;

                try
                {
                    while (true)
                    {
                        token.ThrowIfCancellationRequested();

                        if (lastTimeInMs + UPDATE_INTERVAL_IN_MS < (currentTimeInMs = DateTime.UtcNow.ToTotalMillisUTC()))
                        {
                            lastTimeInMs = currentTimeInMs;
                            Console.WriteLine($"\tSteamServer Updating {lastTimeInMs}");
                            SteamServer.RunCallbacks();
                        }
                    }
                }
                finally
                {
                    SteamServer.Shutdown();
                    Console.WriteLine($"#### SteamServer Shutdown");
                }
            }

            await Task.Run(() => InitializeSteamServer());

            await Task.Factory.StartNew((x) => UpdateSteamServerCallbacks(), token, TaskCreationOptions.LongRunning);
        }
        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);
        }
Beispiel #8
0
        public Server(
            SteamSockets transport,
            int maxConnections,
            uint steamAppID,
            SteamServerInit init,
            SteamSockets.SocketMode socketMode,
            string serverName
            )
        {
            if (transport.debug)
            {
                Debug.Log($"SteamSockets.Server: Starting");
            }
            networkPort = init.GamePort;
            SteamServer.Init(steamAppID, init, false);
            SteamServer.ServerName = serverName;
            if (String.IsNullOrEmpty(transport.gsToken))
            {
                Debug.Log($"No gsToken provided, logging on anonymously");
                SteamServer.LogOnAnonymous();
            }
            else
            {
                Debug.Log($"Logging on with gstoken");
                // Todo: Add SteamServer.LogOn(gsToken); when Facepunch.Steamworks supports it
            }
            if (transport.debug)
            {
                Debug.Log($"Creating socket manager ({socketMode})");
            }
            switch (socketMode)
            {
            case SteamSockets.SocketMode.P2P:
                socketManager = SteamNetworkingSockets.CreateRelaySocket <FPSocketManager>();
                break;

            case SteamSockets.SocketMode.UDP:
                socketManager = SteamNetworkingSockets.CreateNormalSocket <FPSocketManager>(NetAddress.AnyIp(networkPort));
                break;
            }
            socketManager.transport = transport;
        }