namespace OubHackMS.Servers.Handlers
{
    using OubHackMS.Core;
    using OubHackMS.Logging;
    using OubHackMS.Servers;
    using OubHackMS.Users;
    using System;
    using System.IO;
    using System.Net.Sockets;

    internal class PacketRequestKeys : PacketHandler
    {
        private UserDB userdb;

        public PacketRequestKeys(OubHackMS parent) : base(parent)
        {
            base.sIndex = 7;
            this.userdb = (UserDB) base.parent.GetClass("UserDB");
        }

        public override void doWork(NetworkStream str)
        {
            BinaryReader reader = new BinaryReader(str);
            BinaryWriter writer = new BinaryWriter(str);
            User user = this.userdb.getBySessionID(reader.ReadInt64());
            if (user != null)
            {
                writer.Write(true);
                writer.Write(user.bKey.Length);
                writer.Write(user.bKey, 0, user.bKey.Length);
                writer.Write(user.bIV.Length);
                writer.Write(user.bIV, 0, user.bIV.Length);
                base.parent.Log(Level.USER_LOG_FILE, new object[] { user.sUsername, "Requested AES decryption/encryption keys" });
            }
            else
            {
                writer.Write(false);
            }
        }
    }
}

