/// <summary>
        /// The read.
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="packet">
        /// </param>
        public static void Read(Client client, byte[] packet)
        {
            byte[] senderId = BitConverter.GetBytes(client.Character.CharacterId);
            Array.Reverse(senderId);

            ChannelBase channel = client.ChatServer().GetChannel(packet);

            PacketReader reader = new PacketReader(ref packet);

            reader.ReadUInt16();
            reader.ReadUInt16();
            reader.ReadUInt16();
            reader.ReadUInt16();
            reader.ReadByte();
            string text        = reader.ReadString();
            string channelName = channel.ChannelName;

            // Check if it is a Chat Command (starting with a dot)
            if (!ProcessServerCommand(text, client))
            {
                byte[] newpacket = new byte[packet.Length + 4];

                Array.Copy(packet, 0, newpacket, 0, 9);
                Array.Copy(senderId, 0, newpacket, 9, 4);
                Array.Copy(packet, 9, newpacket, 13, packet.Length - 9);
                newpacket[2] = (byte)(packet.Length >> 8);
                newpacket[3] = (byte)packet.Length;

                foreach (Client recipient in client.ChatServer().ConnectedClients.Values)
                {
                    if (recipient.Channels.Contains(channel))
                    {
                        if (!recipient.KnownClients.Contains(client.Character.CharacterId) &&
                            (recipient.Character.CharacterId != client.Character.CharacterId))
                        {
                            byte[] pname = PlayerName.Create(client, client.Character.CharacterId);
                            recipient.Send(pname);
                            recipient.KnownClients.Add(client.Character.CharacterId);
                        }

                        recipient.Send(newpacket);
                    }
                }

                client.ChannelMessageReceived(channel, client.Character.characterName, text);
            }

            ChatLogger.WriteString(channelName, text, client.Character.characterName);
        }
Beispiel #2
0
        /// <summary>
        /// The read.
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="packet">
        /// </param>
        public static void Read(Client client, byte[] packet)
        {
            // TODO: Fix this mess.
            ushort data_length = BitConverter.ToUInt16(new[] { packet[3], packet[2] }, 0);

            byte[] sender_ID = BitConverter.GetBytes(client.Character.characterId);
            Array.Reverse(sender_ID);
            MemoryStream m_stream = new MemoryStream();

            m_stream.Write(packet, 0, 9);
            m_stream.Write(sender_ID, 0, 4);
            m_stream.Write(packet, 9, packet.Length - 9);
            m_stream.Capacity = (int)m_stream.Length;
            byte[] message    = m_stream.GetBuffer();
            byte[] new_length = BitConverter.GetBytes(message.Length - 4);
            message[2] = new_length[1];
            message[3] = new_length[0];
            m_stream.Close();
            m_stream.Dispose();

            foreach (Client m_client in client.Server.Clients)
            {
                if (!m_client.KnownClients.Contains(client.Character.characterId))
                {
                    byte[] pname = PlayerName.New(client, client.Character.characterId);
                    m_client.Send(pname);
                    m_client.KnownClients.Add(client.Character.characterId);
                }

                m_client.Send(message);
            }

            PacketReader reader = new PacketReader(ref packet);

            reader.ReadUInt16();
            reader.ReadUInt16();
            reader.ReadUInt16();
            reader.ReadUInt16();
            reader.ReadByte();
            string text        = reader.ReadString();
            string channelName = ChatChannels.GetChannel(packet).Name;

            ChatLogger.WriteString(channelName, text, client.Character.characterName);
        }