Beispiel #1
0
        private void AddGamePlayer(SteamApp game, SteamProfile player)
        {
            //record the player
            if (!players.ContainsKey(player.SteamID))
            {
                players.Add(player.SteamID, player);
            }
            //record the game
            if (!games.ContainsKey(game.ID))
            {
                games.Add(game.ID, game);
            }

            //record the players in the games
            if (!gamePlayers.ContainsKey(game.ID))
            {
                gamePlayers.Add(game.ID, new HashSet <long>());
            }

            //add player to game
            if (!gamePlayers[game.ID].Contains(player.SteamID))
            {
                gamePlayers[game.ID].Add(player.SteamID);
            }
        }
Beispiel #2
0
        public async Task LoadGames()
        {
            var w = new WebClient();

            SteamProfile profile = await SteamManager.GetSteamProfileByID(Id);

            if (profile == null)
            {
                throw new ArgumentException("Invalid Profile");
            }
            await SteamManager.LoadGamesForProfile(profile);

            var sb = new StringBuilder();

            var allgames = profile.Games.ToList();

            var AllGameIds = allgames.Select(d => d.App.ID.ToString());

            var GamesToLoadIds = allgames.Select(d => d.App.ID.ToString()).ToList();

            foreach (string s in GamesToLoadIds)
            {
                sb.Append(s);
                if (s != GamesToLoadIds.Last())
                {
                    sb.Append(",");
                }
            }
        }
Beispiel #3
0
        public void GetProfile()
        {
            SteamProfile profile = _manager.GetProfile("nullreference");

            Assert.That(profile, Is.Not.Null);
            Assert.That(profile.SteamUserId, Is.EqualTo("Null Reference"));
        }
Beispiel #4
0
        public void TestAllPropertiesWithInitializeFields()
        {
            SteamProfile profile = MockTinySteamWrapper.CreateSteamProfile();
            Friend       friend  = new Friend();

            friend.InitializeFields(profile);
            AssertFriend(friend);
        }
Beispiel #5
0
        public void InitializeProperties(SteamProfile profile)
        {
            PropertyInfo[] properties = typeof(SteamProfile).GetProperties();

            foreach (PropertyInfo property in properties)
            {
                property.SetValue(this, property.GetValue(profile));
            }
        }
Beispiel #6
0
        public void InitializeFields(SteamProfile profile)
        {
            FieldInfo[] fields = typeof(SteamProfile).GetFields(
                BindingFlags.NonPublic |
                BindingFlags.Instance);

            foreach (FieldInfo field in fields)
            {
                field.SetValue(this, field.GetValue(profile));
            }
        }
Beispiel #7
0
            private async void Test(ulong id, string name)
            {
                SteamProfile test = await SteamManager.GetSteamProfileByID((long)id);

                await SteamManager.LoadGamesForProfile(test);

                Console.WriteLine("User {0} Game List:", test.PersonaName);
                foreach (SteamProfileGame game in test.Games)
                {
                    Console.WriteLine("     {0}", game.App.Name);
                }
            }
Beispiel #8
0
        public static SteamProfile CreateSteamProfile()
        {
            var game1 = CreateSteamApp();

            SetValue(game1, "Name", "Game1");
            SetValue(game1, "ID", 101);

            var game2 = CreateSteamApp();

            SetValue(game2, "Name", "Game2");
            SetValue(game2, "ID", 102);

            var game3 = CreateSteamApp();

            SetValue(game3, "Name", "Game3");
            SetValue(game3, "ID", 103);

            SteamProfile profile = new SteamProfile();

            profile.Avatar                   = "Avatar1";
            profile.AvatarFull               = "AvatarFull1";
            profile.AvatarMedium             = "AvatarMedium1";
            profile.CityID                   = "CityID1";
            profile.CommunityVisibilityState = CommunityVisibilityState.Public;
            profile.CountryCode              = "CountryCode1";

            profile.CurrentGame = game2;

            profile.CurrentGameExtraInfo     = "CurrentGameExtraInfo1";
            profile.CurrentGameServerIP      = "CurrentGameServerIP1";
            profile.CurrentGameServerSteamID = 21;
            profile.CurrentLobbySteamID      = 22;

            var profileGames = new ObservableCollection <SteamProfileGame>();

            profileGames.Add(new SteamProfileGame(game1, TimeSpan.FromHours(1)));
            profileGames.Add(new SteamProfileGame(game2, TimeSpan.FromHours(2)));
            profileGames.Add(new SteamProfileGame(game3, TimeSpan.FromHours(3)));
            SetValue(profile, "Games", profileGames);

            profile.LastLogOff        = new DateTime(2016, 6, 15);
            profile.PersonaName       = "PersonaName1";
            profile.PersonaState      = PersonaState.Online;
            profile.PersonaStateFlags = 23;
            profile.PrimaryClanID     = 24;
            profile.ProfileState      = 25;
            profile.ProfileUrl        = "ProfileUrl1";
            profile.RealName          = "RealName1";
            profile.StateCode         = "StateCode1";
            profile.SteamID           = 26;
            profile.TimeCreated       = new DateTime(2016, 9, 21);
            return(profile);
        }
