使用ReceiveArray()读取 (#16)

This commit is contained in:
Yezi 2023-06-06 20:04:11 +08:00 committed by GitHub
parent cef4c80c9e
commit de293557ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 13 deletions

View File

@ -30,10 +30,6 @@
<Content Include="logo.ico" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FunGame.Implement\FunGame.Implement.csproj" />
</ItemGroup>

View File

@ -3,6 +3,7 @@ using Milimoe.FunGame.Core.Api.Utility;
using Milimoe.FunGame.Core.Library.Common.Network;
using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Core.Library.SQLScript.Common;
using Milimoe.FunGame.Core.Library.SQLScript.Entity;
using Milimoe.FunGame.Server.Model;
using Milimoe.FunGame.Server.Others;
using Milimoe.FunGame.Server.Utility;
@ -166,17 +167,21 @@ void StartServer()
bool Read(ClientSocket socket)
{
// 接收客户端消息
SocketObject read = socket.Receive();
SocketMessageType type = read.SocketType;
object[] objs = read.Parameters;
if (type != SocketMessageType.Unknown)
foreach (SocketObject read in socket.ReceiveArray())
{
if (objs[0] != null && objs[0].GetType() == typeof(string) && objs[0].ToString()!.Trim() != "")
ServerHelper.WriteLine("[" + ServerSocket.GetTypeString(type) + "] " + ServerHelper.MakeClientName(socket.ClientIP) + " -> " + objs[0]);
else
ServerHelper.WriteLine("[" + ServerSocket.GetTypeString(type) + "] " + ServerHelper.MakeClientName(socket.ClientIP));
return true;
SocketMessageType type = read.SocketType;
if (type == SocketMessageType.Connect)
{
if (read.Parameters.Length > 0)
{
string str = (read.GetParam<string>(0) ?? "").Trim();
if (str != "") ServerHelper.WriteLine("[" + ServerSocket.GetTypeString(type) + "] " + ServerHelper.MakeClientName(socket.ClientIP) + " -> " + str);
}
else ServerHelper.WriteLine("[" + ServerSocket.GetTypeString(type) + "] " + ServerHelper.MakeClientName(socket.ClientIP));
return true;
}
}
ServerHelper.WriteLine("客户端发送了不符合FunGame规定的字符拒绝连接。");
return false;
}