2024-09-10 01:13:20 +08:00
|
|
|
|
using PSO2SERVER.Database;
|
2024-11-27 18:05:53 +08:00
|
|
|
|
using PSO2SERVER.Protocol.Packets;
|
2024-09-10 01:13:20 +08:00
|
|
|
|
using PSO2SERVER.Party;
|
2024-09-20 16:10:43 +08:00
|
|
|
|
using System;
|
2024-09-12 15:06:07 +08:00
|
|
|
|
using System.Linq;
|
2024-09-10 00:31:40 +08:00
|
|
|
|
|
2024-11-27 18:05:53 +08:00
|
|
|
|
namespace PSO2SERVER.Protocol.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
|
2024-09-17 22:47:58 +08:00
|
|
|
|
{
|
|
|
|
|
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 21:58:37 +08:00
|
|
|
|
if (context._account == null)
|
2024-09-20 11:48:27 +08:00
|
|
|
|
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
|
|
|
|
|
2024-09-20 16:10:43 +08:00
|
|
|
|
var charId = pkt.CharId;
|
|
|
|
|
|
2024-11-27 18:05:53 +08:00
|
|
|
|
//Logger.Write("id {0}", charId);
|
2024-09-12 15:06:07 +08:00
|
|
|
|
|
2024-11-25 09:25:21 +08:00
|
|
|
|
if (context.Character == null)
|
2024-09-10 00:31:40 +08:00
|
|
|
|
{
|
2024-09-10 01:13:20 +08:00
|
|
|
|
using (var db = new ServerEf())
|
2024-09-10 00:31:40 +08:00
|
|
|
|
{
|
2024-09-20 16:10:43 +08:00
|
|
|
|
try
|
2024-09-12 15:06:07 +08:00
|
|
|
|
{
|
2024-11-25 23:33:41 +08:00
|
|
|
|
var character = db.Characters.FirstOrDefault(c => c.CharacterID == charId && c.AccountID == context._account.AccountId);
|
2024-09-20 16:10:43 +08:00
|
|
|
|
|
2024-12-11 19:54:48 +08:00
|
|
|
|
if (character == null)
|
2024-09-20 16:10:43 +08:00
|
|
|
|
{
|
|
|
|
|
Logger.WriteError("数据库中未找到 {0} 角色ID {1} ({2})"
|
2024-09-20 21:58:37 +08:00
|
|
|
|
, context._account.Username
|
2024-09-20 16:10:43 +08:00
|
|
|
|
, charId
|
2024-09-20 21:58:37 +08:00
|
|
|
|
, context._account.AccountId
|
2024-09-12 15:06:07 +08:00
|
|
|
|
);
|
2024-09-20 16:10:43 +08:00
|
|
|
|
context.Socket.Close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.Character = character;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.WriteError("查询角色时发生异常: {0}", ex.Message);
|
2024-09-12 15:06:07 +08:00
|
|
|
|
context.Socket.Close();
|
|
|
|
|
}
|
2024-09-10 00:31:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-16 15:40:15 +08:00
|
|
|
|
// 将客户端加入空余的队伍中
|
2024-09-10 00:31:40 +08:00
|
|
|
|
PartyManager.Instance.CreateNewParty(context);
|
|
|
|
|
|
2024-09-16 15:40:15 +08:00
|
|
|
|
// 告诉客户端切换到加载界面
|
|
|
|
|
context.SendPacket(new LoadingScreenTransitionPacket());
|
2024-09-10 00:31:40 +08:00
|
|
|
|
|
|
|
|
|
// TODO Set area, Set character, possibly more. See PolarisLegacy for more.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|