using MySql.Data.MySqlClient; using System; using System.Collections.Generic; using FFXIVClassic_World_Server.DataObjects; using FFXIVClassic_World_Server.DataObjects.Group; namespace FFXIVClassic_World_Server { class Database { public static bool LoadZoneSessionInfo(Session session) { string characterName; uint currentZone = 0; uint destinationZone = 0; bool readIn = false; 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(); MySqlCommand cmd = new MySqlCommand("SELECT name, currentZoneId, destinationZoneId FROM characters WHERE id = @charaId", conn); cmd.Parameters.AddWithValue("@charaId", session.sessionId); using (MySqlDataReader Reader = cmd.ExecuteReader()) { while (Reader.Read()) { characterName = Reader.GetString("name"); currentZone = Reader.GetUInt32("currentZoneId"); destinationZone = Reader.GetUInt32("destinationZoneId"); session.characterName = characterName; session.currentZoneId = currentZone; readIn = true; } } } catch (MySqlException e) { Program.Log.Error(e.ToString()); } finally { conn.Dispose(); } } return readIn; } public static uint GetCurrentZoneForSession(uint charId) { uint currentZone = 0; uint destinationZone = 0; 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(); MySqlCommand cmd = new MySqlCommand("SELECT currentZoneId, destinationZoneId FROM characters WHERE id = @charaId", conn); cmd.Parameters.AddWithValue("@charaId", charId); using (MySqlDataReader Reader = cmd.ExecuteReader()) { while (Reader.Read()) { currentZone = Reader.GetUInt32("currentZoneId"); destinationZone = Reader.GetUInt32("destinationZoneId"); } } } catch (MySqlException e) { Program.Log.Error(e.ToString()); } finally { conn.Dispose(); } } if (currentZone == 0 && destinationZone != 0) return destinationZone; if (currentZone != 0 && destinationZone == 0) return currentZone; else { return 0; } } public static Dictionary GetRetainers(uint charaId) { throw new NotImplementedException(); } public static Linkshell GetLinkshell(ulong groupIndex, ulong id) { 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(); MySqlCommand cmd = new MySqlCommand("SELECT name, crestIcon, master FROM server_linkshells WHERE id = @lsId", conn); cmd.Parameters.AddWithValue("@lsId", id); using (MySqlDataReader Reader = cmd.ExecuteReader()) { while (Reader.Read()) { string name = Reader.GetString("name"); ushort crest = Reader.GetUInt16("crestIcon"); uint master = Reader.GetUInt32("master"); Linkshell linkshell = new Linkshell(id, groupIndex, name, crest, master, 0xa); return linkshell; } } } catch (MySqlException e) { Program.Log.Error(e.ToString()); } finally { conn.Dispose(); } } return null; } public static Dictionary GetLSMembers(ulong lsId) { Dictionary memberList = new Dictionary(); 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(); MySqlCommand cmd = new MySqlCommand("SELECT characterId, linkshellId, slot, rank FROM characters_linkshells WHERE linkshellId = @lsId", conn); cmd.Parameters.AddWithValue("@lsId", lsId); using (MySqlDataReader Reader = cmd.ExecuteReader()) { while (Reader.Read()) { uint characterId = Reader.GetUInt32("characterId"); ulong linkshellId = Reader.GetUInt64("linkshellId"); ushort slot = Reader.GetUInt16("slot"); ushort rank = Reader.GetUInt16("rank"); LinkshellMember member = new LinkshellMember(characterId, linkshellId, slot, rank); memberList.Add(characterId, member); } } } catch (MySqlException e) { Program.Log.Error(e.ToString()); } finally { conn.Dispose(); } } return memberList; } public static List GetPlayerLSMembership(uint charaId) { List memberList = 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))) { try { conn.Open(); MySqlCommand cmd = new MySqlCommand("SELECT characterId, linkshellId, slot, rank FROM characters_linkshells WHERE characterid = @charaId", conn); cmd.Parameters.AddWithValue("@lsId", charaId); using (MySqlDataReader Reader = cmd.ExecuteReader()) { while (Reader.Read()) { uint characterId = Reader.GetUInt32("characterId"); ulong linkshellId = Reader.GetUInt64("linkshellId"); ushort slot = Reader.GetUInt16("slot"); ushort rank = Reader.GetUInt16("rank"); LinkshellMember member = new LinkshellMember(characterId, linkshellId, slot, rank); memberList.Add(member); } } } catch (MySqlException e) { Program.Log.Error(e.ToString()); } finally { conn.Dispose(); } } return memberList; } public static ulong CreateLinkshell(string name, ushort crest, uint master) { throw new NotImplementedException(); } public static bool DeleteLinkshell(ulong lsId) { throw new NotImplementedException(); } public static bool LinkshellAddPlayer(ulong dbId, uint charaId) { throw new NotImplementedException(); } public static bool LinkshellRemovePlayer(ulong lsId, uint charaId) { throw new NotImplementedException(); } } }