添加接口

This commit is contained in:
Mili 2022-09-02 00:47:20 +08:00
parent 2618b8b41e
commit 0e9b873b7a
12 changed files with 71 additions and 150 deletions

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<BaseOutputPath>..\bin</BaseOutputPath> <BaseOutputPath>..\bin</BaseOutputPath>
@ -13,4 +13,12 @@
<Title>FunGame</Title> <Title>FunGame</Title>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>embedded</DebugType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>embedded</DebugType>
</PropertyGroup>
</Project> </Project>

View File

@ -13,7 +13,7 @@ namespace FunGame.Core.Api.Interface
namespace FunGame.Core.Implement namespace FunGame.Core.Implement
{ {
public class ServerInterfaceImpl : ServerInterface public class ClientConnectInterfaceImpl : ClientConnectInterface
{ {
public string RemoteServerIP() public string RemoteServerIP()
{ {
@ -26,8 +26,13 @@ namespace FunGame.Core.Api.Interface
} }
*/ */
public interface ServerInterface public interface ClientConnectInterface
{ {
public string RemoteServerIP(); public string RemoteServerIP();
} }
public interface ServerInterface
{
public string ServerNotice();
}
} }

View File

@ -59,7 +59,8 @@ namespace FunGame.Core.Api.Model.Enum
public enum InterfaceType public enum InterfaceType
{ {
ServerInterface = 1 ClientConnectInterface = 1,
ServerInterface = 2
} }
#endregion #endregion
@ -88,7 +89,8 @@ namespace FunGame.Core.Api.Model.Enum
public enum InterfaceMethod public enum InterfaceMethod
{ {
GetServerIP = 1 RemoteServerIP = 1,
ServerNotice = 2
} }
#endregion #endregion

View File

@ -19,12 +19,14 @@ namespace FunGame.Core.Api.Util
/** /**
* *
*/ */
public const string ClientConnectInterface = "ClientConnectInterface";
public const string ServerInterface = "ServerInterface"; public const string ServerInterface = "ServerInterface";
/** /**
* *
*/ */
public const string GetRemoteServerIP = "RemoteServerIP"; public const string RemoteServerIP = "RemoteServerIP";
public const string ServerNotice = "ServerNotice";
/** /**
* DLL * DLL
@ -35,7 +37,8 @@ namespace FunGame.Core.Api.Util
* *
*/ */
public const string Implement = "Impl"; // 实现类的后缀 public const string Implement = "Impl"; // 实现类的后缀
public static string PluginDocPath = System.Diagnostics.Process.GetCurrentProcess() + "/plugins/"; // 插件目录反射插件DLL需要用LoadFile()方法 public static string EXEDocPath = System.Environment.CurrentDirectory.ToString() + "\\"; // 程序目录
public static string PluginDocPath = System.Environment.CurrentDirectory + "\\plugins\\"; // 插件目录
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
/////////////// * 下 面 是 工 具 类 实 现 * //////////////// /////////////// * 下 面 是 工 具 类 实 现 * ////////////////
@ -59,7 +62,7 @@ namespace FunGame.Core.Api.Util
// 通过类名获取获取命名空间+类名称 // 通过类名获取获取命名空间+类名称
string ClassName = Interface switch string ClassName = Interface switch
{ {
(int)CommonEnums.InterfaceType.ServerInterface => ServerInterface + Implement, (int)CommonEnums.InterfaceType.ClientConnectInterface => ClientConnectInterface + Implement,
_ => "", _ => "",
}; };
List<Type>? Classes = null; List<Type>? Classes = null;
@ -84,8 +87,8 @@ namespace FunGame.Core.Api.Util
// 通过AssemblyHelperType来获取方法名 // 通过AssemblyHelperType来获取方法名
switch (Method) switch (Method)
{ {
case (int)CommonEnums.InterfaceMethod.GetServerIP: case (int)CommonEnums.InterfaceMethod.RemoteServerIP:
return GetRemoteServerIP; return RemoteServerIP;
} }
return ""; return "";
} }
@ -98,7 +101,7 @@ namespace FunGame.Core.Api.Util
/// <returns></returns> /// <returns></returns>
public object? GetFunGameCoreValue(int Interface, int Method) public object? GetFunGameCoreValue(int Interface, int Method)
{ {
Assembly = Assembly.Load(@FUNGAME_CORE); Assembly = Assembly.LoadFile(EXEDocPath + @FUNGAME_CORE + ".dll");
Type = GetFunGameCoreImplement(Interface); // 通过类名获取获取命名空间+类名称 Type = GetFunGameCoreImplement(Interface); // 通过类名获取获取命名空间+类名称
string MethodName = GetMethodName(Method); // 获取方法名 string MethodName = GetMethodName(Method); // 获取方法名
if (Assembly != null && Type != null) this.Method = Type.GetMethod(MethodName); // 从Type中查找方法名 if (Assembly != null && Type != null) this.Method = Type.GetMethod(MethodName); // 从Type中查找方法名

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<Company>Milimoe</Company> <Company>Milimoe</Company>
@ -13,12 +13,19 @@
<FileVersion>1.0</FileVersion> <FileVersion>1.0</FileVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Folder Include="Implement\" /> <DebugType>embedded</DebugType>
</ItemGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>embedded</DebugType>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\FunGame.Core.Api\FunGame.Core.Api.csproj" /> <ProjectReference Include="..\FunGame.Core.Api\FunGame.Core.Api.csproj">
<Private>False</Private>
<CopyLocalSatelliteAssemblies>True</CopyLocalSatelliteAssemblies>
</ProjectReference>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -11,7 +11,7 @@
<PackageIcon>logo.ico</PackageIcon> <PackageIcon>logo.ico</PackageIcon>
<Company>Milimoe</Company> <Company>Milimoe</Company>
<BaseOutputPath>..\bin</BaseOutputPath> <BaseOutputPath>..\bin</BaseOutputPath>
<GenerateDocumentationFile>True</GenerateDocumentationFile> <GenerateDocumentationFile>False</GenerateDocumentationFile>
<SignAssembly>False</SignAssembly> <SignAssembly>False</SignAssembly>
<Authors>Milimoe</Authors> <Authors>Milimoe</Authors>
<Product>FunGame</Product> <Product>FunGame</Product>
@ -21,6 +21,14 @@
<FileVersion>1.0</FileVersion> <FileVersion>1.0</FileVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>embedded</DebugType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>embedded</DebugType>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Content Include="Images\logo.ico" /> <Content Include="Images\logo.ico" />
</ItemGroup> </ItemGroup>
@ -50,8 +58,12 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\FunGame.Core.Api\FunGame.Core.Api.csproj" /> <ProjectReference Include="..\FunGame.Core.Api\FunGame.Core.Api.csproj">
<ProjectReference Include="..\FunGame.Core\FunGame.Core.csproj" /> <CopyLocalSatelliteAssemblies>True</CopyLocalSatelliteAssemblies>
</ProjectReference>
<ProjectReference Include="..\FunGame.Core\FunGame.Core.csproj">
<CopyLocalSatelliteAssemblies>True</CopyLocalSatelliteAssemblies>
</ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -7,7 +7,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using FunGame.Desktop.Models.Enum; using FunGame.Core.Api.Model.Enum;
namespace FunGame.Desktop.Models.Component namespace FunGame.Desktop.Models.Component
{ {

View File

@ -1,97 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FunGame.Desktop.Models.Enum
{
/// <summary>
/// 这里存放框架实现相关的State Type Result Method
/// 添加FunGame.Core接口和实现时需要在这里同步添加InterfaceType和InterfaceMethod
/// </summary>
public static class CommonEnums
{
#region State
public enum StartMatch_State
{
Matching = 1,
Success = 2,
Enable = 3,
Cancel = 4
}
public enum CreateRoom_State
{
Creating = 1,
Success = 2
}
public enum RoomState
{
Created = 1,
Gaming = 2,
Close = 3,
Complete = 4
}
public enum OnlineState
{
Offline = 1,
Online = 2,
Matching = 3,
InRoom = 4,
Gaming = 5
}
#endregion
#region Type
public enum RoomType
{
Mix = 1,
Team = 2,
MixHasPass = 3,
TeamHasPass = 4
}
public enum InterfaceType
{
ServerInterface = 1
}
#endregion
#region Result
public enum MessageResult
{
OK = 1,
Cancel = 2,
Yes = 3,
No = 4,
Retry = 5
}
#endregion
#region Method
public enum WebHelperMethod
{
CreateSocket = 1,
CloseSocket = 2,
StartWebHelper = 3,
}
public enum InterfaceMethod
{
GetServerIP = 1
}
#endregion
}
}

View File

@ -1,27 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FunGame.Desktop.Models.Enum
{
public static class SocketEnums
{
public enum Type
{
GetNotice = 1,
Login = 2,
CheckLogin = 3,
Logout = 4,
HeartBeat = 5
}
public const string TYPE_UNKNOWN = "Unknown Type";
public const string TYPE_GetNotice = "GetNotice";
public const string TYPE_Login = "Login";
public const string TYPE_CheckLogin = "CheckLogin";
public const string TYPE_Logout = "Logout";
public const string TYPE_HeartBeat = "HeartBeat";
}
}

View File

@ -3,13 +3,12 @@ using System.Diagnostics;
using System.Net.Sockets; using System.Net.Sockets;
using System.Net; using System.Net;
using System.Windows.Forms; using System.Windows.Forms;
using static FunGame.Desktop.Models.Enum.CommonEnums;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using System.Text; using System.Text;
using FunGame.Core.Api.Model.Entity; using FunGame.Core.Api.Model.Entity;
using FunGame.Desktop.Models.Enum;
using FunGame.Desktop.Models.Config; using FunGame.Desktop.Models.Config;
using FunGame.Desktop.Utils; using FunGame.Desktop.Utils;
using static FunGame.Core.Api.Model.Enum.CommonEnums;
namespace FunGame.Desktop.UI namespace FunGame.Desktop.UI
{ {
@ -173,7 +172,7 @@ namespace FunGame.Desktop.UI
{ {
try try
{ {
string? ipaddress = (string?)Config.DefaultAssemblyHelper.GetFunGameCoreValue((int)InterfaceType.ServerInterface, (int)InterfaceMethod.GetServerIP); // 获取服务器IP string? ipaddress = (string?)Config.DefaultAssemblyHelper.GetFunGameCoreValue((int)InterfaceType.ClientConnectInterface, (int)InterfaceMethod.RemoteServerIP); // 获取服务器IP
if (ipaddress != null) if (ipaddress != null)
{ {
string[] s = ipaddress.Split(':'); string[] s = ipaddress.Split(':');
@ -685,6 +684,7 @@ namespace FunGame.Desktop.UI
/// 设置服务器连接状态指示灯 /// 设置服务器连接状态指示灯
/// </summary> /// </summary>
/// <param name="green"></param> /// <param name="green"></param>
/// <param name="ping"></param>
private void SetServerStatusLight(bool green, int ping = 0) private void SetServerStatusLight(bool green, int ping = 0)
{ {
if (green) if (green)

View File

@ -9,7 +9,7 @@ using FunGame.Desktop.Models.Component;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using FunGame.Core.Api.Model.Entity; using FunGame.Core.Api.Model.Entity;
using FunGame.Desktop.Models.Enum; using FunGame.Core.Api.Model.Enum;
using FunGame.Desktop.Models.Config; using FunGame.Desktop.Models.Config;
using FunGame.Desktop.UI; using FunGame.Desktop.UI;

View File

@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<BaseOutputPath>..\bin</BaseOutputPath> <BaseOutputPath>..\bin\</BaseOutputPath>
<Authors>Milimoe</Authors> <Authors>Milimoe</Authors>
<Company>Milimoe</Company> <Company>Milimoe</Company>
<Title>FunGame</Title> <Title>FunGame</Title>
@ -13,4 +13,12 @@
<PackageOutputPath>..\bin\plugin</PackageOutputPath> <PackageOutputPath>..\bin\plugin</PackageOutputPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>embedded</DebugType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>embedded</DebugType>
</PropertyGroup>
</Project> </Project>