PSO2SERVER/Server/Packets/Handlers/11-ClientHandler/11-04-CharacterSelected.cs

67 lines
2.1 KiB
C#
Raw Normal View History

2024-09-10 01:13:20 +08:00
using PSO2SERVER.Database;
using PSO2SERVER.Packets.PSOPackets;
using PSO2SERVER.Party;
2024-09-12 15:06:07 +08:00
using System.Linq;
2024-09-10 00:31:40 +08:00
2024-09-10 01:13:20 +08:00
namespace PSO2SERVER.Packets.Handlers
2024-09-10 00:31:40 +08:00
{
2024-09-16 15:30:00 +08:00
[PacketHandlerAttr(0x11, 0x04)]
2024-09-19 11:48:56 +08:00
public class CharacterSelected : PacketHandler
2024-09-10 00:31:40 +08:00
{
2024-09-19 11:48:56 +08:00
public struct CharacterSelectedPacket
{
/// <summary>
/// Selected character ID.
/// </summary>
public uint CharId;
public uint Unk1;
public uint Unk2;
}
2024-09-10 00:31:40 +08:00
#region implemented abstract members of PacketHandler
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
{
2024-09-20 11:48:27 +08:00
if (context.User == null)
return;
2024-09-10 00:31:40 +08:00
var reader = new PacketReader(data, position, size);
2024-09-19 11:48:56 +08:00
var pkt = reader.ReadStruct<CharacterSelectedPacket>();
2024-09-10 00:31:40 +08:00
//Logger.Write("id {0}", charId);
2024-09-12 15:06:07 +08:00
2024-09-10 00:31:40 +08:00
if (context.Character == null) // On character create, this is already set.
{
2024-09-10 01:13:20 +08:00
using (var db = new ServerEf())
2024-09-10 00:31:40 +08:00
{
2024-09-20 11:48:27 +08:00
var character = db.Characters.Where(c => c.CharacterID == pkt.CharId).First();
2024-09-10 00:31:40 +08:00
if (character == null || character.Player.PlayerId != context.User.PlayerId)
2024-09-12 15:06:07 +08:00
{
Logger.WriteError("数据库中未找到 {0} 角色ID {1} ({2})"
, context.User.Username
, pkt.CharId
2024-09-12 15:06:07 +08:00
, context.User.PlayerId
);
context.Socket.Close();
2024-09-10 00:31:40 +08:00
return;
2024-09-12 15:06:07 +08:00
}
2024-09-10 00:31:40 +08:00
context.Character = character;
}
}
// 将客户端加入空余的队伍中
2024-09-10 00:31:40 +08:00
PartyManager.Instance.CreateNewParty(context);
// 告诉客户端切换到加载界面
context.SendPacket(new LoadingScreenTransitionPacket());
2024-09-10 00:31:40 +08:00
// TODO Set area, Set character, possibly more. See PolarisLegacy for more.
}
#endregion
}
}