Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }