// Copyright © 2017-2018 Atomic Software, LLC. All Rights Reserved.
// See LICENSE.md for full license information.

using Atom.Core.Diagnostics;
using Atom.Core.Extensions;
using Atom.Core.Networking;
using Atom.Core.Networking.Messages.Structures.User;
using Atom.WorldManagerServer.Services;

namespace Atom.WorldManagerServer.Logic
{
    internal static class AccountLogic
    {
        internal static void Login(Client client, string userName, string validateNew)
        {
            Log.Info($"{userName} is logging in");

            if (!TransferService.GetTransfers().ContainsKey(validateNew) || !TransferService.GetTransfers().Remove(validateNew) || userName.ToMD5() != validateNew || !AccountService.LoadAccount(client, userName))
            {
                return;
            }

            Log.Info($"{userName} logged in");
            new PROTO_NC_USER_LOGINWORLD_ACK(client).Send(client);
        }
    }
}
