暂存开发

This commit is contained in:
Sancaros 2024-10-26 11:44:15 +08:00
parent b01661365a
commit 34afd58cf5
3 changed files with 112 additions and 89 deletions

View File

@ -239,29 +239,43 @@ namespace PSO2SERVER
private void LogPacket(bool fromClient, byte typeA, byte typeB, byte flags1, byte flags2, byte[] packet)
{
// 记录数据包
LogPacketInternal("packets", fromClient, typeA, typeB, flags1, flags2, packet);
}
private void LogUnkClientPacket(byte typeA, byte typeB, byte flags1, byte flags2, byte[] packet)
{
// 记录未知数据包
LogPacketInternal("UnkClientPackets", true, typeA, typeB, flags1, flags2, packet, "C-unk");
}
private void LogPacketInternal(string directory, bool fromClient, byte typeA, byte typeB, byte flags1, byte flags2, byte[] packet, string customPrefix = "")
{
// 生成格式化日期和时间
var datePart = _server.StartTime.ToString("yyyy-MM-dd");
var timePart = _server.StartTime.ToString("HH-mm-ss");
// Check for and create packets directory if it doesn't exist
var packetPath = string.Format(
"packets/0x{0:X2}-0x{1:X2}/{2}"
, typeA, typeB
, _server.StartTime.ToShortDateString().Replace('/', '-')
);
var packetPath = Path.Combine(directory, $"0x{typeA:X2}-0x{typeB:X2}", datePart);
// 创建目录
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++
, fromClient ? "C" : "S"
, _server.StartTime.ToShortTimeString().Replace('/', '-').Replace(':', '-')
);
// 构造文件名
var prefix = string.IsNullOrEmpty(customPrefix) ? (fromClient ? "客户端" : "服务端") : customPrefix;
// 确保文件名不包含不允许的字符
var safePrefix = string.Join("_", prefix.Split(Path.GetInvalidFileNameChars()));
var filename = Path.Combine(packetPath, $"0x{typeA:X2}-0x{typeB:X2}-此处加入字节显示-{safePrefix}-{timePart}.bin");
try
{
using (var stream = new FileStream(filename, FileMode.Append, FileAccess.Write, FileShare.None))
{
if (fromClient)
if (fromClient || !string.IsNullOrEmpty(customPrefix))
{
stream.Write(new byte[] { typeA, typeB, flags1, flags2 }, 0, 4);
}
@ -273,39 +287,5 @@ namespace PSO2SERVER
Console.WriteLine($"记录数据包时出错: {ex.Message}");
}
}
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/0x{0:X2}-0x{1:X2}/{2}"
, typeA, typeB
, _server.StartTime.ToShortDateString().Replace('/', '-')
);
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"
, _server.StartTime.ToShortTimeString().Replace('/', '-').Replace(':', '-')
);
try
{
using (var stream = new FileStream(filename, FileMode.Append, FileAccess.Write, FileShare.None))
{
stream.Write(new byte[] { typeA, typeB, flags1, flags2 }, 0, 4);
stream.Write(packet, 0, packet.Length);
}
}
catch (Exception ex)
{
Console.WriteLine($"记录未知数据包时出错: {ex.Message}");
}
}
}
}

View File

