Merge pull request #51 from Thorfusion/sec-patch-1

Remove voiceserver, cape module and update downloader
This commit is contained in:
DrParadox7 authored and GitHub committed 2022-11-21 18:59:49 +01:00
commit 6da1c70373
36 files changed
+4 -1233

No files matched your search

@@ -15,7 +15,6 @@ public class MekanismConfig
public static boolean controlCircuitOreDict = true;
public static boolean logPackets = false;
public static boolean dynamicTankEasterEgg = false;
public static boolean voiceServerEnabled = true;
public static boolean cardboardSpawners = true;
public static boolean enableWorldRegeneration = true;
public static boolean spawnBabySkeletons = true;
@@ -27,7 +26,6 @@ public class MekanismConfig
public static int saltPerChunk = 2;
public static int obsidianTNTDelay = 100;
public static int UPDATE_DELAY = 10;
public static int VOICE_PORT = 36123;
public static int maxUpgradeMultiplier = 10;
public static int userWorldGenVersion = 0;
public static double ENERGY_PER_REDSTONE = 10000;
@@ -259,7 +257,6 @@ public class MekanismConfig
public static boolean enableTeleporterCore = true;
public static boolean enableConfigurator = true;
public static boolean enableNetworkReader = true;
public static boolean enableWalkieTalkie = true;
public static boolean enableJetpacks = true;
public static boolean enableScubaSet = true;
public static boolean enableFreeRunners = true;
@@ -1,43 +0,0 @@
package mekanism.client;
import java.net.InetSocketAddress;
import mekanism.api.MekanismConfig.general;
import mekanism.client.voice.VoiceClient;
import mekanism.common.Mekanism;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent.ClientConnectedToServerEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ClientConnectionHandler
{
@SubscribeEvent
public void onConnection(ClientConnectedToServerEvent event)
{
if(general.voiceServerEnabled)
{
if(event.isLocal)
{
//If the client is connecting to its own corresponding integrated server.
try {
MekanismClient.voiceClient = new VoiceClient("127.0.0.1");
//Will probably not work when multiple integrateds are running on one computer
} catch(Throwable e) {
Mekanism.logger.error("Unable to establish VoiceClient on local connection.");
e.printStackTrace();
}
}
else {
//If the client is connecting to a foreign integrated or dedicated server.
try {
MekanismClient.voiceClient = new VoiceClient(((InetSocketAddress)event.manager.getSocketAddress()).getHostString());
} catch(Throwable e) {
Mekanism.logger.error("Unable to establish VoiceClient on remote connection.");
e.printStackTrace();
}
}
}
}
}
@@ -6,7 +6,6 @@ import com.jadarstudios.developercapes.DevCapes;
import cpw.mods.fml.common.Loader;
import mekanism.api.Coord4D;
import mekanism.api.MekanismConfig.client;
import mekanism.api.MekanismConfig.general;
import mekanism.api.Pos3D;
import mekanism.client.SparkleAnimation.INodeChecker;
import mekanism.client.entity.EntityLaser;
@@ -351,7 +350,6 @@ public class ClientProxy extends CommonProxy
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(MekanismBlocks.MachineBlock2), handler);
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(MekanismBlocks.MachineBlock3), handler);
MinecraftForgeClient.registerItemRenderer(MekanismItems.Robit, handler);
MinecraftForgeClient.registerItemRenderer(MekanismItems.WalkieTalkie, handler);
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(MekanismBlocks.GasTank), handler);
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(MekanismBlocks.ObsidianTNT), handler);
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(MekanismBlocks.BasicBlock), handler);
@@ -585,7 +583,6 @@ public class ClientProxy extends CommonProxy
{
super.loadUtilities();
FMLCommonHandler.instance().bus().register(new ClientConnectionHandler());
FMLCommonHandler.instance().bus().register(new ClientPlayerTracker());
FMLCommonHandler.instance().bus().register(new ClientTickHandler());
FMLCommonHandler.instance().bus().register(new RenderTickHandler());
@@ -646,11 +643,6 @@ public class ClientProxy extends CommonProxy
public void onConfigSync(boolean fromPacket)
{
super.onConfigSync(fromPacket);
if(fromPacket && general.voiceServerEnabled && MekanismClient.voiceClient != null)
{
MekanismClient.voiceClient.start();
}
}
@Override
@@ -4,11 +4,9 @@ import static mekanism.client.sound.SoundHandler.Channel.FLAMETHROWER;
import static mekanism.client.sound.SoundHandler.Channel.GASMASK;
import static mekanism.client.sound.SoundHandler.Channel.JETPACK;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import mekanism.api.IClientTicker;
@@ -32,13 +30,9 @@ import mekanism.common.network.PacketScubaTankData.ScubaTankDataMessage;
import mekanism.common.network.PacketScubaTankData.ScubaTankPacket;
import mekanism.common.util.MekanismUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.StringUtils;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
@@ -57,21 +51,10 @@ public class ClientTickHandler
{
public boolean hasNotified = false;
public boolean initHoliday = false;
public boolean preloadedSounds = false;
public boolean lastTickUpdate;
public boolean shouldReset = false;
public static Minecraft mc = FMLClientHandler.instance().getClient();
public static final String DONATE_CAPE = "http://aidancbrady.com/data/capes/donate.png";
public static final String AIDAN_CAPE = "http://aidancbrady.com/data/capes/aidan.png";
private Map<String, CapeBufferDownload> donateDownload = new HashMap<String, CapeBufferDownload>();
private Map<String, CapeBufferDownload> aidanDownload = new HashMap<String, CapeBufferDownload>();
public static Set<IClientTicker> tickingSet = new HashSet<IClientTicker>();
@SubscribeEvent
@@ -127,58 +110,6 @@ public class ClientTickHandler
initHoliday = true;
}
for(EntityPlayer entityPlayer : (List<EntityPlayer>)mc.theWorld.playerEntities)
{
if(entityPlayer instanceof AbstractClientPlayer)
{
AbstractClientPlayer player = (AbstractClientPlayer)entityPlayer;
if(player != null)
{
if(StringUtils.stripControlCodes(player.getCommandSenderName()).equals("aidancbrady"))
{
CapeBufferDownload download = aidanDownload.get(player.getCommandSenderName());
if(download == null)
{
download = new CapeBufferDownload(player.getCommandSenderName(), AIDAN_CAPE);
aidanDownload.put(player.getCommandSenderName(), download);
download.start();
}
else {
if(!download.downloaded)
{
continue;
}
player.func_152121_a(MinecraftProfileTexture.Type.CAPE, download.getResourceLocation());
}
}
else if(Mekanism.donators.contains(StringUtils.stripControlCodes(player.getCommandSenderName())))
{
CapeBufferDownload download = donateDownload.get(player.getCommandSenderName());
if(download == null)
{
download = new CapeBufferDownload(player.getCommandSenderName(), DONATE_CAPE);
donateDownload.put(player.getCommandSenderName(), download);
download.start();
}
else {
if(!download.downloaded)
{
continue;
}
player.func_152121_a(MinecraftProfileTexture.Type.CAPE, download.getResourceLocation());
}
}
}
}
}
if(mc.thePlayer.getEquipmentInSlot(1) != null && mc.thePlayer.getEquipmentInSlot(1).getItem() instanceof ItemFreeRunners)
{
mc.thePlayer.stepHeight = 1.002F;
@@ -5,9 +5,7 @@ import java.util.Map;
import mekanism.api.MekanismAPI;
import mekanism.api.MekanismAPI.BoxBlacklistEvent;
import mekanism.api.MekanismConfig.general;
import mekanism.client.sound.SoundHandler;
import mekanism.client.voice.VoiceClient;
import mekanism.common.Mekanism;
import mekanism.common.base.IModule;
import mekanism.common.content.boiler.SynchronizedBoilerData;
@@ -20,8 +18,6 @@ import net.minecraftforge.common.MinecraftForge;
public class MekanismClient extends Mekanism
{
public static Map<String, SecurityData> clientSecurityMap = new HashMap<String, SecurityData>();
public static VoiceClient voiceClient;
public static long ticksPassed = 0;
@@ -39,15 +35,6 @@ public class MekanismClient extends Mekanism
public static void reset()
{
clientSecurityMap.clear();
if(general.voiceServerEnabled)
{
if(MekanismClient.voiceClient != null)
{
MekanismClient.voiceClient.disconnect();
MekanismClient.voiceClient = null;
}
}
ClientTickHandler.tickingSet.clear();
@@ -13,7 +13,6 @@ import mekanism.common.item.ItemFlamethrower;
import mekanism.common.item.ItemJetpack;
import mekanism.common.item.ItemJetpack.JetpackMode;
import mekanism.common.item.ItemScubaTank;
import mekanism.common.item.ItemWalkieTalkie;
import mekanism.common.network.PacketConfiguratorState.ConfiguratorStateMessage;
import mekanism.common.network.PacketElectricBowState.ElectricBowStateMessage;
import mekanism.common.network.PacketFlamethrowerData;
@@ -22,7 +21,6 @@ import mekanism.common.network.PacketJetpackData.JetpackPacket;
import mekanism.common.network.PacketPortableTankState.PortableTankStateMessage;
import mekanism.common.network.PacketScubaTankData.ScubaTankDataMessage;
import mekanism.common.network.PacketScubaTankData.ScubaTankPacket;
import mekanism.common.network.PacketWalkieTalkieState.WalkieTalkieStateMessage;
import mekanism.common.util.LangUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
@@ -47,17 +45,15 @@ public class MekanismKeyHandler extends MekKeyHandler
public static final String keybindCategory = "Mekanism";
public static KeyBinding modeSwitchKey = new KeyBinding("Mekanism " + LangUtils.localize("key.mode"), Keyboard.KEY_M, keybindCategory);
public static KeyBinding armorModeSwitchKey = new KeyBinding("Mekanism " + LangUtils.localize("key.armorMode"), Keyboard.KEY_F, keybindCategory);
public static KeyBinding voiceKey = new KeyBinding("Mekanism " + LangUtils.localize("key.voice"), Keyboard.KEY_U, keybindCategory);
public static KeyBinding sneakKey = Minecraft.getMinecraft().gameSettings.keyBindSneak;
public static KeyBinding jumpKey = Minecraft.getMinecraft().gameSettings.keyBindJump;
public MekanismKeyHandler()
{
super(new KeyBinding[] {modeSwitchKey, armorModeSwitchKey, voiceKey}, new boolean[] {false, false, true});
super(new KeyBinding[] {modeSwitchKey, armorModeSwitchKey}, new boolean[] {false, false, true});
ClientRegistry.registerKeyBinding(modeSwitchKey);
ClientRegistry.registerKeyBinding(armorModeSwitchKey);
ClientRegistry.registerKeyBinding(voiceKey);
FMLCommonHandler.instance().bus().register(this);
}
@@ -106,18 +102,6 @@ public class MekanismKeyHandler extends MekKeyHandler
player.addChatMessage(new ChatComponentText(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + LangUtils.localize("tooltip.portableTank.bucketMode") + ": " + (machine.getBucketMode(toolStack) ? EnumColor.DARK_GREEN : EnumColor.DARK_RED) + LangUtils.transOnOff(machine.getBucketMode(toolStack))));
}
}
else if(player.isSneaking() && item instanceof ItemWalkieTalkie)
{
ItemWalkieTalkie wt = (ItemWalkieTalkie)item;
if(wt.getOn(toolStack))
{
int newChan = wt.getChannel(toolStack) < 9 ? wt.getChannel(toolStack) + 1 : 1;
wt.setChannel(toolStack, newChan);
Mekanism.packetHandler.sendToServer(new WalkieTalkieStateMessage(newChan));
SoundHandler.playSound("mekanism:etc.Ding");
}
}
else if(player.isSneaking() && item instanceof ItemFlamethrower)
{
ItemFlamethrower flamethrower = (ItemFlamethrower)item;
@@ -1,210 +0,0 @@
package mekanism.client;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import mekanism.api.EnumColor;
import mekanism.client.gui.GuiCredits;
import mekanism.common.Mekanism;
import mekanism.common.Version;
import mekanism.common.base.IModule;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Thread that downloads the latest release of Mekanism. The older file is deleted and the newly downloaded file takes it's place.
* @author AidanBrady
*
*/
@SideOnly(Side.CLIENT)
public class ThreadClientUpdate extends Thread
{
private int bytesDownloaded;
private int lastBytesDownloaded;
private byte[] buffer = new byte[10240];
private static File modsDir = new File(Mekanism.proxy.getMinecraftDir(), "mods");
private static File tempDir = new File(modsDir, "temp");
private static URL zipUrl = createURL();
public static boolean hasUpdated;
public ThreadClientUpdate()
{
setDaemon(false);
start();
}
@Override
public void run()
{
try {
deleteTemp();
createTemp();
File download = new File(tempDir, "builds.zip");
prepareForDownload();
download.createNewFile();
GuiCredits.updateInfo("Downloading...");
FileOutputStream outputStream = new FileOutputStream(download.getAbsolutePath());
InputStream stream = zipUrl.openStream();
while((lastBytesDownloaded = stream.read(buffer)) > 0)
{
outputStream.write(buffer, 0, lastBytesDownloaded);
buffer = new byte[10240];
bytesDownloaded += lastBytesDownloaded;
}
outputStream.close();
stream.close();
if(Mekanism.versionNumber.comparedState(Version.get(Mekanism.latestVersionNumber)) == -1)
{
ZipInputStream zip = new ZipInputStream(new FileInputStream(download));
deployEntry(zip, "Mekanism-");
zip.close();
}
for(IModule module : Mekanism.modulesLoaded)
{
if(module.getVersion().comparedState(Version.get(Mekanism.latestVersionNumber)) == -1)
{
ZipInputStream zip = new ZipInputStream(new FileInputStream(download));
deployEntry(zip, "Mekanism" + module.getName());
zip.close();
}
}
deleteTemp();
hasUpdated = true;
GuiCredits.updateInfo("Update installed, reboot Minecraft for changes.");
Mekanism.logger.info("Successfully updated to latest version (" + Mekanism.latestVersionNumber + ").");
finalize();
} catch(Throwable t) {
GuiCredits.updateInfo(EnumColor.DARK_RED + "Error updating.");
hasUpdated = true;
Mekanism.logger.error("Error while finishing update thread: " + t.getMessage());
t.printStackTrace();
}
}
private void deployEntry(ZipInputStream zip, String filePrefix) throws IOException
{
byte[] zipBuffer = new byte[1024];
ZipEntry entry = zip.getNextEntry();
while(entry != null)
{
if(entry.isDirectory())
{
continue;
}
if(entry.getName().contains(filePrefix))
{
File modFile = new File(modsDir, entry.getName().replace("output/", ""));
if(modFile.exists())
{
modFile.delete();
}
modFile.createNewFile();
FileOutputStream outStream = new FileOutputStream(modFile);
int len;
while((len = zip.read(zipBuffer)) > 0)
{
outStream.write(zipBuffer, 0, len);
}
zip.closeEntry();
outStream.close();
break;
}
entry = zip.getNextEntry();
}
}
private void createTemp() throws IOException
{
if(!tempDir.exists())
{
tempDir.mkdir();
}
}
private void deleteTemp() throws IOException
{
if(tempDir.exists())
{
clearFiles(tempDir);
}
}
private void clearFiles(File file)
{
if(file.isDirectory())
{
for(File sub : file.listFiles())
{
clearFiles(sub);
}
}
file.delete();
}
private void prepareForDownload()
{
File[] modsList = new File(new StringBuilder().append(Mekanism.proxy.getMinecraftDir()).append(File.separator + "mods").toString()).listFiles();
if(Mekanism.versionNumber.comparedState(Version.get(Mekanism.latestVersionNumber)) == -1)
{
for(File file : modsList)
{
if(file.getName().startsWith("Mekanism-") && file.getName().endsWith(".jar") && !file.getName().contains(Mekanism.latestVersionNumber))
{
file.delete();
}
}
}
for(IModule module : Mekanism.modulesLoaded)
{
for(File file : modsList)
{
if(file.getName().startsWith("Mekanism" + module.getName()) && file.getName().endsWith(".jar") && !file.getName().contains(Mekanism.latestVersionNumber))
{
file.delete();
}
}
}
Mekanism.logger.info("Preparing to update...");
}
private static URL createURL()
{
try {
return new URL("http://technic-solder.eu-central-1.linodeobjects.com/mekanism/latestmekanism.zip");
} catch(Exception e) {}
return null;
}
}
@@ -1,12 +1,9 @@
package mekanism.client.gui;
import mekanism.api.EnumColor;
import mekanism.client.ThreadClientUpdate;
import mekanism.common.Mekanism;
import mekanism.common.Version;
import mekanism.common.base.IModule;
import mekanism.common.util.MekanismUtils;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -14,44 +11,6 @@ import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiCredits extends GuiScreen
{
private static String updateProgress = "";
@Override
public void initGui()
{
buttonList.clear();
buttonList.add(new GuiButton(0, width / 2 - 100, height / 4 + 72 + 12, "Update"));
buttonList.add(new GuiButton(1, width / 2 - 100, height / 4 + 96 + 12, "Cancel"));
((GuiButton)buttonList.get(0)).enabled = !MekanismUtils.noUpdates() && !ThreadClientUpdate.hasUpdated;
}
public static void updateInfo(String info)
{
updateProgress = info;
}
@Override
protected void actionPerformed(GuiButton guibutton)
{
if(guibutton.id == 0)
{
if(!MekanismUtils.noUpdates())
{
updateProgress = "Preparing to update...";
guibutton.enabled = false;
new ThreadClientUpdate();
}
else {
updateProgress = "You already have the latest version.";
}
}
else if(guibutton.id == 1)
{
mc.displayGuiScreen(null);
}
}
public void writeText(String text, int yAxis)
{
drawString(fontRendererObj, text, width / 2 - 140, (height / 4 - 60) + 20 + yAxis, 0xa0a0a0);
@@ -93,10 +52,7 @@ public class GuiCredits extends GuiScreen
}
writeText(EnumColor.GREY + "Newest version: " + Mekanism.latestVersionNumber, size+9);
writeText(EnumColor.GREY + "*Developed on Mac OS X 10.8 Mountain Lion", size+18);
writeText(EnumColor.GREY + "*Code, textures, and ideas by aidancbrady", size+27);
writeText(EnumColor.GREY + "Recent news: " + EnumColor.DARK_BLUE + (!Mekanism.recentNews.contains("null") ? Mekanism.recentNews : "couldn't access."), size+36);
writeText(EnumColor.GREY + updateProgress, size+45);
writeText(EnumColor.GREY + "Recent news: " + EnumColor.DARK_BLUE + (!Mekanism.recentNews.contains("null") ? Mekanism.recentNews : "couldn't access."), size+18);
super.drawScreen(mouseX, mouseY, partialTick);
}
@@ -43,7 +43,6 @@ import mekanism.common.item.ItemFreeRunners;
import mekanism.common.item.ItemGasMask;
import mekanism.common.item.ItemRobit;
import mekanism.common.item.ItemScubaTank;
import mekanism.common.item.ItemWalkieTalkie;
import mekanism.common.multipart.ItemGlowPanel;
import mekanism.common.multipart.ItemPartTransmitter;
import mekanism.common.multipart.TransmitterType;
@@ -101,11 +100,6 @@ public class ItemRenderingHandler implements IItemRenderer
@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type)
{
if(item.getItem() == MekanismItems.WalkieTalkie)
{
return type != ItemRenderType.INVENTORY;
}
return true;
}
@@ -327,20 +321,6 @@ public class ItemRenderingHandler implements IItemRenderer
obsidianTNT.render(0.0625F);
GL11.glPopMatrix();
}
else if(item.getItem() instanceof ItemWalkieTalkie)
{
if(((ItemWalkieTalkie)item.getItem()).getOn(item))
{
MekanismRenderer.glowOn();
}
MekanismRenderer.renderItem(item);
if(((ItemWalkieTalkie)item.getItem()).getOn(item))
{
MekanismRenderer.glowOff();
}
}
else if(MachineType.get(item) == MachineType.PERSONAL_CHEST)
{
GL11.glPushMatrix();
@@ -1,105 +0,0 @@
package mekanism.client.voice;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.ConnectException;
import java.net.Socket;
import javax.sound.sampled.AudioFormat;
import mekanism.api.MekanismConfig.general;
import mekanism.common.Mekanism;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class VoiceClient extends Thread
{
public Socket socket;
public String ip;
public AudioFormat format = new AudioFormat(16000F, 16, 1, true, true);
public VoiceInput inputThread;
public VoiceOutput outputThread;
public DataInputStream input;
public DataOutputStream output;
public boolean running;
public VoiceClient(String s)
{
ip = s;
}
@Override
public void run()
{
Mekanism.logger.info("VoiceServer: Starting client connection...");
try {
socket = new Socket(ip, general.VOICE_PORT);
running = true;
input = new DataInputStream(new BufferedInputStream(socket.getInputStream()));
output = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
(outputThread = new VoiceOutput(this)).start();
(inputThread = new VoiceInput(this)).start();
Mekanism.logger.info("VoiceServer: Successfully connected to server.");
} catch(ConnectException e) {
Mekanism.logger.error("VoiceServer: Server's VoiceServer is disabled.");
} catch(Exception e) {
Mekanism.logger.error("VoiceServer: Error while starting client connection.");
e.printStackTrace();
}
}
public void disconnect()
{
Mekanism.logger.info("VoiceServer: Stopping client connection...");
try {
try {
inputThread.interrupt();
outputThread.interrupt();
} catch(Exception e) {}
try {
interrupt();
} catch(Exception e) {}
try {
inputThread.close();
outputThread.close();
} catch(Exception e) {}
try {
output.flush();
output.close();
output = null;
} catch(Exception e) {}
try {
input.close();
input = null;
} catch(Exception e) {}
try {
socket.close();
socket = null;
} catch(Exception e) {}
running = false;
} catch(Exception e) {
Mekanism.logger.error("VoiceServer: Error while stopping client connection.");
e.printStackTrace();
}
}
}
@@ -1,95 +0,0 @@
package mekanism.client.voice;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.TargetDataLine;
import mekanism.client.MekanismKeyHandler;
import mekanism.common.Mekanism;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class VoiceInput extends Thread
{
public VoiceClient voiceClient;
public DataLine.Info microphone;
public TargetDataLine targetLine;
public VoiceInput(VoiceClient client)
{
voiceClient = client;
microphone = new DataLine.Info(TargetDataLine.class, voiceClient.format, 2200);
setDaemon(true);
setName("VoiceServer Client Input Thread");
}
@Override
public void run()
{
try {
targetLine = ((TargetDataLine)AudioSystem.getLine(microphone));
targetLine.open(voiceClient.format, 2200);
targetLine.start();
AudioInputStream audioInput = new AudioInputStream(targetLine);
boolean doFlush = false;
while(voiceClient.running)
{
if(MekanismKeyHandler.voiceKey.getIsKeyPressed())
{
targetLine.flush();
while(voiceClient.running && MekanismKeyHandler.voiceKey.getIsKeyPressed())
{
try {
int availableBytes = audioInput.available();
byte[] audioData = new byte[availableBytes > 2200 ? 2200 : availableBytes];
int bytesRead = audioInput.read(audioData, 0, audioData.length);
if(bytesRead > 0)
{
voiceClient.output.writeShort(audioData.length);
voiceClient.output.write(audioData);
}
} catch(Exception e) {}
}
try {
Thread.sleep(200L);
} catch(Exception e) {}
doFlush = true;
}
else if(doFlush)
{
try {
voiceClient.output.flush();
} catch(Exception e) {}
doFlush = false;
}
try {
Thread.sleep(20L);
} catch(Exception e) {}
}
audioInput.close();
} catch(Exception e) {
Mekanism.logger.error("VoiceServer: Error while running client input thread.");
e.printStackTrace();
}
}
public void close()
{
targetLine.flush();
targetLine.close();
}
}
@@ -1,58 +0,0 @@
package mekanism.client.voice;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
import mekanism.common.Mekanism;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class VoiceOutput extends Thread
{
public VoiceClient voiceClient;
public DataLine.Info speaker;
public SourceDataLine sourceLine;
public VoiceOutput(VoiceClient client)
{
voiceClient = client;
speaker = new DataLine.Info(SourceDataLine.class, voiceClient.format, 2200);
setDaemon(true);
setName("VoiceServer Client Output Thread");
}
@Override
public void run()
{
try {
sourceLine = ((SourceDataLine)AudioSystem.getLine(speaker));
sourceLine.open(voiceClient.format, 2200);
sourceLine.start();
while(voiceClient.running)
{
try {
short byteCount = voiceClient.input.readShort();
byte[] audioData = new byte[byteCount];
voiceClient.input.readFully(audioData);
sourceLine.write(audioData, 0, audioData.length);
} catch(Exception e) {}
}
} catch(Exception e) {
Mekanism.logger.error("VoiceServer: Error while running client output thread.");
e.printStackTrace();
}
}
public void close()
{
sourceLine.flush();
sourceLine.close();
}
}
@@ -253,7 +253,6 @@ public class CommonProxy implements IGuiProvider
general.controlCircuitOreDict = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "ControlCircuitOreDict", true).getBoolean();
general.logPackets = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "LogPackets", false).getBoolean();
general.dynamicTankEasterEgg = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "DynamicTankEasterEgg", false).getBoolean();
general.voiceServerEnabled = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "VoiceServerEnabled", false).getBoolean();
general.cardboardSpawners = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "AllowSpawnerBoxPickup", true).getBoolean();
general.enableWorldRegeneration = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "EnableWorldRegeneration", false).getBoolean();
general.enableBoPProgression = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "enableBoPProgression", true).getBoolean();
@@ -275,7 +274,6 @@ public class CommonProxy implements IGuiProvider
general.METHANE_BURN_TIME = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "MethaneBurnTime", 10).getInt();
general.ENERGY_PER_REDSTONE = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "EnergyPerRedstone", 10000D).getDouble();
general.DISASSEMBLER_USAGE = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "DisassemblerEnergyUsage", 10).getInt();
general.VOICE_PORT = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "VoicePort", 36123, null, 1, 65535).getInt();
//If this is less than 1, upgrades make machines worse. If less than 0, I don't even know.
general.maxUpgradeMultiplier = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "UpgradeModifier", 10, null, 1, Integer.MAX_VALUE).getInt();
general.minerSilkMultiplier = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "MinerSilkMultiplier", 6).getDouble();
@@ -485,7 +483,6 @@ public class CommonProxy implements IGuiProvider
recipes.enableTeleporterCore = Mekanism.configurationrecipes.get("Recipes","enableTeleporterCore", true).getBoolean();
recipes.enableConfigurator = Mekanism.configurationrecipes.get("Recipes","enableConfigurator", true).getBoolean();
recipes.enableNetworkReader = Mekanism.configurationrecipes.get("Recipes","enableNetworkReader", true).getBoolean();
recipes.enableWalkieTalkie = Mekanism.configurationrecipes.get("Recipes","enableWalkieTalkie", true).getBoolean();
recipes.enableJetpacks = Mekanism.configurationrecipes.get("Recipes","enableJetpacks", true).getBoolean();
recipes.enableScubaSet = Mekanism.configurationrecipes.get("Recipes","enableScubaSet", true).getBoolean();
recipes.enableFreeRunners = Mekanism.configurationrecipes.get("Recipes","enableFreeRunners", true).getBoolean();
@@ -85,7 +85,6 @@ import mekanism.common.tile.TileEntitySuperheatingElement;
import mekanism.common.tile.TileEntityThermalEvaporationBlock;
import mekanism.common.tile.TileEntityThermalEvaporationValve;
import mekanism.common.util.MekanismUtils;
import mekanism.common.voice.VoiceServerManager;
import mekanism.common.world.GenHandler;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.init.Blocks;
@@ -194,9 +193,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<String>();
@@ -1362,10 +1358,6 @@ public class Mekanism
@EventHandler
public void serverStarting(FMLServerStartingEvent event)
{
if(general.voiceServerEnabled)
{
voiceManager.start();
}
//Load cached furnace recipes
Recipe.ENERGIZED_SMELTER.get().clear();
@@ -1383,10 +1375,6 @@ public class Mekanism
@EventHandler
public void serverStopping(FMLServerStoppingEvent event)
{
if(general.voiceServerEnabled)
{
voiceManager.stop();
}
//Clear all cache data
jetpackOn.clear();
@@ -1506,12 +1494,6 @@ public class Mekanism
//Register this module's GUI handler in the simple packet protocol
PacketSimpleGui.handlers.add(0, proxy);
//Set up VoiceServerManager
if(general.voiceServerEnabled)
{
voiceManager = new VoiceServerManager();
}
//Register with TransmitterNetworkRegistry
TransmitterNetworkRegistry.initiate();
@@ -32,7 +32,6 @@ import mekanism.common.item.ItemScubaTank;
import mekanism.common.item.ItemSeismicReader;
import mekanism.common.item.ItemShard;
import mekanism.common.item.ItemUpgrade;
import mekanism.common.item.ItemWalkieTalkie;
import mekanism.common.multipart.ItemGlowPanel;
import mekanism.common.multipart.ItemPartTransmitter;
import net.minecraft.init.Items;
@@ -77,7 +76,6 @@ public class MekanismItems
public static final ItemPortableTeleporter PortableTeleporter = (ItemPortableTeleporter)new ItemPortableTeleporter().setUnlocalizedName("PortableTeleporter");
public static final ItemConfigurator Configurator = (ItemConfigurator)new ItemConfigurator().setUnlocalizedName("Configurator");
public static final ItemNetworkReader NetworkReader = (ItemNetworkReader)new ItemNetworkReader().setUnlocalizedName("NetworkReader");
public static final Item WalkieTalkie = new ItemWalkieTalkie().setUnlocalizedName("WalkieTalkie");
public static final ItemElectricBow ElectricBow = (ItemElectricBow)new ItemElectricBow().setUnlocalizedName("ElectricBow");
public static final ItemFlamethrower Flamethrower = (ItemFlamethrower)new ItemFlamethrower().setUnlocalizedName("Flamethrower");
public static final ItemSeismicReader SeismicReader = (ItemSeismicReader)new ItemSeismicReader().setUnlocalizedName("SeismicReader");
@@ -142,7 +140,6 @@ public class MekanismItems
GameRegistry.registerItem(DirtyDust, "DirtyDust");
GameRegistry.registerItem(Configurator, "Configurator");
GameRegistry.registerItem(NetworkReader, "NetworkReader");
GameRegistry.registerItem(WalkieTalkie, "WalkieTalkie");
GameRegistry.registerItem(Jetpack, "Jetpack");
GameRegistry.registerItem(Dictionary, "Dictionary");
GameRegistry.registerItem(GasMask, "GasMask");
@@ -67,8 +67,6 @@ import mekanism.common.network.PacketTileEntity;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.network.PacketTransmitterUpdate;
import mekanism.common.network.PacketTransmitterUpdate.TransmitterUpdateMessage;
import mekanism.common.network.PacketWalkieTalkieState;
import mekanism.common.network.PacketWalkieTalkieState.WalkieTalkieStateMessage;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
@@ -113,7 +111,6 @@ public class PacketHandler
netHandler.registerMessage(PacketPortableTeleporter.class, PortableTeleporterMessage.class, 10, Side.SERVER);
netHandler.registerMessage(PacketRemoveUpgrade.class, RemoveUpgradeMessage.class, 11, Side.SERVER);
netHandler.registerMessage(PacketRedstoneControl.class, RedstoneControlMessage.class, 12, Side.SERVER);
netHandler.registerMessage(PacketWalkieTalkieState.class, WalkieTalkieStateMessage.class, 13, Side.SERVER);
netHandler.registerMessage(PacketLogisticalSorterGui.class, LogisticalSorterGuiMessage.class, 14, Side.CLIENT);
netHandler.registerMessage(PacketLogisticalSorterGui.class, LogisticalSorterGuiMessage.class, 14, Side.SERVER);
netHandler.registerMessage(PacketNewFilter.class, NewFilterMessage.class, 15, Side.SERVER);
@@ -41,7 +41,5 @@ public class ThreadGetData extends Thread
}
}
}
MekanismUtils.updateDonators();
}
}
@@ -156,11 +156,6 @@ public final class OreDictManager
" B ", "ECE", "OOO", Character.valueOf('B'), Items.bucket, Character.valueOf('E'), MekanismItems.EnrichedAlloy, Character.valueOf('C'), new ItemStack(MekanismBlocks.BasicBlock, 1, 8), Character.valueOf('O'), "ingot" + s
}));
}
if (MekanismConfig.recipes.enableWalkieTalkie) {
CraftingManager.getInstance().getRecipeList().add(new ShapedMekanismRecipe(new ItemStack(MekanismItems.WalkieTalkie), new Object[]{
" O", "SCS", " S ", Character.valueOf('O'), "ingot" + s, Character.valueOf('S'), "ingotSteel", Character.valueOf('C'), MekanismUtils.getControlCircuit(Tier.BaseTier.BASIC)
}));
}
if (MekanismConfig.recipes.enableElectroliticCore) {
CraftingManager.getInstance().getRecipeList().add(new ShapedMekanismRecipe(new ItemStack(MekanismItems.ElectrolyticCore), new Object[]{
@@ -1,112 +0,0 @@
package mekanism.common.item;
import java.util.List;
import mekanism.api.EnumColor;
import mekanism.common.util.LangUtils;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
public class ItemWalkieTalkie extends ItemMekanism
{
public IIcon[] icons = new IIcon[256];
public ItemWalkieTalkie()
{
super();
setMaxStackSize(1);
}
@Override
public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag)
{
super.addInformation(itemstack, entityplayer, list, flag);
list.add((getOn(itemstack) ? EnumColor.DARK_GREEN : EnumColor.DARK_RED) + LangUtils.localize("gui." + (getOn(itemstack) ? "on" : "off")));
list.add(EnumColor.DARK_AQUA + LangUtils.localize("tooltip.channel") + ": " + EnumColor.GREY + getChannel(itemstack));
}
@Override
public IIcon getIconIndex(ItemStack itemStack)
{
if(!getOn(itemStack))
{
return icons[0];
}
return icons[getChannel(itemStack)];
}
@Override
public void registerIcons(IIconRegister register)
{
icons[0] = register.registerIcon("mekanism:WalkieTalkieOff");
for(int i = 1; i <= 9; i++)
{
icons[i] = register.registerIcon("mekanism:WalkieTalkie_ch" + i);
}
}
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
{
if(player.isSneaking())
{
setOn(itemStack, !getOn(itemStack));
}
return itemStack;
}
public void setOn(ItemStack itemStack, boolean on)
{
if(itemStack.stackTagCompound == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
itemStack.stackTagCompound.setBoolean("on", on);
}
public boolean getOn(ItemStack itemStack)
{
if(itemStack.stackTagCompound == null)
{
return false;
}
return itemStack.stackTagCompound.getBoolean("on");
}
public void setChannel(ItemStack itemStack, int channel)
{
if(itemStack.stackTagCompound == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
itemStack.stackTagCompound.setInteger("channel", channel);
}
public int getChannel(ItemStack itemStack)
{
if(itemStack.stackTagCompound == null)
{
return 1;
}
int channel = itemStack.stackTagCompound.getInteger("channel");
if(channel == 0)
{
setChannel(itemStack, 1);
}
return itemStack.stackTagCompound.getInteger("channel");
}
}
@@ -33,7 +33,6 @@ public class PacketConfigSync implements IMessageHandler<ConfigSyncMessage, IMes
dataStream.writeBoolean(general.controlCircuitOreDict);
dataStream.writeBoolean(general.logPackets);
dataStream.writeBoolean(general.dynamicTankEasterEgg);
dataStream.writeBoolean(general.voiceServerEnabled);
dataStream.writeBoolean(general.cardboardSpawners);
dataStream.writeBoolean(general.spawnBabySkeletons);
dataStream.writeBoolean(general.enableBoPProgression);
@@ -49,7 +48,6 @@ public class PacketConfigSync implements IMessageHandler<ConfigSyncMessage, IMes
dataStream.writeInt(general.METHANE_BURN_TIME);
dataStream.writeDouble(general.ENERGY_PER_REDSTONE);
dataStream.writeDouble(general.DISASSEMBLER_USAGE);
dataStream.writeInt(general.VOICE_PORT);
dataStream.writeInt(general.maxUpgradeMultiplier);
dataStream.writeInt(general.energyUnit.ordinal());
dataStream.writeDouble(general.minerSilkMultiplier);
@@ -196,7 +194,6 @@ public class PacketConfigSync implements IMessageHandler<ConfigSyncMessage, IMes
dataStream.writeBoolean(recipes.enableTeleporterCore);
dataStream.writeBoolean(recipes.enableConfigurator);
dataStream.writeBoolean(recipes.enableNetworkReader);
dataStream.writeBoolean(recipes.enableWalkieTalkie);
dataStream.writeBoolean(recipes.enableJetpacks);
dataStream.writeBoolean(recipes.enableScubaSet);
dataStream.writeBoolean(recipes.enableFreeRunners);
@@ -228,7 +225,6 @@ public class PacketConfigSync implements IMessageHandler<ConfigSyncMessage, IMes
general.controlCircuitOreDict = dataStream.readBoolean();
general.logPackets = dataStream.readBoolean();
general.dynamicTankEasterEgg = dataStream.readBoolean();
general.voiceServerEnabled = dataStream.readBoolean();
general.cardboardSpawners = dataStream.readBoolean();
general.spawnBabySkeletons = dataStream.readBoolean();
general.enableBoPProgression = dataStream.readBoolean();
@@ -244,7 +240,6 @@ public class PacketConfigSync implements IMessageHandler<ConfigSyncMessage, IMes
general.METHANE_BURN_TIME = dataStream.readInt();
general.ENERGY_PER_REDSTONE = dataStream.readDouble();
general.DISASSEMBLER_USAGE = dataStream.readDouble();
general.VOICE_PORT = dataStream.readInt();
general.maxUpgradeMultiplier = dataStream.readInt();
general.energyUnit = EnergyType.values()[dataStream.readInt()];
general.minerSilkMultiplier = dataStream.readDouble();
@@ -391,7 +386,6 @@ public class PacketConfigSync implements IMessageHandler<ConfigSyncMessage, IMes
recipes.enableTeleporterCore = dataStream.readBoolean();
recipes.enableConfigurator = dataStream.readBoolean();
recipes.enableNetworkReader = dataStream.readBoolean();
recipes.enableWalkieTalkie = dataStream.readBoolean();
recipes.enableJetpacks = dataStream.readBoolean();
recipes.enableScubaSet = dataStream.readBoolean();
recipes.enableFreeRunners = dataStream.readBoolean();
@@ -1,50 +0,0 @@
package mekanism.common.network;
import io.netty.buffer.ByteBuf;
import mekanism.common.PacketHandler;
import mekanism.common.item.ItemWalkieTalkie;
import mekanism.common.network.PacketWalkieTalkieState.WalkieTalkieStateMessage;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
public class PacketWalkieTalkieState implements IMessageHandler<WalkieTalkieStateMessage, IMessage>
{
@Override
public IMessage onMessage(WalkieTalkieStateMessage message, MessageContext context)
{
ItemStack itemstack = PacketHandler.getPlayer(context).getCurrentEquippedItem();
if(itemstack != null && itemstack.getItem() instanceof ItemWalkieTalkie)
{
((ItemWalkieTalkie)itemstack.getItem()).setChannel(itemstack, message.channel);
}
return null;
}
public static class WalkieTalkieStateMessage implements IMessage
{
public int channel;
public WalkieTalkieStateMessage() {}
public WalkieTalkieStateMessage(int chan)
{
channel = chan;
}
@Override
public void toBytes(ByteBuf dataStream)
{
dataStream.writeInt(channel);
}
@Override
public void fromBytes(ByteBuf dataStream)
{
channel = dataStream.readInt();
}
}
}
@@ -3,7 +3,6 @@ package mekanism.common.util;
import ic2.api.energy.EnergyNet;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -160,18 +159,6 @@ public final class MekanismUtils
return false;
}
/**
* Updates the donator list by retrieving the most recent information from a foreign document.
*/
public static void updateDonators()
{
Mekanism.donators.clear();
for(String s : getHTML("http://aidancbrady.com/data/capes/Mekanism.txt"))
{
Mekanism.donators.add(s);
}
}
/**
* Returns one line of HTML from the url.
@@ -243,20 +230,6 @@ public final class MekanismUtils
return true;
}
/**
* Checks if Minecraft is running in offline mode.
* @return if mod is running in offline mode.
*/
public static boolean isOffline()
{
try {
new URL("http://www.apple.com").openConnection().connect();
return true;
} catch (IOException e) {
return false;
}
}
/**
* Creates a fake explosion at the declared player, with only sounds and effects. No damage is caused to either blocks or the player.
* @param entityplayer - player to explode
@@ -1,203 +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 cpw.mods.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 l = Collections.synchronizedList((List)((ArrayList)server.getConfigurationManager().playerEntityList).clone());
for(Object obj : l)
{
if(obj instanceof EntityPlayerMP)
{
EntityPlayerMP playerMP = (EntityPlayerMP)obj;
String playerIP = playerMP.getPlayerIP();
if(!server.isDedicatedServer() && playerIP.equals("local") && !Mekanism.voiceManager.foundLocal)
{
Mekanism.voiceManager.foundLocal = true;
username = playerMP.getCommandSenderName();
break;
}
else if(playerIP.equals(socket.getInetAddress().getHostAddress()))
{
username = playerMP.getCommandSenderName();
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(new Runnable()
{
@Override
public void run()
{
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(itemStack != null)
{
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().getCurrentEquippedItem();
if(itemStack != null)
{
ItemWalkieTalkie walkieTalkie = (ItemWalkieTalkie)itemStack.getItem();
if(walkieTalkie != null)
{
if(walkieTalkie.getOn(itemStack))
{
return walkieTalkie.getChannel(itemStack);
}
}
}
return 0;
}
public EntityPlayerMP getPlayer()
{
return server.getConfigurationManager().func_152612_a(username); //TODO getPlayerForUsername
}
}
@@ -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.api.MekanismConfig.general;
import mekanism.common.Mekanism;
public class VoiceServerManager
{
public Set<VoiceConnection> connections = new HashSet<VoiceConnection>();
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 e) {
} catch(NullPointerException e) {
} catch(Exception e) {
Mekanism.logger.error("VoiceServer: Error while accepting connection.");
e.printStackTrace();
}
}
}
}
}