更新部分数据包

This commit is contained in:
Longfeng Qin 2024-11-24 23:40:50 +08:00
parent 17a264516a
commit 3e74d13348
14 changed files with 276 additions and 30 deletions

View File

@ -391,7 +391,7 @@ namespace PSO2SERVER
Commands.Add(tellLoc);
// Exit
var exit = new ConsoleCommand(Exit, "exit", "quit") { Help = "Close the PSO2 Server" };
var exit = new ConsoleCommand(Exit, "exit", "quit") { Help = "关闭PSO2服务器" };
Commands.Add(exit);
}

View File

@ -9,6 +9,17 @@ namespace PSO2SERVER.Models
{
public class Character
{
[StructLayout(LayoutKind.Sequential)]
public unsafe struct CharParam
{
public int character_id;
public int player_id;
public uint unk1;
public uint voice_type;
public ushort unk2;
public short voice_pitch;
}
public enum ClassType : byte
{
Unknown = 0xFF,
@ -69,17 +80,6 @@ namespace PSO2SERVER.Models
Luster = 1 << 14
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct CharParam
{
public int character_id;
public int player_id;
public uint unk1;
public uint voice_type;
public ushort unk2;
public short voice_pitch;
}
[StructLayout(LayoutKind.Sequential)]
public struct JobEntry
{

View File

@ -138,7 +138,7 @@ namespace PSO2SERVER.Packets.Handlers
db.SaveChanges();
//context.SendPacket(0x11, 0x1e, 0x0, new byte[0x44]); // Request nickname
context.SendPacket(new NicknameRequestPacket(0)); // Request nickname
context.SendPacket(new NicknameRequestPacket()); // Request nickname
}
}
else

View File

@ -17,8 +17,6 @@ namespace PSO2SERVER.Packets.Handlers
if (context._account == null)
return;
var reader = new PacketReader(data, position, size);
var info = string.Format("[<--] 接收到的数据 (hex): {0} 字节", data.Length);
Logger.WriteHex(info, data);

View File

@ -0,0 +1,22 @@
using System;
using PSO2SERVER.Models;
using PSO2SERVER.Packets.PSOPackets;
namespace PSO2SERVER.Packets.Handlers
{
[PacketHandlerAttr(0x11, 0x97)]
class CharacterRenameRequestPacket : PacketHandler
{
public uint player_id { get; set; }
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
{
var info = string.Format("[<--] 接收到的数据 (hex): {0} 字节", data.Length);
Logger.WriteHex(info, data);
if (context._account == null)
return;
context.SendPacket(new CharacterRenamePacket());
}
}
}

View File

@ -0,0 +1,54 @@
using System;
using PSO2SERVER.Database;
using System.Data.Entity;
using PSO2SERVER.Models;
using PSO2SERVER.Packets.PSOPackets;
using static PSO2SERVER.Packets.PSOPackets.CharacterNewNamePacket;
using System.Linq;
namespace PSO2SERVER.Packets.Handlers
{
[PacketHandlerAttr(0x11, 0x9B)]
class CharacterNewNameRequestPacket : PacketHandler
{
public uint player_id { get; set; }
public string Name { get; set; }
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
{
var info = string.Format("[<--] 接收到的数据 (hex): {0} 字节", data.Length);
Logger.WriteHex(info, data);
if (context._account == null)
return;
var reader = new PacketReader(data, position, size);
player_id = reader.ReadUInt32();
Name = reader.ReadFixedLengthUtf16(16);
NewNameStatus isdone = NewNameStatus.Failure;
// 修改数据库字段
using (var db = new ServerEf())
{
// 先检测角色是否存在
var existingCharacters = db.Characters.Where(c => c.Account.AccountId == context._account.AccountId).ToList();
if (existingCharacters.Count > 0)
{
// 更新角色名字字段
var character = existingCharacters.FirstOrDefault();
if (character != null)
{
// 确保名字不为空并且是16字节长度
character.Name = Name; // 用0填充至16字节
db.SaveChanges(); // 保存修改
isdone = NewNameStatus.Success;
}
}
}
context.SendPacket(new CharacterNewNamePacket(isdone, player_id, Name));
}
}
}

View File

@ -0,0 +1,22 @@
using System;
using PSO2SERVER.Models;
using PSO2SERVER.Packets.PSOPackets;
namespace PSO2SERVER.Packets.Handlers
{
[PacketHandlerAttr(0x11, 0xBC)]
class CharacterShipTransferCanceldRequest : PacketHandler
{
public uint player_id { get; set; }
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
{
var info = string.Format("[<--] 接收到的数据 (hex): {0} 字节", data.Length);
Logger.WriteHex(info, data);
var reader = new PacketReader(data, position, size);
player_id = reader.ReadUInt32();
context.SendPacket(new CharacterMoveComfirmPacket());// TODO 不对的 只是给个反应
}
}
}

View File

@ -0,0 +1,28 @@
using System;
using PSO2SERVER.Models;
namespace PSO2SERVER.Packets.PSOPackets
{
public class LoadEquipedPacket : Packet
{
public Int64 NewAmount = 0;
#region implemented abstract members of Packet
public override byte[] Build()
{
var writer = new PacketWriter();
writer.Write(NewAmount);
return writer.ToArray();
}
public override PacketHeader GetHeader()
{
return new PacketHeader(0x0F, 0x0C, PacketFlags.PACKED);
}
#endregion
}
}

View File

@ -20,12 +20,7 @@ namespace PSO2SERVER.Packets.PSOPackets
public override PacketHeader GetHeader()
{
return new PacketHeader
{
Type = 0x0F,
Subtype = 0x14,
Flags1 = 0
};
return new PacketHeader(0x0F, 0x14, PacketFlags.None);
}
#endregion

View File

@ -42,12 +42,12 @@ namespace PSO2SERVER.Packets.PSOPackets
{
var chars = db.Characters
.Where(w => w.Account.AccountId == _PlayerId)
.OrderBy(o => o.Character_ID) // TODO: Order by last played
.OrderBy(o => o.Character_ID) // TODO: 按照最后游玩的角色排序
.Select(s => s);
writer.Write((uint)chars.Count()); // Number of characters
writer.Write((uint)chars.Count()); // 写入玩家数量
for (var i = 0; i < 0x4; i++) // Whatever this is
for (var i = 0; i < 0x4; i++) // 可能是账户ID
writer.Write((byte)0);
foreach (var ch in chars)
@ -55,19 +55,40 @@ namespace PSO2SERVER.Packets.PSOPackets
writer.Write((uint)ch.Character_ID);
writer.Write((uint)_PlayerId);
for (var i = 0; i < 0x10; i++)
writer.Write((byte)0);
//for (var i = 0; i < 0x10; i++)
// writer.Write((byte)0);
writer.Write(ch.Unk1);
writer.Write(ch.Voice_Type);
writer.Write(ch.Unk2);
writer.Write(ch.Voice_Pitch);
writer.Write((uint)0);
writer.WriteFixedLengthUtf16(ch.Name, 16);
//Logger.WriteInternal("[CHR] 新增名为 {0} 的新角色.", ch.Name);
writer.Write((uint)0);
writer.Write((uint)0); // 修改这个值 可能会触发角色不可用或变为联动角色
writer.WriteStruct(ch.Looks); // Note: Pre-Episode 4 created looks doesn't seem to work anymore
writer.WriteStruct(ch.Jobs);
for (var i = 0; i < 0x94; i++)
writer.Write((byte)0);
writer.Write((byte)0); //TODO:解析这个是什么
}
//for (var i = 0; i < 60; i++)
// writer.Write((byte)0);
//for (var i = 0; i < 30; i++)
// writer.Write((uint)1);
//for (var i = 0; i < 240; i++)
// writer.Write((byte)0);
//for (var i = 0; i < 240; i++)
// writer.Write((byte)0);
////writer.Write((ushort)0);
//writer.Write((uint)0);
//writer.Write((uint)0);
}
return writer.ToArray();

View File

@ -8,9 +8,60 @@ namespace PSO2SERVER.Packets.PSOPackets
{
public class CharacterRenamePacket : Packet
{
public enum RenameRequestStatus : uint
{
/// <summary>
/// Renaming allowed.
/// </summary>
Allowed = 0,
/// <summary>
/// Renaming permit needed.
/// </summary>
PermitNeeded = 1,
/// <summary>
/// Renaming privileges suspended.
/// </summary>
PrivilegesSuspended = 2,
/// <summary>
/// System error has occurred.
/// </summary>
SystemError = 3,
/// <summary>
/// Renaming cooldown hasn't yet expired.
/// </summary>
TooEarly = 4
}
/// <summary>
/// Renaming availability status.
/// </summary>
public RenameRequestStatus Status { get; set; }
/// <summary>
/// AC price for a rename pass.
/// </summary>
public uint AcPrice { get; set; }
/// <summary>
/// Rename cooldown expiry timestamp.
/// </summary>
public uint CooldownExpires { get; set; }
/// <summary>
/// Seconds until the rename cooldown expires.
/// </summary>
public uint CooldownSecs { get; set; }
public CharacterRenamePacket()
{
Status = RenameRequestStatus.Allowed;
AcPrice = 0;
CooldownExpires = 0;
CooldownSecs = 0;
}
#region implemented abstract members of Packet
@ -18,6 +69,10 @@ namespace PSO2SERVER.Packets.PSOPackets
public override byte[] Build()
{
var pkt = new PacketWriter();
pkt.Write((uint)Status);
pkt.Write(AcPrice);
pkt.Write(CooldownExpires);
pkt.Write(CooldownSecs);
return pkt.ToArray();
}

View File

@ -8,9 +8,21 @@ namespace PSO2SERVER.Packets.PSOPackets
{
public class CharacterNewNamePacket : Packet
{
public CharacterNewNamePacket()
public enum NewNameStatus : uint
{
Success = 0,
Failure = 1
}
public NewNameStatus status { get; set; }
public uint player_id { get; set; }
public string Name { get; set; }
public CharacterNewNamePacket(NewNameStatus Status, uint Player_id, string Newname)
{
status = Status;
player_id = Player_id;
Name = Newname;
}
#region implemented abstract members of Packet
@ -18,6 +30,9 @@ namespace PSO2SERVER.Packets.PSOPackets
public override byte[] Build()
{
var pkt = new PacketWriter();
pkt.Write((uint)status);
pkt.Write(player_id);
pkt.WriteFixedLengthUtf16(Name, 16);
return pkt.ToArray();
}

View File

@ -0,0 +1,31 @@
using PSO2SERVER.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PSO2SERVER.Packets.PSOPackets
{
public class CharacterMoveComfirmPacket : Packet
{
public CharacterMoveComfirmPacket()
{
}
#region implemented abstract members of Packet
public override byte[] Build()
{
var pkt = new PacketWriter();
return pkt.ToArray();
}
public override PacketHeader GetHeader()
{
return new PacketHeader(0x11, 0xBD, PacketFlags.None);
}
#endregion
}
}

View File

@ -198,6 +198,9 @@
<Compile Include="Packets\Handlers\0E-PartyHandler\0E-29-PlayerIsNotBusyState.cs" />
<Compile Include="Packets\Handlers\0E-PartyHandler\0E-28-PlayerIsBusyState.cs" />
<Compile Include="Packets\Handlers\0E-PartyHandler\0E-19-ChatStatusHandler.cs" />
<Compile Include="Packets\Handlers\11-ClientHandler\11-9B-CharacterNewNameRequestPacket.cs" />
<Compile Include="Packets\Handlers\11-ClientHandler\11-97-CharacterRenameRequest.cs" />
<Compile Include="Packets\Handlers\11-ClientHandler\11-BC-CharacterShipTransferCanceldRequest.cs" />
<Compile Include="Packets\Handlers\11-ClientHandler\11-B8-CharacterShipTransferRightsRequest.cs" />
<Compile Include="Packets\Handlers\11-ClientHandler\11-06-DeleteCharacter.cs" />
<Compile Include="Packets\Handlers\11-ClientHandler\11-0D-ClientPingHandler.cs" />
@ -221,6 +224,8 @@
<Compile Include="Packets\Handlers\4A-ARKSMisionsHandler\4A-00-MissionListRequest.cs" />
<Compile Include="Packets\Handlers\4D-ClassicMissionPassHandler\4D-02-MissionPassRequest.cs" />
<Compile Include="Packets\Handlers\4D-ClassicMissionPassHandler\4D-00-MissionPassInfoRequest.cs" />
<Compile Include="Packets\PSOPackets\0F-ItemPacket\0F-0C-LoadEquipedPacket.cs" />
<Compile Include="Packets\PSOPackets\11-ClientPacket\11-BD-CharacterMoveComfirmPacket.cs" />
<Compile Include="Packets\PSOPackets\4A-ARKSMissionPacket\4A-03-Unk4A03Packet.cs" />
<Compile Include="Packets\PSOPackets\4A-ARKSMissionPacket\4A-01-ARKSMissionListPacket.cs" />
<Compile Include="Packets\PSOPackets\07-ChatPacket\07-00-ChatPacket.cs" />