Beispiel #9
0
        private async void GetSteamProfile(ulong steamId)
        {
            long         id            = (long)steamId;
            SteamProfile friendProfile = await SteamManager.GetSteamProfileByID(id);

            if (friendProfile != null)
            {
                await SteamManager.LoadGamesForProfile(friendProfile);

                lock (Friends)
                {
                    Friends[friendProfile.SteamID] = friendProfile;
                }
                OnFriendListUpdate?.Invoke(this, friendProfile.SteamID);
            }
        }
        public void PerfectMatchesTest()
        {
            List <SteamProfile> Friends = new List <SteamProfile>();

            SteamApp app1 = MockTinySteamWrapper.CreateSteamApp();

            MockTinySteamWrapper.SetValue(app1, "Name", "Game1");
            MockTinySteamWrapper.SetValue(app1, "ID", 101);
            SteamApp app2 = MockTinySteamWrapper.CreateSteamApp();

            MockTinySteamWrapper.SetValue(app2, "Name", "Game2");
            MockTinySteamWrapper.SetValue(app2, "ID", 102);
            SteamApp app3 = MockTinySteamWrapper.CreateSteamApp();

            MockTinySteamWrapper.SetValue(app3, "Name", "Game3");
            MockTinySteamWrapper.SetValue(app3, "ID", 103);

            SteamProfileGame game1      = new SteamProfileGame(app1, TimeSpan.FromHours(1));
            SteamProfileGame game2      = new SteamProfileGame(app2, TimeSpan.FromHours(1));
            SteamProfileGame gameCommon = new SteamProfileGame(app3, TimeSpan.FromHours(1));

            SteamProfile friend1 = new SteamProfile()
            {
                SteamID = 1, Avatar = "AvatarUrl1", PersonaState = TinySteamWrapper.Steam.PersonaState.Online
            };

            friend1.Games.Add(game1);
            friend1.Games.Add(gameCommon);
            Friends.Add(friend1);

            SteamProfile friend2 = new SteamProfile()
            {
                SteamID = 2, Avatar = "AvatarUrl2", PersonaState = TinySteamWrapper.Steam.PersonaState.Online
            };

            friend2.Games.Add(game2);
            friend2.Games.Add(gameCommon);
            Friends.Add(friend2);

            GamesAndPlayers gamesAndPlayers = new GamesAndPlayers(Friends);
            var             match           = gamesAndPlayers.GetPerfectMatches();

            Assert.AreEqual(1, match.Count);
            Assert.AreEqual(gameCommon.App, match[0].SteamApp);
        }
Beispiel #11
0
        public void NotifyPropertyChangedIsCalledOnInitializeProperties()
        {
            ManualResetEvent propertyChangedRaised = new ManualResetEvent(false);
            SteamProfile     profile = MockTinySteamWrapper.CreateSteamProfile();

            Friend friend = new Friend();

            friend.PropertyChanged += (o, e) => { propertyChangedRaised.Set(); };

            bool isPropertyChangedRaisedBefore = propertyChangedRaised.WaitOne(0);

            Assert.IsFalse(isPropertyChangedRaisedBefore, "the event should not been raised yet");
            friend.InitializeProperties(profile);
            //event is raised asynchronously, so give it 2 seconds to be called.
            bool isPropertyChangedRaisedAfter = propertyChangedRaised.WaitOne(TimeSpan.FromSeconds(2));

            Assert.IsTrue(isPropertyChangedRaisedAfter, "the event should have been raised by now");

            Assert.AreEqual("Avatar1", friend.Avatar, "and at least 1 property should have been set");
        }
