public async Task RelayEndtoEndFakeIP()
        {
            SteamNetworkingUtils.InitRelayNetworkAccess();
            SteamNetworkingUtils.DebugLevel     = NetDebugOutput.Warning;
            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);

            Console.WriteLine($"----- Creating Socket Relay Socket..");
            var socket = SteamNetworkingSockets.CreateRelaySocketFakeIP <TestSocketInterface>();
            var server = socket.RunAsync();

            await Task.Delay(1000);

            Console.WriteLine($"----- Retrieving Fake IP..");
            SteamNetworkingSockets.GetFakeIP(0, out NetAddress address);

            Console.WriteLine($"----- Connecting To Socket via Fake IP ({address})");
            var connection = SteamNetworkingSockets.ConnectNormal <TestConnectionInterface>(address);
            var client     = connection.RunAsync();

            await Task.WhenAll(server, client);
        }
        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 static void Shutdown()
        {
            Event.DisposeAllClient();

            initialized = false;

            ShutdownInterfaces();
            SteamApps.Shutdown();
            SteamUtils.Shutdown();
            SteamParental.Shutdown();
            SteamMusic.Shutdown();
            SteamVideo.Shutdown();
            SteamUser.Shutdown();
            SteamFriends.Shutdown();
            SteamScreenshots.Shutdown();
            SteamUserStats.Shutdown();
            SteamInventory.Shutdown();
            SteamNetworking.Shutdown();
            SteamMatchmaking.Shutdown();
            SteamParties.Shutdown();
            SteamNetworkingUtils.Shutdown();
            SteamNetworkingSockets.Shutdown();
            ServerList.Base.Shutdown();

            SteamAPI.Shutdown();
        }
        private static void ConnectionStatusChanged(SteamNetConnectionStatusChangedCallback_t data)
        {
            if (data.Nfo.listenSocket.Id == 0)
            {
                ConnectionInterface connectionInterface = SteamNetworkingSockets.GetConnectionInterface(data.Conn.Id);
                if (connectionInterface != null)
                {
                    connectionInterface.OnConnectionChanged(data.Nfo);
                }
            }
            else
            {
                SocketInterface socketInterface = SteamNetworkingSockets.GetSocketInterface(data.Nfo.listenSocket.Id);
                if (socketInterface != null)
                {
                    socketInterface.OnConnectionChanged(data.Conn, data.Nfo);
                }
            }
            Action <Connection, ConnectionInfo> action = SteamNetworkingSockets.OnConnectionStatusChanged;

            if (action != null)
            {
                action(data.Conn, data.Nfo);
            }
            else
            {
            }
        }
        public static void Init(uint appid)
        {
            System.Environment.SetEnvironmentVariable("SteamAppId", appid.ToString());
            System.Environment.SetEnvironmentVariable("SteamGameId", appid.ToString());

            if (!SteamAPI.Init())
            {
                throw new System.Exception("SteamApi_Init returned false. Steam isn't running, couldn't find Steam, AppId is ureleased, Don't own AppId.");
            }

            AppId = appid;

            initialized = true;

            SteamApps.InstallEvents();
            SteamUtils.InstallEvents();
            SteamParental.InstallEvents();
            SteamMusic.InstallEvents();
            SteamVideo.InstallEvents();
            SteamUser.InstallEvents();
            SteamFriends.InstallEvents();
            SteamScreenshots.InstallEvents();
            SteamUserStats.InstallEvents();
            SteamInventory.InstallEvents();
            SteamNetworking.InstallEvents();
            SteamMatchmaking.InstallEvents();
            SteamParties.InstallEvents();
            SteamNetworkingSockets.InstallEvents();
            SteamInput.InstallEvents();

            RunCallbacksAsync();
        }
 public static void Init(uint appid)
 {
     if (IntPtr.Size != 8)
     {
         throw new Exception("Only 64bit processes are currently supported");
     }
     Environment.SetEnvironmentVariable("SteamAppId", appid.ToString());
     Environment.SetEnvironmentVariable("SteamGameId", appid.ToString());
     if (!SteamAPI.Init())
     {
         throw new Exception("SteamApi_Init returned false. Steam isn't running, couldn't find Steam, AppId is ureleased, Don't own AppId.");
     }
     SteamClient.AppId       = appid;
     SteamClient.initialized = true;
     SteamApps.InstallEvents();
     SteamUtils.InstallEvents();
     SteamParental.InstallEvents();
     SteamMusic.InstallEvents();
     SteamVideo.InstallEvents();
     SteamUser.InstallEvents();
     SteamFriends.InstallEvents();
     SteamScreenshots.InstallEvents();
     SteamUserStats.InstallEvents();
     SteamInventory.InstallEvents();
     SteamNetworking.InstallEvents();
     SteamMatchmaking.InstallEvents();
     SteamParties.InstallEvents();
     SteamNetworkingSockets.InstallEvents();
     SteamClient.RunCallbacksAsync();
 }
        public static T CreateRelaySocket <T>(int virtualport = 0)
            where T : SocketInterface, new()
        {
            T t = Activator.CreateInstance <T>();

            t.Socket = SteamNetworkingSockets.Internal.CreateListenSocketP2P(virtualport);
            SteamNetworkingSockets.SetSocketInterface(t.Socket.Id, t);
            return(t);
        }
        public static T CreateNormalSocket <T>(NetAddress address)
            where T : SocketInterface, new()
        {
            T t = Activator.CreateInstance <T>();

            t.Socket = SteamNetworkingSockets.Internal.CreateListenSocketIP(ref address);
            SteamNetworkingSockets.SetSocketInterface(t.Socket.Id, t);
            return(t);
        }
        public static T ConnectNormal <T>(NetAddress address)
            where T : ConnectionInterface, new()
        {
            T t = Activator.CreateInstance <T>();

            t.Connection = SteamNetworkingSockets.Internal.ConnectByIPAddress(ref address);
            SteamNetworkingSockets.SetConnectionInterface(t.Connection.Id, t);
            return(t);
        }
        public static T ConnectRelay <T>(SteamId serverId, int virtualport = 0)
            where T : ConnectionInterface, new()
        {
            T           t           = Activator.CreateInstance <T>();
            NetIdentity netIdentity = serverId;

            t.Connection = SteamNetworkingSockets.Internal.ConnectP2P(ref netIdentity, virtualport);
            SteamNetworkingSockets.SetConnectionInterface(t.Connection.Id, t);
            return(t);
        }
        internal static void InstallEvents()
        {
            SteamInventory.InstallEvents();
            SteamNetworkingSockets.InstallEvents(true);

            ValidateAuthTicketResponse_t.Install(x => OnValidateAuthTicketResponse?.Invoke(x.SteamID, x.OwnerSteamID, x.AuthSessionResponse), true);
            SteamServersConnected_t.Install(x => OnSteamServersConnected?.Invoke(), true);
            SteamServerConnectFailure_t.Install(x => OnSteamServerConnectFailure?.Invoke(x.Result, x.StillRetrying), true);
            SteamServersDisconnected_t.Install(x => OnSteamServersDisconnected?.Invoke(x.Result), true);
        }
 public static void Shutdown()
 {
     Event.DisposeAllServer();
     SteamServer.initialized = false;
     SteamServer._internal   = null;
     SteamServer.ShutdownInterfaces();
     SteamNetworkingUtils.Shutdown();
     SteamNetworkingSockets.Shutdown();
     SteamInventory.Shutdown();
     SteamGameServer.Shutdown();
 }
        public async Task CreateRelayServer()
        {
            var si = SteamNetworkingSockets.CreateRelaySocket <TestSocketInterface>();

            Console.WriteLine($"Created Socket: {si}");

            // Give it a second for something to happen
            await Task.Delay(1000);

            si.Close();
        }
        public async Task CreateNormalServer()
        {
            var si = SteamNetworkingSockets.CreateNormalSocket <TestSocketInterface>(Data.NetAddress.AnyIp(21893));

            Console.WriteLine($"Created Socket: {si}");

            // Give it a second for something to happen
            await Task.Delay(1000);

            si.Close();
        }
        public async Task RelayEndtoEnd()
        {
            var socket = SteamNetworkingSockets.CreateRelaySocket <TestSocketInterface>(7788);
            var server = socket.RunAsync();

            await Task.Delay(1000);

            var connection = SteamNetworkingSockets.ConnectRelay <TestConnectionInterface>(SteamClient.SteamId, 7788);
            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);
        }
        public async Task CreateRelayServerFakeIP()
        {
            SteamNetworkingUtils.DebugLevel     = NetDebugOutput.Everything;
            SteamNetworkingUtils.OnDebugOutput += DebugOutput;

            var si = SteamNetworkingSockets.CreateRelaySocketFakeIP <TestSocketInterface>();

            Console.WriteLine($"Created Socket: {si}");

            // Give it a second for something to happen
            await Task.Delay(1000);

            si.Close();
        }
