public ZklSteamHandler(TasClient tas)
        {
            this.tas = tas;
            if (Environment.OSVersion.Platform == PlatformID.Unix)
            {
                EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.libCSteamworks.so", "libCSteamworks.so");
                EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.libsteam_api.so", "libsteam_api.so");
            }
            else
            {
                EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.CSteamworks.dll", "CSteamworks.dll");
                EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.steam_api.dll", "steam_api.dll");
            }
            EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.steam_appid.txt", "steam_appid.txt");

            SteamHelper              = new SteamClientHelper();
            SteamHelper.SteamOnline += () =>
            {
                SteamName = SteamHelper.GetMyName();
                friends   = SteamHelper.GetFriends();
                SteamID   = SteamHelper.GetSteamID();
                if (tas.IsLoggedIn && tas.MyUser != null && tas.MyUser.EffectiveElo != 0)
                {
                    OnLoggedToBothSteamAndTas();
                }
            };


            tas.MyExtensionsChanged += (sender, args) => { if (SteamHelper.IsOnline && SteamID != 0)
                                                           {
                                                               OnLoggedToBothSteamAndTas();
                                                           }
            };
            tas.UserExtensionsChanged += (sender, args) =>
            {
                if (args.Data.SteamID != null)
                {
                    Voice.AddListenerSteamID(args.Data.SteamID.Value);                            // todo only for battle in future
                }
                if (args.Data.SteamID != null && SteamID != 0 && friends.Contains(args.Data.SteamID.Value))
                {
                    AddFriend(args.Data.Name);
                }
            };

            tas.UserRemoved += (sender, args) =>
            {
                User us;
                if (tas.ExistingUsers.TryGetValue(args.Name, out us) && us.SteamID.HasValue)
                {
                    Voice.RemoveListenerSteamID(us.SteamID.Value);
                }
            };
        }
Ejemplo n.º 2
0
        public ZklSteamHandler(TasClient tas)
        {
            this.tas = tas;
            if (Environment.OSVersion.Platform == PlatformID.Unix)
            {
                if (Environment.Is64BitProcess)
                {
                    EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.libCSteamworks-x86_64.so", "libCSteamworks.so");
                    EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.libsteam_api-x86_64.so", "libsteam_api.so");
                }
                else
                {
                    EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.libCSteamworks.so", "libCSteamworks.so");
                    EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.libsteam_api.so", "libsteam_api.so");
                }
            }
            else
            {
                EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.CSteamworks.dll", "CSteamworks.dll");
                EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.steam_api.dll", "steam_api.dll");
            }
            EmbeddedResourceExtractor.ExtractFile("ZeroKLobby.NativeLibs.steam_appid.txt", "steam_appid.txt");

            SteamHelper              = new SteamClientHelper();
            SteamHelper.SteamOnline += () =>
            {
                SteamName = SteamHelper.GetMyName();
                friends   = SteamHelper.GetFriends();
                SteamID   = SteamHelper.GetSteamID();
                if (tas.IsLoggedIn && tas.MyUser != null)
                {
                    OnLoggedToBothSteamAndTas();
                }
            };


            tas.MyUserStatusChanged += (sender, args) => { if (SteamHelper.IsOnline && SteamID != 0)
                                                           {
                                                               OnLoggedToBothSteamAndTas();
                                                           }
            };
            tas.UserStatusChanged += (sender, args) =>
            {
                if (args?.New?.SteamID != null && args?.Old?.SteamID != args?.New?.SteamID && !string.IsNullOrEmpty(args?.New?.SteamID))
                {
                    Voice.AddListenerSteamID(ulong.Parse(args.New.SteamID)); // todo only for battle in future
                    if (friends.Contains(ulong.Parse(args.New.SteamID)))
                    {
                        AddFriend(args.New.Name);
                    }
                }
            };

            tas.UserRemoved += (sender, args) =>
            {
                User us;
                if (tas.ExistingUsers.TryGetValue(args.Name, out us) && !string.IsNullOrEmpty(us.SteamID))
                {
                    Voice.RemoveListenerSteamID(ulong.Parse(us.SteamID));
                }
            };
        }