예제 #1
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;
        }
예제 #2
0
        public void AddContribution(RPPContribution _Contribution)
        {
            int loggedExceptions = 0;

            try
            {
                SavedVariablesParser.Document doc = new SavedVariablesParser.Document(_Contribution.GetFilename());
                var xmlDoc = doc.ConvertToXMLDocument();

                WowVersionEnum wowVersion = WowVersionEnum.Unknown;
                try
                {
                    string addonVersion = XMLUtility.GetChildValue(xmlDoc.DocumentElement, "VF_RealmPlayersVersion", "0.0");
                    if (addonVersion.Split('.').Length == 2) //VF_RealmPlayers
                    {
                        if (Utility.ParseDouble(addonVersion) <= 1.58)
                        {
                            return;
                        }
                        wowVersion = WowVersionEnum.Vanilla;
                    }
                    else //VF_RealmPlayersTBC
                    {
                        wowVersion = WowVersionEnum.TBC;
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogException(ex);
                }
                var dataNode = XMLUtility.GetChild(xmlDoc.DocumentElement, "VF_RealmPlayersData");
                foreach (System.Xml.XmlNode playerNode in dataNode.ChildNodes)
                {
                    try
                    {
                        if (XMLUtility.GetChild(playerNode, "PlayerData") != null)
                        {
                            string   realmStr = PlayerData.DataParser.ParseRealm(playerNode);
                            WowRealm realm    = StaticValues.ConvertRealm(realmStr);
                            if (realm == WowRealm.Archangel || wowVersion == WowVersionEnum.TBC)
                            {
                                if (realm != WowRealm.Archangel || wowVersion != WowVersionEnum.TBC)
                                {
                                    Logger.ConsoleWriteLine("RealmPlayers WoWversion guess was wrong!!!", ConsoleColor.Red);
                                }
                            }

                            if (realm == WowRealm.Unknown || m_Realms.ContainsKey(realm) == false)
                            {
                                Logger.ConsoleWriteLine("RealmStr: \"" + realmStr + "\" was not recognized as a realm");
                            }
                            else
                            {
                                RealmDatabase realmDB = m_Realms[realm];
                                realmDB.UpdatePlayer(playerNode, _Contribution.GetContributor());
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (loggedExceptions < 5)
                        {
                            Logger.LogException(ex);
                        }
                        ++loggedExceptions;
                    }
                }
                Logger.ConsoleWriteLine(_Contribution.GetContributor().GetFilename() + " just updated database successfully!");
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }
        }
예제 #3
0
        public bool AddContribution(RPPContribution _Contribution)
        {
            int loggedExceptions = 0;

            try
            {
                SavedVariablesParser.Document doc = new SavedVariablesParser.Document(_Contribution.GetFilename());
                var xmlDoc = doc.ConvertToXMLDocument();

                WowVersionEnum wowVersion = WowVersionEnum.Unknown;
                try
                {
                    string addonVersion = XMLUtility.GetChildValue(xmlDoc.DocumentElement, "VF_RealmPlayersVersion", "0.0");
                    if (addonVersion.Split('.').Length == 2) //VF_RealmPlayers
                    {
                        if (Utility.ParseDouble(addonVersion) <= 1.58)
                        {
                            return(false);
                        }
                        wowVersion = WowVersionEnum.Vanilla;
                    }
                    else //VF_RealmPlayersTBC
                    {
                        wowVersion = WowVersionEnum.TBC;
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogException(ex);
                }
#if UPDATE_SQL_DB
                List <VF.SQLUploadID> uploadIDs = new List <VF.SQLUploadID>();
#endif
                var dataNode = XMLUtility.GetChild(xmlDoc.DocumentElement, "VF_RealmPlayersData");
                int wowVersionWrongGuessCount = 0;
                foreach (System.Xml.XmlNode playerNode in dataNode.ChildNodes)
                {
                    try
                    {
                        if (PlayerData.DataParser.ParsePlayerName(playerNode) == "OnlineData")
                        {
                            foreach (System.Xml.XmlNode onlineDataNode in playerNode.ChildNodes)
                            {
                                int loggedStrangeDataException = 0;

                                string   onlineData = onlineDataNode.Attributes["value"].Value;
                                var      dataParts  = onlineData.Split(new char[] { ';' }, 5);
                                string   realmStr   = dataParts[1];
                                WowRealm realm      = StaticValues.ConvertRealm(realmStr);
                                if (realm == WowRealm.Unknown)
                                {
                                    realmStr = realmStr.Substring(0, 1) + realmStr.Substring(2);
                                    realm    = StaticValues.ConvertRealm(realmStr);
                                }

                                string   dateTimeStartStr = dataParts[2];
                                string   dateTimeEndStr   = dataParts[3];
                                string[] playersDatas     = dataParts[4].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                DateTime dateTimeStart;
                                DateTime dateTimeEnd;
                                if (System.DateTime.TryParse(dateTimeStartStr, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeUniversal | System.Globalization.DateTimeStyles.AdjustToUniversal, out dateTimeStart) == true &&
                                    System.DateTime.TryParse(dateTimeEndStr, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeUniversal | System.Globalization.DateTimeStyles.AdjustToUniversal, out dateTimeEnd) == true)
                                {
                                    PlayersOnlineDB playersOnlineDB = m_Realms[realm].PlayersOnlineData;

                                    var onlineEntry = playersOnlineDB.GetOnlineEntry(dateTimeStart, dateTimeEnd);
                                    if (onlineEntry == null && (dateTimeEnd - dateTimeStart).TotalMinutes < 5)
                                    {
                                        //Widen the online-span to approx 5 minutes since we are creating a new entry anyways...
                                        double addMinutes = 5.0 - (dateTimeEnd - dateTimeStart).TotalMinutes;
                                        double halfMins   = addMinutes / 2;
                                        dateTimeStart = dateTimeStart.AddMinutes(-halfMins);
                                        dateTimeEnd   = dateTimeEnd.AddMinutes(halfMins);
                                    }
                                    onlineEntry = playersOnlineDB.CreateOnlineEntry(dateTimeStart, dateTimeEnd);

                                    foreach (var playerData in playersDatas)
                                    {
                                        var data = playerData.Split(':');
                                        if (data.Length == 6)
                                        {
                                            PlayersOnlineDB.OnlinePlayerEntry onlinePlayer = new PlayersOnlineDB.OnlinePlayerEntry();
                                            onlinePlayer.Name  = data[0];
                                            onlinePlayer.Race  = (PlayerRace)int.Parse(data[1]);
                                            onlinePlayer.Class = (PlayerClass)int.Parse(data[2]);
                                            onlinePlayer.Guild = data[3];
                                            onlinePlayer.Level = int.Parse(data[4]);
                                            onlinePlayer.Zone  = (WorldZone)int.Parse(data[5]);
                                            onlineEntry.AddOnlinePlayer(onlinePlayer);
                                        }
                                        else if (loggedStrangeDataException < 5)
                                        {
                                            Logger.ConsoleWriteLine("Strange data in OnlineData segment! \"" + playerData + "\"");
                                            ++loggedStrangeDataException;
                                        }
                                    }
                                    m_Realms[realm].Updated = true;
                                    Logger.ConsoleWriteLine(onlineEntry.OnlinePlayers.Count + " players online " + dateTimeStart.ToDateTimeStr());
                                }
                            }
                        }
                        else if (XMLUtility.GetChild(playerNode, "PlayerData") != null)
                        {
                            string   realmStr = PlayerData.DataParser.ParseRealm(playerNode);
                            WowRealm realm    = StaticValues.ConvertRealm(realmStr);
                            if (realm == WowRealm.Unknown)
                            {
                                realmStr = realmStr.Substring(0, 1) + realmStr.Substring(2);
                                realm    = StaticValues.ConvertRealm(realmStr);
                            }
                            if (StaticValues.DeadRealms.Contains(realm) == true ||
                                StaticValues.Disabled_UploadRealmNames.Contains(realmStr) == true)
                            {
                                Logger.ConsoleWriteLine("RealmStr: \"" + realmStr + "\" was recognized as a dead realm");
                                continue;
                            }
                            if ((StaticValues.GetWowVersion(realm) != wowVersion))
                            {
                                ++wowVersionWrongGuessCount;
                            }

                            if (realm == WowRealm.Unknown || m_Realms.ContainsKey(realm) == false)
                            {
                                Logger.ConsoleWriteLine("RealmStr: \"" + realmStr + "\" was not recognized as a realm");
                            }
                            else
                            {
#if UPDATE_SQL_DB
                                Func <int, VF.SQLUploadID> getUploadID = (int _Index) =>
                                {
                                    while (uploadIDs.Count <= _Index)
                                    {
                                        using (VF.SQLComm comm = new VF.SQLComm())
                                        {
                                            var uploadID = comm.GenerateNewUploadEntry(_Contribution.GetContributor(), DateTime.UtcNow);
                                            uploadIDs.Add(uploadID);
                                        }
                                    }
                                    return(uploadIDs[_Index]);
                                };
                                RealmDatabase realmDB = m_Realms[realm];
                                realmDB.UpdatePlayer(playerNode, _Contribution.GetContributor(), getUploadID);
#else
                                RealmDatabase realmDB = m_Realms[realm];
                                realmDB.UpdatePlayer(playerNode, _Contribution.GetContributor(), null);
#endif
                            }
                        }
                    }
                    catch (Npgsql.NpgsqlException ex)
                    {
                        throw ex;
                    }
                    catch (Exception ex)
                    {
                        if (loggedExceptions < 5)
                        {
                            Logger.LogException(ex);
                        }
                        ++loggedExceptions;
                    }
                }
                if (wowVersionWrongGuessCount > 0)
                {
                    Logger.ConsoleWriteLine("RealmPlayers WoWversion guess was wrong " + wowVersionWrongGuessCount + " times!!!", ConsoleColor.Red);
                }
                Logger.ConsoleWriteLine(_Contribution.GetContributor().GetFilename() + " just updated database successfully!");
                return(true);
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }
            return(false);
        }
예제 #4
0
        public bool AddContribution(RPPContribution _Contribution)
        {
            int loggedExceptions = 0;

            try
            {
                SavedVariablesParser.Document doc = new SavedVariablesParser.Document(_Contribution.GetFilename());
                var xmlDoc = doc.ConvertToXMLDocument();

                WowVersionEnum wowVersion = WowVersionEnum.Unknown;
                try
                {
                    string addonVersion = XMLUtility.GetChildValue(xmlDoc.DocumentElement, "VF_RealmPlayersVersion", "0.0");
                    if (addonVersion.Split('.').Length == 2) //VF_RealmPlayers
                    {
                        if (Utility.ParseDouble(addonVersion) <= 1.58)
                        {
                            return(false);
                        }
                        wowVersion = WowVersionEnum.Vanilla;
                    }
                    else //VF_RealmPlayersTBC
                    {
                        wowVersion = WowVersionEnum.TBC;
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogException(ex);
                }
                List <VF.SQLUploadID> uploadIDs = new List <VF.SQLUploadID>();
                var dataNode = XMLUtility.GetChild(xmlDoc.DocumentElement, "VF_RealmPlayersData");
                int wowVersionWrongGuessCount = 0;
                foreach (System.Xml.XmlNode playerNode in dataNode.ChildNodes)
                {
                    try
                    {
                        if (XMLUtility.GetChild(playerNode, "PlayerData") != null)
                        {
                            string   realmStr = PlayerData.DataParser.ParseRealm(playerNode);
                            WowRealm realm    = StaticValues.ConvertRealm(realmStr);
                            if ((StaticValues.GetWowVersion(realm) != wowVersion))
                            {
                                ++wowVersionWrongGuessCount;
                            }

                            if (realm == WowRealm.Unknown || m_Realms.ContainsKey(realm) == false)
                            {
                                Logger.ConsoleWriteLine("RealmStr: \"" + realmStr + "\" was not recognized as a realm");
                            }
                            else
                            {
                                Func <int, VF.SQLUploadID> getUploadID = (int _Index) =>
                                {
                                    while (uploadIDs.Count <= _Index)
                                    {
                                        using (VF.SQLComm comm = new VF.SQLComm())
                                        {
                                            var uploadID = comm.GenerateNewUploadEntry(_Contribution.GetContributor(), DateTime.UtcNow);
                                            uploadIDs.Add(uploadID);
                                        }
                                    }
                                    return(uploadIDs[_Index]);
                                };
                                RealmDatabase realmDB = m_Realms[realm];
                                realmDB.UpdatePlayer(playerNode, _Contribution.GetContributor(), getUploadID);
                            }
                        }
                    }
                    catch (Npgsql.NpgsqlException ex)
                    {
                        throw ex;
                    }
                    catch (Exception ex)
                    {
                        if (loggedExceptions < 5)
                        {
                            Logger.LogException(ex);
                        }
                        ++loggedExceptions;
                    }
                }
                if (wowVersionWrongGuessCount > 0)
                {
                    Logger.ConsoleWriteLine("RealmPlayers WoWversion guess was wrong " + wowVersionWrongGuessCount + " times!!!", ConsoleColor.Red);
                }
                Logger.ConsoleWriteLine(_Contribution.GetContributor().GetFilename() + " just updated database successfully!");
                return(true);
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }
            return(false);
        }
예제 #5
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;
        }