public void Start()
    {
        // keep us around until the game closes
        GameObject.DontDestroyOnLoad(gameObject);
        if (AppId == 0)
        {
            throw new System.Exception("You need to set the AppId to your game");
        }

        //
        // Configure us for this unity platform
        //
        Facepunch.Steamworks.Config.ForUnity(Application.platform.ToString());
        // Create the client
        client = new Facepunch.Steamworks.Client(506500);

        if (!client.IsValid)
        {
            client = null;
            Debug.Log("Couldn't initialize Steam");
            return;
        }

        Debug.Log("Steam Initialized: " + client.Username + " / " + client.SteamId);

        NetworkManager.instance.RegisterMyConnection(client.SteamId);

        Debug.Log("Registering Callbacks");
        client.Networking.SetListenChannel(0, true);
        client.Networking.OnP2PData            = OnP2PData;
        client.Networking.OnIncomingConnection = OnIncommingConnection;
        client.Networking.OnConnectionFailed   = OnConnectionFailed;
    }
Beispiel #2
0
        void Startup()
        {
            Facepunch.Steamworks.Config.ForUnity(Application.platform.ToString());

            try
            {
                System.IO.File.WriteAllText("steam_appid.txt", AppId.ToString());
            }
            catch (System.Exception e)
            {
                DevTools.Logger.LogError(PlatformFrontendServiceLog, "Couldn't write steam_appid.txt: {}", () => new object[] { e.Message });
            }

            // Create the client
            client = new Facepunch.Steamworks.Client(AppId);

            if (!client.IsValid)
            {
                client = null;
                DevTools.Logger.LogError(PlatformFrontendServiceLog, "Couldn't initialize Steam");
                return;
            }

            DevTools.Logger.Log(PlatformFrontendServiceLog, "Steam Initialized: {} / {}", () => new object[] { client.Username, client.SteamId });
        }
Beispiel #3
0
        public void CreateLobby()
        {
            using (var client = new Facepunch.Steamworks.Client(252490))
            {
                Assert.IsTrue(client.IsValid);

                client.Lobby.Create(Steamworks.Lobby.Type.Public, 10);

                client.Lobby.OnLobbyCreated = (success) =>
                {
                    Assert.IsTrue(success);
                    Assert.IsTrue(client.Lobby.IsValid);
                    Console.WriteLine("lobby created: " + client.Lobby.CurrentLobby);
                    Console.WriteLine($"Owner: {client.Lobby.Owner}");
                    Console.WriteLine($"Max Members: {client.Lobby.MaxMembers}");
                    Console.WriteLine($"Num Members: {client.Lobby.NumMembers}");
                    client.Lobby.Leave();
                };

                var sw = Stopwatch.StartNew();

                while (sw.Elapsed.TotalSeconds < 3)
                {
                    client.Update();
                    System.Threading.Thread.Sleep(10);
                }
            }
        }
Beispiel #4
0
        public void SetGetUserMetadata()
        {
            using (var client = new Facepunch.Steamworks.Client(252490))
            {
                Assert.IsTrue(client.IsValid);

                client.Lobby.OnLobbyCreated = (success) =>
                {
                    Assert.IsTrue(success);
                    Assert.IsTrue(client.Lobby.IsValid);
                    Console.WriteLine("lobby created: " + client.Lobby.CurrentLobby);
                    client.Lobby.SetMemberData("testkey", "testvalue");
                };

                client.Lobby.OnLobbyMemberDataUpdated = (steamID) =>
                {
                    string name = client.Friends.GetName(steamID);
                    Console.WriteLine(name + " updated data");
                    Assert.IsTrue(client.Lobby.GetMemberData(steamID, "testkey") == "testvalue");
                    Console.WriteLine("testkey is now: " + client.Lobby.GetMemberData(steamID, "testkey"));
                };

                client.Lobby.Create(Steamworks.Lobby.Type.Public, 10);

                var sw = Stopwatch.StartNew();

                while (sw.Elapsed.TotalSeconds < 5)
                {
                    client.Update();
                    System.Threading.Thread.Sleep(10);
                }

                client.Lobby.Leave();
            }
        }
