diff --git a/gateway/EaglercraftXVelocity/EaglerXVelocity-Latest.jar b/gateway/EaglercraftXVelocity/EaglerXVelocity-Latest.jar index a06b780..c2f3cb0 100644 Binary files a/gateway/EaglercraftXVelocity/EaglerXVelocity-Latest.jar and b/gateway/EaglercraftXVelocity/EaglerXVelocity-Latest.jar differ diff --git a/gateway/EaglercraftXVelocity/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_velocity/EaglerXVelocityVersion.java b/gateway/EaglercraftXVelocity/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_velocity/EaglerXVelocityVersion.java index 55c7250..83d4d03 100644 --- a/gateway/EaglercraftXVelocity/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_velocity/EaglerXVelocityVersion.java +++ b/gateway/EaglercraftXVelocity/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_velocity/EaglerXVelocityVersion.java @@ -17,13 +17,13 @@ package net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity; */ public class EaglerXVelocityVersion { - public static final String NATIVE_VELOCITY_BUILD = "3.4.0-SNAPSHOT:cefa3b27:b450"; + public static final String NATIVE_VELOCITY_BUILD = "3.4.0-SNAPSHOT:a33f2d1a:b452"; public static final String ID = "EaglerXVelocity"; public static final String PLUGIN_ID = "eaglerxvelocity"; public static final String NAME = "EaglercraftXVelocity"; public static final String DESCRIPTION = "Plugin to allow EaglercraftX 1.8 players to join your network, or allow EaglercraftX 1.8 players to use your network as a proxy to join other networks"; - public static final String VERSION = "1.1.4"; + public static final String VERSION = "1.1.5"; public static final String[] AUTHORS = new String[] { "lax1dude", "ayunami2000" }; } diff --git a/gateway/EaglercraftXVelocity/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_velocity/voice/VoiceServerImpl.java b/gateway/EaglercraftXVelocity/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_velocity/voice/VoiceServerImpl.java index 808366c..90b0d3e 100644 --- a/gateway/EaglercraftXVelocity/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_velocity/voice/VoiceServerImpl.java +++ b/gateway/EaglercraftXVelocity/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_velocity/voice/VoiceServerImpl.java @@ -5,6 +5,7 @@ import java.util.Collection; 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 java.util.UUID; @@ -17,6 +18,7 @@ import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.api.event.Eaglercra import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.server.EaglerPlayerData; import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.server.backend_rpc_protocol.EnumSubscribedEvent; import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.GameMessagePacket; +import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.server.SPacketVoiceSignalConnectAnnounceV4EAG; import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.server.SPacketVoiceSignalConnectV3EAG; import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.server.SPacketVoiceSignalConnectV4EAG; import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.server.SPacketVoiceSignalDescEAG; @@ -101,13 +103,15 @@ public class VoiceServerImpl { } void handleVoiceSignalPacketTypeRequest(UUID player, EaglerPlayerData sender) { + UUID senderUUID; + EaglerPlayerData targetPlayerCon; synchronized (voicePlayers) { - UUID senderUUID = sender.getUniqueId(); + senderUUID = sender.getUniqueId(); if (senderUUID.equals(player)) return; // prevent duplicates if (!voicePlayers.containsKey(senderUUID)) return; - EaglerPlayerData targetPlayerCon = voicePlayers.get(player); + targetPlayerCon = voicePlayers.get(player); if (targetPlayerCon == null) return; VoicePair newPair = new VoicePair(player, senderUUID); @@ -132,22 +136,24 @@ public class VoiceServerImpl { voiceRequests.remove(senderUUID); // send each other add data voicePairs.add(newPair); - if (targetPlayerCon.getEaglerProtocol().ver <= 3) { - targetPlayerCon.sendEaglerMessage(new SPacketVoiceSignalConnectV3EAG( - senderUUID.getMostSignificantBits(), senderUUID.getLeastSignificantBits(), false, false)); - } else { - targetPlayerCon.sendEaglerMessage(new SPacketVoiceSignalConnectV4EAG( - senderUUID.getMostSignificantBits(), senderUUID.getLeastSignificantBits(), false)); - } - if (sender.getEaglerProtocol().ver <= 3) { - sender.sendEaglerMessage(new SPacketVoiceSignalConnectV3EAG( - player.getMostSignificantBits(), player.getLeastSignificantBits(), false, true)); - } else { - sender.sendEaglerMessage(new SPacketVoiceSignalConnectV4EAG( - player.getMostSignificantBits(), player.getLeastSignificantBits(), true)); - } + }else { + return; } } + if (targetPlayerCon.getEaglerProtocol().ver <= 3) { + targetPlayerCon.sendEaglerMessage(new SPacketVoiceSignalConnectV3EAG( + senderUUID.getMostSignificantBits(), senderUUID.getLeastSignificantBits(), false, false)); + } else { + targetPlayerCon.sendEaglerMessage(new SPacketVoiceSignalConnectV4EAG( + senderUUID.getMostSignificantBits(), senderUUID.getLeastSignificantBits(), false)); + } + if (sender.getEaglerProtocol().ver <= 3) { + sender.sendEaglerMessage(new SPacketVoiceSignalConnectV3EAG( + player.getMostSignificantBits(), player.getLeastSignificantBits(), false, true)); + } else { + sender.sendEaglerMessage(new SPacketVoiceSignalConnectV4EAG( + player.getMostSignificantBits(), player.getLeastSignificantBits(), true)); + } } void handleVoiceSignalPacketTypeConnect(EaglerPlayerData sender) { @@ -158,26 +164,46 @@ public class VoiceServerImpl { if(sender.getRPCEventSubscribed(EnumSubscribedEvent.TOGGLE_VOICE)) { sender.getRPCSessionHandler().handleVoiceStateTransition(SPacketRPCEventToggledVoice.VOICE_STATE_ENABLED); } + UUID senderUuid = sender.getUniqueId(); + List lst; synchronized (voicePlayers) { - if (voicePlayers.containsKey(sender.getUniqueId())) { + if (voicePlayers.containsKey(senderUuid)) { return; } boolean hasNoOtherPlayers = voicePlayers.isEmpty(); - voicePlayers.put(sender.getUniqueId(), sender); + voicePlayers.put(senderUuid, sender); if (hasNoOtherPlayers) { return; } - Collection userDatas = new ArrayList<>(voicePlayers.size()); - for(EaglerPlayerData userCon : voicePlayers.values()) { - UUID uuid = userCon.getUniqueId(); - userDatas.add(new SPacketVoiceSignalGlobalEAG.UserData(uuid.getMostSignificantBits(), - uuid.getLeastSignificantBits(), userCon.getName())); - } - GameMessagePacket packetToBroadcast = new SPacketVoiceSignalGlobalEAG(userDatas); - for (EaglerPlayerData userCon : voicePlayers.values()) { - userCon.sendEaglerMessage(packetToBroadcast); + lst = new ArrayList<>(voicePlayers.values()); + } + GameMessagePacket v3p = null; + GameMessagePacket v4p = null; + for (EaglerPlayerData handler : lst) { + if (handler.getEaglerProtocol().ver <= 3) { + handler.sendEaglerMessage( + v3p == null + ? (v3p = new SPacketVoiceSignalConnectV3EAG(senderUuid.getMostSignificantBits(), + senderUuid.getLeastSignificantBits(), true, false)) + : v3p); + } else { + handler.sendEaglerMessage( + v4p == null + ? (v4p = new SPacketVoiceSignalConnectAnnounceV4EAG(senderUuid.getMostSignificantBits(), + senderUuid.getLeastSignificantBits())) + : v4p); } } + Collection userDatas = new ArrayList<>(voicePlayers.size()); + for(EaglerPlayerData userCon : lst) { + UUID uuid = userCon.getUniqueId(); + userDatas.add(new SPacketVoiceSignalGlobalEAG.UserData(uuid.getMostSignificantBits(), + uuid.getLeastSignificantBits(), userCon.getName())); + } + GameMessagePacket packetToBroadcast = new SPacketVoiceSignalGlobalEAG(userDatas); + for (EaglerPlayerData userCon : lst) { + userCon.sendEaglerMessage(packetToBroadcast); + } } void handleVoiceSignalPacketTypeICE(UUID player, byte[] str, EaglerPlayerData sender) { @@ -211,6 +237,7 @@ public class VoiceServerImpl { } void handleVoiceSignalPacketTypeDisconnectPeer(UUID player, EaglerPlayerData sender) { + List peersToDisconnect = new ArrayList<>(); synchronized (voicePlayers) { if (!voicePlayers.containsKey(player)) { return; @@ -226,28 +253,39 @@ public class VoiceServerImpl { } if (target != null) { pairsItr.remove(); - EaglerPlayerData conn = voicePlayers.get(target); - if (conn != null) { - conn.sendEaglerMessage(new SPacketVoiceSignalDisconnectPeerEAG(player.getMostSignificantBits(), - player.getLeastSignificantBits())); - } - sender.sendEaglerMessage(new SPacketVoiceSignalDisconnectPeerEAG(target.getMostSignificantBits(), - target.getLeastSignificantBits())); + final EaglerPlayerData conn = voicePlayers.get(target); + final UUID target2 = target; + peersToDisconnect.add(() -> { + if (conn != null) { + conn.sendEaglerMessage(new SPacketVoiceSignalDisconnectPeerEAG(player.getMostSignificantBits(), + player.getLeastSignificantBits())); + } + sender.sendEaglerMessage(new SPacketVoiceSignalDisconnectPeerEAG(target2.getMostSignificantBits(), + target2.getLeastSignificantBits())); + }); } } } + for(Runnable r : peersToDisconnect) { + r.run(); + } } - public void removeUser(UUID user) { + public void removeUser(final UUID user) { + List peersToDisconnect; synchronized (voicePlayers) { - EaglerPlayerData connRemove; + final EaglerPlayerData connRemove; if ((connRemove = voicePlayers.remove(user)) == null) { return; - }else { - connRemove.fireVoiceStateChange(EaglercraftVoiceStatusChangeEvent.EnumVoiceState.DISABLED); - if(connRemove.getRPCEventSubscribed(EnumSubscribedEvent.TOGGLE_VOICE)) { - connRemove.getRPCSessionHandler().handleVoiceStateTransition(SPacketRPCEventToggledVoice.VOICE_STATE_DISABLED); - } + } + peersToDisconnect = new ArrayList<>(); + if(connRemove != null){ + peersToDisconnect.add(() -> { + connRemove.fireVoiceStateChange(EaglercraftVoiceStatusChangeEvent.EnumVoiceState.DISABLED); + if(connRemove.getRPCEventSubscribed(EnumSubscribedEvent.TOGGLE_VOICE)) { + connRemove.getRPCSessionHandler().handleVoiceStateTransition(SPacketRPCEventToggledVoice.VOICE_STATE_DISABLED); + } + }); } voiceRequests.remove(user); if (voicePlayers.size() > 0) { @@ -257,10 +295,12 @@ public class VoiceServerImpl { userDatas.add(new SPacketVoiceSignalGlobalEAG.UserData(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits(), userCon.getName())); } - GameMessagePacket voicePlayersPkt = new SPacketVoiceSignalGlobalEAG(userDatas); - for (EaglerPlayerData userCon : voicePlayers.values()) { + final GameMessagePacket voicePlayersPkt = new SPacketVoiceSignalGlobalEAG(userDatas); + for (final EaglerPlayerData userCon : voicePlayers.values()) { if (!user.equals(userCon.getUniqueId())) { - userCon.sendEaglerMessage(voicePlayersPkt); + peersToDisconnect.add(() -> { + userCon.sendEaglerMessage(voicePlayersPkt); + }); } } } @@ -276,15 +316,20 @@ public class VoiceServerImpl { if (target != null) { pairsItr.remove(); if (voicePlayers.size() > 0) { - EaglerPlayerData conn = voicePlayers.get(target); + final EaglerPlayerData conn = voicePlayers.get(target); if (conn != null) { - conn.sendEaglerMessage(new SPacketVoiceSignalDisconnectPeerEAG( - user.getMostSignificantBits(), user.getLeastSignificantBits())); + peersToDisconnect.add(() -> { + conn.sendEaglerMessage(new SPacketVoiceSignalDisconnectPeerEAG( + user.getMostSignificantBits(), user.getLeastSignificantBits())); + }); } } } } } + for(Runnable r : peersToDisconnect) { + r.run(); + } } EnumVoiceState getPlayerVoiceState(UUID uniqueId) { diff --git a/gateway/EaglercraftXVelocity/src/main/resources/velocity-plugin.json b/gateway/EaglercraftXVelocity/src/main/resources/velocity-plugin.json index 7fd3bf4..6d8420e 100644 --- a/gateway/EaglercraftXVelocity/src/main/resources/velocity-plugin.json +++ b/gateway/EaglercraftXVelocity/src/main/resources/velocity-plugin.json @@ -1 +1 @@ -{"id":"eaglerxvelocity","name":"EaglercraftXVelocity","version":"1.1.4","description":"Plugin to allow EaglercraftX 1.8 players to join your network, or allow EaglercraftX 1.8 players to use your network as a proxy to join other networks","authors":["lax1dude", "ayunami2000"],"dependencies":[],"main":"net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.EaglerXVelocity"} \ No newline at end of file +{"id":"eaglerxvelocity","name":"EaglercraftXVelocity","version":"1.1.5","description":"Plugin to allow EaglercraftX 1.8 players to join your network, or allow EaglercraftX 1.8 players to use your network as a proxy to join other networks","authors":["lax1dude", "ayunami2000"],"dependencies":[],"main":"net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.EaglerXVelocity"} \ No newline at end of file diff --git a/gateway_version_velocity b/gateway_version_velocity index 1b87bcd..314c3d7 100644 --- a/gateway_version_velocity +++ b/gateway_version_velocity @@ -1 +1 @@ -1.1.4 \ No newline at end of file +1.1.5 \ No newline at end of file