Cleanup SQL Connections and fix tickets
This commit is contained in:
26
Account.cs
26
Account.cs
@ -2,10 +2,11 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
namespace NightmareCoreWeb2 {
|
||||
|
||||
public class Account
|
||||
namespace NightmareCoreWeb2
|
||||
{
|
||||
|
||||
public class Account
|
||||
{
|
||||
public UInt32 Id { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Email { get; set; }
|
||||
@ -15,8 +16,10 @@ public class Account
|
||||
public List<AccountAccess> Access { get; set; }
|
||||
|
||||
|
||||
public Account AccountByID(int id, MySqlConnection conn)
|
||||
public static Account AccountByID(int id)
|
||||
{
|
||||
|
||||
MySqlConnection conn = new MySqlConnection(Program.connStr);
|
||||
conn.Open();
|
||||
string sql = "select username from account where id=@id";
|
||||
MySqlCommand cmd = new MySqlCommand(sql, conn);
|
||||
@ -26,8 +29,7 @@ public class Account
|
||||
{
|
||||
try
|
||||
{
|
||||
this.Username = rdr.GetString(0);
|
||||
return new Account(this.Username, conn);
|
||||
return new Account(rdr.GetString(0));
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
@ -38,8 +40,10 @@ public class Account
|
||||
return null;
|
||||
}
|
||||
|
||||
public Account(string username, MySqlConnection conn)
|
||||
public Account(string username)
|
||||
{
|
||||
|
||||
MySqlConnection conn = new MySqlConnection(Program.connStr);
|
||||
conn.Open();
|
||||
|
||||
string sql = "select id,username,email,last_ip,last_login from account where username=@username";
|
||||
@ -112,10 +116,10 @@ public class Account
|
||||
conn.Close();
|
||||
}
|
||||
|
||||
}
|
||||
public class AccountAccess
|
||||
{
|
||||
}
|
||||
public class AccountAccess
|
||||
{
|
||||
public int SecurityLevel { get; set; }
|
||||
public int RealmID { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
|
||||
25
GMTicket.cs
25
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<GMTicket> GetAllTickets(MySqlConnection conn)
|
||||
public static List<GMTicket> GetAllTickets()
|
||||
{
|
||||
List<GMTicket> ret = new List<GMTicket>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -44,12 +44,12 @@
|
||||
{
|
||||
@foreach (var ticket in Model.Tickets)
|
||||
{
|
||||
if (ticket.ClosedBy == null)
|
||||
@if (ticket.ClosedBy == null)
|
||||
{
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h6>@ticket.CharacterName</h6>
|
||||
<a href="/?handler=Account&name=@ticket.OpenedBy.Username">@ticket.CharacterName</a>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text">@ticket.Description</p>
|
||||
|
||||
@ -11,7 +11,6 @@ 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 UserPassword { get; set; }
|
||||
public string CharacterListType { get; set; }
|
||||
@ -29,22 +28,22 @@ namespace NightmareCoreWeb2.Pages
|
||||
public AccountModel(ILogger<AccountModel> 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;
|
||||
|
||||
@ -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<Character> OnlineCharacters = new List<Character>();
|
||||
public Dictionary<string, string> Realms = new Dictionary<string, string>();
|
||||
|
||||
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<IndexModel> _logger;
|
||||
@ -25,7 +24,7 @@ namespace NightmareCoreWeb2.Pages
|
||||
{
|
||||
_logger = logger;
|
||||
|
||||
conn = new MySqlConnection(connStr);
|
||||
conn = new MySqlConnection(Program.connStr);
|
||||
try
|
||||
{
|
||||
conn.Open();
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
Reference in New Issue
Block a user