diff --git a/Account.cs b/Account.cs index b6e4af5..e56e27a 100644 --- a/Account.cs +++ b/Account.cs @@ -2,120 +2,124 @@ using System; using System.Collections.Generic; using MySql.Data.MySqlClient; -namespace NightmareCoreWeb2 { - -public class Account +namespace NightmareCoreWeb2 { - public UInt32 Id { get; set; } - public string Username { get; set; } - public string Email { get; set; } - public string LastIP { get; set; } - public DateTime LastLogin { get; set; } - public List Characters { get; set; } - public List Access { get; set; } - - public Account AccountByID(int id, MySqlConnection conn) + public class Account { - conn.Open(); - string sql = "select username from account where id=@id"; - MySqlCommand cmd = new MySqlCommand(sql, conn); - cmd.Parameters.AddWithValue("id", id); - MySqlDataReader rdr = cmd.ExecuteReader(); - while (rdr.Read()) + public UInt32 Id { get; set; } + public string Username { get; set; } + public string Email { get; set; } + public string LastIP { get; set; } + public DateTime LastLogin { get; set; } + public List Characters { get; set; } + public List Access { get; set; } + + + public static Account AccountByID(int id) { - try - { - this.Username = rdr.GetString(0); - return new Account(this.Username, conn); - } - catch (Exception e) + MySqlConnection conn = new MySqlConnection(Program.connStr); + conn.Open(); + string sql = "select username from account where id=@id"; + MySqlCommand cmd = new MySqlCommand(sql, conn); + cmd.Parameters.AddWithValue("id", id); + MySqlDataReader rdr = cmd.ExecuteReader(); + while (rdr.Read()) { - Console.WriteLine(e); + try + { + return new Account(rdr.GetString(0)); + + } + catch (Exception e) + { + Console.WriteLine(e); + } } + return null; } - return null; - } - public Account(string username, MySqlConnection conn) - { - conn.Open(); + public Account(string username) + { - string sql = "select id,username,email,last_ip,last_login from account where username=@username"; - MySqlCommand cmd = new MySqlCommand(sql, conn); - cmd.Parameters.AddWithValue("username", username); - MySqlDataReader rdr = cmd.ExecuteReader(); + MySqlConnection conn = new MySqlConnection(Program.connStr); + conn.Open(); - while (rdr.Read()) - { - try - { - this.Id = rdr.GetUInt32(0); - this.Username = rdr.GetString(1); - this.Email = rdr.GetString(2); - this.LastIP = rdr.GetString(3); - this.LastLogin = rdr.GetDateTime(4); - } - catch (Exception e) - { - Console.WriteLine(e); - } - } - rdr.Close(); - sql = "select guid,username,name,level,race,class from characters.characters join auth.account on characters.characters.account = auth.account.id where characters.characters.account=@id"; - cmd = new MySqlCommand(sql, conn); - cmd.Parameters.AddWithValue("id", this.Id); - rdr = cmd.ExecuteReader(); - this.Characters = new List(); - while (rdr.Read()) - { - try + string sql = "select id,username,email,last_ip,last_login from account where username=@username"; + MySqlCommand cmd = new MySqlCommand(sql, conn); + cmd.Parameters.AddWithValue("username", username); + MySqlDataReader rdr = cmd.ExecuteReader(); + + while (rdr.Read()) { - Character c = new Character(); - c.guid = (int)rdr.GetUInt32(0); - c.Username = rdr.GetString(1); - c.Name = rdr.GetString(2); - c.Level = rdr.GetByte(3); - c.Race = rdr.GetByte(4); - c.Class = rdr.GetByte(5); - this.Characters.Add(c); + try + { + this.Id = rdr.GetUInt32(0); + this.Username = rdr.GetString(1); + this.Email = rdr.GetString(2); + this.LastIP = rdr.GetString(3); + this.LastLogin = rdr.GetDateTime(4); + } + catch (Exception e) + { + Console.WriteLine(e); + } } - catch (Exception e) + rdr.Close(); + sql = "select guid,username,name,level,race,class from characters.characters join auth.account on characters.characters.account = auth.account.id where characters.characters.account=@id"; + cmd = new MySqlCommand(sql, conn); + cmd.Parameters.AddWithValue("id", this.Id); + rdr = cmd.ExecuteReader(); + this.Characters = new List(); + while (rdr.Read()) { - Console.WriteLine(e); + try + { + Character c = new Character(); + c.guid = (int)rdr.GetUInt32(0); + c.Username = rdr.GetString(1); + c.Name = rdr.GetString(2); + c.Level = rdr.GetByte(3); + c.Race = rdr.GetByte(4); + c.Class = rdr.GetByte(5); + this.Characters.Add(c); + } + catch (Exception e) + { + Console.WriteLine(e); + } } - } - rdr.Close(); + rdr.Close(); - sql = "select SecurityLevel,RealmID from account_access where AccountID=@id"; - cmd = new MySqlCommand(sql, conn); - cmd.Parameters.AddWithValue("id", this.Id); - rdr = cmd.ExecuteReader(); - this.Access = new List(); - while (rdr.Read()) - { - try + sql = "select SecurityLevel,RealmID from account_access where AccountID=@id"; + cmd = new MySqlCommand(sql, conn); + cmd.Parameters.AddWithValue("id", this.Id); + rdr = cmd.ExecuteReader(); + this.Access = new List(); + while (rdr.Read()) { - AccountAccess acctA = new AccountAccess(); - acctA.SecurityLevel = rdr.GetByte(0); - acctA.RealmID = rdr.GetInt32(1); - this.Access.Add(acctA); - } - catch (Exception e) - { - Console.WriteLine(e); + try + { + AccountAccess acctA = new AccountAccess(); + acctA.SecurityLevel = rdr.GetByte(0); + acctA.RealmID = rdr.GetInt32(1); + this.Access.Add(acctA); + } + catch (Exception e) + { + Console.WriteLine(e); + } } + rdr.Close(); + + conn.Close(); } - rdr.Close(); - conn.Close(); } - -} -public class AccountAccess -{ - public int SecurityLevel { get; set; } - public int RealmID { get; set; } -} + public class AccountAccess + { + public int SecurityLevel { get; set; } + public int RealmID { get; set; } + } } \ No newline at end of file diff --git a/Character.cs b/Character.cs index 9d1d5fb..216e61b 100644 --- a/Character.cs +++ b/Character.cs @@ -66,8 +66,10 @@ namespace NightmareCoreWeb2 } public Character() { } - public Character(int guid, MySqlConnection conn) + public Character(int guid) { + + MySqlConnection conn = new MySqlConnection(Program.connStr); conn.Open(); string sql = "select username,name,level,race,class,at_login from characters.characters join auth.account on characters.characters.account = auth.account.id where characters.characters.guid=@id"; @@ -95,7 +97,8 @@ namespace NightmareCoreWeb2 conn.Close(); } - public void SetAtLogin(MySqlConnection conn) { + public void SetAtLogin() { + MySqlConnection conn = new MySqlConnection(Program.connStr); conn.Open(); string sql = "update characters.characters set at_login=@loginOpts where guid=@guid"; MySqlCommand cmd = new MySqlCommand(sql, conn); diff --git a/GMTicket.cs b/GMTicket.cs index 970b1d6..98e4954 100644 --- a/GMTicket.cs +++ b/GMTicket.cs @@ -10,7 +10,7 @@ namespace NightmareCoreWeb2 public class GMTicket { public int Id { get; set; } - public Account Account { get; set; } + public Account OpenedBy { get; set; } public string CharacterName { get; set; } public DateTime CreateTime { get; set; } public DateTime LastModifiedTime { get; set; } @@ -19,19 +19,20 @@ namespace NightmareCoreWeb2 public string Description { get; set; } - public static List GetAllTickets(MySqlConnection conn) + public static List GetAllTickets() { List ret = new List(); + MySqlConnection conn = new MySqlConnection(Program.connStr); conn.Open(); - string sql = "select id from gm_ticket"; + string sql = "select id from characters.gm_ticket"; MySqlCommand cmd = new MySqlCommand(sql, conn); MySqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { try { - GMTicket ticket = new GMTicket(rdr.GetInt32(0), conn); + GMTicket ticket = new GMTicket(rdr.GetInt32(0)); ret.Add(ticket); } catch (Exception e) @@ -42,12 +43,14 @@ namespace NightmareCoreWeb2 return ret; } - public GMTicket(int id, MySqlConnection conn) + public GMTicket(int id) { this.Id = id; + + MySqlConnection conn = new MySqlConnection(Program.connStr); conn.Open(); - string sql = "select id,playerGuid,name,description,createTime,lastModifiedTime,closedBy,assignedTo from gm_ticket where id=@id"; + string sql = "select playerGuid,name,createTime,lastModifiedTime,closedBy,assignedTo,description from characters.gm_ticket where id=@id"; MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.Parameters.AddWithValue("id", id); MySqlDataReader rdr = cmd.ExecuteReader(); @@ -56,17 +59,17 @@ namespace NightmareCoreWeb2 { try { - this.Account = Account.AccountByID(rdr.GetInt32(0), conn); + this.OpenedBy = new Account(new Character(rdr.GetInt32(0)).Username); this.CharacterName = rdr.GetString(1); - this.CreateTime = rdr.GetDateTime(2); - this.LastModifiedTime = rdr.GetDateTime(3); + this.CreateTime = DateTimeOffset.FromUnixTimeSeconds(rdr.GetInt32(2)).UtcDateTime; + this.LastModifiedTime = DateTimeOffset.FromUnixTimeSeconds(rdr.GetInt32(3)).UtcDateTime; if (rdr.GetInt32(4) != 0) { - this.ClosedBy = Account.AccountByID(rdr.GetInt32(4), conn); + this.ClosedBy = Account.AccountByID(rdr.GetInt32(4)); } if (rdr.GetInt32(5) != 0) { - this.AssignedTo = Account.AccountByID(rdr.GetInt32(5), conn); + this.AssignedTo = Account.AccountByID(rdr.GetInt32(5)); } this.Description = rdr.GetString(6); } diff --git a/Pages/Account.cshtml b/Pages/Account.cshtml index 7dfbfb8..66428b7 100644 --- a/Pages/Account.cshtml +++ b/Pages/Account.cshtml @@ -44,12 +44,12 @@ { @foreach (var ticket in Model.Tickets) { - if (ticket.ClosedBy == null) + @if (ticket.ClosedBy == null) {
-
@ticket.CharacterName
+ @ticket.CharacterName

@ticket.Description

diff --git a/Pages/Account.cshtml.cs b/Pages/Account.cshtml.cs index 0f74317..cdb7b74 100644 --- a/Pages/Account.cshtml.cs +++ b/Pages/Account.cshtml.cs @@ -11,8 +11,7 @@ namespace NightmareCoreWeb2.Pages { public class AccountModel : PageModel { - string connStr = $"SslMode=None;server={Program.MysqlServer};user={Program.MysqlUser};database={Program.MysqlDatabase};port={Program.MysqlPort};password={Program.MysqlPassword}"; - public string UserEmail { get; set; } + public string UserEmail { get; set; } public string UserPassword { get; set; } public string CharacterListType { get; set; } public string AuthToken { get; set; } @@ -29,22 +28,22 @@ namespace NightmareCoreWeb2.Pages public AccountModel(ILogger logger) { - conn = new MySqlConnection(connStr); + conn = new MySqlConnection(Program.connStr); _logger = logger; } public void OnGetAccount(string name) { - Account a = new Account(name, conn); - //AuthToken = "OK"; + Account a = new Account(name); + AuthToken = "OK"; UserAccount = a; OnlineCharacters = a.Characters; foreach (var access in a.Access) { - if (access.RealmID == -1 && access.RealmID >= 1) + if (access.RealmID == -1 && access.SecurityLevel >= 1) { this.IsGM = true; - this.Tickets = GMTicket.GetAllTickets(conn); + this.Tickets = GMTicket.GetAllTickets(); } } ViewData["Title"] = a.Username; @@ -52,12 +51,12 @@ namespace NightmareCoreWeb2.Pages } public void OnGetCharacterAction(int guid, int action) { - Character c = new Character(guid, conn); + Character c = new Character(guid); if ((c.AtLogin & Character.AtLoginOptions.AT_LOGIN_FIRST) == 0) { c.AtLogin |= (Character.AtLoginOptions)action; } - c.SetAtLogin(conn); + c.SetAtLogin(); } public void OnGet() @@ -68,7 +67,7 @@ namespace NightmareCoreWeb2.Pages Username = Request.Cookies["Username"]; if (!string.IsNullOrEmpty(Username)) { - Account a = new Account(Username, conn); + Account a = new Account(Username); AuthToken = "OK"; UserAccount = a; OnlineCharacters = a.Characters; @@ -77,7 +76,7 @@ namespace NightmareCoreWeb2.Pages if (access.RealmID == -1 && access.RealmID >= 1) { this.IsGM = true; - this.Tickets = GMTicket.GetAllTickets(conn); + this.Tickets = GMTicket.GetAllTickets(); } } ViewData["Title"] = a.Username; diff --git a/Pages/Index.cshtml.cs b/Pages/Index.cshtml.cs index dc1c07f..dcf7fb0 100644 --- a/Pages/Index.cshtml.cs +++ b/Pages/Index.cshtml.cs @@ -8,15 +8,14 @@ namespace NightmareCoreWeb2.Pages { public class IndexModel : PageModel { - string connStr = $"SslMode=None;server={Program.MysqlServer};user={Program.MysqlUser};database={Program.MysqlDatabase};port={Program.MysqlPort};password={Program.MysqlPassword}"; public List OnlineCharacters = new List(); public Dictionary Realms = new Dictionary(); - public string ActivateEmail {get; set;} - public string ActivatePassword {get; set;} - public string ActivateToken {get; set;} - public string RequestTokenEmail {get; set;} - public string CharacterListType {get; set;} + public string ActivateEmail { get; set; } + public string ActivatePassword { get; set; } + public string ActivateToken { get; set; } + public string RequestTokenEmail { get; set; } + public string CharacterListType { get; set; } private MySqlConnection conn; private readonly ILogger _logger; @@ -24,8 +23,8 @@ namespace NightmareCoreWeb2.Pages public IndexModel(ILogger logger) { _logger = logger; - - conn = new MySqlConnection(connStr); + + conn = new MySqlConnection(Program.connStr); try { conn.Open(); @@ -45,10 +44,10 @@ namespace NightmareCoreWeb2.Pages OnlineCharacters.Add(c); } rdr.Close(); - sql = "SELECT name,flag FROM realmlist"; + sql = "SELECT name,flag FROM realmlist"; cmd = new MySqlCommand(sql, conn); rdr = cmd.ExecuteReader(); - + while (rdr.Read()) { Realms.Add(rdr.GetString(0), rdr.GetString(1).Equals("2") ? "❌" : "✔️"); @@ -64,32 +63,39 @@ namespace NightmareCoreWeb2.Pages } - public void OnGet() { + public void OnGet() + { ViewData["Title"] = "WotDN"; } - public void OnGetAccount(string name) { - Account a = new Account(name, conn); + public void OnGetAccount(string name) + { + Account a = new Account(name); ViewData["Title"] = name; CharacterListType = $"{name}'s Characters"; OnlineCharacters = a.Characters; } - public void OnPostActivateAccount() { + public void OnPostActivateAccount() + { ActivateEmail = Request.Form["ActivateEmail"]; ActivatePassword = Request.Form["ActivatePassword"]; ActivateToken = Request.Form["ActivateToken"]; } - public void OnPostRequestToken() { + public void OnPostRequestToken() + { RequestTokenEmail = Request.Form["RequestTokenEmail"]; } - public bool RequestToken() { + public bool RequestToken() + { return false; } - public bool CreateAccount() { + public bool CreateAccount() + { return false; } - public bool IsTokenValid(string username, string token) { + public bool IsTokenValid(string username, string token) + { return false; } } diff --git a/Program.cs b/Program.cs index 1cc08bd..46c989d 100644 --- a/Program.cs +++ b/Program.cs @@ -18,6 +18,7 @@ namespace NightmareCoreWeb2 public static string MysqlDatabase; public static string MysqlPort; public static string MysqlPassword; + public static string connStr; public static void Main(string[] args) { using (StreamReader r = new StreamReader("config.json")) @@ -29,6 +30,8 @@ namespace NightmareCoreWeb2 Program.MysqlDatabase = config.MysqlDatabase; Program.MysqlPassword = config.MysqlPassword; Program.MysqlPort = config.MysqlPort; + connStr = $"SslMode=None;server={Program.MysqlServer};user={Program.MysqlUser};database={Program.MysqlDatabase};port={Program.MysqlPort};password={Program.MysqlPassword}"; + } CreateHostBuilder(args).Build().Run();