More core work

This commit is contained in:
Aidan C. Brady 2013-10-13 23:27:49 -04:00
parent 34f1053354
commit fbedc1915f
2 changed files with 101 additions and 0 deletions

View file

@ -1,8 +1,18 @@
package mekanism.client;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.TargetDataLine;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.NetLoginHandler;
import net.minecraft.network.packet.NetHandler;
@ -14,6 +24,19 @@ import cpw.mods.fml.common.network.Player;
public class VoiceClientManager implements IConnectionHandler
{
public Socket socket;
public AudioFormat format = new AudioFormat(11025.0F, 8, 1, true, true);
public DataLine.Info microphone = new DataLine.Info(TargetDataLine.class, this.format, 2200);
public DataLine.Info speaker = new DataLine.Info(SourceDataLine.class, this.format, 2200);
public TargetDataLine targetLine;
public SourceDataLine sourceLine;
public DataInputStream input;
public DataOutputStream output;
public boolean running;
@Override
public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager)
@ -35,6 +58,7 @@ public class VoiceClientManager implements IConnectionHandler
//connecting to foreign server
try {
socket = new Socket(server, 36123);
running = true;
} catch(Exception e) {}
}
@ -44,6 +68,7 @@ public class VoiceClientManager implements IConnectionHandler
//connecting to LAN server on same instance
try {
socket = new Socket(InetAddress.getLocalHost().getHostAddress(), 36123);
running = true;
} catch(Exception e) {}
}
@ -51,8 +76,22 @@ public class VoiceClientManager implements IConnectionHandler
public void connectionClosed(INetworkManager manager)
{
try {
sourceLine.flush();
sourceLine.close();
targetLine.flush();
targetLine.close();
output.flush();
output.close();
output = null;
input.close();
input = null;
socket.close();
socket = null;
running = false;
} catch(Exception e) {}
}
@ -61,4 +100,40 @@ public class VoiceClientManager implements IConnectionHandler
{
}
public void init()
{
try {
input = new DataInputStream(new BufferedInputStream(socket.getInputStream()));
output = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
//Speaker (Out)
new Thread(new Runnable()
{
@Override
public void run()
{
try {
VoiceClientManager.this.sourceLine = ((SourceDataLine)AudioSystem.getLine(VoiceClientManager.this.speaker));
VoiceClientManager.this.sourceLine.open(VoiceClientManager.this.format, 2200);
VoiceClientManager.this.sourceLine.start();
} catch(Exception e) {}
}
}).start();
//Microphone (In)
new Thread(new Runnable()
{
@Override
public void run()
{
try {
VoiceClientManager.this.targetLine = ((TargetDataLine)AudioSystem.getLine(microphone));
VoiceClientManager.this.targetLine.open(VoiceClientManager.this.format, 2200);
VoiceClientManager.this.targetLine.start();
} catch(Exception e) {}
}
}).start();
} catch(Exception e) {}
}
}

View file

@ -1,13 +1,39 @@
package mekanism.common;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.Socket;
public class VoiceConnection
{
public Socket socket;
public DataInputStream input;
public DataOutputStream output;
public VoiceConnection(Socket s)
{
socket = s;
}
public void start()
{
try {
input = new DataInputStream(new BufferedInputStream(socket.getInputStream()));
output = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
new Thread(new Runnable()
{
@Override
public void run()
{
try {
} catch(Exception e) {}
}
}).start();
} catch(Exception e) {}
}
}