コード例 #1
0
ファイル: WebConnection.cs プロジェクト: emhm/jabboserver
        internal void Received(IAsyncResult Result)
        {
            if (!IsAlive || Result == null || Sock == null || !Sock.Connected)
            {
                return;
            }

            int ResultCount = 0;

            try
            {
                ResultCount = Sock.EndReceive(Result);
            }
            catch
            {
                Dispose();
                return;
            }

            if (ResultCount > 0)
            {
                byte[] Bytes = ByteUtil.ChompBytes(Buffer, 0, ResultCount);
                InvokeBytes(ref Bytes);
            }
            else
            {
                Dispose();
                return;
            }

            Receive();
        }
コード例 #2
0
 private void DataReceived(IAsyncResult iAr)
 {
     if (!this.mDisposed)
     {
         try
         {
             int numBytes = 0;
             try
             {
                 numBytes = base.EndReceive(iAr);
             }
             catch
             {
                 this.ConnectionDead();
                 return;
             }
             if (numBytes > 0)
             {
                 byte[] data = ByteUtil.ChompBytes(this.mDataBuffer, 0, numBytes);
                 this.RouteData(ref data);
             }
             else
             {
                 this.ConnectionDead();
                 return;
             }
             this.WaitForData();
         }
         catch
         {
             this.ConnectionDead();
         }
     }
 }
コード例 #3
0
ファイル: Connection.cs プロジェクト: Ravoit/Neptunium
        private void DataReceived(object sender, SocketAsyncEventArgs socketAsyncEventArgs)
        {
            try
            {
                if (!_socket.Connected)
                {
                    return;
                }

                var numReceivedBytes = socketAsyncEventArgs.BytesTransferred;

                if (numReceivedBytes > 0)
                {
                    var bytes = ByteUtil.ChompBytes(socketAsyncEventArgs.Buffer, 0, numReceivedBytes);

                    var data = Encoding.UTF8.GetString(bytes);

                    data = _serverType switch
                    {
                        ServerEnum.Chat => CompressionUtil.DecompressChat(data),
                        ServerEnum.Game => CompressionUtil.DecompressGame(data),
                        _ => data
                    };

                    _receivedMessage += data;

                    if (_receivedMessage.Contains((char)0x00))
                    {
                        var messages = _receivedMessage.Split((char)0x00);

                        foreach (var message in messages)
                        {
                            if (message.Length == 0)
                            {
                                continue;
                            }

                            var packet = new XmlRead("<root>" + message + "</root>");

                            foreach (var incoming in packet.Children)
                            {
                                var packetType =
                                    Neptunium.PacketManager.GetPacketHandler(incoming.XmlName, _serverType);

                                if (packetType == null)
                                {
                                    Log.Debug("[{0}] [{1}] [{2}] [{3}] [{4}] {@attributes} {@child}", "IN", _serverType,
                                              Bot?.Login,
                                              Bot?.Login, incoming.XmlName,
                                              incoming.Attributes,
                                              incoming.Children);
                                    continue;
                                }

                                try
                                {
                                    Log.Verbose("[{0}] [{1}] [{2}] [{3}] [{4}] {@attributes} {@child}", "IN",
                                                _serverType,
                                                Bot?.Login,
                                                Bot?.Login, incoming.XmlName,
                                                incoming.Attributes,
                                                incoming.Children);
                                    var packetIn = (PacketIn)Activator.CreateInstance(packetType);
                                    packetIn.Read(this, incoming);
                                    packetIn.Handle();
                                }
                                catch (Exception ex)
                                {
                                    Log.Error(ex, "Packet Error");
                                }
                            }
                        }

                        _receivedMessage = messages[^ 1];