Update #42 - Fixed several WebRTC bugs and other issues

This commit is contained in:
lax1dude
2024-11-16 21:47:35 -08:00
parent 4d66ca140a
commit 64ac208565
95 changed files with 1084 additions and 501 deletions

View File

@ -215,10 +215,12 @@ public class EagRuntime {
}
public static void getStackTrace(Throwable t, Consumer<String> ret) {
if(t == null) return;
PlatformRuntime.getStackTrace(t, ret);
}
public static String[] getStackTraceElements(Throwable t) {
if(t == null) return new String[0];
List<String> lst = new ArrayList<>();
PlatformRuntime.getStackTrace(t, (s) -> {
lst.add(s);
@ -227,6 +229,9 @@ public class EagRuntime {
}
public static String getStackTrace(Throwable t) {
if(t == null) {
return "[null]";
}
StringBuilder sb = new StringBuilder();
getStackTrace0(t, sb);
Throwable c = t.getCause();

View File

@ -21,7 +21,6 @@ import net.minecraft.client.audio.SoundHandler;
import net.minecraft.client.audio.SoundPoolEntry;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ITickable;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
@ -42,7 +41,7 @@ import net.minecraft.util.ResourceLocation;
*/
public class EaglercraftSoundManager {
protected static class ActiveSoundEvent {
protected class ActiveSoundEvent {
protected final EaglercraftSoundManager manager;
@ -88,14 +87,11 @@ public class EaglercraftSoundManager {
activeZ = z;
}
if(pitch != activePitch) {
soundHandle.pitch(MathHelper.clamp_float(pitch * (float)soundConfig.getPitch(), 0.5f, 2.0f));
soundHandle.pitch(EaglercraftSoundManager.this.getNormalizedPitch(soundInstance, soundConfig));
activePitch = pitch;
}
if(gain != activeGain) {
float attenuatedGain = gain * manager.categoryVolumes[SoundCategory.MASTER.getCategoryId()] *
(soundCategory == SoundCategory.MASTER ? 1.0f : manager.categoryVolumes[soundCategory.getCategoryId()])
* (float)soundConfig.getVolume();
soundHandle.gain(MathHelper.clamp_float(attenuatedGain, 0.0f, 1.0f));
soundHandle.gain(EaglercraftSoundManager.this.getNormalizedVolume(soundInstance, soundConfig, soundCategory));
activeGain = gain;
}
}
@ -152,10 +148,7 @@ public class EaglercraftSoundManager {
ActiveSoundEvent evt = soundItr.next();
if((category == SoundCategory.MASTER || evt.soundCategory == category)
&& !evt.soundHandle.shouldFree()) {
float newVolume = (evt.activeGain = evt.soundInstance.getVolume()) * categoryVolumes[SoundCategory.MASTER.getCategoryId()] *
(evt.soundCategory == SoundCategory.MASTER ? 1.0f : categoryVolumes[evt.soundCategory.getCategoryId()])
* (float)evt.soundConfig.getVolume();
newVolume = MathHelper.clamp_float(newVolume, 0.0f, 1.0f);
float newVolume = getNormalizedVolume(evt.soundInstance, evt.soundConfig, evt.soundCategory);
if(newVolume > 0.0f) {
evt.soundHandle.gain(newVolume);
}else {
@ -211,34 +204,34 @@ public class EaglercraftSoundManager {
Iterator<ActiveSoundEvent> soundItr = activeSounds.iterator();
while(soundItr.hasNext()) {
ActiveSoundEvent evt = soundItr.next();
if(!evt.paused && (evt.soundInstance instanceof ITickable)) {
boolean persist = false;
if(!evt.paused && (evt.soundInstance instanceof ITickableSound)) {
boolean destroy = false;
try {
((ITickable)evt.soundInstance).update();
if ((evt.soundInstance instanceof ITickableSound)
&& ((ITickableSound) evt.soundInstance).isDonePlaying()) {
ITickableSound snd = (ITickableSound) evt.soundInstance;
lbl : {
try {
snd.update();
if(snd.isDonePlaying()) {
destroy = true;
break lbl;
}
persist = true;
}catch(Throwable t) {
logger.error("Error ticking sound: {}", t.toString());
logger.error(t);
destroy = true;
}
}catch(Throwable t) {
logger.error("Error ticking sound: {}", t.toString());
logger.error(t);
destroy = true;
}
if(destroy) {
if(!evt.soundHandle.shouldFree()) {
evt.soundHandle.end();
}
soundItr.remove();
continue;
}
}
if(evt.soundHandle.shouldFree()) {
if(evt.soundInstance.canRepeat()) {
if(!evt.paused && ++evt.repeatCounter > evt.soundInstance.getRepeatDelay()) {
evt.repeatCounter = 0;
evt.updateLocation();
evt.soundHandle.restart();
}
}else {
if(!persist) {
soundItr.remove();
}
}else {
@ -323,17 +316,16 @@ public class EaglercraftSoundManager {
ActiveSoundEvent newSound = new ActiveSoundEvent(this, sound, accessor.getSoundCategory(), etr, null);
float pitch = MathHelper.clamp_float(newSound.activePitch * (float)etr.getPitch(), 0.5f, 2.0f);
float attenuatedGain = newSound.activeGain * categoryVolumes[SoundCategory.MASTER.getCategoryId()] *
(accessor.getSoundCategory() == SoundCategory.MASTER ? 1.0f :
categoryVolumes[accessor.getSoundCategory().getCategoryId()]) * (float)etr.getVolume();
float pitch = getNormalizedPitch(sound, etr);
float attenuatedGain = getNormalizedVolume(sound, etr, accessor.getSoundCategory());
boolean repeat = sound.canRepeat();
AttenuationType tp = sound.getAttenuationType();
if(tp == AttenuationType.LINEAR) {
newSound.soundHandle = PlatformAudio.beginPlayback(trk, newSound.activeX, newSound.activeY,
newSound.activeZ, attenuatedGain, pitch);
newSound.activeZ, attenuatedGain, pitch, repeat);
}else {
newSound.soundHandle = PlatformAudio.beginPlaybackStatic(trk, attenuatedGain, pitch);
newSound.soundHandle = PlatformAudio.beginPlaybackStatic(trk, attenuatedGain, pitch, repeat);
}
if(newSound.soundHandle == null) {
@ -351,6 +343,17 @@ public class EaglercraftSoundManager {
queuedSounds.add(new WaitingSoundEvent(sound, delay));
}
private float getNormalizedVolume(ISound sound, SoundPoolEntry entry, SoundCategory category) {
return (float) MathHelper.clamp_double((double) sound.getVolume() * entry.getVolume(), 0.0D, 1.0D)
* (category.getCategoryId() == SoundCategory.MASTER.getCategoryId() ? 1.0f
: categoryVolumes[category.getCategoryId()])
* categoryVolumes[SoundCategory.MASTER.getCategoryId()];
}
private float getNormalizedPitch(ISound sound, SoundPoolEntry entry) {
return MathHelper.clamp_float(sound.getPitch() * (float)entry.getPitch(), 0.5f, 2.0f);
}
public void setListener(EntityPlayer player, float partialTicks) {
if(!PlatformAudio.available()) {
return;

View File

@ -10,7 +10,7 @@ public class EaglercraftVersion {
/// Customize these to fit your fork:
public static final String projectForkName = "EaglercraftX";
public static final String projectForkVersion = "u41";
public static final String projectForkVersion = "u42";
public static final String projectForkVendor = "lax1dude";
public static final String projectForkURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8";
@ -20,20 +20,20 @@ public class EaglercraftVersion {
public static final String projectOriginName = "EaglercraftX";
public static final String projectOriginAuthor = "lax1dude";
public static final String projectOriginRevision = "1.8";
public static final String projectOriginVersion = "u41";
public static final String projectOriginVersion = "u42";
public static final String projectOriginURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8"; // rest in peace
// EPK Version Identifier
public static final String EPKVersionIdentifier = "u41"; // Set to null to disable EPK version check
public static final String EPKVersionIdentifier = "u42"; // Set to null to disable EPK version check
// Updating configuration
public static final boolean enableUpdateService = true;
public static final String updateBundlePackageName = "net.lax1dude.eaglercraft.v1_8.client";
public static final int updateBundlePackageVersionInt = 41;
public static final int updateBundlePackageVersionInt = 42;
public static final String updateLatestLocalStorageKey = "latestUpdate_" + updateBundlePackageName;

View File

@ -16,7 +16,7 @@ package net.lax1dude.eaglercraft.v1_8.internal;
*
*/
public enum EnumPlatformType {
DESKTOP("Desktop"), JAVASCRIPT("JavaScript"), ASM("ASM");
DESKTOP("Desktop"), JAVASCRIPT("JavaScript"), WASM_GC("ASM");
private final String name;

View File

@ -21,6 +21,8 @@ public interface IAudioHandle {
void restart();
void repeat(boolean en);
void move(float x, float y, float z);
void pitch(float f);

View File

@ -283,7 +283,7 @@ public class EaglerFolderResourcePack extends AbstractResourcePack {
return;
}
}
PlatformRuntime.downloadRemoteURIByteArray(url, arr -> {
PlatformRuntime.downloadRemoteURIByteArray(url, true, arr -> {
ast.accept(() -> {
if (arr == null) {
cb.accept(null);

View File

@ -517,6 +517,8 @@ public class FontMappingHelper {
return 253;
case 9632:
return 254;
case 160:
return 32; //nbsp
default:
return -1;
}

View File

@ -162,7 +162,6 @@ public class SingleplayerServerController implements ISaveFormat {
}else {
openLANChannels.add(ch);
sendIPCPacket(new IPCPacket0CPlayerChannel(ch, true));
PlatformWebRTC.serverLANCreatePeer(ch);
}
}
@ -288,6 +287,8 @@ public class SingleplayerServerController implements ISaveFormat {
logger.warn("Recieved {} byte packet on closed local player connection", packetData.contents.length);
}
}else {
//logger.warn("Recieved packet on IPC channel '{}', forwarding to PlatformWebRTC even though the channel should be mapped", packetData.channel);
// just to be safe
PlatformWebRTC.serverLANWritePacket(packetData.channel, packetData.contents);
}
}

View File

@ -6,9 +6,7 @@ import net.lax1dude.eaglercraft.v1_8.sp.WorkerStartupFailedException;
import net.lax1dude.eaglercraft.v1_8.sp.ipc.IPCPacket15Crashed;
import net.lax1dude.eaglercraft.v1_8.sp.ipc.IPCPacket1CIssueDetected;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiSelectWorld;
import net.minecraft.client.resources.I18n;
/**

View File

@ -151,7 +151,7 @@ public class GuiShareToLan extends GuiScreen {
}
this.mc.displayGuiScreen(null);
LoadingScreenRenderer ls = mc.loadingScreen;
String code = LANServerController.shareToLAN(ls::resetProgressAndMessage, worldName, hiddenToggle);
String code = LANServerController.shareToLAN((msg) -> ls.eaglerShow(msg, null), worldName, hiddenToggle);
if (code != null) {
SingleplayerServerController.configureLAN(WorldSettings.GameType.getByName(this.gameMode), this.allowCommands);
this.mc.ingameGUI.getChatGUI().printChatMessage(new ChatComponentText(I18n.format("lanServer.opened")

View File

@ -1,10 +1,8 @@
package net.lax1dude.eaglercraft.v1_8.sp.lan;
import java.util.Iterator;
import java.util.List;
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.EagUtils;
import net.lax1dude.eaglercraft.v1_8.internal.IPCPacketData;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformWebRTC;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
@ -33,42 +31,26 @@ class LANClientPeer {
private static final Logger logger = LogManager.getLogger("LANClientPeer");
private static final int PRE = 0, SENT_ICE_CANDIDATE = 2, SENT_DESCRIPTION = 3, CONNECTED = 4, CLOSED = 5;
private static final int PRE = 0, RECEIVED_ICE_CANDIDATE = 1, SENT_ICE_CANDIDATE = 2, RECEIVED_DESCRIPTION = 3,
SENT_DESCRIPTION = 4, RECEIVED_SUCCESS = 5, CONNECTED = 6, CLOSED = 7;
protected final String clientId;
protected int state = PRE;
protected boolean dead = false;
protected long startTime;
protected LANClientPeer(String clientId) {
this.clientId = clientId;
this.startTime = EagRuntime.steadyTimeMillis();
PlatformWebRTC.serverLANCreatePeer(clientId);
}
protected void handleICECandidates(String candidates) {
if(state == SENT_DESCRIPTION) {
PlatformWebRTC.serverLANPeerICECandidates(clientId, candidates);
long millis = EagRuntime.steadyTimeMillis();
do {
PlatformWebRTC.runScheduledTasks();
LANPeerEvent evt;
if((evt = PlatformWebRTC.serverLANGetEvent(clientId)) != null) {
if(evt instanceof LANPeerEvent.LANPeerICECandidateEvent) {
LANServerController.lanRelaySocket.writePacket(new RelayPacket03ICECandidate(clientId, ((LANPeerEvent.LANPeerICECandidateEvent)evt).candidates));
state = SENT_ICE_CANDIDATE;
return;
}else if(evt instanceof LANPeerEvent.LANPeerDisconnectEvent) {
logger.error("LAN client '{}' disconnected while waiting for server ICE candidates", clientId);
}else {
logger.error("LAN client '{}' had an accident: {}", clientId, evt.getClass().getSimpleName());
}
disconnect();
return;
}
EagUtils.sleep(20);
}while(EagRuntime.steadyTimeMillis() - millis < 5000l);
logger.error("Getting server ICE candidates for '{}' timed out!", clientId);
disconnect();
state = RECEIVED_ICE_CANDIDATE;
}else {
logger.error("Relay [{}] unexpected IPacket03ICECandidate for '{}'", LANServerController.lanRelaySocket.getURI(), clientId);
}
@ -77,27 +59,7 @@ class LANClientPeer {
protected void handleDescription(String description) {
if(state == PRE) {
PlatformWebRTC.serverLANPeerDescription(clientId, description);
long millis = EagRuntime.steadyTimeMillis();
do {
PlatformWebRTC.runScheduledTasks();
LANPeerEvent evt;
if((evt = PlatformWebRTC.serverLANGetEvent(clientId)) != null) {
if(evt instanceof LANPeerEvent.LANPeerDescriptionEvent) {
LANServerController.lanRelaySocket.writePacket(new RelayPacket04Description(clientId, ((LANPeerEvent.LANPeerDescriptionEvent)evt).description));
state = SENT_DESCRIPTION;
return;
}else if(evt instanceof LANPeerEvent.LANPeerDisconnectEvent) {
logger.error("LAN client '{}' disconnected while waiting for server description", clientId);
}else {
logger.error("LAN client '{}' had an accident: {}", clientId, evt.getClass().getSimpleName());
}
disconnect();
return;
}
EagUtils.sleep(20);
}while(EagRuntime.steadyTimeMillis() - millis < 5000l);
logger.error("Getting server description for '{}' timed out!", clientId);
disconnect();
state = RECEIVED_DESCRIPTION;
}else {
logger.error("Relay [{}] unexpected IPacket04Description for '{}'", LANServerController.lanRelaySocket.getURI(), clientId);
}
@ -105,31 +67,8 @@ class LANClientPeer {
protected void handleSuccess() {
if(state == SENT_ICE_CANDIDATE) {
long millis = EagRuntime.steadyTimeMillis();
do {
PlatformWebRTC.runScheduledTasks();
LANPeerEvent evt;
while((evt = PlatformWebRTC.serverLANGetEvent(clientId)) != null && evt instanceof LANPeerEvent.LANPeerICECandidateEvent) {
// skip ice candidates
}
if(evt != null) {
if(evt instanceof LANPeerEvent.LANPeerDataChannelEvent) {
SingleplayerServerController.openPlayerChannel(clientId);
state = CONNECTED;
return;
}else if(evt instanceof LANPeerEvent.LANPeerDisconnectEvent) {
logger.error("LAN client '{}' disconnected while waiting for connection", clientId);
}else {
logger.error("LAN client '{}' had an accident: {}", clientId, evt.getClass().getSimpleName());
}
disconnect();
return;
}
EagUtils.sleep(20);
}while(EagRuntime.steadyTimeMillis() - millis < 5000l);
logger.error("Getting server description for '{}' timed out!", clientId);
disconnect();
}else {
state = RECEIVED_SUCCESS;
}else if(state != CONNECTED) {
logger.error("Relay [{}] unexpected IPacket05ClientSuccess for '{}'", LANServerController.lanRelaySocket.getURI(), clientId);
}
}
@ -144,24 +83,67 @@ class LANClientPeer {
}
protected void update() {
if(state == CONNECTED) {
if(state != CLOSED) {
if(state != CONNECTED && EagRuntime.steadyTimeMillis() - startTime > 10000l) {
logger.info("LAN client '{}' handshake timed out", clientId);
disconnect();
return;
}
List<LANPeerEvent> l = PlatformWebRTC.serverLANGetAllEvent(clientId);
if(l == null) {
return;
}
Iterator<LANPeerEvent> itr = l.iterator();
while(state == CONNECTED && itr.hasNext()) {
LANPeerEvent evt = itr.next();
if(evt instanceof LANPeerEvent.LANPeerPacketEvent) {
ClientPlatformSingleplayer.sendPacket(new IPCPacketData(clientId, ((LANPeerEvent.LANPeerPacketEvent)evt).payload));
}else if(evt instanceof LANPeerEvent.LANPeerDisconnectEvent) {
read_loop: for(int i = 0, s = l.size(); i < s; ++i) {
LANPeerEvent evt = l.get(i);
if(evt instanceof LANPeerEvent.LANPeerDisconnectEvent) {
logger.info("LAN client '{}' disconnected", clientId);
disconnect();
}else {
logger.error("LAN client '{}' had an accident: {}", clientId, evt.getClass().getSimpleName());
switch(state) {
case RECEIVED_ICE_CANDIDATE: {
if(evt instanceof LANPeerEvent.LANPeerICECandidateEvent) {
LANServerController.lanRelaySocket.writePacket(new RelayPacket03ICECandidate(clientId, ((LANPeerEvent.LANPeerICECandidateEvent)evt).candidates));
state = SENT_ICE_CANDIDATE;
continue read_loop;
}
}
case RECEIVED_DESCRIPTION: {
if(evt instanceof LANPeerEvent.LANPeerDescriptionEvent) {
LANServerController.lanRelaySocket.writePacket(new RelayPacket04Description(clientId, ((LANPeerEvent.LANPeerDescriptionEvent)evt).description));
state = SENT_DESCRIPTION;
continue read_loop;
}
}
case SENT_ICE_CANDIDATE:
case RECEIVED_SUCCESS: {
if(evt instanceof LANPeerEvent.LANPeerDataChannelEvent) {
SingleplayerServerController.openPlayerChannel(clientId);
PlatformWebRTC.serverLANPeerMapIPC(clientId, clientId);
state = CONNECTED;
continue read_loop;
}
}
case CONNECTED: {
if(evt instanceof LANPeerEvent.LANPeerPacketEvent) {
//logger.warn("Forwarding packet for '{}' to IPC channel manually, even though the channel should be mapped", clientId);
// just to be safe
ClientPlatformSingleplayer.sendPacket(new IPCPacketData(clientId, ((LANPeerEvent.LANPeerPacketEvent)evt).payload));
continue read_loop;
}
}
default: {
break;
}
}
if(state != CLOSED) {
logger.error("LAN client '{}' had an accident: {}", clientId, evt.getClass().getSimpleName());
}
disconnect();
return;
}
}
}else {
disconnect();
}
}

View File

@ -12,6 +12,7 @@ import java.util.Set;
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformWebRTC;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayManager;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayQueryDispatch;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayServer;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayWorldsQuery;
import net.lax1dude.eaglercraft.v1_8.sp.relay.pkt.RelayPacket07LocalWorlds;
@ -123,7 +124,7 @@ public class LANServerList {
for(int i = 0, l = RelayManager.relayManager.count(); i < l; ++i) {
RelayServer srv = RelayManager.relayManager.get(i);
if(!lanServersQueryList.containsKey(srv.address) && !deadURIs.contains(srv.address)) {
lanServersQueryList.put(srv.address, PlatformWebRTC.openRelayWorldsQuery(srv.address));
lanServersQueryList.put(srv.address, RelayQueryDispatch.openRelayWorldsQuery(srv.address));
}
}
}

View File

@ -0,0 +1,44 @@
package net.lax1dude.eaglercraft.v1_8.sp.relay;
/**
* Copyright (c) 2024 lax1dude. 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 RelayQueryDispatch {
public static RelayQuery openRelayQuery(String addr) {
RelayQuery.RateLimit limit = RelayServerRateLimitTracker.isLimited(addr);
if(limit == RelayQuery.RateLimit.LOCKED || limit == RelayQuery.RateLimit.BLOCKED) {
return new RelayQueryRateLimitDummy(limit);
}
return new RelayQueryImpl(addr);
}
public static RelayWorldsQuery openRelayWorldsQuery(String addr) {
RelayQuery.RateLimit limit = RelayServerRateLimitTracker.isLimited(addr);
if(limit == RelayQuery.RateLimit.LOCKED || limit == RelayQuery.RateLimit.BLOCKED) {
return new RelayWorldsQueryRateLimitDummy(limit);
}
return new RelayWorldsQueryImpl(addr);
}
public static RelayServerSocket openRelayConnection(String addr, int timeout) {
RelayQuery.RateLimit limit = RelayServerRateLimitTracker.isLimited(addr);
if(limit == RelayQuery.RateLimit.LOCKED || limit == RelayQuery.RateLimit.BLOCKED) {
return new RelayServerSocketRateLimitDummy(limit);
}
return new RelayServerSocketImpl(addr, timeout);
}
}

View File

@ -89,7 +89,7 @@ public class RelayServer {
public void ping() {
if(PlatformWebRTC.supported()) {
close();
query = PlatformWebRTC.openRelayQuery(address);
query = RelayQueryDispatch.openRelayQuery(address);
queriedVersion = -1;
queriedComment = null;
queriedVendor = null;
@ -142,7 +142,7 @@ public class RelayServer {
}
public RelayServerSocket openSocket() {
return PlatformWebRTC.openRelayConnection(address, Minecraft.getMinecraft().gameSettings.relayTimeout * 1000);
return RelayQueryDispatch.openRelayConnection(address, Minecraft.getMinecraft().gameSettings.relayTimeout * 1000);
}
}

View File

@ -10,8 +10,8 @@ import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.EaglerInputStream;
import net.lax1dude.eaglercraft.v1_8.EaglerOutputStream;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformApplication;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformWebRTC;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayManager;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayQueryDispatch;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayServerSocket;
import net.lax1dude.eaglercraft.v1_8.sp.relay.pkt.RelayPacket00Handshake;
import net.minecraft.client.Minecraft;
@ -111,7 +111,7 @@ public class RelayUpdateChecker {
private static void connect(RelayEntry socket) {
try {
socket.handshake = false;
socket.currentSocket = PlatformWebRTC.openRelayConnection(socket.uri, 10000);
socket.currentSocket = RelayQueryDispatch.openRelayConnection(socket.uri, 10000);
if(socket.currentSocket.isClosed()) {
socket.currentSocket = null;
}

View File

@ -1,20 +0,0 @@
package net.lax1dude.eaglercraft.v1_8.voice;
/**
* Copyright (c) 2024 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 enum EnumVoiceChannelPeerState {
FAILED, SUCCESS, LOADING;
}

View File

@ -20,6 +20,7 @@ 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.lax1dude.eaglercraft.v1_8.sp.lan.LANServerController;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
@ -133,23 +134,23 @@ public class VoiceClientController {
}
public static void handleVoiceSignalPacketTypeConnect(EaglercraftUUID user, boolean offer) {
PlatformVoiceClient.signalConnect(user, offer);
if (voiceChannel != EnumVoiceChannelType.NONE) PlatformVoiceClient.signalConnect(user, offer);
}
public static void handleVoiceSignalPacketTypeConnectAnnounce(EaglercraftUUID user) {
sendPacketRequest(user);
if (voiceChannel != EnumVoiceChannelType.NONE) sendPacketRequest(user);
}
public static void handleVoiceSignalPacketTypeDisconnect(EaglercraftUUID user) {
PlatformVoiceClient.signalDisconnect(user, true);
if (voiceChannel != EnumVoiceChannelType.NONE) PlatformVoiceClient.signalDisconnect(user, true);
}
public static void handleVoiceSignalPacketTypeICECandidate(EaglercraftUUID user, String ice) {
PlatformVoiceClient.signalICECandidate(user, ice);
if (voiceChannel != EnumVoiceChannelType.NONE) PlatformVoiceClient.signalICECandidate(user, ice);
}
public static void handleVoiceSignalPacketTypeDescription(EaglercraftUUID user, String desc) {
PlatformVoiceClient.signalDescription(user, desc);
if (voiceChannel != EnumVoiceChannelType.NONE) PlatformVoiceClient.signalDescription(user, desc);
}
public static void tickVoiceClient(Minecraft mc) {
@ -161,6 +162,11 @@ public class VoiceClientController {
if (getVoiceChannel() != EnumVoiceChannelType.NONE && (getVoiceStatus() == EnumVoiceChannelStatus.CONNECTING || getVoiceStatus() == EnumVoiceChannelStatus.CONNECTED)) {
activateVoice((mc.currentScreen == null || !mc.currentScreen.blockPTTKey()) && Keyboard.isKeyDown(mc.gameSettings.voicePTTKey));
if(mc.isSingleplayer() && !LANServerController.isHostingLAN()) {
setVoiceChannel(EnumVoiceChannelType.NONE);
return;
}
if (mc.theWorld != null && mc.thePlayer != null) {
HashSet<EaglercraftUUID> seenPlayers = new HashSet<>();
for (EntityPlayer player : mc.theWorld.playerEntities) {
@ -209,7 +215,6 @@ public class VoiceClientController {
public static void setVoiceChannel(EnumVoiceChannelType channel) {
if (voiceChannel == channel) return;
if (channel != EnumVoiceChannelType.NONE) PlatformVoiceClient.initializeDevices();
PlatformVoiceClient.resetPeerStates();
if (channel == EnumVoiceChannelType.NONE) {
for (EaglercraftUUID uuid : nearbyPlayers) {
PlatformVoiceClient.signalDisconnect(uuid, false);
@ -261,13 +266,10 @@ public class VoiceClientController {
return voiceChannel;
}
private static boolean voicePeerErrored() {
return PlatformVoiceClient.getPeerState() == EnumVoiceChannelPeerState.FAILED || PlatformVoiceClient.getPeerStateConnect() == EnumVoiceChannelPeerState.FAILED || PlatformVoiceClient.getPeerStateInitial() == EnumVoiceChannelPeerState.FAILED || PlatformVoiceClient.getPeerStateDesc() == EnumVoiceChannelPeerState.FAILED || PlatformVoiceClient.getPeerStateIce() == EnumVoiceChannelPeerState.FAILED;
}
public static EnumVoiceChannelStatus getVoiceStatus() {
return (!isClientSupported() || !isServerSupported()) ? EnumVoiceChannelStatus.UNAVAILABLE :
(PlatformVoiceClient.getReadyState() != EnumVoiceChannelReadyState.DEVICE_INITIALIZED ?
EnumVoiceChannelStatus.CONNECTING : (voicePeerErrored() ? EnumVoiceChannelStatus.UNAVAILABLE : EnumVoiceChannelStatus.CONNECTED));
EnumVoiceChannelStatus.CONNECTING : EnumVoiceChannelStatus.CONNECTED);
}
private static boolean talkStatus = false;
@ -352,35 +354,47 @@ public class VoiceClientController {
}
public static void sendPacketICE(EaglercraftUUID peerId, String candidate) {
packetSendCallback.accept(new CPacketVoiceSignalICEEAG(peerId.msb, peerId.lsb, candidate));
if(packetSendCallback != null) {
packetSendCallback.accept(new CPacketVoiceSignalICEEAG(peerId.msb, peerId.lsb, candidate));
}
}
public static void sendPacketDesc(EaglercraftUUID peerId, String desc) {
packetSendCallback.accept(new CPacketVoiceSignalDescEAG(peerId.msb, peerId.lsb, desc));
if(packetSendCallback != null) {
packetSendCallback.accept(new CPacketVoiceSignalDescEAG(peerId.msb, peerId.lsb, desc));
}
}
public static void sendPacketDisconnect() {
if(protocolVersion <= 3) {
packetSendCallback.accept(new CPacketVoiceSignalDisconnectV3EAG());
}else {
packetSendCallback.accept(new CPacketVoiceSignalDisconnectV4EAG());
if(packetSendCallback != null) {
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));
if(packetSendCallback != null) {
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(new CPacketVoiceSignalConnectEAG());
if(packetSendCallback != null) {
packetSendCallback.accept(new CPacketVoiceSignalConnectEAG());
}
}
public static void sendPacketRequest(EaglercraftUUID peerId) {
packetSendCallback.accept(new CPacketVoiceSignalRequestEAG(peerId.msb, peerId.lsb));
if(packetSendCallback != null) {
packetSendCallback.accept(new CPacketVoiceSignalRequestEAG(peerId.msb, peerId.lsb));
}
}
private static void sendPacketRequestIfNeeded(EaglercraftUUID uuid) {