mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-04-22 03:59:35 +08:00
parent
e1c3f7cce1
commit
ecdb321eb6
@ -42,7 +42,7 @@ namespace Milimoe.FunGame.Core.Api.Transmittal
|
|||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Request : BaseModel
|
private class Request : BaseController
|
||||||
{
|
{
|
||||||
public Hashtable RequestData { get; } = new();
|
public Hashtable RequestData { get; } = new();
|
||||||
public Hashtable ResultData { get; } = new();
|
public Hashtable ResultData { get; } = new();
|
||||||
|
@ -28,8 +28,4 @@
|
|||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Library\Server\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
namespace Milimoe.FunGame.Core.Library.Common.Architecture
|
|
||||||
{
|
|
||||||
public abstract class BaseController
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 重写此方法并调用Model的Dispose方法,否则将无法正常将监听Socket的事件移除!
|
|
||||||
/// </summary>
|
|
||||||
public abstract void Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,7 +4,7 @@ using Milimoe.FunGame.Core.Service;
|
|||||||
|
|
||||||
namespace Milimoe.FunGame.Core.Library.Common.Architecture
|
namespace Milimoe.FunGame.Core.Library.Common.Architecture
|
||||||
{
|
{
|
||||||
public class BaseModel : ISocketHandler, IDisposable
|
public class BaseController : ISocketHandler, IDisposable
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 接收到的SocketObject实例
|
/// 接收到的SocketObject实例
|
||||||
@ -25,7 +25,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Architecture
|
|||||||
/// 继承请调用base构造
|
/// 继承请调用base构造
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="socket">Socket</param>
|
/// <param name="socket">Socket</param>
|
||||||
public BaseModel(Socket? socket)
|
public BaseController(Socket? socket)
|
||||||
{
|
{
|
||||||
if (socket != null)
|
if (socket != null)
|
||||||
{
|
{
|
||||||
|
@ -5,7 +5,7 @@ using Milimoe.FunGame.Core.Library.Constant;
|
|||||||
namespace Milimoe.FunGame.Core.Library.Common.Network
|
namespace Milimoe.FunGame.Core.Library.Common.Network
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class JsonObject
|
public struct JsonObject
|
||||||
{
|
{
|
||||||
public SocketMessageType MessageType { get; } = SocketMessageType.Unknown;
|
public SocketMessageType MessageType { get; } = SocketMessageType.Unknown;
|
||||||
public Guid Token { get; }
|
public Guid Token { get; }
|
||||||
@ -34,7 +34,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
|
|||||||
return new JsonObject(MessageType, Token, Parameters).JsonString;
|
return new JsonObject(MessageType, Token, Parameters).JsonString;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonObject? GetObject(string JsonString)
|
public static JsonObject GetObject(string JsonString)
|
||||||
{
|
{
|
||||||
return JsonConvert.DeserializeObject<JsonObject>(JsonString);
|
return JsonConvert.DeserializeObject<JsonObject>(JsonString);
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Numerics;
|
|
||||||
using Milimoe.FunGame.Core.Entity;
|
using Milimoe.FunGame.Core.Entity;
|
||||||
using Milimoe.FunGame.Core.Library.Constant;
|
using Milimoe.FunGame.Core.Library.Constant;
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Core.Library.Common.Architecture
|
namespace Milimoe.FunGame.Core.Model
|
||||||
{
|
{
|
||||||
public class RoomList : IEnumerable
|
public class RoomListModel : IEnumerable
|
||||||
{
|
{
|
||||||
private readonly Hashtable _List = new();
|
private readonly Hashtable _List = new();
|
||||||
private readonly Hashtable _PlayerList = new();
|
private readonly Hashtable _PlayerList = new();
|
||||||
@ -16,7 +15,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Architecture
|
|||||||
|
|
||||||
public List<string> ListRoomID => _List.Keys.Cast<string>().ToList();
|
public List<string> ListRoomID => _List.Keys.Cast<string>().ToList();
|
||||||
|
|
||||||
public RoomList()
|
public RoomListModel()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -117,7 +116,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Architecture
|
|||||||
|
|
||||||
public IEnumerator GetEnumerator()
|
public IEnumerator GetEnumerator()
|
||||||
{
|
{
|
||||||
foreach(Room room in ListRoom)
|
foreach (Room room in ListRoom)
|
||||||
{
|
{
|
||||||
yield return room;
|
yield return room;
|
||||||
}
|
}
|
@ -1,6 +0,0 @@
|
|||||||
namespace Milimoe.FunGame.Core.Others
|
|
||||||
{
|
|
||||||
internal class Others
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
@ -40,6 +40,7 @@ namespace Milimoe.FunGame.Core.Service
|
|||||||
IPEndPoint ServerEndPoint = new(IPAddress.Any, Port);
|
IPEndPoint ServerEndPoint = new(IPAddress.Any, Port);
|
||||||
_ServerSocket.Bind(ServerEndPoint);
|
_ServerSocket.Bind(ServerEndPoint);
|
||||||
_ServerSocket.Listen(MaxConnection);
|
_ServerSocket.Listen(MaxConnection);
|
||||||
|
_ServerSocket.NoDelay = true;
|
||||||
return _ServerSocket;
|
return _ServerSocket;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
@ -61,6 +62,7 @@ namespace Milimoe.FunGame.Core.Service
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Client = ServerSocket.Accept();
|
Client = ServerSocket.Accept();
|
||||||
|
Client.NoDelay = true;
|
||||||
IPEndPoint? ClientIPEndPoint = (IPEndPoint?)Client.RemoteEndPoint;
|
IPEndPoint? ClientIPEndPoint = (IPEndPoint?)Client.RemoteEndPoint;
|
||||||
ClientIP = (ClientIPEndPoint != null) ? ClientIPEndPoint.ToString() : "Unknown";
|
ClientIP = (ClientIPEndPoint != null) ? ClientIPEndPoint.ToString() : "Unknown";
|
||||||
return new object[] { ClientIP, Client };
|
return new object[] { ClientIP, Client };
|
||||||
@ -95,6 +97,7 @@ namespace Milimoe.FunGame.Core.Service
|
|||||||
ClientSocket.Connect(ServerEndPoint);
|
ClientSocket.Connect(ServerEndPoint);
|
||||||
if (ClientSocket.Connected)
|
if (ClientSocket.Connected)
|
||||||
{
|
{
|
||||||
|
ClientSocket.NoDelay = true;
|
||||||
_Socket = ClientSocket;
|
_Socket = ClientSocket;
|
||||||
return _Socket;
|
return _Socket;
|
||||||
}
|
}
|
||||||
@ -167,11 +170,8 @@ namespace Milimoe.FunGame.Core.Service
|
|||||||
if (length > 0)
|
if (length > 0)
|
||||||
{
|
{
|
||||||
string msg = General.DefaultEncoding.GetString(buffer, 0, length);
|
string msg = General.DefaultEncoding.GetString(buffer, 0, length);
|
||||||
Library.Common.Network.JsonObject? json = Library.Common.Network.JsonObject.GetObject(msg);
|
Library.Common.Network.JsonObject json = Library.Common.Network.JsonObject.GetObject(msg);
|
||||||
if (json != null)
|
|
||||||
{
|
|
||||||
result = new Library.Common.Network.SocketObject(json);
|
result = new Library.Common.Network.SocketObject(json);
|
||||||
}
|
|
||||||
// 客户端接收消息,广播ScoketObject到每个UIModel
|
// 客户端接收消息,广播ScoketObject到每个UIModel
|
||||||
OnSocketReceive(result);
|
OnSocketReceive(result);
|
||||||
return result;
|
return result;
|
||||||
@ -196,11 +196,8 @@ namespace Milimoe.FunGame.Core.Service
|
|||||||
if (length > 0)
|
if (length > 0)
|
||||||
{
|
{
|
||||||
string msg = General.DefaultEncoding.GetString(buffer, 0, length);
|
string msg = General.DefaultEncoding.GetString(buffer, 0, length);
|
||||||
Library.Common.Network.JsonObject? json = Library.Common.Network.JsonObject.GetObject(msg);
|
Library.Common.Network.JsonObject json = Library.Common.Network.JsonObject.GetObject(msg);
|
||||||
if (json != null)
|
|
||||||
{
|
|
||||||
result = new Library.Common.Network.SocketObject(json);
|
result = new Library.Common.Network.SocketObject(json);
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user