Compare commits

...

2 Commits

Author SHA1 Message Date
c31ccc6d12 Merge branch 'master' of http://sanc.top:3000/Sancaros/PSO2SERVER 2024-12-19 01:21:02 +08:00
f4d6e88141 暂存 2024-12-19 01:21:00 +08:00
5 changed files with 42 additions and 23 deletions

View File

@ -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()

View File

@ -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
{

View File

@ -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();

View File

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

View File

@ -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);