ScoketManager

This commit is contained in:
Mili 2022-11-18 21:28:15 +08:00
parent 256369ebb0
commit d8489d654a
10 changed files with 37 additions and 9 deletions

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Milimoe.FunGame.Core.Entity.Enum; using Milimoe.FunGame.Core.Entity.Enum;
using Milimoe.FunGame.Core.Others; using Milimoe.FunGame.Core.Library.Constant;
namespace Milimoe.FunGame.Core.Api.Utility namespace Milimoe.FunGame.Core.Api.Utility
{ {

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Milimoe.FunGame.Core.Library.Constant;
namespace Milimoe.FunGame.Core.Api.Utility namespace Milimoe.FunGame.Core.Api.Utility
{ {
@ -41,7 +42,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
/// <returns></returns> /// <returns></returns>
public static object New<T>(params object[]? objs) public static object New<T>(params object[]? objs)
{ {
object instance = Core.Others.Constant.EntityInstance; object instance = General.EntityInstance;
if (!IsEntity<T>()) return instance; if (!IsEntity<T>()) return instance;
if (objs is null || objs.Length == 0) return instance; if (objs is null || objs.Length == 0) return instance;
if (typeof(T) == typeof(Entity.General.User)) if (typeof(T) == typeof(Entity.General.User))
@ -66,7 +67,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
/// <returns></returns> /// <returns></returns>
public static object NewSingle<T>(params object[]? objs) public static object NewSingle<T>(params object[]? objs)
{ {
object instance = Core.Others.Constant.EntityInstance; object instance = General.EntityInstance;
if (!IsEntity<T>()) return instance; if (!IsEntity<T>()) return instance;
if (objs is null || objs.Length == 0) return instance; if (objs is null || objs.Length == 0) return instance;
if (typeof(T) == typeof(Entity.General.User)) if (typeof(T) == typeof(Entity.General.User))

View File

@ -22,4 +22,8 @@
<DebugType>embedded</DebugType> <DebugType>embedded</DebugType>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Folder Include="Library\Common\" />
</ItemGroup>
</Project> </Project>

View File

@ -1,7 +1,8 @@
namespace Milimoe.FunGame.Core.Interface namespace Milimoe.FunGame.Core.Interface
{ {
/** /**
* FunGame.Core项目中Implement文件夹创建新的类实现 * FunGame.Core项目中创建新的类实现
* namespace必须是Milimoe.FunGame.Core.Implement
* *
* using Milimoe.FunGame.Core.Interface; * using Milimoe.FunGame.Core.Interface;

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Milimoe.FunGame.Core.Library.Constant
{
public class General
{
public static Entity.General.Empty EntityInstance { get; } = new();
}
}

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Milimoe.FunGame.Core.Others namespace Milimoe.FunGame.Core.Library.Constant
{ {
public enum InterfaceType public enum InterfaceType
{ {

View File

@ -5,7 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Milimoe.FunGame.Core.Entity.Exception namespace Milimoe.FunGame.Core.Library.Exception
{ {
public class SystemError : System.Exception public class SystemError : System.Exception
{ {

View File

@ -6,8 +6,7 @@ using System.Threading.Tasks;
namespace Milimoe.FunGame.Core.Others namespace Milimoe.FunGame.Core.Others
{ {
public class Constant internal class Others
{ {
public static Entity.General.Empty EntityInstance = new Entity.General.Empty();
} }
} }

View File

@ -12,6 +12,15 @@ namespace Milimoe.FunGame.Core.Service
{ {
internal class SocketManager internal class SocketManager
{ {
internal static SocketManager? Instance { get; private set; }
internal Socket? Socket { get; } = null;
private SocketManager(Socket socket)
{
Socket = socket;
}
internal static Socket? Connect(string IP, int Port = 22222) internal static Socket? Connect(string IP, int Port = 22222)
{ {
Socket? socket = null; Socket? socket = null;
@ -29,6 +38,7 @@ namespace Milimoe.FunGame.Core.Service
socket.Connect(ServerEndPoint); socket.Connect(ServerEndPoint);
if (socket.Connected) if (socket.Connected)
{ {
Instance = new SocketManager(socket);
return socket; return socket;
} }
} }

View File

@ -7,10 +7,10 @@ using System.Text;
using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Api.Utility;
using Milimoe.FunGame.Core.Entity.General; using Milimoe.FunGame.Core.Entity.General;
using Milimoe.FunGame.Core.Entity.Enum; using Milimoe.FunGame.Core.Entity.Enum;
using Milimoe.FunGame.Core.Others;
using Milimoe.FunGame.Desktop.Entity.Component; using Milimoe.FunGame.Desktop.Entity.Component;
using Milimoe.FunGame.Desktop.Others; using Milimoe.FunGame.Desktop.Others;
using Milimoe.FunGame.Desktop.Utils; using Milimoe.FunGame.Desktop.Utils;
using Milimoe.FunGame.Core.Library.Constant;
namespace Milimoe.FunGame.Desktop.UI namespace Milimoe.FunGame.Desktop.UI
{ {