Commits vergleichen

..

Keine gemeinsamen Commits. "multitool/main" und "master" haben vollständig unterschiedliche Historien.

14 geänderte Dateien mit 188 neuen und 186 gelöschten Zeilen

4
build.gradle Normale Datei → Ausführbare Datei
Datei anzeigen

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

0
gradlew vendored Normale Datei → Ausführbare Datei
Datei anzeigen

Datei anzeigen

@ -21,13 +21,12 @@ 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 lombok.Setter;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.List;
@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> byId = table.select(Table.PRIMARY);
private static final SelectStatement<Event> allShort = new SelectStatement<>(table, "SELECT * FROM Event");
private static final Statement create = table.insertFields(true, "eventName", "deadline", "start", "end", "maximumTeamMembers", "publicSchemsOnly");
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 final SelectStatement<Event> byName = table.select("eventName");
private static final SelectStatement<Event> byComing = new SelectStatement<>(table, "SELECT * FROM Event WHERE Start > now()");
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){
return byId.select(eventID);
}
public static List<Event> getAllShort(){
return allShort.listSelect();
public static Event get(String eventName) {
return byName.select(eventName);
}
public static Event create(String eventName, Timestamp start, Timestamp end){
return get(create.insertGetKey(eventName, start, start, end, 5, false, false));
}
public static void delete(int eventID){
delete.update(eventID);
public static List<Event> getComing() {
return byComing.listSelect();
}
@Getter
@Field(keys = {Table.PRIMARY}, autoincrement = true)
private final int eventID;
@Setter
@Getter
@Field(keys = {"eventName"})
private String eventName;
@Setter
private final String eventName;
@Getter
@Field
private Timestamp deadline;
@Setter
private final Timestamp deadline;
@Getter
@Field
private Timestamp start;
@Setter
private final Timestamp start;
@Getter
@Field
private Timestamp end;
@Setter
private final Timestamp end;
@Getter
@Field
private int maximumTeamMembers;
@Setter
private final int maximumTeamMembers;
@Field(nullable = true)
private SchematicType schemType;
@Setter
private final SchematicType schemType;
@Field
private boolean publicSchemsOnly;
private final boolean publicSchemsOnly;
@Deprecated
@Field
private boolean spectateSystem;
private final boolean spectateSystem;
public boolean publicSchemsOnly() {
return publicSchemsOnly;
}
@Deprecated
public boolean spectateSystem(){
return spectateSystem;
}
@ -109,12 +102,8 @@ public class Event {
return schemType;
}
@Deprecated
public void setSpectateSystem(boolean spectateSystem) {
this.spectateSystem = spectateSystem;
}
public void update(){
update.update(eventName, deadline, start, end, schemType, maximumTeamMembers, publicSchemsOnly, eventID);
private boolean now() {
Instant now = Instant.now();
return now.isAfter(start.toInstant()) && now.isBefore(end.toInstant());
}
}

Datei anzeigen

@ -25,10 +25,6 @@ import de.steamwar.sql.internal.Statement;
import de.steamwar.sql.internal.Table;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import java.sql.Timestamp;
import java.util.List;
import java.sql.Timestamp;
import java.util.*;
@ -36,7 +32,7 @@ import java.util.*;
import static java.time.temporal.ChronoUnit.SECONDS;
@AllArgsConstructor
public class EventFight {
public class EventFight implements Comparable<EventFight> {
private static final Table<EventFight> table = new Table<>(EventFight.class);
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 setResult = table.update(Table.PRIMARY, "Ergebnis");
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<>();
@ -56,49 +48,47 @@ public class EventFight {
return byId.select(fightID);
}
public static EventFight create(int eventID, Timestamp startTime, String spielModus, String map, int teamBlue, int teamRed, Integer spectatePort) {
return EventFight.get(create.insertGetKey(eventID, startTime, spielModus, map, teamBlue, teamRed, spectatePort, 0));
public static void loadAllComingFights() {
fights.clear();
fights.addAll(allComing.listSelect());
}
public static List<EventFight> getFromEvent(int eventID) {
return byEvent.listSelect(eventID);
public static List<EventFight> getEvent(int eventID) {
return event.listSelect(eventID);
}
public static Queue<EventFight> getFights() {
return fights;
}
@Getter
@Field
private int eventID;
private final int eventID;
@Getter
@Field(keys = {Table.PRIMARY}, autoincrement = true)
private int fightID;
private final int fightID;
@Getter
@Setter
@Field
private Timestamp startTime;
@Getter
@Setter
@Field
private String spielModus;
private final String spielmodus;
@Getter
@Setter
@Field
private String map;
private final String map;
@Getter
@Setter
@Field
private int teamBlue;
private final int teamBlue;
@Getter
@Setter
@Field
private int teamRed;
private final int teamRed;
@Getter
@Setter
@Field
@Deprecated
private int kampfleiter;
private final int kampfleiter;
@Getter
@Setter
@Field(nullable = true)
private Integer spectatePort;
@Field
private final int spectatePort;
@Getter
@Field(def = "0")
private int ergebnis;
@ -126,15 +116,21 @@ public class EventFight {
}
@Override
public int hashCode() {
public int hashCode(){
return fightID;
}
public void update() {
update.update(startTime, spielModus, map, teamBlue, teamRed, spectatePort, fightID);
@Override
public boolean equals(Object o){
if(o == null)
return false;
if(!(o instanceof EventFight))
return false;
return fightID == ((EventFight) o).fightID;
}
public void delete() {
delete.update(fightID);
@Override
public int compareTo(EventFight o) {
return startTime.compareTo(o.startTime);
}
}

Datei anzeigen

@ -46,6 +46,7 @@ public class Fight {
fight.initPlayers(fightPlayers);
}
SteamwarUser.batchCache(fightPlayers.stream().map(FightPlayer::getUserID).collect(Collectors.toSet()));
return fights;
}

Datei anzeigen

@ -26,7 +26,6 @@ import lombok.Getter;
import java.util.List;
@AllArgsConstructor
@Getter
public class Mod {
static {
@ -35,34 +34,46 @@ public class Mod {
}
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);
private static final SelectStatement<Mod> all = new SelectStatement(table, "SELECT * FROM Mods");
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 Mod get(String name, Platform platform) {
return get.select(platform, name);
}
public static List<Mod> getAll() {
return all.listSelect();
public static Mod getOrCreate(String name, Platform platform) {
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() {
return allUnklassified.listSelect();
public static List<Mod> getAllModsFiltered(int page, int elementsPerPage, Mod.ModType filter) {
return Mod.getPageOfType.listSelect(filter, page * elementsPerPage, elementsPerPage);
}
public static Mod findFirstMod() {
return findFirst.select();
}
@Getter
@Field(keys = {Table.PRIMARY})
private final Platform platform;
@Getter
@Field(keys = {Table.PRIMARY})
private final String modName;
@Getter
@Field(def = "0")
private ModType modType;
public void setModType(ModType modType) {
public void setModType(Mod.ModType modType) {
set.update(modType, platform, modName);
this.modType = modType;
update.update(modType, platform, modName);
}
public enum Platform {

Datei anzeigen

@ -20,11 +20,9 @@
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;
@ -32,13 +30,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;
@ -47,20 +45,25 @@ public class NodeDownload {
@Field(def = "CURRENT_TIMESTAMP")
private final Timestamp timestamp;
public static NodeDownload addCode(SchematicNode node, String link) {
insert.update(node.getId(), link);
return get(node.getId());
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);
}
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 NodeDownload get(String link) {
return select.select(link);
}
public void delete() {
delete.update(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();
}
}

Datei anzeigen

@ -21,7 +21,6 @@ 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;
@ -33,16 +32,6 @@ public class Referee {
private static final Table<Referee> table = new Table<>(Referee.class);
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) {
return byEvent.listSelect(eventID).stream().map(referee -> referee.userID).collect(Collectors.toSet());

Datei anzeigen

@ -383,8 +383,8 @@ public class SchematicNode {
}
public int getRank() {
if (isDir())
return 0;
if(isDir())
throw new SecurityException("Node is Directory");
return nodeRank;
}
@ -400,8 +400,8 @@ public class SchematicNode {
}
public SchematicType getSchemtype() {
if (isDir())
return null;
if(isDir())
throw new SecurityException("Is Directory");
return nodeType;
}
@ -443,25 +443,8 @@ public class SchematicNode {
return SchemElo.getElo(this, season);
}
public boolean accessibleByUser(SteamwarUser user) {
if (user.getId() == nodeOwner) {
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 boolean accessibleByUser(int user) {
return NodeMember.getNodeMember(nodeId, user) != null;
}
public Set<NodeMember> getMembers() {
@ -523,19 +506,6 @@ 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) {

Datei anzeigen

@ -61,9 +61,8 @@ public class SteamwarUser {
private static final SelectStatement<SteamwarUser> byName = table.selectFields("UserName");
private static final SelectStatement<SteamwarUser> byDiscord = table.selectFields("DiscordId");
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 updatePassword = table.update(Table.PRIMARY, "Password");
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 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){
SteamwarUser user = usersByName.get(userName.toLowerCase());
if(user != null)
return user;
return byName.select(userName);
}
public static SteamwarUser get(UUID uuid){
SteamwarUser user = usersByUUID.get(uuid);
if(user != null)
return user;
return byUUID.select(uuid);
}
public static SteamwarUser get(int id) {
SteamwarUser user = usersById.get(id);
if(user != null)
return user;
return byID.select(id);
}
public static SteamwarUser get(Long discordId) {
if(usersByDiscord.containsKey(discordId))
return usersByDiscord.get(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) {
SteamwarUser user = get(uuid);
@ -112,14 +138,24 @@ public class SteamwarUser {
}
}
public static List<SteamwarUser> getUsersWithPerm(UserPerm perm) {
return getUsersWithPerm.listSelect(perm);
public static List<SteamwarUser> getServerTeam() {
return getServerTeam.listSelect();
}
public static List<SteamwarUser> getTeam(int 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
@Field(keys = {Table.PRIMARY}, autoincrement = true)
private final int id;
@ -158,6 +194,13 @@ public class SteamwarUser {
this.locale = locale;
this.manualLocale = manualLocale;
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() {
@ -248,8 +291,12 @@ public class SteamwarUser {
}
public void setDiscordId(Long discordId) {
usersByDiscord.remove(this.discordId);
this.discordId = discordId;
updateDiscord.update(discordId, id);
if (discordId != null) {
usersByDiscord.put(discordId, this);
}
}
public void setPassword(String password) {

Datei anzeigen

@ -75,15 +75,20 @@ public class Team {
}
public static Team get(int id) {
if(id == -1)
return new Team(-1, "?", "?", "8", "", 25565, false);
if(id == 0)
return new Team(0, "PUB", "Public", "8", "", 25565, false);
return byId.select(id);
return teamCache.computeIfAbsent(id, byId::select);
}
public static List<Team> getAll() {
return all.listSelect();
public static Team get(String name){
// 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(){

Datei anzeigen

@ -44,6 +44,7 @@ public class Tutorial {
public static List<Tutorial> getPage(int page, int elementsPerPage, boolean released) {
List<Tutorial> tutorials = by_popularity.listSelect(released, page * elementsPerPage, elementsPerPage);
SteamwarUser.batchCache(tutorials.stream().map(tutorial -> tutorial.creator).collect(Collectors.toSet()));
return tutorials;
}

Datei anzeigen

@ -19,7 +19,10 @@
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.Getter;
@ -55,9 +58,9 @@ public enum UserPerm {
p.put(PREFIX_YOUTUBER, new Prefix("§7", "YT"));
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_MODERATOR, new Prefix("§6", "Mod"));
p.put(PREFIX_BUILDER, new Prefix("§e", "Arch"));
p.put(PREFIX_DEVELOPER, new Prefix("§e", "Dev"));
p.put(PREFIX_ADMIN, new Prefix("§e", "Admin"));
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 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) {
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
@AllArgsConstructor
public static class Prefix {
private static int ordinalCounter = 0;
private final String colorCode;
private final String chatPrefix;
private final int ordinal = ordinalCounter++;
}
@AllArgsConstructor

Datei anzeigen

@ -47,7 +47,7 @@ public class Statement implements AutoCloseable {
private static final boolean PRODUCTION_DATABASE;
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();
if(MYSQL_MODE) {