Beispiel #5
0
        public void GetCreatedLobbyData()
        {
            using (var client = new Facepunch.Steamworks.Client(252490))
            {
                Assert.IsTrue(client.IsValid);

                client.Lobby.Create(Steamworks.Lobby.Type.Public, 10);

                client.Lobby.OnLobbyCreated = (success) =>
                {
                    Assert.IsTrue(success);
                    Assert.IsTrue(client.Lobby.IsValid);
                    Console.WriteLine("lobby created: " + client.Lobby.CurrentLobby);
                    foreach (KeyValuePair <string, string> data in client.Lobby.CurrentLobbyData.GetAllData())
                    {
                        if (data.Key == "appid")
                        {
                            Assert.IsTrue(data.Value == "252490");
                        }
                        Console.WriteLine($"{data.Key} {data.Value}");
                    }
                    client.Lobby.Leave();
                };

                var sw = Stopwatch.StartNew();

                while (sw.Elapsed.TotalSeconds < 3)
                {
                    client.Update();
                    System.Threading.Thread.Sleep(10);
                }
            }
        }
Beispiel #6
0
    void Start()
    {
        // keep us around until the game closes
        GameObject.DontDestroyOnLoad(gameObject);

        if (AppId == 0)
        {
            throw new System.Exception("You need to set the AppId to your game");
        }

        //
        // Configure us for this unity platform
        //
        Facepunch.Steamworks.Config.ForUnity(Application.platform.ToString());

        // Create the client
        client = new Facepunch.Steamworks.Client(AppId);

        if (!client.IsValid)
        {
            client = null;
            Debug.LogWarning("Couldn't initialize Steam");
            return;
        }

        Debug.Log("Steam Initialized: " + client.Username + " / " + client.SteamId);
    }
    // Use this for initialization
    void Start()
    {
        if (instance != null)
        {
            Destroy(this.gameObject);
        }

        instance = this;
        GameObject.DontDestroyOnLoad(gameObject);

        if (AppId == 0)
        {
            throw new System.Exception("You need to set the AppId to your game");
        }

        Facepunch.Steamworks.Config.ForUnity(Application.platform.ToString());

        try {
            System.IO.File.WriteAllText("steam_appid.txt", AppId.ToString());
        } catch (System.Exception e) {
            Debug.LogWarning("Couldn't write steam_appid.txt: " + e.Message);
        }

        // Create the client
        client = new Facepunch.Steamworks.Client(AppId);

        if (!client.IsValid)
        {
            client = null;
            Debug.LogWarning("Couldn't initialize Steam");
            return;
        }
        Debug.Log("Steam Initialized: " + client.Username + " / " + client.SteamId);
    }
Beispiel #8
0
 void OnDisable()
 {
     if (steamClient != null)
     {
         steamClient.Dispose();
         steamClient = null;
     }
 }
 private void OnDestroy()
 {
     if (client != null)
     {
         client.Dispose();
         client = null;
     }
 }
Beispiel #10
0
 private void OnDestroy()
 {
     // disposes the steamclient when the steammanager/steamclient-script is destroyed
     if (client != null)
     {
         Client.Instance.Auth.GetAuthSessionTicket().Cancel();
         client.Dispose();
         client = null;
     }
 }
Beispiel #11
0
    void Start()
    {
        // keep us around until the game closes
        GameObject.DontDestroyOnLoad(gameObject);
        // We do not want a client running on a dedicated server

        if (AppId == 0)
        {
            throw new System.Exception("You need to set the AppId to your game");
        }

        //
        // Configure us for this unity platform
        //
        Facepunch.Steamworks.Config.ForUnity(Application.platform.ToString());

        //
        // Create a steam_appid.txt (this seems greasy as f**k, but this is exactly
        // what UE's Steamworks plugin does, so f**k it.
        //
        try
        {
            System.IO.File.WriteAllText("steam_appid.txt", AppId.ToString());
        }
        catch (System.Exception e)
        {
            Logger.LogWarning("Couldn't write steam_appid.txt: " + e.Message, Category.Steam);
        }

        // Create the client
        if (GameData.IsHeadlessServer || GameData.Instance.testServer || SystemInfo.graphicsDeviceType == GraphicsDeviceType.Null)
        {
            Logger.Log("Skipping Steam Client Init as this is a Headless Server", Category.Steam);
        }
        else
        {
            client = new Facepunch.Steamworks.Client(AppId);

            // Prevents NRE's if something goes wrong with the Client
            if (client != null)
            {
                if (!client.IsValid)
                {
                    client = null;
                    Logger.LogWarning("Couldn't initialize Steam", Category.Steam);
                    return;
                }

                Logger.Log("Steam Initialized: " + client.Username + " / " + client.SteamId, Category.Steam);
            }
        }
    }
Beispiel #12
0
        public void RefreshLobbyListWithFilterAndGetLobbyDataFromListLobby()
        {
            using (var client = new Facepunch.Steamworks.Client(755870))
            {
                Assert.IsTrue(client.IsValid);

                client.Lobby.OnLobbyCreated = (success) =>
                {
                    Assert.IsTrue(success);
                    Assert.IsTrue(client.Lobby.IsValid);
                    Console.WriteLine("lobby created: " + client.Lobby.CurrentLobby);
                    client.Lobby.CurrentLobbyData.SetData("testkey", "testvalue");
                };

                client.Lobby.OnLobbyDataUpdated = () =>
                {
                    var filter = new LobbyList.Filter();
                    filter.StringFilters.Add("testkey", "testvalue");
                    client.LobbyList.Refresh(filter);
                };

                client.LobbyList.OnLobbiesUpdated = () =>
                {
                    Console.WriteLine("lobbies updating");
                    if (client.LobbyList.Finished)
                    {
                        Console.WriteLine("lobbies finished updating");
                        Console.WriteLine($"found {client.LobbyList.Lobbies.Count} lobbies");

                        foreach (LobbyList.Lobby lobby in client.LobbyList.Lobbies)
                        {
                            foreach (var pair in lobby.GetAllData())
                            {
                                Console.WriteLine(string.Format("Key: {0,-36} Value: {1}", pair.Key, pair.Value));
                            }
                        }
                    }
                };

                client.Lobby.Create(Steamworks.Lobby.Type.Public, 10);

                var sw = Stopwatch.StartNew();

                while (sw.Elapsed.TotalSeconds < 5)
                {
                    client.Update();
                    System.Threading.Thread.Sleep(10);
                }

                client.Lobby.Leave();
            }
        }
Beispiel #13
0
    void OnEnable()
    {
        steamClient = new Facepunch.Steamworks.Client(220);   // 220 = half-life 2 appid

        if (!steamClient.IsValid)
        {
            steamClient.Dispose();
            throw new System.Exception("Couldn't init Steam - is Steam running? Do you own Half-Life 2? Is steam_appid.txt in your project folder?");
        }

        Debug.Log("Hello " + steamClient.Username);
        Debug.Log("Your SteamID is " + steamClient.SteamId);
    }
    private void OnDestroy()
    {
        if (client != null)
        {
            //should we try to close any open connections?
            //client.Networking.CloseSession()
            //any clients should time out when closed...once we have keep-alive packets up and running
            if (NetworkManager.instance != null)
            {
                NetworkManager.instance.CloseConnectionsOnDestroy();
            }

            client.Dispose();
            client = null;
        }
    }
