Exemplo n.º 1
0
        /// <summary>
        /// Sends a packet to the chat server.
        /// </summary>
        /// <param name="type">The type of packet to send.</param>
        /// <param name="data">The packet data (Not the packet header).</param>
        private void SendPacket(ChatServerPacketType type, byte[] data)
        {
            ChatServerPacket packet;

            packet.Magic  = 0xff;
            packet.Length = (ushort)(data.Length + 4);
            packet.Id     = type;
            packet.Data   = data;

            if (settings.ShowPackets)
            {
                LogDebug("C -> S: " + packet);
            }
            if (settings.ShowPacketData)
            {
                LogDebug(Util.GetPacketDump(packet.GetBytes(), false));
            }

            byte[] packetBytes = packet.GetBytes();
            try
            {
                client.GetStream().Write(packetBytes, 0, packetBytes.Length);
            }
            catch (Exception ex)
            {
                if (!IsDisconnecting)
                {
                    Fail(FailureArgs.FailureTypes.FailedToSend, "Failed to send packet to chat server: " + ex.Message);
                    Disconnect();
                }
                return;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sends a packet to the chat server.
        /// </summary>
        /// <param name="type">The type of packet to send.</param>
        /// <param name="data">The packet data (Not the packet header).</param>
        private void SendPacket(ChatServerPacketType type, byte[] data)
        {
            ChatServerPacket packet;

            packet.Magic = 0xff;
            packet.Length = (ushort)(data.Length + 4);
            packet.Id = type;
            packet.Data = data;

            if (settings.ShowPackets)
            {
                LogDebug("C -> S: " + packet);
            }
            if (settings.ShowPacketData)
            {
                LogDebug(Util.GetPacketDump(packet.GetBytes(), false));
            }

            byte[] packetBytes = packet.GetBytes();
            try
            {
                client.GetStream().Write(packetBytes, 0, packetBytes.Length);
            }
            catch (Exception ex)
            {
                if (!IsDisconnecting)
                {
                    Fail(FailureArgs.FailureTypes.FailedToSend, "Failed to send packet to chat server: " + ex.Message);
                    Disconnect();
                }
                return;
            }
        }