Beispiel #12
0
        // UI -----------------------------------------------------------------------------------------------
        #region UI

        private async Task ChangePlayerInfo(EFilter_Game newGame, EFilter_Mode newMode, EFilter_PlayerType newPlayerType, string newPlayerValue)
        {
            if (newGame == game && newMode == mode && newPlayerValue == playerValue)
            {
                return;
            }

            var playerInfoDatum = await playerViewModel.GetPlayerInfo(newGame, newMode, newPlayerType, newPlayerValue);

            playerInfoData = playerInfoDatum?.data;
            if (playerInfoData is null || playerInfoData.basicInfo is null)
            {
                await DisplayAlert("Could not find player profile!", "Invalid SteamID or rank.", "OK");

                return;
            }

            playerType    = newPlayerType;
            playerValue   = newPlayerValue;
            game          = newGame;
            mode          = newMode;
            playerSteamId = playerInfoData.basicInfo.steamID;
            playerRank    = playerInfoData.SurfRank;

            string playerName = playerInfoData.basicInfo.name;

            if (playerName.Length > 18)
            {
                playerName = playerName.Substring(0, 13) + "...";
            }
            Title = playerName + " [" + EFilter_ToString.toString2(game) + ", " + EFilter_ToString.toString(mode) + "]";

            var PlayerSteamDatum = await playerViewModel.GetPlayerSteamProfile(playerSteamId);

            playerSteamProfile = PlayerSteamDatum?.response.players[0];

            wrsType = EFilter_PlayerWRsType.none;
            LayoutPlayerInfo();
            LayoutPlayerProfile();
        }
        public async Task <SteamProfile> GetSteamProfile(string query)
        {
            var steamIdRegex = new Regex(@"\d{17}");

            var profile = new SteamProfile();

            if (!steamIdRegex.IsMatch(query))
            {
                profile.Id = GetSteamIdFromName(query);
            }
            else
            {
                profile.Id = query;
            }

            var fullProfile = await GetFullSteamProfile(profile.Id);

            profile.Name      = fullProfile.Realname;
            profile.Persona   = fullProfile.Personaname;
            profile.AvatarUrl = fullProfile.Avatar.AbsoluteUri;

            return(profile);
        }
