mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-12-05 00:06:02 +00:00
MISC
This commit is contained in:
parent
0a88d420c2
commit
6471474c59
@ -12,11 +12,11 @@ namespace Milimoe.FunGame.Core.Interface.Base
|
||||
{
|
||||
public System.Net.Sockets.Socket Instance { get; }
|
||||
public int Runtime { get; }
|
||||
public string Token { get; }
|
||||
public string ServerIP { get; }
|
||||
public int ServerPort { get; }
|
||||
public string ServerName { get; }
|
||||
public string ServerNotice { get; }
|
||||
public int HeartBeatFaileds { get; }
|
||||
public bool Connected
|
||||
{
|
||||
get
|
||||
@ -25,7 +25,6 @@ namespace Milimoe.FunGame.Core.Interface.Base
|
||||
}
|
||||
}
|
||||
public bool Receiving { get; }
|
||||
public bool SendingHeartBeat { get; }
|
||||
public SocketResult Send(SocketMessageType type, params object[] objs);
|
||||
public object[] Receive();
|
||||
public void Close();
|
||||
|
||||
14
FunGame.Core/Interface/Base/ISocketHeartBeat.cs
Normal file
14
FunGame.Core/Interface/Base/ISocketHeartBeat.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Interface.Base
|
||||
{
|
||||
public interface ISocketHeartBeat
|
||||
{
|
||||
public int HeartBeatFaileds { get; }
|
||||
public bool SendingHeartBeat { get; }
|
||||
}
|
||||
}
|
||||
@ -13,13 +13,13 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
|
||||
{
|
||||
public System.Net.Sockets.Socket Instance { get; }
|
||||
public int Runtime { get; } = (int)SocketRuntimeType.Server;
|
||||
public string Token { get; } = "";
|
||||
public string ServerIP { get; } = "";
|
||||
public int ServerPort { get; } = 0;
|
||||
public string ServerName { get; } = "";
|
||||
public string ServerNotice { get; } = "";
|
||||
public string ClientIP { get; } = "";
|
||||
public string ClientName { get; private set; } = "";
|
||||
public int HeartBeatFaileds { get; private set; } = 0;
|
||||
public bool Connected
|
||||
{
|
||||
get
|
||||
@ -28,7 +28,6 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
|
||||
}
|
||||
}
|
||||
public bool Receiving { get; private set; } = false;
|
||||
public bool SendingHeartBeat { get; private set; } = false;
|
||||
|
||||
private Task? ReceivingTask;
|
||||
|
||||
@ -57,7 +56,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
|
||||
{
|
||||
if (Instance != null)
|
||||
{
|
||||
if (SocketManager.Send(Instance, type, objs) == SocketResult.Success)
|
||||
if (SocketManager.Send(Instance, type, Token, objs) == SocketResult.Success)
|
||||
{
|
||||
return SocketResult.Success;
|
||||
}
|
||||
|
||||
@ -12,19 +12,21 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
|
||||
internal class JsonObject
|
||||
{
|
||||
internal SocketMessageType MessageType { get; } = SocketMessageType.Unknown;
|
||||
internal string Token { get; }
|
||||
internal object[] Parameters { get; }
|
||||
internal string JsonString { get; }
|
||||
|
||||
internal JsonObject(SocketMessageType MessageType, object[] Parameters)
|
||||
internal JsonObject(SocketMessageType MessageType, string Token, object[] Parameters)
|
||||
{
|
||||
this.MessageType = MessageType;
|
||||
this.Token = Token;
|
||||
this.Parameters = Parameters;
|
||||
this.JsonString = JsonSerializer.Serialize(this);
|
||||
}
|
||||
|
||||
internal static string GetString(SocketMessageType MessageType, object[] Parameters)
|
||||
internal static string GetString(SocketMessageType MessageType, string Token, object[] Parameters)
|
||||
{
|
||||
return new JsonObject(MessageType, Parameters).JsonString;
|
||||
return new JsonObject(MessageType, Token, Parameters).JsonString;
|
||||
}
|
||||
|
||||
internal static JsonObject? GetObject(string JsonString)
|
||||
|
||||
@ -14,11 +14,11 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
|
||||
{
|
||||
public System.Net.Sockets.Socket Instance { get; }
|
||||
public int Runtime { get; } = (int)SocketRuntimeType.Server;
|
||||
public string Token { get; } = "";
|
||||
public string ServerIP { get; } = "";
|
||||
public int ServerPort { get; } = 0;
|
||||
public string ServerName { get; } = "";
|
||||
public string ServerNotice { get; } = "";
|
||||
public int HeartBeatFaileds { get; private set; } = 0;
|
||||
public bool Connected
|
||||
{
|
||||
get
|
||||
@ -27,7 +27,6 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
|
||||
}
|
||||
}
|
||||
public bool Receiving { get; private set; } = false;
|
||||
public bool SendingHeartBeat { get; private set; } = false;
|
||||
|
||||
private readonly ThreadManager PlayerThreads;
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
using System.Security.Cryptography;
|
||||
using Milimoe.FunGame.Core.Interface;
|
||||
using Milimoe.FunGame.Core.Service;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
@ -12,10 +13,11 @@ using Milimoe.FunGame.Core.Interface.Base;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Library.Common.Network
|
||||
{
|
||||
public class Socket : ISocket
|
||||
public class Socket : ISocket, ISocketHeartBeat
|
||||
{
|
||||
public System.Net.Sockets.Socket Instance { get; }
|
||||
public int Runtime { get; } = (int)SocketRuntimeType.Client;
|
||||
public string Token { get; set; } = "";
|
||||
public string ServerIP { get; } = "";
|
||||
public int ServerPort { get; } = 0;
|
||||
public string ServerName { get; } = "";
|
||||
@ -54,11 +56,11 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
|
||||
{
|
||||
if (Instance != null)
|
||||
{
|
||||
if (SocketManager.Send(type, objs) == SocketResult.Success)
|
||||
if (SocketManager.Send(type, Token, objs) == SocketResult.Success)
|
||||
{
|
||||
return SocketResult.Success;
|
||||
}
|
||||
else return SocketResult.Fail;
|
||||
return SocketResult.Fail;
|
||||
}
|
||||
return SocketResult.NotSent;
|
||||
}
|
||||
|
||||
@ -115,11 +115,11 @@ namespace Milimoe.FunGame.Core.Service
|
||||
/// <param name="type">通信类型</param>
|
||||
/// <param name="objs">参数</param>
|
||||
/// <returns>通信结果</returns>
|
||||
internal static SocketResult Send(Socket ClientSocket, SocketMessageType type, object[] objs)
|
||||
internal static SocketResult Send(Socket ClientSocket, SocketMessageType type, string token, object[] objs)
|
||||
{
|
||||
if (ClientSocket != null && objs != null && objs.Length > 0)
|
||||
{
|
||||
if (ClientSocket.Send(General.DEFAULT_ENCODING.GetBytes(Library.Common.Network.JsonObject.GetString(type, objs))) > 0)
|
||||
if (ClientSocket.Send(General.DEFAULT_ENCODING.GetBytes(Library.Common.Network.JsonObject.GetString(type, token, objs))) > 0)
|
||||
{
|
||||
return SocketResult.Success;
|
||||
}
|
||||
@ -134,7 +134,7 @@ namespace Milimoe.FunGame.Core.Service
|
||||
/// <param name="type">通信类型</param>
|
||||
/// <param name="objs">参数</param>
|
||||
/// <returns>通信结果</returns>
|
||||
internal static SocketResult Send(SocketMessageType type, object[] objs)
|
||||
internal static SocketResult Send(SocketMessageType type, string token, object[] objs)
|
||||
{
|
||||
if (objs is null || objs.Length <= 0)
|
||||
{
|
||||
@ -142,7 +142,7 @@ namespace Milimoe.FunGame.Core.Service
|
||||
}
|
||||
if (Socket != null)
|
||||
{
|
||||
if (Socket.Send(General.DEFAULT_ENCODING.GetBytes(Library.Common.Network.JsonObject.GetString(type, objs))) > 0)
|
||||
if (Socket.Send(General.DEFAULT_ENCODING.GetBytes(Library.Common.Network.JsonObject.GetString(type, token, objs))) > 0)
|
||||
{
|
||||
return SocketResult.Success;
|
||||
}
|
||||
|
||||
@ -279,6 +279,8 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
string ServerNotice = strings[1];
|
||||
Config.FunGame_ServerName = ServerName;
|
||||
Config.FunGame_Notice = ServerNotice;
|
||||
if (objs.Length > 1) msg = (string)objs[1];
|
||||
Socket!!.Token = msg;
|
||||
Main?.GetMessage($"已连接服务器:{ServerName}。\n\n********** 服务器公告 **********\n\n{ServerNotice}\n\n");
|
||||
// 设置等待登录的黄灯
|
||||
Main?.UpdateUI(MainControllerSet.WaitLoginAndSetYellow);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user