// Received from the client. private void ClientOnDataReceivedEvent(object sender, DataReceivedEventArgs dataReceivedEventArgs) { _destinationConnectDone.WaitOne(); if (dataReceivedEventArgs.Bytes.Length == 23 && dataReceivedEventArgs.Data.StartsWith("<policy")) { _policyConnection = true; Server.Send(dataReceivedEventArgs.Bytes); Console.WriteLine($"[{_connectionId}][Connection#ClientOnDataReceivedEvent]: This is a policy connection."); } else { var packets = _packetProcessor.ProcessClientBytes(dataReceivedEventArgs.Bytes); foreach (ClientPacket packet in packets) { _manager.FrmMain.WindowPacketLogger.AddPacket(PacketType.CLIENT, PacketType.SERVER, packet.Header, packet.Length, packet.Packet); Console.WriteLine($"[{_connectionId}][Connection#ClientOnDataReceivedEvent][{packet.Header}][{packet.Length}]: {packet.Packet}"); Server.Send(packet.Bytes); } } Client.Receive(); }
// Received from server. private void ServerOnDataReceivedEvent(object sender, DataReceivedEventArgs dataReceivedEventArgs) { if (_policyConnection) { Client.Send(dataReceivedEventArgs.Bytes); } else { var packets = _packetProcessor.ProcessServerBytes(dataReceivedEventArgs.Bytes); foreach (ServerPacket packet in packets) { _manager.FrmMain.WindowPacketLogger.AddPacket(PacketType.SERVER, PacketType.CLIENT, packet.Header, packet.Length, packet.Packet); Console.WriteLine($"[{_connectionId}][Connection#ServerOnDataReceivedEvent][{packet.Header}][{packet.Length}]: {packet.Packet}"); Client.Send(packet.Bytes); } } Server.Receive(); }