/// <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);
            }
        }
        /// <summary>
        /// Read and send back Player name lookup packet
        /// </summary>
        /// <param name="client">
        /// Client sending
        /// </param>
        /// <param name="packet">
        /// Packet data
        /// </param>
        public static void Read(Client client, byte[] packet)
        {
            PacketReader reader = new PacketReader(ref packet);

            reader.ReadUInt16(); // packet ID
            reader.ReadUInt16(); // data length
            uint playerId = uint.MaxValue;
            string playerName = reader.ReadString();
            if (playerName == string.Empty)
            {
                return;
            }

            if (playerName == ConfigReadWrite.Instance.CurrentConfig.RelayBotNick)
            {
                byte[] botlookup = NameLookupResult.Create(
                    0x80000000,
                    ConfigReadWrite.Instance.CurrentConfig.RelayBotNick);
                client.Send(botlookup);
                client.Send(BuddyOnlineStatus.Create(0x80000000, 1, new byte[] { 0x00, 0x01, 0x00 }));
                return;
            }

            client.Server.Debug(
                client,
                "{0} >> PlayerNameLookup: PlayerName: {1}",
                client.Character.characterName,
                playerName);
            reader.Finish();

            DBCharacter character = CharacterDao.GetByCharName(playerName);
            if (character != null)
            {
                playerId = (uint)character.Id;
            }

            byte[] namelookup = NameLookupResult.Create(playerId, playerName);
            client.Send(namelookup);
            client.Send(
                BuddyOnlineStatus.Create(
                    playerId,
                    (uint)OnlineDao.IsOnline((int)playerId).Online,
                    new byte[] { 0x00, 0x01, 0x00 }));
            client.KnownClients.Add(playerId);
        }
Beispiel #3
0
        /// <summary>
        /// Read and process Tell message
        /// </summary>
        /// <param name="client">
        /// Client sending
        /// </param>
        /// <param name="packet">
        /// Packet data
        /// </param>
        public static void Read(Client client, byte[] packet)
        {
            PacketReader reader = new PacketReader(ref packet);

            reader.ReadUInt16();
            reader.ReadUInt16();
            uint playerId = reader.ReadUInt32();
            string message = reader.ReadString();
            client.Server.Debug(client, "{0} >> Tell: PlayerId: {1}", client.Character.characterName, playerId);
            reader.Finish();
            if (client.ChatServer().ConnectedClients.ContainsKey(playerId))
            {
                Client tellClient = (Client)client.ChatServer().ConnectedClients[playerId];
                if (!tellClient.KnownClients.Contains(client.Character.CharacterId))
                {
                    byte[] pname = PlayerName.Create(client, client.Character.CharacterId);
                    tellClient.Send(pname);
                    tellClient.KnownClients.Add(client.Character.CharacterId);

                    // TODO: Check if status bytes are correct even for offline chars
                    client.Send(
                        BuddyOnlineStatus.Create(
                            (uint)tellClient.Character.CharacterId,
                            (uint)OnlineDao.IsOnline((int)tellClient.Character.CharacterId).Online,
                            new byte[] { 0x00, 0x01, 0x00 }));
                }

                byte[] pgroup = MsgPrivateGroup.Create(client.Character.CharacterId, message, string.Empty);
                tellClient.Send(pgroup);
            }
            else
            {
                byte[] sysmsg = MsgSystem.Create("Player not online.");
                client.Send(sysmsg);
            }
        }
        /// <summary>
        /// Read Login Character packet
        /// </summary>
        /// <param name="client">
        /// Client sending
        /// </param>
        /// <param name="packet">
        /// packet data
        /// </param>
        public static void Read(Client client, byte[] packet)
        {
            PacketReader reader = new PacketReader(ref packet);

            reader.ReadUInt16(); // Packet ID
            reader.ReadUInt16(); // Data length
            uint playerId = reader.ReadUInt32();
            client.Server.Debug(
                client,
                "{0} >> LoginCharacter: PlayerID: {1}",
                client.Character.characterName,
                playerId);
            reader.Finish();

            if (client.IsBot)
            {
                CharacterDao.Instance.SetOnline((int)playerId);
            }

            DBCharacter character = CharacterDao.Instance.Get((int)playerId);

            client.Character.CharacterId = playerId;
            client.Character.characterName = character.Name;
            client.Character.characterFirstName = character.FirstName;
            client.Character.characterLastName = character.LastName;

            client.ChatServer().AddClientToChannels(client);

            if (client.IsBot)
            {
                // 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);

                // TODO: Add Buddies List/BuddyOnlineStatus messages

                foreach (ChannelBase channel in client.Channels)
                {
                    byte[] channelJoin = ChannelJoin.Create(
                        channel.channelType,
                        channel.ChannelId,
                        channel.ChannelName,
                        channel.channelFlags,
                        new byte[] { 0x00, 0x00 });
                    client.Send(channelJoin);
                }

                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);
            }
        }
        /// <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);
        }