/// <summary>
        /// The read.
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="packet">
        /// </param>
        public static void Read(Client client, byte[] packet)
        {
            LogUtil.Debug(DebugInfoDetail.Network, "\r\nReceived:\r\n" + HexOutput.Output(packet));

            MemoryStream m_stream = new MemoryStream(packet);
            BinaryReader m_reader = new BinaryReader(m_stream);

            // now we should do password check and then send OK or Error
            // sending OK now
            m_stream.Position = 8;

            short userNameLength = IPAddress.NetworkToHostOrder(m_reader.ReadInt16());
            string userName = Encoding.ASCII.GetString(m_reader.ReadBytes(userNameLength));
            short loginKeyLength = IPAddress.NetworkToHostOrder(m_reader.ReadInt16());
            string loginKey = Encoding.ASCII.GetString(m_reader.ReadBytes(loginKeyLength));

            LoginEncryption loginEncryption = new LoginEncryption();

            if (loginEncryption.IsValidLogin(loginKey, client.ServerSalt, userName))
            {
                client.IsBot = true;
                byte[] chars = AccountCharacterList.Create(userName);
                LogUtil.Debug(DebugInfoDetail.Network, "\r\nReceived:\r\n" + HexOutput.Output(chars));

                client.Send(chars);
            }
            else
            {
                byte[] loginerr = LoginError.Create();
                client.Send(loginerr);
                client.Server.DisconnectClient(client);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="characterId">
        /// </param>
        /// <returns>
        /// </returns>
        public bool IsCharacterOnAccount(Client client, int characterId)
        {
            var le = new LoginEncryption();

            return le.IsCharacterOnAccount(client.AccountName, (UInt32)characterId);
        }
Exemplo n.º 3
0
        /// <summary>
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="loginKey">
        /// </param>
        /// <returns>
        /// </returns>
        public bool IsLoginCorrect(Client client, string loginKey)
        {
            var le = new LoginEncryption();

            this.lp.GetLoginPassword(client.AccountName);

            return le.IsValidLogin(loginKey, client.ServerSalt, client.AccountName, this.lp.PasswdL);
        }
Exemplo n.º 4
0
 /// <summary>
 /// </summary>
 /// <param name="obj">
 /// </param>
 private static void SetPassword(string[] obj)
 {
     string Syntax =
         "The syntax for this command is \"setpass <account username> <newpass>\" where newpass is alpha numeric no spaces";
     if (obj.Length != 3)
     {
         Colouring.Push(ConsoleColor.Red);
         Console.WriteLine(Syntax);
         Colouring.Pop();
     }
     else
     {
         string username = obj[1];
         string newpass = obj[2];
         var le = new LoginEncryption();
         string hashed = le.GeneratePasswordHash(newpass);
         int affected =
             LoginDataDao.WriteNewPassword(new DBLoginData() { Username = username, Password = hashed });
         if (affected == 0)
         {
             Colouring.Push(ConsoleColor.Red);
             Console.WriteLine("Could not set new password. Maybe username is wrong?");
             Colouring.Pop();
         }
         else
         {
             Colouring.Push(ConsoleColor.Green);
             Console.WriteLine("New password is set.");
             Colouring.Pop();
         }
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// </summary>
        /// <param name="obj">
        /// </param>
        private static void SetHash(string[] obj)
        {
            Colouring.Push(ConsoleColor.Red);

            if (obj.Length != 2)
            {
                Console.WriteLine("The Syntax for this command is \"hash <String to hash>\" alphanumeric no spaces");
                Colouring.Pop();
                return;
            }

            string pass = obj[1];
            var le = new LoginEncryption();
            string hashed = le.GeneratePasswordHash(pass);
            Colouring.Pop();
            Console.Write("The Hash for password '");
            Colouring.Push(ConsoleColor.Green);
            Console.Write(obj[1]);
            Colouring.Pop();
            Console.Write("' is '");
            Colouring.Push(ConsoleColor.Green);
            Console.Write(hashed);
            Colouring.Pop();
            Console.WriteLine("'");
        }
Exemplo n.º 6
0
        /// <summary>
        /// The read.
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="packet">
        /// </param>
        public static void Read(Client client, ref byte[] packet)
        {
            MemoryStream m_stream = new MemoryStream(packet);
            BinaryReader m_reader = new BinaryReader(m_stream);

            // now we should do password check and then send OK or Error
            // sending OK now
            m_stream.Position = 12;

            short userNameLength = IPAddress.NetworkToHostOrder(m_reader.ReadInt16());
            string userName = Encoding.ASCII.GetString(m_reader.ReadBytes(userNameLength));
            short loginKeyLength = IPAddress.NetworkToHostOrder(m_reader.ReadInt16());
            string loginKey = Encoding.ASCII.GetString(m_reader.ReadBytes(loginKeyLength));

            uint characterId = BitConverter.ToUInt32(new[] { packet[11], packet[10], packet[9], packet[8] }, 0);

            LoginEncryption loginEncryption = new LoginEncryption();

            if (loginEncryption.IsValidLogin(loginKey, client.ServerSalt, userName)
                && loginEncryption.IsCharacterOnAccount(userName, characterId))
            {
                byte[] loginok = LoginOk.Create();
                client.Send(loginok);
            }
            else
            {
                byte[] loginerr = LoginError.Create();
                client.Send(loginerr);
                client.Server.DisconnectClient(client);
                byte[] invalid = BitConverter.GetBytes(characterId);

                ZoneCom.SendMessage(99, invalid);
                return;
            }

            // save characters ID in client - note, this is usually 0 if it is a chat client connecting
            client.Character = new Character(characterId, client);

            // add client to connected clients list
            if (!client.ChatServer().ConnectedClients.ContainsKey(client.Character.CharacterId))
            {
                client.ChatServer().ConnectedClients.Add(client.Character.CharacterId, client);
            }

            // add yourself to that list
            client.KnownClients.Add(client.Character.CharacterId);

            // and give client its own name lookup
            byte[] pname = PlayerName.Create(client, client.Character.CharacterId);
            client.Send(pname);

            // send server welcome message to client
            byte[] anonv = MsgAnonymousVicinity.Create(
                string.Empty,
                string.Format(
                    client.ChatServer().MessageOfTheDay,
                    AssemblyInfoclass.RevisionName + " " + AssemblyInfoclass.AssemblyVersion),
                string.Empty);
            client.Send(anonv);

            client.ChatServer().AddClientToChannels(client);
        }