mirror of
https://github.com/Eaglercraft-Archive/Eaglercraftx-1.8.8-src.git
synced 2025-06-27 18:38:14 -05:00
Update #37 - Touch support without userscript, many other feats
This commit is contained in:
@ -5,6 +5,8 @@ import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2022 ayunami2000. All Rights Reserved.
|
||||
*
|
||||
@ -42,7 +44,7 @@ public class ExpiringSet<T> extends HashSet<T> {
|
||||
|
||||
public void checkForExpirations() {
|
||||
Iterator<T> iterator = this.timestamps.keySet().iterator();
|
||||
long now = System.currentTimeMillis();
|
||||
long now = EagRuntime.steadyTimeMillis();
|
||||
while (iterator.hasNext()) {
|
||||
T element = iterator.next();
|
||||
if (super.contains(element)) {
|
||||
@ -61,7 +63,7 @@ public class ExpiringSet<T> extends HashSet<T> {
|
||||
public boolean add(T o) {
|
||||
checkForExpirations();
|
||||
boolean success = super.add(o);
|
||||
if (success) timestamps.put(o, System.currentTimeMillis());
|
||||
if (success) timestamps.put(o, EagRuntime.steadyTimeMillis());
|
||||
return success;
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,10 @@ import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
|
||||
import net.lax1dude.eaglercraft.v1_8.EaglercraftUUID;
|
||||
import net.lax1dude.eaglercraft.v1_8.Keyboard;
|
||||
import net.lax1dude.eaglercraft.v1_8.PointerInputAbstraction;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.sp.gui.GuiSlider2;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@ -124,17 +126,8 @@ public class GuiVoiceMenu extends Gui {
|
||||
|
||||
public void initGui() {
|
||||
this.sliderBlocks = new GuiSlider2(-1, (width - 150) / 2, height / 3 + 20, 150, 20, (VoiceClientController.getVoiceProximity() - 5) / 17.0f, 1.0f) {
|
||||
public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) {
|
||||
if(super.mousePressed(par1Minecraft, par2, par3)) {
|
||||
this.displayString = "" + (int)((sliderValue * 17.0f) + 5.0f) + " Blocks";
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public void mouseDragged(Minecraft par1Minecraft, int par2, int par3) {
|
||||
super.mouseDragged(par1Minecraft, par2, par3);
|
||||
this.displayString = "" + (int)((sliderValue * 17.0f) + 5.0f) + " Blocks";
|
||||
protected String updateDisplayString() {
|
||||
return (int)((sliderValue * 17.0f) + 5.0f) + " Blocks";
|
||||
}
|
||||
};
|
||||
sliderBlocks.displayString = "" + VoiceClientController.getVoiceProximity() + " Blocks";
|
||||
@ -386,7 +379,7 @@ public class GuiVoiceMenu extends Gui {
|
||||
}
|
||||
|
||||
}else if(status == EnumVoiceChannelStatus.CONNECTING) {
|
||||
float fadeTimer = MathHelper.sin((float)((System.currentTimeMillis() % 700l) * 0.0014d) * 3.14159f) * 0.35f + 0.3f;
|
||||
float fadeTimer = MathHelper.sin((float)((EagRuntime.steadyTimeMillis() % 700l) * 0.0014d) * 3.14159f) * 0.35f + 0.3f;
|
||||
txt = I18n.format("voice.connecting");
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
@ -487,7 +480,7 @@ public class GuiVoiceMenu extends Gui {
|
||||
|
||||
drawNotice(I18n.format("voice.unsupportedWarning1"), false, I18n.format("voice.unsupportedWarning2"), I18n.format("voice.unsupportedWarning3"),
|
||||
"", I18n.format("voice.unsupportedWarning4"), I18n.format("voice.unsupportedWarning5"), I18n.format("voice.unsupportedWarning6"),
|
||||
I18n.format("voice.unsupportedWarning7"), I18n.format("voice.unsupportedWarning8"), I18n.format("voice.unsupportedWarning9"));
|
||||
I18n.format("voice.unsupportedWarning7"), "", I18n.format("voice.unsupportedWarning8"), I18n.format("voice.unsupportedWarning9"));
|
||||
|
||||
noticeContinueButton.visible = true;
|
||||
noticeCancelButton.visible = false;
|
||||
@ -495,8 +488,7 @@ public class GuiVoiceMenu extends Gui {
|
||||
|
||||
drawNotice(I18n.format("voice.ipGrabWarning1"), true, I18n.format("voice.ipGrabWarning2"), I18n.format("voice.ipGrabWarning3"),
|
||||
I18n.format("voice.ipGrabWarning4"), "", I18n.format("voice.ipGrabWarning5"), I18n.format("voice.ipGrabWarning6"),
|
||||
I18n.format("voice.ipGrabWarning7"), I18n.format("voice.ipGrabWarning8"), I18n.format("voice.ipGrabWarning9"),
|
||||
I18n.format("voice.ipGrabWarning10"), I18n.format("voice.ipGrabWarning11"), I18n.format("voice.ipGrabWarning12"));
|
||||
I18n.format("voice.ipGrabWarning7"));
|
||||
|
||||
noticeContinueButton.visible = true;
|
||||
noticeCancelButton.visible = true;
|
||||
@ -590,17 +582,21 @@ public class GuiVoiceMenu extends Gui {
|
||||
}
|
||||
|
||||
public void mouseReleased(int par1, int par2, int par3) {
|
||||
applyRadiusButton.mouseReleased(par1, par2);
|
||||
applyVolumeButton.mouseReleased(par1, par2);
|
||||
noticeContinueButton.mouseReleased(par1, par2);
|
||||
noticeCancelButton.mouseReleased(par1, par2);
|
||||
if(par3 != 0 && par3 != 12345) return;
|
||||
boolean touchMode = PointerInputAbstraction.isTouchMode();
|
||||
if(!touchMode || par3 == 0) {
|
||||
applyRadiusButton.mouseReleased(par1, par2);
|
||||
applyVolumeButton.mouseReleased(par1, par2);
|
||||
noticeContinueButton.mouseReleased(par1, par2);
|
||||
noticeCancelButton.mouseReleased(par1, par2);
|
||||
}
|
||||
if(showSliderBlocks || showSliderVolume) {
|
||||
if(showSliderBlocks) {
|
||||
if(par3 == 0) {
|
||||
if(!touchMode || par3 == 12345) {
|
||||
sliderBlocks.mouseReleased(par1, par2);
|
||||
}
|
||||
}else if(showSliderVolume) {
|
||||
if(par3 == 0) {
|
||||
if(!touchMode || par3 == 12345) {
|
||||
sliderListenVolume.mouseReleased(par1, par2);
|
||||
sliderSpeakVolume.mouseReleased(par1, par2);
|
||||
}
|
||||
@ -624,19 +620,23 @@ public class GuiVoiceMenu extends Gui {
|
||||
}
|
||||
|
||||
public void mouseClicked(int mx, int my, int button) {
|
||||
if(button != 0 && button != 12345) return;
|
||||
boolean touchMode = PointerInputAbstraction.isTouchMode();
|
||||
if(showSliderBlocks || showSliderVolume || showPTTKeyConfig || showingCompatWarning || showingTrackingWarning) {
|
||||
if(showSliderBlocks) {
|
||||
sliderBlocks.mousePressed(mc, mx, my);
|
||||
if(!touchMode || button == 12345) {
|
||||
sliderBlocks.mousePressed(mc, mx, my);
|
||||
}
|
||||
}else if(showSliderVolume) {
|
||||
sliderListenVolume.mousePressed(mc, mx, my);
|
||||
sliderSpeakVolume.mousePressed(mc, mx, my);
|
||||
}
|
||||
if(button == 0) {
|
||||
if(applyRadiusButton.mousePressed(mc, mx, my)) actionPerformed(applyRadiusButton);
|
||||
if(applyVolumeButton.mousePressed(mc, mx, my)) actionPerformed(applyVolumeButton);
|
||||
if(noticeContinueButton.mousePressed(mc, mx, my)) actionPerformed(noticeContinueButton);
|
||||
if(noticeCancelButton.mousePressed(mc, mx, my)) actionPerformed(noticeCancelButton);
|
||||
if(!touchMode || button == 12345) {
|
||||
sliderListenVolume.mousePressed(mc, mx, my);
|
||||
sliderSpeakVolume.mousePressed(mc, mx, my);
|
||||
}
|
||||
}
|
||||
if((!touchMode || button == 0) && applyRadiusButton.mousePressed(mc, mx, my)) actionPerformed(applyRadiusButton);
|
||||
if((!touchMode || button == 0) && applyVolumeButton.mousePressed(mc, mx, my)) actionPerformed(applyVolumeButton);
|
||||
if((!touchMode || button == 0) && noticeContinueButton.mousePressed(mc, mx, my)) actionPerformed(noticeContinueButton);
|
||||
if((!touchMode || button == 0) && noticeCancelButton.mousePressed(mc, mx, my)) actionPerformed(noticeCancelButton);
|
||||
throw new AbortedException();
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
|
||||
import net.lax1dude.eaglercraft.v1_8.EaglercraftUUID;
|
||||
import net.lax1dude.eaglercraft.v1_8.Keyboard;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
|
||||
@ -82,7 +83,7 @@ public class GuiVoiceOverlay extends Gui {
|
||||
mc.getTextureManager().bindTexture(voiceGuiIcons);
|
||||
|
||||
if((mc.currentScreen == null || !mc.currentScreen.blockPTTKey()) && Keyboard.isKeyDown(mc.gameSettings.voicePTTKey)) {
|
||||
long millis = System.currentTimeMillis();
|
||||
long millis = EagRuntime.steadyTimeMillis();
|
||||
if(pttTimer == 0l) {
|
||||
pttTimer = millis;
|
||||
}
|
||||
@ -118,7 +119,7 @@ public class GuiVoiceOverlay extends Gui {
|
||||
Set<EaglercraftUUID> speakers = VoiceClientController.getVoiceSpeaking();
|
||||
Set<EaglercraftUUID> muted = VoiceClientController.getVoiceMuted();
|
||||
|
||||
List<EaglercraftUUID> listenerList = new ArrayList();
|
||||
List<EaglercraftUUID> listenerList = new ArrayList<>();
|
||||
listenerList.addAll(listeners);
|
||||
listenerList.removeAll(muted);
|
||||
|
||||
@ -145,7 +146,7 @@ public class GuiVoiceOverlay extends Gui {
|
||||
hh -= 15;
|
||||
}
|
||||
|
||||
List<String> listenerListStr = new ArrayList(Math.min(5, listenerList.size()));
|
||||
List<String> listenerListStr = new ArrayList<>(Math.min(5, listenerList.size()));
|
||||
|
||||
int left = 50;
|
||||
for(int i = 0, l = listenerList.size(); i < l && i < 5; ++i) {
|
||||
@ -196,7 +197,7 @@ public class GuiVoiceOverlay extends Gui {
|
||||
Set<EaglercraftUUID> speakers = VoiceClientController.getVoiceSpeaking();
|
||||
Set<EaglercraftUUID> muted = VoiceClientController.getVoiceMuted();
|
||||
|
||||
List<EaglercraftUUID> listenerList = new ArrayList();
|
||||
List<EaglercraftUUID> listenerList = new ArrayList<>();
|
||||
listenerList.addAll(speakers);
|
||||
listenerList.removeAll(muted);
|
||||
|
||||
@ -209,7 +210,7 @@ public class GuiVoiceOverlay extends Gui {
|
||||
hh -= 15;
|
||||
}
|
||||
|
||||
List<String> listenerListStr = new ArrayList(Math.min(5, listenerList.size()));
|
||||
List<String> listenerListStr = new ArrayList<>(Math.min(5, listenerList.size()));
|
||||
|
||||
int left = 50;
|
||||
for(int i = 0, l = listenerList.size(); i < l && i < 5; ++i) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.voice;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@ -16,9 +17,11 @@ import net.lax1dude.eaglercraft.v1_8.internal.PlatformVoiceClient;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
||||
import net.lax1dude.eaglercraft.v1_8.profile.EaglerProfile;
|
||||
import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.GameMessagePacket;
|
||||
import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.client.*;
|
||||
import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.server.SPacketVoiceSignalGlobalEAG;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2022-2024 lax1dude, ayunami2000. All Rights Reserved.
|
||||
@ -43,7 +46,8 @@ public class VoiceClientController {
|
||||
|
||||
private static boolean clientSupport = false;
|
||||
private static boolean serverSupport = false;
|
||||
private static Consumer<PacketBuffer> packetSendCallback = null;
|
||||
private static Consumer<GameMessagePacket> packetSendCallback = null;
|
||||
private static int protocolVersion = -1;
|
||||
private static EnumVoiceChannelType voiceChannel = EnumVoiceChannelType.NONE;
|
||||
private static final HashSet<EaglercraftUUID> nearbyPlayers = new HashSet<>();
|
||||
private static final ExpiringSet<EaglercraftUUID> recentlyNearbyPlayers = new ExpiringSet<>(5000, uuid -> {
|
||||
@ -71,17 +75,14 @@ public class VoiceClientController {
|
||||
return serverSupport;
|
||||
}
|
||||
|
||||
public static void initializeVoiceClient(Consumer<PacketBuffer> signalSendCallbackIn) {
|
||||
public static void initializeVoiceClient(Consumer<GameMessagePacket> signalSendCallbackIn, int proto) {
|
||||
packetSendCallback = signalSendCallbackIn;
|
||||
protocolVersion = proto;
|
||||
uuidToNameLookup.clear();
|
||||
if (getVoiceChannel() != EnumVoiceChannelType.NONE) sendInitialVoice();
|
||||
}
|
||||
|
||||
public static void handleVoiceSignalPacket(PacketBuffer packetData) {
|
||||
VoiceSignalPackets.handleVoiceSignal(packetData);
|
||||
}
|
||||
|
||||
static void handleVoiceSignalPacketTypeGlobal(EaglercraftUUID[] voicePlayers, String[] voiceNames) {
|
||||
public static void handleVoiceSignalPacketTypeGlobal(EaglercraftUUID[] voicePlayers, String[] voiceNames) {
|
||||
uuidToNameLookup.clear();
|
||||
for (int i = 0; i < voicePlayers.length; i++) {
|
||||
if(voiceNames != null) {
|
||||
@ -91,6 +92,17 @@ public class VoiceClientController {
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleVoiceSignalPacketTypeGlobalNew(Collection<SPacketVoiceSignalGlobalEAG.UserData> voicePlayers) {
|
||||
uuidToNameLookup.clear();
|
||||
for (SPacketVoiceSignalGlobalEAG.UserData player : voicePlayers) {
|
||||
EaglercraftUUID uuid = new EaglercraftUUID(player.uuidMost, player.uuidLeast);
|
||||
if(player.username != null) {
|
||||
uuidToNameLookup.put(uuid, player.username);
|
||||
}
|
||||
sendPacketRequestIfNeeded(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleServerDisconnect() {
|
||||
if(!isClientSupported()) return;
|
||||
serverSupport = false;
|
||||
@ -110,7 +122,7 @@ public class VoiceClientController {
|
||||
activateVoice(false);
|
||||
}
|
||||
|
||||
static void handleVoiceSignalPacketTypeAllowed(boolean voiceAvailableStat, String[] servs) {
|
||||
public static void handleVoiceSignalPacketTypeAllowed(boolean voiceAvailableStat, String[] servs) {
|
||||
serverSupport = voiceAvailableStat;
|
||||
PlatformVoiceClient.setICEServers(servs);
|
||||
if(isSupported()) {
|
||||
@ -120,23 +132,23 @@ public class VoiceClientController {
|
||||
}
|
||||
}
|
||||
|
||||
static void handleVoiceSignalPacketTypeConnect(EaglercraftUUID user, boolean offer) {
|
||||
public static void handleVoiceSignalPacketTypeConnect(EaglercraftUUID user, boolean offer) {
|
||||
PlatformVoiceClient.signalConnect(user, offer);
|
||||
}
|
||||
|
||||
static void handleVoiceSignalPacketTypeConnectAnnounce(EaglercraftUUID user) {
|
||||
public static void handleVoiceSignalPacketTypeConnectAnnounce(EaglercraftUUID user) {
|
||||
sendPacketRequest(user);
|
||||
}
|
||||
|
||||
static void handleVoiceSignalPacketTypeDisconnect(EaglercraftUUID user) {
|
||||
public static void handleVoiceSignalPacketTypeDisconnect(EaglercraftUUID user) {
|
||||
PlatformVoiceClient.signalDisconnect(user, true);
|
||||
}
|
||||
|
||||
static void handleVoiceSignalPacketTypeICECandidate(EaglercraftUUID user, String ice) {
|
||||
public static void handleVoiceSignalPacketTypeICECandidate(EaglercraftUUID user, String ice) {
|
||||
PlatformVoiceClient.signalICECandidate(user, ice);
|
||||
}
|
||||
|
||||
static void handleVoiceSignalPacketTypeDescription(EaglercraftUUID user, String desc) {
|
||||
public static void handleVoiceSignalPacketTypeDescription(EaglercraftUUID user, String desc) {
|
||||
PlatformVoiceClient.signalDescription(user, desc);
|
||||
}
|
||||
|
||||
@ -211,7 +223,7 @@ public class VoiceClientController {
|
||||
for (EaglercraftUUID uuid : antiConcurrentModificationUUIDs) {
|
||||
PlatformVoiceClient.signalDisconnect(uuid, false);
|
||||
}
|
||||
sendPacketDisconnect(null);
|
||||
sendPacketDisconnect();
|
||||
activateVoice(false);
|
||||
} else if (voiceChannel == EnumVoiceChannelType.PROXIMITY) {
|
||||
for (EaglercraftUUID uuid : nearbyPlayers) {
|
||||
@ -222,7 +234,7 @@ public class VoiceClientController {
|
||||
}
|
||||
nearbyPlayers.clear();
|
||||
recentlyNearbyPlayers.clear();
|
||||
sendPacketDisconnect(null);
|
||||
sendPacketDisconnect();
|
||||
} else if(voiceChannel == EnumVoiceChannelType.GLOBAL) {
|
||||
Set<EaglercraftUUID> antiConcurrentModificationUUIDs = new HashSet<>(listeningSet);
|
||||
antiConcurrentModificationUUIDs.removeAll(nearbyPlayers);
|
||||
@ -230,7 +242,7 @@ public class VoiceClientController {
|
||||
for (EaglercraftUUID uuid : antiConcurrentModificationUUIDs) {
|
||||
PlatformVoiceClient.signalDisconnect(uuid, false);
|
||||
}
|
||||
sendPacketDisconnect(null);
|
||||
sendPacketDisconnect();
|
||||
}
|
||||
voiceChannel = channel;
|
||||
if (channel != EnumVoiceChannelType.NONE) {
|
||||
@ -340,23 +352,35 @@ public class VoiceClientController {
|
||||
}
|
||||
|
||||
public static void sendPacketICE(EaglercraftUUID peerId, String candidate) {
|
||||
packetSendCallback.accept(VoiceSignalPackets.makeVoiceSignalPacketICE(peerId, candidate));
|
||||
packetSendCallback.accept(new CPacketVoiceSignalICEEAG(peerId.msb, peerId.lsb, candidate));
|
||||
}
|
||||
|
||||
public static void sendPacketDesc(EaglercraftUUID peerId, String desc) {
|
||||
packetSendCallback.accept(VoiceSignalPackets.makeVoiceSignalPacketDesc(peerId, desc));
|
||||
packetSendCallback.accept(new CPacketVoiceSignalDescEAG(peerId.msb, peerId.lsb, desc));
|
||||
}
|
||||
|
||||
public static void sendPacketDisconnect(EaglercraftUUID peerId) {
|
||||
packetSendCallback.accept(VoiceSignalPackets.makeVoiceSignalPacketDisconnect(peerId));
|
||||
public static void sendPacketDisconnect() {
|
||||
if(protocolVersion <= 3) {
|
||||
packetSendCallback.accept(new CPacketVoiceSignalDisconnectV3EAG());
|
||||
}else {
|
||||
packetSendCallback.accept(new CPacketVoiceSignalDisconnectV4EAG());
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacketDisconnectPeer(EaglercraftUUID peerId) {
|
||||
if(protocolVersion <= 3) {
|
||||
packetSendCallback.accept(new CPacketVoiceSignalDisconnectV3EAG(true, peerId.msb, peerId.lsb));
|
||||
}else {
|
||||
packetSendCallback.accept(new CPacketVoiceSignalDisconnectPeerV4EAG(peerId.msb, peerId.lsb));
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacketConnect() {
|
||||
packetSendCallback.accept(VoiceSignalPackets.makeVoiceSignalPacketConnect());
|
||||
packetSendCallback.accept(new CPacketVoiceSignalConnectEAG());
|
||||
}
|
||||
|
||||
public static void sendPacketRequest(EaglercraftUUID peerId) {
|
||||
packetSendCallback.accept(VoiceSignalPackets.makeVoiceSignalPacketRequest(peerId));
|
||||
packetSendCallback.accept(new CPacketVoiceSignalRequestEAG(peerId.msb, peerId.lsb));
|
||||
}
|
||||
|
||||
private static void sendPacketRequestIfNeeded(EaglercraftUUID uuid) {
|
||||
|
@ -1,142 +0,0 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.voice;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.EaglercraftUUID;
|
||||
import net.lax1dude.eaglercraft.v1_8.netty.Unpooled;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2024 lax1dude, ayunami2000. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
public class VoiceSignalPackets {
|
||||
|
||||
static final int VOICE_SIGNAL_ALLOWED = 0;
|
||||
static final int VOICE_SIGNAL_REQUEST = 0;
|
||||
static final int VOICE_SIGNAL_CONNECT = 1;
|
||||
static final int VOICE_SIGNAL_DISCONNECT = 2;
|
||||
static final int VOICE_SIGNAL_ICE = 3;
|
||||
static final int VOICE_SIGNAL_DESC = 4;
|
||||
static final int VOICE_SIGNAL_GLOBAL = 5;
|
||||
|
||||
static void handleVoiceSignal(PacketBuffer streamIn) {
|
||||
try {
|
||||
int sig = streamIn.readUnsignedByte();
|
||||
switch(sig) {
|
||||
case VOICE_SIGNAL_ALLOWED: {
|
||||
boolean voiceAvailableStat = streamIn.readUnsignedByte() == 1;
|
||||
String[] servs = null;
|
||||
if(voiceAvailableStat) {
|
||||
servs = new String[streamIn.readVarIntFromBuffer()];
|
||||
for(int i = 0; i < servs.length; i++) {
|
||||
servs[i] = streamIn.readStringFromBuffer(1024);
|
||||
}
|
||||
}
|
||||
VoiceClientController.handleVoiceSignalPacketTypeAllowed(voiceAvailableStat, servs);
|
||||
break;
|
||||
}
|
||||
case VOICE_SIGNAL_GLOBAL: {
|
||||
if (VoiceClientController.getVoiceChannel() != EnumVoiceChannelType.GLOBAL) return;
|
||||
EaglercraftUUID[] voiceIds = new EaglercraftUUID[streamIn.readVarIntFromBuffer()];
|
||||
for(int i = 0; i < voiceIds.length; i++) {
|
||||
voiceIds[i] = streamIn.readUuid();
|
||||
}
|
||||
String[] voiceNames = null;
|
||||
if (streamIn.isReadable()) {
|
||||
voiceNames = new String[voiceIds.length];
|
||||
for(int i = 0; i < voiceNames.length; i++) {
|
||||
voiceNames[i] = streamIn.readStringFromBuffer(16);
|
||||
}
|
||||
}
|
||||
VoiceClientController.handleVoiceSignalPacketTypeGlobal(voiceIds, voiceNames);
|
||||
break;
|
||||
}
|
||||
case VOICE_SIGNAL_CONNECT: {
|
||||
EaglercraftUUID uuid = streamIn.readUuid();
|
||||
if (streamIn.isReadable()) {
|
||||
VoiceClientController.handleVoiceSignalPacketTypeConnect(uuid, streamIn.readBoolean());
|
||||
} else if (VoiceClientController.getVoiceChannel() != EnumVoiceChannelType.PROXIMITY || VoiceClientController.getVoiceListening().contains(uuid)) {
|
||||
VoiceClientController.handleVoiceSignalPacketTypeConnectAnnounce(uuid);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case VOICE_SIGNAL_DISCONNECT: {
|
||||
VoiceClientController.handleVoiceSignalPacketTypeDisconnect(streamIn.readableBytes() > 0 ? streamIn.readUuid() : null);
|
||||
break;
|
||||
}
|
||||
case VOICE_SIGNAL_ICE: {
|
||||
VoiceClientController.handleVoiceSignalPacketTypeICECandidate(streamIn.readUuid(), streamIn.readStringFromBuffer(32767));
|
||||
break;
|
||||
}
|
||||
case VOICE_SIGNAL_DESC: {
|
||||
VoiceClientController.handleVoiceSignalPacketTypeDescription(streamIn.readUuid(), streamIn.readStringFromBuffer(32767));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
VoiceClientController.logger.error("Unknown voice signal packet '{}'!", sig);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}catch(Throwable ex) {
|
||||
VoiceClientController.logger.error("Failed to handle signal packet!");
|
||||
VoiceClientController.logger.error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
static PacketBuffer makeVoiceSignalPacketRequest(EaglercraftUUID user) {
|
||||
PacketBuffer ret = new PacketBuffer(Unpooled.buffer(17, 17));
|
||||
ret.writeByte(VOICE_SIGNAL_REQUEST);
|
||||
ret.writeUuid(user);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static PacketBuffer makeVoiceSignalPacketICE(EaglercraftUUID user, String icePacket) {
|
||||
byte[] str = icePacket.getBytes(StandardCharsets.UTF_8);
|
||||
int estLen = 17 + PacketBuffer.getVarIntSize(str.length) + str.length;
|
||||
PacketBuffer ret = new PacketBuffer(Unpooled.buffer(estLen, estLen));
|
||||
ret.writeByte(VOICE_SIGNAL_ICE);
|
||||
ret.writeUuid(user);
|
||||
ret.writeByteArray(str);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static PacketBuffer makeVoiceSignalPacketDesc(EaglercraftUUID user, String descPacket) {
|
||||
byte[] str = descPacket.getBytes(StandardCharsets.UTF_8);
|
||||
int estLen = 17 + PacketBuffer.getVarIntSize(str.length) + str.length;
|
||||
PacketBuffer ret = new PacketBuffer(Unpooled.buffer(estLen, estLen));
|
||||
ret.writeByte(VOICE_SIGNAL_DESC);
|
||||
ret.writeUuid(user);
|
||||
ret.writeByteArray(str);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static PacketBuffer makeVoiceSignalPacketDisconnect(EaglercraftUUID user) {
|
||||
if (user == null) {
|
||||
PacketBuffer ret = new PacketBuffer(Unpooled.buffer(1, 1));
|
||||
ret.writeByte(VOICE_SIGNAL_DISCONNECT);
|
||||
return ret;
|
||||
}
|
||||
PacketBuffer ret = new PacketBuffer(Unpooled.buffer(17, 17));
|
||||
ret.writeByte(VOICE_SIGNAL_DISCONNECT);
|
||||
ret.writeUuid(user);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static PacketBuffer makeVoiceSignalPacketConnect() {
|
||||
PacketBuffer ret = new PacketBuffer(Unpooled.buffer(1, 1));
|
||||
ret.writeByte(VOICE_SIGNAL_CONNECT);
|
||||
return ret;
|
||||
}
|
||||
}
|
@ -33,7 +33,7 @@ public class VoiceTagRenderer {
|
||||
|
||||
private static final ResourceLocation voiceGuiIcons = new ResourceLocation("eagler:gui/eagler_gui.png");
|
||||
|
||||
private static final Set<EaglercraftUUID> voiceTagsDrawnThisFrame = new HashSet();
|
||||
private static final Set<EaglercraftUUID> voiceTagsDrawnThisFrame = new HashSet<>();
|
||||
|
||||
public static void renderVoiceNameTag(Minecraft mc, EntityOtherPlayerMP player, int offset) {
|
||||
EaglercraftUUID uuid = player.getUniqueID();
|
||||
|
Reference in New Issue
Block a user