代码优化

This commit is contained in:
Mili 2022-09-05 00:15:41 +08:00
parent ee2fa26b26
commit 0c4ea422cf
7 changed files with 45 additions and 27 deletions

View File

@ -33,6 +33,6 @@ namespace FunGame.Core.Api.Interface
public interface ServerInterface public interface ServerInterface
{ {
public string ServerNotice(); public string DBConnection();
} }
} }

View File

@ -14,6 +14,7 @@ namespace FunGame.Core.Api.Model.Entity
public decimal Price { get; set; } public decimal Price { get; set; }
public char Key { get; set; } public char Key { get; set; }
public bool Active { get; set; } public bool Active { get; set; }
public bool Enable { get; set; }
public Character? Character { get; set; } = null; public Character? Character { get; set; } = null;
} }
} }

View File

@ -13,5 +13,6 @@ namespace FunGame.Core.Api.Model.Entity
public string Describe { get; set; } = ""; public string Describe { get; set; } = "";
public char Key { get; set; } public char Key { get; set; }
public bool Active { get; set; } public bool Active { get; set; }
public bool Enable { get; set; }
} }
} }

View File

@ -20,8 +20,9 @@ namespace FunGame.Core.Api.Model.Entity
public bool IsEnable { get; set; } = false; public bool IsEnable { get; set; } = false;
public int OnlineState { get; set; } = 0; public int OnlineState { get; set; } = 0;
public string Roomid { get; set; } = ""; public string Roomid { get; set; } = "";
public int Credits { get; set; } = 0; public decimal Credits { get; set; } = 0;
public int Material { get; set; } = 0; public decimal Materials { get; set; } = 0;
public decimal GameTime { get; set; } = 0;
public UserStatistics? Statistics { get; set; } = null; public UserStatistics? Statistics { get; set; } = null;
public Stock? Stock { get; set; } = null; public Stock? Stock { get; set; } = null;

View File

@ -90,7 +90,7 @@ namespace FunGame.Core.Api.Model.Enum
public enum InterfaceMethod public enum InterfaceMethod
{ {
RemoteServerIP = 1, RemoteServerIP = 1,
ServerNotice = 2 DBConnection = 2
} }
#endregion #endregion

View File

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using System.Reflection; using System.Reflection;
using System.Diagnostics; using System.Diagnostics;
using FunGame.Core.Api.Model.Enum; using FunGame.Core.Api.Model.Enum;
using System.Data.Common;
namespace FunGame.Core.Api.Util namespace FunGame.Core.Api.Util
{ {
@ -13,6 +14,7 @@ namespace FunGame.Core.Api.Util
/// 在FunGame.Core.Api中添加新接口和新实现时需要 /// 在FunGame.Core.Api中添加新接口和新实现时需要
/// 1、在这里定义类名和方法名 /// 1、在这里定义类名和方法名
/// 2、在FunGame.Core.Api.Model.Enum.CommonEnums里同步添加InterfaceType和InterfaceMethod /// 2、在FunGame.Core.Api.Model.Enum.CommonEnums里同步添加InterfaceType和InterfaceMethod
/// 3、在GetClassName(int)、GetMethodName(int)中添加switch分支
/// </summary> /// </summary>
public class AssemblyHelper public class AssemblyHelper
{ {
@ -26,7 +28,38 @@ namespace FunGame.Core.Api.Util
* *
*/ */
public const string RemoteServerIP = "RemoteServerIP"; public const string RemoteServerIP = "RemoteServerIP";
public const string ServerNotice = "ServerNotice"; public const string DBConnection = "DBConnection";
/// <summary>
/// 获取实现类类名xxInterfaceImpl
/// </summary>
/// <param name="Interface">接口代号</param>
/// <returns></returns>
private string GetClassName(int Interface)
{
return Interface switch
{
(int)CommonEnums.InterfaceType.ClientConnectInterface => ClientConnectInterface + Implement,
(int)CommonEnums.InterfaceType.ServerInterface => ServerInterface + Implement,
_ => "",
};
}
/// <summary>
/// 获取方法名
/// </summary>
/// <param name="Method">方法代号</param>
/// <returns></returns>
private string GetMethodName(int Method)
{
// 通过AssemblyHelperType来获取方法名
return Method switch
{
(int)CommonEnums.InterfaceMethod.RemoteServerIP => RemoteServerIP,
(int)CommonEnums.InterfaceMethod.DBConnection => DBConnection,
_ => "",
};
}
/** /**
* DLL * DLL
@ -55,17 +88,12 @@ namespace FunGame.Core.Api.Util
/// <summary> /// <summary>
/// 获取FunGame.Core.dll中接口的实现方法 /// 获取FunGame.Core.dll中接口的实现方法
/// </summary> /// </summary>
/// <param name="Interface">类名</param> /// <param name="Interface">接口代号</param>
/// <returns></returns> /// <returns></returns>
private Type? GetFunGameCoreImplement(int Interface) private Type? GetFunGameCoreImplement(int Interface)
{ {
// 通过类名获取获取命名空间+类名称 // 通过类名获取获取命名空间+类名称
string ClassName = Interface switch string ClassName = GetClassName(Interface);
{
(int)CommonEnums.InterfaceType.ClientConnectInterface => ClientConnectInterface + Implement,
(int)CommonEnums.InterfaceType.ServerInterface => ServerInterface + Implement,
_ => "",
};
List<Type>? Classes = null; List<Type>? Classes = null;
if (Assembly != null) if (Assembly != null)
{ {
@ -80,21 +108,8 @@ namespace FunGame.Core.Api.Util
else return null; else return null;
} }
private string GetMethodName(int Method)
{
// 通过AssemblyHelperType来获取方法名
switch (Method)
{
case (int)CommonEnums.InterfaceMethod.RemoteServerIP:
return RemoteServerIP;
case (int)CommonEnums.InterfaceMethod.ServerNotice:
return ServerNotice;
}
return "";
}
/// <summary> /// <summary>
/// 获取FUNGAME.CORE.DLL中指定方法的返回值 /// 公开方法获取FUNGAME.CORE.DLL中指定方法的返回值
/// </summary> /// </summary>
/// <param name="Interface">接口代号</param> /// <param name="Interface">接口代号</param>
/// <param name="Method">方法代号</param> /// <param name="Method">方法代号</param>

View File

@ -231,7 +231,7 @@ namespace FunGame.Desktop.Utils
break; break;
case (int)SocketEnums.Type.HeartBeat: case (int)SocketEnums.Type.HeartBeat:
buffer = new byte[2048]; buffer = new byte[2048];
buffer = Config.DEFAULT_ENCODING.GetBytes(Convert.ToString(MakeMessage((int)SocketEnums.Type.HeartBeat, ">> 心跳检测"))); buffer = Config.DEFAULT_ENCODING.GetBytes(Convert.ToString(MakeMessage((int)SocketEnums.Type.HeartBeat, "心跳检测")));
if (socket.Send(buffer) > 0) if (socket.Send(buffer) > 0)
{ {
WaitHeartBeat = Task.Run(() => WaitHeartBeat = Task.Run(() =>