Fixed all errors with player loader from db. DBAppearance is redundent and was removed.

This commit is contained in:
Filip Maj 2016-01-10 01:19:46 -05:00
parent 16f6fe98b3
commit 9fc4101812
6 changed files with 181 additions and 172 deletions

View file

@ -12,6 +12,8 @@ using FFXIVClassic_Map_Server.dataobjects.database;
using FFXIVClassic_Map_Server.dataobjects.chara.npc;
using FFXIVClassic_Map_Server.dataobjects.chara;
using FFXIVClassic_Map_Server.utils;
using FFXIVClassic_Lobby_Server.packets;
using FFXIVClassic_Map_Server.packets.send.player;
namespace FFXIVClassic_Lobby_Server
{
@ -160,9 +162,8 @@ namespace FFXIVClassic_Lobby_Server
}
}
public static void loadPlayerCharacter(Player player, bool isMe)
{
//Load basic info
public static void loadPlayerCharacter(Player player)
{
string query;
MySqlCommand cmd;
@ -172,87 +173,66 @@ namespace FFXIVClassic_Lobby_Server
{
conn.Open();
if (isMe)
{
query = @"
SELECT
name,
positionX,
positionY,
positionZ,
rotation,
actorState,
currentZoneId,
currentClassJob,
gcCurrent,
gcLimsaRank,
gcGridaniaRank,
gcUldahRank,
currentTitle,
guardian,
birthDay,
birthMonth,
initialNation,
currentParty,
restBonus,
achievementPoints
FROM characters WHERE id = @charId";
}
else
{
query = @"
SELECT
name,
positionX,
positionY,
positionZ,
rotation,
actorState,
currentZoneId,
currentClassJob,
gcCurrent,
gcLimsaRank,
gcGridaniaRank,
gcUldahRank,
currentTitle
FROM characters WHERE id = @charId";
}
//Load basic info
query = @"
SELECT
name,
positionX,
positionY,
positionZ,
rotation,
actorState,
currentZoneId,
currentClassJob,
gcCurrent,
gcLimsaRank,
gcGridaniaRank,
gcUldahRank,
currentTitle,
guardian,
birthDay,
birthMonth,
initialTown,
tribe,
currentParty,
restBonus,
achievementPoints
FROM characters WHERE id = @charId";
cmd = new MySqlCommand(query, conn);
cmd.Parameters.AddWithValue("@charId", player.actorId);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
player.displayNameId = 0xFFFFFFFF;
player.customDisplayName = reader.GetString(0);
player.oldPositionX = player.positionX = reader.GetFloat(1);
player.oldPositionY = player.positionY = reader.GetFloat(2);
player.oldPositionZ = player.positionZ = reader.GetFloat(3);
player.oldRotation = player.rotation = reader.GetFloat(4);
player.currentMainState = reader.GetUInt16(5);
player.currentZoneId = reader.GetUInt32(6);
player.charaWork.parameterSave.state_mainSkill[0] = reader.GetByte(7);
player.gcCurrent = reader.GetByte(8);
player.gcRankLimsa = reader.GetByte(9);
player.gcRankGridania = reader.GetByte(10);
player.gcRankUldah = reader.GetByte(11);
player.currentTitle = reader.GetUInt32(12);
if (isMe)
if (reader.Read())
{
player.displayNameId = 0xFFFFFFFF;
player.customDisplayName = reader.GetString(0);
player.oldPositionX = player.positionX = reader.GetFloat(1);
player.oldPositionY = player.positionY = reader.GetFloat(2);
player.oldPositionZ = player.positionZ = reader.GetFloat(3);
player.oldRotation = player.rotation = reader.GetFloat(4);
player.currentMainState = reader.GetUInt16(5);
player.currentZoneId = reader.GetUInt32(6);
player.charaWork.parameterSave.state_mainSkill[0] = reader.GetByte(7);
player.gcCurrent = reader.GetByte(8);
player.gcRankLimsa = reader.GetByte(9);
player.gcRankGridania = reader.GetByte(10);
player.gcRankUldah = reader.GetByte(11);
player.currentTitle = reader.GetUInt32(12);
player.playerWork.guardian = reader.GetByte(13);
player.playerWork.birthdayDay = reader.GetByte(14);
player.playerWork.birthdayMonth = reader.GetByte(15);
player.playerWork.initialTown = reader.GetByte(16);
player.playerWork.restBonusExpRate = reader.GetInt32(17);
player.achievementPoints = reader.GetUInt32(18);
player.playerWork.tribe = reader.GetByte(17);
player.playerWork.restBonusExpRate = reader.GetInt32(19);
player.achievementPoints = reader.GetUInt32(20);
}
}
//Load appearance
query = @"
SELECT
baseId,
tribe,
baseId,
size,
voice,
skinColor,
@ -288,24 +268,31 @@ namespace FFXIVClassic_Lobby_Server
cmd.Parameters.AddWithValue("@charId", player.actorId);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
player.modelID = DBAppearance.getTribeModel(reader.GetByte(1));
player.appearanceIDs[Character.SIZE] = reader.GetByte(2);
player.appearanceIDs[Character.COLORINFO] = (uint)(reader.GetUInt16(4) | (reader.GetUInt16(6) << 10) | (reader.GetUInt16(8) << 20));
player.appearanceIDs[Character.FACEINFO] = PrimitiveConversion.ToUInt32(CharacterUtils.getFaceInfo(reader.GetByte(9), reader.GetByte(10), reader.GetByte(11), reader.GetByte(12), reader.GetByte(13), reader.GetByte(14), reader.GetByte(15), reader.GetByte(16), reader.GetByte(17), reader.GetByte(18)));
player.appearanceIDs[Character.HIGHLIGHT_HAIR] = (uint)(reader.GetUInt16(7) | reader.GetUInt16(5) << 10);
player.appearanceIDs[Character.VOICE] = reader.GetByte(3);
player.appearanceIDs[Character.WEAPON1] = reader.GetUInt32(19);
player.appearanceIDs[Character.WEAPON2] = reader.GetUInt32(20);
player.appearanceIDs[Character.HEADGEAR] = reader.GetUInt32(21);
player.appearanceIDs[Character.BODYGEAR] = reader.GetUInt32(22);
player.appearanceIDs[Character.LEGSGEAR] = reader.GetUInt32(23);
player.appearanceIDs[Character.HANDSGEAR] = reader.GetUInt32(24);
player.appearanceIDs[Character.FEETGEAR] = reader.GetUInt32(25);
player.appearanceIDs[Character.WAISTGEAR] = reader.GetUInt32(26);
player.appearanceIDs[Character.R_EAR] = reader.GetUInt32(27);
player.appearanceIDs[Character.L_EAR] = reader.GetUInt32(28);
player.appearanceIDs[Character.R_FINGER] = reader.GetUInt32(29);
player.appearanceIDs[Character.L_FINGER] = reader.GetUInt32(30);
if (reader.Read())
{
if (reader.GetUInt32(0) == 0xFFFFFFFF)
player.modelID = CharacterUtils.getTribeModel(player.playerWork.tribe);
else
player.modelID = reader.GetUInt32(0);
player.appearanceIDs[Character.SIZE] = reader.GetByte(1);
player.appearanceIDs[Character.COLORINFO] = (uint)(reader.GetUInt16(3) | (reader.GetUInt16(5) << 10) | (reader.GetUInt16(7) << 20));
player.appearanceIDs[Character.FACEINFO] = PrimitiveConversion.ToUInt32(CharacterUtils.getFaceInfo(reader.GetByte(8), reader.GetByte(9), reader.GetByte(10), reader.GetByte(11), reader.GetByte(12), reader.GetByte(13), reader.GetByte(14), reader.GetByte(15), reader.GetByte(16), reader.GetByte(17)));
player.appearanceIDs[Character.HIGHLIGHT_HAIR] = (uint)(reader.GetUInt16(6) | reader.GetUInt16(4) << 10);
player.appearanceIDs[Character.VOICE] = reader.GetByte(2);
player.appearanceIDs[Character.WEAPON1] = reader.GetUInt32(18);
player.appearanceIDs[Character.WEAPON2] = reader.GetUInt32(19);
player.appearanceIDs[Character.HEADGEAR] = reader.GetUInt32(20);
player.appearanceIDs[Character.BODYGEAR] = reader.GetUInt32(21);
player.appearanceIDs[Character.LEGSGEAR] = reader.GetUInt32(22);
player.appearanceIDs[Character.HANDSGEAR] = reader.GetUInt32(23);
player.appearanceIDs[Character.FEETGEAR] = reader.GetUInt32(24);
player.appearanceIDs[Character.WAISTGEAR] = reader.GetUInt32(25);
player.appearanceIDs[Character.R_EAR] = reader.GetUInt32(26);
player.appearanceIDs[Character.L_EAR] = reader.GetUInt32(27);
player.appearanceIDs[Character.R_FINGER] = reader.GetUInt32(28);
player.appearanceIDs[Character.L_FINGER] = reader.GetUInt32(29);
}
}
//Load Status Effects
@ -340,24 +327,15 @@ namespace FFXIVClassic_Lobby_Server
cmd.Parameters.AddWithValue("@charId", player.actorId);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
player.hasChocobo = reader.GetBoolean(0);
player.hasGoobbue = reader.GetBoolean(1);
player.chocoboAppearance = reader.GetByte(2);
player.chocoboName = reader.GetString(3);
if (reader.Read())
{
player.hasChocobo = reader.GetBoolean(0);
player.hasGoobbue = reader.GetBoolean(1);
player.chocoboAppearance = reader.GetByte(2);
player.chocoboName = reader.GetString(3);
}
}
//Load Achievements
query = @"
SELECT
achievementId
FROM characters_achievements WHERE characterId = @charId AND timeDone NOT NULL";
//Load Last 5 Completed
query = @"
SELECT
achievementId
FROM characters_achievements WHERE characterId = @charId ORDER BY timeDone DESC LIMIT 5";
//Load Timers
query = @"
SELECT
@ -380,28 +358,31 @@ namespace FFXIVClassic_Lobby_Server
behests,
companybehests,
returntimer,
skirmish,
skirmish
FROM characters_timers WHERE characterId = @charId";
cmd = new MySqlCommand(query, conn);
cmd.Parameters.AddWithValue("@charId", player.actorId);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
for (int i = 0; i < player.timers.Length; i++)
player.timers[i] = reader.GetUInt32(i);
if (reader.Read())
{
for (int i = 0; i < player.timers.Length; i++)
player.timers[i] = reader.GetUInt32(i);
}
}
//Load Hotbar
query = @"
SELECT
hotbarIndex,
hotbarSlot,
commandId,
recastTime
FROM characters_hotbar WHERE characterId = @charId AND classId = @classId";
cmd = new MySqlCommand(query, conn);
cmd.Parameters.AddWithValue("@charId", player.actorId);
//cmd.Parameters.AddWithValue("@classId", player.currentClassId);
cmd.Parameters.AddWithValue("@charId", player);
cmd.Parameters.AddWithValue("@classId", player.charaWork.parameterSave.state_mainSkill[0]);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
@ -415,10 +396,12 @@ namespace FFXIVClassic_Lobby_Server
//Load Scenario Quests
query = @"
SELECT
index,
questId
slot,
questId
FROM characters_quest_scenario WHERE characterId = @charId";
cmd = new MySqlCommand(query, conn);
cmd.Parameters.AddWithValue("@charId", player);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
@ -431,12 +414,14 @@ namespace FFXIVClassic_Lobby_Server
//Load Guildleve Quests
query = @"
SELECT
index,
slot,
questId,
abandoned,
completed
FROM characters_quest_scenario WHERE characterId = @charId";
cmd = new MySqlCommand(query, conn);
cmd.Parameters.AddWithValue("@charId", player);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
@ -454,8 +439,10 @@ namespace FFXIVClassic_Lobby_Server
npcLinkshellId,
isCalling,
isExtra
FROM characters_quest_scenario WHERE characterId = @charId";
FROM characters_npclinkshell WHERE characterId = @charId";
cmd = new MySqlCommand(query, conn);
cmd.Parameters.AddWithValue("@charId", player);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
@ -476,5 +463,76 @@ namespace FFXIVClassic_Lobby_Server
}
}
public static SubPacket getLatestAchievements(Player player)
{
uint[] latestAchievements = new uint[5];
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)))
{
try
{
conn.Open();
//Load Last 5 Completed
string query = @"
SELECT
achievementId
FROM characters_achievements WHERE characterId = @charId ORDER BY timeDone DESC LIMIT 5";
MySqlCommand cmd = new MySqlCommand(query, conn);
cmd.Parameters.AddWithValue("@charId", player.actorId);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
int count = 0;
while (reader.Read())
latestAchievements[count] = reader.GetUInt32(0);
}
}
catch (MySqlException e)
{ Console.WriteLine(e); }
finally
{
conn.Dispose();
}
}
return SetLatestAchievementsPacket.buildPacket(player.actorId, latestAchievements);
}
public static SubPacket getAchievements(Player player)
{
uint[] latestAchievements = new uint[5];
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)))
{
try
{
conn.Open();
//Load Last 5 Completed
string query = @"
SELECT
achievementId
FROM characters_achievements WHERE characterId = @charId AND timeDone NOT NULL";
MySqlCommand cmd = new MySqlCommand(query, conn);
cmd.Parameters.AddWithValue("@charId", player.actorId);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
int count = 0;
while (reader.Read())
latestAchievements[count] = reader.GetUInt32(0);
}
}
catch (MySqlException e)
{ Console.WriteLine(e); }
finally
{
conn.Dispose();
}
}
return SetLatestAchievementsPacket.buildPacket(player.actorId, latestAchievements);
}
}
}