Beispiel #15
0
        public void SendChatMessage()
        {
            using (var client = new Facepunch.Steamworks.Client(252490))
            {
                Assert.IsTrue(client.IsValid);
                string testString = "Hello, World";

                client.Lobby.OnLobbyCreated = (success) =>
                {
                    Assert.IsTrue(success);
                    Assert.IsTrue(client.Lobby.IsValid);
                    Console.WriteLine("lobby created: " + client.Lobby.CurrentLobby);
                    client.Lobby.CurrentLobbyData.SetData("testkey", "testvalue");
                    client.Lobby.SendChatMessage(testString);
                };

                client.Lobby.OnChatMessageRecieved = (steamID, bytes, length) =>
                {
                    string message = Encoding.UTF8.GetString(bytes, 0, length);
                    Console.WriteLine("message recieved");
                    Assert.IsTrue(message == testString);
                };

                client.Lobby.OnChatStringRecieved = (steamID, message) =>
                {
                    Console.WriteLine("message recieved");
                    Assert.IsTrue(message == testString);
                };

                client.Lobby.Create(Steamworks.Lobby.Type.Public, 10);

                var sw = Stopwatch.StartNew();

                while (sw.Elapsed.TotalSeconds < 5)
                {
                    client.Update();
                    System.Threading.Thread.Sleep(10);
                }

                client.Lobby.Leave();
            }
        }
Beispiel #16
0
        public void RefreshLobbyList()
        {
            using (var client = new Facepunch.Steamworks.Client(252490))
            {
                Assert.IsTrue(client.IsValid);

                client.Lobby.OnLobbyCreated = (success) =>
                {
                    Assert.IsTrue(success);
                    Assert.IsTrue(client.Lobby.IsValid);
                    Console.WriteLine("lobby created: " + client.Lobby.CurrentLobby);
                    client.LobbyList.Refresh();
                };

                client.LobbyList.OnLobbiesUpdated = () =>
                {
                    Console.WriteLine("lobbies updating");
                    if (client.LobbyList.Finished)
                    {
                        Console.WriteLine("lobbies finished updating");
                        Console.WriteLine($"found {client.LobbyList.Lobbies.Count} lobbies");

                        foreach (LobbyList.Lobby lobby in client.LobbyList.Lobbies)
                        {
                            Console.WriteLine($"Found Lobby: {lobby.Name}");
                        }

                        client.Lobby.Leave();
                    }
                };

                client.Lobby.Create(Steamworks.Lobby.Type.Public, 10);

                var sw = Stopwatch.StartNew();

                while (sw.Elapsed.TotalSeconds < 3)
                {
                    client.Update();
                    System.Threading.Thread.Sleep(10);
                }
            }
        }
Beispiel #17
0
    void Start()
    {
        // keep us around until the game closes
        GameObject.DontDestroyOnLoad(gameObject);

        if (AppId == 0)
        {
            throw new System.Exception("You need to set the AppId to your game");
        }

        //
        // Configure us for this unity platform
        //
        Facepunch.Steamworks.Config.ForUnity(Application.platform.ToString());

        //
        // Create a steam_appid.txt (this seems greasy as f**k, but this is exactly
        // what UE's Steamworks plugin does, so f**k it.
        //
        try
        {
            System.IO.File.WriteAllText("steam_appid.txt", AppId.ToString());
        }
        catch (System.Exception e)
        {
            Debug.LogWarning("Couldn't write steam_appid.txt: " + e.Message);
        }

        // Create the client
        client = new Facepunch.Steamworks.Client(AppId);

        if (!client.IsValid)
        {
            client = null;
            Debug.LogWarning("Couldn't initialize Steam");
            return;
        }

        Debug.Log("Steam Initialized: " + client.Username + " / " + client.SteamId);
        Debug.Log("Friends: " + client.Friends.AllFriends.Count());
    }
