PSO2SERVER/Server/Packets/Handlers/11-04-StartGame.cs

57 lines
1.8 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-10 00:31:40 +08:00
public class StartGame : PacketHandler
{
#region implemented abstract members of PacketHandler
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
{
var reader = new PacketReader(data, position, size);
var charId = reader.ReadUInt32();
//Logger.Write("id {0}", charId);
2024-09-12 15:06:07 +08:00
2024-09-10 00:31:40 +08:00
if (context.User == null)
return;
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-12 15:06:07 +08:00
var character = db.Characters.Where(c => c.CharacterId == 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
, charId
, 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;
}
}
// Initialize you in an empty party
PartyManager.Instance.CreateNewParty(context);
// Transition to the loading screen
2024-09-16 15:30:00 +08:00
context.SendPacket(new NoPayloadPacket(0x03, 0x04));
2024-09-10 00:31:40 +08:00
// TODO Set area, Set character, possibly more. See PolarisLegacy for more.
}
#endregion
}
}