private uint GetDictionaryItemID(uint _ItemID, WowRealm _Realm) { if (_ItemID > 0xFFFFFF) { throw new Exception("(GetDictionaryItemID) ItemID: " + _ItemID.ToString() + " is too large"); } switch (_Realm) { case WowRealm.Unknown: throw new Exception("(GetDictionaryItemID) Could not get dictionary ItemID for Unknown Realm"); case WowRealm.Emerald_Dream: return((1U << 24) + _ItemID); case WowRealm.Al_Akir: return((1U << 24) + _ItemID); case WowRealm.Warsong: case WowRealm.Warsong2: case WowRealm.Nemesis: return((1U << 24) + _ItemID); case WowRealm.All: return(uint.MaxValue); case WowRealm.Archangel: case WowRealm.WarsongTBC: return((0x10U << 24) + _ItemID); case WowRealm.Valkyrie: case WowRealm.Elysium: case WowRealm.Elysium2: case WowRealm.Zeth_Kur: return((2U << 24) + _ItemID); case WowRealm.Rebirth: return((3U << 24) + _ItemID); case WowRealm.VanillaGaming: return((4U << 24) + _ItemID); case WowRealm.Nostalrius: case WowRealm.NostalriusPVE: case WowRealm.Nostralia: case WowRealm.Firemaw: //Should have own ID return((5U << 24) + _ItemID); case WowRealm.Kronos: case WowRealm.KronosII: return((6U << 24) + _ItemID); case WowRealm.NostalGeek: return((7U << 24) + _ItemID); case WowRealm.Nefarian: return((8U << 24) + _ItemID); case WowRealm.Vengeance_Wildhammer: case WowRealm.Vengeance_Stonetalon: return((0x11U << 24) + _ItemID); case WowRealm.ExcaliburTBC: return((0x12U << 24) + _ItemID); case WowRealm.L4G_Hellfire: case WowRealm.Hellfire2: case WowRealm.HellGround: //Should have own ID case WowRealm.Felmyst: //Should have own ID case WowRealm.Outland: //Should have own ID case WowRealm.Medivh: //Should have own ID case WowRealm.Ares: //Should have own ID return((0x13U << 24) + _ItemID); default: if (StaticValues.GetWowVersion(_Realm) == WowVersionEnum.Vanilla) //Should have own ID { return((5U << 24) + _ItemID); } else if (StaticValues.GetWowVersion(_Realm) == WowVersionEnum.TBC) //Should have own ID { return((0x13U << 24) + _ItemID); } break; } throw new Exception("(GetDictionaryItemID) Could not get dictionary ItemID for Realm: " + _Realm.ToString()); }
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); } }
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); }
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); }
public RealmDatabase(WowRealm _Realm) { Realm = _Realm; WowVersion = StaticValues.GetWowVersion(_Realm); Updated = false; }