mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-06-10 06:24:38 +02:00
Initial Commit.
This commit is contained in:
commit
46c4c26d01
82 changed files with 70188 additions and 0 deletions
90
FFXIVClassic Map Server/Database.cs
Normal file
90
FFXIVClassic Map Server/Database.cs
Normal file
|
@ -0,0 +1,90 @@
|
|||
using FFXIVClassic_Lobby_Server.dataobjects;
|
||||
using MySql.Data.MySqlClient;
|
||||
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;
|
||||
|
||||
namespace FFXIVClassic_Lobby_Server
|
||||
{
|
||||
|
||||
class Database
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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)))
|
||||
{
|
||||
World world = null;
|
||||
try
|
||||
{
|
||||
conn.Open();
|
||||
world = conn.Query<World>("SELECT * FROM servers WHERE id=@ServerId", new {ServerId = serverId}).SingleOrDefault();
|
||||
}
|
||||
catch (MySqlException e)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
conn.Dispose();
|
||||
}
|
||||
|
||||
return world;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue