SteamWar/BungeeCore
Archiviert
13
2

Fix localhost connections #357

Zusammengeführt
Lixfel hat 2 Commits von FixLocalHost nach master 2022-05-24 20:06:12 +02:00 zusammengeführt
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.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;

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_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.

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