mirror of https://github.com/LOOHP/Limbo.git
Clean up whitelist changes
This commit is contained in:
parent
f8bad7fa14
commit
c720a0fd67
|
|
@ -433,29 +433,6 @@ public class Limbo {
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadAllowlist() {
|
|
||||||
properties.reloadAllowlist();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean uuidIsAllowed(UUID requestedUuid) {
|
|
||||||
if (!properties.isEnforceAllowlist()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (properties.uuidIsAllowed(requestedUuid)) {
|
|
||||||
if(!properties.isReducedDebugInfo()) {
|
|
||||||
Limbo.getInstance().getConsole().sendMessage(String.format("allowlist: %s allowed", requestedUuid.toString()));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!properties.isReducedDebugInfo()) {
|
|
||||||
Limbo.getInstance().getConsole().sendMessage(String.format("allowlist: %s not allowed", requestedUuid.toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ServerConnection getServerConnection() {
|
public ServerConnection getServerConnection() {
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -165,14 +165,16 @@ public class DefaultCommands implements CommandExecutor, TabCompletor {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (args[0].equalsIgnoreCase("allowlist")) {
|
|
||||||
if (sender.hasPermission("limboserver.allowlist")) {
|
if (args[0].equalsIgnoreCase("whitelist")) {
|
||||||
|
if (sender.hasPermission("limboserver.whitelist")) {
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
sender.sendMessage(ChatColor.RED + "Invalid usage!");
|
sender.sendMessage(ChatColor.RED + "Invalid usage!");
|
||||||
} else if (!args[1].equalsIgnoreCase("reload")) {
|
} else if (!args[1].equalsIgnoreCase("reload")) {
|
||||||
sender.sendMessage(ChatColor.RED + "Invalid usage!");
|
sender.sendMessage(ChatColor.RED + "Invalid usage!");
|
||||||
} else {
|
} else {
|
||||||
Limbo.getInstance().reloadAllowlist();
|
Limbo.getInstance().getServerProperties().reloadWhitelist();
|
||||||
|
sender.sendMessage("Whitelist has been reloaded");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(ChatColor.RED + "You do not have permission to use that command!");
|
sender.sendMessage(ChatColor.RED + "You do not have permission to use that command!");
|
||||||
|
|
|
||||||
|
|
@ -19,33 +19,6 @@
|
||||||
|
|
||||||
package com.loohp.limbo.file;
|
package com.loohp.limbo.file;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
|
|
||||||
import org.json.simple.JSONArray;
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.json.simple.parser.JSONParser;
|
|
||||||
import org.json.simple.parser.ParseException;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.loohp.limbo.Console;
|
import com.loohp.limbo.Console;
|
||||||
import com.loohp.limbo.Limbo;
|
import com.loohp.limbo.Limbo;
|
||||||
|
|
@ -53,9 +26,28 @@ import com.loohp.limbo.location.Location;
|
||||||
import com.loohp.limbo.utils.GameMode;
|
import com.loohp.limbo.utils.GameMode;
|
||||||
import com.loohp.limbo.utils.NamespacedKey;
|
import com.loohp.limbo.utils.NamespacedKey;
|
||||||
import com.loohp.limbo.world.World;
|
import com.loohp.limbo.world.World;
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import org.json.simple.parser.JSONParser;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ServerProperties {
|
public class ServerProperties {
|
||||||
|
|
||||||
|
|
@ -84,8 +76,8 @@ public class ServerProperties {
|
||||||
private int viewDistance;
|
private int viewDistance;
|
||||||
private double ticksPerSecond;
|
private double ticksPerSecond;
|
||||||
private boolean handshakeVerbose;
|
private boolean handshakeVerbose;
|
||||||
private boolean enforceAllowlist;
|
private boolean enforceWhitelist;
|
||||||
private HashMap<UUID, Boolean> allowlist;
|
private Set<UUID> whitelist;
|
||||||
|
|
||||||
private String resourcePackSHA1;
|
private String resourcePackSHA1;
|
||||||
private String resourcePackLink;
|
private String resourcePackLink;
|
||||||
|
|
@ -106,7 +98,7 @@ public class ServerProperties {
|
||||||
defStream.close();
|
defStream.close();
|
||||||
|
|
||||||
Properties prop = new Properties();
|
Properties prop = new Properties();
|
||||||
InputStreamReader stream = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
|
InputStreamReader stream = new InputStreamReader(Files.newInputStream(file.toPath()), StandardCharsets.UTF_8);
|
||||||
prop.load(stream);
|
prop.load(stream);
|
||||||
stream.close();
|
stream.close();
|
||||||
|
|
||||||
|
|
@ -115,7 +107,7 @@ public class ServerProperties {
|
||||||
String value = entry.getValue().toString();
|
String value = entry.getValue().toString();
|
||||||
prop.putIfAbsent(key, value);
|
prop.putIfAbsent(key, value);
|
||||||
}
|
}
|
||||||
PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8));
|
PrintWriter pw = new PrintWriter(new OutputStreamWriter(Files.newOutputStream(file.toPath()), StandardCharsets.UTF_8));
|
||||||
prop.store(pw, COMMENT);
|
prop.store(pw, COMMENT);
|
||||||
pw.close();
|
pw.close();
|
||||||
|
|
||||||
|
|
@ -198,63 +190,53 @@ public class ServerProperties {
|
||||||
favicon = Optional.empty();
|
favicon = Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
enforceAllowlist = Boolean.parseBoolean(prop.getProperty("enforce-allowlist"));
|
enforceWhitelist = Boolean.parseBoolean(prop.getProperty("enforce-whitelist"));
|
||||||
if (enforceAllowlist) {
|
if (enforceWhitelist) {
|
||||||
reloadAllowlist();
|
reloadWhitelist();
|
||||||
}
|
}
|
||||||
|
|
||||||
Limbo.getInstance().getConsole().sendMessage("Loaded server.properties");
|
Limbo.getInstance().getConsole().sendMessage("Loaded server.properties");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadAllowlist() {
|
public void reloadWhitelist() {
|
||||||
Console console = Limbo.getInstance().getConsole();
|
Console console = Limbo.getInstance().getConsole();
|
||||||
|
|
||||||
allowlist = new HashMap<UUID, Boolean>();
|
whitelist = new HashSet<>();
|
||||||
try {
|
try {
|
||||||
JSONParser parser = new JSONParser();
|
JSONParser parser = new JSONParser();
|
||||||
Object obj = parser.parse(new FileReader("allowlist.json"));
|
Object obj = parser.parse(new InputStreamReader(Files.newInputStream(new File("whitelist.json").toPath()), StandardCharsets.UTF_8));
|
||||||
|
|
||||||
if (!(obj instanceof JSONArray)) {
|
if (!(obj instanceof JSONArray)) {
|
||||||
console.sendMessage("allowlist: expected [] got {}");
|
console.sendMessage("whitelist: expected [] got {}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONArray array = (JSONArray) obj;
|
JSONArray array = (JSONArray) obj;
|
||||||
|
|
||||||
Iterator<?> iter = array.iterator();
|
for (Object o : array) {
|
||||||
while (iter.hasNext()) {
|
if (!(o instanceof JSONObject)) {
|
||||||
Object o = iter.next();
|
console.sendMessage("whitelist: array element is not an object");
|
||||||
if (!(o instanceof JSONObject)) {
|
continue;
|
||||||
console.sendMessage("allowlist: array element is not an object");
|
}
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONObject element = (JSONObject) o;
|
JSONObject element = (JSONObject) o;
|
||||||
o = element.get("uuid");
|
o = element.get("uuid");
|
||||||
if (o == null) {
|
if (o == null) {
|
||||||
console.sendMessage("allowlist: missing uuid attribute");
|
console.sendMessage("whitelist: missing uuid attribute");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!(o instanceof String)) {
|
if (!(o instanceof String)) {
|
||||||
console.sendMessage("allowlist: uuid is not a string");
|
console.sendMessage("whitelist: uuid is not a string");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String uuidStr = (String) o;
|
String uuidStr = (String) o;
|
||||||
UUID allowedUuid = UUID.fromString(uuidStr);
|
UUID allowedUuid = UUID.fromString(uuidStr);
|
||||||
allowlist.put(allowedUuid, true);
|
whitelist.add(allowedUuid);
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (Exception e) {
|
||||||
console.sendMessage(e.toString());
|
e.printStackTrace();
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
console.sendMessage(String.format("allowlist: %s", e.toString()));
|
|
||||||
} catch (IOException e) {
|
|
||||||
console.sendMessage(String.format("allowlist: %s", e.toString()));
|
|
||||||
} catch (ParseException e) {
|
|
||||||
console.sendMessage(String.format(" allowlist: parse: %s", e.toString()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.sendMessage("allowlist: reloaded");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getServerImplementationVersion() {
|
public String getServerImplementationVersion() {
|
||||||
|
|
@ -365,15 +347,12 @@ public class ServerProperties {
|
||||||
return handshakeVerbose;
|
return handshakeVerbose;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnforceAllowlist() {
|
public boolean enforceWhitelist() {
|
||||||
return enforceAllowlist;
|
return enforceWhitelist;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean uuidIsAllowed(UUID requestedUuid) {
|
public boolean uuidWhitelisted(UUID uuid) {
|
||||||
if (allowlist.containsKey(requestedUuid)) {
|
return whitelist.contains(uuid);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getResourcePackLink() {
|
public String getResourcePackLink() {
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,7 @@ import com.loohp.limbo.world.BlockPosition;
|
||||||
import com.loohp.limbo.world.World;
|
import com.loohp.limbo.world.World;
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
|
@ -231,6 +232,11 @@ public class ClientConnection extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disconnectDuringLogin(Component reason) {
|
private void disconnectDuringLogin(Component reason) {
|
||||||
|
ServerProperties properties = Limbo.getInstance().getServerProperties();
|
||||||
|
if (!properties.isReducedDebugInfo()) {
|
||||||
|
String str = (properties.isLogPlayerIPAddresses() ? inetAddress.getHostName() : "<ip address withheld>") + ":" + clientSocket.getPort();
|
||||||
|
Limbo.getInstance().getConsole().sendMessage("[/" + str + "] <-> Player disconnected with the reason " + PlainTextComponentSerializer.plainText().serialize(reason));
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
PacketLoginOutDisconnect packet = new PacketLoginOutDisconnect(reason);
|
PacketLoginOutDisconnect packet = new PacketLoginOutDisconnect(reason);
|
||||||
sendPacket(packet);
|
sendPacket(packet);
|
||||||
|
|
@ -470,8 +476,8 @@ public class ClientConnection extends Thread {
|
||||||
|
|
||||||
UUID uuid = isBungeecord || isBungeeGuard ? bungeeUUID : UUID.nameUUIDFromBytes(("OfflinePlayer:" + username).getBytes(StandardCharsets.UTF_8));
|
UUID uuid = isBungeecord || isBungeeGuard ? bungeeUUID : UUID.nameUUIDFromBytes(("OfflinePlayer:" + username).getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
if (!Limbo.getInstance().uuidIsAllowed(uuid)) {
|
if (!properties.enforceWhitelist() && properties.uuidWhitelisted(uuid)) {
|
||||||
disconnectDuringLogin(TextComponent.fromLegacyText("You are not invited to this server"));
|
disconnectDuringLogin(TextComponent.fromLegacyText("You are not whitelisted on the server"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue