From b48f777dc68d13c0481a81dbd59007d844689ab2 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Thu, 1 Feb 2024 09:43:05 -0500 Subject: [PATCH] Core/Realms: Replaced hardcoded realm category list with Cfg_Categories.db2 Port From (https://github.com/TrinityCore/TrinityCore/commit/e161874695c5506bfa3cbcddf944d68b11cbc124) --- .../Constants/Authentication/RealmConst.cs | 42 ------- Source/Framework/Constants/CliDBConst.cs | 16 +++ Source/Framework/Constants/Language.cs | 9 -- .../Database/Databases/HotfixDatabase.cs | 8 ++ Source/Framework/Realm/RealmManager.cs | 2 + Source/Game/DataStorage/CliDB.cs | 2 + Source/Game/DataStorage/Structs/C_Records.cs | 15 +++ Source/Game/Globals/ObjectManager.cs | 118 ++++++++---------- Source/Game/Server/WorldConfig.cs | 10 +- 9 files changed, 103 insertions(+), 119 deletions(-) diff --git a/Source/Framework/Constants/Authentication/RealmConst.cs b/Source/Framework/Constants/Authentication/RealmConst.cs index e1f106943..b2ea0b6ce 100644 --- a/Source/Framework/Constants/Authentication/RealmConst.cs +++ b/Source/Framework/Constants/Authentication/RealmConst.cs @@ -32,46 +32,4 @@ namespace Framework.Constants FFAPVP = 16 // custom, free for all pvp mode like arena PvP in all zones except rest activated places and sanctuaries // replaced by REALM_PVP in realm list } - - public enum RealmZones - { - Unknown = 0, // Any Language - Development = 1, // Any Language - UnitedStates = 2, // Extended-Latin - Oceanic = 3, // Extended-Latin - LatinAmerica = 4, // Extended-Latin - Tournament5 = 5, // Basic-Latin At Create, Any At Login - Korea = 6, // East-Asian - Tournament7 = 7, // Basic-Latin At Create, Any At Login - English = 8, // Extended-Latin - German = 9, // Extended-Latin - French = 10, // Extended-Latin - Spanish = 11, // Extended-Latin - Russian = 12, // Cyrillic - Tournament13 = 13, // Basic-Latin At Create, Any At Login - Taiwan = 14, // East-Asian - Tournament15 = 15, // Basic-Latin At Create, Any At Login - China = 16, // East-Asian - Cn1 = 17, // Basic-Latin At Create, Any At Login - Cn2 = 18, // Basic-Latin At Create, Any At Login - Cn3 = 19, // Basic-Latin At Create, Any At Login - Cn4 = 20, // Basic-Latin At Create, Any At Login - Cn5 = 21, // Basic-Latin At Create, Any At Login - Cn6 = 22, // Basic-Latin At Create, Any At Login - Cn7 = 23, // Basic-Latin At Create, Any At Login - Cn8 = 24, // Basic-Latin At Create, Any At Login - Tournament25 = 25, // Basic-Latin At Create, Any At Login - TestServer = 26, // Any Language - Tournament27 = 27, // Basic-Latin At Create, Any At Login - QaServer = 28, // Any Language - Cn9 = 29, // Basic-Latin At Create, Any At Login - TestServer2 = 30, // Any Language - Cn10 = 31, // Basic-Latin At Create, Any At Login - Ctc = 32, - Cnc = 33, - Cn14 = 34, // Basic-Latin At Create, Any At Login - Cn269 = 35, // Basic-Latin At Create, Any At Login - Cn37 = 36, // Basic-Latin At Create, Any At Login - Cn58 = 37 // Basic-Latin At Create, Any At Login - } } diff --git a/Source/Framework/Constants/CliDBConst.cs b/Source/Framework/Constants/CliDBConst.cs index 478eaf86e..7157c15c1 100644 --- a/Source/Framework/Constants/CliDBConst.cs +++ b/Source/Framework/Constants/CliDBConst.cs @@ -1079,6 +1079,22 @@ namespace Framework.Constants Factional = 0x40 } + public enum CfgCategoriesCharsets + { + Any = 0x00, + Latin1 = 0x01, + English = 0x02, + Russian = 0x04, + Korean = 0x08, + Chinese = 0x10 + } + + public enum CfgCategoriesFlags + { + None = 0x0, + Tournament = 0x1 + } + [Flags] public enum ChrRacesFlag { diff --git a/Source/Framework/Constants/Language.cs b/Source/Framework/Constants/Language.cs index eacc05160..9effb842b 100644 --- a/Source/Framework/Constants/Language.cs +++ b/Source/Framework/Constants/Language.cs @@ -1272,13 +1272,4 @@ namespace Framework.Constants CallForHelp = 2541, FleeForAssist = 1150 } - - public enum LanguageType - { - BasicLatin = 0x00, - ExtendenLatin = 0x01, - Cyrillic = 0x02, - EastAsia = 0x04, - Any = 0xFFFF - } } diff --git a/Source/Framework/Database/Databases/HotfixDatabase.cs b/Source/Framework/Database/Databases/HotfixDatabase.cs index 05a3c0dbe..5e47f9086 100644 --- a/Source/Framework/Database/Databases/HotfixDatabase.cs +++ b/Source/Framework/Database/Databases/HotfixDatabase.cs @@ -208,6 +208,11 @@ namespace Framework.Database PrepareStatement(HotfixStatements.SEL_BROADCAST_TEXT_DURATION, "SELECT ID, BroadcastTextID, Locale, Duration FROM broadcast_text_duration" + " WHERE (`VerifiedBuild` > 0) = ?"); + // CfgCategories.db2 + PrepareStatement(HotfixStatements.SEL_CFG_CATEGORIES, "SELECT ID, Name, LocaleMask, CreateCharsetMask, ExistingCharsetMask, Flags, `Order`" + + " FROM cfg_categories WHERE (`VerifiedBuild` > 0) = ?"); + PrepareStatement(HotfixStatements.SEL_CFG_CATEGORIES_LOCALE, "SELECT ID, Name_lang FROM cfg_categories_locale WHERE (`VerifiedBuild` > 0) = ? AND locale = ?"); + // CfgRegions.db2 PrepareStatement(HotfixStatements.SEL_CFG_REGIONS, "SELECT ID, Tag, RegionID, Raidorigin, RegionGroupMask, ChallengeOrigin FROM cfg_regions" + " WHERE (`VerifiedBuild` > 0) = ?"); @@ -1681,6 +1686,9 @@ namespace Framework.Database SEL_BROADCAST_TEXT_DURATION, + SEL_CFG_CATEGORIES, + SEL_CFG_CATEGORIES_LOCALE, + SEL_CFG_REGIONS, SEL_CHALLENGE_MODE_ITEM_BONUS_OVERRIDE, diff --git a/Source/Framework/Realm/RealmManager.cs b/Source/Framework/Realm/RealmManager.cs index edb7197c0..8e599b356 100644 --- a/Source/Framework/Realm/RealmManager.cs +++ b/Source/Framework/Realm/RealmManager.cs @@ -15,6 +15,8 @@ using Framework.Realm; public class RealmManager : Singleton { + public static uint HardcodedDevelopmentRealmCategoryId = 1; + RealmManager() { } public void Initialize(int updateInterval) diff --git a/Source/Game/DataStorage/CliDB.cs b/Source/Game/DataStorage/CliDB.cs index 8b8da82bc..b340f6ad6 100644 --- a/Source/Game/DataStorage/CliDB.cs +++ b/Source/Game/DataStorage/CliDB.cs @@ -92,6 +92,7 @@ namespace Game.DataStorage BattlemasterListStorage = ReadDB2("BattlemasterList.db2", HotfixStatements.SEL_BATTLEMASTER_LIST, HotfixStatements.SEL_BATTLEMASTER_LIST_LOCALE); BroadcastTextStorage = ReadDB2("BroadcastText.db2", HotfixStatements.SEL_BROADCAST_TEXT, HotfixStatements.SEL_BROADCAST_TEXT_LOCALE); BroadcastTextDurationStorage = ReadDB2("BroadcastTextDuration.db2", HotfixStatements.SEL_BROADCAST_TEXT_DURATION); + CfgCategoriesStorage = ReadDB2("Cfg_Categories.db2", HotfixStatements.SEL_CFG_CATEGORIES, HotfixStatements.SEL_CFG_CATEGORIES_LOCALE); CfgRegionsStorage = ReadDB2("Cfg_Regions.db2", HotfixStatements.SEL_CFG_REGIONS); ChallengeModeItemBonusOverrideStorage = ReadDB2("ChallengeModeItemBonusOverride.db2", HotfixStatements.SEL_CHALLENGE_MODE_ITEM_BONUS_OVERRIDE); CharTitlesStorage = ReadDB2("CharTitles.db2", HotfixStatements.SEL_CHAR_TITLES, HotfixStatements.SEL_CHAR_TITLES_LOCALE); @@ -525,6 +526,7 @@ namespace Game.DataStorage public static DB6Storage BattlemasterListStorage; public static DB6Storage BroadcastTextStorage; public static DB6Storage BroadcastTextDurationStorage; + public static DB6Storage CfgCategoriesStorage; public static DB6Storage CfgRegionsStorage; public static DB6Storage ChallengeModeItemBonusOverrideStorage; public static DB6Storage CharTitlesStorage; diff --git a/Source/Game/DataStorage/Structs/C_Records.cs b/Source/Game/DataStorage/Structs/C_Records.cs index 99121dbbd..b6ebb0547 100644 --- a/Source/Game/DataStorage/Structs/C_Records.cs +++ b/Source/Game/DataStorage/Structs/C_Records.cs @@ -6,6 +6,21 @@ using System.Numerics; namespace Game.DataStorage { + public sealed class Cfg_CategoriesRecord + { + public uint Id; + public LocalizedString Name; + public ushort LocaleMask; + public byte CreateCharsetMask; + public byte ExistingCharsetMask; + public byte Flags; + public sbyte Order; + + public CfgCategoriesCharsets GetCreateCharsetMask() { return (CfgCategoriesCharsets)CreateCharsetMask; } + public CfgCategoriesCharsets GetExistingCharsetMask() { return (CfgCategoriesCharsets)ExistingCharsetMask; } + public CfgCategoriesFlags GetFlags() { return (CfgCategoriesFlags)Flags; } + } + public sealed class Cfg_RegionsRecord { public uint Id; diff --git a/Source/Game/Globals/ObjectManager.cs b/Source/Game/Globals/ObjectManager.cs index 240cd70fd..fdf84c5f6 100644 --- a/Source/Game/Globals/ObjectManager.cs +++ b/Source/Game/Globals/ObjectManager.cs @@ -47,6 +47,7 @@ namespace Game name = new string(charArray); return true; } + public static ExtendedPlayerName ExtractExtendedPlayerName(string name) { int pos = name.IndexOf('-'); @@ -55,32 +56,14 @@ namespace Game else return new ExtendedPlayerName(name, ""); } - static LanguageType GetRealmLanguageType(bool create) + + static CfgCategoriesCharsets GetRealmLanguageType(bool create) { - switch ((RealmZones)WorldConfig.GetIntValue(WorldCfg.RealmZone)) - { - case RealmZones.Unknown: // any language - case RealmZones.Development: - case RealmZones.TestServer: - case RealmZones.QaServer: - return LanguageType.Any; - case RealmZones.UnitedStates: // extended-Latin - case RealmZones.Oceanic: - case RealmZones.LatinAmerica: - case RealmZones.English: - case RealmZones.German: - case RealmZones.French: - case RealmZones.Spanish: - return LanguageType.ExtendenLatin; - case RealmZones.Korea: // East-Asian - case RealmZones.Taiwan: - case RealmZones.China: - return LanguageType.EastAsia; - case RealmZones.Russian: // Cyrillic - return LanguageType.Cyrillic; - default: - return create ? LanguageType.BasicLatin : LanguageType.Any; // basic-Latin at create, any at login - } + Cfg_CategoriesRecord category = CliDB.CfgCategoriesStorage.LookupByKey(Global.WorldMgr.GetRealm().Timezone); + if (category != null) + return create ? category.GetCreateCharsetMask() : category.GetExistingCharsetMask(); + + return create ? CfgCategoriesCharsets.English : CfgCategoriesCharsets.Any; // basic-Latin at create, any at login } public static CreatureModel ChooseDisplayId(CreatureTemplate cinfo, CreatureData data = null) @@ -175,44 +158,43 @@ namespace Game { if (strictMask == 0) // any language, ignore realm { - if (IsCultureString(LanguageType.BasicLatin, str, numericOrSpace)) + if (IsCultureString(CfgCategoriesCharsets.Latin1, str, numericOrSpace)) return true; - if (IsCultureString(LanguageType.ExtendenLatin, str, numericOrSpace)) + if (IsCultureString(CfgCategoriesCharsets.Russian, str, numericOrSpace)) return true; - if (IsCultureString(LanguageType.Cyrillic, str, numericOrSpace)) + if (IsCultureString(CfgCategoriesCharsets.Korean, str, numericOrSpace)) return true; - if (IsCultureString(LanguageType.EastAsia, str, numericOrSpace)) + if (IsCultureString(CfgCategoriesCharsets.Chinese, str, numericOrSpace)) return true; return false; } if (Convert.ToBoolean(strictMask & 0x2)) // realm zone specific { - LanguageType lt = GetRealmLanguageType(create); - if (lt.HasAnyFlag(LanguageType.ExtendenLatin)) - { - if (IsCultureString(LanguageType.BasicLatin, str, numericOrSpace)) - return true; - if (IsCultureString(LanguageType.ExtendenLatin, str, numericOrSpace)) - return true; - } - if (lt.HasAnyFlag(LanguageType.Cyrillic)) - if (IsCultureString(LanguageType.Cyrillic, str, numericOrSpace)) - return true; - if (lt.HasAnyFlag(LanguageType.EastAsia)) - if (IsCultureString(LanguageType.EastAsia, str, numericOrSpace)) - return true; + CfgCategoriesCharsets lt = GetRealmLanguageType(create); + if (lt == CfgCategoriesCharsets.Any) + return true; + if (lt.HasFlag(CfgCategoriesCharsets.Latin1) && IsCultureString(CfgCategoriesCharsets.Latin1, str, numericOrSpace)) + return true; + if (lt.HasFlag(CfgCategoriesCharsets.English) && IsCultureString(CfgCategoriesCharsets.English, str, numericOrSpace)) + return true; + if (lt.HasFlag(CfgCategoriesCharsets.Russian) && IsCultureString(CfgCategoriesCharsets.Russian, str, numericOrSpace)) + return true; + if (lt.HasFlag(CfgCategoriesCharsets.Korean) && IsCultureString(CfgCategoriesCharsets.Korean, str, numericOrSpace)) + return true; + if (lt.HasFlag(CfgCategoriesCharsets.Chinese) && IsCultureString(CfgCategoriesCharsets.Chinese, str, numericOrSpace)) + return true; } if (Convert.ToBoolean(strictMask & 0x1)) // basic Latin { - if (IsCultureString(LanguageType.BasicLatin, str, numericOrSpace)) + if (IsCultureString(CfgCategoriesCharsets.English, str, numericOrSpace)) return true; } return false; } - static bool IsCultureString(LanguageType culture, string str, bool numericOrSpace) + static bool IsCultureString(CfgCategoriesCharsets culture, string str, bool numericOrSpace) { foreach (var wchar in str) { @@ -221,13 +203,17 @@ namespace Game switch (culture) { - case LanguageType.BasicLatin: + case CfgCategoriesCharsets.English: + if (wchar >= 'a' && wchar <= 'z') // LATIN SMALL LETTER A - LATIN SMALL LETTER Z + return true; + if (wchar >= 'A' && wchar <= 'Z') // LATIN CAPITAL LETTER A - LATIN CAPITAL LETTER Z + return true; + break; + case CfgCategoriesCharsets.Latin1: if (wchar >= 'a' && wchar <= 'z') // LATIN SMALL LETTER A - LATIN SMALL LETTER Z return true; if (wchar >= 'A' && wchar <= 'Z') // LATIN CAPITAL LETTER A - LATIN CAPITAL LETTER Z return true; - return false; - case LanguageType.ExtendenLatin: if (wchar >= 0x00C0 && wchar <= 0x00D6) // LATIN CAPITAL LETTER A WITH GRAVE - LATIN CAPITAL LETTER O WITH DIAERESIS return true; if (wchar >= 0x00D8 && wchar <= 0x00DE) // LATIN CAPITAL LETTER O WITH STROKE - LATIN CAPITAL LETTER THORN @@ -242,31 +228,33 @@ namespace Game return true; if (wchar == 0x1E9E) // LATIN CAPITAL LETTER SHARP S return true; - return false; - case LanguageType.Cyrillic: + break; + case CfgCategoriesCharsets.Russian: if (wchar >= 0x0410 && wchar <= 0x044F) // CYRILLIC CAPITAL LETTER A - CYRILLIC SMALL LETTER YA return true; if (wchar == 0x0401 || wchar == 0x0451) // CYRILLIC CAPITAL LETTER IO, CYRILLIC SMALL LETTER IO return true; - return false; - case LanguageType.EastAsia: + break; + case CfgCategoriesCharsets.Korean: if (wchar >= 0x1100 && wchar <= 0x11F9) // Hangul Jamo return true; - if (wchar >= 0x3041 && wchar <= 0x30FF) // Hiragana + Katakana - return true; if (wchar >= 0x3131 && wchar <= 0x318E) // Hangul Compatibility Jamo return true; - if (wchar >= 0x31F0 && wchar <= 0x31FF) // Katakana Phonetic Ext. - return true; - if (wchar >= 0x3400 && wchar <= 0x4DB5) // CJK Ideographs Ext. A - return true; - if (wchar >= 0x4E00 && wchar <= 0x9FC3) // Unified CJK Ideographs - return true; if (wchar >= 0xAC00 && wchar <= 0xD7A3) // Hangul Syllables return true; if (wchar >= 0xFF01 && wchar <= 0xFFEE) // Halfwidth forms return true; - return false; + break; + case CfgCategoriesCharsets.Chinese: + if (wchar >= 0x4E00 && wchar <= 0x9FFF) // Unified CJK Ideographs + return true; + if (wchar >= 0x3400 && wchar <= 0x4DBF) // CJK Ideographs Ext. A + return true; + if (wchar >= 0x3100 && wchar <= 0x312C) // Bopomofo + return true; + if (wchar >= 0xF900 && wchar <= 0xFAFF) // CJK Compatibility Ideographs + return true; + break; } } @@ -1455,7 +1443,7 @@ namespace Game Log.outError(LogFilter.Sql, $"Table `spell_scripts` - spell {spellId} effect {spellEffIndex} is not SPELL_EFFECT_SCRIPT_EFFECT or SPELL_EFFECT_DUMMY"); } } - + void LoadEventSet() { _eventStorage.Clear(); @@ -5253,7 +5241,7 @@ namespace Game { return _creatureTemplateSparringStorage.LookupByKey(entry); } - + public CreatureMovementData GetCreatureMovementOverride(ulong spawnId) { return creatureMovementOverrides.LookupByKey(spawnId); @@ -8232,7 +8220,7 @@ namespace Game return null; } - + //Spells /Skills / Phases public void LoadPhases() { @@ -10319,7 +10307,7 @@ namespace Game return 0; } - + public uint GetMaxLevelForExpansion(Expansion expansion) { switch (expansion) diff --git a/Source/Game/Server/WorldConfig.cs b/Source/Game/Server/WorldConfig.cs index 3715efdc1..fa64982e1 100644 --- a/Source/Game/Server/WorldConfig.cs +++ b/Source/Game/Server/WorldConfig.cs @@ -3,6 +3,7 @@ using Framework.Configuration; using Framework.Constants; +using Game.DataStorage; using System; using System.Collections.Generic; @@ -312,12 +313,12 @@ namespace Game if (reload) { - int val = (int)GetDefaultValue("RealmZone", RealmZones.Development); + int val = (int)GetDefaultValue("RealmZone", RealmManager.HardcodedDevelopmentRealmCategoryId); if (val != (int)Values[WorldCfg.RealmZone]) Log.outError(LogFilter.ServerLoading, "RealmZone option can't be changed at worldserver.conf reload, using current value ({0}).", Values[WorldCfg.RealmZone]); } else - Values[WorldCfg.RealmZone] = GetDefaultValue("RealmZone", (int)RealmZones.Development); + Values[WorldCfg.RealmZone] = GetDefaultValue("RealmZone", RealmManager.HardcodedDevelopmentRealmCategoryId); Values[WorldCfg.AllowTwoSideInteractionCalendar] = GetDefaultValue("AllowTwoSide.Interaction.Calendar", false); Values[WorldCfg.AllowTwoSideInteractionChannel] = GetDefaultValue("AllowTwoSide.Interaction.Channel", false); @@ -702,8 +703,11 @@ namespace Game Values[WorldCfg.ThreatRadius] = GetDefaultValue("ThreatRadius", 60.0f); + Values[WorldCfg.DeclinedNamesUsed] = GetDefaultValue("DeclinedNames", false); // always use declined names in the russian client - Values[WorldCfg.DeclinedNamesUsed] = (RealmZones)Values[WorldCfg.RealmZone] == RealmZones.Russian || GetDefaultValue("DeclinedNames", false); + var category = CliDB.CfgCategoriesStorage.LookupByKey((uint)Values[WorldCfg.RealmZone]); + if (category != null && category.GetCreateCharsetMask().HasFlag(CfgCategoriesCharsets.Russian)) + Values[WorldCfg.DeclinedNamesUsed] = true; Values[WorldCfg.ListenRangeSay] = GetDefaultValue("ListenRange.Say", 25.0f); Values[WorldCfg.ListenRangeTextemote] = GetDefaultValue("ListenRange.TextEmote", 25.0f);