Archiviert
1
0

Fix localhost connections

Dieser Commit ist enthalten in:
yoyosource 2022-05-24 19:45:20 +02:00
Ursprung 29b2aee2f1
Commit b3d16a1279
3 geänderte Dateien mit 25 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -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.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.net.InetSocketAddress; import java.net.*;
import java.time.Instant; import java.time.Instant;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
@ -600,6 +600,15 @@ public class TeamCommand extends BasicCommand {
return; return;
} }
String server = args[1]; 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; int port = 25565;
if (args.length == 3) { if (args.length == 3) {
try { try {
@ -619,6 +628,19 @@ public class TeamCommand extends BasicCommand {
Message.send("TEAM_SERVER_SET", player); 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) { private void changeColor(ProxiedPlayer player, SteamwarUser user, Team team) {
if(notLeader(player, user, team)) if(notLeader(player, user, team))
return; return;

Datei anzeigen

@ -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_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_SET=§7You changed the team server address§8!
TEAM_SERVER_PORT_INVALID=§cInvalid port number. TEAM_SERVER_PORT_INVALID=§cInvalid port number.
TEAM_SERVER_ADDRESS_INVALID=§cInvalid address.
TEAM_NO_ADDRESS=§cNo team server address set. TEAM_NO_ADDRESS=§cNo team server address set.
TEAM_TP_NO_TEAM=§cUnknown team. TEAM_TP_NO_TEAM=§cUnknown team.

Datei anzeigen

@ -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_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_SET=§7Du hast die Teamserveradresse geändert§8!
TEAM_SERVER_PORT_INVALID=§cUnmögliche Portnummer. TEAM_SERVER_PORT_INVALID=§cUnmögliche Portnummer.
TEAM_SERVER_ADDRESS_INVALID=§cInvalide Adresse.
TEAM_NO_ADDRESS=§cTeamserveradresse nicht gesetzt. TEAM_NO_ADDRESS=§cTeamserveradresse nicht gesetzt.
TEAM_TP_NO_TEAM=§cUnbekanntes Team. TEAM_TP_NO_TEAM=§cUnbekanntes Team.