<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,6 +136,10 @@ 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);
}else {
return;
}
}
if (targetPlayerCon.getEaglerProtocol().ver <= 3) { if (targetPlayerCon.getEaglerProtocol().ver <= 3) {
targetPlayerCon.sendEaglerMessage(new SPacketVoiceSignalConnectV3EAG( targetPlayerCon.sendEaglerMessage(new SPacketVoiceSignalConnectV3EAG(
senderUUID.getMostSignificantBits(), senderUUID.getLeastSignificantBits(), false, false)); senderUUID.getMostSignificantBits(), senderUUID.getLeastSignificantBits(), false, false));
@ -147,8 +155,6 @@ public class VoiceServerImpl {
player.getMostSignificantBits(), player.getLeastSignificantBits(), true)); player.getMostSignificantBits(), player.getLeastSignificantBits(), true));
} }
} }
}
}
void handleVoiceSignalPacketTypeConnect(EaglerPlayerData sender) { void handleVoiceSignalPacketTypeConnect(EaglerPlayerData sender) {
if(!sender.voiceConnectRateLimiter.rateLimit(VOICE_CONNECT_RATELIMIT)) { if(!sender.voiceConnectRateLimiter.rateLimit(VOICE_CONNECT_RATELIMIT)) {
@ -158,27 +164,47 @@ 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;
} }
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<SPacketVoiceSignalGlobalEAG.UserData> userDatas = new ArrayList<>(voicePlayers.size()); Collection<SPacketVoiceSignalGlobalEAG.UserData> userDatas = new ArrayList<>(voicePlayers.size());
for(EaglerPlayerData userCon : voicePlayers.values()) { for(EaglerPlayerData userCon : lst) {
UUID uuid = userCon.getUniqueId(); UUID uuid = userCon.getUniqueId();
userDatas.add(new SPacketVoiceSignalGlobalEAG.UserData(uuid.getMostSignificantBits(), userDatas.add(new SPacketVoiceSignalGlobalEAG.UserData(uuid.getMostSignificantBits(),
uuid.getLeastSignificantBits(), userCon.getName())); uuid.getLeastSignificantBits(), userCon.getName()));
} }
GameMessagePacket packetToBroadcast = new SPacketVoiceSignalGlobalEAG(userDatas); GameMessagePacket packetToBroadcast = new SPacketVoiceSignalGlobalEAG(userDatas);
for (EaglerPlayerData userCon : voicePlayers.values()) { for (EaglerPlayerData userCon : lst) {
userCon.sendEaglerMessage(packetToBroadcast); userCon.sendEaglerMessage(packetToBroadcast);
} }
} }
}
void handleVoiceSignalPacketTypeICE(UUID player, byte[] str, EaglerPlayerData sender) { void handleVoiceSignalPacketTypeICE(UUID player, byte[] str, EaglerPlayerData sender) {
EaglerPlayerData pass; EaglerPlayerData pass;
@ -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);
final UUID target2 = target;
peersToDisconnect.add(() -> {
if (conn != null) { if (conn != null) {
conn.sendEaglerMessage(new SPacketVoiceSignalDisconnectPeerEAG(player.getMostSignificantBits(), conn.sendEaglerMessage(new SPacketVoiceSignalDisconnectPeerEAG(player.getMostSignificantBits(),
player.getLeastSignificantBits())); player.getLeastSignificantBits()));
} }
sender.sendEaglerMessage(new SPacketVoiceSignalDisconnectPeerEAG(target.getMostSignificantBits(), sender.sendEaglerMessage(new SPacketVoiceSignalDisconnectPeerEAG(target2.getMostSignificantBits(),
target.getLeastSignificantBits())); 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 { }
peersToDisconnect = new ArrayList<>();
if(connRemove != null){
peersToDisconnect.add(() -> {
connRemove.fireVoiceStateChange(EaglercraftVoiceStatusChangeEvent.EnumVoiceState.DISABLED); connRemove.fireVoiceStateChange(EaglercraftVoiceStatusChangeEvent.EnumVoiceState.DISABLED);
if(connRemove.getRPCEventSubscribed(EnumSubscribedEvent.TOGGLE_VOICE)) { if(connRemove.getRPCEventSubscribed(EnumSubscribedEvent.TOGGLE_VOICE)) {
connRemove.getRPCSessionHandler().handleVoiceStateTransition(SPacketRPCEventToggledVoice.VOICE_STATE_DISABLED); 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())) {
peersToDisconnect.add(() -> {
userCon.sendEaglerMessage(voicePlayersPkt); 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) {
peersToDisconnect.add(() -> {
conn.sendEaglerMessage(new SPacketVoiceSignalDisconnectPeerEAG( conn.sendEaglerMessage(new SPacketVoiceSignalDisconnectPeerEAG(
user.getMostSignificantBits(), user.getLeastSignificantBits())); 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