Beispiel #14
0
            public async void SetSteamId(string steamId)
            {
                if (steamId == null)
                {
                    return;
                }

                _cancellationTokenSource?.Cancel();

                var existing = SteamProfiles.FirstOrDefault(x => x.SteamId == steamId);

                if (existing != null)
                {
                    SteamProfile = existing;
                    return;
                }

                var profile = new SteamProfile(steamId);

                SteamProfiles.Add(profile);
                SteamProfile = profile;

                profile.ProfileName = await SteamIdHelper.GetSteamName(steamId);
            }
 public SteamGameAndMissingPlayerInfo(SteamApp game, SteamProfile missingPlayer) : base(game)
 {
     SteamProfile = missingPlayer;
 }
        public void OnlyIncludeOnlinePlayers()
        {
            List <SteamProfile> Friends = new List <SteamProfile>();

            SteamApp app1 = MockTinySteamWrapper.CreateSteamApp();

            MockTinySteamWrapper.SetValue(app1, "Name", "Game1");
            MockTinySteamWrapper.SetValue(app1, "ID", 101);
            SteamApp app2 = MockTinySteamWrapper.CreateSteamApp();

            MockTinySteamWrapper.SetValue(app2, "Name", "Game2");
            MockTinySteamWrapper.SetValue(app2, "ID", 102);
            SteamApp app3 = MockTinySteamWrapper.CreateSteamApp();

            MockTinySteamWrapper.SetValue(app3, "Name", "Game3");
            MockTinySteamWrapper.SetValue(app3, "ID", 103);
            SteamApp appCommon = MockTinySteamWrapper.CreateSteamApp();

            MockTinySteamWrapper.SetValue(appCommon, "Name", "GameCommon");
            MockTinySteamWrapper.SetValue(appCommon, "ID", 999);

            SteamProfileGame game1      = new SteamProfileGame(app1, TimeSpan.FromHours(1));
            SteamProfileGame game2      = new SteamProfileGame(app2, TimeSpan.FromHours(1));
            SteamProfileGame game3      = new SteamProfileGame(app3, TimeSpan.FromHours(1));
            SteamProfileGame gameCommon = new SteamProfileGame(appCommon, TimeSpan.FromHours(1));
            {
                SteamProfile friend1 = new SteamProfile()
                {
                    SteamID = 1, Avatar = "AvatarUrl1", PersonaState = TinySteamWrapper.Steam.PersonaState.Online
                };
                friend1.Games.Add(game1);
                friend1.Games.Add(gameCommon);
                Friends.Add(friend1);
            }
            {
                //Friend 2 does not have the common game, or the unique games game1, or game2.
                SteamProfile friend2 = new SteamProfile()
                {
                    SteamID = 2, Avatar = "AvatarUrl2", PersonaState = TinySteamWrapper.Steam.PersonaState.Offline
                };
                friend2.Games.Add(game2);
                Friends.Add(friend2);
            }
            {
                SteamProfile friend3 = new SteamProfile()
                {
                    SteamID = 3, Avatar = "AvatarUrl3", PersonaState = TinySteamWrapper.Steam.PersonaState.Online
                };
                friend3.Games.Add(game3);
                friend3.Games.Add(gameCommon);
                Friends.Add(friend3);
            }
            GamesAndPlayers gamesAndPlayers = new GamesAndPlayers(Friends);

            var match = gamesAndPlayers.GetPerfectMatches();

            Assert.AreEqual(1, match.Count);
            Assert.AreEqual(gameCommon.App, match[0].SteamApp);

            var similar = gamesAndPlayers.GetOffByOneMatches();

            Assert.AreEqual(2, similar.Count);
            Assert.IsNotNull(similar.Find(s => s.ID == game1.App.ID));
            Assert.IsNotNull(similar.Find(s => s.ID == game3.App.ID));
        }
        /// <summary>
        /// Gets or downloads the Steam profile. The only time this will ever return null is if Steam can't find the user.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <DbSteamCache> GetSteamProfileById(string id)
        {
            //Check if we have any in memory
            if (memory_steam_cache.ContainsKey(id))
            {
                return(memory_steam_cache[id]);
            }

            //Check if we have any (up to date) steam profiles in the database
            DbSteamCache profile = null;

            {
                //Get the latest date we can use
                long time = DateTime.UtcNow.AddMinutes(steamCacheExpireMinutes).Ticks;

                //Fetch
                var filterBuilder = Builders <DbSteamCache> .Filter;
                var filter        = filterBuilder.Eq("steam_id", id) & filterBuilder.Lt("time_utc", time);
                var results       = await system_steam_cache.FindAsync(filter);

                profile = await results.FirstOrDefaultAsync();
            }

            //If the profile was valid, return it
            if (profile != null)
            {
                return(profile);
            }

            //We'll fetch updated Steam info
            SteamProfile_Full profiles;

            try
            {
                var response = await http.GetAsync("https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=" + steamApiKey + "&steamids=" + id);

                if (!response.IsSuccessStatusCode)
                {
                    return(null);
                }
                profiles = JsonConvert.DeserializeObject <SteamProfile_Full>(await response.Content.ReadAsStringAsync());
            } catch
            {
                return(null);
            }

            //Get the profile from this
            if (profiles.response.players.Count != 1)
            {
                return(null);
            }
            SteamProfile profileData = profiles.response.players[0];

            //Create a profile object
            profile = new DbSteamCache
            {
                icon_url    = profileData.avatarfull,
                name        = profileData.personaname,
                profile_url = profileData.profileurl,
                steam_id    = profileData.steamid,
                time_utc    = DateTime.UtcNow.Ticks
            };

            //Now, insert for future use
            {
                var filterBuilder = Builders <DbSteamCache> .Filter;
                var filter        = filterBuilder.Eq("steam_id", id);
                var response      = await system_steam_cache.FindOneAndReplaceAsync <DbSteamCache>(filter, profile, new FindOneAndReplaceOptions <DbSteamCache, DbSteamCache>
                {
                    IsUpsert       = true,
                    ReturnDocument = ReturnDocument.After
                });

                profile._id = response._id;
            }

            //Add to memory cache
            if (!memory_steam_cache.ContainsKey(id))
            {
                memory_steam_cache.Add(id, profile);
            }

            return(profile);
        }
        public async void SteamUpdate()
        {
            SteamManager.SteamAPIKey = AccountInformation.getAPITKey();
            AccountInformation.SteamProfileID = await SteamManager.GetSteamIDByName(AccountInformation.getSteamID());

            long steamID = await SteamManager.GetSteamIDByName(AccountInformation.getSteamID());
            profile = await SteamManager.GetSteamProfileByID(AccountInformation.SteamProfileID);
            if (profile == null)
            {
                Environment.FailFast("Steam Profile = NULL");
                return;
            }
            this.DataContext = profile;
            await SteamManager.LoadGamesForProfile(profile);

            // Set GUI values
            SteamUsernameBox.Text = profile.PersonaName;
            SteamAvitarImage.Source = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new System.Uri(profile.AvatarMedium));
            string currentGame;
            SteamStatusBox.Text = "Current Status: " + profile.PersonaState.ToString();
            if (profile.CurrentGame != null) SteamSetGame();
            else if (SteamInfoBox.IsEnabled)
            {
                SteamInfoBox.Text = "Current Game Info:\n";
                SteamInfoBox.IsEnabled = false;
            }
            SteamSetStatus();

        }
Beispiel #19
0
 public Friend(SteamProfile profile) : base()
 {
     InitializeProperties(profile);
 }
 private async void updateProfile(string Name)
 {
     long steamID = await SteamManager.GetSteamIDByName(Name);
     p = await SteamManager.GetSteamProfileByID(steamID);
 }