Beispiel #18
0
        private SteamManager()
        {
            try
            {
                client        = new Facepunch.Steamworks.Client(AppID);
                isInitialized = client.IsSubscribed && client.IsValid;

                if (isInitialized)
                {
                    DebugConsole.Log("Logged in as " + client.Username + " (SteamID " + client.SteamId + ")");
                }
            }
            catch (DllNotFoundException)
            {
                isInitialized = false;
                initializationErrors.Add("SteamDllNotFound");
            }
            catch (Exception)
            {
                isInitialized = false;
                initializationErrors.Add("SteamClientInitFailed");
            }

            if (!isInitialized)
            {
                try
                {
                    Facepunch.Steamworks.Client.Instance.Dispose();
                }
                catch (Exception e)
                {
                    if (GameSettings.VerboseLogging)
                    {
                        DebugConsole.ThrowError("Disposing Steam client failed.", e);
                    }
                }
            }
        }
Beispiel #19
0
    public static void StartClient()
    {
        if (appId == 0)
        {
            throw new System.Exception("You need to set the AppId to your game");
        }

        //
        // Configure us for this unity platform
        //
        Facepunch.Steamworks.Config.ForUnity(Application.platform.ToString());

        //
        // Create a steam_appid.txt (this seems greasy as f**k, but this is exactly
        // what UE's Steamworks plugin does, so f**k it.
        //
        try
        {
            System.IO.File.WriteAllText("steam_appid.txt", appId.ToString());
        }
        catch (System.Exception e)
        {
            Debug.LogWarning("Couldn't write steam_appid.txt: " + e.Message);
        }

        // Create the client
        client = new Facepunch.Steamworks.Client(appId);

        if (!client.IsValid)
        {
            client = null;
            Debug.LogWarning("Couldn't initialize Steam");
            return;
        }

        Debug.Log("Steam Initialized: " + client.Username + " / " + client.SteamId + " time: " + Time.time);
    }
Beispiel #20
0
        public void UpdateLobbyData()
        {
            using (var client = new Facepunch.Steamworks.Client(252490))
            {
                Assert.IsTrue(client.IsValid);

                client.Lobby.Create(Steamworks.Lobby.Type.Public, 10);

                client.Lobby.OnLobbyCreated = (success) =>
                {
                    Assert.IsTrue(success);
                    Assert.IsTrue(client.Lobby.IsValid);
                    Console.WriteLine("lobby created: " + client.Lobby.CurrentLobby);

                    client.Lobby.Name = "My Updated Lobby Name";
                    client.Lobby.CurrentLobbyData.SetData("testkey", "testvalue");
                    client.Lobby.LobbyType  = Steamworks.Lobby.Type.Private;
                    client.Lobby.MaxMembers = 5;
                    client.Lobby.Joinable   = false;

                    foreach (KeyValuePair <string, string> data in client.Lobby.CurrentLobbyData.GetAllData())
                    {
                        if (data.Key == "appid")
                        {
                            Assert.IsTrue(data.Value == "252490");
                        }

                        if (data.Key == "testkey")
                        {
                            Assert.IsTrue(data.Value == "testvalue");
                        }

                        if (data.Key == "lobbytype")
                        {
                            Assert.IsTrue(data.Value == Steamworks.Lobby.Type.Private.ToString());
                        }

                        Console.WriteLine($"{data.Key} {data.Value}");
                    }
                };


                client.Lobby.OnLobbyDataUpdated = () =>
                {
                    Console.WriteLine("lobby data updated");
                    Console.WriteLine(client.Lobby.MaxMembers);
                    Console.WriteLine(client.Lobby.Joinable);
                };



                var sw = Stopwatch.StartNew();

                while (sw.Elapsed.TotalSeconds < 3)
                {
                    client.Update();
                    System.Threading.Thread.Sleep(10);
                }

                client.Lobby.Leave();
            }
        }
Beispiel #21
0
 internal Stats(Client c)
 {
     client = c;
 }
Beispiel #22
0
 public void Dispose()
 {
     client = null;
 }
 internal Stats(Client c)
 {
     client             = c;
     CurrentPlayerCount = new PlayerCount(c);
 }