Skip to content

Commit

Permalink
Added server blacklist (Can be disabled)
Browse files Browse the repository at this point in the history
For now only hive is blocked due to request from Hive Games
  • Loading branch information
RaphiMC committed Jan 11, 2025
1 parent b6a634b commit eb1d699
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/net/raphimc/viabedrock/ViaBedrockConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class ViaBedrockConfig extends Config implements net.raphimc.viabedrock.p
private String resourcePackUrl;
private PackCacheMode packCacheMode;
private boolean translateShowCoordinatesGameRule;
private boolean disableServerBlacklist;

public ViaBedrockConfig(final File configFile, final Logger logger) {
super(configFile, logger);
Expand All @@ -54,6 +55,7 @@ private void loadFields() {
this.resourcePackUrl = this.getString("resource-pack-url", "");
this.packCacheMode = PackCacheMode.byName(this.getString("pack-cache", "disk"));
this.translateShowCoordinatesGameRule = this.getBoolean("translate-show-coordinates-game-rule", false);
this.disableServerBlacklist = this.getBoolean("disable-server-blacklist", false);
}

@Override
Expand Down Expand Up @@ -105,4 +107,9 @@ public boolean shouldTranslateShowCoordinatesGameRule() {
return this.translateShowCoordinatesGameRule;
}

@Override
public boolean shouldDisableServerBlacklist() {
return this.disableServerBlacklist;
}

}
36 changes: 36 additions & 0 deletions src/main/java/net/raphimc/viabedrock/api/util/ServerBlacklist.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This file is part of ViaBedrock - https://github.com/RaphiMC/ViaBedrock
* Copyright (C) 2023-2025 RK_01/RaphiMC 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 net.raphimc.viabedrock.api.util;

import java.util.List;
import java.util.Locale;

public class ServerBlacklist {

private static final List<String> BLACKLISTED_HOSTS = List.of(
"geo.hivebedrock.network",
"ca.hivebedrock.network",
"fr.hivebedrock.network",
"sg.hivebedrock.network"
);

public static boolean isBlacklisted(final String hostname) {
return BLACKLISTED_HOSTS.contains(hostname.toLowerCase(Locale.ROOT));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public interface ViaBedrockConfig extends Config {
*/
boolean shouldTranslateShowCoordinatesGameRule();

/**
* @return If true, disables the internal server blacklist. This will allow you to connect to any server, even if it's known to ban ViaBedrock clients
*/
boolean shouldDisableServerBlacklist();

enum BlobCacheMode {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
import com.viaversion.viaversion.protocols.base.ServerboundHandshakePackets;
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
import io.jsonwebtoken.*;
import io.jsonwebtoken.gson.io.GsonDeserializer;
import io.netty.util.AsciiString;
import net.raphimc.viabedrock.ViaBedrock;
import net.raphimc.viabedrock.api.io.compression.ProtocolCompression;
import net.raphimc.viabedrock.api.util.PacketFactory;
import net.raphimc.viabedrock.api.util.ServerBlacklist;
import net.raphimc.viabedrock.protocol.BedrockProtocol;
import net.raphimc.viabedrock.protocol.ClientboundBedrockPackets;
import net.raphimc.viabedrock.protocol.ServerboundBedrockPackets;
Expand Down Expand Up @@ -149,6 +153,21 @@ protected Key locate(ProtectedHeader header) {
protocol.registerServerboundTransition(ServerboundLoginPackets.HELLO, ServerboundBedrockPackets.REQUEST_NETWORK_SETTINGS, wrapper -> {
final HandshakeStorage handshakeStorage = wrapper.user().get(HandshakeStorage.class);

if (!ViaBedrock.getConfig().shouldDisableServerBlacklist() && ServerBlacklist.isBlacklisted(handshakeStorage.hostname())) {
wrapper.cancel();
try {
final PacketWrapper loginDisconnect = PacketWrapper.create(ClientboundLoginPackets.LOGIN_DISCONNECT, wrapper.user());
PacketFactory.writeJavaDisconnect(loginDisconnect, "§cThis server is blacklisted by ViaBedrock because the server is known to ban players joining with ViaBedrock (Due to the server's anti-cheat).\n\n§7If you want to join the server anyway, set disable-server-blacklist to true in the ViaBedrock config file.");
loginDisconnect.send(BedrockProtocol.class);
} catch (Throwable ignored) {
}
if (wrapper.user().getChannel() != null) {
wrapper.user().getChannel().flush();
wrapper.user().getChannel().close();
}
return;
}

final ProtocolInfo protocolInfo = wrapper.user().getProtocolInfo();
protocolInfo.setUsername(wrapper.read(Types.STRING));
protocolInfo.setUuid(wrapper.read(Types.UUID));
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/viabedrock/viabedrock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ resource-pack-url: ""
pack-cache: "disk"
# If true, translates bedrock's showCoordinates game rule to java's reduced debug info flag
translate-show-coordinates-game-rule: false
# If true, disables the internal server blacklist. This will allow you to connect to any server, even if it's known to ban ViaBedrock clients
disable-server-blacklist: false

0 comments on commit eb1d699

Please sign in to comment.