Refactoring of BNetServer

This commit is contained in:
hondacrx
2020-07-12 00:06:43 -04:00
parent 4164384b72
commit 581d077acd
318 changed files with 2046 additions and 4694 deletions
+2 -2
View File
@@ -28,7 +28,7 @@ namespace Game.DataStorage
internal static int LoadedFileCount;
internal static string DataPath;
public static void LoadStores(string dataPath, LocaleConstant defaultLocale)
public static void LoadStores(string dataPath, Locale defaultLocale)
{
uint oldMSTime = Time.GetMSTime();
LoadedFileCount = 0;
@@ -36,7 +36,7 @@ namespace Game.DataStorage
DataPath = dataPath + "/dbc/" + defaultLocale + "/";
AchievementStorage = DBReader.Read<AchievementRecord>("Achievement.db2", HotfixStatements.SEL_ACHIEVEMENT, HotfixStatements.SEL_ACHIEVEMENT_LOCALE);
AnimationDataStorage = DBReader.Read<AnimationDataRecord>("AnimationData.db2", HotfixStatements.SEL_ANIMATION_DATA);
//AnimationDataStorage = DBReader.Read<AnimationDataRecord>("AnimationData.db2", HotfixStatements.SEL_ANIMATION_DATA);
AnimKitStorage = DBReader.Read<AnimKitRecord>("AnimKit.db2", HotfixStatements.SEL_ANIM_KIT);
AreaGroupMemberStorage = DBReader.Read<AreaGroupMemberRecord>("AreaGroupMember.db2", HotfixStatements.SEL_AREA_GROUP_MEMBER);
AreaTableStorage = DBReader.Read<AreaTableRecord>("AreaTable.db2", HotfixStatements.SEL_AREA_TABLE, HotfixStatements.SEL_AREA_TABLE_LOCALE);
@@ -30,7 +30,7 @@ namespace Game.DataStorage
{
bool HasRecord(uint id);
void WriteRecord(uint id, LocaleConstant locale, ByteBuffer buffer);
void WriteRecord(uint id, Locale locale, ByteBuffer buffer);
void EraseRecord(uint id);
}
@@ -191,9 +191,9 @@ namespace Game.DataStorage
if (preparedStatementLocale == 0)
return;
for (LocaleConstant locale = 0; locale < LocaleConstant.Total; ++locale)
for (Locale locale = 0; locale < Locale.Total; ++locale)
{
if (Global.WorldMgr.GetDefaultDbcLocale() == locale || locale == LocaleConstant.None)
if (Global.WorldMgr.GetDefaultDbcLocale() == locale || locale == Locale.None)
continue;
PreparedStatement stmt = DB.Hotfix.GetPreparedStatement(preparedStatementLocale);
@@ -235,7 +235,7 @@ namespace Game.DataStorage
return ContainsKey(id);
}
public void WriteRecord(uint id, LocaleConstant locale, ByteBuffer buffer)
public void WriteRecord(uint id, Locale locale, ByteBuffer buffer)
{
T entry = this.LookupByKey(id);
@@ -536,13 +536,13 @@ namespace Game.DataStorage
LocalizedString localized = new LocalizedString();
if (_stringsTable == null)
{
localized[LocaleConstant.enUS] = _data.ReadCString();
localized[Locale.enUS] = _data.ReadCString();
}
else
{
var pos = _recordsOffset + (_data.Position >> 3);
int ofs = GetFieldValue<int>(fieldIndex);
localized[LocaleConstant.enUS] = _stringsTable.LookupByKey(pos + ofs);
localized[Locale.enUS] = _stringsTable.LookupByKey(pos + ofs);
}
f.SetValue(obj, localized);
@@ -732,12 +732,12 @@ namespace Game.DataStorage
public class LocalizedString
{
public bool HasString(LocaleConstant locale = SharedConst.DefaultLocale)
public bool HasString(Locale locale = SharedConst.DefaultLocale)
{
return !string.IsNullOrEmpty(stringStorage[(int)locale]);
}
public string this[LocaleConstant locale]
public string this[Locale locale]
{
get
{
@@ -749,6 +749,6 @@ namespace Game.DataStorage
}
}
StringArray stringStorage = new StringArray((int)LocaleConstant.Total);
StringArray stringStorage = new StringArray((int)Locale.Total);
}
}
+18 -18
View File
@@ -18,7 +18,7 @@
using Framework.Constants;
using Framework.Database;
using Framework.GameMath;
using Game.Network;
using Game.Networking;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -37,7 +37,7 @@ namespace Game.DataStorage
_powersByClass[i][j] = (uint)PowerType.Max;
}
for (uint i = 0; i < (int)LocaleConstant.Total + 1; ++i)
for (uint i = 0; i < (int)Locale.Total + 1; ++i)
_nameValidators[i] = new List<string>();
}
@@ -360,13 +360,13 @@ namespace Game.DataStorage
foreach (var namesProfanity in CliDB.NamesProfanityStorage.Values)
{
Cypher.Assert(namesProfanity.Language < (int)LocaleConstant.Total || namesProfanity.Language == -1);
Cypher.Assert(namesProfanity.Language < (int)Locale.Total || namesProfanity.Language == -1);
if (namesProfanity.Language != -1)
_nameValidators[namesProfanity.Language].Add(namesProfanity.Name);
else
for (uint i = 0; i < (int)LocaleConstant.Total; ++i)
for (uint i = 0; i < (int)Locale.Total; ++i)
{
if (i == (int)LocaleConstant.None)
if (i == (int)Locale.None)
continue;
_nameValidators[i].Add(namesProfanity.Name);
@@ -376,16 +376,16 @@ namespace Game.DataStorage
CliDB.NamesProfanityStorage.Clear();
foreach (var namesReserved in CliDB.NamesReservedStorage.Values)
_nameValidators[(int)LocaleConstant.Total].Add(namesReserved.Name);
_nameValidators[(int)Locale.Total].Add(namesReserved.Name);
CliDB.NamesReservedStorage.Clear();
foreach (var namesReserved in CliDB.NamesReservedLocaleStorage.Values)
{
Cypher.Assert(!Convert.ToBoolean(namesReserved.LocaleMask & ~((1 << (int)LocaleConstant.Total) - 1)));
for (int i = 0; i < (int)LocaleConstant.Total; ++i)
Cypher.Assert(!Convert.ToBoolean(namesReserved.LocaleMask & ~((1 << (int)Locale.Total) - 1)));
for (int i = 0; i < (int)Locale.Total; ++i)
{
if (i == (int)LocaleConstant.None)
if (i == (int)Locale.None)
continue;
if (Convert.ToBoolean(namesReserved.LocaleMask & (1 << i)))
@@ -816,7 +816,7 @@ namespace Game.DataStorage
return (uint)CliDB.AzeriteLevelInfoStorage.Count;
}
public string GetBroadcastTextValue(BroadcastTextRecord broadcastText, LocaleConstant locale = LocaleConstant.enUS, Gender gender = Gender.Male, bool forceGender = false)
public string GetBroadcastTextValue(BroadcastTextRecord broadcastText, Locale locale = Locale.enUS, Gender gender = Gender.Male, bool forceGender = false)
{
if ((gender == Gender.Female || gender == Gender.None) && (forceGender || broadcastText.Text1.HasString(SharedConst.DefaultLocale)))
{
@@ -857,7 +857,7 @@ namespace Game.DataStorage
return _charStartOutfits.LookupByKey(race | (class_ << 8) | (gender << 16));
}
public string GetClassName(Class class_, LocaleConstant locale = LocaleConstant.enUS)
public string GetClassName(Class class_, Locale locale = Locale.enUS)
{
ChrClassesRecord classEntry = CliDB.ChrClassesStorage.LookupByKey(class_);
if (classEntry == null)
@@ -866,7 +866,7 @@ namespace Game.DataStorage
if (classEntry.Name[locale][0] != '\0')
return classEntry.Name[locale];
return classEntry.Name[LocaleConstant.enUS];
return classEntry.Name[Locale.enUS];
}
public uint GetPowerIndexByClass(PowerType powerType, Class classId)
@@ -874,7 +874,7 @@ namespace Game.DataStorage
return _powersByClass[(int)classId][(int)powerType];
}
public string GetChrRaceName(Race race, LocaleConstant locale = LocaleConstant.enUS)
public string GetChrRaceName(Race race, Locale locale = Locale.enUS)
{
ChrRacesRecord raceEntry = CliDB.ChrRacesStorage.LookupByKey(race);
if (raceEntry == null)
@@ -883,7 +883,7 @@ namespace Game.DataStorage
if (raceEntry.Name[locale][0] != '\0')
return raceEntry.Name[locale];
return raceEntry.Name[LocaleConstant.enUS];
return raceEntry.Name[Locale.enUS];
}
public ChrSpecializationRecord GetChrSpecializationByIndex(Class class_, uint index)
@@ -896,7 +896,7 @@ namespace Game.DataStorage
return _defaultChrSpecializationsByClass.LookupByKey(class_);
}
public string GetCreatureFamilyPetName(CreatureFamily petfamily, LocaleConstant locale)
public string GetCreatureFamilyPetName(CreatureFamily petfamily, Locale locale)
{
if (petfamily == CreatureFamily.None)
return null;
@@ -1526,14 +1526,14 @@ namespace Game.DataStorage
return listNameGen[gender].SelectRandom().Name;
}
public ResponseCodes ValidateName(string name, LocaleConstant locale)
public ResponseCodes ValidateName(string name, Locale locale)
{
foreach (var testName in _nameValidators[(int)locale])
if (testName.Equals(name, StringComparison.OrdinalIgnoreCase))
return ResponseCodes.CharNameProfane;
// regexes at TOTAL_LOCALES are loaded from NamesReserved which is not locale specific
foreach (var testName in _nameValidators[(int)LocaleConstant.Total])
foreach (var testName in _nameValidators[(int)Locale.Total])
if (testName.Equals(name, StringComparison.OrdinalIgnoreCase))
return ResponseCodes.CharNameReserved;
@@ -2099,7 +2099,7 @@ namespace Game.DataStorage
MultiMap<uint, MountTypeXCapabilityRecord> _mountCapabilitiesByType = new MultiMap<uint, MountTypeXCapabilityRecord>();
MultiMap<uint, MountXDisplayRecord> _mountDisplays = new MultiMap<uint, MountXDisplayRecord>();
Dictionary<uint, List<NameGenRecord>[]> _nameGenData = new Dictionary<uint, List<NameGenRecord>[]>();
List<string>[] _nameValidators = new List<string>[(int)LocaleConstant.Total + 1];
List<string>[] _nameValidators = new List<string>[(int)Locale.Total + 1];
MultiMap<uint, uint> _phasesByGroup = new MultiMap<uint, uint>();
Dictionary<PowerType, PowerTypeRecord> _powerTypes = new Dictionary<PowerType, PowerTypeRecord>();
Dictionary<uint, byte> _pvpItemBonus = new Dictionary<uint, byte>();