Add Action buttons to Account/Character menu
This commit is contained in:
13
Account.cs
13
Account.cs
@ -63,7 +63,7 @@ public class Account
|
||||
}
|
||||
}
|
||||
rdr.Close();
|
||||
sql = "select username,name,level,race,class from characters.characters join auth.account on characters.characters.account = auth.account.id where characters.characters.account=@id";
|
||||
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();
|
||||
@ -73,11 +73,12 @@ public class Account
|
||||
try
|
||||
{
|
||||
Character c = new Character();
|
||||
c.Username = rdr.GetString(0);
|
||||
c.Name = rdr.GetString(1);
|
||||
c.Level = rdr.GetByte(2);
|
||||
c.Race = rdr.GetByte(3);
|
||||
c.Class = rdr.GetByte(4);
|
||||
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)
|
||||
|
||||
61
Character.cs
61
Character.cs
@ -1,11 +1,19 @@
|
||||
using System;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
namespace NightmareCoreWeb2
|
||||
{
|
||||
|
||||
public class Character
|
||||
{
|
||||
//select username,name,level,race,class from characters.characters join auth.account on characters.characters.account = auth.account.id where characters.characters.online = 1;
|
||||
public int guid { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int Level { get; set; }
|
||||
public int Race { get; set; }
|
||||
public int Class { get; set; }
|
||||
public AtLoginOptions AtLogin { get; set; }
|
||||
|
||||
public string[] classes = {
|
||||
"Null",
|
||||
@ -36,6 +44,18 @@ public class Character
|
||||
"Blood Elf",
|
||||
"Draenei"
|
||||
};
|
||||
[Flags]
|
||||
public enum AtLoginOptions
|
||||
{
|
||||
AT_LOGIN_RENAME = 1,
|
||||
AT_LOGIN_RESET_SPELLS = 2,
|
||||
AT_LOGIN_RESET_TALENTS = 4,
|
||||
AT_LOGIN_CUSTOMIZE = 8,
|
||||
AT_LOGIN_RESET_PET_TALENTS = 16,
|
||||
AT_LOGIN_FIRST = 32,
|
||||
AT_LOGIN_CHANGE_FACTION = 64,
|
||||
AT_LOGIN_CHANGE_RACE = 128
|
||||
}
|
||||
public string GetClass()
|
||||
{
|
||||
return classes[this.Class];
|
||||
@ -44,4 +64,45 @@ public class Character
|
||||
{
|
||||
return races[this.Race];
|
||||
}
|
||||
|
||||
public Character() { }
|
||||
public Character(int guid, MySqlConnection conn)
|
||||
{
|
||||
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";
|
||||
MySqlCommand cmd = new MySqlCommand(sql, conn);
|
||||
cmd.Parameters.AddWithValue("id", guid);
|
||||
MySqlDataReader rdr = cmd.ExecuteReader();
|
||||
while (rdr.Read())
|
||||
{
|
||||
try
|
||||
{
|
||||
this.guid = guid;
|
||||
this.Username = rdr.GetString(0);
|
||||
this.Name = rdr.GetString(1);
|
||||
this.Level = rdr.GetByte(2);
|
||||
this.Race = rdr.GetByte(3);
|
||||
this.Class = rdr.GetByte(4);
|
||||
this.AtLogin = (AtLoginOptions)rdr.GetUInt16(5);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
rdr.Close();
|
||||
conn.Close();
|
||||
}
|
||||
|
||||
public void SetAtLogin(MySqlConnection conn) {
|
||||
conn.Open();
|
||||
string sql = "update characters.characters set at_login=@loginOpts where guid=@guid";
|
||||
MySqlCommand cmd = new MySqlCommand(sql, conn);
|
||||
cmd.Parameters.AddWithValue("guid", this.guid);
|
||||
cmd.Parameters.AddWithValue("loginOpts", (int)this.AtLogin);
|
||||
cmd.ExecuteNonQuery();
|
||||
conn.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -73,7 +73,10 @@
|
||||
<h6>@character.Name</h6>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text">Card action buttons could go here!</p>
|
||||
<a class="btn active" href="/Account?handler=CharacterAction&guid=@character.guid&action=1">Rename Character</a>
|
||||
<a class="btn active" href="/Account?handler=CharacterAction&guid=@character.guid&action=8">Recustomize Character</a>
|
||||
<a class="btn active" href="/Account?handler=CharacterAction&guid=@character.guid&action=64">Change Faction</a>
|
||||
<a class="btn active" href="/Account?handler=CharacterAction&guid=@character.guid&action=128">Change Race</a>
|
||||
</div>
|
||||
<div class="card-footer text-muted">
|
||||
<p>Level @character.Level @character.GetRace() @character.GetClass()</p>
|
||||
|
||||
@ -50,6 +50,16 @@ namespace NightmareCoreWeb2.Pages
|
||||
ViewData["Title"] = a.Username;
|
||||
CharacterListType = $"{a.Username}'s Characters";
|
||||
}
|
||||
public void OnGetCharacterAction(int guid, int action)
|
||||
{
|
||||
Character c = new Character(guid, conn);
|
||||
if ((c.AtLogin & Character.AtLoginOptions.AT_LOGIN_FIRST) == 0)
|
||||
{
|
||||
c.AtLogin |= (Character.AtLoginOptions)action;
|
||||
}
|
||||
c.SetAtLogin(conn);
|
||||
|
||||
}
|
||||
public void OnGet()
|
||||
{
|
||||
|
||||
|
||||
@ -13,7 +13,6 @@ namespace NightmareCoreWeb2
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
// "server=localhost;user=trinity;database=auth;port=3306;password=Baevannas335a";
|
||||
public static string MysqlServer;
|
||||
public static string MysqlUser;
|
||||
public static string MysqlDatabase;
|
||||
|
||||
Reference in New Issue
Block a user