<1.1.5> Fix voice chat issue in EaglerXVelocity

This commit is contained in:
lax1dude 2024-12-01 23:03:34 -08:00
parent 28b7627a0f
commit 919014b4df
5 changed files with 96 additions and 51 deletions

View File

@ -17,13 +17,13 @@ package net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity;
*/ */
public class EaglerXVelocityVersion { 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 ID = "EaglerXVelocity";
public static final String PLUGIN_ID = "eaglerxvelocity"; public static final String PLUGIN_ID = "eaglerxvelocity";
public static final String NAME = "EaglercraftXVelocity"; 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 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" }; public static final String[] AUTHORS = new String[] { "lax1dude", "ayunami2000" };
} }

View File

@ -5,6 +5,7 @@ import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; 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.EaglerPlayerData;
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.server.backend_rpc_protocol.EnumSubscribedEvent; 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.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.SPacketVoiceSignalConnectV3EAG;
import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.server.SPacketVoiceSignalConnectV4EAG; import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.server.SPacketVoiceSignalConnectV4EAG;
import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.server.SPacketVoiceSignalDescEAG; import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.server.SPacketVoiceSignalDescEAG;
@ -101,13 +103,15 @@ public class VoiceServerImpl {
} }
void handleVoiceSignalPacketTypeRequest(UUID player, EaglerPlayerData sender) { void handleVoiceSignalPacketTypeRequest(UUID player, EaglerPlayerData sender) {
UUID senderUUID;
EaglerPlayerData targetPlayerCon;
synchronized (voicePlayers) { synchronized (voicePlayers) {
UUID senderUUID = sender.getUniqueId(); senderUUID = sender.getUniqueId();
if (senderUUID.equals(player)) if (senderUUID.equals(player))
return; // prevent duplicates return; // prevent duplicates
if (!voicePlayers.containsKey(senderUUID)) if (!voicePlayers.containsKey(senderUUID))
return; return;
EaglerPlayerData targetPlayerCon = voicePlayers.get(player); targetPlayerCon = voicePlayers.get(player);
if (targetPlayerCon == null) if (targetPlayerCon == null)
return; return;
VoicePair newPair = new VoicePair(player, senderUUID); VoicePair newPair = new VoicePair(player, senderUUID);
@ -132,22 +136,24 @@ public class VoiceServerImpl {
voiceRequests.remove(senderUUID); voiceRequests.remove(senderUUID);
// send each other add data // send each other add data
voicePairs.add(newPair); voicePairs.add(newPair);
if (targetPlayerCon.getEaglerProtocol().ver <= 3) { }else {
targetPlayerCon.sendEaglerMessage(new SPacketVoiceSignalConnectV3EAG( return;
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));
}
} }
} }
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) { void handleVoiceSignalPacketTypeConnect(EaglerPlayerData sender) {
@ -158,26 +164,46 @@ public class VoiceServerImpl {
if(sender.getRPCEventSubscribed(EnumSubscribedEvent.TOGGLE_VOICE)) { if(sender.getRPCEventSubscribed(EnumSubscribedEvent.TOGGLE_VOICE)) {
sender.getRPCSessionHandler().handleVoiceStateTransition(SPacketRPCEventToggledVoice.VOICE_STATE_ENABLED); sender.getRPCSessionHandler().handleVoiceStateTransition(SPacketRPCEventToggledVoice.VOICE_STATE_ENABLED);
} }
UUID senderUuid = sender.getUniqueId();
List<EaglerPlayerData> lst;
synchronized (voicePlayers) { synchronized (voicePlayers) {
if (voicePlayers.containsKey(sender.getUniqueId())) { if (voicePlayers.containsKey(senderUuid)) {
return; return;
} }
boolean hasNoOtherPlayers = voicePlayers.isEmpty(); boolean hasNoOtherPlayers = voicePlayers.isEmpty();
voicePlayers.put(sender.getUniqueId(), sender); voicePlayers.put(senderUuid, sender);
if (hasNoOtherPlayers) { if (hasNoOtherPlayers) {
return; return;
} }
Collection<SPacketVoiceSignalGlobalEAG.UserData> userDatas = new ArrayList<>(voicePlayers.size()); lst = new ArrayList<>(voicePlayers.values());
for(EaglerPlayerData userCon : voicePlayers.values()) { }
UUID uuid = userCon.getUniqueId(); GameMessagePacket v3p = null;
userDatas.add(new SPacketVoiceSignalGlobalEAG.UserData(uuid.getMostSignificantBits(), GameMessagePacket v4p = null;
uuid.getLeastSignificantBits(), userCon.getName())); for (EaglerPlayerData handler : lst) {
} if (handler.getEaglerProtocol().ver <= 3) {
GameMessagePacket packetToBroadcast = new SPacketVoiceSignalGlobalEAG(userDatas); handler.sendEaglerMessage(
for (EaglerPlayerData userCon : voicePlayers.values()) { v3p == null
userCon.sendEaglerMessage(packetToBroadcast); ? (v3p = new SPacketVoiceSignalConnectV3EAG(senderUuid.getMostSignificantBits(),
senderUuid.getLeastSignificantBits(), true, false))
: v3p);
} else {
handler.sendEaglerMessage(
v4p == null
? (v4p = new SPacketVoiceSignalConnectAnnounceV4EAG(senderUuid.getMostSignificantBits(),
senderUuid.getLeastSignificantBits()))
: v4p);
} }
} }
Collection<SPacketVoiceSignalGlobalEAG.UserData> 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) { void handleVoiceSignalPacketTypeICE(UUID player, byte[] str, EaglerPlayerData sender) {
@ -211,6 +237,7 @@ public class VoiceServerImpl {
} }
void handleVoiceSignalPacketTypeDisconnectPeer(UUID player, EaglerPlayerData sender) { void handleVoiceSignalPacketTypeDisconnectPeer(UUID player, EaglerPlayerData sender) {
List<Runnable> peersToDisconnect = new ArrayList<>();
synchronized (voicePlayers) { synchronized (voicePlayers) {
if (!voicePlayers.containsKey(player)) { if (!voicePlayers.containsKey(player)) {
return; return;
@ -226,28 +253,39 @@ public class VoiceServerImpl {
} }
if (target != null) { if (target != null) {
pairsItr.remove(); pairsItr.remove();
EaglerPlayerData conn = voicePlayers.get(target); final EaglerPlayerData conn = voicePlayers.get(target);
if (conn != null) { final UUID target2 = target;
conn.sendEaglerMessage(new SPacketVoiceSignalDisconnectPeerEAG(player.getMostSignificantBits(), peersToDisconnect.add(() -> {
player.getLeastSignificantBits())); if (conn != null) {
} conn.sendEaglerMessage(new SPacketVoiceSignalDisconnectPeerEAG(player.getMostSignificantBits(),
sender.sendEaglerMessage(new SPacketVoiceSignalDisconnectPeerEAG(target.getMostSignificantBits(), player.getLeastSignificantBits()));
target.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<Runnable> peersToDisconnect;
synchronized (voicePlayers) { synchronized (voicePlayers) {
EaglerPlayerData connRemove; final EaglerPlayerData connRemove;
if ((connRemove = voicePlayers.remove(user)) == null) { if ((connRemove = voicePlayers.remove(user)) == null) {
return; return;
}else { }
connRemove.fireVoiceStateChange(EaglercraftVoiceStatusChangeEvent.EnumVoiceState.DISABLED); peersToDisconnect = new ArrayList<>();
if(connRemove.getRPCEventSubscribed(EnumSubscribedEvent.TOGGLE_VOICE)) { if(connRemove != null){
connRemove.getRPCSessionHandler().handleVoiceStateTransition(SPacketRPCEventToggledVoice.VOICE_STATE_DISABLED); peersToDisconnect.add(() -> {
} connRemove.fireVoiceStateChange(EaglercraftVoiceStatusChangeEvent.EnumVoiceState.DISABLED);
if(connRemove.getRPCEventSubscribed(EnumSubscribedEvent.TOGGLE_VOICE)) {
connRemove.getRPCSessionHandler().handleVoiceStateTransition(SPacketRPCEventToggledVoice.VOICE_STATE_DISABLED);
}
});
} }
voiceRequests.remove(user); voiceRequests.remove(user);
if (voicePlayers.size() > 0) { if (voicePlayers.size() > 0) {
@ -257,10 +295,12 @@ public class VoiceServerImpl {
userDatas.add(new SPacketVoiceSignalGlobalEAG.UserData(uuid.getMostSignificantBits(), userDatas.add(new SPacketVoiceSignalGlobalEAG.UserData(uuid.getMostSignificantBits(),
uuid.getLeastSignificantBits(), userCon.getName())); uuid.getLeastSignificantBits(), userCon.getName()));
} }
GameMessagePacket voicePlayersPkt = new SPacketVoiceSignalGlobalEAG(userDatas); final GameMessagePacket voicePlayersPkt = new SPacketVoiceSignalGlobalEAG(userDatas);
for (EaglerPlayerData userCon : voicePlayers.values()) { for (final EaglerPlayerData userCon : voicePlayers.values()) {
if (!user.equals(userCon.getUniqueId())) { if (!user.equals(userCon.getUniqueId())) {
userCon.sendEaglerMessage(voicePlayersPkt); peersToDisconnect.add(() -> {
userCon.sendEaglerMessage(voicePlayersPkt);
});
} }
} }
} }
@ -276,15 +316,20 @@ public class VoiceServerImpl {
if (target != null) { if (target != null) {
pairsItr.remove(); pairsItr.remove();
if (voicePlayers.size() > 0) { if (voicePlayers.size() > 0) {
EaglerPlayerData conn = voicePlayers.get(target); final EaglerPlayerData conn = voicePlayers.get(target);
if (conn != null) { if (conn != null) {
conn.sendEaglerMessage(new SPacketVoiceSignalDisconnectPeerEAG( peersToDisconnect.add(() -> {
user.getMostSignificantBits(), user.getLeastSignificantBits())); conn.sendEaglerMessage(new SPacketVoiceSignalDisconnectPeerEAG(
user.getMostSignificantBits(), user.getLeastSignificantBits()));
});
} }
} }
} }
} }
} }
for(Runnable r : peersToDisconnect) {
r.run();
}
} }
EnumVoiceState getPlayerVoiceState(UUID uniqueId) { EnumVoiceState getPlayerVoiceState(UUID uniqueId) {

View File

@ -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"} {"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"}

View File

@ -1 +1 @@
1.1.4 1.1.5