Exemple #18
0
        public async Task RelayEndtoEnd()
        {
            SteamNetworkingUtils.InitRelayNetworkAccess();

            // For some reason giving steam a couple of seconds here
            // seems to prevent it returning null connections from ConnectNormal
            await Task.Delay(2000);

            Console.WriteLine($"----- Creating Socket Relay Socket..");
            var socket = SteamNetworkingSockets.CreateRelaySocket <TestSocketInterface>(6);
            var server = socket.RunAsync();

            await Task.Delay(1000);

            Console.WriteLine($"----- Connecting To Socket via SteamId ({SteamClient.SteamId})");
            var connection = SteamNetworkingSockets.ConnectRelay <TestConnectionInterface>(SteamClient.SteamId, 6);
            var client     = connection.RunAsync();

            await Task.WhenAll(server, client);
        }
        public static void AssemblyInit(TestContext context)
        {
            Steamworks.Dispatch.OnDebugCallback = (type, str, server) =>
            {
                Console.WriteLine($"[Callback {type} {(server ? "server" : "client")}]");
                Console.WriteLine(str);
                Console.WriteLine($"");
            };

            Steamworks.Dispatch.OnException = (e) =>
            {
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine(e.StackTrace);
                Assert.Fail(e.Message);
            };

            //
            // Init Client
            //
            Steamworks.SteamClient.Init(252490);

            //
            // Init Server
            //
            var serverInit = new SteamServerInit("rust", "Rusty Mode")
            {
                GamePort  = 28015,
                Secure    = true,
                QueryPort = 28016
            };

            Steamworks.SteamServer.Init(252490, serverInit);

            //
            // Needs to happen before LogOnAnonymous
            //
            SteamNetworkingSockets.RequestFakeIP();

            SteamServer.LogOnAnonymous();
        }
 internal static void InstallEvents()
 {
     SteamNetConnectionStatusChangedCallback_t.Install((SteamNetConnectionStatusChangedCallback_t x) => SteamNetworkingSockets.ConnectionStatusChanged(x), false);
 }