Exemple #1
0
 public bool tryAddGame(mod_steam_game g)
 {
     if (games.Where(x => x.gameID == g.gameID).Count() == 0)
     {
         games.Add(g);
         return(true);
     }
     else
     {
         return(false);
     }
 }
        public static List <mod_steam_game> getRecentGames(string playerID)
        {
            mod_steam_core_data   localData = getLocalData();
            List <mod_steam_game> games     = new List <mod_steam_game>();
            NameValueCollection   pairs     = new NameValueCollection();

            pairs["steamid"] = playerID.ToString();
            JObject response = sendPOST(@"/IPlayerService/GetRecentlyPlayedGames/v0001/", pairs);

            foreach (JToken token in response.SelectTokens("response.games[*]"))//jo.Children()) //) records[*].data.importedPath"
            {
                //mangle this into a player object
                string gameName = "";
                string gameID   = "";
                try
                {
                    //get the message details
                    gameName = token.SelectToken("name").Value <string>();
                    gameID   = token.SelectToken("appid").Value <string>();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error parsing message " + e.ToString());
                }

                //try get the game from our game cache
                mod_steam_game game = localData.getGame(gameID);

                if (game == null)
                {
                    //otherwise add it
                    game = new mod_steam_game(gameID, gameName);
                }
                games.Add(game);
            }

            //make sure these are all in our local cache
            foreach (mod_steam_game g in games)
            {
                bool added = localData.tryAddGame(g);
                if (added)
                {
                    Console.WriteLine("Added game " + g.displayName + " to the list of games we know about");
                }
            }
            return(games);
        }
Exemple #3
0
        public void checkAchievements()
        {
            List <string>       announce  = new List <string>();
            mod_steam_core_data localData = Roboto.Settings.getPluginData <mod_steam_core_data>();

            //get a list of what the player has been playing
            try
            {
                List <mod_steam_game> playerGames = mod_steam_steamapi.getRecentGames(playerID);

                foreach (mod_steam_game g in playerGames)
                {
                    //get the local data object
                    mod_steam_game gameData = localData.getGame(g.gameID);

                    //get the achievement list for each game
                    try
                    {
                        List <string> gainedAchievements = mod_steam_steamapi.getAchievements(playerID, g.gameID);

                        //make a list of any that we havent recorded yet
                        List <string> newAchievements = new List <string>();
                        foreach (string achievementCode in gainedAchievements)
                        {
                            if (chievs.Where(x => x.chievName == achievementCode && x.appID == g.gameID).Count() == 0)
                            {
                                newAchievements.Add(achievementCode);
                            }
                        }

                        if (newAchievements.Count() > 0)
                        {
                            List <string> failedAchieves = new List <string>();
                            //try get the cached friendly text for each achievement, and add them to our player's stash.
                            foreach (string s in newAchievements)
                            {
                                chievs.Add(new mod_steam_chiev(s, g.gameID));
                                mod_steam_achievement chiev = gameData.getAchievement(s);
                                if (chiev == null)
                                {
                                    Console.WriteLine("Failed to get friendly data for " + s + " from cache, will refresh");
                                    failedAchieves.Add(s);
                                }
                                else
                                {
                                    announce.Add(chiev.ToString() + " in " + g.displayName);
                                }
                            }

                            //if we failed, refresh the cache and try again.
                            if (failedAchieves.Count() > 0)
                            {
                                gameData.refreshAchievs();
                            }
                            //add any that failed originally.
                            foreach (string s in failedAchieves)
                            {
                                mod_steam_achievement chiev = gameData.getAchievement(s);
                                if (chiev == null)
                                {
                                    Console.WriteLine("Failed to get friendly data for " + s + " even after refresh. Will add default text instead");
                                    announce.Add(s.Replace("_", " ") + " in " + g.displayName);
                                }
                                else
                                {
                                    announce.Add(chiev.ToString() + " in " + g.displayName);
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        //probably failed to call the web service.
                        Console.WriteLine("Failed during update of player achievements for game" + e.ToString());
                    }
                }
            }
            catch (Exception e)
            {
                //probably failed to call the web service.
                Console.WriteLine("Failed during update of player achievements " + e.ToString());
            }
            //send a message (first few per game)
            if (announce.Count() > 0)
            {
                string message = playerName + " got the following achievements:" + "\n\r";
                int    max     = 5;
                if (announce.Count < 5)
                {
                    max = announce.Count;
                }

                for (int i = 0; i < max; i++)
                {
                    message += "- " + announce[i] + "\n\r";
                }
                if (announce.Count > 5)
                {
                    message += "And (" + (announce.Count - 5).ToString() + ") others";
                }
                TelegramAPI.SendMessage(this.chatID, message, null, true, -1, true);
            }
        }
        public static List<mod_steam_game> getRecentGames(string playerID)
        {
            mod_steam_core_data localData = getLocalData();
            List<mod_steam_game> games = new List<mod_steam_game>();
            NameValueCollection pairs = new NameValueCollection();
            pairs["steamid"] = playerID.ToString();
            JObject response = sendPOST(@"/IPlayerService/GetRecentlyPlayedGames/v0001/", pairs);

            foreach (JToken token in response.SelectTokens("response.games[*]"))//jo.Children()) //) records[*].data.importedPath"
            {
                //mangle this into a player object
                string gameName = "";
                string gameID = "";
                try
                {
                    //get the message details
                    gameName = token.SelectToken("name").Value<string>();
                    gameID = token.SelectToken("appid").Value<string>();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error parsing message " + e.ToString());
                }

                //try get the game from our game cache
                mod_steam_game game = localData.getGame(gameID);

                if (game == null)
                {
                    //otherwise add it
                    game = new mod_steam_game(gameID, gameName);
                }
                games.Add(game);
            }

            //make sure these are all in our local cache
            foreach (mod_steam_game g in games)
            {
                bool added = localData.tryAddGame(g);
                if (added)
                {
                    Console.WriteLine("Added game " + g.displayName + " to the list of games we know about");
                }
            }
            return games;
        }
Exemple #5
0
 public bool tryAddGame(mod_steam_game g)
 {
     if (games.Where(x => x.gameID == g.gameID ).Count() == 0 )
     {
         games.Add(g);
         return true;
     }
     else
     {
         return false;
     }
 }