mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-25 14:24:35 +00:00
Remove vestigal voice related stuff; not yet removing walkie talkies as that _could_ break worlds
This commit is contained in:
1 parent
ec52e9f27c
commit
d2b905dcdc
3 files changed
-329
No files matched your search
@@ -94,7 +94,6 @@ import mekanism.common.transmitters.grid.EnergyNetwork.EnergyTransferEvent;
|
||||
import mekanism.common.transmitters.grid.FluidNetwork.FluidTransferEvent;
|
||||
import mekanism.common.transmitters.grid.GasNetwork.GasTransferEvent;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.voice.VoiceServerManager;
|
||||
import mekanism.common.world.GenHandler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.EnumCreatureType;
|
||||
@@ -222,9 +221,6 @@ public class Mekanism
|
||||
/** The recent news which is received from the Mekanism server */
|
||||
public static String recentNews;
|
||||
|
||||
/** The VoiceServer manager for walkie talkies */
|
||||
public static VoiceServerManager voiceManager;
|
||||
|
||||
/** A list of the usernames of players who have donated to Mekanism. */
|
||||
public static List<String> donators = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -1,213 +0,0 @@
|
||||
package mekanism.common.voice;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.item.ItemWalkieTalkie;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
|
||||
public class VoiceConnection extends Thread
|
||||
{
|
||||
public Socket socket;
|
||||
|
||||
public String username;
|
||||
|
||||
public boolean open = true;
|
||||
|
||||
public DataInputStream input;
|
||||
public DataOutputStream output;
|
||||
|
||||
public MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
|
||||
|
||||
public VoiceConnection(Socket s)
|
||||
{
|
||||
socket = s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try {
|
||||
input = new DataInputStream(new BufferedInputStream(socket.getInputStream()));
|
||||
output = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
|
||||
|
||||
synchronized(Mekanism.voiceManager)
|
||||
{
|
||||
int retryCount = 0;
|
||||
|
||||
while(username == null && retryCount <= 100)
|
||||
{
|
||||
try {
|
||||
List<EntityPlayerMP> l = Collections.synchronizedList(new ArrayList<>(server.getPlayerList().getPlayers()));
|
||||
|
||||
for(EntityPlayerMP playerMP : l)
|
||||
{
|
||||
String playerIP = playerMP.getPlayerIP();
|
||||
|
||||
if(!server.isDedicatedServer() && playerIP.equals("local") && !Mekanism.voiceManager.foundLocal)
|
||||
{
|
||||
Mekanism.voiceManager.foundLocal = true;
|
||||
username = playerMP.getName();
|
||||
break;
|
||||
}
|
||||
else if(playerIP.equals(socket.getInetAddress().getHostAddress()))
|
||||
{
|
||||
username = playerMP.getName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
retryCount++;
|
||||
Thread.sleep(50);
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
|
||||
if(username == null)
|
||||
{
|
||||
Mekanism.logger.error("VoiceServer: Unable to trace connection's IP address.");
|
||||
kill();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
Mekanism.logger.info("VoiceServer: Traced IP in " + retryCount + " attempts.");
|
||||
}
|
||||
}
|
||||
} catch(Exception e) {
|
||||
Mekanism.logger.error("VoiceServer: Error while starting server-based connection.");
|
||||
e.printStackTrace();
|
||||
open = false;
|
||||
}
|
||||
|
||||
//Main client listen thread
|
||||
new Thread(() ->
|
||||
{
|
||||
while(open)
|
||||
{
|
||||
try {
|
||||
short byteCount = VoiceConnection.this.input.readShort();
|
||||
byte[] audioData = new byte[byteCount];
|
||||
VoiceConnection.this.input.readFully(audioData);
|
||||
|
||||
if(byteCount > 0)
|
||||
{
|
||||
Mekanism.voiceManager.sendToPlayers(byteCount, audioData, VoiceConnection.this);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
open = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(!open)
|
||||
{
|
||||
kill();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void kill()
|
||||
{
|
||||
try {
|
||||
input.close();
|
||||
output.close();
|
||||
socket.close();
|
||||
|
||||
Mekanism.voiceManager.connections.remove(this);
|
||||
} catch(Exception e) {
|
||||
Mekanism.logger.error("VoiceServer: Error while stopping server-based connection.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void sendToPlayer(short byteCount, byte[] audioData, VoiceConnection connection)
|
||||
{
|
||||
if(!open)
|
||||
{
|
||||
kill();
|
||||
}
|
||||
|
||||
try {
|
||||
output.writeShort(byteCount);
|
||||
output.write(audioData);
|
||||
|
||||
output.flush();
|
||||
} catch(Exception e) {
|
||||
Mekanism.logger.error("VoiceServer: Error while sending data to player.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canListen(int channel)
|
||||
{
|
||||
for(ItemStack itemStack : getPlayer().inventory.mainInventory)
|
||||
{
|
||||
if(canListen(channel, itemStack))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for(ItemStack itemStack : getPlayer().inventory.offHandInventory)
|
||||
{
|
||||
if(canListen(channel, itemStack))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canListen(int channel, ItemStack itemStack)
|
||||
{
|
||||
if(!itemStack.isEmpty())
|
||||
{
|
||||
if(itemStack.getItem() instanceof ItemWalkieTalkie)
|
||||
{
|
||||
if(((ItemWalkieTalkie)itemStack.getItem()).getOn(itemStack))
|
||||
{
|
||||
if(((ItemWalkieTalkie)itemStack.getItem()).getChannel(itemStack) == channel)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getCurrentChannel()
|
||||
{
|
||||
ItemStack itemStack = getPlayer().inventory.getCurrentItem();
|
||||
|
||||
if(!itemStack.isEmpty())
|
||||
{
|
||||
ItemWalkieTalkie walkieTalkie = (ItemWalkieTalkie)itemStack.getItem();
|
||||
|
||||
if(walkieTalkie != null)
|
||||
{
|
||||
if(walkieTalkie.getOn(itemStack))
|
||||
{
|
||||
return walkieTalkie.getChannel(itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public EntityPlayerMP getPlayer()
|
||||
{
|
||||
return server.getPlayerList().getPlayerByUsername(username);
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
package mekanism.common.voice;
|
||||
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.config.MekanismConfig.general;
|
||||
|
||||
public class VoiceServerManager
|
||||
{
|
||||
public Set<VoiceConnection> connections = new HashSet<>();
|
||||
|
||||
public ServerSocket serverSocket;
|
||||
|
||||
public boolean running;
|
||||
|
||||
public boolean foundLocal = false;
|
||||
|
||||
public Thread listenThread;
|
||||
|
||||
public void start()
|
||||
{
|
||||
Mekanism.logger.info("VoiceServer: Starting up server...");
|
||||
|
||||
try {
|
||||
running = true;
|
||||
serverSocket = new ServerSocket(general.VOICE_PORT);
|
||||
(listenThread = new ListenThread()).start();
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
|
||||
public void stop()
|
||||
{
|
||||
try {
|
||||
Mekanism.logger.info("VoiceServer: Shutting down server...");
|
||||
|
||||
try {
|
||||
listenThread.interrupt();
|
||||
} catch(Exception e) {}
|
||||
|
||||
foundLocal = false;
|
||||
|
||||
try {
|
||||
serverSocket.close();
|
||||
serverSocket = null;
|
||||
} catch(Exception e) {}
|
||||
} catch(Exception e) {
|
||||
Mekanism.logger.error("VoiceServer: Error while shutting down server.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
running = false;
|
||||
}
|
||||
|
||||
public void sendToPlayers(short byteCount, byte[] audioData, VoiceConnection connection)
|
||||
{
|
||||
if(connection.getPlayer() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int channel = connection.getCurrentChannel();
|
||||
|
||||
if(channel == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for(VoiceConnection iterConn : connections)
|
||||
{
|
||||
if(iterConn.getPlayer() == null || iterConn == connection || !iterConn.canListen(channel))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
iterConn.sendToPlayer(byteCount, audioData, connection);
|
||||
}
|
||||
}
|
||||
|
||||
public class ListenThread extends Thread
|
||||
{
|
||||
public ListenThread()
|
||||
{
|
||||
setDaemon(true);
|
||||
setName("VoiceServer Listen Thread");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while(running)
|
||||
{
|
||||
try {
|
||||
Socket s = serverSocket.accept();
|
||||
VoiceConnection connection = new VoiceConnection(s);
|
||||
connection.start();
|
||||
connections.add(connection);
|
||||
|
||||
Mekanism.logger.info("VoiceServer: Accepted new connection.");
|
||||
} catch(SocketException | NullPointerException e) {
|
||||
}
|
||||
catch(Exception e) {
|
||||
Mekanism.logger.error("VoiceServer: Error while accepting connection.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user