From b3d16a1279abf2f3293c8f40dce607fc2798f906 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 24 May 2022 19:45:20 +0200 Subject: [PATCH 1/2] Fix localhost connections --- .../bungeecore/commands/TeamCommand.java | 24 ++++++++++++++++++- .../steamwar/messages/BungeeCore.properties | 1 + .../messages/BungeeCore_de.properties | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index 20b4b95..2c58296 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -35,7 +35,7 @@ import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; -import java.net.InetSocketAddress; +import java.net.*; import java.time.Instant; import java.time.format.DateTimeFormatter; import java.util.ArrayList; @@ -600,6 +600,15 @@ public class TeamCommand extends BasicCommand { return; } String server = args[1]; + try { + if (isLocalhost(InetAddress.getByName(server))) { + Message.send("TEAM_SERVER_ADDRESS_INVALID", player); + return; + } + } catch (UnknownHostException e) { + Message.send("TEAM_SERVER_ADDRESS_INVALID", player); + return; + } int port = 25565; if (args.length == 3) { try { @@ -619,6 +628,19 @@ public class TeamCommand extends BasicCommand { Message.send("TEAM_SERVER_SET", player); } + private static boolean isLocalhost(InetAddress addr) { + // Check if the address is a valid special local or loop back + if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) + return true; + + // Check if the address is defined on any interface + try { + return NetworkInterface.getByInetAddress(addr) != null; + } catch (SocketException e) { + return false; + } + } + private void changeColor(ProxiedPlayer player, SteamwarUser user, Team team) { if(notLeader(player, user, team)) return; diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index b7859d6..95a1d5e 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -476,6 +476,7 @@ TEAM_COLOR_TITLE=Choose color TEAM_SERVER_USAGE=§8/§7team server §8[§eIP/address§8] §8(§7port§8) §8- §7Sets the address of the team server. TEAM_SERVER_SET=§7You changed the team server address§8! TEAM_SERVER_PORT_INVALID=§cInvalid port number. +TEAM_SERVER_ADDRESS_INVALID=§cInvalid address. TEAM_NO_ADDRESS=§cNo team server address set. TEAM_TP_NO_TEAM=§cUnknown team. diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index 3067774..0f0394d 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -455,6 +455,7 @@ TEAM_COLOR_TITLE=Farbe wählen TEAM_SERVER_USAGE=§8/§7team server §8[§eIP/Adresse§8] §8(§7Port§8) §8- §7Setzt Adresse des Teamservers. TEAM_SERVER_SET=§7Du hast die Teamserveradresse geändert§8! TEAM_SERVER_PORT_INVALID=§cUnmögliche Portnummer. +TEAM_SERVER_ADDRESS_INVALID=§cInvalide Adresse. TEAM_NO_ADDRESS=§cTeamserveradresse nicht gesetzt. TEAM_TP_NO_TEAM=§cUnbekanntes Team. From 63b6450ae8e771de94390b54777bbf348696babb Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 24 May 2022 20:04:35 +0200 Subject: [PATCH 2/2] Fix localhost connections --- src/de/steamwar/messages/BungeeCore_de.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index 0f0394d..26d21bc 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -455,7 +455,7 @@ TEAM_COLOR_TITLE=Farbe wählen TEAM_SERVER_USAGE=§8/§7team server §8[§eIP/Adresse§8] §8(§7Port§8) §8- §7Setzt Adresse des Teamservers. TEAM_SERVER_SET=§7Du hast die Teamserveradresse geändert§8! TEAM_SERVER_PORT_INVALID=§cUnmögliche Portnummer. -TEAM_SERVER_ADDRESS_INVALID=§cInvalide Adresse. +TEAM_SERVER_ADDRESS_INVALID=§cUngültige Adresse. TEAM_NO_ADDRESS=§cTeamserveradresse nicht gesetzt. TEAM_TP_NO_TEAM=§cUnbekanntes Team.