Commits vergleichen
Keine gemeinsamen Commits. "multitool/main" und "master" haben vollständig unterschiedliche Historien.
multitool/
...
master
4
build.gradle
Normale Datei → Ausführbare Datei
4
build.gradle
Normale Datei → Ausführbare Datei
@ -44,8 +44,8 @@ ext {
|
|||||||
|
|
||||||
compileJava.options.encoding = 'UTF-8'
|
compileJava.options.encoding = 'UTF-8'
|
||||||
|
|
||||||
sourceCompatibility = 17
|
sourceCompatibility = 1.8
|
||||||
targetCompatibility = 17
|
targetCompatibility = 1.8
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
|
0
gradlew
vendored
Normale Datei → Ausführbare Datei
0
gradlew
vendored
Normale Datei → Ausführbare Datei
@ -21,13 +21,12 @@ 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.SelectStatement;
|
||||||
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 lombok.Getter;
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@ -41,66 +40,60 @@ public class Event {
|
|||||||
|
|
||||||
private static final SelectStatement<Event> byCurrent = new SelectStatement<>(table, "SELECT * FROM Event WHERE Start < now() AND End > now()");
|
private static final SelectStatement<Event> byCurrent = new SelectStatement<>(table, "SELECT * FROM Event WHERE Start < now() AND End > now()");
|
||||||
private static final SelectStatement<Event> byId = table.select(Table.PRIMARY);
|
private static final SelectStatement<Event> byId = table.select(Table.PRIMARY);
|
||||||
private static final SelectStatement<Event> allShort = new SelectStatement<>(table, "SELECT * FROM Event");
|
private static final SelectStatement<Event> byName = table.select("eventName");
|
||||||
private static final Statement create = table.insertFields(true, "eventName", "deadline", "start", "end", "maximumTeamMembers", "publicSchemsOnly");
|
private static final SelectStatement<Event> byComing = new SelectStatement<>(table, "SELECT * FROM Event WHERE Start > now()");
|
||||||
private static final Statement update = table.update(Table.PRIMARY, "eventName", "deadline", "start", "end", "schemType", "maximumTeamMembers", "publicSchemsOnly");
|
|
||||||
private static final Statement delete = table.delete(Table.PRIMARY);
|
|
||||||
|
|
||||||
|
private static Event current = null;
|
||||||
|
|
||||||
|
public static Event get(){
|
||||||
|
if(current != null && current.now())
|
||||||
|
return current;
|
||||||
|
|
||||||
|
current = byCurrent.select();
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
public static Event get(int eventID){
|
public static Event get(int eventID){
|
||||||
return byId.select(eventID);
|
return byId.select(eventID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Event> getAllShort(){
|
public static Event get(String eventName) {
|
||||||
return allShort.listSelect();
|
return byName.select(eventName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Event create(String eventName, Timestamp start, Timestamp end){
|
public static List<Event> getComing() {
|
||||||
return get(create.insertGetKey(eventName, start, start, end, 5, false, false));
|
return byComing.listSelect();
|
||||||
}
|
|
||||||
|
|
||||||
public static void delete(int eventID){
|
|
||||||
delete.update(eventID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Field(keys = {Table.PRIMARY}, autoincrement = true)
|
@Field(keys = {Table.PRIMARY}, autoincrement = true)
|
||||||
private final int eventID;
|
private final int eventID;
|
||||||
@Setter
|
|
||||||
@Getter
|
@Getter
|
||||||
@Field(keys = {"eventName"})
|
@Field(keys = {"eventName"})
|
||||||
private String eventName;
|
private final String eventName;
|
||||||
@Setter
|
|
||||||
@Getter
|
@Getter
|
||||||
@Field
|
@Field
|
||||||
private Timestamp deadline;
|
private final Timestamp deadline;
|
||||||
@Setter
|
|
||||||
@Getter
|
@Getter
|
||||||
@Field
|
@Field
|
||||||
private Timestamp start;
|
private final Timestamp start;
|
||||||
@Setter
|
|
||||||
@Getter
|
@Getter
|
||||||
@Field
|
@Field
|
||||||
private Timestamp end;
|
private final Timestamp end;
|
||||||
@Setter
|
|
||||||
@Getter
|
@Getter
|
||||||
@Field
|
@Field
|
||||||
private int maximumTeamMembers;
|
private final int maximumTeamMembers;
|
||||||
@Setter
|
|
||||||
@Field(nullable = true)
|
@Field(nullable = true)
|
||||||
private SchematicType schemType;
|
private final SchematicType schemType;
|
||||||
@Setter
|
|
||||||
@Field
|
@Field
|
||||||
private boolean publicSchemsOnly;
|
private final boolean publicSchemsOnly;
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@Field
|
@Field
|
||||||
private boolean spectateSystem;
|
private final boolean spectateSystem;
|
||||||
|
|
||||||
public boolean publicSchemsOnly() {
|
public boolean publicSchemsOnly() {
|
||||||
return publicSchemsOnly;
|
return publicSchemsOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public boolean spectateSystem(){
|
public boolean spectateSystem(){
|
||||||
return spectateSystem;
|
return spectateSystem;
|
||||||
}
|
}
|
||||||
@ -109,12 +102,8 @@ public class Event {
|
|||||||
return schemType;
|
return schemType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
private boolean now() {
|
||||||
public void setSpectateSystem(boolean spectateSystem) {
|
Instant now = Instant.now();
|
||||||
this.spectateSystem = spectateSystem;
|
return now.isAfter(start.toInstant()) && now.isBefore(end.toInstant());
|
||||||
}
|
|
||||||
|
|
||||||
public void update(){
|
|
||||||
update.update(eventName, deadline, start, end, schemType, maximumTeamMembers, publicSchemsOnly, eventID);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,6 @@ 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 lombok.Getter;
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -36,7 +32,7 @@ import java.util.*;
|
|||||||
import static java.time.temporal.ChronoUnit.SECONDS;
|
import static java.time.temporal.ChronoUnit.SECONDS;
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class EventFight {
|
public class EventFight implements Comparable<EventFight> {
|
||||||
|
|
||||||
private static final Table<EventFight> table = new Table<>(EventFight.class);
|
private static final Table<EventFight> table = new Table<>(EventFight.class);
|
||||||
private static final SelectStatement<EventFight> byId = table.select(Table.PRIMARY);
|
private static final SelectStatement<EventFight> byId = table.select(Table.PRIMARY);
|
||||||
@ -45,10 +41,6 @@ public class EventFight {
|
|||||||
private static final Statement reschedule = table.update(Table.PRIMARY, "StartTime");
|
private static final Statement reschedule = table.update(Table.PRIMARY, "StartTime");
|
||||||
private static final Statement setResult = table.update(Table.PRIMARY, "Ergebnis");
|
private static final Statement setResult = table.update(Table.PRIMARY, "Ergebnis");
|
||||||
private static final Statement setFight = table.update(Table.PRIMARY, "Fight");
|
private static final Statement setFight = table.update(Table.PRIMARY, "Fight");
|
||||||
private static final SelectStatement<EventFight> byEvent = table.selectFields("eventID");
|
|
||||||
private static final Statement update = table.update(Table.PRIMARY, "startTime", "spielModus", "map", "teamBlue", "teamRed", "spectatePort");
|
|
||||||
private static final Statement create = table.insertFields(true, "eventID", "startTime", "spielModus", "map", "teamBlue", "teamRed", "spectatePort", "kampfleiter");
|
|
||||||
private static final Statement delete = table.delete(Table.PRIMARY);
|
|
||||||
|
|
||||||
private static final Queue<EventFight> fights = new PriorityQueue<>();
|
private static final Queue<EventFight> fights = new PriorityQueue<>();
|
||||||
|
|
||||||
@ -56,49 +48,47 @@ public class EventFight {
|
|||||||
return byId.select(fightID);
|
return byId.select(fightID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EventFight create(int eventID, Timestamp startTime, String spielModus, String map, int teamBlue, int teamRed, Integer spectatePort) {
|
public static void loadAllComingFights() {
|
||||||
return EventFight.get(create.insertGetKey(eventID, startTime, spielModus, map, teamBlue, teamRed, spectatePort, 0));
|
fights.clear();
|
||||||
|
fights.addAll(allComing.listSelect());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<EventFight> getFromEvent(int eventID) {
|
public static List<EventFight> getEvent(int eventID) {
|
||||||
return byEvent.listSelect(eventID);
|
return event.listSelect(eventID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Queue<EventFight> getFights() {
|
||||||
|
return fights;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Field
|
@Field
|
||||||
private int eventID;
|
private final int eventID;
|
||||||
@Getter
|
@Getter
|
||||||
@Field(keys = {Table.PRIMARY}, autoincrement = true)
|
@Field(keys = {Table.PRIMARY}, autoincrement = true)
|
||||||
private int fightID;
|
private final int fightID;
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
|
||||||
@Field
|
@Field
|
||||||
private Timestamp startTime;
|
private Timestamp startTime;
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
|
||||||
@Field
|
@Field
|
||||||
private String spielModus;
|
private final String spielmodus;
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
|
||||||
@Field
|
@Field
|
||||||
private String map;
|
private final String map;
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
|
||||||
@Field
|
@Field
|
||||||
private int teamBlue;
|
private final int teamBlue;
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
|
||||||
@Field
|
@Field
|
||||||
private int teamRed;
|
private final int teamRed;
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
|
||||||
@Field
|
@Field
|
||||||
@Deprecated
|
@Deprecated
|
||||||
private int kampfleiter;
|
private final int kampfleiter;
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Field
|
||||||
@Field(nullable = true)
|
private final int spectatePort;
|
||||||
private Integer spectatePort;
|
|
||||||
@Getter
|
@Getter
|
||||||
@Field(def = "0")
|
@Field(def = "0")
|
||||||
private int ergebnis;
|
private int ergebnis;
|
||||||
@ -126,15 +116,21 @@ public class EventFight {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode(){
|
||||||
return fightID;
|
return fightID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
@Override
|
||||||
update.update(startTime, spielModus, map, teamBlue, teamRed, spectatePort, fightID);
|
public boolean equals(Object o){
|
||||||
|
if(o == null)
|
||||||
|
return false;
|
||||||
|
if(!(o instanceof EventFight))
|
||||||
|
return false;
|
||||||
|
return fightID == ((EventFight) o).fightID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() {
|
@Override
|
||||||
delete.update(fightID);
|
public int compareTo(EventFight o) {
|
||||||
|
return startTime.compareTo(o.startTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@ public class Fight {
|
|||||||
fight.initPlayers(fightPlayers);
|
fight.initPlayers(fightPlayers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SteamwarUser.batchCache(fightPlayers.stream().map(FightPlayer::getUserID).collect(Collectors.toSet()));
|
||||||
return fights;
|
return fights;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ import lombok.Getter;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Getter
|
|
||||||
public class Mod {
|
public class Mod {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@ -35,34 +34,46 @@ public class Mod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final Table<Mod> table = new Table<>(Mod.class, "Mods");
|
private static final Table<Mod> table = new Table<>(Mod.class, "Mods");
|
||||||
|
private static final SelectStatement<Mod> get = table.select(Table.PRIMARY);
|
||||||
|
private static final SelectStatement<Mod> findFirst = new SelectStatement<>(table, "SELECT * FROM Mods WHERE ModType = 0 LIMIT 1");
|
||||||
|
private static final SelectStatement<Mod> getPageOfType = new SelectStatement<>(table, "SELECT * FROM Mods WHERE ModType = ? ORDER BY ModName DESC LIMIT ?, ?");
|
||||||
|
private static final Statement insert = table.insert(Table.PRIMARY);
|
||||||
|
private static final Statement set = table.update(Table.PRIMARY, "ModType");
|
||||||
|
|
||||||
private static final SelectStatement<Mod> select = table.select(Table.PRIMARY);
|
public static Mod get(String name, Platform platform) {
|
||||||
private static final SelectStatement<Mod> all = new SelectStatement(table, "SELECT * FROM Mods");
|
return get.select(platform, name);
|
||||||
private static final SelectStatement<Mod> allUnklassified = new SelectStatement(table, "SELECT * FROM Mods WHERE modType = 0");
|
|
||||||
private static final Statement update = table.update(Table.PRIMARY, "modType");
|
|
||||||
|
|
||||||
public static Mod get(Platform platform, String name) {
|
|
||||||
return select.select(platform, name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Mod> getAll() {
|
public static Mod getOrCreate(String name, Platform platform) {
|
||||||
return all.listSelect();
|
Mod mod = get(name, platform);
|
||||||
|
if(mod != null)
|
||||||
|
return mod;
|
||||||
|
|
||||||
|
insert.update(platform, name);
|
||||||
|
return new Mod(platform, name, ModType.UNKLASSIFIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Mod> getAllUnklassified() {
|
public static List<Mod> getAllModsFiltered(int page, int elementsPerPage, Mod.ModType filter) {
|
||||||
return allUnklassified.listSelect();
|
return Mod.getPageOfType.listSelect(filter, page * elementsPerPage, elementsPerPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Mod findFirstMod() {
|
||||||
|
return findFirst.select();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
@Field(keys = {Table.PRIMARY})
|
@Field(keys = {Table.PRIMARY})
|
||||||
private final Platform platform;
|
private final Platform platform;
|
||||||
|
@Getter
|
||||||
@Field(keys = {Table.PRIMARY})
|
@Field(keys = {Table.PRIMARY})
|
||||||
private final String modName;
|
private final String modName;
|
||||||
|
@Getter
|
||||||
@Field(def = "0")
|
@Field(def = "0")
|
||||||
private ModType modType;
|
private ModType modType;
|
||||||
|
|
||||||
public void setModType(ModType modType) {
|
public void setModType(Mod.ModType modType) {
|
||||||
|
set.update(modType, platform, modName);
|
||||||
this.modType = modType;
|
this.modType = modType;
|
||||||
update.update(modType, platform, modName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Platform {
|
public enum Platform {
|
||||||
|
@ -20,11 +20,9 @@
|
|||||||
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;
|
||||||
@ -32,13 +30,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;
|
||||||
@ -47,20 +45,25 @@ public class NodeDownload {
|
|||||||
@Field(def = "CURRENT_TIMESTAMP")
|
@Field(def = "CURRENT_TIMESTAMP")
|
||||||
private final Timestamp timestamp;
|
private final Timestamp timestamp;
|
||||||
|
|
||||||
public static NodeDownload addCode(SchematicNode node, String link) {
|
public static String getLink(SchematicNode schem){
|
||||||
insert.update(node.getId(), link);
|
if(schem.isDir())
|
||||||
return get(node.getId());
|
throw new SecurityException("Can not Download Directorys");
|
||||||
|
MessageDigest digest;
|
||||||
|
try {
|
||||||
|
digest = MessageDigest.getInstance("SHA-1");
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new SecurityException(e);
|
||||||
}
|
}
|
||||||
|
digest.reset();
|
||||||
public static NodeDownload get(int nodeId) {
|
digest.update((Instant.now().toString() + schem.getOwner() + schem.getId()).getBytes());
|
||||||
return getId.select(nodeId);
|
String hash = base16encode(digest.digest());
|
||||||
|
insert.update(schem.getId(), hash);
|
||||||
|
return LINK_BASE + hash;
|
||||||
}
|
}
|
||||||
|
public static String base16encode(byte[] byteArray) {
|
||||||
public static NodeDownload get(String link) {
|
StringBuilder hexBuffer = new StringBuilder(byteArray.length * 2);
|
||||||
return select.select(link);
|
for (byte b : byteArray)
|
||||||
}
|
hexBuffer.append(HEX[(b >>> 4) & 0xF]).append(HEX[b & 0xF]);
|
||||||
|
return hexBuffer.toString();
|
||||||
public void delete() {
|
|
||||||
delete.update(nodeId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ 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.SelectStatement;
|
||||||
import de.steamwar.sql.internal.Statement;
|
|
||||||
import de.steamwar.sql.internal.Table;
|
import de.steamwar.sql.internal.Table;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
|
||||||
@ -33,16 +32,6 @@ public class Referee {
|
|||||||
|
|
||||||
private static final Table<Referee> table = new Table<>(Referee.class);
|
private static final Table<Referee> table = new Table<>(Referee.class);
|
||||||
private static final SelectStatement<Referee> byEvent = table.selectFields("eventID");
|
private static final SelectStatement<Referee> byEvent = table.selectFields("eventID");
|
||||||
private static final Statement insert = table.insertAll();
|
|
||||||
private static final Statement delete = table.delete("eventReferee");
|
|
||||||
|
|
||||||
public static void add(int eventID, int userID) {
|
|
||||||
insert.update(eventID, userID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void remove(int eventID, int userID) {
|
|
||||||
delete.update(eventID, userID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<Integer> get(int eventID) {
|
public static Set<Integer> get(int eventID) {
|
||||||
return byEvent.listSelect(eventID).stream().map(referee -> referee.userID).collect(Collectors.toSet());
|
return byEvent.listSelect(eventID).stream().map(referee -> referee.userID).collect(Collectors.toSet());
|
||||||
|
@ -383,8 +383,8 @@ public class SchematicNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getRank() {
|
public int getRank() {
|
||||||
if (isDir())
|
if(isDir())
|
||||||
return 0;
|
throw new SecurityException("Node is Directory");
|
||||||
return nodeRank;
|
return nodeRank;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,8 +400,8 @@ public class SchematicNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SchematicType getSchemtype() {
|
public SchematicType getSchemtype() {
|
||||||
if (isDir())
|
if(isDir())
|
||||||
return null;
|
throw new SecurityException("Is Directory");
|
||||||
return nodeType;
|
return nodeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -443,25 +443,8 @@ public class SchematicNode {
|
|||||||
return SchemElo.getElo(this, season);
|
return SchemElo.getElo(this, season);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean accessibleByUser(SteamwarUser user) {
|
public boolean accessibleByUser(int user) {
|
||||||
if (user.getId() == nodeOwner) {
|
return NodeMember.getNodeMember(nodeId, user) != null;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parentNode == null) {
|
|
||||||
return NodeMember.getNodeMember(nodeId, user.getId()) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
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() {
|
||||||
@ -523,19 +506,6 @@ 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) {
|
||||||
|
@ -61,9 +61,8 @@ public class SteamwarUser {
|
|||||||
private static final SelectStatement<SteamwarUser> byName = table.selectFields("UserName");
|
private static final SelectStatement<SteamwarUser> byName = table.selectFields("UserName");
|
||||||
private static final SelectStatement<SteamwarUser> byDiscord = table.selectFields("DiscordId");
|
private static final SelectStatement<SteamwarUser> byDiscord = table.selectFields("DiscordId");
|
||||||
private static final SelectStatement<SteamwarUser> byTeam = table.selectFields("Team");
|
private static final SelectStatement<SteamwarUser> byTeam = table.selectFields("Team");
|
||||||
private static final SelectStatement<SteamwarUser> getUsersWithPerm = new SelectStatement<>(table, "SELECT S.* FROM UserData S JOIN UserPerm P ON S.id = P.User WHERE P.Perm = ?");
|
private static final SelectStatement<SteamwarUser> getServerTeam = new SelectStatement<>(table, "SELECT * FROM UserData WHERE UserGroup != 'Member' AND UserGroup != 'YouTuber'");
|
||||||
|
|
||||||
private static final SelectStatement<SteamwarUser> getAll = new SelectStatement<>(table, "SELECT * FROM UserData");
|
|
||||||
private static final Statement updateName = table.update(Table.PRIMARY, "UserName");
|
private static final Statement updateName = table.update(Table.PRIMARY, "UserName");
|
||||||
private static final Statement updatePassword = table.update(Table.PRIMARY, "Password");
|
private static final Statement updatePassword = table.update(Table.PRIMARY, "Password");
|
||||||
private static final Statement updateLocale = table.update(Table.PRIMARY, "Locale", "ManualLocale");
|
private static final Statement updateLocale = table.update(Table.PRIMARY, "Locale", "ManualLocale");
|
||||||
@ -74,26 +73,53 @@ public class SteamwarUser {
|
|||||||
private static final Statement getPlaytime = new Statement("SELECT SUM(UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime)) as Playtime FROM Session WHERE UserID = ?");
|
private static final Statement getPlaytime = new Statement("SELECT SUM(UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime)) as Playtime FROM Session WHERE UserID = ?");
|
||||||
private static final Statement getFirstjoin = new Statement("SELECT MIN(StartTime) AS FirstJoin FROM Session WHERE UserID = ?");
|
private static final Statement getFirstjoin = new Statement("SELECT MIN(StartTime) AS FirstJoin FROM Session WHERE UserID = ?");
|
||||||
|
|
||||||
|
private static final Map<Integer, SteamwarUser> usersById = new HashMap<>();
|
||||||
|
private static final Map<UUID, SteamwarUser> usersByUUID = new HashMap<>();
|
||||||
|
private static final Map<String, SteamwarUser> usersByName = new HashMap<>();
|
||||||
|
private static final Map<Long, SteamwarUser> usersByDiscord = new HashMap<>();
|
||||||
|
public static void clear() {
|
||||||
|
usersById.clear();
|
||||||
|
usersByName.clear();
|
||||||
|
usersByUUID.clear();
|
||||||
|
usersByDiscord.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void invalidate(int userId) {
|
||||||
|
SteamwarUser user = usersById.remove(userId);
|
||||||
|
if (user == null)
|
||||||
|
return;
|
||||||
|
usersByName.remove(user.getUserName());
|
||||||
|
usersByUUID.remove(user.getUUID());
|
||||||
|
usersByDiscord.remove(user.getDiscordId());
|
||||||
|
}
|
||||||
|
|
||||||
public static SteamwarUser get(String userName){
|
public static SteamwarUser get(String userName){
|
||||||
|
SteamwarUser user = usersByName.get(userName.toLowerCase());
|
||||||
|
if(user != null)
|
||||||
|
return user;
|
||||||
return byName.select(userName);
|
return byName.select(userName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SteamwarUser get(UUID uuid){
|
public static SteamwarUser get(UUID uuid){
|
||||||
|
SteamwarUser user = usersByUUID.get(uuid);
|
||||||
|
if(user != null)
|
||||||
|
return user;
|
||||||
return byUUID.select(uuid);
|
return byUUID.select(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SteamwarUser get(int id) {
|
public static SteamwarUser get(int id) {
|
||||||
|
SteamwarUser user = usersById.get(id);
|
||||||
|
if(user != null)
|
||||||
|
return user;
|
||||||
return byID.select(id);
|
return byID.select(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SteamwarUser get(Long discordId) {
|
public static SteamwarUser get(Long discordId) {
|
||||||
|
if(usersByDiscord.containsKey(discordId))
|
||||||
|
return usersByDiscord.get(discordId);
|
||||||
return byDiscord.select(discordId);
|
return byDiscord.select(discordId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SteamwarUser> getAll() {
|
|
||||||
return getAll.listSelect();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SteamwarUser getOrCreate(UUID uuid, String name, Consumer<UUID> newPlayer, BiConsumer<String, String> nameUpdate) {
|
public static SteamwarUser getOrCreate(UUID uuid, String name, Consumer<UUID> newPlayer, BiConsumer<String, String> nameUpdate) {
|
||||||
SteamwarUser user = get(uuid);
|
SteamwarUser user = get(uuid);
|
||||||
|
|
||||||
@ -112,14 +138,24 @@ public class SteamwarUser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SteamwarUser> getUsersWithPerm(UserPerm perm) {
|
public static List<SteamwarUser> getServerTeam() {
|
||||||
return getUsersWithPerm.listSelect(perm);
|
return getServerTeam.listSelect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SteamwarUser> getTeam(int teamId) {
|
public static List<SteamwarUser> getTeam(int teamId) {
|
||||||
return byTeam.listSelect(teamId);
|
return byTeam.listSelect(teamId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void batchCache(Set<Integer> ids) {
|
||||||
|
ids.removeIf(usersById::containsKey);
|
||||||
|
if(ids.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
try (SelectStatement<SteamwarUser> batch = new SelectStatement<>(table, "SELECT * FROM UserData WHERE id IN (" + ids.stream().map(Object::toString).collect(Collectors.joining(", ")) + ")")) {
|
||||||
|
batch.listSelect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Field(keys = {Table.PRIMARY}, autoincrement = true)
|
@Field(keys = {Table.PRIMARY}, autoincrement = true)
|
||||||
private final int id;
|
private final int id;
|
||||||
@ -158,6 +194,13 @@ public class SteamwarUser {
|
|||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
this.manualLocale = manualLocale;
|
this.manualLocale = manualLocale;
|
||||||
this.discordId = discordId != null && discordId != 0 ? discordId : null;
|
this.discordId = discordId != null && discordId != 0 ? discordId : null;
|
||||||
|
|
||||||
|
usersById.put(id, this);
|
||||||
|
usersByName.put(userName.toLowerCase(), this);
|
||||||
|
usersByUUID.put(uuid, this);
|
||||||
|
if (this.discordId != null) {
|
||||||
|
usersByDiscord.put(discordId, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getUUID() {
|
public UUID getUUID() {
|
||||||
@ -248,8 +291,12 @@ public class SteamwarUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setDiscordId(Long discordId) {
|
public void setDiscordId(Long discordId) {
|
||||||
|
usersByDiscord.remove(this.discordId);
|
||||||
this.discordId = discordId;
|
this.discordId = discordId;
|
||||||
updateDiscord.update(discordId, id);
|
updateDiscord.update(discordId, id);
|
||||||
|
if (discordId != null) {
|
||||||
|
usersByDiscord.put(discordId, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPassword(String password) {
|
public void setPassword(String password) {
|
||||||
|
@ -75,15 +75,20 @@ public class Team {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Team get(int id) {
|
public static Team get(int id) {
|
||||||
if(id == -1)
|
return teamCache.computeIfAbsent(id, byId::select);
|
||||||
return new Team(-1, "?", "?", "8", "", 25565, false);
|
|
||||||
if(id == 0)
|
|
||||||
return new Team(0, "PUB", "Public", "8", "", 25565, false);
|
|
||||||
return byId.select(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Team> getAll() {
|
public static Team get(String name){
|
||||||
return all.listSelect();
|
// No cache lookup due to low frequency use
|
||||||
|
name = name.toLowerCase();
|
||||||
|
return byName.select(name, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Team> getAll(){
|
||||||
|
clear();
|
||||||
|
List<Team> teams = all.listSelect(false);
|
||||||
|
teams.forEach(team -> teamCache.put(team.getTeamId(), team));
|
||||||
|
return teams;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> getMembers(){
|
public List<Integer> getMembers(){
|
||||||
|
@ -44,6 +44,7 @@ public class Tutorial {
|
|||||||
|
|
||||||
public static List<Tutorial> getPage(int page, int elementsPerPage, boolean released) {
|
public static List<Tutorial> getPage(int page, int elementsPerPage, boolean released) {
|
||||||
List<Tutorial> tutorials = by_popularity.listSelect(released, page * elementsPerPage, elementsPerPage);
|
List<Tutorial> tutorials = by_popularity.listSelect(released, page * elementsPerPage, elementsPerPage);
|
||||||
|
SteamwarUser.batchCache(tutorials.stream().map(tutorial -> tutorial.creator).collect(Collectors.toSet()));
|
||||||
return tutorials;
|
return tutorials;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,10 @@
|
|||||||
|
|
||||||
package de.steamwar.sql;
|
package de.steamwar.sql;
|
||||||
|
|
||||||
import de.steamwar.sql.internal.*;
|
import de.steamwar.sql.internal.Field;
|
||||||
|
import de.steamwar.sql.internal.SelectStatement;
|
||||||
|
import de.steamwar.sql.internal.SqlTypeMapper;
|
||||||
|
import de.steamwar.sql.internal.Table;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@ -55,9 +58,9 @@ public enum UserPerm {
|
|||||||
p.put(PREFIX_YOUTUBER, new Prefix("§7", "YT"));
|
p.put(PREFIX_YOUTUBER, new Prefix("§7", "YT"));
|
||||||
p.put(PREFIX_GUIDE, new Prefix("§a", "Guide"));
|
p.put(PREFIX_GUIDE, new Prefix("§a", "Guide"));
|
||||||
|
|
||||||
p.put(PREFIX_BUILDER, new Prefix("§e", "Arch"));
|
|
||||||
p.put(PREFIX_SUPPORTER, new Prefix("§6", "Sup"));
|
p.put(PREFIX_SUPPORTER, new Prefix("§6", "Sup"));
|
||||||
p.put(PREFIX_MODERATOR, new Prefix("§6", "Mod"));
|
p.put(PREFIX_MODERATOR, new Prefix("§6", "Mod"));
|
||||||
|
p.put(PREFIX_BUILDER, new Prefix("§e", "Arch"));
|
||||||
p.put(PREFIX_DEVELOPER, new Prefix("§e", "Dev"));
|
p.put(PREFIX_DEVELOPER, new Prefix("§e", "Dev"));
|
||||||
p.put(PREFIX_ADMIN, new Prefix("§e", "Admin"));
|
p.put(PREFIX_ADMIN, new Prefix("§e", "Admin"));
|
||||||
prefixes = Collections.unmodifiableMap(p);
|
prefixes = Collections.unmodifiableMap(p);
|
||||||
@ -65,29 +68,16 @@ public enum UserPerm {
|
|||||||
|
|
||||||
private static final Table<UserPermTable> table = new Table<>(UserPermTable.class, "UserPerm");
|
private static final Table<UserPermTable> table = new Table<>(UserPermTable.class, "UserPerm");
|
||||||
private static final SelectStatement<UserPermTable> getPerms = table.selectFields("user");
|
private static final SelectStatement<UserPermTable> getPerms = table.selectFields("user");
|
||||||
private static final Statement addPerm = table.insertFields("user", "perm");
|
|
||||||
private static final Statement removePerm = table.delete(Table.PRIMARY);
|
|
||||||
|
|
||||||
public static Set<UserPerm> getPerms(int user) {
|
public static Set<UserPerm> getPerms(int user) {
|
||||||
return getPerms.listSelect(user).stream().map(up -> up.perm).collect(Collectors.toSet());
|
return getPerms.listSelect(user).stream().map(up -> up.perm).collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addPerm(SteamwarUser user, UserPerm perm) {
|
|
||||||
addPerm.update(user, perm);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void removePerm(SteamwarUser user, UserPerm perm) {
|
|
||||||
removePerm.update(user, perm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static class Prefix {
|
public static class Prefix {
|
||||||
private static int ordinalCounter = 0;
|
|
||||||
|
|
||||||
private final String colorCode;
|
private final String colorCode;
|
||||||
private final String chatPrefix;
|
private final String chatPrefix;
|
||||||
private final int ordinal = ordinalCounter++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@ -47,7 +47,7 @@ public class Statement implements AutoCloseable {
|
|||||||
private static final boolean PRODUCTION_DATABASE;
|
private static final boolean PRODUCTION_DATABASE;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
File file = new File(System.getProperty("user.home"), "mysql.api.properties");
|
File file = new File(System.getProperty("user.home"), "mysql.properties");
|
||||||
MYSQL_MODE = file.exists();
|
MYSQL_MODE = file.exists();
|
||||||
|
|
||||||
if(MYSQL_MODE) {
|
if(MYSQL_MODE) {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren