forked from project-redbud/FunGame-Core
parent
ecdb321eb6
commit
b08d62d6f8
@ -8,6 +8,7 @@ namespace Milimoe.FunGame.Core.Interface.Base
|
|||||||
public void StartReceiving(Task t);
|
public void StartReceiving(Task t);
|
||||||
public SocketResult Send(SocketMessageType type, params object[] objs);
|
public SocketResult Send(SocketMessageType type, params object[] objs);
|
||||||
public Library.Common.Network.SocketObject Receive();
|
public Library.Common.Network.SocketObject Receive();
|
||||||
|
public Library.Common.Network.SocketObject[] ReceiveArray();
|
||||||
public void BindEvent(Delegate Method, bool Remove = false);
|
public void BindEvent(Delegate Method, bool Remove = false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,6 +50,18 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SocketObject[] ReceiveArray()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return SocketManager.ReceiveArray(Instance);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw new SocketWrongInfoException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public SocketResult Send(SocketMessageType type, params object[] objs)
|
public SocketResult Send(SocketMessageType type, params object[] objs)
|
||||||
{
|
{
|
||||||
if (Instance != null)
|
if (Instance != null)
|
||||||
|
|||||||
@ -38,6 +38,30 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
|
|||||||
{
|
{
|
||||||
return JsonConvert.DeserializeObject<JsonObject>(JsonString);
|
return JsonConvert.DeserializeObject<JsonObject>(JsonString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static JsonObject[] GetObjects(string JsonString)
|
||||||
|
{
|
||||||
|
List<JsonObject> jsons = new();
|
||||||
|
|
||||||
|
JsonSerializer serializer = new();
|
||||||
|
JsonTextReader reader = new(new StringReader(JsonString))
|
||||||
|
{
|
||||||
|
SupportMultipleContent = true
|
||||||
|
};
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
if (!reader.Read())
|
||||||
|
{
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonObject json = serializer.Deserialize<JsonObject>(reader);
|
||||||
|
|
||||||
|
jsons.Add(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsons.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,6 +72,27 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SocketObject[] ReceiveArray()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SocketObject[] result = SocketManager.ReceiveArray();
|
||||||
|
foreach (SocketObject obj in result)
|
||||||
|
{
|
||||||
|
if (obj.SocketType == SocketMessageType.HeartBeat)
|
||||||
|
{
|
||||||
|
if (WaitHeartBeatReply != null && !WaitHeartBeatReply.IsCompleted) WaitHeartBeatReply.Wait(1);
|
||||||
|
_HeartBeatFaileds = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw new SocketWrongInfoException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void BindEvent(Delegate Method, bool Remove = false)
|
public void BindEvent(Delegate Method, bool Remove = false)
|
||||||
{
|
{
|
||||||
if (!Remove)
|
if (!Remove)
|
||||||
|
|||||||
7
Model/RunTimeModel.cs
Normal file
7
Model/RunTimeModel.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace Milimoe.FunGame.Core.Model
|
||||||
|
{
|
||||||
|
public class RunTimeModel
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
10
Model/SessionModel.cs
Normal file
10
Model/SessionModel.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace Milimoe.FunGame.Core.Model
|
||||||
|
{
|
||||||
|
public class SessionModel
|
||||||
|
{
|
||||||
|
public SessionModel()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -204,6 +204,61 @@ namespace Milimoe.FunGame.Core.Service
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 用于客户端接收服务器信息(数组版)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>SocketObjects</returns>
|
||||||
|
internal static Library.Common.Network.SocketObject[] ReceiveArray()
|
||||||
|
{
|
||||||
|
List<Library.Common.Network.SocketObject> result = new();
|
||||||
|
if (Socket != null)
|
||||||
|
{
|
||||||
|
// 从服务器接收消息
|
||||||
|
byte[] buffer = new byte[General.SocketByteSize];
|
||||||
|
int length = Socket.Receive(buffer);
|
||||||
|
if (length > 0)
|
||||||
|
{
|
||||||
|
string msg = General.DefaultEncoding.GetString(buffer, 0, length);
|
||||||
|
Library.Common.Network.JsonObject[] jsons = Library.Common.Network.JsonObject.GetObjects(msg);
|
||||||
|
foreach (Library.Common.Network.JsonObject json in jsons)
|
||||||
|
{
|
||||||
|
// 客户端接收消息,广播ScoketObject到每个UIModel
|
||||||
|
Library.Common.Network.SocketObject obj = new(json);
|
||||||
|
result.Add(obj);
|
||||||
|
OnSocketReceive(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 用于服务器接收客户端信息(数组版)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ClientSocket">客户端Socket</param>
|
||||||
|
/// <returns>SocketObjects</returns>
|
||||||
|
internal static Library.Common.Network.SocketObject[] ReceiveArray(Socket ClientSocket)
|
||||||
|
{
|
||||||
|
List<Library.Common.Network.SocketObject> result = new();
|
||||||
|
if (ClientSocket != null)
|
||||||
|
{
|
||||||
|
// 从客户端接收消息
|
||||||
|
byte[] buffer = new byte[General.SocketByteSize];
|
||||||
|
int length = ClientSocket.Receive(buffer);
|
||||||
|
if (length > 0)
|
||||||
|
{
|
||||||
|
string msg = General.DefaultEncoding.GetString(buffer, 0, length);
|
||||||
|
Library.Common.Network.JsonObject[] jsons = Library.Common.Network.JsonObject.GetObjects(msg);
|
||||||
|
foreach (Library.Common.Network.JsonObject json in jsons)
|
||||||
|
{
|
||||||
|
Library.Common.Network.SocketObject so = new(json);
|
||||||
|
result.Add(so);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 将通信类型的枚举转换为字符串
|
/// 将通信类型的枚举转换为字符串
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user