Skip to content

Commit

Permalink
更新协议库版本
Browse files Browse the repository at this point in the history
  • Loading branch information
Megghy committed Jul 19, 2022
1 parent 4ff0d90 commit 029b292
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 37 deletions.
10 changes: 5 additions & 5 deletions MultiSEngine/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public static Config Load()
var config = new Config()
{
SwitchToDefaultServerOnJoin = true,
DefaultServer = "yfeil",
DefaultServer = "boss",
Servers = new()
{
new()
{
Visible = true,
IP = "yfeil.top",
IP = "trcn.fun",
Port = 7777,
Name = "yfeil",
Name = "boss",
}
}
};
Expand Down Expand Up @@ -77,9 +77,9 @@ public void Save()
public string ListenIP { get; set; } = "0.0.0.0";
public int ListenPort { get; set; } = 7778;
public string ServerName { get; set; } = "MultiSEngine";
public int ServerVersion { get; set; } = 244;
public int ServerVersion { get; set; } = 248;
public string Token { get; set; } = "114514";
public int SwitchTimeOut { get; set; } = 5000;
public int SwitchTimeOut { get; set; } = 10000;
public bool EnableCrossplayFeature { get; set; } = false;
public bool EnableChatForward { get; set; } = true;
public bool SwitchToDefaultServerOnJoin { get; set; } = false;
Expand Down
15 changes: 9 additions & 6 deletions MultiSEngine/Core/Adapter/BaseAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MultiSEngine.DataStruct;
using MultiSEngine.Modules;
using System;
using System.Collections.Concurrent;
using System.IO;
Expand Down Expand Up @@ -78,12 +79,12 @@ protected void ProcessPacketLoop()
SendPacket(packet);
}
#if DEBUG
catch (IOException io)
{
Console.WriteLine(io);
}
catch (IOException io)
{
Console.WriteLine(io);
}
#endif
catch (BadBoundException)
catch (OutOfBoundsException)
{
}
catch (Exception ex)
Expand All @@ -106,13 +107,15 @@ protected virtual void OnRecieveLoopError(Exception ex)
{
case EndOfStreamException:
case IOException:
case BadBoundException:
case OutOfBoundsException:
//
break;
default:
Logs.Warn($"{(ListenningClient ? "Client" : "Server")} recieve loop abnormally terminated. [{ErrorCount}]\r\n{ex}");
break;
}
if (ErrorCount > 10)
Client.Back();
}
protected void RecieveLoop()
{
Expand Down
15 changes: 8 additions & 7 deletions MultiSEngine/Core/Adapter/VisualPlayerAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,6 @@ public override bool GetPacket(Packet packet)
Client.SendInfoMessage($"SSC: {worldData.EventInfo1[6]}");
#endif
Player.UpdateData(worldData, false);
if (SuccessCallback != null)
{
TestConnecting = false;
SuccessCallback?.Invoke(Client);
SuccessCallback = null;
Client.Server = TargetServer;
}
InternalSendPacket(new RequestTileData() { Position = new(Client.SpawnX, Client.SpawnY) });//请求物块数据
InternalSendPacket(new SpawnPlayer() { Position = new(Client.SpawnX, Client.SpawnY) });//请求物块数据
break;
Expand All @@ -121,6 +114,14 @@ public override bool GetPacket(Packet packet)
case StartPlaying:
Client.SendDataToClient(new SpawnPlayer() { PlayerSlot = Client.Index, Context = TrProtocol.Models.PlayerSpawnContext.RecallFromItem, Position = new(Client.SpawnX, (short)(Client.SpawnY - 3)), Timer = 0 });
ChangeProcessState(true); //转换处理模式为普通

if (SuccessCallback != null)
{
TestConnecting = false;
SuccessCallback?.Invoke(Client);
SuccessCallback = null;
Client.Server = TargetServer;
}
break;
default:
return base.GetPacket(packet);
Expand Down
7 changes: 5 additions & 2 deletions MultiSEngine/DataStruct/ClientData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ public override string ToString()
public void Dispose()
{
Disposed = true;
if (!Data.Clients.Remove(this))
Logs.Warn($"Abnormal remove of client data.");
lock (Data.Clients)
{
if (!Data.Clients.Remove(this))
Logs.Warn($"Abnormal remove of client data.");
}
State = ClientState.Disconnect;
SAdapter?.Stop(true);
CAdapter?.Stop(true);
Expand Down
4 changes: 2 additions & 2 deletions MultiSEngine/DataStruct/CustomData/CustomData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public virtual void RecievedData(ClientData client)
}
private class CustomDataSerializer : FieldSerializer<CustomData>
{
protected override CustomData _Read(BinaryReader br)
protected override CustomData ReadOverride(BinaryReader br)
{
var name = br.ReadString();
if (Core.DataBridge.CustomPackets.TryGetValue(name, out var type))
Expand All @@ -40,7 +40,7 @@ protected override CustomData _Read(BinaryReader br)
}
}

protected override void _Write(BinaryWriter bw, CustomData t)
protected override void WriteOverride(BinaryWriter bw, CustomData t)
{
bw.Write(t.Name);
bw.Write(t.Token);
Expand Down
2 changes: 1 addition & 1 deletion MultiSEngine/DataStruct/CustomData/ExcuteMSECommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override void InternalWrite(BinaryWriter writer)
}
public override void RecievedData(ClientData client)
{
if (ClientHelper.GetClientByName(PlayerName) is { } tempClient)
if (ClientManager.GetClientByName(PlayerName) is { } tempClient)
{
tempClient.HandleCommand($"/{Command}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace MultiSEngine.Modules
/// <summary>
/// 服务器切换
/// </summary>
public static partial class ClientHelper
public static partial class ClientManager
{
/// <summary>
/// 加入到指定的服务器
Expand Down Expand Up @@ -59,6 +59,8 @@ await client.TempAdapter.TryConnect(server, (client) =>
client.State = ClientData.ClientState.ReadyToSwitch;
if (ex is SocketException se && se.SocketErrorCode == SocketError.OperationAborted)
return;
client.TempAdapter?.Stop();
client.TempAdapter = null;
Logs.Error($"Unable to connect to server {server.IP}:{server.Port}{Environment.NewLine}{ex}");
client.SendErrorMessage(Localization.Instance["Prompt_CannotConnect", server.Name]);
}
Expand Down Expand Up @@ -123,7 +125,7 @@ public static void Disconnect(this ClientData client, string reason = null)
client.Dispose();
}
}
public static partial class ClientHelper
public static partial class ClientManager
{
#region 消息函数
public static bool SendDataToClient(this ClientData client, byte[] buffer, int start = 0, int? length = null)
Expand All @@ -140,9 +142,9 @@ public static bool SendDataToClient(this ClientData client, byte[] buffer, int s
#endif
return true;
}
using var arg = new SocketAsyncEventArgs();
arg.SetBuffer(buffer ?? new byte[3] { 3, 0, 0 }, start, length ?? buffer?.Length ?? 3);
client?.CAdapter?.Connection?.SendAsync(arg);
//using var arg = new SocketAsyncEventArgs();
//arg.SetBuffer(buffer ?? new byte[3] { 3, 0, 0 }, start, length ?? buffer?.Length ?? 3);
client?.CAdapter?.Connection?.Send(buffer ?? new byte[3] { 3, 0, 0 }, start, length ?? buffer?.Length ?? 3, SocketFlags.None);
return true;
}
catch (Exception ex)
Expand All @@ -160,9 +162,9 @@ public static void SendDataToServer(this ClientData client, byte[] buffer, int s
#if DEBUG
Console.WriteLine($"[Send to SERVER] <{BitConverter.ToInt16(buffer)} byte> {(MessageID)buffer[start + 2]}");
#endif
using var arg = new SocketAsyncEventArgs();
arg.SetBuffer(buffer ?? new byte[3] { 3, 0, 0 }, start, length ?? buffer?.Length ?? 3);
client.SAdapter?.Connection?.SendAsync(arg);
//using var arg = new SocketAsyncEventArgs();
//arg.SetBuffer(buffer ?? new byte[3] { 3, 0, 0 }, start, length ?? buffer?.Length ?? 3);
client.SAdapter?.Connection?.Send(buffer ?? new byte[3] { 3, 0, 0 }, start, length ?? buffer?.Length ?? 3, SocketFlags.None);
}
catch
{
Expand Down
2 changes: 1 addition & 1 deletion MultiSEngine/Modules/Cmds/ConsoleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public override bool Execute(ClientData client, string cmdName, string[] parma)
Logs.Error(string.Format(Localization.Get("Command_ServerNotFound"), parma[1]));
}
else
ClientHelper.Broadcast(null, $"[Broadcast] {parma.FirstOrDefault()}");
ClientManager.Broadcast(null, $"[Broadcast] {parma.FirstOrDefault()}");
Logs.Info($"Broadcast: {(parma.Length > 1 ? parma[1] : parma[0])}");
break;
case "t":
Expand Down
2 changes: 1 addition & 1 deletion MultiSEngine/Modules/Cmds/InternalCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public override bool Execute(ClientData client, string cmdName, string[] parma)
if (parma.Length < 3)
Console.Write("error /mse let name server");
else
Data.Clients.FirstOrDefault(c => c.Name.ToLower().StartsWith(parma[1].ToLower()))?.Join(Utils.GetServerInfoByName(parma[2]).FirstOrDefault());
Data.Clients.FirstOrDefault(c => c.Name.ToLower().StartsWith(parma[1].ToLower()))?.Join(Utils.GetSingleServerInfoByName(parma[2]));
break;
#endif
default:
Expand Down
5 changes: 3 additions & 2 deletions MultiSEngine/Modules/Data.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MultiSEngine.Core;
using MultiSEngine.DataStruct;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -10,8 +11,8 @@ namespace MultiSEngine.Modules
{
public static class Data
{
public static readonly List<ClientData> Clients = new();
public static readonly List<CmdBase> Commands = new();
public static List<ClientData> Clients { get; } = new();
public static List<CmdBase> Commands { get; } = new();
internal static byte[] StaticSpawnSquareData { get; set; }
private static string _motd = string.Empty;
public static string Motd => _motd
Expand Down
8 changes: 6 additions & 2 deletions MultiSEngine/MultiSEngine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<LangVersion>preview</LangVersion>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<AssemblyVersion>1.0.7.1</AssemblyVersion>
<FileVersion>1.0.7.1</FileVersion>
<AssemblyVersion>1.0.7.2</AssemblyVersion>
<FileVersion>1.0.7.2</FileVersion>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<AnalysisLevel>latest</AnalysisLevel>
<PublishSingleFile>true</PublishSingleFile>
Expand All @@ -21,6 +21,10 @@
<FileAlignment>512</FileAlignment>
</PropertyGroup>

<ItemGroup>
<None Remove="lib\TrProtocol.zip" />
</ItemGroup>

<ItemGroup>
<Reference Include="TrProtocol">
<HintPath>lib\TrProtocol.dll</HintPath>
Expand Down
Binary file modified MultiSEngine/lib/TrProtocol.dll
Binary file not shown.

0 comments on commit 029b292

Please sign in to comment.