Exemplo n.º 1
0
        public override void Send(Framework.Network.Packets.ServerPacket packet)
        {
            try
            {
                packet.Write();
                packet.Packet.Finish();

                if (packet.Packet.Header != null)
                    PacketLog.Write<ServerMessage>(packet.Packet.Header.Message, packet.Packet.Data, client.RemoteEndPoint);

                if (Crypt != null && Crypt.IsInitialized)
                    Encrypt(packet.Packet);

                var socketEventargs = new SocketAsyncEventArgs();

                socketEventargs.SetBuffer(packet.Packet.Data, 0, packet.Packet.Data.Length);

                socketEventargs.Completed += SendCompleted;
                socketEventargs.UserToken = packet;
                socketEventargs.RemoteEndPoint = client.RemoteEndPoint;
                socketEventargs.SocketFlags = SocketFlags.None;

                client.SendAsync(socketEventargs);
            }
            catch (SocketException ex)
            {
                Log.Message(LogType.Error, "{0}", ex.Message);

                client.Close();
            }
        }
Exemplo n.º 2
0
        public override async Task Send(Framework.Network.Packets.ServerPacket packet)
        {
            try
            {
                packet.Write();
                packet.Packet.Finish();

                if (packet.Packet.Header != null)
                {
                    if (packet.Packet.Header.Size > 0x100)
                    {
                        packet = await Compress(packet);
                    }

                    PacketLog.Write <ServerMessage>(packet.Packet.Header.Message, packet.Packet.Data, client.RemoteEndPoint);
                }

                if (Crypt != null && Crypt.IsInitialized)
                {
                    Encrypt(packet.Packet);
                }

                var socketEventargs = new SocketAsyncEventArgs();

                socketEventargs.SetBuffer(packet.Packet.Data, 0, packet.Packet.Data.Length);

                if (!client.Connected)
                {
                    return;
                }

                socketEventargs.Completed     += SendCompleted;
                socketEventargs.UserToken      = packet;
                socketEventargs.RemoteEndPoint = client.RemoteEndPoint;
                socketEventargs.SocketFlags    = SocketFlags.None;

                client.SendAsync(socketEventargs);
            }
            catch (Exception ex)
            {
                Dispose();

                ExceptionLog.Write(ex);

                Log.Error(ex.ToString());
            }
        }