2015-08-26 13:38:58 -04:00
|
|
|
|
using FFXIVClassic_Lobby_Server.dataobjects;
|
|
|
|
|
using MySql.Data.MySqlClient;
|
2015-09-09 00:08:46 -04:00
|
|
|
|
using Dapper;
|
2015-08-26 13:38:58 -04:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2015-09-13 18:21:28 -04:00
|
|
|
|
using FFXIVClassic_Lobby_Server.common;
|
2015-08-26 13:38:58 -04:00
|
|
|
|
|
|
|
|
|
namespace FFXIVClassic_Lobby_Server
|
|
|
|
|
{
|
2015-09-13 18:21:28 -04:00
|
|
|
|
//charState: 0 - Reserved, 1 - Inactive, 2 - Active
|
2015-08-26 13:38:58 -04:00
|
|
|
|
|
|
|
|
|
class Database
|
|
|
|
|
{
|
2015-08-27 10:19:00 -04:00
|
|
|
|
public static uint getUserIdFromSession(String sessionId)
|
2015-08-26 13:38:58 -04:00
|
|
|
|
{
|
2015-08-27 10:19:00 -04:00
|
|
|
|
uint id = 0;
|
2015-08-26 13:38:58 -04: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)))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
conn.Open();
|
2015-09-09 00:08:46 -04:00
|
|
|
|
MySqlCommand cmd = new MySqlCommand("SELECT * FROM sessions WHERE id = @sessionId AND expiration > NOW()", conn);
|
2015-08-27 10:19:00 -04:00
|
|
|
|
cmd.Parameters.AddWithValue("@sessionId", sessionId);
|
|
|
|
|
using (MySqlDataReader Reader = cmd.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
while (Reader.Read())
|
|
|
|
|
{
|
|
|
|
|
id = Reader.GetUInt32("userId");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
|
|
|
|
{ Console.WriteLine(e); }
|
|
|
|
|
finally
|
|
|
|
|
{
|
2015-09-09 00:08:46 -04:00
|
|
|
|
conn.Dispose();
|
2015-09-13 18:21:28 -04:00
|
|
|
|
}
|
2015-08-27 10:19:00 -04:00
|
|
|
|
}
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-08 00:42:02 -04:00
|
|
|
|
public static bool reserveCharacter(uint userId, uint slot, uint serverId, String name, out uint pid, out uint cid)
|
2015-08-27 10:19:00 -04:00
|
|
|
|
{
|
|
|
|
|
bool alreadyExists = 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();
|
|
|
|
|
|
|
|
|
|
//Check if exists
|
2015-09-09 00:08:46 -04:00
|
|
|
|
MySqlCommand cmd = new MySqlCommand("SELECT * FROM characters WHERE name=@name AND serverId=@serverId", conn);
|
2015-08-26 13:38:58 -04:00
|
|
|
|
cmd.Parameters.AddWithValue("@serverId", serverId);
|
|
|
|
|
cmd.Parameters.AddWithValue("@name", name);
|
2015-08-27 10:19:00 -04:00
|
|
|
|
using (MySqlDataReader Reader = cmd.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
if (Reader.HasRows)
|
2015-09-08 00:42:02 -04:00
|
|
|
|
{
|
|
|
|
|
alreadyExists = true;
|
|
|
|
|
}
|
2015-08-27 10:19:00 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Reserve
|
|
|
|
|
if (!alreadyExists)
|
|
|
|
|
{
|
|
|
|
|
MySqlCommand cmd2 = new MySqlCommand();
|
|
|
|
|
cmd2.Connection = conn;
|
2015-09-09 00:08:46 -04:00
|
|
|
|
cmd2.CommandText = "INSERT INTO characters(userId, slot, serverId, name, state) VALUES(@userId, @slot, @serverId, @name, 0)";
|
2015-08-27 10:19:00 -04:00
|
|
|
|
cmd2.Prepare();
|
|
|
|
|
cmd2.Parameters.AddWithValue("@userId", userId);
|
|
|
|
|
cmd2.Parameters.AddWithValue("@slot", slot);
|
|
|
|
|
cmd2.Parameters.AddWithValue("@serverId", serverId);
|
|
|
|
|
cmd2.Parameters.AddWithValue("@name", name);
|
|
|
|
|
cmd2.ExecuteNonQuery();
|
2015-09-09 00:08:46 -04:00
|
|
|
|
cid = (ushort)cmd2.LastInsertedId;
|
|
|
|
|
pid = 0xBABE;
|
2015-09-08 00:42:02 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pid = 0;
|
|
|
|
|
cid = 0;
|
|
|
|
|
}
|
2015-08-26 13:38:58 -04:00
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
|
|
|
|
{
|
2015-09-08 00:42:02 -04:00
|
|
|
|
pid = 0;
|
|
|
|
|
cid = 0;
|
2015-08-26 13:38:58 -04:00
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
2015-09-09 00:08:46 -04:00
|
|
|
|
conn.Dispose();
|
2015-08-26 13:38:58 -04:00
|
|
|
|
}
|
2015-09-13 18:21:28 -04:00
|
|
|
|
|
|
|
|
|
Log.database(String.Format("CID={0} created on 'characters' table.", cid));
|
2015-08-26 13:38:58 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-27 10:19:00 -04:00
|
|
|
|
return alreadyExists;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-09 00:08:46 -04:00
|
|
|
|
public static void makeCharacter(uint accountId, uint cid, CharaInfo charaInfo)
|
2015-08-26 13:38:58 -04:00
|
|
|
|
{
|
2015-10-05 19:37:03 -04:00
|
|
|
|
//Update character entry
|
2015-08-26 13:38:58 -04: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)))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
conn.Open();
|
|
|
|
|
MySqlCommand cmd = new MySqlCommand();
|
|
|
|
|
cmd.Connection = conn;
|
2015-09-13 18:21:28 -04:00
|
|
|
|
cmd.CommandText = "UPDATE characters SET state=2, charaInfo=@encodedInfo WHERE userId=@userId AND id=@cid";
|
2015-08-26 13:38:58 -04:00
|
|
|
|
cmd.Prepare();
|
|
|
|
|
|
2015-09-09 00:08:46 -04:00
|
|
|
|
cmd.Parameters.AddWithValue("@userId", accountId);
|
|
|
|
|
cmd.Parameters.AddWithValue("@cid", cid);
|
|
|
|
|
string json = JsonConvert.SerializeObject(charaInfo);
|
|
|
|
|
cmd.Parameters.AddWithValue("@encodedInfo", json);
|
2015-08-26 13:38:58 -04:00
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
2015-09-09 00:08:46 -04:00
|
|
|
|
conn.Dispose();
|
2015-08-26 13:38:58 -04:00
|
|
|
|
}
|
2015-09-13 18:21:28 -04:00
|
|
|
|
|
|
|
|
|
Log.database(String.Format("CID={0} state updated to active(2).", cid));
|
2015-08-26 13:38:58 -04:00
|
|
|
|
}
|
2015-10-05 19:37:03 -04:00
|
|
|
|
|
|
|
|
|
//Create appearance entry
|
|
|
|
|
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();
|
|
|
|
|
cmd.Connection = conn;
|
|
|
|
|
cmd.CommandText = "INSERT INTO appearance(characterId, baseId, tribe, size, voice, skinColor, hairStyle, hairColor, hairHighlightColor, eyeColor, faceType, faceEyebrows, faceEyeShape, faceIrisSize, faceNose, faceMouth, faceFeatures, ears, characteristics, characteristicsColor, mainhand, offhand, head, body, hands, legs, feet, waist, leftFinger, rightFinger, leftEar, rightEar) VALUES(@characterId, @baseId, @tribe, @size, @voice, @skinColor, @hairStyle, @hairColor, @hairHighlightColor, @eyeColor, @faceType, @faceEyebrows, @faceEyeShape, @faceIrisSize, @faceNose, @faceMouth, @faceFeatures, @ears, @characteristics, @characteristicsColor, @mainhand, @offhand, @head, @body, @hands, @legs, @feet, @waist, @leftFinger, @rightFinger, @leftEar, @rightEar)";
|
|
|
|
|
cmd.Prepare();
|
|
|
|
|
|
|
|
|
|
cmd.Parameters.AddWithValue("@characterId", cid);
|
|
|
|
|
cmd.Parameters.AddWithValue("@baseId", 0xFFFFFFFF);
|
|
|
|
|
cmd.Parameters.AddWithValue("@size", charaInfo.appearance.size);
|
|
|
|
|
cmd.Parameters.AddWithValue("@voice", charaInfo.appearance.voice);
|
|
|
|
|
cmd.Parameters.AddWithValue("@skinColor", charaInfo.appearance.skinColor);
|
|
|
|
|
cmd.Parameters.AddWithValue("@hairStyle", charaInfo.appearance.hairStyle);
|
|
|
|
|
cmd.Parameters.AddWithValue("@hairColor", charaInfo.appearance.hairColor);
|
|
|
|
|
cmd.Parameters.AddWithValue("@hairHighlightColor", charaInfo.appearance.hairHighlightColor);
|
|
|
|
|
cmd.Parameters.AddWithValue("@eyeColor", charaInfo.appearance.eyeColor);
|
|
|
|
|
cmd.Parameters.AddWithValue("@faceType", charaInfo.appearance.faceType);
|
|
|
|
|
cmd.Parameters.AddWithValue("@faceEyebrows", charaInfo.appearance.faceEyebrows);
|
|
|
|
|
cmd.Parameters.AddWithValue("@faceEyeShape", charaInfo.appearance.faceEyeShape);
|
|
|
|
|
cmd.Parameters.AddWithValue("@faceIrisSize", charaInfo.appearance.faceIrisSize);
|
|
|
|
|
cmd.Parameters.AddWithValue("@faceNose", charaInfo.appearance.faceNose);
|
|
|
|
|
cmd.Parameters.AddWithValue("@faceMouth", charaInfo.appearance.faceMouth);
|
|
|
|
|
cmd.Parameters.AddWithValue("@faceFeatures", charaInfo.appearance.faceFeatures);
|
|
|
|
|
cmd.Parameters.AddWithValue("@characteristics", charaInfo.appearance.characteristics);
|
|
|
|
|
cmd.Parameters.AddWithValue("@characteristicsColor", charaInfo.appearance.characteristicsColor);
|
|
|
|
|
|
|
|
|
|
cmd.Parameters.AddWithValue("@mainhand", charaInfo.appearance.mainHand);
|
|
|
|
|
cmd.Parameters.AddWithValue("@offhand", charaInfo.appearance.offHand);
|
|
|
|
|
cmd.Parameters.AddWithValue("@head", charaInfo.appearance.head);
|
|
|
|
|
cmd.Parameters.AddWithValue("@body", charaInfo.appearance.body);
|
|
|
|
|
cmd.Parameters.AddWithValue("@hands", charaInfo.appearance.hands);
|
|
|
|
|
cmd.Parameters.AddWithValue("@legs", charaInfo.appearance.legs);
|
|
|
|
|
cmd.Parameters.AddWithValue("@feet", charaInfo.appearance.feet);
|
|
|
|
|
cmd.Parameters.AddWithValue("@waist", charaInfo.appearance.waist);
|
|
|
|
|
cmd.Parameters.AddWithValue("@leftFinger", charaInfo.appearance.leftFinger);
|
|
|
|
|
cmd.Parameters.AddWithValue("@rightFinger", charaInfo.appearance.rightFinger);
|
|
|
|
|
cmd.Parameters.AddWithValue("@leftEar", charaInfo.appearance.leftEar);
|
|
|
|
|
cmd.Parameters.AddWithValue("@rightEar", charaInfo.appearance.rightEar);
|
|
|
|
|
|
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
conn.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.database(String.Format("CID={0} state updated to active(2).", cid));
|
|
|
|
|
}
|
2015-08-26 13:38:58 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-13 11:30:33 -04:00
|
|
|
|
public static bool renameCharacter(uint userId, uint characterId, uint serverId, String newName)
|
2015-08-26 13:38:58 -04: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)))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
conn.Open();
|
2015-09-13 11:30:33 -04:00
|
|
|
|
|
|
|
|
|
//Check if exists
|
|
|
|
|
MySqlCommand cmd = new MySqlCommand("SELECT * FROM characters WHERE name=@name AND serverId=@serverId", conn);
|
|
|
|
|
cmd.Parameters.AddWithValue("@serverId", serverId);
|
|
|
|
|
cmd.Parameters.AddWithValue("@name", newName);
|
|
|
|
|
using (MySqlDataReader Reader = cmd.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
if (Reader.HasRows)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd = new MySqlCommand();
|
2015-08-26 13:38:58 -04:00
|
|
|
|
cmd.Connection = conn;
|
2015-09-13 11:30:33 -04:00
|
|
|
|
cmd.CommandText = "UPDATE characters SET name=@name, doRename=0 WHERE id=@cid AND userId=@uid";
|
2015-08-26 13:38:58 -04:00
|
|
|
|
cmd.Prepare();
|
2015-09-13 11:30:33 -04:00
|
|
|
|
cmd.Parameters.AddWithValue("@uid", userId);
|
2015-08-26 13:38:58 -04:00
|
|
|
|
cmd.Parameters.AddWithValue("@cid", characterId);
|
|
|
|
|
cmd.Parameters.AddWithValue("@name", newName);
|
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
2015-09-09 00:08:46 -04:00
|
|
|
|
conn.Dispose();
|
2015-08-26 13:38:58 -04:00
|
|
|
|
}
|
2015-09-13 11:30:33 -04:00
|
|
|
|
|
2015-09-13 18:21:28 -04:00
|
|
|
|
Log.database(String.Format("CID={0} name updated to \"{1}\".", characterId, newName));
|
|
|
|
|
|
2015-09-13 11:30:33 -04:00
|
|
|
|
return false;
|
2015-08-26 13:38:58 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void deleteCharacter(uint characterId, String name)
|
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
cmd.Connection = conn;
|
2015-09-13 11:30:33 -04:00
|
|
|
|
cmd.CommandText = "DELETE FROM characters WHERE id=@cid AND name=@name";
|
2015-08-26 13:38:58 -04:00
|
|
|
|
cmd.Prepare();
|
|
|
|
|
cmd.Parameters.AddWithValue("@cid", characterId);
|
|
|
|
|
cmd.Parameters.AddWithValue("@name", name);
|
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
2015-09-09 00:08:46 -04:00
|
|
|
|
conn.Dispose();
|
2015-08-26 13:38:58 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-09-13 18:21:28 -04:00
|
|
|
|
|
|
|
|
|
Log.database(String.Format("CID={0} deleted.", characterId));
|
2015-08-26 13:38:58 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<World> getServers()
|
|
|
|
|
{
|
2015-09-09 00:08:46 -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-08-26 13:38:58 -04:00
|
|
|
|
{
|
2015-09-09 00:08:46 -04:00
|
|
|
|
List<World> worldList = null;
|
2015-08-26 13:38:58 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
conn.Open();
|
2015-09-09 00:08:46 -04:00
|
|
|
|
worldList = conn.Query<World>("SELECT * FROM servers WHERE isActive=true").ToList();
|
2015-08-26 13:38:58 -04:00
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
2015-09-09 00:08:46 -04:00
|
|
|
|
{ worldList = new List<World>(); }
|
2015-08-26 13:38:58 -04:00
|
|
|
|
finally
|
2015-09-09 00:08:46 -04:00
|
|
|
|
{
|
|
|
|
|
conn.Dispose();
|
2015-08-26 13:38:58 -04:00
|
|
|
|
}
|
|
|
|
|
return worldList;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static World getServer(uint serverId)
|
|
|
|
|
{
|
2015-09-09 00:08:46 -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-08-26 13:38:58 -04:00
|
|
|
|
{
|
|
|
|
|
World world = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
conn.Open();
|
2015-09-09 00:08:46 -04:00
|
|
|
|
world = conn.Query<World>("SELECT * FROM servers WHERE id=@ServerId", new {ServerId = serverId}).SingleOrDefault();
|
2015-08-26 13:38:58 -04:00
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
2015-09-08 00:42:02 -04:00
|
|
|
|
{
|
2015-08-26 13:38:58 -04:00
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
2015-09-08 00:42:02 -04:00
|
|
|
|
conn.Dispose();
|
2015-08-26 13:38:58 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return world;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-27 10:19:00 -04:00
|
|
|
|
|
2015-09-09 00:08:46 -04:00
|
|
|
|
public static List<Character> getCharacters(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<Character> charaList = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
conn.Open();
|
2015-09-13 21:30:54 -04:00
|
|
|
|
charaList = conn.Query<Character>("SELECT * FROM characters WHERE userId=@UserId AND state in (1,2) ORDER BY slot", new { UserId = userId }).ToList();
|
2015-09-09 00:08:46 -04:00
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
|
|
|
|
{ charaList = new List<Character>(); }
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
conn.Dispose();
|
|
|
|
|
}
|
|
|
|
|
return charaList;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-13 11:30:33 -04:00
|
|
|
|
|
|
|
|
|
public static Character getCharacter(uint userId, uint charId)
|
|
|
|
|
{
|
|
|
|
|
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)))
|
|
|
|
|
{
|
|
|
|
|
Character chara = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
conn.Open();
|
|
|
|
|
chara = conn.Query<Character>("SELECT * FROM characters WHERE id=@CharaId and userId=@UserId", new { UserId = userId, CharaId = charId }).SingleOrDefault();
|
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
conn.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return chara;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-05 19:37:03 -04:00
|
|
|
|
public static Appearance getAppearance(uint charaId)
|
|
|
|
|
{
|
|
|
|
|
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();
|
2016-02-16 23:35:21 -05:00
|
|
|
|
appearance = conn.Query<Appearance>("SELECT * FROM characters_appearance WHERE characterId=@CharaId", new { CharaId = charaId }).SingleOrDefault();
|
2015-10-05 19:37:03 -04:00
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
conn.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return appearance;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-10 00:52:31 -04:00
|
|
|
|
public static List<String> getReservedNames(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<String> nameList = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
conn.Open();
|
|
|
|
|
nameList = conn.Query<String>("SELECT name FROM reserved_names WHERE userId=@UserId", new { UserId = userId }).ToList();
|
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
|
|
|
|
{ nameList = new List<String>(); }
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
conn.Dispose();
|
|
|
|
|
}
|
|
|
|
|
return nameList;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<Retainer> 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<Retainer> retainerList = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
conn.Open();
|
|
|
|
|
retainerList = conn.Query<Retainer>("SELECT * FROM retainers WHERE id=@UserId ORDER BY characterId, slot", new { UserId = userId }).ToList();
|
|
|
|
|
}
|
|
|
|
|
catch (MySqlException e)
|
|
|
|
|
{ retainerList = new List<Retainer>(); }
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
conn.Dispose();
|
|
|
|
|
}
|
|
|
|
|
return retainerList;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-26 13:38:58 -04:00
|
|
|
|
}
|
|
|
|
|
}
|