@ -1,7 +1,11 @@
using PSO2SERVER.Packets.PSOPackets;
using Org.BouncyCastle.Bcpg;
using Org.BouncyCastle.Utilities.Encoders;
using PSO2SERVER.Models;
using PSO2SERVER.Packets.PSOPackets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
@ -12,19 +16,53 @@ namespace PSO2SERVER.Packets.Handlers
{
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
{
QuestDifficultyPacket.QuestDifficulty[] diffs = new QuestDifficultyPacket.QuestDifficulty[1];
for (int i = 0; i < diffs.Length; i++)
{
diffs[i].dateOrSomething = "2017/2/20";
diffs[i].quest_obj.ID = 496;
diffs[i].something2 = 0x0B;
diffs[i].questNameString = 30010;
var reader = new PacketReader(data, position, size);
// These are likely bitfields
diffs[i].something3 = 0x00030301;
}
var info = string.Format("[<--] 接收到的数据 (hex): {0}字节", data.Length);
Logger.WriteHex(info, data);
//[< --] 接收到的数据(hex): 16字节
//00000000 7F A3 00 00 20 00 00 00 00 00 00 00 0B 00 00 00 £......... ...
//[-->] 0x0B - 0x1C(NoPayloadPacket)(Flags None)(8 字节)
//[< --] 0x0B - 0x19(QuestDifficultyRequestHandler)(Flags PACKED)(24 字节)
//[< --] 接收到的数据(hex): 16字节
//00000000 7F A3 00 00 20 00 00 00 00 00 00 00 0B 00 00 00 £......... ...
//[-->] 0x0B - 0x1C(NoPayloadPacket)(Flags None)(8 字节)
//[< --] 0x0B - 0x19(QuestDifficultyRequestHandler)(Flags PACKED)(24 字节)
//[< --] 接收到的数据(hex): 16字节
//00000000 7F A3 00 00 20 00 00 00 00 00 00 00 0B 00 00 00 £......... ...
//[-->] 0x0B - 0x1C(NoPayloadPacket)(Flags None)(8 字节)
//[< --] 0x0B - 0x19(QuestDifficultyRequestHandler)(Flags PACKED)(24 字节)
//[< --] 接收到的数据(hex): 16字节
//00000000 7F A3 00 00 20 00 00 00 00 00 00 00 0B 00 00 00 £......... ...
//[-->] 0x0B - 0x1C(NoPayloadPacket)(Flags None)(8 字节)
//[< --] 0x0B - 0x19(QuestDifficultyRequestHandler)(Flags PACKED)(24 字节)
//[< --] 接收到的数据(hex): 16字节
//00000000 7F A3 00 00 20 00 00 00 00 00 00 00 0B 00 00 00 £......... ...
//[-->] 0x0B - 0x1C(NoPayloadPacket)(Flags None)(8 字节)
//[< --] 0x0B - 0x19(QuestDifficultyRequestHandler)(Flags PACKED)(24 字节)
//[< --] 接收到的数据(hex): 16字节
//00000000 7F A3 00 00 20 00 00 00 00 00 00 00 0B 00 00 00 £......... ...
//[-->] 0x0B - 0x1C(NoPayloadPacket)(Flags None)(8 字节)
//[< --] 0x0B - 0x19(QuestDifficultyRequestHandler)(Flags PACKED)(24 字节)
//[< --] 接收到的数据(hex): 16字节
//00000000 7F A3 00 00 20 00 00 00 00 00 00 00 0B 00 00 00 £......... ...
//[-->] 0x0B - 0x1C(NoPayloadPacket)(Flags None)(8 字节)
//[< --] 0x0B - 0x19(QuestDifficultyRequestHandler)(Flags PACKED)(24 字节)
context.SendPacket(new QuestDifficultyPacket(diffs));
//QuestDifficultyPacket.QuestDifficulty[] diffs = new QuestDifficultyPacket.QuestDifficulty[1];
//for (int i = 0; i < diffs.Length; i++)
//{
// diffs[i].dateOrSomething = "2017/2/20";
// diffs[i].quest_obj.ID = 496;
// diffs[i].quest_obj.padding = 0;
// diffs[i].something2 = 0x0B;
// diffs[i].questNameString = 30010;
// // These are likely bitfields
// diffs[i].something3 = 0x00030301;
//}
//context.SendPacket(new QuestDifficultyPacket(diffs));
// [K873] I believe this is the correct packet, but it causes an infinite send/recieve loop, we're probably just missing something else
context.SendPacket(new NoPayloadPacket(0x0B, 0x1C));

View File

@ -10,39 +10,44 @@ namespace PSO2SERVER.Packets.Handlers
// Go go maximum code duplication (for now)
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
{
QuestDefiniton def = new QuestDefiniton
{
dateOrSomething = "2024/09/21",
needsToBeNonzero = 0x00000020,
getsSetToWord = 0x0000000B,
questNameString = 30010,
playTime = (byte)QuestListPacket.EstimatedTime.Short,
partyType = (byte)QuestListPacket.PartyType.SinglePartyQuest,
difficulties = (byte)QuestListPacket.Difficulties.Normal | (byte)QuestListPacket.Difficulties.hard | (byte)QuestListPacket.Difficulties.VeryHard | (byte)QuestListPacket.Difficulties.SuperHard,
requiredLevel = 1,
// Not sure why but these need to be set for the quest to be enabled
field_FF = 0xF1,
field_101 = 1
};
var reader = new PacketReader(data, position, size);
QuestDifficultyPacket.QuestDifficulty diff = new QuestDifficultyPacket.QuestDifficulty
{
dateOrSomething = "2024/09/21",
something = 0x20,
something2 = 0x0B,
questNameString = 30010,
var info = string.Format("[<--] 接收到的数据 (hex): {0}字节", data.Length);
Logger.WriteHex(info, data);
// These are likely bitfields
something3 = 0x00030301
};
//QuestDefiniton def = new QuestDefiniton
//{
// dateOrSomething = "2024/09/21",
// needsToBeNonzero = 0x00000020,
// getsSetToWord = 0x0000000B,
// questNameString = 30010,
// playTime = (byte)QuestListPacket.EstimatedTime.Short,
// partyType = (byte)QuestListPacket.PartyType.SinglePartyQuest,
// difficulties = (byte)QuestListPacket.Difficulties.Normal | (byte)QuestListPacket.Difficulties.hard | (byte)QuestListPacket.Difficulties.VeryHard | (byte)QuestListPacket.Difficulties.SuperHard,
// requiredLevel = 1,
// // Not sure why but these need to be set for the quest to be enabled
// field_FF = 0xF1,
// field_101 = 1
//};
var quest = new Quest("arks_010120")
{
questDef = def
};
context.currentParty.currentQuest = quest;
context.SendPacket(new SetQuestInfoPacket(def, context._account.AccountId));
context.SendPacket(new QuestStartPacket(def, diff));
//QuestDifficultyPacket.QuestDifficulty diff = new QuestDifficultyPacket.QuestDifficulty
//{
// dateOrSomething = "2024/09/21",
// something = 0x20,
// something2 = 0x0B,
// questNameString = 30010,
// // These are likely bitfields
// something3 = 0x00030301
//};
//var quest = new Quest("arks_010120")
//{
// questDef = def
//};
//context.currentParty.currentQuest = quest;
//context.SendPacket(new SetQuestInfoPacket(def, context._account.AccountId));
//context.SendPacket(new QuestStartPacket(def, diff));
}
}