Пример #1
0
        private static bool GetOlderMatchesPerPlayer(long steamID64)
        {
            Dota2DataMiner.Class1 d2Dm = new Dota2DataMiner.Class1();

            PlayersList playersList = new PlayersList();
            int matchID = 0;
            // Make sure there is older matches to find.
            if (playersList.LastMatchFound(steamID64, out matchID))
                return false;

            // Check for and Recover Local Data.
            d2Dm.GetMatchPerPlayerLocalData(steamID64, matchID);

            // Check if System Config permits this method call.
            SystemConfig systemConfig = new SystemConfig();
            systemConfig.GetByKey("GetOlderMatchesPerPlayer");

            if (systemConfig.RecordExists)
            {
                if (DateTime.Now < Convert.ToDateTime(systemConfig.SCValue).AddSeconds(1))
                    return true;
            }
            else
            {
                systemConfig.SCKey = "GetOlderMatchesPerPlayer";
            }

            // Get or Create SteamRequest
            SteamRequests steamRequests;
            GetSteamRequest(out steamRequests);

            // Check if API can be used else return
            if (DateTime.Now < steamRequests.LastUpdated.AddSeconds(1))
                return true;

            // Increment the Steam Request Counter
            Console.WriteLine("Steam request number : " + steamRequests.RequestNumber + " - Get Older Matches Per Player");
            steamRequests.RequestNumber++;
            steamRequests.LastUpdated = DateTime.Now;
            steamRequests.InsertOrUpdate();

            Players player = new Players();

            // Get Live Data.
            try
            {
                if (!d2Dm.GetMatchPerPlayer(steamID64, matchID, "GetOlderMatchesPerPlayer", systemConfig))
                {
                    if (!QuiteMode)
                        Console.WriteLine("Oldest Player match found.");

                    player.GetBySteamID64(steamID64);
                    player.OldestMatchFound = true;
                    player.Update();
                }

                systemConfig.SCValue = DateTime.Now.ToString();
                systemConfig.InsertOrUpdate();
            }
            catch (Exception)
            {
                steamRequests.RequestNumber--;
                steamRequests.InsertOrUpdate();
            }

            if (player.RecordExists && player.OldestMatchFound)
                return false;
            else
                return true;
        }
