diff --git a/Server/Protocol/Packets/04-ObjectRelatedPacket/04-02-TeleportTransferPacket.cs b/Server/Protocol/Packets/04-ObjectRelatedPacket/04-02-TeleportTransferPacket.cs index 3febf46..78c901d 100644 --- a/Server/Protocol/Packets/04-ObjectRelatedPacket/04-02-TeleportTransferPacket.cs +++ b/Server/Protocol/Packets/04-ObjectRelatedPacket/04-02-TeleportTransferPacket.cs @@ -18,12 +18,12 @@ namespace PSO2SERVER.Protocol.Packets public override byte[] Build() { - PacketWriter writer = new PacketWriter(); - writer.Write(new byte[12]); - src.Header.WriteObjectHeaderToStream(writer); - writer.WritePosition(dst); - writer.Write(new byte[2]); - return writer.ToArray(); + PacketWriter pkt = new PacketWriter(); + pkt.Write(new byte[12]); + pkt.WriteObjectHeader(src.Header); + pkt.WritePosition(dst); + pkt.Write(new byte[2]); + return pkt.ToArray(); } public override PacketHeader GetHeader() diff --git a/Server/Protocol/Packets/04-ObjectRelatedPacket/04-07-MovementPacket.cs b/Server/Protocol/Packets/04-ObjectRelatedPacket/04-07-MovementPacket.cs index 3509f85..465c344 100644 --- a/Server/Protocol/Packets/04-ObjectRelatedPacket/04-07-MovementPacket.cs +++ b/Server/Protocol/Packets/04-ObjectRelatedPacket/04-07-MovementPacket.cs @@ -1,11 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using PSO2SERVER.Models; -using PSO2SERVER.Protocol.Handlers; +using PSO2SERVER.Models; using PSO2SERVER.Zone; +using System; +using System.Runtime.InteropServices; namespace PSO2SERVER.Protocol.Packets { diff --git a/Server/Protocol/Packets/08-SpawnPacket/08-04-CharacterSpawnPacket.cs b/Server/Protocol/Packets/08-SpawnPacket/08-04-CharacterSpawnPacket.cs index 560988e..ee7b191 100644 --- a/Server/Protocol/Packets/08-SpawnPacket/08-04-CharacterSpawnPacket.cs +++ b/Server/Protocol/Packets/08-SpawnPacket/08-04-CharacterSpawnPacket.cs @@ -108,7 +108,7 @@ namespace PSO2SERVER.Protocol.Packets pkt.Write(Unk11); pkt.Write(GmFlag); pkt.WriteFixedLengthUtf16(_client._account.Nickname, 0x10); - pkt.BaseStream.Seek(0x60, SeekOrigin.Current); + pkt.BaseStream.Seek(0x60 - (0x10 * 2), SeekOrigin.Current); pkt.Write(Unk12); return pkt.ToArray(); diff --git a/Server/Protocol/Packets/11-ClientPacket/11-03-CharacterListPacket.cs b/Server/Protocol/Packets/11-ClientPacket/11-03-CharacterListPacket.cs index 2b76b63..81a6d33 100644 --- a/Server/Protocol/Packets/11-ClientPacket/11-03-CharacterListPacket.cs +++ b/Server/Protocol/Packets/11-ClientPacket/11-03-CharacterListPacket.cs @@ -96,6 +96,8 @@ namespace PSO2SERVER.Protocol.Packets // }; //} + ch.EquipedItems = new PSO2Items[10]; + EquippedItems.Add(ch.EquipedItems); } diff --git a/Server/QueryServer.cs b/Server/QueryServer.cs index c3f276a..e79b9fb 100644 --- a/Server/QueryServer.cs +++ b/Server/QueryServer.cs @@ -1,15 +1,10 @@ -using System; +using PSO2SERVER.Models; +using PSO2SERVER.Protocol.Packets; +using System; using System.Collections.Generic; using System.Net; using System.Net.Sockets; -using System.IO; -using System.Runtime.InteropServices; -using System.Threading; - -using PSO2SERVER.Models; -using PSO2SERVER.Protocol; using System.Threading.Tasks; -using PSO2SERVER.Protocol.Packets; namespace PSO2SERVER { @@ -30,9 +25,29 @@ namespace PSO2SERVER { _mode = mode; _port = port; + var queryTask = Task.Run(() => RunAsync()); RunningServers.Add(queryTask); - //Logger.WriteInternal("[监听] 监听" + desc + "端口 " + port); + Logger.WriteInternal("[监听] 监听" + desc + "端口 " + port); + } + + private bool IsPortInUse(int port) + { + try + { + // 创建一个 TcpListener 实例 + TcpListener listener = new TcpListener(IPAddress.Any, port); + + // 尝试启动监听 + listener.Start(); + listener.Stop(); + + return false; // 如果没有异常,说明端口没有被占用 + } + catch (SocketException) + { + return true; // 捕获异常,说明端口已被占用 + } } private async Task RunAsync() @@ -55,6 +70,12 @@ namespace PSO2SERVER { Blocking = true }; + + if (IsPortInUse(_port)) + { + Logger.WriteError($"端口 {_port} 已被占用."); + } + var ep = new IPEndPoint(IPAddress.Any, _port); serverSocket.Bind(ep); // TODO: Custom bind address. serverSocket.Listen(5);