Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Commit

Permalink
Changes -> Added geyser standalone support
Browse files Browse the repository at this point in the history
  • Loading branch information
EinfacheSache committed Aug 1, 2023
1 parent 1faad5e commit 1d9dc48
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ protected void initChannel(Channel channel) {

initChannelMethod.invoke(bungeeChannelInitializer, channel);

if (channel.localAddress().toString().startsWith("local:")) {
AtomicReference<InetSocketAddress> playerAddress = new AtomicReference<>();
String sourceAddress = ((InetSocketAddress) channel.remoteAddress()).getAddress().getHostAddress();

if (channel.localAddress().toString().startsWith("local:") || sourceAddress.equals(Config.getGeyserServerIP())) {
instance.getCore().debug("Detected bedrock player (return)");
return;
}

AtomicReference<InetSocketAddress> playerAddress = new AtomicReference<>();
String sourceAddress = ((InetSocketAddress) channel.remoteAddress()).getAddress().getHostAddress();

if (!instance.getCore().getDirectConnectWhitelist().contains(sourceAddress)) {
if (instance.getCore().isSetup() && (instance.getCore().getRestAPI().getNeoServerIPs() == null ||
instance.getCore().getRestAPI().getNeoServerIPs().toList().stream().noneMatch(ipRange -> isIPInRange((String) ipRange, sourceAddress)))) {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/de/cubeattack/neoprotect/core/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Config {
private static String BackendID;
private static boolean updateIP;
private static boolean debugMode;
private static String geyserServerIP;
private static String updateSetting;

private static Core core;
Expand All @@ -33,6 +34,7 @@ public static void loadConfig(Core core, FileUtils config) {
BackendID = config.getString("gameshield.backendId", "");
updateIP = config.getBoolean("gameshield.autoUpdateIP", false);
debugMode = config.getBoolean("DebugMode", false);
geyserServerIP = config.getString("geyserServerIP", "127.0.0.1");

if (APIKey.length() != 64) {
core.severe("Failed to load API-Key. Key is null or not valid");
Expand Down Expand Up @@ -80,6 +82,10 @@ public static boolean isDebugMode() {
return debugMode;
}

public static String getGeyserServerIP() {
return geyserServerIP;
}

public static VersionUtils.UpdateSetting getAutoUpdaterSettings() {
return VersionUtils.UpdateSetting.getByNameOrDefault(updateSetting);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {

instance.getCore().debug("Open channel (" + channel.remoteAddress().toString() + ")");

if (channel.localAddress().toString().startsWith("local:")) {
if (channel.localAddress().toString().startsWith("local:") || ((InetSocketAddress) channel.remoteAddress()).getAddress().getHostAddress().equals(Config.getGeyserServerIP())) {
instance.getCore().debug("Detected bedrock player (return)");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ protected void initChannel(Channel channel) {
initChannelMethod.getMethod().setAccessible(true);
initChannelMethod.invoke(oldInitializer, channel);

if (channel.localAddress().toString().startsWith("local:")) {
AtomicReference<InetSocketAddress> playerAddress = new AtomicReference<>();
String sourceAddress = ((InetSocketAddress) channel.remoteAddress()).getAddress().getHostAddress();

if (channel.localAddress().toString().startsWith("local:") || sourceAddress.equals(Config.getGeyserServerIP())) {
instance.getCore().debug("Detected bedrock player (return)");
return;
}

AtomicReference<InetSocketAddress> playerAddress = new AtomicReference<>();
String sourceAddress = ((InetSocketAddress) channel.remoteAddress()).getAddress().getHostAddress();

if (!instance.getCore().getDirectConnectWhitelist().contains(sourceAddress)) {
if (instance.getCore().isSetup() && (instance.getCore().getRestAPI().getNeoServerIPs() == null ||
instance.getCore().getRestAPI().getNeoServerIPs().toList().stream().noneMatch(ipRange -> isIPInRange((String) ipRange, sourceAddress)))) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ gameshield:
serverId: '' # The serverID is set automatically during setup
backendId: '' # The backendID is set automatically during setup
autoUpdateIP: false # This setting automatically sets the IP of the NeoProtect backend every 10 seconds
geyserServerIP: '127.0.0.1' #IMPORTANT ONLY FOR GEYSER STANDALONE
DebugMode: false # IMPORTANT Please ensure that you activate this option solely upon receiving a prompt from a NeoProtect maintainer.

0 comments on commit 1d9dc48

Please sign in to comment.