Ejemplo n.º 1
0
        public static Dictionary <string, PlayerData.PlayerHistory> _LoadPlayersHistoryChunked(string _RealmPath, DateTime _HistoryEarliestDateTime)
        {
            Dictionary <string, PlayerData.PlayerHistory> loadedPlayersHistory = new Dictionary <string, PlayerData.PlayerHistory>();
            DateTime dateToLoad = DateTime.UtcNow;

            dateToLoad = dateToLoad.AddDays(15 - dateToLoad.Day); //Så att dagen ställs in på ungefär mitten av månaden för säkerhetsskull

            {                                                     ////BORDE BRYTAS UT TILL EN FUNKTION???
                Utility.LoadSerialize <Dictionary <string, PlayerData.PlayerHistory> >
                    (_RealmPath + "\\PlayersHistoryData_Now.dat", out loadedPlayersHistory);
            }////BORDE BRYTAS UT TILL EN FUNKTION???
            while (dateToLoad >= _HistoryEarliestDateTime)
            {
                if (System.IO.File.Exists(_RealmPath + "\\PlayersHistoryData_" + dateToLoad.ToString("yyyy_MM") + ".dat") == true)
                {////BORDE BRYTAS UT TILL EN FUNKTION???
                    Dictionary <string, PlayerData.PlayerHistory> extraPlayerHistory = null;
                    Utility.LoadSerialize <Dictionary <string, PlayerData.PlayerHistory> >
                        (_RealmPath + "\\PlayersHistoryData_" + dateToLoad.ToString("yyyy_MM") + ".dat", out extraPlayerHistory);

                    foreach (var playerHistory in loadedPlayersHistory)
                    {
                        PlayerData.PlayerHistory oldHistory = null;
                        if (extraPlayerHistory.TryGetValue(playerHistory.Key, out oldHistory))
                        {
                            playerHistory.Value.AddOldHistory(oldHistory);
                            extraPlayerHistory.Remove(playerHistory.Key);
                        }
                    }
                    foreach (var playerHistory in extraPlayerHistory)
                    {
                        loadedPlayersHistory.Add(playerHistory.Key, playerHistory.Value);
                    }
                }////BORDE BRYTAS UT TILL EN FUNKTION???
                dateToLoad = dateToLoad.AddMonths(-1);
            }

            if (_HistoryEarliestDateTime.Year <= 2012 && System.IO.File.Exists(_RealmPath + "\\PlayersHistoryData_ManuallyAdded.dat") == true)
            {////BORDE BRYTAS UT TILL EN FUNKTION???
                Dictionary <string, PlayerData.PlayerHistory> extraPlayerHistory = null;
                Utility.LoadSerialize <Dictionary <string, PlayerData.PlayerHistory> >
                    (_RealmPath + "\\PlayersHistoryData_ManuallyAdded.dat", out extraPlayerHistory);

                foreach (var playerHistory in loadedPlayersHistory)
                {
                    PlayerData.PlayerHistory oldHistory = null;
                    if (extraPlayerHistory.TryGetValue(playerHistory.Key, out oldHistory))
                    {
                        playerHistory.Value.AddOldHistory(oldHistory);
                        extraPlayerHistory.Remove(playerHistory.Key);
                    }
                }
                foreach (var playerHistory in extraPlayerHistory)
                {
                    loadedPlayersHistory.Add(playerHistory.Key, playerHistory.Value);
                }
            }////BORDE BRYTAS UT TILL EN FUNKTION???

            return(loadedPlayersHistory);
        }
