Compare commits

..

No commits in common. "c31ccc6d126475c5048d8f7b3ed329469abc2586" and "05de6788e19819095bd627d444bf674f4de0a54c" have entirely different histories.

5 changed files with 23 additions and 42 deletions

View File

@ -18,12 +18,12 @@ namespace PSO2SERVER.Protocol.Packets
public override byte[] Build() public override byte[] Build()
{ {
PacketWriter pkt = new PacketWriter(); PacketWriter writer = new PacketWriter();
pkt.Write(new byte[12]); writer.Write(new byte[12]);
pkt.WriteObjectHeader(src.Header); src.Header.WriteObjectHeaderToStream(writer);
pkt.WritePosition(dst); writer.WritePosition(dst);
pkt.Write(new byte[2]); writer.Write(new byte[2]);
return pkt.ToArray(); return writer.ToArray();
} }
public override PacketHeader GetHeader() public override PacketHeader GetHeader()

View File

@ -1,7 +1,11 @@
using PSO2SERVER.Models; using System;
using PSO2SERVER.Zone; using System.Collections.Generic;
using System; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using PSO2SERVER.Models;
using PSO2SERVER.Protocol.Handlers;
using PSO2SERVER.Zone;
namespace PSO2SERVER.Protocol.Packets namespace PSO2SERVER.Protocol.Packets
{ {

View File

@ -108,7 +108,7 @@ namespace PSO2SERVER.Protocol.Packets
pkt.Write(Unk11); pkt.Write(Unk11);
pkt.Write(GmFlag); pkt.Write(GmFlag);
pkt.WriteFixedLengthUtf16(_client._account.Nickname, 0x10); pkt.WriteFixedLengthUtf16(_client._account.Nickname, 0x10);
pkt.BaseStream.Seek(0x60 - (0x10 * 2), SeekOrigin.Current); pkt.BaseStream.Seek(0x60, SeekOrigin.Current);
pkt.Write(Unk12); pkt.Write(Unk12);
return pkt.ToArray(); return pkt.ToArray();

View File

@ -96,8 +96,6 @@ namespace PSO2SERVER.Protocol.Packets
// }; // };
//} //}
ch.EquipedItems = new PSO2Items[10];
EquippedItems.Add(ch.EquipedItems); EquippedItems.Add(ch.EquipedItems);
} }

View File

@ -1,10 +1,15 @@
using PSO2SERVER.Models; using System;
using PSO2SERVER.Protocol.Packets;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.Net.Sockets; 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 System.Threading.Tasks;
using PSO2SERVER.Protocol.Packets;
namespace PSO2SERVER namespace PSO2SERVER
{ {
@ -25,29 +30,9 @@ namespace PSO2SERVER
{ {
_mode = mode; _mode = mode;
_port = port; _port = port;
var queryTask = Task.Run(() => RunAsync()); var queryTask = Task.Run(() => RunAsync());
RunningServers.Add(queryTask); 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() private async Task RunAsync()
@ -70,12 +55,6 @@ namespace PSO2SERVER
{ {
Blocking = true Blocking = true
}; };
if (IsPortInUse(_port))
{
Logger.WriteError($"端口 {_port} 已被占用.");
}
var ep = new IPEndPoint(IPAddress.Any, _port); var ep = new IPEndPoint(IPAddress.Any, _port);
serverSocket.Bind(ep); // TODO: Custom bind address. serverSocket.Bind(ep); // TODO: Custom bind address.
serverSocket.Listen(5); serverSocket.Listen(5);