Пример #2
0
        private bool GetMatchs(XmlDocument response, long steamId64, int recordMatchID)
        {
            bool lastMatch = false;
            bool newPlayersAdded = false;

            foreach (XmlNode subRootNode in response.DocumentElement.ChildNodes)
            {
                if (subRootNode.Name == "status" && subRootNode.InnerText == "15")
                {

                    Players player = new Players();
                    player.GetBySteamID64(steamId64);

                    if (player.RecordExists)
                    {
                        if (!QuiteMode)
                            Console.WriteLine(player.PersonaName + " likes his/her privacy.");
                        player.IsPrivate = true;
                        // Not really updating the player, more of testing his private. *snicker*
                        //player.LastUpdated = DateTime.Now;
                        player.InsertOrUpdate();
                    }
                    else
                    {
                        if (!QuiteMode)
                            Console.WriteLine("ID: " + steamId64 + " likes his/her privacy.");
                    }
                    return true;
                }

                if (subRootNode.Name == "results_remaining" && subRootNode.InnerText == "0")
                    lastMatch = true;

                if (subRootNode.Name == "matches")
                {
                    foreach (XmlNode matchNode in subRootNode)
                    {
                        Matches matches = new Matches();
                        if (matchNode["match_id"] != null)
                        {
                            int matchID = Convert.ToInt32(matchNode["match_id"].InnerText);
                            matches.LoadItem(matchID);
                            if (!matches.RecordExists)
                            {
                                matches = new Matches();
                            }
                        }
                        else
                        {
                            matches = new Matches();
                        }

                        if (matchNode["match_id"] != null)
                            matches.ID = Convert.ToInt32(matchNode["match_id"].InnerText);

                        if (matchNode["match_seq_num"] != null)
                            matches.SequenceNumber = Convert.ToInt32(matchNode["match_seq_num"].InnerText);

                        if (matchNode["start_time"] != null)
                            matches.StartTime = UnixTimeStampToDateTime(Convert.ToDouble(matchNode["start_time"].InnerText));

                        if (matchNode["lobby_type"] != null)
                            matches.LobbyType = Convert.ToInt32(matchNode["lobby_type"].InnerText);

                        matches.InsertOrUpdate();
                        if (!QuiteMode)
                            Console.WriteLine("Match Found: " + matches.ID + "; Sequence Number: " + matches.SequenceNumber + "; Start Time: " + matches.StartTime.ToString());

                        if (matchNode["players"] != null)
                        {
                            MatchPlayerList matchPlayerList = new MatchPlayerList();
                            foreach (XmlNode playerNode in matchNode["players"])
                            {
                                MatchPlayer matchPlayer = new MatchPlayer();

                                if (playerNode["account_id"] == null)
                                {
                                    //BOT
                                    matchPlayer.GetByMatchSlot(matches.ID, Convert.ToInt32(playerNode["player_slot"].InnerText));

                                    if (!matchPlayer.RecordExists)
                                    {
                                        matchPlayer.Match = matches.ID;
                                        matchPlayer.Player = -1;
                                        matchPlayer.Player64 = -1;
                                        matchPlayer.Slot = Convert.ToInt32(playerNode["player_slot"].InnerText);
                                        matchPlayer.Hero = Convert.ToInt32(playerNode["hero_id"].InnerText);
                                        matchPlayerList.Add(matchPlayer);

                                        if (!QuiteMode)
                                            Console.WriteLine("Player: " + matchPlayer.Player64 + "; Playing hero: " +
                                                              matchPlayer.Hero);
                                    }
                                }
                                else
                                {
                                    matchPlayer.GetByMatchPlayer64(matches.ID,
                                                                   Convert.ToInt64(playerNode["account_id"].InnerText));

                                    if (!matchPlayer.RecordExists)
                                    {
                                        matchPlayer.Match = matches.ID;
                                        matchPlayer.Player64 = Convert.ToInt64(playerNode["account_id"].InnerText);
                                        matchPlayer.Slot = Convert.ToInt32(playerNode["player_slot"].InnerText);
                                        matchPlayer.Hero = Convert.ToInt32(playerNode["hero_id"].InnerText);
                                        matchPlayerList.Add(matchPlayer);

                                        if (!QuiteMode)
                                            Console.WriteLine("Player: " + matchPlayer.Player64 + "; Playing hero: " +
                                                              matchPlayer.Hero);

                                        //Players player = new Players();
                                        //player.GetBySteamID64((long)matchPlayer.Player64);

                                        //if (!player.RecordExists)
                                        //{
                                        //    Console.WriteLine("; NOT FOUND!");
                                        //    // Shit shit the player doesn't exist and I've already used this seconds request!
                                        //    // Make a plan!
                                        //}
                                        //Console.WriteLine("");
                                    }
                                }
                            }
                            matchPlayerList.UpdateAll();
                        }

                        newPlayersAdded = true;
                    }
                }
            }

            if (lastMatch)
            {
                Players playersLastMatch = new Players();
                playersLastMatch.GetBySteamID64(steamId64);
                playersLastMatch.OldestMatchFound = true;
                playersLastMatch.InsertOrUpdate();
            }

            if (File.Exists("GetMatchPerPlayer" + steamId64.ToString() + (recordMatchID != 0 ? recordMatchID.ToString() : "") + "(" +
                              DateTime.Now.ToString("ddMMyyyy") + ").xml"))
            {
                File.Delete("GetMatchPerPlayer" + steamId64.ToString() + (recordMatchID != 0 ? recordMatchID.ToString() : "") + "(" +
                              DateTime.Now.ToString("ddMMyyyy") + ").xml");
            }

            return newPlayersAdded;
        }