Ejemplo n.º 2
0
        public void UpdatePlayer(System.Xml.XmlNode _PlayerNode, Contributor _Contributor, Func <int, VF.SQLUploadID> _GetSQLUploadIDFunc)
        {
            string   playerName = PlayerData.DataParser.ParsePlayerName(_PlayerNode);
            DateTime lastSeen   = PlayerData.DataParser.ParseLastSeenUTC(_PlayerNode);

            if (lastSeen > DateTime.UtcNow)
            {
                if (lastSeen > DateTime.UtcNow.AddMinutes(2))
                {
                    //Tillåt inte data som är från framtiden(wtf) flagga Contributor som opålitlig
                    _Contributor.SetWarningFlag(Contributor.WarningFlag.DataFromFuture);
                    return;
                }
                lastSeen = DateTime.UtcNow;                 //Om det är OK så sätter vi LastSeen till UtcNow istället.
            }
            if ((DateTime.UtcNow - lastSeen).TotalDays > 5) //Tillåt inte data som är äldre än 5 dagar
            {
                return;
            }
            //if (lastSeen < DATE_HONOR_CORRUPTION)// Honor corruption occured the 16th January, uncomment this line after 5 days have passed!
            //{
            //    Logger.ConsoleWriteLine("Someone submitted data that was during the Honor Corruption. Good thing i implemented this code!!!", ConsoleColor.Red);
            //    return;
            //}
            var uploadID = _Contributor.GetUploadID(lastSeen);

            PlayerData.Player        currPlayer        = GetPlayer(playerName);
            PlayerData.PlayerHistory currPlayerHistory = GetPlayerHistory(playerName);
            currPlayer.Update(_PlayerNode, uploadID, lastSeen, currPlayerHistory, WowVersion, _GetSQLUploadIDFunc);
            try
            {
                //ANVÄND INTE = tecken innuti savedvariables data!!!!!!!!! då buggar det ur totalt
                string extraData = XMLUtility.GetChildValue(_PlayerNode, "ExtraData", "");
                if (extraData != "")
                {
                    VF.SQLPlayerID playerID;
                    using (VF.SQLComm comm = new VF.SQLComm())
                    {
                        if (comm.GetPlayerID(Realm, playerName, out playerID) == false)
                        {
                            Logger.ConsoleWriteLine("Could not find SQL PlayerID for Player \"" + playerName + "\"");
                        }
                    }
                    var currPlayerExtraData = GetPlayerExtraData(playerName);
                    currPlayerExtraData.AddData(uploadID, extraData, playerID, _GetSQLUploadIDFunc);
                }
            }
            catch (NpgsqlException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }
            Updated = true;
        }
Ejemplo n.º 3
0
        public PlayerHistory ExtractOldHistory(DateTime _NewestData, bool _RemoveOld)
        {
            PlayerHistory extractedHistory = new PlayerHistory();

            extractedHistory.CharacterHistory = ExtractOldHistoryItems_T(CharacterHistory, (_Item) => { return(_Item.Uploader.GetTime() < _NewestData); }, _RemoveOld);
            extractedHistory.GuildHistory     = ExtractOldHistoryItems_T(GuildHistory, (_Item) => { return(_Item.Uploader.GetTime() < _NewestData); }, _RemoveOld);
            extractedHistory.HonorHistory     = ExtractOldHistoryItems_T(HonorHistory, (_Item) => { return(_Item.Uploader.GetTime() < _NewestData); }, _RemoveOld);
            extractedHistory.GearHistory      = ExtractOldHistoryItems_T(GearHistory, (_Item) => { return(_Item.Uploader.GetTime() < _NewestData); }, _RemoveOld);
            if (ArenaHistory != null)
            {
                extractedHistory.ArenaHistory = ExtractOldHistoryItems_T(ArenaHistory, (_Item) => { return(_Item.Uploader.GetTime() < _NewestData); }, _RemoveOld);
            }
            if (TalentsHistory != null)
            {
                extractedHistory.TalentsHistory = ExtractOldHistoryItems_T(TalentsHistory, (_Item) => { return(_Item.Uploader.GetTime() < _NewestData); }, _RemoveOld);
            }
            return(extractedHistory);
        }
Ejemplo n.º 4
0
        //public void Update(string _PlayerName, PlayerData.Player _PlayerData)
        //{
        //    GuildPlayerStatusHistory playerGuildHistory = null;
        //    if (m_Players.TryGetValue(_PlayerName, out playerGuildHistory) == false)
        //        playerGuildHistory = null;

        //    if (_PlayerData.Guild.GuildName == m_GuildName)
        //    {
        //        playerGuildHistory = new GuildPlayerStatusHistory(_PlayerName);
        //        playerGuildHistory.InitCache(this);
        //        m_Players.Add(_PlayerName, playerGuildHistory);
        //        playerGuildHistory.SetGuildData(_PlayerData.Guild, _PlayerData.LastSeen);

        //        if (m_Faction == Faction.Unknown)
        //        {
        //            m_Faction = VF_RealmPlayersDatabase.StaticValues.GetFaction(_PlayerData.Character.Race);
        //        }
        //    }
        //    else if (playerGuildHistory != null)
        //    {
        //        playerGuildHistory.SetNotInGuild(_PlayerData.LastSeen);
        //    }
        //}
        public void Update(string _PlayerName, PlayerData.PlayerHistory _PlayerData, DateTime _EarliestDateTime)
        {
            GuildPlayerStatusHistory playerGuildHistory = null;

            if (m_Players.TryGetValue(_PlayerName, out playerGuildHistory) == false)
            {
                playerGuildHistory = null;
            }

            for (int i = 0; i < _PlayerData.GuildHistory.Count; ++i)
            {
                var guildHistory = _PlayerData.GuildHistory[i];
                if (guildHistory.Uploader.GetTime() < _EarliestDateTime)
                {
                    continue;
                }

                if (guildHistory.Data.GuildName == m_GuildName)
                {
                    if (playerGuildHistory == null)
                    {
                        if (m_Players.TryGetValue(_PlayerName, out playerGuildHistory) == false)
                        {
                            playerGuildHistory = new GuildPlayerStatusHistory(_PlayerName);
                            playerGuildHistory.InitCache(this);
                            m_Players.Add(_PlayerName, playerGuildHistory);

                            if (m_Faction == Faction.Unknown || (DateTime.UtcNow - guildHistory.Uploader.GetTime()).TotalDays < 14)
                            {
                                if (_PlayerData.CharacterHistory.Count > 0)
                                {
                                    m_Faction = VF_RealmPlayersDatabase.StaticValues.GetFaction(_PlayerData.GetCharacterItemAtTime(guildHistory.Uploader.GetTime()).Data.Race);
                                }
                            }
                        }
                    }
                    playerGuildHistory.SetGuildData(guildHistory.Data, guildHistory.Uploader.GetTime());
                }
                else if (playerGuildHistory != null)
                {
                    playerGuildHistory.SetNotInGuild(guildHistory.Uploader.GetTime());
                }
            }
        }
Ejemplo n.º 5
0
 public void AddOldHistory(PlayerHistory _OldHistory)
 {
     AddOldHistoryItems_T(CharacterHistory, _OldHistory.CharacterHistory, CharacterDataHistoryItem.Time1BiggerThan2);
     AddOldHistoryItems_T(GuildHistory, _OldHistory.GuildHistory, GuildDataHistoryItem.Time1BiggerThan2);
     AddOldHistoryItems_T(HonorHistory, _OldHistory.HonorHistory, HonorDataHistoryItem.Time1BiggerThan2);
     AddOldHistoryItems_T(GearHistory, _OldHistory.GearHistory, GearDataHistoryItem.Time1BiggerThan2);
     if (_OldHistory.ArenaHistory != null)
     {
         if (ArenaHistory == null)
         {
             ArenaHistory = new List <ArenaDataHistoryItem>();
         }
         AddOldHistoryItems_T(ArenaHistory, _OldHistory.ArenaHistory, ArenaDataHistoryItem.Time1BiggerThan2);
     }
     if (_OldHistory.TalentsHistory != null)
     {
         if (TalentsHistory == null)
         {
             TalentsHistory = new List <TalentsDataHistoryItem>();
         }
         AddOldHistoryItems_T(TalentsHistory, _OldHistory.TalentsHistory, TalentsDataHistoryItem.Time1BiggerThan2);
     }
 }
Ejemplo n.º 6
0
 public void Update(string _PlayerName, PlayerData.PlayerHistory _PlayerData)
 {
     Update(_PlayerName, _PlayerData, DateTime.MinValue);
 }
