From bec0cae0ebd6a3b5837fc565ffbb7d8a69089346 Mon Sep 17 00:00:00 2001 From: Filip Maj Date: Sat, 20 Oct 2018 12:08:47 -0400 Subject: [PATCH] Removed more dapper code and unsupported syntax. --- FFXIVClassic Lobby Server/Database.cs | 265 +++++++++++++----- .../dataobjects/World.cs | 32 ++- .../actors/chara/Character.cs | 33 ++- 3 files changed, 244 insertions(+), 86 deletions(-) diff --git a/FFXIVClassic Lobby Server/Database.cs b/FFXIVClassic Lobby Server/Database.cs index a08da78e..67e4534d 100644 --- a/FFXIVClassic Lobby Server/Database.cs +++ b/FFXIVClassic Lobby Server/Database.cs @@ -1,6 +1,5 @@ using FFXIVClassic_Lobby_Server.dataobjects; using MySql.Data.MySqlClient; -using Dapper; using System; using System.Collections.Generic; using System.Linq; @@ -361,48 +360,105 @@ namespace FFXIVClassic_Lobby_Server public static List GetServers() { - using (var conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD))) + string query; + MySqlCommand cmd; + List worldList = new List(); + + using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD))) { - List worldList = null; try { conn.Open(); - worldList = conn.Query("SELECT * FROM servers WHERE isActive=true").ToList(); + query = "SELECT * FROM servers WHERE isActive=true"; + cmd = new MySqlCommand(query, conn); + + using (MySqlDataReader reader = cmd.ExecuteReader()) + { + while (reader.Read()) + { + ushort id; + string address; + ushort port; + ushort listPosition; + ushort population; + string name; + bool isActive; + + id = reader.GetUInt16("id"); + address = reader.GetString("address"); + port = reader.GetUInt16("port"); + listPosition = reader.GetUInt16("listPosition"); + population = reader.GetUInt16("population"); + name = reader.GetString("name"); + isActive = reader.GetBoolean("isActive"); + + worldList.Add(new World(id, address, port, listPosition, population, name, isActive)); + } + } } catch (MySqlException e) { Program.Log.Error(e.ToString()); - worldList = new List(); } + worldList = new List(); + } finally - { + { conn.Dispose(); } - return worldList; } + return worldList; } public static World GetServer(uint serverId) { - using (var conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD))) + string query; + MySqlCommand cmd; + World world = null; + + using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD))) { - World world = null; try { conn.Open(); - world = conn.Query("SELECT * FROM servers WHERE id=@ServerId", new {ServerId = serverId}).SingleOrDefault(); + query = "SELECT * FROM servers WHERE id=@ServerId"; + cmd = new MySqlCommand(query, conn); + cmd.Parameters.AddWithValue("@ServerId", serverId); + + using (MySqlDataReader reader = cmd.ExecuteReader()) + { + while (reader.Read()) + { + ushort id; + string address; + ushort port; + ushort listPosition; + ushort population; + string name; + bool isActive; + + id = reader.GetUInt16("id"); + address = reader.GetString("address"); + port = reader.GetUInt16("port"); + listPosition = reader.GetUInt16("listPosition"); + population = reader.GetUInt16("population"); + name = reader.GetString("name"); + isActive = reader.GetBoolean("isActive"); + + world = new World(id, address, port, listPosition, population, name, isActive); + } + } } catch (MySqlException e) { - Program.Log.Error(e.ToString()); - + Program.Log.Error(e.ToString()); } finally { conn.Dispose(); } - - return world; } + + return world; } public static List GetCharacters(uint userId) @@ -468,9 +524,11 @@ namespace FFXIVClassic_Lobby_Server Character chara = null; using (var conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD))) { - conn.Open(); + try + { + conn.Open(); - string query = @" + string query = @" SELECT id, slot, @@ -490,100 +548,179 @@ namespace FFXIVClassic_Lobby_Server INNER JOIN characters_parametersave ON id = characters_parametersave.characterId WHERE id = @charId"; - MySqlCommand cmd = new MySqlCommand(query, conn); - cmd.Parameters.AddWithValue("@charId", charId); - using (MySqlDataReader reader = cmd.ExecuteReader()) - { - if (reader.Read()) + MySqlCommand cmd = new MySqlCommand(query, conn); + cmd.Parameters.AddWithValue("@charId", charId); + using (MySqlDataReader reader = cmd.ExecuteReader()) { - chara = new Character(); - chara.id = reader.GetUInt32("id"); - chara.slot = reader.GetUInt16("slot"); - chara.serverId = reader.GetUInt16("serverId"); - chara.name = reader.GetString("name"); - chara.isLegacy = reader.GetBoolean("isLegacy"); - chara.doRename = reader.GetBoolean("doRename"); - chara.currentZoneId = reader.GetUInt32("currentZoneId"); - chara.guardian = reader.GetByte("guardian"); - chara.birthMonth = reader.GetByte("birthMonth"); - chara.birthDay = reader.GetByte("birthDay"); - chara.initialTown = reader.GetByte("initialTown"); - chara.tribe = reader.GetByte("tribe"); - chara.currentClass = reader.GetByte("mainSkill"); - //chara.currentJob = ??? - chara.currentLevel = reader.GetInt16("mainSkillLevel"); + if (reader.Read()) + { + chara = new Character(); + chara.id = reader.GetUInt32("id"); + chara.slot = reader.GetUInt16("slot"); + chara.serverId = reader.GetUInt16("serverId"); + chara.name = reader.GetString("name"); + chara.isLegacy = reader.GetBoolean("isLegacy"); + chara.doRename = reader.GetBoolean("doRename"); + chara.currentZoneId = reader.GetUInt32("currentZoneId"); + chara.guardian = reader.GetByte("guardian"); + chara.birthMonth = reader.GetByte("birthMonth"); + chara.birthDay = reader.GetByte("birthDay"); + chara.initialTown = reader.GetByte("initialTown"); + chara.tribe = reader.GetByte("tribe"); + chara.currentClass = reader.GetByte("mainSkill"); + //chara.currentJob = ??? + chara.currentLevel = reader.GetInt16("mainSkillLevel"); + } } } + catch (MySqlException e) + { + Program.Log.Error(e.ToString()); + + } + finally + { + conn.Dispose(); + } } return chara; } public static Appearance GetAppearance(uint charaId) { + Appearance appearance = null; using (var conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD))) { - Appearance appearance = null; try { conn.Open(); - appearance = conn.Query("SELECT * FROM characters_appearance WHERE characterId=@CharaId", new { CharaId = charaId }).SingleOrDefault(); + //Load appearance + string query = @" + SELECT + baseId, + size, + voice, + skinColor, + hairStyle, + hairColor, + hairHighlightColor, + eyeColor, + characteristics, + characteristicsColor, + faceType, + ears, + faceMouth, + faceFeatures, + faceNose, + faceEyeShape, + faceIrisSize, + faceEyebrows, + mainHand, + offHand, + head, + body, + legs, + hands, + feet, + waist, + leftFinger, + rightFinger, + leftEar, + rightEar + FROM characters_appearance WHERE characterId = @charaId"; + + MySqlCommand cmd = new MySqlCommand(query, conn); + cmd.Parameters.AddWithValue("@charaId", charaId); + using (MySqlDataReader reader = cmd.ExecuteReader()) + { + if (reader.Read()) + { + appearance.size = reader.GetByte("size"); + appearance.voice = reader.GetByte("voice"); + appearance.skinColor = reader.GetByte("skinColor"); + appearance.hairStyle = reader.GetByte("hairStyle"); + appearance.hairColor = reader.GetByte("hairColor"); + appearance.hairHighlightColor = reader.GetByte("hairHighlightColor"); + appearance.eyeColor = reader.GetByte("eyeColor"); + appearance.characteristics = reader.GetByte("characteristics"); + appearance.characteristicsColor = reader.GetByte("characteristicsColor"); + appearance.faceType = reader.GetByte("faceType"); + appearance.ears = reader.GetByte("ears"); + appearance.faceMouth = reader.GetByte("faceMouth"); + appearance.faceFeatures = reader.GetByte("faceFeatures"); + appearance.faceNose = reader.GetByte("faceNose"); + appearance.faceEyeShape = reader.GetByte("faceEyeShape"); + appearance.faceIrisSize = reader.GetByte("faceIrisSize"); + appearance.faceEyebrows = reader.GetByte("faceEyebrows"); + + appearance.mainHand = reader.GetByte("mainHand"); + appearance.offHand = reader.GetByte("offHand"); + appearance.head = reader.GetByte("head"); + appearance.body = reader.GetByte("body"); + appearance.mainHand = reader.GetByte("mainHand"); + appearance.legs = reader.GetByte("legs"); + appearance.hands = reader.GetByte("hands"); + appearance.feet = reader.GetByte("feet"); + appearance.waist = reader.GetByte("waist"); + appearance.leftFinger = reader.GetByte("leftFinger"); + appearance.rightFinger = reader.GetByte("rightFinger"); + appearance.leftEar = reader.GetByte("leftEar"); + appearance.rightEar = reader.GetByte("rightEar"); + } + + } } catch (MySqlException e) { Program.Log.Error(e.ToString()); - + } finally { conn.Dispose(); } - - return appearance; } + + return appearance; } public static List GetReservedNames(uint userId) { + List reservedNames = new List(); using (var conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD))) { - List nameList = null; try { conn.Open(); - nameList = conn.Query("SELECT name FROM reserved_names WHERE userId=@UserId", new { UserId = userId }).ToList(); + + string query = "SELECT name FROM reserved_names WHERE userId=@UserId"; + + MySqlCommand cmd = new MySqlCommand(query, conn); + cmd.Parameters.AddWithValue("@UserId", userId); + using (MySqlDataReader reader = cmd.ExecuteReader()) + { + while (reader.Read()) + { + reservedNames.Add(reader.GetString("name")); + } + } } catch (MySqlException e) { Program.Log.Error(e.ToString()); - nameList = new List(); } + + } finally { conn.Dispose(); } - return nameList; } + return reservedNames; } public static List GetRetainers(uint userId) { - using (var conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD))) - { - List retainerList = null; - try - { - conn.Open(); - retainerList = conn.Query("SELECT * FROM retainers WHERE id=@UserId ORDER BY characterId, slot", new { UserId = userId }).ToList(); - } - catch (MySqlException e) - { - Program.Log.Error(e.ToString()); - retainerList = new List(); } - finally - { - conn.Dispose(); - } - return retainerList; - } + return new List(); } } diff --git a/FFXIVClassic Lobby Server/dataobjects/World.cs b/FFXIVClassic Lobby Server/dataobjects/World.cs index 8cab7502..67749216 100644 --- a/FFXIVClassic Lobby Server/dataobjects/World.cs +++ b/FFXIVClassic Lobby Server/dataobjects/World.cs @@ -2,12 +2,30 @@ { class World { - public ushort id; - public string address; - public ushort port; - public ushort listPosition; - public ushort population; - public string name; - public bool isActive; + public readonly ushort id; + public readonly string address; + public readonly ushort port; + public readonly ushort listPosition; + public readonly ushort population; + public readonly string name; + public readonly bool isActive; + + public World( + ushort id, + string address, + ushort port, + ushort listPosition, + ushort population, + string name, + bool isActive) + { + this.id = id; + this.address = address; + this.port = port; + this.listPosition = listPosition; + this.population = population; + this.name = name; + this.isActive = isActive; + } } } diff --git a/FFXIVClassic Map Server/actors/chara/Character.cs b/FFXIVClassic Map Server/actors/chara/Character.cs index e6735553..4aa32d67 100644 --- a/FFXIVClassic Map Server/actors/chara/Character.cs +++ b/FFXIVClassic Map Server/actors/chara/Character.cs @@ -200,7 +200,7 @@ namespace FFXIVClassic_Map_Server.Actors { if (!effect.GetHidden()) { - propPacketUtil.AddProperty($"charaWork.statusShownTime[{i}]"); + propPacketUtil.AddProperty(String.Format("charaWork.statusShownTime[{0}]", i)); propPacketUtil.AddProperty(String.Format("charaWork.statusShownTime[{0}]", i)); i++; } @@ -287,7 +287,8 @@ namespace FFXIVClassic_Map_Server.Actors #region ai stuff public void PathTo(float x, float y, float z, float stepSize = 0.70f, int maxPath = 40, float polyRadius = 0.0f) { - aiContainer?.pathFind?.PreparePath(x, y, z, stepSize, maxPath, polyRadius); + if (aiContainer != null && aiContainer.pathFind != null) + aiContainer.pathFind.PreparePath(x, y, z, stepSize, maxPath, polyRadius); } public void FollowTarget(Actor target, float stepSize = 1.2f, int maxPath = 25, float radius = 0.0f) @@ -759,7 +760,7 @@ namespace FFXIVClassic_Map_Server.Actors foreach (BattleAction action in actions) { - if (zone.FindActorInArea(action.targetId) is Character chara) + if (zone.FindActorInArea(action.targetId) is Character) { //BattleUtils.HandleHitType(this, chara, action); //BattleUtils.DoAction(this, chara, action, DamageTakenType.Magic); @@ -775,7 +776,7 @@ namespace FFXIVClassic_Map_Server.Actors foreach (BattleAction action in actions) { //Should we just store the character insteado f having to find it again? - if (zone.FindActorInArea(action.targetId) is Character chara) + if (zone.FindActorInArea(action.targetId) is Character) { //BattleUtils.DoAction(this, chara, action, DamageTakenType.Weaponskill); } @@ -788,7 +789,7 @@ namespace FFXIVClassic_Map_Server.Actors { foreach (var action in actions) { - if (zone.FindActorInArea(action.targetId) is Character chara) + if (zone.FindActorInArea(action.targetId) is Character) { //BattleUtils.DoAction(this, chara, action, DamageTakenType.Ability); } @@ -947,12 +948,12 @@ namespace FFXIVClassic_Map_Server.Actors { shouldSend = true; charaWork.battleTemp.timingCommandFlag[i] = false; - propPacketUtil.AddProperty($"charaWork.battleTemp.timingCommandFlag[{i}]"); + propPacketUtil.AddProperty(String.Format("charaWork.battleTemp.timingCommandFlag[{0}]", i)); } } - if (shouldSend && this is Player player) - player.QueuePackets(propPacketUtil.Done()); + if (shouldSend && this is Player) + ((Player)this).QueuePackets(propPacketUtil.Done()); } //Set given proc to true and send packet if this is a player @@ -976,11 +977,11 @@ namespace FFXIVClassic_Map_Server.Actors statusEffects.RemoveStatusEffect(statusEffects.GetStatusEffectById((uint)effectId)); } - if (this is Player player) + if (this is Player) { var propPacketUtil = new ActorPropertyPacketUtil("charaWork/timingCommand", this); - propPacketUtil.AddProperty($"charaWork.battleTemp.timingCommandFlag[{procId}]"); - player.QueuePackets(propPacketUtil.Done()); + propPacketUtil.AddProperty(String.Format("charaWork.battleTemp.timingCommandFlag[{0}]", procId)); + ((Player)this).QueuePackets(propPacketUtil.Done()); } } @@ -1106,12 +1107,14 @@ namespace FFXIVClassic_Map_Server.Actors } //Now that we know if we hit the target we can check if the combo continues - if (this is Player player) + if (this is Player) + { if (command.isCombo && hitTarget) - player.SetCombos(command.comboNextCommandId); + ((Player)this).SetCombos(command.comboNextCommandId); else - player.SetCombos(); - + ((Player)this).SetCombos(); + } + BattleAction error = new BattleAction(actorId, 0, 0); DelMP(command.CalculateMpCost(this)); DelTP(command.CalculateTpCost(this));