暂存变动
This commit is contained in:
parent
d9d0314312
commit
501b0d9f8f
@ -59,13 +59,13 @@ namespace PSO2SERVER
|
||||
{
|
||||
if ((_readBufferSize + size) > _readBuffer.Length)
|
||||
{
|
||||
Logger.WriteError("[<--] 接收到 {0} 字节大于预设buf长度", size);
|
||||
Logger.WriteError("[接收] 接收到 {0} 字节大于预设buf长度", size);
|
||||
// Buffer overrun
|
||||
// TODO: Drop the connection when this occurs?
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.Write("[<--] 接收到 {0} 字节", size);
|
||||
Logger.Write("[接收] 接收到 {0} 字节", size);
|
||||
|
||||
Array.Copy(data, 0, _readBuffer, _readBufferSize, size);
|
||||
|
||||
@ -143,13 +143,13 @@ namespace PSO2SERVER
|
||||
sendName = $"{typeA:X}-{typeB:X}";
|
||||
}
|
||||
|
||||
Logger.Write($"[<--] 数据 {sendName} (Flags {(PacketFlags)flags1}) ({blob.Length} 字节)");
|
||||
LogPacket(false, typeA, typeB, flags1, flags2, blob);
|
||||
Logger.Write($"[接收] 数据 {sendName} (Flags {(PacketFlags)flags1}) ({blob.Length} 字节)");
|
||||
|
||||
if (Logger.VerbosePackets)
|
||||
{
|
||||
var info = string.Format("[<--] {0:X}-{1:X} 数据包:", typeA, typeB);
|
||||
var info = string.Format("[接收] {0:X}-{1:X} 数据包:", typeA, typeB);
|
||||
Logger.WriteHex(info, blob);
|
||||
LogPacket(false, typeA, typeB, flags1, flags2, blob);
|
||||
}
|
||||
|
||||
OutputArc4?.TransformBlock(blob, 0, blob.Length, blob, 0);
|
||||
@ -203,28 +203,28 @@ namespace PSO2SERVER
|
||||
{
|
||||
packetName = $"{typeA:X}-{typeB:X}";
|
||||
}
|
||||
Logger.Write($"[-->] 数据包 {packetName} (Flags {(PacketFlags)flags1}) ({size + 8} 字节)");
|
||||
Logger.Write($"[发送] 数据包 {packetName} (Flags {(PacketFlags)flags1}) ({size + 8} 字节)");
|
||||
var packet = new byte[size];
|
||||
Array.Copy(data, position, packet, 0, size);
|
||||
|
||||
if (Logger.VerbosePackets && size > 0) // TODO: This is trimming too far?
|
||||
{
|
||||
var dataTrimmed = new byte[size];
|
||||
for (var i = 0; i < size; i++)
|
||||
dataTrimmed[i] = data[i];
|
||||
|
||||
var info = string.Format("[-->] {0:X}-{1:X} 数据:", typeA, typeB);
|
||||
var info = string.Format("[发送] {0:X}-{1:X} 数据:", typeA, typeB);
|
||||
Logger.WriteHex(info, dataTrimmed);
|
||||
LogPacket(true, typeA, typeB, flags1, flags2, packet);
|
||||
}
|
||||
|
||||
var packet = new byte[size];
|
||||
Array.Copy(data, position, packet, 0, size);
|
||||
LogPacket(true, typeA, typeB, flags1, flags2, packet);
|
||||
|
||||
if (handler != null)
|
||||
|
||||
handler.HandlePacket(this, flags1, packet, 0, size);
|
||||
else
|
||||
{
|
||||
Logger.WriteWarning("[!!!] 未解析数据包 {0:X}-{1:X} - (Flags {2}) ({3} 字节)", typeA,
|
||||
typeB, (PacketFlags)flags1, size);
|
||||
LogUnkClientPacket(typeA, typeB, flags1, flags2, packet);
|
||||
}
|
||||
|
||||
// throw new NotImplementedException();
|
||||
@ -233,13 +233,22 @@ namespace PSO2SERVER
|
||||
private void LogPacket(bool fromClient, byte typeA, byte typeB, byte flags1, byte flags2, byte[] packet)
|
||||
{
|
||||
// Check for and create packets directory if it doesn't exist
|
||||
var packetPath = "packets/" + _server.StartTime.ToShortDateString().Replace('/', '-') + "-" +
|
||||
_server.StartTime.ToShortTimeString().Replace('/', '-').Replace(':', '-');
|
||||
var packetPath = string.Format(
|
||||
"packets/{0}-{1}/0x{2:X2} - 0x{3:X2}",
|
||||
_server.StartTime.ToShortDateString().Replace('/', '-'),
|
||||
_server.StartTime.ToShortTimeString().Replace(':', '-').Replace('/', '-'),
|
||||
typeA, typeB
|
||||
);
|
||||
|
||||
if (!Directory.Exists(packetPath))
|
||||
Directory.CreateDirectory(packetPath);
|
||||
|
||||
var filename = string.Format("{0}/{1}.{2:X}.{3:X}.{4}.bin", packetPath, _packetId++, typeA, typeB,
|
||||
fromClient ? "C" : "S");
|
||||
var filename = string.Format("{0}/0x{1:X2}-0x{2:X2}-{3}-{4}.bin"
|
||||
, packetPath
|
||||
, typeA, typeB
|
||||
, _packetId++
|
||||
, fromClient ? "C" : "S"
|
||||
);
|
||||
|
||||
using (var stream = File.OpenWrite(filename))
|
||||
{
|
||||
@ -253,5 +262,34 @@ namespace PSO2SERVER
|
||||
stream.Write(packet, 0, packet.Length);
|
||||
}
|
||||
}
|
||||
|
||||
private void LogUnkClientPacket(byte typeA, byte typeB, byte flags1, byte flags2, byte[] packet)
|
||||
{
|
||||
// Check for and create packets directory if it doesn't exist
|
||||
var packetPath = string.Format(
|
||||
"UnkClientPackets/{0}-{1}/0x{2:X2} - 0x{3:X2}",
|
||||
_server.StartTime.ToShortDateString().Replace('/', '-'),
|
||||
_server.StartTime.ToShortTimeString().Replace(':', '-').Replace('/', '-'),
|
||||
typeA, typeB
|
||||
);
|
||||
if (!Directory.Exists(packetPath))
|
||||
Directory.CreateDirectory(packetPath);
|
||||
|
||||
var filename = string.Format("{0}/0x{1:X2}-0x{2:X2}-{3}-{4}.bin"
|
||||
, packetPath
|
||||
, typeA, typeB
|
||||
, _packetId++
|
||||
, "C-unk"
|
||||
);
|
||||
|
||||
using (var stream = File.OpenWrite(filename))
|
||||
{
|
||||
stream.WriteByte(typeA);
|
||||
stream.WriteByte(typeB);
|
||||
stream.WriteByte(flags1);
|
||||
stream.WriteByte(flags2);
|
||||
stream.Write(packet, 0, packet.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ namespace PSO2SERVER
|
||||
public class Config
|
||||
{
|
||||
private readonly string _configFile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) +
|
||||
Path.DirectorySeparatorChar + "Server.cfg";
|
||||
Path.DirectorySeparatorChar + "config\\Server.cfg";
|
||||
|
||||
// Settings
|
||||
[ConfigComment("服务器对外绑定的地址(支持域名或者IP,优先获取IPV4)")]
|
||||
@ -89,7 +89,7 @@ namespace PSO2SERVER
|
||||
// Check length
|
||||
if (split.Length != 2)
|
||||
{
|
||||
Logger.WriteWarning("[CFG] 发现分割大小不正确的配置行");
|
||||
Logger.WriteWarning("[设置] 发现分割大小不正确的配置行");
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ namespace PSO2SERVER
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.WriteException("[CFG] 设置文件载入错误", ex);
|
||||
Logger.WriteException("[设置] 设置文件载入错误", ex);
|
||||
}
|
||||
|
||||
// Display all settings
|
||||
@ -109,7 +109,7 @@ namespace PSO2SERVER
|
||||
// Some settings require manual refreshing
|
||||
SettingsChanged();
|
||||
|
||||
Logger.WriteInternal("[CFG] 设置文件载入完成");
|
||||
Logger.WriteInternal("[设置] 设置文件载入完成");
|
||||
}
|
||||
|
||||
private void DisplaySettings()
|
||||
@ -118,7 +118,7 @@ namespace PSO2SERVER
|
||||
foreach (var field in fields)
|
||||
{
|
||||
var value = field.GetValue(this);
|
||||
Logger.WriteInternal($"[CFG] 设置项 {field.Name} = {value}");
|
||||
Logger.WriteInternal($"[设置] 设置项 {field.Name} = {value}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,7 +140,7 @@ namespace PSO2SERVER
|
||||
}
|
||||
|
||||
if (!silent)
|
||||
Logger.WriteInternal("[CFG] 设置已保存");
|
||||
Logger.WriteInternal("[设置] 设置已保存");
|
||||
}
|
||||
|
||||
public void SettingsChanged()
|
||||
|
@ -19,7 +19,7 @@ namespace PSO2SERVER.Packets.Handlers
|
||||
return;
|
||||
|
||||
var reader = new PacketReader(data, position, size);
|
||||
//var info = string.Format("[<--] 接收到的数据 (hex): ");
|
||||
//var info = string.Format("[接收] 接收到的数据 (hex): ");
|
||||
//Logger.WriteHex(info, data);
|
||||
|
||||
reader.ReadBytes(12); // 12 unknown bytes
|
||||
|
@ -12,7 +12,7 @@ namespace PSO2SERVER.Packets.Handlers
|
||||
{
|
||||
if (context.Character == null)
|
||||
return;
|
||||
var info = string.Format("[<--] 接收到的数据 (hex): ");
|
||||
var info = string.Format("[接收] 接收到的数据 (hex): ");
|
||||
Logger.WriteHex(info, data);
|
||||
|
||||
var reader = new PacketReader(data, position, size);
|
||||
|
@ -26,7 +26,7 @@ namespace PSO2SERVER.Packets.Handlers
|
||||
Array.Reverse(cryptedBlob);
|
||||
|
||||
// Print the contents of cryptedBlob in hexadecimal format
|
||||
//var info = string.Format("[<--] 接收到的数据 (hex): ");
|
||||
//var info = string.Format("[接收] 接收到的数据 (hex): ");
|
||||
//Logger.WriteHex(info, cryptedBlob);
|
||||
|
||||
//// Convert cryptedBlob to a hexadecimal string
|
||||
|
@ -16,7 +16,7 @@ namespace PSO2SERVER.Packets.Handlers
|
||||
{
|
||||
var reader = new PacketReader(data, position, size);
|
||||
|
||||
//var info = string.Format("[<--] 接收到的数据 (hex): ");
|
||||
//var info = string.Format("[接收] 接收到的数据 (hex): ");
|
||||
//Logger.WriteHex(info, data);
|
||||
|
||||
reader.BaseStream.Seek(0x2C, SeekOrigin.Current);
|
||||
|
@ -40,8 +40,11 @@ namespace PSO2SERVER.Packets.Handlers
|
||||
if (attrs.Length > 0)
|
||||
{
|
||||
var attr = (PacketHandlerAttr) attrs[0];
|
||||
Logger.WriteInternal("[PKT] 载入数据包处理 {0} 数据包 {1:X}-{2:X}.", t.Name, attr.Type,
|
||||
attr.Subtype);
|
||||
Logger.WriteInternal("[数据] 数据包 0x{0:X2} - 0x{1:X2} {2} 处理已载入 ."
|
||||
, attr.Type
|
||||
, attr.Subtype
|
||||
, t.Name
|
||||
);
|
||||
if (!Handlers.ContainsKey(Helper.PacketTypeToUShort(attr.Type, attr.Subtype)))
|
||||
Handlers.Add(Helper.PacketTypeToUShort(attr.Type, attr.Subtype),
|
||||
(PacketHandler) Activator.CreateInstance(t));
|
||||
|
@ -31,7 +31,7 @@ namespace PSO2SERVER
|
||||
_port = port;
|
||||
var queryTask = Task.Run(() => RunAsync());
|
||||
RunningServers.Add(queryTask);
|
||||
Logger.WriteInternal("[QSP] 开始监听" + desc + "端口 " + port);
|
||||
Logger.WriteInternal("[监听] 开始监听" + desc + "端口 " + port);
|
||||
}
|
||||
|
||||
private async Task RunAsync()
|
||||
|
Loading…
Reference in New Issue
Block a user