feat(Access): added access list
Some checks failed
Build the Docker Image / docker (push) Has been cancelled
Some checks failed
Build the Docker Image / docker (push) Has been cancelled
This commit is contained in:
parent
9460828187
commit
02a88f53da
2 changed files with 35 additions and 1 deletions
|
@ -3,12 +3,14 @@ package de.pauljako.cosmeticserver;
|
||||||
import de.craftsblock.craftsnet.addon.Addon;
|
import de.craftsblock.craftsnet.addon.Addon;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class CosmeticServer extends Addon {
|
public class CosmeticServer extends Addon {
|
||||||
|
|
||||||
|
|
||||||
private static CosmeticServer instance;
|
private static CosmeticServer instance;
|
||||||
public File cosmeticFile;
|
public File cosmeticFile;
|
||||||
|
public File accessFile;
|
||||||
private Thread thread;
|
private Thread thread;
|
||||||
|
|
||||||
public static CosmeticServer instance() {
|
public static CosmeticServer instance() {
|
||||||
|
@ -25,6 +27,24 @@ public class CosmeticServer extends Addon {
|
||||||
|
|
||||||
cosmeticFile = new File(getDataFolder(), "cosmetics.json");
|
cosmeticFile = new File(getDataFolder(), "cosmetics.json");
|
||||||
|
|
||||||
|
if (!cosmeticFile.exists()) {
|
||||||
|
try {
|
||||||
|
cosmeticFile.createNewFile();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
accessFile = new File(getDataFolder(), "access.json");
|
||||||
|
|
||||||
|
if (!accessFile.exists()) {
|
||||||
|
try {
|
||||||
|
accessFile.createNewFile();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
routeRegistry().share("/v1/cosmetic/assets", assets);
|
routeRegistry().share("/v1/cosmetic/assets", assets);
|
||||||
|
|
||||||
CosmeticSocket socket = new CosmeticSocket();
|
CosmeticSocket socket = new CosmeticSocket();
|
||||||
|
|
|
@ -15,6 +15,7 @@ import de.craftsblock.craftsnet.api.websocket.annotations.Socket;
|
||||||
import de.craftsblock.craftsnet.events.sockets.ClientDisconnectEvent;
|
import de.craftsblock.craftsnet.events.sockets.ClientDisconnectEvent;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@ -79,7 +80,9 @@ public class CosmeticSocket implements SocketHandler, ListenerAdapter {
|
||||||
UUID uuid = UUID.fromString(data.getString("uuid"));
|
UUID uuid = UUID.fromString(data.getString("uuid"));
|
||||||
|
|
||||||
ConcurrentHashMap<String, Object> cosmetics = new ConcurrentHashMap<>();
|
ConcurrentHashMap<String, Object> cosmetics = new ConcurrentHashMap<>();
|
||||||
data.get("cosmetics").getAsJsonObject().entrySet().forEach(entry -> cosmetics.put(entry.getKey(), entry.getValue()));
|
data.get("cosmetics").getAsJsonObject().entrySet().forEach(entry -> {
|
||||||
|
if (isAllowedToHaveCosmetic(entry.getKey(), entry.getValue().toString(), uuid.toString())) cosmetics.put(entry.getKey(), entry.getValue());
|
||||||
|
});
|
||||||
|
|
||||||
ClientMapping mapping = new ClientMapping(uuid, cosmetics);
|
ClientMapping mapping = new ClientMapping(uuid, cosmetics);
|
||||||
exchange.broadcast(JsonParser.parse("{}").set("uuid", uuid.toString()).set("cosmetics", bakeData(cosmetics)).toString());
|
exchange.broadcast(JsonParser.parse("{}").set("uuid", uuid.toString()).set("cosmetics", bakeData(cosmetics)).toString());
|
||||||
|
@ -147,6 +150,17 @@ public class CosmeticSocket implements SocketHandler, ListenerAdapter {
|
||||||
return object.getObject();
|
return object.getObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isAllowedToHaveCosmetic(String type, String value, String uuid) {
|
||||||
|
Json access = JsonParser.parse(CosmeticServer.instance().accessFile);
|
||||||
|
|
||||||
|
String path = type.replace(".", "\\.") + "." + value.replace(".", "\\.");
|
||||||
|
if (!access.contains(type.replace(".", "\\.")) || !access.contains(path)) return true;
|
||||||
|
|
||||||
|
Collection<String> allowedUUIDs = access.getStringList(path);
|
||||||
|
|
||||||
|
return allowedUUIDs.contains(uuid.toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void handleDisconnect(ClientDisconnectEvent event) {
|
public void handleDisconnect(ClientDisconnectEvent event) {
|
||||||
WebSocketClient client = event.getExchange().client();
|
WebSocketClient client = event.getExchange().client();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue