示例#1
0
        public void GenerateCache(Dictionary <string, PlayerData.Player> _RealmDB, bool _ForceGenerate = false)
        {
            if (_RealmDB == null)
            {
                return;
            }

            if (m_MembersGenerated == true)
            {
                if (_ForceGenerate == false)
                {
                    return;
                }
            }
            List <Tuple <PlayerData.Player, GuildPlayerStatusHistory> > membersArray = new List <Tuple <PlayerData.Player, GuildPlayerStatusHistory> >();

            foreach (var guildPlayer in m_Players)
            {
                if (guildPlayer.Value.IsInGuild == true)
                {
                    PlayerData.Player currPlayer = null;
                    if (_RealmDB.TryGetValue(guildPlayer.Value.PlayerName, out currPlayer) == true)
                    {
                        if ((DateTime.UtcNow - currPlayer.Uploader.GetTime()).Days < 31)
                        {
                            membersArray.Add(Tuple.Create(currPlayer, guildPlayer.Value));
                        }
                    }
                }
            }
            m_MembersArray     = membersArray;
            m_MembersGenerated = true;
        }
示例#2
0
        public SQLPlayerID GenerateNewPlayerEntry(SQLUploadID _UploadID, PlayerData.Player _PlayerData)
        {
            WowVersionEnum wowVersion = VF_RealmPlayersDatabase.StaticValues.GetWowVersion(_PlayerData.Realm);
            SQLPlayerID    playerID   = new SQLPlayerID();
            var            conn       = OpenConnection();

            try
            {
                using (var cmd = new NpgsqlCommand("INSERT INTO playertable(id, name, realm, latestuploadid) VALUES (DEFAULT, :Name, :Realm, :LatestUploadID) RETURNING id", conn))
                {
                    cmd.Parameters.Add(new NpgsqlParameter("Name", NpgsqlDbType.Text)).Value              = _PlayerData.Name;
                    cmd.Parameters.Add(new NpgsqlParameter("Realm", NpgsqlDbType.Integer)).Value          = (int)_PlayerData.Realm;
                    cmd.Parameters.Add(new NpgsqlParameter("LatestUploadID", NpgsqlDbType.Integer)).Value = (int)0;
                    using (var reader = cmd.ExecuteReader())
                    {
                        if (reader.Read() == true)
                        {
                            playerID = new SQLPlayerID(reader.GetInt32(0));
                        }
                    }
                }
            }
            finally
            {
                CloseConnection();
            }

            if (playerID.IsValid() == false)
            {
                return(playerID);
            }

            return(UpdateLatestPlayerDataEntry(playerID, _UploadID, _PlayerData));
        }
示例#3
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;
        }
示例#4
0
 public bool FindPlayerAtTime(string _Name, DateTime _DateTime, out PlayerData.Player _RetPlayer)
 {
     _RetPlayer = null;
     try
     {
         PlayerData.PlayerHistory playerHistory;
         if (PlayersHistory.TryGetValue(_Name, out playerHistory))
         {
             return(playerHistory.GetPlayerAtTime(_Name, Realm, _DateTime, out _RetPlayer));
         }
         return(false);
     }
     catch (Exception)
     {}
     return(false);
 }
示例#5
0
        public SQLPlayerID UpdateLatestPlayerDataEntry(SQLPlayerID _PlayerID, SQLUploadID _UploadID, PlayerData.Player _PlayerData)
        {
            WowVersionEnum wowVersion = VF_RealmPlayersDatabase.StaticValues.GetWowVersion(_PlayerData.Realm);
            SQLPlayerData  playerData = new SQLPlayerData();

            playerData.PlayerID        = _PlayerID;
            playerData.UploadID        = _UploadID;
            playerData.UpdateTime      = _PlayerData.LastSeen;
            playerData.PlayerCharacter = _PlayerData.Character;
            playerData.PlayerGuildID   = GenerateNewPlayerGuildDataEntry(_PlayerData.Guild);
            playerData.PlayerHonorID   = GenerateNewPlayerHonorDataEntry(_PlayerData.Honor, wowVersion);
            playerData.PlayerGearID    = GenerateNewPlayerGearDataEntry(_PlayerData.Gear, wowVersion);
            if (wowVersion != WowVersionEnum.Vanilla)
            {
                playerData.PlayerArenaID   = GenerateNewPlayerArenaInfoEntry(_PlayerData.Arena);
                playerData.PlayerTalentsID = GenerateNewPlayerTalentsDataEntry(_PlayerData.TalentPointsData);
            }
            else
            {
                playerData.PlayerArenaID   = 0;
                playerData.PlayerTalentsID = 0;
            }
            if (GenerateNewPlayerDataEntry(playerData) == true)
            {
                if (UpdatePlayerEntry(playerData.PlayerID, playerData.UploadID) == false)
                {
                    VF_RealmPlayersDatabase.Logger.ConsoleWriteLine("Error in UpdateLatestPlayerDataEntry, could not UpdatePlayerEntry!!!");
                    return(SQLPlayerID.Invalid());
                }
            }
            else
            {
                VF_RealmPlayersDatabase.Logger.ConsoleWriteLine("Error in UpdateLatestPlayerDataEntry, could not GenerateNewPlayerDataEntry!!!");
                return(SQLPlayerID.Invalid());
            }
            return(_PlayerID);
        }
示例#6
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;
        }