mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-04-23 20:49:33 +08:00
代码优化
This commit is contained in:
parent
ee2fa26b26
commit
0c4ea422cf
@ -33,6 +33,6 @@ namespace FunGame.Core.Api.Interface
|
||||
|
||||
public interface ServerInterface
|
||||
{
|
||||
public string ServerNotice();
|
||||
public string DBConnection();
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ namespace FunGame.Core.Api.Model.Entity
|
||||
public decimal Price { get; set; }
|
||||
public char Key { get; set; }
|
||||
public bool Active { get; set; }
|
||||
public bool Enable { get; set; }
|
||||
public Character? Character { get; set; } = null;
|
||||
}
|
||||
}
|
||||
|
@ -13,5 +13,6 @@ namespace FunGame.Core.Api.Model.Entity
|
||||
public string Describe { get; set; } = "";
|
||||
public char Key { get; set; }
|
||||
public bool Active { get; set; }
|
||||
public bool Enable { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,9 @@ namespace FunGame.Core.Api.Model.Entity
|
||||
public bool IsEnable { get; set; } = false;
|
||||
public int OnlineState { get; set; } = 0;
|
||||
public string Roomid { get; set; } = "";
|
||||
public int Credits { get; set; } = 0;
|
||||
public int Material { get; set; } = 0;
|
||||
public decimal Credits { get; set; } = 0;
|
||||
public decimal Materials { get; set; } = 0;
|
||||
public decimal GameTime { get; set; } = 0;
|
||||
public UserStatistics? Statistics { get; set; } = null;
|
||||
public Stock? Stock { get; set; } = null;
|
||||
|
||||
|
@ -90,7 +90,7 @@ namespace FunGame.Core.Api.Model.Enum
|
||||
public enum InterfaceMethod
|
||||
{
|
||||
RemoteServerIP = 1,
|
||||
ServerNotice = 2
|
||||
DBConnection = 2
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using System.Reflection;
|
||||
using System.Diagnostics;
|
||||
using FunGame.Core.Api.Model.Enum;
|
||||
using System.Data.Common;
|
||||
|
||||
namespace FunGame.Core.Api.Util
|
||||
{
|
||||
@ -13,6 +14,7 @@ namespace FunGame.Core.Api.Util
|
||||
/// 在FunGame.Core.Api中添加新接口和新实现时,需要:
|
||||
/// 1、在这里定义类名和方法名
|
||||
/// 2、在FunGame.Core.Api.Model.Enum.CommonEnums里同步添加InterfaceType和InterfaceMethod
|
||||
/// 3、在GetClassName(int)、GetMethodName(int)中添加switch分支
|
||||
/// </summary>
|
||||
public class AssemblyHelper
|
||||
{
|
||||
@ -26,7 +28,38 @@ namespace FunGame.Core.Api.Util
|
||||
* 定义方法名
|
||||
*/
|
||||
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
|
||||
@ -55,17 +88,12 @@ namespace FunGame.Core.Api.Util
|
||||
/// <summary>
|
||||
/// 获取FunGame.Core.dll中接口的实现方法
|
||||
/// </summary>
|
||||
/// <param name="Interface">类名</param>
|
||||
/// <param name="Interface">接口代号</param>
|
||||
/// <returns></returns>
|
||||
private Type? GetFunGameCoreImplement(int Interface)
|
||||
{
|
||||
// 通过类名获取获取命名空间+类名称
|
||||
string ClassName = Interface switch
|
||||
{
|
||||
(int)CommonEnums.InterfaceType.ClientConnectInterface => ClientConnectInterface + Implement,
|
||||
(int)CommonEnums.InterfaceType.ServerInterface => ServerInterface + Implement,
|
||||
_ => "",
|
||||
};
|
||||
string ClassName = GetClassName(Interface);
|
||||
List<Type>? Classes = null;
|
||||
if (Assembly != null)
|
||||
{
|
||||
@ -80,21 +108,8 @@ namespace FunGame.Core.Api.Util
|
||||
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>
|
||||
/// 获取FUNGAME.CORE.DLL中指定方法的返回值
|
||||
/// 公开方法:获取FUNGAME.CORE.DLL中指定方法的返回值
|
||||
/// </summary>
|
||||
/// <param name="Interface">接口代号</param>
|
||||
/// <param name="Method">方法代号</param>
|
||||
|
@ -231,7 +231,7 @@ namespace FunGame.Desktop.Utils
|
||||
break;
|
||||
case (int)SocketEnums.Type.HeartBeat:
|
||||
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)
|
||||
{
|
||||
WaitHeartBeat = Task.Run(() =>
|
||||
|
Loading…
x
Reference in New Issue
Block a user