using Fiesta.Game.Networking.PacketTypes;
using Fiesta.Networking.Packets;
using Fiesta.Players;
using Fiesta.Players.Networking;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Villain.Networking.Packets;
using World.Players.Networking.Packets.User.Out;

namespace World.Players.Networking.Packets.User.In
{
	public static class WorldTransfer
	{
		[PacketHandler("Player", USER.LOGINWORLD_REQ)]
		public static void Handle(PlayerConnection client, InPacket packet)
		{
			string username = packet.ReadString(256);
			string guid = packet.ReadString(32);

			packet.Skip(32);
			
			PlayerGUID playerGUID = PlayerManager.GrabPlayerGUID(guid);

			if (playerGUID != null)
			{
				client.Account = new Account(playerGUID.UserID);

				using (WorldInfo worldInfo = new WorldInfo())
				{
					client.Send(worldInfo);
				}
			}
			else
			{
				using (WorldTransferError worldTransferError = new WorldTransferError())
				{
					client.Send(worldTransferError);
				}
			}
		}
	}
}