Ejemplo n.º 7
0
        public bool Update(System.Xml.XmlNode _PlayerNode, UploadID _Uploader /*Contains LastSeen*/, DateTime _LastSeen, PlayerHistory _PlayerHistory, WowVersionEnum _WowVersion)
        {
            var newCharacter = new PlayerData.CharacterData(_PlayerNode);
            var newGuild     = new PlayerData.GuildData(_PlayerNode);
            var newGear      = new PlayerData.GearData(_PlayerNode, _WowVersion);
            var newHonor     = new PlayerData.HonorData(_PlayerNode, _WowVersion);

            if (newGear.Items.Count == 0 && newGuild.GuildName == "nil" && newGuild.GuildRank == "nil" && newHonor.CurrentRank == 0 && _WowVersion == WowVersionEnum.Vanilla)
            {
                return(true);
            }

            PlayerData.ArenaData newArena = null;
            string newTalentPointsData    = null;

            if (_WowVersion == WowVersionEnum.TBC)
            {
                newArena = new PlayerData.ArenaData(_PlayerNode);
                _PlayerHistory.AddToHistory(newArena, _Uploader);
                newTalentPointsData = XMLUtility.GetChildValue(_PlayerNode, "TalentsData", "");
                _PlayerHistory.AddTalentsToHistory(newTalentPointsData, _Uploader);
            }

            _PlayerHistory.AddToHistory(newCharacter, _Uploader);
            _PlayerHistory.AddToHistory(newGuild, _Uploader);
            if (newGear.Items.Count > 0)
            {
                _PlayerHistory.AddToHistory(newGear, _Uploader);
            }
            _PlayerHistory.AddToHistory(newHonor, _Uploader);
            if (_LastSeen > LastSeen)
            {
                Uploader  = _Uploader;
                LastSeen  = _LastSeen;
                Character = newCharacter;
                Guild     = newGuild;
                if (newGear.Items.Count > 0)
                {
                    Gear = newGear;
                }
                Honor            = newHonor;
                Arena            = newArena;
                TalentPointsData = newTalentPointsData;
                return(false);
            }

            return(true);
        }
Ejemplo n.º 8
0
        public bool IsEqual(PlayerHistory _PlayerHistory)
        {
            if (CharacterHistory.Count != _PlayerHistory.CharacterHistory.Count ||
                GuildHistory.Count != _PlayerHistory.GuildHistory.Count ||
                HonorHistory.Count != _PlayerHistory.HonorHistory.Count ||
                GearHistory.Count != _PlayerHistory.GearHistory.Count ||
                (ArenaHistory == null && _PlayerHistory.ArenaHistory != null) ||
                (ArenaHistory != null && _PlayerHistory.ArenaHistory == null) ||
                (ArenaHistory != null && _PlayerHistory.ArenaHistory != null && ArenaHistory.Count != _PlayerHistory.ArenaHistory.Count) ||
                (TalentsHistory == null && _PlayerHistory.TalentsHistory != null) ||
                (TalentsHistory != null && _PlayerHistory.TalentsHistory == null) ||
                (TalentsHistory != null && _PlayerHistory.TalentsHistory != null && TalentsHistory.Count != _PlayerHistory.TalentsHistory.Count))
            {
                return(false);
            }

            for (int i = 0; i < CharacterHistory.Count; ++i)
            {
                if (CharacterHistory[i].Data.IsSame(_PlayerHistory.CharacterHistory[i].Data) == false)
                {
                    return(false);
                }
                if (CharacterHistory[i].Uploader.GetTime() != _PlayerHistory.CharacterHistory[i].Uploader.GetTime() ||
                    CharacterHistory[i].Uploader.GetContributorID() != _PlayerHistory.CharacterHistory[i].Uploader.GetContributorID())
                {
                    return(false);
                }
            }
            for (int i = 0; i < GuildHistory.Count; ++i)
            {
                if (GuildHistory[i].Data.IsSame(_PlayerHistory.GuildHistory[i].Data) == false)
                {
                    return(false);
                }
                if (GuildHistory[i].Uploader.GetTime() != _PlayerHistory.GuildHistory[i].Uploader.GetTime() ||
                    GuildHistory[i].Uploader.GetContributorID() != _PlayerHistory.GuildHistory[i].Uploader.GetContributorID())
                {
                    return(false);
                }
            }
            for (int i = 0; i < HonorHistory.Count; ++i)
            {
                if (HonorHistory[i].Data.IsSame(_PlayerHistory.HonorHistory[i].Data) == false)
                {
                    return(false);
                }
                if (HonorHistory[i].Uploader.GetTime() != _PlayerHistory.HonorHistory[i].Uploader.GetTime() ||
                    HonorHistory[i].Uploader.GetContributorID() != _PlayerHistory.HonorHistory[i].Uploader.GetContributorID())
                {
                    return(false);
                }
            }
            for (int i = 0; i < GearHistory.Count; ++i)
            {
                if (GearHistory[i].Data.IsSame(_PlayerHistory.GearHistory[i].Data) == false)
                {
                    return(false);
                }
                if (GearHistory[i].Uploader.GetTime() != _PlayerHistory.GearHistory[i].Uploader.GetTime() ||
                    GearHistory[i].Uploader.GetContributorID() != _PlayerHistory.GearHistory[i].Uploader.GetContributorID())
                {
                    return(false);
                }
            }
            if (ArenaHistory != null)
            {
                for (int i = 0; i < ArenaHistory.Count; ++i)
                {
                    if (ArenaHistory[i].Data.IsSame(_PlayerHistory.ArenaHistory[i].Data) == false)
                    {
                        return(false);
                    }
                    if (ArenaHistory[i].Uploader.GetTime() != _PlayerHistory.ArenaHistory[i].Uploader.GetTime() ||
                        ArenaHistory[i].Uploader.GetContributorID() != _PlayerHistory.ArenaHistory[i].Uploader.GetContributorID())
                    {
                        return(false);
                    }
                }
            }
            if (TalentsHistory != null)
            {
                for (int i = 0; i < TalentsHistory.Count; ++i)
                {
                    if (TalentsHistory[i].Data != _PlayerHistory.TalentsHistory[i].Data)
                    {
                        return(false);
                    }
                    if (TalentsHistory[i].Uploader.GetTime() != _PlayerHistory.TalentsHistory[i].Uploader.GetTime() ||
                        TalentsHistory[i].Uploader.GetContributorID() != _PlayerHistory.TalentsHistory[i].Uploader.GetContributorID())
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 9
0
        public void UpdatePlayer(System.Xml.XmlNode _PlayerNode, Contributor _Contributor, Func <int, VF.SQLUploadID> _GetSQLUploadIDFunc)
        {
            string   playerName = PlayerData.DataParser.ParsePlayerName(_PlayerNode);
            DateTime lastSeen   = PlayerData.DataParser.ParseLastSeenUTC(_PlayerNode);

            if (lastSeen > DateTime.UtcNow)
            {
                if (lastSeen > DateTime.UtcNow.AddMinutes(2))
                {
                    //Tillåt inte data som är från framtiden(wtf) flagga Contributor som opålitlig
                    _Contributor.SetWarningFlag(Contributor.WarningFlag.DataFromFuture);
                    return;
                }
                lastSeen = DateTime.UtcNow;                                                        //Om det är OK så sätter vi LastSeen till UtcNow istället.
            }
            if ((DateTime.UtcNow - lastSeen).TotalDays > 5)                                        //Tillåt inte data som är äldre än 5 dagar
            {
                if (Realm == WowRealm.Northdale && lastSeen < new DateTime(2018, 6, 23, 12, 0, 0)) //Do not allow inspects before server even opened...
                {
                    return;
                }
                if (DateTime.UtcNow < new DateTime(2018, 9, 1) && lastSeen > new DateTime(2018, 4, 1))
                {
                    //Special case, allow this! We are temporary allowing adding some old data!
                }
                else
                {
                    return;
                }
            }
            //if (lastSeen < DATE_HONOR_CORRUPTION)// Honor corruption occured the 16th January, uncomment this line after 5 days have passed!
            //{
            //    Logger.ConsoleWriteLine("Someone submitted data that was during the Honor Corruption. Good thing i implemented this code!!!", ConsoleColor.Red);
            //    return;
            //}
            var uploadID = _Contributor.GetUploadID(lastSeen);

            PlayerData.Player        currPlayer        = GetPlayer(playerName);
            PlayerData.PlayerHistory currPlayerHistory = GetPlayerHistory(playerName);
            currPlayer.Update(_PlayerNode, uploadID, lastSeen, currPlayerHistory, WowVersion, _GetSQLUploadIDFunc);
            try
            {
                //ANVÄND INTE = tecken innuti savedvariables data!!!!!!!!! då buggar det ur totalt
                string extraData = XMLUtility.GetChildValue(_PlayerNode, "ExtraData", "");
                if (extraData != "")
                {
#if UPDATE_SQL_DB
                    VF.SQLPlayerID playerID;
                    using (VF.SQLComm comm = new VF.SQLComm())
                    {
                        if (comm.GetPlayerID(Realm, playerName, out playerID) == false)
                        {
                            Logger.ConsoleWriteLine("Could not find SQL PlayerID for Player \"" + playerName + "\"");
                        }
                    }
                    var currPlayerExtraData = GetPlayerExtraData(playerName);
                    currPlayerExtraData.AddData(uploadID, extraData, playerID, _GetSQLUploadIDFunc);
#else
                    if (_GetSQLUploadIDFunc != null)
                    {
                        while (true)
                        {
                            Console.WriteLine("ERROR, SQL USAGE CONFUSION"); System.Threading.Thread.Sleep(5000);
                        }
                    }
                    var currPlayerExtraData = GetPlayerExtraData(playerName);
                    currPlayerExtraData.AddData(uploadID, extraData, null, null);
#endif
                }
            }
            catch (NpgsqlException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }
            Updated = true;
        }
Ejemplo n.º 10
0
        public bool Update(System.Xml.XmlNode _PlayerNode, UploadID _Uploader /*Contains LastSeen*/, DateTime _LastSeen, PlayerHistory _PlayerHistory, WowVersionEnum _WowVersion, Func <int, VF.SQLUploadID> _GetSQLUploadIDFunc = null)
        {
            var newCharacter = new PlayerData.CharacterData(_PlayerNode);
            var newGuild     = new PlayerData.GuildData(_PlayerNode);
            var newGear      = new PlayerData.GearData(_PlayerNode, _WowVersion);
            var newHonor     = new PlayerData.HonorData(_PlayerNode, _WowVersion);

            if (newGear.Items.Count == 0 && newGuild.GuildName == "nil" && newGuild.GuildRank == "nil" && newHonor.CurrentRank == 0 && _WowVersion == WowVersionEnum.Vanilla)
            {
                return(true);
            }

            PlayerData.ArenaData newArena = null;
            string newTalentPointsData    = null;

            if (_WowVersion == WowVersionEnum.TBC)
            {
                newArena            = new PlayerData.ArenaData(_PlayerNode);
                newTalentPointsData = XMLUtility.GetChildValue(_PlayerNode, "TalentsData", "");
            }
            if (_GetSQLUploadIDFunc != null)
            {
                UpdateSQL(_GetSQLUploadIDFunc, Uploader, _LastSeen, _PlayerHistory, _WowVersion, newCharacter, newGuild, newGear, newHonor, newArena, newTalentPointsData);
            }
            return(Update(_Uploader, _LastSeen, _PlayerHistory, _WowVersion, newCharacter, newGuild, newGear, newHonor, newArena, newTalentPointsData));
        }
Ejemplo n.º 11
0
        public bool Update(UploadID _Uploader /*Contains LastSeen*/, DateTime _LastSeen, PlayerHistory _PlayerHistory, WowVersionEnum _WowVersion
                           , PlayerData.CharacterData _NewCharacter, PlayerData.GuildData _NewGuild, PlayerData.GearData _NewGear, PlayerData.HonorData _NewHonor, PlayerData.ArenaData _NewArena = null, string _NewTalents = null)
        {
            if (_WowVersion == WowVersionEnum.TBC)
            {
                if (_NewArena != null)
                {
                    _PlayerHistory.AddToHistory(_NewArena, _Uploader);
                }
                if (_NewTalents != null)
                {
                    _PlayerHistory.AddTalentsToHistory(_NewTalents, _Uploader);
                }
            }

            _PlayerHistory.AddToHistory(_NewCharacter, _Uploader);
            _PlayerHistory.AddToHistory(_NewGuild, _Uploader);
            if (_NewGear.Items.Count > 0)
            {
                _PlayerHistory.AddToHistory(_NewGear, _Uploader);
            }
            _PlayerHistory.AddToHistory(_NewHonor, _Uploader);
            if (_LastSeen > LastSeen)
            {
                Uploader  = _Uploader;
                LastSeen  = _LastSeen;
                Character = _NewCharacter;
                Guild     = _NewGuild;
                if (_NewGear.Items.Count > 0)
                {
                    Gear = _NewGear;
                }
                Honor            = _NewHonor;
                Arena            = _NewArena;
                TalentPointsData = _NewTalents;
                return(false);
            }

            return(true);
        }
Ejemplo n.º 12
0
        public void UpdateSQL(Func <int, VF.SQLUploadID> _GetSQLUploadIDFunc, UploadID _Uploader /*Contains LastSeen*/, DateTime _LastSeen, PlayerHistory _PlayerHistory, WowVersionEnum _WowVersion
                              , PlayerData.CharacterData _NewCharacter, PlayerData.GuildData _NewGuild, PlayerData.GearData _NewGear, PlayerData.HonorData _NewHonor, PlayerData.ArenaData _NewArena = null, string _NewTalents = null)
        {
            using (VF.SQLComm comm = new VF.SQLComm())
            {
                VF.SQLPlayerData playerData      = VF.SQLPlayerData.Invalid();
                bool             validPlayerData = false;

                VF.SQLPlayerID playerID;
                bool           validPlayerID = false;
                if (comm.GetPlayerID(Realm, Name, out playerID) == true)
                {
                    validPlayerID = true;
                    if (_LastSeen < LastSeen)
                    {
                        if (comm.GetPlayerDataAtTime(playerID, _LastSeen, out playerData) == true)
                        {
                            validPlayerData = true;
                        }
                    }

                    if (validPlayerData == false)
                    {
                        if (comm.GetLatestPlayerData(playerID, out playerData) == true)
                        {
                            validPlayerData = true;
                        }
                    }
                }

                if (validPlayerData == true)
                {
                    bool playerDataChanged = false;
                    if (playerData.PlayerCharacter.IsSame(_NewCharacter) == false)
                    {
                        playerData.PlayerCharacter = _NewCharacter;
                        playerDataChanged          = true;
                    }

                    PlayerData.GuildData playerDataGuildData;
                    if (comm.GetPlayerGuildData(playerData, out playerDataGuildData) == true)
                    {
                        if (playerDataGuildData.IsSame(_NewGuild) == false)
                        {
                            playerData.PlayerGuildID = comm.GenerateNewPlayerGuildDataEntry(_NewGuild);
                            playerDataChanged        = true;
                        }
                    }
                    else if (playerData.PlayerGuildID == 0)
                    {
                        playerData.PlayerGuildID = comm.GenerateNewPlayerGuildDataEntry(_NewGuild);
                        if (playerData.PlayerGuildID != 0)
                        {
                            playerDataChanged = true;
                        }
                    }

                    PlayerData.GearData playerDataGearData;
                    if (comm.GetPlayerGearData(playerData, out playerDataGearData) == true)
                    {
                        if (playerDataGearData.IsSame(_NewGear) == false)
                        {
                            playerData.PlayerGearID = comm.GenerateNewPlayerGearDataEntry(_NewGear, _WowVersion);
                            playerDataChanged       = true;
                        }
                    }
                    else if (playerData.PlayerGearID == 0)
                    {
                        playerData.PlayerGearID = comm.GenerateNewPlayerGearDataEntry(_NewGear, _WowVersion);
                        if (playerData.PlayerGearID != 0)
                        {
                            playerDataChanged = true;
                        }
                    }

                    PlayerData.HonorData playerDataHonorData;
                    if (comm.GetPlayerHonorData(playerData, out playerDataHonorData) == true)
                    {
                        if (playerDataHonorData.IsSame(_NewHonor, _WowVersion) == false)
                        {
                            playerData.PlayerHonorID = comm.GenerateNewPlayerHonorDataEntry(_NewHonor, _WowVersion);
                            playerDataChanged        = true;
                        }
                    }
                    else if (playerData.PlayerHonorID == 0)
                    {
                        playerData.PlayerHonorID = comm.GenerateNewPlayerHonorDataEntry(_NewHonor, _WowVersion);
                        if (playerData.PlayerHonorID != 0)
                        {
                            playerDataChanged = true;
                        }
                    }

                    if (_WowVersion == WowVersionEnum.TBC)
                    {
                        PlayerData.ArenaData playerDataArenaData;
                        if (comm.GetPlayerArenaData(playerData, out playerDataArenaData) == true)
                        {
                            if (playerDataArenaData.IsSame(_NewArena) == false)
                            {
                                playerData.PlayerArenaID = comm.GenerateNewPlayerArenaInfoEntry(_NewArena);
                                playerDataChanged        = true;
                            }
                        }
                        else if (playerData.PlayerArenaID == 0)
                        {
                            playerData.PlayerArenaID = comm.GenerateNewPlayerArenaInfoEntry(_NewArena);
                            if (playerData.PlayerArenaID != 0)
                            {
                                playerDataChanged = true;
                            }
                        }

                        string playerDataTalentsData;
                        if (comm.GetPlayerTalentsData(playerData, out playerDataTalentsData) == true)
                        {
                            if (playerDataTalentsData == _NewTalents)
                            {
                                playerData.PlayerTalentsID = comm.GenerateNewPlayerTalentsDataEntry(_NewTalents);
                                playerDataChanged          = true;
                            }
                        }
                        else if (playerData.PlayerTalentsID == 0)
                        {
                            playerData.PlayerTalentsID = comm.GenerateNewPlayerTalentsDataEntry(_NewTalents);
                            if (playerData.PlayerTalentsID != 0)
                            {
                                playerDataChanged = true;
                            }
                        }
                    }

                    if (playerDataChanged == true)
                    {
                        playerData.UpdateTime = _LastSeen;
                        playerData.UploadID   = _GetSQLUploadIDFunc(0);

                        if (comm.GenerateNewPlayerDataEntry(playerData) == false)
                        {
                            Logger.ConsoleWriteLine("Failed to update PlayerData for player \"" + Name + "\"", ConsoleColor.Red);
                        }

                        if (_LastSeen > LastSeen)
                        {
                            //Also update the latestupdateid in playertable since this is the latest available data!
                            if (comm.UpdatePlayerEntry(playerData.PlayerID, playerData.UploadID) == false)
                            {
                                Logger.ConsoleWriteLine("Failed to update LatestUploadID for player \"" + Name + "\"", ConsoleColor.Red);
                            }
                        }
                    }
                }
                else
                {
                    Player newPlayer = new Player();
                    newPlayer.Name             = Name;
                    newPlayer.Realm            = Realm;
                    newPlayer.Character        = _NewCharacter;
                    newPlayer.Guild            = _NewGuild;
                    newPlayer.Gear             = _NewGear;
                    newPlayer.Honor            = _NewHonor;
                    newPlayer.Arena            = _NewArena;
                    newPlayer.TalentPointsData = _NewTalents;
                    newPlayer.LastSeen         = _LastSeen;

                    //Assume PlayerID did not exist!!!
                    if (validPlayerID == true)
                    {
                        //OK PlayerID exists, so maybe this is just an earlier data than currently exists at all for player.
                        //This case should be handled above though, so if this happens something is very weird and unexpected!
                        //This issue can be resolved automatically, it should never happen normally. But if it does...
                        Logger.ConsoleWriteLine("Unexpected problem when updating PlayerData for player \"" + Name + "\"", ConsoleColor.Red);
                        if (comm.UpdateLatestPlayerDataEntry(playerID, _GetSQLUploadIDFunc(0), newPlayer).ID == playerID.ID)
                        {
                            Logger.ConsoleWriteLine("Unexpected problem was resolved successfully!", ConsoleColor.Green);
                        }
                        else
                        {
                            Logger.ConsoleWriteLine("\n--------------------------------------------\nERROR ERROR ERRO ERROR ERROR\nWhen attempting to fix unexpected problem for player \"" + Name + "\" it did not work!!!\n--------------------------------------------\n", ConsoleColor.Red);
                        }
                    }
                    else
                    {
                        if (comm.GenerateNewPlayerEntry(_GetSQLUploadIDFunc(0), newPlayer).IsValid() == false)
                        {
                            Logger.ConsoleWriteLine("Unexpected problem when creating new SQLPlayerID for player \"" + Name + "\"", ConsoleColor.Red);
                        }
                    }
                }
            }
        }