private void ProcessIncoming(byte[] data) { ++_toClientS; if (!IsIncomingEncrypted) { Task.Factory.StartNew(() => Triggers.ProcessIncoming(data), TaskCreationOptions.LongRunning); } if (DataToClient == null) { SendToClient(data); } else { var e = new DataToEventArgs(data, HDestination.Client, _toClientS, Filters); try { OnDataToClient(e); } catch { e.Cancel = true; } finally { if (e.Cancel) { SendToClient(e.Packet.ToBytes()); } else if (!e.IsBlocked) { SendToClient(e.Replacement.ToBytes()); } } } }
public override void ProcessIncoming(byte[] data) { ++_toClientS; if (!ResponseEncrypted) { Task.Factory.StartNew(() => base.ProcessIncoming(data), TaskCreationOptions.LongRunning) .ContinueWith(OnException, TaskContinuationOptions.OnlyOnFaulted); } if (DataToClient == null) { SendToClient(data); } else { var e = new DataToEventArgs(data, HDestination.Client, _toClientS); try { OnDataToClient(e); } catch { e.Cancel = true; SendToClient(data); } finally { if (!e.Cancel) { SendToClient(e.Packet.ToBytes()); } } } }
protected virtual void OnDataToServer(DataToEventArgs e) { EventHandler <DataToEventArgs> handler = DataToServer; if (handler != null) { handler(this, e); } }
private void ProcessOutgoing(byte[] data) { ++_toServerS; if (!IsOutgoingEncrypted) { Task.Factory.StartNew(() => Triggers.ProcessOutgoing(data), TaskCreationOptions.LongRunning); } if (DataToServer == null) { SendToServer(data); } else { var e = new DataToEventArgs(data, HDestination.Server, _toServerS, Filters); try { OnDataToServer(e); } catch { e.Cancel = true; } finally { if (e.Cancel) { SendToServer(data = e.Packet.ToBytes()); } else if (!e.IsBlocked) { SendToServer(data = e.Replacement.ToBytes()); } } } if (_grabHeaders) { switch (_toServerS) { case 2: Outgoing.Global.InitiateHandshake = BigEndian.DecypherShort(data, 4); break; case 3: Outgoing.Global.ClientPublicKey = BigEndian.DecypherShort(data, 4); break; case 4: Outgoing.Global.FlashClientUrl = BigEndian.DecypherShort(data, 4); break; case 6: Outgoing.Global.ClientSsoTicket = BigEndian.DecypherShort(data, 4); break; case 7: _grabHeaders = false; break; } } }
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(); } }
private void DataFromClient(IAsyncResult iAr) { try { if (ClientS == null) { return; } int Length = ClientS.EndReceive(iAr); if (Length > 0) { byte[] Data = ByteUtils.CopyBlock(ClientB, 0, Length); #region Official Socket Check if (!HasOfficialSocket) { bool IsModern = false; if (HasOfficialSocket = (Ancient.DecypherShort(Data, 3) == 206 || (IsModern = BigEndian.DecypherShort(Data, 4) == 4000))) { TCP.Stop(); TCP = null; ResetHost(); Protocol = IsModern ? HProtocols.Modern : HProtocols.Ancient; if (OnConnected != null) { OnConnected(this, EventArgs.Empty); } } else { SendToServer(Data); return; } } #endregion try { #region Decrypt/Split if (ClientDecrypt != null) { ClientDecrypt.Parse(Data); } if ((ToServerS + 1) == 4 && Protocol == HProtocols.Modern) { int DLength = BigEndian.DecypherInt(Data); RequestEncrypted = (DLength > Data.Length - 4 || DLength < 6); } byte[][] Chunks = RequestEncrypted ? new byte[1][] { Data } : Chunks = ByteUtils.Split(ref SCache, Data, HDestinations.Server, Protocol); #endregion foreach (byte[] Chunk in Chunks) { ++ToServerS; if (DataToServer == null) { SendToServer(Chunk); } else { DataToEventArgs Args = new DataToEventArgs(Chunk, HDestinations.Server, ToServerS); try { DataToServer(this, Args); } catch { SendToServer(Chunk); continue; } if (!Args.Skip) { SendToServer(Args.Packet.ToBytes()); } } if (CaptureEvents && !RequestEncrypted) { DataFromClient(Chunk); } } } catch { SendToServer(Data); } ReadClientData(); } else { Disconnect(); } } catch { Disconnect(); } }