public uint GetMaxId() { MySqlResult result = SelectPreparedStatement(CharacterPreparedStatement.CharacterMaxIndex); Debug.Assert(result != null, "Invalid prepared statement value."); return(result.Read <uint>(0, "MAX(`guid`)") + 1); }
public async Task <Character> LoadCharacter(uint id) { MySqlResult result = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterSelect, id); Character c = null; if (result?.Count > 0) { uint guid = result.Read <uint>(0, "guid"); uint accountId = result.Read <uint>(0, "accountId"); c = new Character(guid, accountId); c.Name = result.Read <string>(0, "name"); c.TemplateOption = result.Read <uint>(0, "templateOption"); c.StartArea = result.Read <uint>(0, "startArea"); c.IsAdmin = result.Read <bool>(0, "isAdmin"); c.IsEnvoy = result.Read <bool>(0, "isEnvoy"); c.Position = await this.GetPosition(guid); result = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterSkillsSelect, id); for (uint i = 0; i < result?.Count; i++) { Skill s = result.Read <Skill>(i, "skillId"); SkillStatus ss = result.Read <SkillStatus>(i, "skillStatus"); uint ranks = result.Read <uint>(i, "skillPoints"); c.Skills.Add(s, new CharacterSkill(c, s, ss, ranks)); } result = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterStatsSelect, id); if (result?.Count > 0) { c.Strength.Base = result.Read <uint>(0, "strength"); c.Strength.Ranks = result.Read <uint>(0, "strength_ranks"); c.Endurance.Base = result.Read <uint>(0, "endurance"); c.Endurance.Ranks = result.Read <uint>(0, "endurance_ranks"); c.Coordination.Base = result.Read <uint>(0, "coordination"); c.Coordination.Ranks = result.Read <uint>(0, "coordination_ranks"); c.Quickness.Base = result.Read <uint>(0, "quickness"); c.Quickness.Ranks = result.Read <uint>(0, "quickness_ranks"); c.Focus.Base = result.Read <uint>(0, "focus"); c.Focus.Ranks = result.Read <uint>(0, "focus_ranks"); c.Self.Base = result.Read <uint>(0, "self"); c.Self.Ranks = result.Read <uint>(0, "self_ranks"); c.Health.Ranks = result.Read <uint>(0, "health_ranks"); c.Health.Current = result.Read <uint>(0, "health_current"); c.Stamina.Ranks = result.Read <uint>(0, "stamina_ranks"); c.Stamina.Current = result.Read <uint>(0, "stamina_current"); c.Mana.Ranks = result.Read <uint>(0, "mana_ranks"); c.Mana.Current = result.Read <uint>(0, "mana_current"); } } return(c); }
public bool IsNameAvailable(string name) { MySqlResult result = SelectPreparedStatement(CharacterPreparedStatement.CharacterUniqueNameSelect, name); Debug.Assert(result != null, "Invalid prepared statement value."); uint charsWithName = result.Read <uint>(0, "cnt"); return(charsWithName == 0); }
private uint GetMaxId(WorldPreparedStatement id, uint min, uint max) { object[] critera = new object[] { min, max }; MySqlResult res = SelectPreparedStatement <WorldPreparedStatement>(id, critera); var ret = res.Rows[0][0]; if (ret is DBNull) { return(uint.MaxValue); } return((uint)res.Rows[0][0]); }
protected async Task <MySqlResult> SelectPreparedStatementAsync <T>(T id, params object[] parameters) { Debug.Assert(typeof(T) == PreparedStatementType, "Invalid prepared statement type."); StoredPreparedStatement preparedStatement; if (!preparedStatements.TryGetValue(Convert.ToUInt32(id), out preparedStatement)) { Debug.Assert(preparedStatement != null, "Invalid prepared statement id."); return(null); } try { using (var connection = new MySqlConnection(connectionString)) { using (var command = new MySqlCommand(preparedStatement.Query, connection)) { for (int i = 0; i < preparedStatement.Types.Count; i++) { command.Parameters.Add("", preparedStatement.Types[i]).Value = parameters[i]; } await connection.OpenAsync(); return(await Task.Run(() => { using (var commandReader = command.ExecuteReader(CommandBehavior.Default)) { using (var result = new MySqlResult()) { result.Load(commandReader); result.Count = (uint)result.Rows.Count; return result; } } })); } } } catch (Exception exception) { log.Error($"An exception occured while selecting prepared statement {id}!"); log.Error($"Exception: {exception.Message}"); } return(null); }
public async Task <List <CachedCharacter> > GetByAccount(uint accountId) { MySqlResult result = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterListSelect, accountId); List <CachedCharacter> characters = new List <CachedCharacter>(); for (byte i = 0; i < result.Count; i++) { uint lowGuid = result.Read <uint>(i, "guid"); string name = result.Read <string>(i, "name"); ulong deleteTime = result.Read <ulong>(i, "deleteTime"); characters.Add(new CachedCharacter(new ObjectGuid(lowGuid, GuidType.Player), i, name, deleteTime)); } return(characters); }
protected MySqlResult SelectPreparedStatement <T>(T id, params object[] parameters) { Debug.Assert(typeof(T) == preparedStatementType); StoredPreparedStatement preparedStatement; if (!preparedStatements.TryGetValue(Convert.ToUInt32(id), out preparedStatement)) { Debug.Assert(preparedStatement != null); return(null); } try { using (var connection = new MySqlConnection(connectionString)) { connection.Open(); using (var command = new MySqlCommand(preparedStatement.Query, connection)) { for (int i = 0; i < preparedStatement.Types.Count; i++) { command.Parameters.Add("", preparedStatement.Types[i]).Value = parameters[i]; } using (var commandReader = command.ExecuteReader(CommandBehavior.Default)) { using (var result = new MySqlResult()) { result.Load(commandReader); result.Count = (uint)result.Rows.Count; return(result); } } } } } catch (Exception exception) { Console.WriteLine($"An exception occured while selecting prepared statement {id}!"); Console.WriteLine($"Exception: {exception.Message}"); } return(null); }
public async Task <Character> GetCharacterByName(string name) { MySqlResult result = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterSelectByName, name); Character c = null; if (result?.Count > 0) { uint guid = result.Read <uint>(0, "guid"); uint accountId = result.Read <uint>(0, "accountId"); c = new Character(guid, accountId); c.Name = result.Read <string>(0, "name"); c.TemplateOption = result.Read <uint>(0, "templateOption"); c.StartArea = result.Read <uint>(0, "startArea"); } return(c); }
public async Task <Position> GetPosition(uint id) { MySqlResult result = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterPositionSelect, id); Position pos; if (result.Count > 0) { pos = new Position(result.Read <uint>(0, "cell"), result.Read <float>(0, "positionX"), result.Read <float>(0, "positionY"), result.Read <float>(0, "positionZ"), result.Read <float>(0, "rotationX"), result.Read <float>(0, "rotationY"), result.Read <float>(0, "rotationZ"), result.Read <float>(0, "rotationW")); } else { // use fallback position if position information doesn't exist in the DB, show error in the future pos = new Position(0x7F0401AD, 12.3199f, -28.482f, 0.0049999995f, 0.0f, 0.0f, -0.9408059f, -0.3389459f); } return(pos); }
public async Task LoadCharacterProperties(DbObject dbObject) { MySqlResult results = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterPropertiesBoolSelect, dbObject.Id); for (uint i = 0; i < results.Count; i++) { dbObject.SetPropertyBool(results.Read <PropertyBool>(i, "propertyId"), results.Read <bool>(i, "propertyValue")); } results = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterPropertiesIntSelect, dbObject.Id); for (uint i = 0; i < results.Count; i++) { dbObject.SetPropertyInt(results.Read <PropertyInt>(i, "propertyId"), results.Read <uint>(i, "propertyValue")); } results = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterPropertiesBigIntSelect, dbObject.Id); for (uint i = 0; i < results.Count; i++) { dbObject.SetPropertyInt64(results.Read <PropertyInt64>(i, "propertyId"), results.Read <ulong>(i, "propertyValue")); } results = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterPropertiesDoubleSelect, dbObject.Id); for (uint i = 0; i < results.Count; i++) { dbObject.SetPropertyDouble(results.Read <PropertyDouble>(i, "propertyId"), results.Read <double>(i, "propertyValue")); } results = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterPropertiesStringSelect, dbObject.Id); for (uint i = 0; i < results.Count; i++) { dbObject.SetPropertyString(results.Read <PropertyString>(i, "propertyId"), results.Read <string>(i, "propertyValue")); } }
public async Task <Character> LoadCharacter(uint id) { MySqlResult result = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterSelect, id); Character c = null; if (result?.Count > 0) { uint guid = result.Read <uint>(0, "guid"); uint accountId = result.Read <uint>(0, "accountId"); c = new Character(guid, accountId); c.Name = result.Read <string>(0, "name"); c.TemplateOption = result.Read <uint>(0, "templateOption"); c.StartArea = result.Read <uint>(0, "startArea"); c.Position = await this.GetPosition(guid); uint characterOptions1Flag = result.Read <uint>(0, "characterOptions1"); uint characterOptions2Flag = result.Read <uint>(0, "characterOptions2"); LoadCharacterOptions(characterOptions1Flag, characterOptions2Flag, c); result = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterSkillsSelect, id); for (uint i = 0; i < result?.Count; i++) { Skill s = result.Read <Skill>(i, "skillId"); SkillStatus ss = result.Read <SkillStatus>(i, "skillStatus"); uint ranks = result.Read <uint>(i, "skillPoints"); uint xpSpent = result.Read <uint>(i, "skillXpSpent"); c.Skills.Add(s, new CharacterSkill(c, s, ss, ranks, xpSpent)); } result = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterAppearanceSelect, id); if (result?.Count > 0) { c.Appearance = new Appearance(); c.Appearance.Eyes = result.Read <uint>(0, "eyes"); c.Appearance.Nose = result.Read <uint>(0, "nose"); c.Appearance.Mouth = result.Read <uint>(0, "mouth"); c.Appearance.EyeColor = result.Read <uint>(0, "eyeColor"); c.Appearance.HairColor = result.Read <uint>(0, "hairColor"); c.Appearance.HairStyle = result.Read <uint>(0, "hairStyle"); c.Appearance.HairHue = result.Read <uint>(0, "hairHue"); c.Appearance.SkinHue = result.Read <uint>(0, "skinHue"); } result = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterStatsSelect, id); if (result?.Count > 0) { c.Strength.Base = result.Read <uint>(0, "strength"); c.Strength.ExperienceSpent = result.Read <uint>(0, "strengthXpSpent"); c.Strength.Ranks = result.Read <uint>(0, "strengthRanks"); c.Endurance.Base = result.Read <uint>(0, "endurance"); c.Endurance.ExperienceSpent = result.Read <uint>(0, "enduranceXpSpent"); c.Endurance.Ranks = result.Read <uint>(0, "enduranceRanks"); c.Coordination.Base = result.Read <uint>(0, "coordination"); c.Coordination.ExperienceSpent = result.Read <uint>(0, "coordinationXpSpent"); c.Coordination.Ranks = result.Read <uint>(0, "coordinationRanks"); c.Quickness.Base = result.Read <uint>(0, "quickness"); c.Quickness.ExperienceSpent = result.Read <uint>(0, "quicknessXpSpent"); c.Quickness.Ranks = result.Read <uint>(0, "quicknessRanks"); c.Focus.Base = result.Read <uint>(0, "focus"); c.Focus.ExperienceSpent = result.Read <uint>(0, "focusXpSpent"); c.Focus.Ranks = result.Read <uint>(0, "focusRanks"); c.Self.Base = result.Read <uint>(0, "self"); c.Self.ExperienceSpent = result.Read <uint>(0, "selfXpSpent"); c.Self.Ranks = result.Read <uint>(0, "selfRanks"); c.Health.Ranks = result.Read <uint>(0, "healthRanks"); c.Health.ExperienceSpent = result.Read <uint>(0, "healthXpSpent"); c.Health.Current = result.Read <uint>(0, "healthCurrent"); c.Stamina.Ranks = result.Read <uint>(0, "staminaRanks"); c.Stamina.ExperienceSpent = result.Read <uint>(0, "staminaXpSpent"); c.Stamina.Current = result.Read <uint>(0, "staminaCurrent"); c.Mana.Ranks = result.Read <uint>(0, "manaRanks"); c.Mana.ExperienceSpent = result.Read <uint>(0, "manaXpSpent"); c.Mana.Current = result.Read <uint>(0, "manaCurrent"); } result = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterFriendsSelect, id); for (uint i = 0; i < result?.Count; i++) { Friend f = new Friend(); f.Id = new ObjectGuid(result.Read <uint>(i, "friendId"), GuidType.Player); f.Name = result.Read <string>(i, "name"); // Not sure we want the actually load these next two values. They are passed in the packet, but their purpose is unknown. f.FriendIdList = new List <ObjectGuid>(); f.FriendOfIdList = new List <ObjectGuid>(); c.AddFriend(f); } await LoadCharacterProperties(c); } return(c); }
public async Task <Character> LoadCharacter(uint id) { MySqlResult result = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterSelect, id); Character c = null; if (result?.Count > 0) { uint guid = result.Read <uint>(0, "guid"); uint accountId = result.Read <uint>(0, "accountId"); c = new Character(guid, accountId); c.Name = result.Read <string>(0, "name"); c.TemplateOption = result.Read <uint>(0, "templateOption"); c.StartArea = result.Read <uint>(0, "startArea"); c.TotalLogins = result.Read <uint>(0, "totalLogins"); // Loads the positions into the player object and resets the landlock id LoadCharacterPositions(c); // Load the best location from the database c.Location = c.Positions[PositionType.Location]; uint characterOptions1Flag = result.Read <uint>(0, "characterOptions1"); uint characterOptions2Flag = result.Read <uint>(0, "characterOptions2"); LoadCharacterOptions(characterOptions1Flag, characterOptions2Flag, c); result = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterSkillsSelect, id); for (uint i = 0; i < result?.Count; i++) { Skill s = result.Read <Skill>(i, "skillId"); SkillStatus ss = result.Read <SkillStatus>(i, "skillStatus"); uint ranks = result.Read <uint>(i, "skillPoints"); uint xpSpent = result.Read <uint>(i, "skillXpSpent"); c.Skills.Add(s, new CharacterSkill(c, s, ss, ranks, xpSpent)); } result = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterAppearanceSelect, id); if (result?.Count > 0) { c.Appearance = new Appearance(); c.Appearance.Eyes = result.Read <uint>(0, "eyes"); c.Appearance.Nose = result.Read <uint>(0, "nose"); c.Appearance.Mouth = result.Read <uint>(0, "mouth"); c.Appearance.EyeColor = result.Read <uint>(0, "eyeColor"); c.Appearance.HairColor = result.Read <uint>(0, "hairColor"); c.Appearance.HairStyle = result.Read <uint>(0, "hairStyle"); c.Appearance.HairHue = result.Read <double>(0, "hairHue"); c.Appearance.SkinHue = result.Read <double>(0, "skinHue"); } // Get the character's startup gear. // TODO: This is a temporary solution. Ultimately, this table should be removed entirely and Startup gear should be created/saved in that system once available. result = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterStartupGearSelect, id); if (result?.Count > 0) { c.Appearance.HeadgearStyle = result.Read <uint>(0, "headgearStyle"); c.Appearance.HeadgearColor = result.Read <uint>(0, "headgearColor"); c.Appearance.HeadgearHue = result.Read <float>(0, "headgearHue"); c.Appearance.ShirtStyle = result.Read <uint>(0, "shirtStyle"); c.Appearance.ShirtColor = result.Read <uint>(0, "shirtColor"); c.Appearance.ShirtHue = result.Read <float>(0, "shirtHue"); c.Appearance.PantsStyle = result.Read <uint>(0, "pantsStyle"); c.Appearance.PantsColor = result.Read <uint>(0, "pantsColor"); c.Appearance.PantsHue = result.Read <float>(0, "pantsHue"); c.Appearance.FootwearStyle = result.Read <uint>(0, "footwearStyle"); c.Appearance.FootwearColor = result.Read <uint>(0, "footwearColor"); c.Appearance.FootwearHue = result.Read <float>(0, "footwearHue"); } result = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterStatsSelect, id); if (result?.Count > 0) { c.StrengthAbility.Base = result.Read <uint>(0, "strength"); c.StrengthAbility.ExperienceSpent = result.Read <uint>(0, "strengthXpSpent"); c.StrengthAbility.Ranks = result.Read <uint>(0, "strengthRanks"); c.EnduranceAbility.Base = result.Read <uint>(0, "endurance"); c.EnduranceAbility.ExperienceSpent = result.Read <uint>(0, "enduranceXpSpent"); c.EnduranceAbility.Ranks = result.Read <uint>(0, "enduranceRanks"); c.CoordinationAbility.Base = result.Read <uint>(0, "coordination"); c.CoordinationAbility.ExperienceSpent = result.Read <uint>(0, "coordinationXpSpent"); c.CoordinationAbility.Ranks = result.Read <uint>(0, "coordinationRanks"); c.QuicknessAbility.Base = result.Read <uint>(0, "quickness"); c.QuicknessAbility.ExperienceSpent = result.Read <uint>(0, "quicknessXpSpent"); c.QuicknessAbility.Ranks = result.Read <uint>(0, "quicknessRanks"); c.FocusAbility.Base = result.Read <uint>(0, "focus"); c.FocusAbility.ExperienceSpent = result.Read <uint>(0, "focusXpSpent"); c.FocusAbility.Ranks = result.Read <uint>(0, "focusRanks"); c.SelfAbility.Base = result.Read <uint>(0, "self"); c.SelfAbility.ExperienceSpent = result.Read <uint>(0, "selfXpSpent"); c.SelfAbility.Ranks = result.Read <uint>(0, "selfRanks"); c.Health.Ranks = result.Read <uint>(0, "healthRanks"); c.Health.ExperienceSpent = result.Read <uint>(0, "healthXpSpent"); c.Health.Current = result.Read <uint>(0, "healthCurrent"); c.Stamina.Ranks = result.Read <uint>(0, "staminaRanks"); c.Stamina.ExperienceSpent = result.Read <uint>(0, "staminaXpSpent"); c.Stamina.Current = result.Read <uint>(0, "staminaCurrent"); c.Mana.Ranks = result.Read <uint>(0, "manaRanks"); c.Mana.ExperienceSpent = result.Read <uint>(0, "manaXpSpent"); c.Mana.Current = result.Read <uint>(0, "manaCurrent"); } result = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterFriendsSelect, id); for (uint i = 0; i < result?.Count; i++) { Friend f = new Friend(); f.Id = new ObjectGuid(result.Read <uint>(i, "friendId"), GuidType.Player); f.Name = result.Read <string>(i, "name"); // Not sure we want the actually load these next two values. They are passed in the packet, but their purpose is unknown. f.FriendIdList = new List <ObjectGuid>(); f.FriendOfIdList = new List <ObjectGuid>(); c.AddFriend(f); } await LoadCharacterProperties(c); } return(c); }
public async Task <Character> LoadCharacter(uint id) { MySqlResult result = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterSelect, id); Character c = null; if (result?.Count > 0) { uint guid = result.Read <uint>(0, "guid"); uint accountId = result.Read <uint>(0, "accountId"); c = new Character(guid, accountId); c.Name = result.Read <string>(0, "name"); c.TemplateOption = result.Read <uint>(0, "templateOption"); c.StartArea = result.Read <uint>(0, "startArea"); c.Position = await this.GetPosition(guid); result = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterSkillsSelect, id); for (uint i = 0; i < result?.Count; i++) { Skill s = result.Read <Skill>(i, "skillId"); SkillStatus ss = result.Read <SkillStatus>(i, "skillStatus"); uint ranks = result.Read <uint>(i, "skillPoints"); c.Skills.Add(s, new CharacterSkill(c, s, ss, ranks)); } result = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterAppearanceSelect, id); if (result?.Count > 0) { c.Appearance = new Appearance(); c.Appearance.Eyes = result.Read <uint>(0, "eyes"); c.Appearance.Nose = result.Read <uint>(0, "nose"); c.Appearance.Mouth = result.Read <uint>(0, "mouth"); c.Appearance.EyeColor = result.Read <uint>(0, "eyeColor"); c.Appearance.HairColor = result.Read <uint>(0, "hairColor"); c.Appearance.HairStyle = result.Read <uint>(0, "hairStyle"); c.Appearance.HairHue = result.Read <uint>(0, "hairHue"); c.Appearance.SkinHue = result.Read <uint>(0, "skinHue"); } result = await SelectPreparedStatementAsync(CharacterPreparedStatement.CharacterStatsSelect, id); if (result?.Count > 0) { c.Strength.Base = result.Read <uint>(0, "strength"); c.Strength.Ranks = result.Read <uint>(0, "strengthRanks"); c.Endurance.Base = result.Read <uint>(0, "endurance"); c.Endurance.Ranks = result.Read <uint>(0, "enduranceRanks"); c.Coordination.Base = result.Read <uint>(0, "coordination"); c.Coordination.Ranks = result.Read <uint>(0, "coordinationRanks"); c.Quickness.Base = result.Read <uint>(0, "quickness"); c.Quickness.Ranks = result.Read <uint>(0, "quicknessRanks"); c.Focus.Base = result.Read <uint>(0, "focus"); c.Focus.Ranks = result.Read <uint>(0, "focusRanks"); c.Self.Base = result.Read <uint>(0, "self"); c.Self.Ranks = result.Read <uint>(0, "selfRanks"); c.Health.Ranks = result.Read <uint>(0, "healthRanks"); c.Health.Current = result.Read <uint>(0, "healthCurrent"); c.Stamina.Ranks = result.Read <uint>(0, "staminaRanks"); c.Stamina.Current = result.Read <uint>(0, "staminaCurrent"); c.Mana.Ranks = result.Read <uint>(0, "manaRanks"); c.Mana.Current = result.Read <uint>(0, "manaCurrent"); } LoadCharacterProperties(c); } return(c); }