private void DataFromServer(IAsyncResult iAr) { try { if (ServerS == null) { return; } int Length = ServerS.EndReceive(iAr); if (Length > 0) { byte[] Data = ByteUtils.CopyBlock(ServerB, 0, Length); try { byte[][] Chunks = new byte[][] { Data }; if (ServerDecrypt != null) { ServerDecrypt.Parse(Chunks[0]); } if (!ResponseEncrypted) { Chunks = ByteUtils.Split(ref ServerC, Data, HDestinations.Client, HProtocols.Modern); } if (ToClientS == 2) { ResponseEncrypted = (Chunks[0].Length - 4 != BigEndian.DecypherInt(Chunks[0])); } foreach (byte[] Chunk in Chunks) { ++ToClientS; if (DataToClient != null) { try { DataToClient(this, new DataToEventArgs(Chunk, HDestinations.Client, ToClientS)); } catch { } } } } catch { } ReadServerData(); } else { Disconnect(); } } catch { Disconnect(); } }
private void DataFromServer(IAsyncResult iAr) { try { if (_serverS == null) { return; } int length = _serverS.EndReceive(iAr); if (length < 1) { Disconnect(); return; } byte[] data = ByteUtils.CopyBlock(_serverB, 0, length); try { #region Decrypt/Split if (ServerDecrypt != null) { ServerDecrypt.Parse(data); } if (_toClientS == 2) { int dLength = Modern.DecypherInt(data); ResponseEncrypted = (dLength > data.Length - 4 || dLength < 6); } byte[][] chunks = ResponseEncrypted ? new[] { data } : ByteUtils.Split(ref _serverC, data, HDestination.Client, HProtocol.Modern); #endregion foreach (byte[] chunk in chunks) { if (Modern.DecypherShort(chunk, 4) == 4000) { Disconnect(); return; } ++_toClientS; if (DataToClient != null) { try { DataToClient(this, new DataToEventArgs(chunk, HDestination.Client, _toClientS)); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } } } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } ReadServerData(); } catch (Exception ex) { Disconnect(); Debug.WriteLine(ex.ToString()); } }
private void DataFromServer(IAsyncResult iAr) { try { if (_serverS == null) { return; } int length = _serverS.EndReceive(iAr); if (length < 1) { Disconnect(); return; } byte[] data = ByteUtils.CopyBlock(_serverB, 0, length); #region Official Socket Check if (!_hasOfficialSocket) { SendToClient(data); _htcpExt.BeginAcceptSocket(SocketAccepted, null); return; } #endregion #region Decrypt/Split if (ServerDecrypt != null) { ServerDecrypt.Parse(data); } if (_toClientS == 2 && Protocol == HProtocol.Modern) { int dLength = data.Length >= 6 ? Modern.DecypherInt(data) : 0; ResponseEncrypted = (dLength != data.Length - 4); } byte[][] chunks = ResponseEncrypted ? new[] { data } : ByteUtils.Split(ref _serverC, data, HDestination.Client, Protocol); #endregion foreach (byte[] chunk in chunks) { ProcessIncoming(chunk); } ReadServerData(); } catch { Disconnect(); } }
private void DataFromServer(IAsyncResult iAr) { try { if (ServerS == null) { return; } int Length = ServerS.EndReceive(iAr); if (Length > 0) { byte[] Data = ByteUtils.CopyBlock(ServerB, 0, Length); #region Official Socket Check if (!HasOfficialSocket) { SendToClient(Data); TCP.BeginAcceptSocket(SocketAccepted, null); return; } #endregion try { #region Decrypt/Split if (ServerDecrypt != null) { ServerDecrypt.Parse(Data); } if ((ToClientS + 1) == 3 && Protocol == HProtocols.Modern) { int DLength = BigEndian.DecypherInt(Data); ResponseEncrypted = (DLength > Data.Length - 4 || DLength < 6); } byte[][] Chunks = ResponseEncrypted ? new byte[1][] { Data } : ByteUtils.Split(ref CCache, Data, HDestinations.Client, Protocol); #endregion foreach (byte[] Chunk in Chunks) { ++ToClientS; if (DataToClient == null) { SendToClient(Chunk); } else { DataToEventArgs Args = new DataToEventArgs(Chunk, HDestinations.Client, ToClientS); try { DataToClient(this, Args); } catch { SendToClient(Chunk); continue; } if (!Args.Skip) { SendToClient(Args.Packet.ToBytes()); } } if (CaptureEvents && !ResponseEncrypted) { DataFromServer(Chunk); } } } catch { SendToClient(Data); } ReadServerData(); } else { Disconnect(); } } catch { Disconnect(); } }