Dieser Commit ist enthalten in:
Ursprung
fa04945595
Commit
61985fb806
@ -44,8 +44,8 @@ ext {
|
|||||||
|
|
||||||
compileJava.options.encoding = 'UTF-8'
|
compileJava.options.encoding = 'UTF-8'
|
||||||
|
|
||||||
sourceCompatibility = 1.8
|
sourceCompatibility = 17
|
||||||
targetCompatibility = 1.8
|
targetCompatibility = 17
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
|
@ -20,9 +20,11 @@
|
|||||||
package de.steamwar.sql;
|
package de.steamwar.sql;
|
||||||
|
|
||||||
import de.steamwar.sql.internal.Field;
|
import de.steamwar.sql.internal.Field;
|
||||||
|
import de.steamwar.sql.internal.SelectStatement;
|
||||||
import de.steamwar.sql.internal.Statement;
|
import de.steamwar.sql.internal.Statement;
|
||||||
import de.steamwar.sql.internal.Table;
|
import de.steamwar.sql.internal.Table;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
@ -30,13 +32,13 @@ import java.sql.Timestamp;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
public class NodeDownload {
|
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 Table<NodeDownload> table = new Table<>(NodeDownload.class);
|
||||||
private static final Statement insert = table.insertFields("NodeId", "Link");
|
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})
|
@Field(keys = {Table.PRIMARY})
|
||||||
private final int nodeId;
|
private final int nodeId;
|
||||||
@ -45,25 +47,20 @@ public class NodeDownload {
|
|||||||
@Field(def = "CURRENT_TIMESTAMP")
|
@Field(def = "CURRENT_TIMESTAMP")
|
||||||
private final Timestamp timestamp;
|
private final Timestamp timestamp;
|
||||||
|
|
||||||
public static String getLink(SchematicNode schem){
|
public static NodeDownload addCode(SchematicNode node, String link) {
|
||||||
if(schem.isDir())
|
insert.update(node.getId(), link);
|
||||||
throw new SecurityException("Can not Download Directorys");
|
return get(node.getId());
|
||||||
MessageDigest digest;
|
|
||||||
try {
|
|
||||||
digest = MessageDigest.getInstance("SHA-1");
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new SecurityException(e);
|
|
||||||
}
|
|
||||||
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 String base16encode(byte[] byteArray) {
|
|
||||||
StringBuilder hexBuffer = new StringBuilder(byteArray.length * 2);
|
public static NodeDownload get(int nodeId) {
|
||||||
for (byte b : byteArray)
|
return getId.select(nodeId);
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -383,8 +383,8 @@ public class SchematicNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getRank() {
|
public int getRank() {
|
||||||
if(isDir())
|
if (isDir())
|
||||||
throw new SecurityException("Node is Directory");
|
return 0;
|
||||||
return nodeRank;
|
return nodeRank;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,8 +400,8 @@ public class SchematicNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SchematicType getSchemtype() {
|
public SchematicType getSchemtype() {
|
||||||
if(isDir())
|
if (isDir())
|
||||||
throw new SecurityException("Is Directory");
|
return null;
|
||||||
return nodeType;
|
return nodeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -443,8 +443,25 @@ public class SchematicNode {
|
|||||||
return SchemElo.getElo(this, season);
|
return SchemElo.getElo(this, season);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean accessibleByUser(int user) {
|
public boolean accessibleByUser(SteamwarUser user) {
|
||||||
return NodeMember.getNodeMember(nodeId, user) != null;
|
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() {
|
public Set<NodeMember> getMembers() {
|
||||||
@ -506,6 +523,19 @@ public class SchematicNode {
|
|||||||
return builder.toString();
|
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"));
|
private static final List<String> FORBIDDEN_NAMES = Collections.unmodifiableList(Arrays.asList("public"));
|
||||||
public static boolean invalidSchemName(String[] layers) {
|
public static boolean invalidSchemName(String[] layers) {
|
||||||
for (String layer : layers) {
|
for (String layer : layers) {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren