2016-01-10 03:05:22 -05:00
|
|
|
|
using MySql.Data.MySqlClient;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
using Dapper;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using FFXIVClassic_Lobby_Server.common;
|
2016-01-10 00:00:50 -05:00
|
|
|
|
using FFXIVClassic_Map_Server.utils;
|
2016-01-10 01:19:46 -05:00
|
|
|
|
using FFXIVClassic_Lobby_Server.packets;
|
|
|
|
|
using FFXIVClassic_Map_Server.packets.send.player;
|
2016-01-10 03:05:22 -05:00
|
|
|
|
using FFXIVClassic_Lobby_Server.dataobjects;
|
2016-01-17 01:51:02 -05:00
|
|
|
|
using FFXIVClassic_Map_Server;
|
2016-01-17 11:48:55 -05:00
|
|
|
|
using FFXIVClassic_Map_Server.common.EfficientHashTables;
|
2016-01-20 23:18:10 -05:00
|
|
|
|
using FFXIVClassic_Map_Server.Actors;
|
2016-02-11 22:14:40 -05:00
|
|
|
|
using FFXIVClassic_Map_Server.dataobjects;
|
|
|
|
|
using FFXIVClassic_Map_Server.packets.send.Actor.inventory;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
|
|
|
|
namespace FFXIVClassic_Lobby_Server
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
class Database
|
|
|
|
|
{
|
2016-01-17 01:51:02 -05:00
|
|
|
|
|
2015-09-25 18:52:25 -04:00
|
|
|
|
public static uint getUserIdFromSession(String sessionId)
|
|
|
|
|
{
|
|
|
|
|
uint id = 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 * FROM sessions WHERE id = @sessionId AND expiration > NOW()", conn);
|
|
|
|
|
cmd.Parameters.AddWithValue("@sessionId", sessionId);
|
|
|
|
|
using (MySqlDataReader Reader = cmd.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
while (Reader.Read())
|
|
|
|
|
{
|
|
|
|
|
id = Reader.GetUInt32("userId");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
|
|
|
|
{ Console.WriteLine(e); }
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
conn.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-04 02:00:05 -05:00
|
|
|
|
public static DBWorld getServer(uint serverId)
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
|
|
|
|
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)))
|
|
|
|
|
{
|
2015-12-04 02:00:05 -05:00
|
|
|
|
DBWorld world = null;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
conn.Open();
|
2015-12-04 02:00:05 -05:00
|
|
|
|
world = conn.Query<DBWorld>("SELECT * FROM servers WHERE id=@ServerId", new {ServerId = serverId}).SingleOrDefault();
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
conn.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return world;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-02 14:05:37 -05:00
|
|
|
|
public static List<Npc> getNpcList()
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
|
|
|
|
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)))
|
|
|
|
|
{
|
2016-01-02 14:05:37 -05:00
|
|
|
|
List<Npc> npcList = null;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
conn.Open();
|
2016-01-02 14:05:37 -05:00
|
|
|
|
npcList = conn.Query<Npc>("SELECT * FROM npc_list").ToList();
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
conn.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-02 14:05:37 -05:00
|
|
|
|
return npcList;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-10 01:19:46 -05:00
|
|
|
|
public static void loadPlayerCharacter(Player player)
|
|
|
|
|
{
|
2016-01-09 23:22:10 -05:00
|
|
|
|
string query;
|
|
|
|
|
MySqlCommand cmd;
|
|
|
|
|
|
|
|
|
|
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)))
|
2015-10-06 00:39:18 -04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
conn.Open();
|
2016-01-02 14:05:37 -05:00
|
|
|
|
|
2016-01-10 01:19:46 -05:00
|
|
|
|
//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";
|
2016-01-09 23:22:10 -05:00
|
|
|
|
|
|
|
|
|
cmd = new MySqlCommand(query, conn);
|
|
|
|
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
|
|
|
|
using (MySqlDataReader reader = cmd.ExecuteReader())
|
|
|
|
|
{
|
2016-01-10 01:19:46 -05:00
|
|
|
|
if (reader.Read())
|
2016-01-09 23:22:10 -05:00
|
|
|
|
{
|
2016-01-10 01:19:46 -05:00
|
|
|
|
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);
|
2016-01-17 11:48:55 -05:00
|
|
|
|
player.zoneId = reader.GetUInt32(6);
|
2016-01-10 01:19:46 -05:00
|
|
|
|
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);
|
2016-01-09 23:22:10 -05:00
|
|
|
|
player.playerWork.guardian = reader.GetByte(13);
|
|
|
|
|
player.playerWork.birthdayDay = reader.GetByte(14);
|
|
|
|
|
player.playerWork.birthdayMonth = reader.GetByte(15);
|
|
|
|
|
player.playerWork.initialTown = reader.GetByte(16);
|
2016-01-10 01:19:46 -05:00
|
|
|
|
player.playerWork.tribe = reader.GetByte(17);
|
|
|
|
|
player.playerWork.restBonusExpRate = reader.GetInt32(19);
|
|
|
|
|
player.achievementPoints = reader.GetUInt32(20);
|
2016-01-09 23:22:10 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-16 11:26:35 -05:00
|
|
|
|
player.charaWork.parameterSave.state_mainSkillLevel = 49;
|
2016-01-10 13:36:36 -05:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
//Get level of our classjob
|
|
|
|
|
//Load appearance
|
|
|
|
|
query = @"
|
|
|
|
|
SELECT
|
|
|
|
|
baseId
|
|
|
|
|
FROM characters_appearance WHERE characterId = @charId";
|
|
|
|
|
|
|
|
|
|
cmd = new MySqlCommand(query, conn);
|
|
|
|
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
|
|
|
|
using (MySqlDataReader reader = cmd.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
if (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
//Get level of our classjob
|
|
|
|
|
//Load appearance
|
|
|
|
|
query = @"
|
|
|
|
|
SELECT
|
|
|
|
|
hp,
|
|
|
|
|
hpMax,
|
|
|
|
|
mp,
|
|
|
|
|
mpMax
|
|
|
|
|
FROM characters_parametersave WHERE characterId = @charId";
|
|
|
|
|
|
|
|
|
|
cmd = new MySqlCommand(query, conn);
|
|
|
|
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
|
|
|
|
using (MySqlDataReader reader = cmd.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
if (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
player.charaWork.parameterSave.hp[0] = reader.GetInt16(0);
|
|
|
|
|
player.charaWork.parameterSave.hpMax[0] = reader.GetInt16(1);
|
|
|
|
|
player.charaWork.parameterSave.mp = reader.GetInt16(2);
|
|
|
|
|
player.charaWork.parameterSave.mpMax = reader.GetInt16(3);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-09 23:22:10 -05:00
|
|
|
|
//Load appearance
|
|
|
|
|
query = @"
|
|
|
|
|
SELECT
|
2016-01-10 01:19:46 -05:00
|
|
|
|
baseId,
|
2016-01-09 23:22:10 -05:00
|
|
|
|
size,
|
|
|
|
|
voice,
|
|
|
|
|
skinColor,
|
|
|
|
|
hairStyle,
|
|
|
|
|
hairColor,
|
|
|
|
|
hairHighlightColor,
|
|
|
|
|
eyeColor,
|
2016-01-10 00:00:50 -05:00
|
|
|
|
characteristics,
|
|
|
|
|
characteristicsColor,
|
2016-01-09 23:22:10 -05:00
|
|
|
|
faceType,
|
2016-01-10 00:00:50 -05:00
|
|
|
|
ears,
|
2016-01-09 23:22:10 -05:00
|
|
|
|
faceMouth,
|
|
|
|
|
faceFeatures,
|
2016-01-10 00:00:50 -05:00
|
|
|
|
faceNose,
|
|
|
|
|
faceEyeShape,
|
|
|
|
|
faceIrisSize,
|
|
|
|
|
faceEyebrows,
|
2016-01-09 23:22:10 -05:00
|
|
|
|
mainHand,
|
|
|
|
|
offHand,
|
|
|
|
|
head,
|
|
|
|
|
body,
|
|
|
|
|
hands,
|
|
|
|
|
legs,
|
|
|
|
|
feet,
|
|
|
|
|
waist,
|
|
|
|
|
leftFinger,
|
|
|
|
|
rightFinger,
|
|
|
|
|
leftEars,
|
|
|
|
|
rightEars
|
|
|
|
|
FROM characters_appearance WHERE characterId = @charId";
|
2016-01-10 00:01:33 -05:00
|
|
|
|
|
2016-01-09 23:22:10 -05:00
|
|
|
|
cmd = new MySqlCommand(query, conn);
|
|
|
|
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
|
|
|
|
using (MySqlDataReader reader = cmd.ExecuteReader())
|
|
|
|
|
{
|
2016-01-10 01:19:46 -05:00
|
|
|
|
if (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.GetUInt32(0) == 0xFFFFFFFF)
|
2016-01-17 11:53:52 -05:00
|
|
|
|
player.modelId = CharacterUtils.getTribeModel(player.playerWork.tribe);
|
2016-01-10 01:19:46 -05:00
|
|
|
|
else
|
2016-01-17 11:53:52 -05:00
|
|
|
|
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);
|
2016-01-10 01:19:46 -05:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-09 23:22:10 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Load Status Effects
|
|
|
|
|
query = @"
|
|
|
|
|
SELECT
|
|
|
|
|
statusId,
|
|
|
|
|
expireTime
|
2016-01-10 00:00:50 -05:00
|
|
|
|
FROM characters_statuseffect WHERE characterId = @charId";
|
2016-01-09 23:22:10 -05:00
|
|
|
|
|
|
|
|
|
cmd = new MySqlCommand(query, conn);
|
|
|
|
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
|
|
|
|
using (MySqlDataReader reader = cmd.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
int count = 0;
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
player.charaWork.status[count] = reader.GetUInt16(0);
|
|
|
|
|
player.charaWork.statusShownTime[count] = reader.GetUInt32(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Load Chocobo
|
|
|
|
|
query = @"
|
|
|
|
|
SELECT
|
|
|
|
|
hasChocobo,
|
|
|
|
|
hasGoobbue,
|
|
|
|
|
chocoboAppearance,
|
|
|
|
|
chocoboName
|
|
|
|
|
FROM characters_chocobo WHERE characterId = @charId";
|
|
|
|
|
|
|
|
|
|
cmd = new MySqlCommand(query, conn);
|
|
|
|
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
|
|
|
|
using (MySqlDataReader reader = cmd.ExecuteReader())
|
|
|
|
|
{
|
2016-01-10 01:19:46 -05:00
|
|
|
|
if (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
player.hasChocobo = reader.GetBoolean(0);
|
|
|
|
|
player.hasGoobbue = reader.GetBoolean(1);
|
|
|
|
|
player.chocoboAppearance = reader.GetByte(2);
|
|
|
|
|
player.chocoboName = reader.GetString(3);
|
|
|
|
|
}
|
2016-01-09 23:22:10 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Load Timers
|
|
|
|
|
query = @"
|
|
|
|
|
SELECT
|
|
|
|
|
thousandmaws,
|
|
|
|
|
dzemaeldarkhold,
|
|
|
|
|
bowlofembers_hard,
|
|
|
|
|
bowlofembers,
|
|
|
|
|
thornmarch,
|
|
|
|
|
aurumvale,
|
|
|
|
|
cutterscry,
|
|
|
|
|
battle_aleport,
|
|
|
|
|
battle_hyrstmill,
|
|
|
|
|
battle_goldenbazaar,
|
|
|
|
|
howlingeye_hard,
|
|
|
|
|
howlingeye,
|
|
|
|
|
castrumnovum,
|
|
|
|
|
bowlofembers_extreme,
|
|
|
|
|
rivenroad,
|
|
|
|
|
rivenroad_hard,
|
|
|
|
|
behests,
|
|
|
|
|
companybehests,
|
|
|
|
|
returntimer,
|
2016-01-10 01:19:46 -05:00
|
|
|
|
skirmish
|
2016-01-09 23:22:10 -05:00
|
|
|
|
FROM characters_timers WHERE characterId = @charId";
|
|
|
|
|
|
|
|
|
|
cmd = new MySqlCommand(query, conn);
|
|
|
|
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
|
|
|
|
using (MySqlDataReader reader = cmd.ExecuteReader())
|
|
|
|
|
{
|
2016-01-10 01:19:46 -05:00
|
|
|
|
if (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < player.timers.Length; i++)
|
|
|
|
|
player.timers[i] = reader.GetUInt32(i);
|
|
|
|
|
}
|
2016-01-09 23:22:10 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Load Hotbar
|
|
|
|
|
query = @"
|
|
|
|
|
SELECT
|
2016-01-10 01:19:46 -05:00
|
|
|
|
hotbarSlot,
|
2016-01-09 23:22:10 -05:00
|
|
|
|
commandId,
|
|
|
|
|
recastTime
|
2016-01-10 00:00:50 -05:00
|
|
|
|
FROM characters_hotbar WHERE characterId = @charId AND classId = @classId";
|
2016-01-09 23:22:10 -05:00
|
|
|
|
|
|
|
|
|
cmd = new MySqlCommand(query, conn);
|
2016-01-10 14:15:46 -05:00
|
|
|
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
2016-01-10 01:19:46 -05:00
|
|
|
|
cmd.Parameters.AddWithValue("@classId", player.charaWork.parameterSave.state_mainSkill[0]);
|
2016-01-09 23:22:10 -05:00
|
|
|
|
using (MySqlDataReader reader = cmd.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
int index = reader.GetUInt16(0);
|
|
|
|
|
player.charaWork.command[index+32] = reader.GetUInt32(1);
|
|
|
|
|
player.charaWork.parameterSave.commandSlot_recastTime[index] = reader.GetUInt32(2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Load Scenario Quests
|
|
|
|
|
query = @"
|
|
|
|
|
SELECT
|
2016-01-10 01:19:46 -05:00
|
|
|
|
slot,
|
|
|
|
|
questId
|
2016-01-10 00:00:50 -05:00
|
|
|
|
FROM characters_quest_scenario WHERE characterId = @charId";
|
2016-01-10 01:19:46 -05:00
|
|
|
|
|
|
|
|
|
cmd = new MySqlCommand(query, conn);
|
2016-01-10 14:15:46 -05:00
|
|
|
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
2016-01-09 23:22:10 -05:00
|
|
|
|
using (MySqlDataReader reader = cmd.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
int index = reader.GetUInt16(0);
|
2016-01-10 14:15:46 -05:00
|
|
|
|
player.playerWork.questScenario[index] = 0xA0F00000 | reader.GetUInt32(1);
|
2016-01-09 23:22:10 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-10 14:15:46 -05:00
|
|
|
|
//Load Local Guildleves
|
2016-01-09 23:22:10 -05:00
|
|
|
|
query = @"
|
|
|
|
|
SELECT
|
2016-01-10 01:19:46 -05:00
|
|
|
|
slot,
|
2016-01-09 23:22:10 -05:00
|
|
|
|
questId,
|
|
|
|
|
abandoned,
|
|
|
|
|
completed
|
2016-01-10 14:15:46 -05:00
|
|
|
|
FROM characters_quest_guildleve_local WHERE characterId = @charId";
|
2016-01-09 23:22:10 -05:00
|
|
|
|
|
2016-01-10 01:19:46 -05:00
|
|
|
|
cmd = new MySqlCommand(query, conn);
|
2016-01-10 14:15:46 -05:00
|
|
|
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
2016-01-09 23:22:10 -05:00
|
|
|
|
using (MySqlDataReader reader = cmd.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
int index = reader.GetUInt16(0);
|
2016-01-10 14:15:46 -05:00
|
|
|
|
player.playerWork.questGuildleve[index] = 0xA0F00000 | reader.GetUInt32(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Load Regional Guildleve Quests
|
|
|
|
|
query = @"
|
|
|
|
|
SELECT
|
|
|
|
|
slot,
|
|
|
|
|
guildleveId,
|
|
|
|
|
abandoned,
|
|
|
|
|
completed
|
|
|
|
|
FROM characters_quest_guildleve_regional WHERE characterId = @charId";
|
|
|
|
|
|
|
|
|
|
cmd = new MySqlCommand(query, conn);
|
|
|
|
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
|
|
|
|
using (MySqlDataReader reader = cmd.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
int index = reader.GetUInt16(0);
|
|
|
|
|
player.work.guildleveId[index] = reader.GetUInt16(1);
|
2016-01-09 23:22:10 -05:00
|
|
|
|
player.work.guildleveDone[index] = reader.GetBoolean(2);
|
|
|
|
|
player.work.guildleveChecked[index] = reader.GetBoolean(3);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Load NPC Linkshell
|
|
|
|
|
query = @"
|
|
|
|
|
SELECT
|
|
|
|
|
npcLinkshellId,
|
|
|
|
|
isCalling,
|
|
|
|
|
isExtra
|
2016-01-10 01:19:46 -05:00
|
|
|
|
FROM characters_npclinkshell WHERE characterId = @charId";
|
2016-01-09 23:22:10 -05:00
|
|
|
|
|
2016-01-10 01:19:46 -05:00
|
|
|
|
cmd = new MySqlCommand(query, conn);
|
2016-01-10 14:15:46 -05:00
|
|
|
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
2016-01-09 23:22:10 -05:00
|
|
|
|
using (MySqlDataReader reader = cmd.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
int npcLSId = reader.GetUInt16(0);
|
|
|
|
|
player.playerWork.npcLinkshellChatCalling[npcLSId] = reader.GetBoolean(1);
|
|
|
|
|
player.playerWork.npcLinkshellChatExtra[npcLSId] = reader.GetBoolean(2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-11 22:14:40 -05:00
|
|
|
|
player.invNormal = getInventory(player, 0, InventorySetBeginPacket.CODE_INVENTORY);
|
|
|
|
|
player.invKeyItems = getInventory(player, 0, InventorySetBeginPacket.CODE_KEYITEMS);
|
|
|
|
|
player.invCurrancy = getInventory(player, 0, InventorySetBeginPacket.CODE_CURRANCY);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
|
|
|
|
{ Console.WriteLine(e); }
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
conn.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<Item> getInventory(Player player, uint slotOffset, uint type)
|
|
|
|
|
{
|
|
|
|
|
List<Item> items = new List<Item>();
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
serverItemId,
|
|
|
|
|
itemId,
|
|
|
|
|
quantity,
|
|
|
|
|
slot,
|
|
|
|
|
isUntradeable,
|
|
|
|
|
quality,
|
|
|
|
|
durability,
|
|
|
|
|
spiritBind,
|
|
|
|
|
materia1,
|
|
|
|
|
materia2,
|
|
|
|
|
materia3,
|
|
|
|
|
materia4,
|
|
|
|
|
materia5
|
|
|
|
|
FROM characters_inventory
|
|
|
|
|
INNER JOIN server_items ON serverItemId = server_items.id
|
|
|
|
|
WHERE characterId = @charId AND inventoryType = @type AND slot >= @slot ORDER BY slot";
|
|
|
|
|
|
|
|
|
|
MySqlCommand cmd = new MySqlCommand(query, conn);
|
|
|
|
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
|
|
|
|
cmd.Parameters.AddWithValue("@slot", slotOffset);
|
|
|
|
|
cmd.Parameters.AddWithValue("@type", type);
|
|
|
|
|
|
|
|
|
|
using (MySqlDataReader reader = cmd.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
uint uniqueId = reader.GetUInt32(0);
|
|
|
|
|
uint itemId = reader.GetUInt32(1);
|
|
|
|
|
int quantity = reader.GetInt32(2);
|
|
|
|
|
uint slot = reader.GetUInt32(3);
|
|
|
|
|
|
|
|
|
|
bool isUntradeable = reader.GetBoolean(4);
|
|
|
|
|
byte qualityNumber = reader.GetByte(5);
|
|
|
|
|
|
|
|
|
|
uint durability = reader.GetUInt32(6);
|
|
|
|
|
ushort spiritBind = reader.GetUInt16(7);
|
|
|
|
|
|
|
|
|
|
byte materia1 = reader.GetByte(8);
|
|
|
|
|
byte materia2 = reader.GetByte(9);
|
|
|
|
|
byte materia3 = reader.GetByte(10);
|
|
|
|
|
byte materia4 = reader.GetByte(11);
|
|
|
|
|
byte materia5 = reader.GetByte(12);
|
|
|
|
|
|
|
|
|
|
items.Add(new Item(uniqueId, itemId, quantity, slot, isUntradeable, qualityNumber, durability, spiritBind, materia1, materia2, materia3, materia4, materia5));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
|
|
|
|
{ Console.WriteLine(e); }
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
conn.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return items;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Item addItem(Player player, uint itemId, int quantity, byte quality, bool isUntradeable, uint durability, ushort type)
|
|
|
|
|
{
|
|
|
|
|
Item insertedItem = 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)))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
conn.Open();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string query = @"
|
|
|
|
|
INSERT INTO server_items
|
|
|
|
|
(itemId, quality, isUntradeable, durability)
|
|
|
|
|
VALUES
|
|
|
|
|
(@itemId, @quality, @isUntradeable, @durability);
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
string query2 = @"
|
|
|
|
|
INSERT INTO characters_inventory
|
|
|
|
|
(characterId, slot, inventoryType, serverItemId, quantity)
|
|
|
|
|
SELECT @charId, IFNULL(MAX(SLOT)+1, 0), @inventoryType, LAST_INSERT_ID(), @quantity FROM characters_inventory WHERE characterId = @charId;
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
query += query2;
|
|
|
|
|
|
|
|
|
|
MySqlCommand cmd = new MySqlCommand(query, conn);
|
|
|
|
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
|
|
|
|
cmd.Parameters.AddWithValue("@inventoryType", type);
|
|
|
|
|
|
|
|
|
|
cmd.Parameters.AddWithValue("@itemId", itemId);
|
|
|
|
|
cmd.Parameters.AddWithValue("@quantity", quantity);
|
|
|
|
|
cmd.Parameters.AddWithValue("@quality", quality);
|
|
|
|
|
cmd.Parameters.AddWithValue("@isUntradeable", isUntradeable);
|
|
|
|
|
cmd.Parameters.AddWithValue("@durability", durability);
|
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
|
|
|
|
|
|
insertedItem = new Item((uint)cmd.LastInsertedId, itemId, quantity, (uint)player.getLastInventorySlot(type), isUntradeable, quality, durability, 0, 0, 0, 0, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
|
|
|
|
{ Console.WriteLine(e); }
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
conn.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return insertedItem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void addQuantity(Player player, uint itemId, int quantity)
|
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
string query = @"
|
|
|
|
|
UPDATE characters_inventory
|
|
|
|
|
SET quantity = quantity + @quantity
|
|
|
|
|
WHERE serverItemId = (SELECT id FROM server_items WHERE characterId = @charId AND itemId = @itemId LIMIT 1)
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
MySqlCommand cmd = new MySqlCommand(query, conn);
|
|
|
|
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
|
|
|
|
cmd.Parameters.AddWithValue("@quantity", quantity);
|
|
|
|
|
cmd.Parameters.AddWithValue("@itemId", itemId);
|
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
|
|
|
|
{ Console.WriteLine(e); }
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
conn.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void removeItem(Player player, uint uniqueItemId)
|
|
|
|
|
{
|
|
|
|
|
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 = @"
|
|
|
|
|
DELETE FROM server_items
|
|
|
|
|
WHERE id = @uniqueItemId;
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
string query2 = @"
|
|
|
|
|
DELETE FROM character_inventory
|
|
|
|
|
WHERE uniqueServerId = @uniqueItemId;
|
|
|
|
|
UPDATE character_inventory
|
|
|
|
|
SET slot = slot - 1
|
|
|
|
|
WHERE characterId = @charId AND slot > X
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
query += query2;
|
|
|
|
|
|
|
|
|
|
MySqlCommand cmd = new MySqlCommand(query, conn);
|
|
|
|
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
|
|
2015-10-06 00:39:18 -04:00
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
2016-01-09 23:22:10 -05:00
|
|
|
|
{ Console.WriteLine(e); }
|
2015-10-06 00:39:18 -04:00
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
conn.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-20 23:18:10 -05:00
|
|
|
|
|
2015-10-06 00:39:18 -04:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-16 18:38:49 -05:00
|
|
|
|
public static SubPacket getLatestAchievements(Player player)
|
2015-12-04 02:00:05 -05:00
|
|
|
|
{
|
2016-01-16 18:38:49 -05:00
|
|
|
|
uint[] latestAchievements = new uint[5];
|
2016-01-10 01:19:46 -05:00
|
|
|
|
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)))
|
2015-12-04 02:00:05 -05:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
conn.Open();
|
2016-01-10 01:19:46 -05:00
|
|
|
|
|
|
|
|
|
//Load Last 5 Completed
|
|
|
|
|
string query = @"
|
|
|
|
|
SELECT
|
2016-01-16 18:38:49 -05:00
|
|
|
|
characters_achievements.achievementId FROM characters_achievements
|
|
|
|
|
INNER JOIN gamedata_achievements ON characters_achievements.achievementId = gamedata_achievements.achievementId
|
|
|
|
|
WHERE characterId = @charId AND rewardPoints <> 0 ORDER BY timeDone LIMIT 5";
|
2016-01-10 01:19:46 -05:00
|
|
|
|
|
|
|
|
|
MySqlCommand cmd = new MySqlCommand(query, conn);
|
|
|
|
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
|
|
|
|
using (MySqlDataReader reader = cmd.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
int count = 0;
|
|
|
|
|
while (reader.Read())
|
2016-01-16 18:38:49 -05:00
|
|
|
|
{
|
|
|
|
|
uint id = reader.GetUInt32(0);
|
|
|
|
|
latestAchievements[count++] = id;
|
2016-01-16 11:26:35 -05:00
|
|
|
|
}
|
2016-01-10 01:19:46 -05:00
|
|
|
|
}
|
2015-12-04 02:00:05 -05:00
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
2016-01-10 01:19:46 -05:00
|
|
|
|
{ Console.WriteLine(e); }
|
2015-12-04 02:00:05 -05:00
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
conn.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-10 01:19:46 -05:00
|
|
|
|
|
2016-01-16 18:38:49 -05:00
|
|
|
|
return SetLatestAchievementsPacket.buildPacket(player.actorId, latestAchievements);
|
2015-12-04 02:00:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-16 18:38:49 -05:00
|
|
|
|
public static SubPacket getAchievementsPacket(Player player)
|
2016-01-02 14:05:37 -05:00
|
|
|
|
{
|
2016-01-16 18:38:49 -05:00
|
|
|
|
SetCompletedAchievementsPacket cheevosPacket = new SetCompletedAchievementsPacket();
|
|
|
|
|
|
2016-01-10 01:19:46 -05:00
|
|
|
|
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)))
|
2016-01-02 14:05:37 -05:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
conn.Open();
|
2016-01-10 01:19:46 -05:00
|
|
|
|
|
|
|
|
|
string query = @"
|
2016-01-16 18:38:49 -05:00
|
|
|
|
SELECT packetOffsetId
|
|
|
|
|
FROM characters_achievements
|
|
|
|
|
INNER JOIN gamedata_achievements ON characters_achievements.achievementId = gamedata_achievements.achievementId
|
|
|
|
|
WHERE characterId = @charId AND timeDone IS NOT NULL";
|
2016-01-10 01:19:46 -05:00
|
|
|
|
|
|
|
|
|
MySqlCommand cmd = new MySqlCommand(query, conn);
|
|
|
|
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
|
|
|
|
using (MySqlDataReader reader = cmd.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
while (reader.Read())
|
2016-01-16 18:38:49 -05:00
|
|
|
|
{
|
|
|
|
|
uint offset = reader.GetUInt32(0);
|
|
|
|
|
|
|
|
|
|
if (offset < 0 || offset >= cheevosPacket.achievementFlags.Length)
|
|
|
|
|
{
|
|
|
|
|
Log.error("SQL Error; achievement flag offset id out of range: " + offset);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
cheevosPacket.achievementFlags[offset] = true;
|
|
|
|
|
}
|
2016-01-10 01:19:46 -05:00
|
|
|
|
}
|
2016-01-02 14:05:37 -05:00
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
2016-01-10 01:19:46 -05:00
|
|
|
|
{ Console.WriteLine(e); }
|
|
|
|
|
finally
|
2016-01-02 14:05:37 -05:00
|
|
|
|
{
|
2016-01-10 01:19:46 -05:00
|
|
|
|
conn.Dispose();
|
2016-01-02 14:05:37 -05:00
|
|
|
|
}
|
2016-01-10 01:19:46 -05:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-16 18:38:49 -05:00
|
|
|
|
return cheevosPacket.buildPacket(player.actorId);
|
2016-01-10 01:19:46 -05:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
}
|