mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-04-21 11:39:35 +08:00
更新自定义转换器和实体工厂方法 (#32)
This commit is contained in:
parent
d25dd8d2e3
commit
42d0ca61c5
@ -1,5 +1,6 @@
|
|||||||
using Milimoe.FunGame.Core.Entity;
|
using Milimoe.FunGame.Core.Entity;
|
||||||
using Milimoe.FunGame.Core.Interface.Base;
|
using Milimoe.FunGame.Core.Interface.Base;
|
||||||
|
using Milimoe.FunGame.Core.Library.Constant;
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Core.Api.Factory
|
namespace Milimoe.FunGame.Core.Api.Factory
|
||||||
{
|
{
|
||||||
@ -9,7 +10,12 @@ namespace Milimoe.FunGame.Core.Api.Factory
|
|||||||
|
|
||||||
public User Create()
|
public User Create()
|
||||||
{
|
{
|
||||||
return new User();
|
return General.UnknownUserInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static User Create(long Id = 0, string Username = "", string Password = "", DateTime? RegTime = null, DateTime? LastTime = null, string Email = "", string NickName = "", bool IsAdmin = false, bool IsOperator = false, bool IsEnable = true, decimal Credits = 0, decimal Materials = 0, decimal GameTime = 0, string AutoKey = "")
|
||||||
|
{
|
||||||
|
return new User(Id, Username, Password, RegTime, LastTime, Email, NickName, IsAdmin, IsOperator, IsEnable, Credits, Materials, GameTime, AutoKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
using Milimoe.FunGame.Core.Api.Factory;
|
using System;
|
||||||
|
using System.Data;
|
||||||
|
using Milimoe.FunGame.Core.Api.Factory;
|
||||||
using Milimoe.FunGame.Core.Entity;
|
using Milimoe.FunGame.Core.Entity;
|
||||||
using Milimoe.FunGame.Core.Library.Constant;
|
using Milimoe.FunGame.Core.Library.Constant;
|
||||||
|
using Milimoe.FunGame.Core.Library.SQLScript.Entity;
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Core.Api.Utility
|
namespace Milimoe.FunGame.Core.Api.Utility
|
||||||
{
|
{
|
||||||
@ -75,6 +78,37 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
|||||||
return RoomFactory.Create(Id, Roomid, CreateTime, RoomMaster, RoomType, RoomState, Password);
|
return RoomFactory.Create(Id, Roomid, CreateTime, RoomMaster, RoomType, RoomState, Password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Room> GetRooms(DataSet DsRoom, DataSet DsUser)
|
||||||
|
{
|
||||||
|
List<Room> list = new()
|
||||||
|
{
|
||||||
|
General.HallInstance
|
||||||
|
};
|
||||||
|
if (DsRoom != null && DsRoom.Tables.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (DataRow DrRoom in DsRoom.Tables[0].Rows)
|
||||||
|
{
|
||||||
|
long Id = (long)DrRoom[RoomQuery.Column_ID];
|
||||||
|
string Roomid = (string)DrRoom[RoomQuery.Column_RoomID];
|
||||||
|
DateTime CreateTime = (DateTime)DrRoom[RoomQuery.Column_CreateTime];
|
||||||
|
User RoomMaster = General.UnknownUserInstance;
|
||||||
|
if (DsUser != null && DsUser.Tables.Count > 0)
|
||||||
|
{
|
||||||
|
DataRow[] rows = DsUser.Tables[0].Select($"{UserQuery.Column_UID} = {(long)DrRoom[RoomQuery.Column_RoomMaster]}");
|
||||||
|
if (rows.Length > 0)
|
||||||
|
{
|
||||||
|
RoomMaster = GetUser(rows[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RoomType RoomType = (RoomType)Convert.ToInt32(DrRoom[RoomQuery.Column_RoomType]);
|
||||||
|
RoomState RoomState = (RoomState)Convert.ToInt32(DrRoom[RoomQuery.Column_RoomState]);
|
||||||
|
string Password = (string)DrRoom[RoomQuery.Column_Password];
|
||||||
|
list.Add(GetRoom(Id, Roomid, CreateTime, RoomMaster, RoomType, RoomState, Password));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取大厅(-1号房)
|
/// 获取大厅(-1号房)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -120,5 +154,70 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
|||||||
{
|
{
|
||||||
return UserFactory.Create();
|
return UserFactory.Create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取用户实例
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Id"></param>
|
||||||
|
/// <param name="Username"></param>
|
||||||
|
/// <param name="Password"></param>
|
||||||
|
/// <param name="RegTime"></param>
|
||||||
|
/// <param name="LastTime"></param>
|
||||||
|
/// <param name="Email"></param>
|
||||||
|
/// <param name="NickName"></param>
|
||||||
|
/// <param name="IsAdmin"></param>
|
||||||
|
/// <param name="IsOperator"></param>
|
||||||
|
/// <param name="IsEnable"></param>
|
||||||
|
/// <param name="Credits"></param>
|
||||||
|
/// <param name="Materials"></param>
|
||||||
|
/// <param name="GameTime"></param>
|
||||||
|
/// <param name="AutoKey"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static User GetUser(long Id = 0, string Username = "", string Password = "", DateTime? RegTime = null, DateTime? LastTime = null, string Email = "", string NickName = "", bool IsAdmin = false, bool IsOperator = false, bool IsEnable = true, decimal Credits = 0, decimal Materials = 0, decimal GameTime = 0, string AutoKey = "")
|
||||||
|
{
|
||||||
|
return UserFactory.Create(Id, Username, Password, RegTime, LastTime, Email, NickName, IsAdmin, IsOperator, IsEnable, Credits, Materials, GameTime, AutoKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取用户实例
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static User GetUser(DataSet ds)
|
||||||
|
{
|
||||||
|
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||||
|
{
|
||||||
|
return GetUser(ds.Tables[0].Rows[0]);
|
||||||
|
}
|
||||||
|
return UserFactory.Create();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取用户实例
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static User GetUser(DataRow dr)
|
||||||
|
{
|
||||||
|
if (dr != null)
|
||||||
|
{
|
||||||
|
long Id = (long)dr[UserQuery.Column_UID];
|
||||||
|
string Username = (string)dr[UserQuery.Column_Username];
|
||||||
|
string Password = (string)dr[UserQuery.Column_Password];
|
||||||
|
DateTime RegTime = (DateTime)dr[UserQuery.Column_RegTime];
|
||||||
|
DateTime LastTime = (DateTime)dr[UserQuery.Column_LastTime];
|
||||||
|
string Email = (string)dr[UserQuery.Column_Email];
|
||||||
|
string NickName = (string)dr[UserQuery.Column_Nickname];
|
||||||
|
bool IsAdmin = Convert.ToInt32(dr[UserQuery.Column_IsAdmin]) == 1;
|
||||||
|
bool IsOperator = Convert.ToInt32(dr[UserQuery.Column_IsOperator]) == 1;
|
||||||
|
bool IsEnable = Convert.ToInt32(dr[UserQuery.Column_IsEnable]) == 1;
|
||||||
|
decimal Credits = Convert.ToDecimal(dr[UserQuery.Column_Credits]);
|
||||||
|
decimal Materials = Convert.ToDecimal(dr[UserQuery.Column_Materials]);
|
||||||
|
decimal GameTime = Convert.ToDecimal(dr[UserQuery.Column_GameTime]);
|
||||||
|
string AutoKey = (string)dr[UserQuery.Column_AutoKey];
|
||||||
|
return UserFactory.Create(Id, Username, Password, RegTime, LastTime, Email, NickName, IsAdmin, IsOperator, IsEnable, Credits, Materials, GameTime, AutoKey);
|
||||||
|
}
|
||||||
|
return UserFactory.Create();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
public Hashtable Skills { get; set; } = new();
|
public Hashtable Skills { get; set; } = new();
|
||||||
public Hashtable Items { get; set; } = new();
|
public Hashtable Items { get; set; } = new();
|
||||||
|
|
||||||
public Character()
|
internal Character()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
public class Room : BaseEntity
|
public class Room : BaseEntity
|
||||||
{
|
{
|
||||||
public override long Id { get => base.Id ; set => base.Id = value; }
|
public override long Id { get => base.Id ; set => base.Id = value; }
|
||||||
public string Roomid { get; set; } = "";
|
public string Roomid { get; set; } = "-1";
|
||||||
public DateTime CreateTime { get; set; } = DateTime.Now;
|
public DateTime CreateTime { get; set; } = General.DefaultTime;
|
||||||
public Dictionary<string, User> Players { get; set; } = new();
|
public Dictionary<string, User> Players { get; set; } = new();
|
||||||
public User? RoomMaster { get; set; }
|
public User? RoomMaster { get; set; }
|
||||||
public RoomType RoomType { get; set; }
|
public RoomType RoomType { get; set; }
|
||||||
@ -16,12 +16,17 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
public string Password { get; set; } = "";
|
public string Password { get; set; } = "";
|
||||||
public GameStatistics? Statistics { get; set; } = null;
|
public GameStatistics? Statistics { get; set; } = null;
|
||||||
|
|
||||||
|
internal Room()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
internal Room(long Id = 0, string Roomid = "-1", DateTime? CreateTime = null, User? RoomMaster = null, RoomType RoomType = RoomType.None, RoomState RoomState = RoomState.Created, string Password = "")
|
internal Room(long Id = 0, string Roomid = "-1", DateTime? CreateTime = null, User? RoomMaster = null, RoomType RoomType = RoomType.None, RoomState RoomState = RoomState.Created, string Password = "")
|
||||||
{
|
{
|
||||||
this.Id = Id;
|
this.Id = Id;
|
||||||
this.Roomid = Roomid;
|
this.Roomid = Roomid;
|
||||||
if (CreateTime != null) this.CreateTime = (DateTime)CreateTime;
|
this.CreateTime = CreateTime ?? General.DefaultTime;
|
||||||
if (RoomMaster != null) this.RoomMaster = RoomMaster;
|
this.RoomMaster = RoomMaster;
|
||||||
this.RoomType = RoomType;
|
this.RoomType = RoomType;
|
||||||
this.RoomState = RoomState;
|
this.RoomState = RoomState;
|
||||||
this.Password = Password;
|
this.Password = Password;
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using Milimoe.FunGame.Core.Interface.Entity;
|
using Milimoe.FunGame.Core.Interface.Entity;
|
||||||
|
using Milimoe.FunGame.Core.Library.Constant;
|
||||||
using Milimoe.FunGame.Core.Library.SQLScript.Entity;
|
using Milimoe.FunGame.Core.Library.SQLScript.Entity;
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Core.Entity
|
namespace Milimoe.FunGame.Core.Entity
|
||||||
{
|
{
|
||||||
public class User : BaseEntity
|
public class User : BaseEntity
|
||||||
{
|
{
|
||||||
|
public override Guid Guid { get; set; } = Guid.NewGuid();
|
||||||
public override long Id { get; set; }
|
public override long Id { get; set; }
|
||||||
public string Username { get; set; } = "";
|
public string Username { get; set; } = "";
|
||||||
public string Password { get; set; } = "";
|
public string Password { get; set; } = "";
|
||||||
@ -15,7 +17,7 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
public string NickName { get; set; } = "";
|
public string NickName { get; set; } = "";
|
||||||
public bool IsAdmin { get; set; } = false;
|
public bool IsAdmin { get; set; } = false;
|
||||||
public bool IsOperator { get; set; } = false;
|
public bool IsOperator { get; set; } = false;
|
||||||
public bool IsEnable { get; set; } = false;
|
public bool IsEnable { get; set; } = true;
|
||||||
public decimal Credits { get; set; } = 0;
|
public decimal Credits { get; set; } = 0;
|
||||||
public decimal Materials { get; set; } = 0;
|
public decimal Materials { get; set; } = 0;
|
||||||
public decimal GameTime { get; set; } = 0;
|
public decimal GameTime { get; set; } = 0;
|
||||||
@ -28,26 +30,22 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal User(DataSet? DataSet, int Index = 0)
|
internal User(long Id = 0, string Username = "", string Password = "", DateTime? RegTime = null, DateTime? LastTime = null, string Email = "", string NickName = "", bool IsAdmin = false, bool IsOperator = false, bool IsEnable = true, decimal Credits = 0, decimal Materials = 0, decimal GameTime = 0, string AutoKey = "")
|
||||||
{
|
{
|
||||||
if (DataSet != null && DataSet.Tables[0].Rows.Count > 0)
|
this.Id = Id;
|
||||||
{
|
this.Username = Username;
|
||||||
DataRow DataRow = DataSet.Tables[0].Rows[Index];
|
this.Password = Password;
|
||||||
Id = (long)DataRow[UserQuery.Column_UID];
|
this.RegTime = RegTime ?? General.DefaultTime;
|
||||||
Username = (string)DataRow[UserQuery.Column_Username];
|
this.LastTime = LastTime ?? General.DefaultTime;
|
||||||
Password = (string)DataRow[UserQuery.Column_Password];
|
this.Email = Email;
|
||||||
RegTime = (DateTime)DataRow[UserQuery.Column_RegTime];
|
this.NickName = NickName;
|
||||||
LastTime = (DateTime)DataRow[UserQuery.Column_LastTime];
|
this.IsAdmin = IsAdmin;
|
||||||
Email = (string)DataRow[UserQuery.Column_Email];
|
this.IsOperator = IsOperator;
|
||||||
NickName = (string)DataRow[UserQuery.Column_Nickname];
|
this.IsEnable = IsEnable;
|
||||||
IsAdmin = Convert.ToInt32(DataRow[UserQuery.Column_IsAdmin]) == 1;
|
this.Credits = Credits;
|
||||||
IsOperator = Convert.ToInt32(DataRow[UserQuery.Column_IsOperator]) == 1;
|
this.Materials = Materials;
|
||||||
IsEnable = Convert.ToInt32(DataRow[UserQuery.Column_IsEnable]) == 1;
|
this.GameTime = GameTime;
|
||||||
Credits = Convert.ToDecimal(DataRow[UserQuery.Column_Credits]);
|
this.AutoKey = AutoKey;
|
||||||
Materials = Convert.ToDecimal(DataRow[UserQuery.Column_Materials]);
|
|
||||||
GameTime = Convert.ToDecimal(DataRow[UserQuery.Column_GameTime]);
|
|
||||||
AutoKey = (string)DataRow[UserQuery.Column_AutoKey];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Equals(IBaseEntity? other)
|
public override bool Equals(IBaseEntity? other)
|
||||||
|
9
Interface/Base/IEntityConverter.cs
Normal file
9
Interface/Base/IEntityConverter.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace Milimoe.FunGame.Core.Interface.Base
|
||||||
|
{
|
||||||
|
internal interface IEntityConverter<T>
|
||||||
|
{
|
||||||
|
public void ReadPropertyName(ref Utf8JsonReader reader, string propertyName, ref T? result);
|
||||||
|
}
|
||||||
|
}
|
29
Library/Common/Architecture/BaseEntityConverter.cs
Normal file
29
Library/Common/Architecture/BaseEntityConverter.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using Milimoe.FunGame.Core.Interface.Base;
|
||||||
|
|
||||||
|
namespace Milimoe.FunGame.Core.Library.Common.Architecture
|
||||||
|
{
|
||||||
|
public abstract class BaseEntityConverter<T> : JsonConverter<T>, IEntityConverter<T>
|
||||||
|
{
|
||||||
|
public override T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
T? result = default;
|
||||||
|
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
if (reader.TokenType == JsonTokenType.EndObject) break;
|
||||||
|
|
||||||
|
if (reader.TokenType == JsonTokenType.PropertyName)
|
||||||
|
{
|
||||||
|
string propertyName = reader.GetString() ?? "";
|
||||||
|
ReadPropertyName(ref reader, propertyName, ref result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void ReadPropertyName(ref Utf8JsonReader reader, string propertyName, ref T? result);
|
||||||
|
}
|
||||||
|
}
|
@ -93,7 +93,7 @@ namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
|
|||||||
{
|
{
|
||||||
values[index] = result;
|
values[index] = result;
|
||||||
}
|
}
|
||||||
else values[index] = DateTime.MinValue;
|
else values[index] = General.DefaultTime;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "System.Decimal":
|
case "System.Decimal":
|
||||||
|
@ -9,59 +9,60 @@ namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
|
|||||||
{
|
{
|
||||||
public class RoomConverter : JsonConverter<Room>
|
public class RoomConverter : JsonConverter<Room>
|
||||||
{
|
{
|
||||||
|
public override bool CanConvert(Type objectType)
|
||||||
|
{
|
||||||
|
return objectType == typeof(Room);
|
||||||
|
}
|
||||||
|
|
||||||
public override Room Read(ref Utf8JsonReader reader, Type type, JsonSerializerOptions options)
|
public override Room Read(ref Utf8JsonReader reader, Type type, JsonSerializerOptions options)
|
||||||
{
|
{
|
||||||
Room room = Factory.GetRoom();
|
Room room = Factory.GetRoom();
|
||||||
|
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
if (reader.TokenType == JsonTokenType.EndObject) break;
|
||||||
|
|
||||||
if (reader.TokenType == JsonTokenType.PropertyName)
|
if (reader.TokenType == JsonTokenType.PropertyName)
|
||||||
{
|
{
|
||||||
string property = reader.GetString() ?? "";
|
string property = reader.GetString() ?? "";
|
||||||
|
reader.Read();
|
||||||
switch (property)
|
switch (property)
|
||||||
{
|
{
|
||||||
case RoomQuery.Column_ID:
|
case RoomQuery.Column_ID:
|
||||||
reader.Read();
|
|
||||||
room.Id = reader.GetInt64();
|
room.Id = reader.GetInt64();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RoomQuery.Column_RoomID:
|
case RoomQuery.Column_RoomID:
|
||||||
reader.Read();
|
|
||||||
room.Roomid = reader.GetString() ?? "";
|
room.Roomid = reader.GetString() ?? "";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RoomQuery.Column_CreateTime:
|
case RoomQuery.Column_CreateTime:
|
||||||
reader.Read();
|
|
||||||
string dateString = reader.GetString() ?? "";
|
string dateString = reader.GetString() ?? "";
|
||||||
if (DateTime.TryParseExact(dateString, General.GeneralDateTimeFormat, null, System.Globalization.DateTimeStyles.None, out DateTime result))
|
if (DateTime.TryParseExact(dateString, General.GeneralDateTimeFormat, null, System.Globalization.DateTimeStyles.None, out DateTime result))
|
||||||
{
|
{
|
||||||
room.CreateTime = result;
|
room.CreateTime = result;
|
||||||
}
|
}
|
||||||
else room.CreateTime = DateTime.MinValue;
|
else room.CreateTime = General.DefaultTime;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RoomQuery.Column_RoomMaster:
|
case RoomQuery.Column_RoomMaster:
|
||||||
reader.Read();
|
|
||||||
string master = reader.GetString() ?? "";
|
string master = reader.GetString() ?? "";
|
||||||
room.RoomMaster = JsonSerializer.Deserialize<User>(master, options);
|
room.RoomMaster = JsonSerializer.Deserialize<User>(master, options);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RoomQuery.Column_RoomType:
|
case RoomQuery.Column_RoomType:
|
||||||
reader.Read();
|
|
||||||
room.RoomType = (RoomType)reader.GetInt64();
|
room.RoomType = (RoomType)reader.GetInt64();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RoomQuery.Column_RoomState:
|
case RoomQuery.Column_RoomState:
|
||||||
reader.Read();
|
|
||||||
room.RoomState = (RoomState)reader.GetInt64();
|
room.RoomState = (RoomState)reader.GetInt64();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RoomQuery.Column_Password:
|
case RoomQuery.Column_Password:
|
||||||
reader.Read();
|
|
||||||
room.Password = reader.GetString() ?? "";
|
room.Password = reader.GetString() ?? "";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,61 +20,64 @@ namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
|
|||||||
|
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
if (reader.TokenType == JsonTokenType.EndObject) break;
|
||||||
|
|
||||||
if (reader.TokenType == JsonTokenType.PropertyName)
|
if (reader.TokenType == JsonTokenType.PropertyName)
|
||||||
{
|
{
|
||||||
string propertyName = reader.GetString() ?? "";
|
string propertyName = reader.GetString() ?? "";
|
||||||
|
reader.Read();
|
||||||
switch (propertyName)
|
switch (propertyName)
|
||||||
{
|
{
|
||||||
case "Id":
|
case UserQuery.Column_UID:
|
||||||
user.Id = reader.GetInt64();
|
user.Id = reader.GetInt64();
|
||||||
break;
|
break;
|
||||||
case "Username":
|
case UserQuery.Column_Username:
|
||||||
user.Username = reader.GetString() ?? "";
|
user.Username = reader.GetString() ?? "";
|
||||||
break;
|
break;
|
||||||
case "Password":
|
case UserQuery.Column_Password:
|
||||||
user.Password = reader.GetString() ?? "";
|
user.Password = reader.GetString() ?? "";
|
||||||
break;
|
break;
|
||||||
case "RegTime":
|
case UserQuery.Column_RegTime:
|
||||||
string regTime = reader.GetString() ?? "";
|
string regTime = reader.GetString() ?? "";
|
||||||
if (DateTime.TryParseExact(regTime, General.GeneralDateTimeFormat, null, System.Globalization.DateTimeStyles.None, out DateTime RegTime))
|
if (DateTime.TryParseExact(regTime, General.GeneralDateTimeFormat, null, System.Globalization.DateTimeStyles.None, out DateTime RegTime))
|
||||||
{
|
{
|
||||||
user.RegTime = RegTime;
|
user.RegTime = RegTime;
|
||||||
}
|
}
|
||||||
else user.RegTime = DateTime.MinValue;
|
else user.RegTime = General.DefaultTime;
|
||||||
break;
|
break;
|
||||||
case "LastTime":
|
case UserQuery.Column_LastTime:
|
||||||
string lastTime = reader.GetString() ?? "";
|
string lastTime = reader.GetString() ?? "";
|
||||||
if (DateTime.TryParseExact(lastTime, General.GeneralDateTimeFormat, null, System.Globalization.DateTimeStyles.None, out DateTime LastTime))
|
if (DateTime.TryParseExact(lastTime, General.GeneralDateTimeFormat, null, System.Globalization.DateTimeStyles.None, out DateTime LastTime))
|
||||||
{
|
{
|
||||||
user.LastTime = LastTime;
|
user.LastTime = LastTime;
|
||||||
}
|
}
|
||||||
else user.LastTime = DateTime.MinValue;
|
else user.LastTime = General.DefaultTime;
|
||||||
break;
|
break;
|
||||||
case "Email":
|
case UserQuery.Column_Email:
|
||||||
user.Email = reader.GetString() ?? "";
|
user.Email = reader.GetString() ?? "";
|
||||||
break;
|
break;
|
||||||
case "NickName":
|
case UserQuery.Column_Nickname:
|
||||||
user.NickName = reader.GetString() ?? "";
|
user.NickName = reader.GetString() ?? "";
|
||||||
break;
|
break;
|
||||||
case "IsAdmin":
|
case UserQuery.Column_IsAdmin:
|
||||||
user.IsAdmin = reader.GetBoolean();
|
user.IsAdmin = reader.GetBoolean();
|
||||||
break;
|
break;
|
||||||
case "IsOperator":
|
case UserQuery.Column_IsOperator:
|
||||||
user.IsOperator = reader.GetBoolean();
|
user.IsOperator = reader.GetBoolean();
|
||||||
break;
|
break;
|
||||||
case "IsEnable":
|
case UserQuery.Column_IsEnable:
|
||||||
user.IsEnable = reader.GetBoolean();
|
user.IsEnable = reader.GetBoolean();
|
||||||
break;
|
break;
|
||||||
case "Credits":
|
case UserQuery.Column_Credits:
|
||||||
user.Credits = reader.GetDecimal();
|
user.Credits = reader.GetDecimal();
|
||||||
break;
|
break;
|
||||||
case "Materials":
|
case UserQuery.Column_Materials:
|
||||||
user.Materials = reader.GetDecimal();
|
user.Materials = reader.GetDecimal();
|
||||||
break;
|
break;
|
||||||
case "GameTime":
|
case UserQuery.Column_GameTime:
|
||||||
user.GameTime = reader.GetDecimal();
|
user.GameTime = reader.GetDecimal();
|
||||||
break;
|
break;
|
||||||
case "AutoKey":
|
case UserQuery.Column_AutoKey:
|
||||||
user.AutoKey = reader.GetString() ?? "";
|
user.AutoKey = reader.GetString() ?? "";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,12 @@ namespace Milimoe.FunGame.Core.Library.Constant
|
|||||||
public class General
|
public class General
|
||||||
{
|
{
|
||||||
// Static Variable
|
// Static Variable
|
||||||
public static Empty EntityInstance { get; } = new();
|
public static Empty EntityInstance => new();
|
||||||
public static User UnknownUserInstance { get; } = new();
|
public static User UnknownUserInstance => new();
|
||||||
public static Room HallInstance { get; } = Api.Utility.Factory.GetHall();
|
public static Room HallInstance => new();
|
||||||
public static Encoding DefaultEncoding => Encoding.Unicode;
|
public static Encoding DefaultEncoding => Encoding.Unicode;
|
||||||
public static string GeneralDateTimeFormat => "yyyy-MM-dd HH:mm:ss.fff";
|
public static string GeneralDateTimeFormat => "yyyy-MM-dd HH:mm:ss.fff";
|
||||||
public static DateTime DefaultTime { get; } = new(1970,1,1,8,0,0);
|
public static DateTime DefaultTime => new(1970, 1, 1, 8, 0, 0);
|
||||||
|
|
||||||
// Const
|
// Const
|
||||||
public const int MaxRetryTimes = 20;
|
public const int MaxRetryTimes = 20;
|
||||||
|
@ -14,7 +14,7 @@ namespace Milimoe.FunGame.Core.Service
|
|||||||
{
|
{
|
||||||
WriteIndented = true,
|
WriteIndented = true,
|
||||||
ReferenceHandler = ReferenceHandler.IgnoreCycles,
|
ReferenceHandler = ReferenceHandler.IgnoreCycles,
|
||||||
Converters = { new DateTimeConverter(), new DataTableConverter(), new DataSetConverter() }
|
Converters = { new DateTimeConverter(), new DataTableConverter(), new DataSetConverter(), new UserConverter(), new RoomConverter() }
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user