Commits vergleichen

..

30 Commits

Autor SHA1 Nachricht Datum
e351352a29 Update CC
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2024-08-06 18:48:35 +02:00
076fa8ad78 Merge remote-tracking branch 'origin/master' into multitool/main
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
# Conflicts:
#	src/de/steamwar/sql/EventFight.java
#	src/de/steamwar/sql/Referee.java
2024-08-06 18:20:54 +02:00
ebbf314e6f Fix SteamWar user in Teamlist 2024-08-06 18:19:17 +02:00
d93b846c1f Add new Referee Stuff
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2024-03-15 22:38:53 +01:00
97e19990b5 Update CommonCore
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2024-03-14 22:26:54 +01:00
187c2ea292 Merge remote-tracking branch 'origin/master' into multitool/main
# Conflicts:
#	src/de/steamwar/sql/Event.java
#	src/de/steamwar/sql/EventFight.java
#	src/de/steamwar/sql/SteamwarUser.java
2024-03-14 22:20:56 +01:00
53d629970a Reorder Userperms
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2024-01-06 22:45:58 +01:00
a28c9b4e04 Merge branch 'multitool/public' into multitool/main
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2023-12-23 17:42:24 +01:00
69e2f9da6a Fix
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2023-12-23 17:42:16 +01:00
6aefb79e78 Add Login
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2023-12-23 17:04:10 +01:00
bf2af5b45b Merge branch 'passwords' into multitool/public
# Conflicts:
#	src/de/steamwar/sql/SteamwarUser.java
2023-12-17 17:23:30 +01:00
3dbbd70a80 Merge branch 'passwords' into multitool/public
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2023-12-17 16:39:08 +01:00
1755d5a99a Merge branch 'master' into multitool/public
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2023-12-11 18:37:17 +01:00
61985fb806 Updates
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2023-11-12 22:44:30 +01:00
fa04945595 Updates
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2023-11-03 20:30:29 +01:00
Chaoscaot
9b22e77f9b
Open to Public
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2023-09-06 23:07:32 +02:00
Chaoscaot
66fc131803
Update to UserPerms
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2023-08-30 00:56:27 +02:00
Chaoscaot
661b75db00
Merge branch 'master' into multitool/main
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2023-08-30 00:24:51 +02:00
Chaoscaot
c0bad2eb42
Merge remote-tracking branch 'origin/user-perm' into multitool/user-perm
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
# Conflicts:
#	src/de/steamwar/sql/SteamwarUser.java
2023-08-29 18:08:24 +02:00
Chaoscaot
e604991cfd
Merge branch 'master' into multitool
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2023-08-29 17:58:50 +02:00
Chaoscaot
02581ec36b Remove Punishments and Update
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2023-06-04 09:22:02 +02:00
Chaoscaot
3e064f7e4c Merge CommonCore Master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2023-04-10 12:58:17 +02:00
Chaoscaot
6c60cc3ce6 Merge branch 'master' into multitool
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
# Conflicts:
#	src/de/steamwar/sql/Event.java
#	src/de/steamwar/sql/EventFight.java
#	src/de/steamwar/sql/Mod.java
#	src/de/steamwar/sql/SteamwarUser.java
#	src/de/steamwar/sql/Team.java
2023-04-10 12:53:40 +02:00
Chaoscaot
4c136b45ca Update CommonCore 2023-01-15 16:50:19 +01:00
Chaoscaot
e9d7e9738c Merge remote-tracking branch 'origin/master' into multitool 2023-01-15 16:46:44 +01:00
Chaoscaot
975ebf4f33 Add Mod Routes
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2023-01-14 11:59:49 +01:00
Chaoscaot
4b5ea06616 Add return of ? team
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2022-12-30 19:08:20 +01:00
Chaoscaot
c98687a9d5 Some uncommited Stuff
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2022-12-30 18:37:18 +01:00
Chaoscaot
fdcd81d21e Add Fight Delete
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2022-12-24 14:38:17 +01:00
Chaoscaot
eef38de3c0 Changes for MultiTool
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2022-12-23 23:19:28 +01:00
14 geänderte Dateien mit 186 neuen und 188 gelöschten Zeilen

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

@ -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 {

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -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);
} }
} }

Datei anzeigen

@ -21,6 +21,7 @@ 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;
@ -32,6 +33,16 @@ 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());

Datei anzeigen

@ -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 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() {
@ -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) {

Datei anzeigen

@ -61,8 +61,9 @@ 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> getServerTeam = new SelectStatement<>(table, "SELECT * FROM UserData WHERE UserGroup != 'Member' AND UserGroup != 'YouTuber'"); 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> 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");
@ -73,53 +74,26 @@ 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);
@ -138,24 +112,14 @@ public class SteamwarUser {
} }
} }
public static List<SteamwarUser> getServerTeam() { public static List<SteamwarUser> getUsersWithPerm(UserPerm perm) {
return getServerTeam.listSelect(); return getUsersWithPerm.listSelect(perm);
} }
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;
@ -194,13 +158,6 @@ 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() {
@ -291,12 +248,8 @@ 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) {

Datei anzeigen

@ -75,20 +75,15 @@ public class Team {
} }
public static Team get(int id) { public static Team get(int id) {
return teamCache.computeIfAbsent(id, byId::select); 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);
} }
public static Team get(String name){ public static List<Team> getAll() {
// No cache lookup due to low frequency use return all.listSelect();
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(){

Datei anzeigen

@ -44,7 +44,6 @@ 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;
} }

Datei anzeigen

@ -19,10 +19,7 @@
package de.steamwar.sql; package de.steamwar.sql;
import de.steamwar.sql.internal.Field; import de.steamwar.sql.internal.*;
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;
@ -58,9 +55,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);
@ -68,16 +65,29 @@ 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

Datei anzeigen

@ -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.properties"); File file = new File(System.getProperty("user.home"), "mysql.api.properties");
MYSQL_MODE = file.exists(); MYSQL_MODE = file.exists();
if(MYSQL_MODE) { if(MYSQL_MODE) {