Updates
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Dieser Commit ist enthalten in:
Chaoscaot 2023-11-12 22:44:30 +01:00
Ursprung fa04945595
Commit 61985fb806
3 geänderte Dateien mit 58 neuen und 31 gelöschten Zeilen

Datei anzeigen

@ -44,8 +44,8 @@ ext {
compileJava.options.encoding = 'UTF-8'
sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceCompatibility = 17
targetCompatibility = 17
sourceSets {
main {

Datei anzeigen

@ -20,9 +20,11 @@
package de.steamwar.sql;
import de.steamwar.sql.internal.Field;
import de.steamwar.sql.internal.SelectStatement;
import de.steamwar.sql.internal.Statement;
import de.steamwar.sql.internal.Table;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@ -30,13 +32,13 @@ import java.sql.Timestamp;
import java.time.Instant;
@AllArgsConstructor
@Getter
public class NodeDownload {
private static final char[] HEX = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
private static final String LINK_BASE = "https://steamwar.de/download.php?schem=";
private static final Table<NodeDownload> table = new Table<>(NodeDownload.class);
private static final Statement insert = table.insertFields("NodeId", "Link");
private static final SelectStatement<NodeDownload> select = table.selectFields("Link");
private static final SelectStatement<NodeDownload> getId = table.select(Table.PRIMARY);
private static final Statement delete = table.delete(Table.PRIMARY);
@Field(keys = {Table.PRIMARY})
private final int nodeId;
@ -45,25 +47,20 @@ public class NodeDownload {
@Field(def = "CURRENT_TIMESTAMP")
private final Timestamp timestamp;
public static String getLink(SchematicNode schem){
if(schem.isDir())
throw new SecurityException("Can not Download Directorys");
MessageDigest digest;
try {
digest = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException e) {
throw new SecurityException(e);
public static NodeDownload addCode(SchematicNode node, String link) {
insert.update(node.getId(), link);
return get(node.getId());
}
digest.reset();
digest.update((Instant.now().toString() + schem.getOwner() + schem.getId()).getBytes());
String hash = base16encode(digest.digest());
insert.update(schem.getId(), hash);
return LINK_BASE + hash;
public static NodeDownload get(int nodeId) {
return getId.select(nodeId);
}
public static String base16encode(byte[] byteArray) {
StringBuilder hexBuffer = new StringBuilder(byteArray.length * 2);
for (byte b : byteArray)
hexBuffer.append(HEX[(b >>> 4) & 0xF]).append(HEX[b & 0xF]);
return hexBuffer.toString();
public static NodeDownload get(String link) {
return select.select(link);
}
public void delete() {
delete.update(nodeId);
}
}

Datei anzeigen

@ -384,7 +384,7 @@ public class SchematicNode {
public int getRank() {
if (isDir())
throw new SecurityException("Node is Directory");
return 0;
return nodeRank;
}
@ -401,7 +401,7 @@ public class SchematicNode {
public SchematicType getSchemtype() {
if (isDir())
throw new SecurityException("Is Directory");
return null;
return nodeType;
}
@ -443,8 +443,25 @@ public class SchematicNode {
return SchemElo.getElo(this, season);
}
public boolean accessibleByUser(int user) {
return NodeMember.getNodeMember(nodeId, user) != null;
public boolean accessibleByUser(SteamwarUser user) {
if (user.getId() == nodeOwner) {
return true;
}
if (parentNode == null) {
return false;
}
SchematicNode parent = getParentNode();
while (parent != null) {
NodeMember member = NodeMember.getNodeMember(nodeId, user.getId());
if (member != null || (parent.getOwner() == user.getId() && parent.parentNode == null)) {
return true;
}
parent = parent.getParentNode();
}
return false;
}
public Set<NodeMember> getMembers() {
@ -506,6 +523,19 @@ public class SchematicNode {
return builder.toString();
}
public List<Map.Entry<String, Integer>> generateBreadcrumbsMap(SteamwarUser user) {
List<Map.Entry<String, Integer>> map = new ArrayList<>();
Optional<SchematicNode> currentNode = Optional.of(this);
if(currentNode.map(SchematicNode::isDir).orElse(false)) {
map.add(Map.entry(getName(), getId()));
}
while (currentNode.isPresent()) {
currentNode = currentNode.flatMap(schematicNode -> Optional.ofNullable(NodeMember.getNodeMember(schematicNode.getId(), effectiveOwner)).map(NodeMember::getParent).orElse(schematicNode.getOptionalParent())).map(SchematicNode::getSchematicNode);
currentNode.ifPresent(node -> map.add(0, Map.entry(node.getName(), node.getId())));
}
return map;
}
private static final List<String> FORBIDDEN_NAMES = Collections.unmodifiableList(Arrays.asList("public"));
public static boolean invalidSchemName(String[] layers) {
for (String layer : layers) {