Compare commits
2 Commits
05de6788e1
...
c31ccc6d12
Author | SHA1 | Date | |
---|---|---|---|
c31ccc6d12 | |||
f4d6e88141 |
@ -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()
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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();
|
||||
|
@ -96,6 +96,8 @@ namespace PSO2SERVER.Protocol.Packets
|
||||
// };
|
||||
//}
|
||||
|
||||
ch.EquipedItems = new PSO2Items[10];
|
||||
|
||||
EquippedItems.Add(ch.EquipedItems);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user