More core work
This commit is contained in:
parent
34f1053354
commit
fbedc1915f
2 changed files with 101 additions and 0 deletions
|
@ -1,8 +1,18 @@
|
||||||
package mekanism.client;
|
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.InetAddress;
|
||||||
import java.net.Socket;
|
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.INetworkManager;
|
||||||
import net.minecraft.network.NetLoginHandler;
|
import net.minecraft.network.NetLoginHandler;
|
||||||
import net.minecraft.network.packet.NetHandler;
|
import net.minecraft.network.packet.NetHandler;
|
||||||
|
@ -14,6 +24,19 @@ import cpw.mods.fml.common.network.Player;
|
||||||
public class VoiceClientManager implements IConnectionHandler
|
public class VoiceClientManager implements IConnectionHandler
|
||||||
{
|
{
|
||||||
public Socket socket;
|
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
|
@Override
|
||||||
public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager)
|
public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager)
|
||||||
|
@ -35,6 +58,7 @@ public class VoiceClientManager implements IConnectionHandler
|
||||||
//connecting to foreign server
|
//connecting to foreign server
|
||||||
try {
|
try {
|
||||||
socket = new Socket(server, 36123);
|
socket = new Socket(server, 36123);
|
||||||
|
running = true;
|
||||||
} catch(Exception e) {}
|
} catch(Exception e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +68,7 @@ public class VoiceClientManager implements IConnectionHandler
|
||||||
//connecting to LAN server on same instance
|
//connecting to LAN server on same instance
|
||||||
try {
|
try {
|
||||||
socket = new Socket(InetAddress.getLocalHost().getHostAddress(), 36123);
|
socket = new Socket(InetAddress.getLocalHost().getHostAddress(), 36123);
|
||||||
|
running = true;
|
||||||
} catch(Exception e) {}
|
} catch(Exception e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,8 +76,22 @@ public class VoiceClientManager implements IConnectionHandler
|
||||||
public void connectionClosed(INetworkManager manager)
|
public void connectionClosed(INetworkManager manager)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
sourceLine.flush();
|
||||||
|
sourceLine.close();
|
||||||
|
|
||||||
|
targetLine.flush();
|
||||||
|
targetLine.close();
|
||||||
|
|
||||||
|
output.flush();
|
||||||
|
output.close();
|
||||||
|
output = null;
|
||||||
|
|
||||||
|
input.close();
|
||||||
|
input = null;
|
||||||
|
|
||||||
socket.close();
|
socket.close();
|
||||||
socket = null;
|
socket = null;
|
||||||
|
running = false;
|
||||||
} catch(Exception e) {}
|
} 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) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,39 @@
|
||||||
package mekanism.common;
|
package mekanism.common;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
|
||||||
public class VoiceConnection
|
public class VoiceConnection
|
||||||
{
|
{
|
||||||
public Socket socket;
|
public Socket socket;
|
||||||
|
|
||||||
|
public DataInputStream input;
|
||||||
|
public DataOutputStream output;
|
||||||
|
|
||||||
public VoiceConnection(Socket s)
|
public VoiceConnection(Socket s)
|
||||||
{
|
{
|
||||||
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) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue