mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-10-06 05:47:40 +02:00
Implemented proper handling of protocol translation errors
Renamed all words. translations to misc. Cleaned up codebase
This commit is contained in:
parent
6e6c58fdef
commit
dfa3838771
@ -25,13 +25,13 @@ import net.minecraft.text.Text;
|
||||
public class GeneralSettings extends SettingGroup {
|
||||
public final static GeneralSettings INSTANCE = new GeneralSettings();
|
||||
|
||||
public final ModeSetting multiplayerScreenButtonOrientation = new ModeSetting(this, Text.translatable("general.viafabricplus.multiplayerscreenbutton"),
|
||||
public final ModeSetting multiplayerScreenButtonOrientation = new ModeSetting(this, Text.translatable("general.viafabricplus.multiplayerscreenbutton"), 1,
|
||||
Text.translatable("words.viafabricplus.lt"),
|
||||
Text.translatable("words.viafabricplus.rt"),
|
||||
Text.translatable("words.viafabricplus.lb"),
|
||||
Text.translatable("words.viafabricplus.rb")
|
||||
);
|
||||
public final ModeSetting addServerScreenButtonOrientation = new ModeSetting(this, Text.translatable("general.viafabricplus.addserverscreenbutton"),
|
||||
public final ModeSetting addServerScreenButtonOrientation = new ModeSetting(this, Text.translatable("general.viafabricplus.addserverscreenbutton"), 1,
|
||||
Text.translatable("words.viafabricplus.lt"),
|
||||
Text.translatable("words.viafabricplus.rt"),
|
||||
Text.translatable("words.viafabricplus.lb"),
|
||||
@ -47,11 +47,13 @@ public class GeneralSettings extends SettingGroup {
|
||||
public final BooleanSetting showClassicLoadingProgressInConnectScreen = new BooleanSetting(this, Text.translatable("general.viafabricplus.classicloading"), true);
|
||||
public final BooleanSetting autoDetectVersion = new BooleanSetting(this, Text.translatable("general.viafabricplus.autodetect"), false);
|
||||
public final BooleanSetting showAdvertisedServerVersion = new BooleanSetting(this, Text.translatable("general.viafabricplus.advertised"), true);
|
||||
public final ModeSetting ignorePacketTranslationErrors = new ModeSetting(this, Text.translatable("general.viafabricplus.ignoreerrors"),
|
||||
Text.translatable("words.viafabricplus.kick"),
|
||||
Text.translatable("words.viafabricplus.cancelnotify"),
|
||||
Text.translatable("words.viafabricplus.cancel")
|
||||
);
|
||||
|
||||
public GeneralSettings() {
|
||||
super(Text.translatable("settings.viafabricplus.general"));
|
||||
|
||||
multiplayerScreenButtonOrientation.setValue(1); // Default value
|
||||
addServerScreenButtonOrientation.setValue(1); // Default value
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,11 @@ public class ModeSetting extends AbstractSetting<MutableText> {
|
||||
private final MutableText[] options;
|
||||
|
||||
public ModeSetting(SettingGroup parent, MutableText name, MutableText... options) {
|
||||
super(parent, name, options[0]);
|
||||
this(parent, name, 0, options);
|
||||
}
|
||||
|
||||
public ModeSetting(SettingGroup parent, MutableText name, int defaultOption, MutableText... options) {
|
||||
super(parent, name, options[defaultOption]);
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
|
@ -17,12 +17,21 @@
|
||||
*/
|
||||
package de.florianmichael.viafabricplus.definition.classic.command;
|
||||
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import com.viaversion.viaversion.api.command.ViaSubCommand;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
||||
import de.florianmichael.viafabricplus.util.ChatUtil;
|
||||
|
||||
public abstract class ClassicViaSubCommand extends ViaSubCommand {
|
||||
|
||||
/**
|
||||
* Automatically prefix all messages
|
||||
*/
|
||||
public void sendMessage(final ViaCommandSender sender, final String message) {
|
||||
ViaSubCommand.sendMessage(sender, ChatUtil.PREFIX + " " + message);
|
||||
}
|
||||
|
||||
public UserConnection getUser() {
|
||||
return ProtocolHack.getMainUserConnection();
|
||||
}
|
||||
|
@ -22,9 +22,9 @@ import de.florianmichael.viafabricplus.ViaFabricPlus;
|
||||
import de.florianmichael.viafabricplus.information.AbstractInformationGroup;
|
||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
||||
import de.florianmichael.viafabricplus.base.settings.groups.GeneralSettings;
|
||||
import de.florianmichael.viafabricplus.util.ChatUtil;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.hud.DebugHud;
|
||||
import net.minecraft.util.Formatting;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@ -45,7 +45,7 @@ public class MixinDebugHud {
|
||||
final UserConnection userConnection = ProtocolHack.getMainUserConnection();
|
||||
|
||||
information.add("");
|
||||
information.add(Formatting.GOLD + "[ViaFabricPlus] " + Formatting.WHITE);
|
||||
information.add(ChatUtil.PREFIX);
|
||||
|
||||
for (AbstractInformationGroup group : ViaFabricPlus.INSTANCE.getInformationSystem().getGroups()) {
|
||||
if (group.getVersionRange() != null && !group.getVersionRange().contains(ProtocolHack.getTargetVersion())) continue;
|
||||
|
@ -20,6 +20,8 @@ package de.florianmichael.viafabricplus.protocolhack.netty;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import de.florianmichael.viafabricplus.ViaFabricPlus;
|
||||
import de.florianmichael.viafabricplus.protocolhack.netty.viabedrock.RakNetClientConnection;
|
||||
import de.florianmichael.viafabricplus.protocolhack.netty.viaversion.ViaFabricPlusViaDecoder;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.raphimc.vialoader.netty.CompressionReorderEvent;
|
||||
import net.raphimc.vialoader.netty.VLLegacyPipeline;
|
||||
@ -40,6 +42,11 @@ public class ViaFabricPlusVLLegacyPipeline extends VLLegacyPipeline {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChannelHandler createViaDecoder() {
|
||||
return new ViaFabricPlusViaDecoder(this.user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerAdded(ChannelHandlerContext ctx) {
|
||||
super.handlerAdded(ctx);
|
||||
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
|
||||
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.florianmichael.viafabricplus.protocolhack.netty.viaversion;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import de.florianmichael.viafabricplus.ViaFabricPlus;
|
||||
import de.florianmichael.viafabricplus.base.settings.groups.GeneralSettings;
|
||||
import de.florianmichael.viafabricplus.util.ChatUtil;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.raphimc.vialoader.netty.ViaDecoder;
|
||||
|
||||
public class ViaFabricPlusViaDecoder extends ViaDecoder {
|
||||
|
||||
public ViaFabricPlusViaDecoder(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
final var mode = GeneralSettings.INSTANCE.ignorePacketTranslationErrors.getIndex();
|
||||
|
||||
if (mode > 0) {
|
||||
try {
|
||||
super.channelRead(ctx, msg);
|
||||
} catch (Throwable t) {
|
||||
ViaFabricPlus.LOGGER.error("Error occurred while decoding packet in ViaDecoder", t);
|
||||
if (mode == 1) {
|
||||
ChatUtil.sendPrefixedMessage(Formatting.RED + "An error occurred while decoding a packet! See more details in the logs!");
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
super.channelRead(ctx, msg);
|
||||
}
|
||||
}
|
@ -18,8 +18,10 @@
|
||||
package de.florianmichael.viafabricplus.protocolhack.provider.vialegacy;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import de.florianmichael.viafabricplus.ViaFabricPlus;
|
||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
||||
import de.florianmichael.viafabricplus.base.settings.groups.AuthenticationSettings;
|
||||
import de.florianmichael.viafabricplus.util.ChatUtil;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
@ -31,16 +33,15 @@ public class ViaFabricPlusOldAuthProvider extends OldAuthProvider {
|
||||
public void sendAuthRequest(UserConnection user, String serverId) throws Throwable {
|
||||
if (!AuthenticationSettings.INSTANCE.allowViaLegacyToCallJoinServerToVerifySession.getValue()) return;
|
||||
|
||||
final MinecraftClient mc = MinecraftClient.getInstance();
|
||||
|
||||
try {
|
||||
final var mc = MinecraftClient.getInstance();
|
||||
|
||||
mc.getSessionService().joinServer(mc.getSession().getProfile(), mc.getSession().getAccessToken(), serverId);
|
||||
} catch (Exception e) {
|
||||
ViaFabricPlus.LOGGER.error("Error occurred while calling join server to verify session", e);
|
||||
|
||||
if (AuthenticationSettings.INSTANCE.disconnectIfJoinServerCallFails.getValue()) {
|
||||
user.getChannel().attr(ProtocolHack.LOCAL_MINECRAFT_CONNECTION).get().
|
||||
disconnect(Text.literal(Formatting.GOLD + "[ViaFabricPlus] " + Formatting.WHITE + Text.translatable("authentication.viafabricplus.error")));
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
user.getChannel().attr(ProtocolHack.LOCAL_MINECRAFT_CONNECTION).get().disconnect(ChatUtil.prefixText(Text.translatable("authentication.viafabricplus.error")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
|
||||
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.florianmichael.viafabricplus.util;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
||||
public class ChatUtil {
|
||||
public final static String PREFIX = Formatting.WHITE + "[" + Formatting.GOLD + "ViaFabricPlus" + Formatting.WHITE + "]";
|
||||
|
||||
public static Text prefixText(final String message) {
|
||||
return prefixText(Text.literal(message));
|
||||
}
|
||||
|
||||
public static Text prefixText(final Text message) {
|
||||
return Text.literal("").append(PREFIX).append(" " + message);
|
||||
}
|
||||
|
||||
public static void sendPrefixedMessage(final String message) {
|
||||
MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(prefixText(message));
|
||||
}
|
||||
}
|
@ -21,6 +21,9 @@
|
||||
"words.viafabricplus.addserverscreenbuttontitle": "Set version for this server",
|
||||
"words.viafabricplus.all": "Vanilla and Modded",
|
||||
"words.viafabricplus.vanillaonly": "Vanilla only",
|
||||
"words.viafabricplus.kick": "Kick",
|
||||
"words.viafabricplus.cancelnotify": "Cancel and notify",
|
||||
"words.viafabricplus.cancel": "Cancel",
|
||||
|
||||
"settings.viafabricplus.authentication": "Authentication",
|
||||
"settings.viafabricplus.experimental": "Experimental",
|
||||
@ -37,6 +40,7 @@
|
||||
"general.viafabricplus.creative": "Remove not available items from creative tab",
|
||||
"general.viafabricplus.autodetect": "Auto detect version",
|
||||
"general.viafabricplus.advertised": "Show advertised/server version in Multiplayer",
|
||||
"general.viafabricplus.ignoreerrors": "Ignore packet translation errors",
|
||||
|
||||
"bedrock.viafabricplus.confirmtransfer": "Open prompt GUI to confirm transferring to other servers",
|
||||
"bedrock.viafabricplus.authentication": "Click to set account for Bedrock edition",
|
||||
|
@ -82,6 +82,7 @@
|
||||
"fixes.minecraft.entity.MixinEntityPredicates",
|
||||
"fixes.minecraft.entity.MixinItemEntity",
|
||||
"fixes.minecraft.entity.MixinLivingEntity",
|
||||
"fixes.minecraft.entity.MixinLockableContainerBlockEntity",
|
||||
"fixes.minecraft.entity.MixinOtherClientPlayerEntity",
|
||||
"fixes.minecraft.entity.MixinPiglinEntity",
|
||||
"fixes.minecraft.entity.MixinPlayerEntity",
|
||||
@ -170,8 +171,7 @@
|
||||
"ipnext.MixinAutoRefillHandler_ItemSlotMonitor",
|
||||
"jsonwebtoken.MixinClasses",
|
||||
"jsonwebtoken.MixinDefaultCompressionCodecResolver",
|
||||
"jsonwebtoken.MixinDefaultJwtParserBuilder",
|
||||
"fixes.minecraft.entity.MixinLockableContainerBlockEntity"
|
||||
"jsonwebtoken.MixinDefaultJwtParserBuilder"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
Loading…
Reference in New Issue
Block a user