geforkt von SteamWar/BungeeCore
Commits vergleichen
4 Commits
Autor | SHA1 | Datum | |
---|---|---|---|
|
00da5f673d | ||
|
e4551e9521 | ||
|
14052c5d01 | ||
|
1a54476cbe |
@ -99,6 +99,8 @@ dependencies {
|
|||||||
exclude module: 'opus-java'
|
exclude module: 'opus-java'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
implementation "com.sparkjava:spark-core:2.9.3"
|
||||||
|
|
||||||
implementation project(":CommonCore")
|
implementation project(":CommonCore")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
45
src/de/steamwar/bungeecore/api/AuthUtils.java
Normale Datei
45
src/de/steamwar/bungeecore/api/AuthUtils.java
Normale Datei
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bungeecore.api;
|
||||||
|
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
import spark.Request;
|
||||||
|
import spark.Response;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class AuthUtils {
|
||||||
|
|
||||||
|
public static Optional<Token> isAuthorized(Request request, Response response) {
|
||||||
|
String authorization = request.headers("Authorization");
|
||||||
|
if (authorization == null) {
|
||||||
|
response.status(401);
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return Optional.of(Token.decrypt(authorization));
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
response.status(401);
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
32
src/de/steamwar/bungeecore/api/EndPoint.java
Normale Datei
32
src/de/steamwar/bungeecore/api/EndPoint.java
Normale Datei
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bungeecore.api;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import spark.Request;
|
||||||
|
import spark.Response;
|
||||||
|
|
||||||
|
public interface EndPoint {
|
||||||
|
|
||||||
|
default String path() {
|
||||||
|
return this.getClass().getTypeName().substring(27).replace("EndPoint", "").replaceAll("([A-Z])", "_\1").toLowerCase();
|
||||||
|
}
|
||||||
|
JsonObject result(Request request, Response response);
|
||||||
|
}
|
164
src/de/steamwar/bungeecore/api/Token.java
Normale Datei
164
src/de/steamwar/bungeecore/api/Token.java
Normale Datei
@ -0,0 +1,164 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bungeecore.api;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import javax.crypto.Cipher;
|
||||||
|
import java.io.*;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.*;
|
||||||
|
import java.security.spec.DSAPrivateKeySpec;
|
||||||
|
import java.security.spec.DSAPublicKeySpec;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class Token {
|
||||||
|
|
||||||
|
private static KeyPair pair;
|
||||||
|
|
||||||
|
private static KeyPair getKeyPair() {
|
||||||
|
if (pair != null) return pair;
|
||||||
|
|
||||||
|
File publicKeyFile = new File("~/token_dsa.pub");
|
||||||
|
File privateKeyFile = new File("~/token_dsa");
|
||||||
|
|
||||||
|
if (publicKeyFile.exists() && privateKeyFile.exists()) {
|
||||||
|
PublicKey publicKey = null;
|
||||||
|
try {
|
||||||
|
JsonObject jsonObject = JsonParser.parseReader(new BufferedReader(new InputStreamReader(new FileInputStream(publicKeyFile)))).getAsJsonObject();
|
||||||
|
BigInteger y = jsonObject.get("y").getAsBigInteger();
|
||||||
|
BigInteger p = jsonObject.get("p").getAsBigInteger();
|
||||||
|
BigInteger q = jsonObject.get("q").getAsBigInteger();
|
||||||
|
BigInteger g = jsonObject.get("g").getAsBigInteger();
|
||||||
|
KeyFactory keyFactory = KeyFactory.getInstance("DSA");
|
||||||
|
publicKey = keyFactory.generatePublic(new DSAPublicKeySpec(y, p, q, g));
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
PrivateKey privateKey = null;
|
||||||
|
try {
|
||||||
|
JsonObject jsonObject = JsonParser.parseReader(new BufferedReader(new InputStreamReader(new FileInputStream(privateKeyFile)))).getAsJsonObject();
|
||||||
|
BigInteger x = jsonObject.get("x").getAsBigInteger();
|
||||||
|
BigInteger p = jsonObject.get("p").getAsBigInteger();
|
||||||
|
BigInteger q = jsonObject.get("q").getAsBigInteger();
|
||||||
|
BigInteger g = jsonObject.get("g").getAsBigInteger();
|
||||||
|
KeyFactory keyFactory = KeyFactory.getInstance("DSA");
|
||||||
|
privateKey = keyFactory.generatePrivate(new DSAPrivateKeySpec(x, p, q, g));
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
pair = new KeyPair(publicKey, privateKey);
|
||||||
|
return pair;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("DSA");
|
||||||
|
keyPairGen.initialize(2048);
|
||||||
|
pair = keyPairGen.generateKeyPair();
|
||||||
|
saveKeyPair();
|
||||||
|
return pair;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new SecurityException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void saveKeyPair() {
|
||||||
|
File publicKeyFile = new File("~/token_dsa.pub");
|
||||||
|
File privateKeyFile = new File("~/token_dsa");
|
||||||
|
|
||||||
|
try {
|
||||||
|
publicKeyFile.createNewFile();
|
||||||
|
KeyFactory keyFactory = KeyFactory.getInstance(pair.getPrivate().getAlgorithm());
|
||||||
|
DSAPublicKeySpec dsaPublicKeySpec = keyFactory.getKeySpec(pair.getPublic(), DSAPublicKeySpec.class);
|
||||||
|
|
||||||
|
JsonObject privateKey = new JsonObject();
|
||||||
|
privateKey.addProperty("y", dsaPublicKeySpec.getY());
|
||||||
|
privateKey.addProperty("p", dsaPublicKeySpec.getP());
|
||||||
|
privateKey.addProperty("q", dsaPublicKeySpec.getQ());
|
||||||
|
privateKey.addProperty("g", dsaPublicKeySpec.getG());
|
||||||
|
new JsonWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(publicKeyFile)))).close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
privateKeyFile.createNewFile();
|
||||||
|
KeyFactory keyFactory = KeyFactory.getInstance(pair.getPrivate().getAlgorithm());
|
||||||
|
DSAPrivateKeySpec dsaPrivateKeySpec = keyFactory.getKeySpec(pair.getPrivate(), DSAPrivateKeySpec.class);
|
||||||
|
|
||||||
|
JsonObject privateKey = new JsonObject();
|
||||||
|
privateKey.addProperty("x", dsaPrivateKeySpec.getX());
|
||||||
|
privateKey.addProperty("p", dsaPrivateKeySpec.getP());
|
||||||
|
privateKey.addProperty("q", dsaPrivateKeySpec.getQ());
|
||||||
|
privateKey.addProperty("g", dsaPrivateKeySpec.getG());
|
||||||
|
new JsonWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(privateKeyFile)))).close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private UUID uuid;
|
||||||
|
private long creationDate;
|
||||||
|
|
||||||
|
public Token(SteamwarUser steamwarUser) {
|
||||||
|
uuid = steamwarUser.getUuid();
|
||||||
|
creationDate = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Token(JsonObject jsonObject) {
|
||||||
|
uuid = UUID.fromString(jsonObject.get("uuid").getAsString());
|
||||||
|
creationDate = jsonObject.get("creationDate").getAsLong();
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonObject toJSON() {
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
jsonObject.addProperty("uuid", uuid.toString());
|
||||||
|
jsonObject.addProperty("creationDate", creationDate);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String encrypt() {
|
||||||
|
try {
|
||||||
|
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
|
||||||
|
cipher.init(Cipher.ENCRYPT_MODE, getKeyPair().getPublic());
|
||||||
|
return Base64.getEncoder().encodeToString(cipher.doFinal(toJSON().toString().getBytes(StandardCharsets.UTF_8)));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new SecurityException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Token decrypt(String s) {
|
||||||
|
try {
|
||||||
|
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
|
||||||
|
cipher.init(Cipher.DECRYPT_MODE, getKeyPair().getPrivate());
|
||||||
|
byte[] bytes = cipher.doFinal(Base64.getDecoder().decode(s));
|
||||||
|
JsonObject jsonObject = JsonParser.parseReader(new InputStreamReader(new ByteArrayInputStream(bytes))).getAsJsonObject();
|
||||||
|
return new Token(jsonObject);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new SecurityException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
68
src/de/steamwar/bungeecore/api/WebAPI.java
Normale Datei
68
src/de/steamwar/bungeecore/api/WebAPI.java
Normale Datei
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bungeecore.api;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import de.steamwar.bungeecore.api.v1.ServerstatusEndPoint;
|
||||||
|
import de.steamwar.bungeecore.api.v1.ServerteamEndPoint;
|
||||||
|
import de.steamwar.bungeecore.api.v1.statistics.*;
|
||||||
|
import de.steamwar.bungeecore.api.v1.user.GetUsernameEndPoint;
|
||||||
|
import de.steamwar.bungeecore.api.v1.user.GetUuidEndPoint;
|
||||||
|
import de.steamwar.bungeecore.api.v1.website.LoginEndPoint;
|
||||||
|
import de.steamwar.bungeecore.api.v1.website.LogoutEndPoint;
|
||||||
|
|
||||||
|
import static spark.Spark.port;
|
||||||
|
import static spark.Spark.post;
|
||||||
|
|
||||||
|
public class WebAPI {
|
||||||
|
|
||||||
|
private static EndPoint[] endPointsV1 = new EndPoint[] {
|
||||||
|
new FightsEndPoint(),
|
||||||
|
new HoursContributedEndPoint(),
|
||||||
|
new HoursPlayedEndPoint(),
|
||||||
|
new SchematicsAcceptedEndPoint(),
|
||||||
|
new UniqueJoinsEndPoint(),
|
||||||
|
new GetUsernameEndPoint(),
|
||||||
|
new GetUuidEndPoint(),
|
||||||
|
new LoginEndPoint(),
|
||||||
|
new LogoutEndPoint(),
|
||||||
|
new ServerstatusEndPoint(),
|
||||||
|
new ServerteamEndPoint(),
|
||||||
|
};
|
||||||
|
|
||||||
|
private static void register(EndPoint[] endPoints) {
|
||||||
|
for (EndPoint endPoint : endPoints) {
|
||||||
|
post(endPoint.path(), (request, response) -> {
|
||||||
|
JsonObject result = endPoint.result(request, response);
|
||||||
|
if (result == null) {
|
||||||
|
result = new JsonObject();
|
||||||
|
}
|
||||||
|
response.type("application/json");
|
||||||
|
return result.toString();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void start() {
|
||||||
|
port(1024);
|
||||||
|
|
||||||
|
register(endPointsV1);
|
||||||
|
}
|
||||||
|
}
|
38
src/de/steamwar/bungeecore/api/doc.txt
Normale Datei
38
src/de/steamwar/bungeecore/api/doc.txt
Normale Datei
@ -0,0 +1,38 @@
|
|||||||
|
```
|
||||||
|
SteamWar Endpoints:
|
||||||
|
|
||||||
|
Serverteam-Endpoint:
|
||||||
|
- UUID, Rang, InGame-Name
|
||||||
|
|
||||||
|
User-Endpoints:
|
||||||
|
- UUID -> skin.png
|
||||||
|
- UUID -> head.png
|
||||||
|
- Token -> UUID
|
||||||
|
- Token -> head.png
|
||||||
|
- Token -> skin.png
|
||||||
|
- Token -> InGame-Name
|
||||||
|
|
||||||
|
Website-User-Endpoints:
|
||||||
|
- (UserName, hashedPW) -> Token
|
||||||
|
- (Token) -> Void // Abmeldung
|
||||||
|
|
||||||
|
Serverstatus-Endpoint:
|
||||||
|
- PlayerSize, MaxPlayerSize
|
||||||
|
Response -> Status
|
||||||
|
|
||||||
|
Ranked-Endpoint:
|
||||||
|
- (Modus, Season?) -> Ranglist
|
||||||
|
- (UUID) -> Ränge
|
||||||
|
Ranglist-Endpoint:
|
||||||
|
- Modi // Alle Modi, welche eine Ranglist haben
|
||||||
|
Schem-Endpoint:
|
||||||
|
- (Modus, Season?) -> Public-Ranglist
|
||||||
|
- (Modus, Season?, Token) -> Privat-Ranglist
|
||||||
|
|
||||||
|
Statistiken-Endpoints:
|
||||||
|
- Modi, AnzahlFights // Anzahl Fights der letzten 7 Tage
|
||||||
|
- AnzahlJoins // Anzahl Joins der letzten 7 Tage (total)
|
||||||
|
- UniqueJoins // Anzahl uniquer PlayerJoins der letzten 7 Tage (total)
|
||||||
|
- HoursPlayed // Anzahl gespielter Stunden für alle Spieler der letzten 7 Tage (total)
|
||||||
|
|
||||||
|
```
|
39
src/de/steamwar/bungeecore/api/v1/ServerstatusEndPoint.java
Normale Datei
39
src/de/steamwar/bungeecore/api/v1/ServerstatusEndPoint.java
Normale Datei
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bungeecore.api.v1;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import de.steamwar.bungeecore.api.EndPoint;
|
||||||
|
import net.md_5.bungee.BungeeCord;
|
||||||
|
import spark.Request;
|
||||||
|
import spark.Response;
|
||||||
|
|
||||||
|
public class ServerstatusEndPoint implements EndPoint {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonObject result(Request request, Response response) {
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
jsonObject.addProperty("players", BungeeCord.getInstance().getPlayers().size());
|
||||||
|
jsonObject.addProperty("maxPlayers", BungeeCord.getInstance().getConfig().getPlayerLimit());
|
||||||
|
|
||||||
|
response.status(200);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
}
|
46
src/de/steamwar/bungeecore/api/v1/ServerteamEndPoint.java
Normale Datei
46
src/de/steamwar/bungeecore/api/v1/ServerteamEndPoint.java
Normale Datei
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bungeecore.api.v1;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import de.steamwar.bungeecore.api.EndPoint;
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import spark.Request;
|
||||||
|
import spark.Response;
|
||||||
|
|
||||||
|
public class ServerteamEndPoint implements EndPoint {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonObject result(Request request, Response response) {
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
JsonArray jsonArray = new JsonArray();
|
||||||
|
SteamwarUser.getServerTeam().forEach(steamwarUser -> {
|
||||||
|
JsonObject user = new JsonObject();
|
||||||
|
user.addProperty("name", steamwarUser.getUserName());
|
||||||
|
user.addProperty("rank", steamwarUser.getUserGroup().name());
|
||||||
|
jsonArray.add(user);
|
||||||
|
});
|
||||||
|
jsonObject.add("", jsonArray);
|
||||||
|
|
||||||
|
response.status(200);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
}
|
45
src/de/steamwar/bungeecore/api/v1/statistics/FightsEndPoint.java
Normale Datei
45
src/de/steamwar/bungeecore/api/v1/statistics/FightsEndPoint.java
Normale Datei
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bungeecore.api.v1.statistics;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import de.steamwar.bungeecore.api.EndPoint;
|
||||||
|
import de.steamwar.bungeecore.sql.Statistics;
|
||||||
|
import spark.Request;
|
||||||
|
import spark.Response;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class FightsEndPoint implements EndPoint {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonObject result(Request request, Response response) {
|
||||||
|
Map<String, Map<String, Integer>> result = Statistics.getFightsPerDayPerGameMode();
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
result.forEach((s, stringIntegerMap) -> {
|
||||||
|
JsonObject singleResult = new JsonObject();
|
||||||
|
stringIntegerMap.forEach(singleResult::addProperty);
|
||||||
|
jsonObject.add(s, singleResult);
|
||||||
|
});
|
||||||
|
|
||||||
|
response.status(200);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bungeecore.api.v1.statistics;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import de.steamwar.bungeecore.api.EndPoint;
|
||||||
|
import de.steamwar.bungeecore.sql.Statistics;
|
||||||
|
import spark.Request;
|
||||||
|
import spark.Response;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class HoursContributedEndPoint implements EndPoint {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonObject result(Request request, Response response) {
|
||||||
|
Map<String, Double> result = Statistics.getHoursContributedPerPlayer();
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
result.forEach(jsonObject::addProperty);
|
||||||
|
|
||||||
|
response.status(200);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bungeecore.api.v1.statistics;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import de.steamwar.bungeecore.api.EndPoint;
|
||||||
|
import de.steamwar.bungeecore.sql.Statistics;
|
||||||
|
import spark.Request;
|
||||||
|
import spark.Response;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class HoursPlayedEndPoint implements EndPoint {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonObject result(Request request, Response response) {
|
||||||
|
Map<String, Double> result = Statistics.getHoursPlayedPerDay();
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
result.forEach(jsonObject::addProperty);
|
||||||
|
|
||||||
|
response.status(200);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bungeecore.api.v1.statistics;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import de.steamwar.bungeecore.api.EndPoint;
|
||||||
|
import de.steamwar.bungeecore.sql.Statistics;
|
||||||
|
import spark.Request;
|
||||||
|
import spark.Response;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class SchematicsAcceptedEndPoint implements EndPoint {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonObject result(Request request, Response response) {
|
||||||
|
Map<String, Map<String, Integer>> result = Statistics.getAcceptedSchematicsPerDayPerGameMode();
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
result.forEach((s, stringIntegerMap) -> {
|
||||||
|
JsonObject singleResult = new JsonObject();
|
||||||
|
stringIntegerMap.forEach(singleResult::addProperty);
|
||||||
|
jsonObject.add(s, singleResult);
|
||||||
|
});
|
||||||
|
|
||||||
|
response.status(200);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bungeecore.api.v1.statistics;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import de.steamwar.bungeecore.api.EndPoint;
|
||||||
|
import de.steamwar.bungeecore.sql.Statistics;
|
||||||
|
import spark.Request;
|
||||||
|
import spark.Response;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class UniqueJoinsEndPoint implements EndPoint {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonObject result(Request request, Response response) {
|
||||||
|
Map<String, Integer> result = Statistics.getUniqueJoinsPerDay();
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
result.forEach(jsonObject::addProperty);
|
||||||
|
|
||||||
|
response.status(200);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
}
|
50
src/de/steamwar/bungeecore/api/v1/user/GetUsernameEndPoint.java
Normale Datei
50
src/de/steamwar/bungeecore/api/v1/user/GetUsernameEndPoint.java
Normale Datei
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bungeecore.api.v1.user;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import de.steamwar.bungeecore.api.AuthUtils;
|
||||||
|
import de.steamwar.bungeecore.api.EndPoint;
|
||||||
|
import de.steamwar.bungeecore.api.Token;
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import spark.Request;
|
||||||
|
import spark.Response;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static spark.Spark.post;
|
||||||
|
|
||||||
|
public class GetUsernameEndPoint implements EndPoint {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonObject result(Request request, Response response) {
|
||||||
|
Optional<Token> optionalToken = AuthUtils.isAuthorized(request, response);
|
||||||
|
if (!optionalToken.isPresent()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Token token = optionalToken.get();
|
||||||
|
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
jsonObject.addProperty("username", SteamwarUser.get(token.getUuid()).getUserName());
|
||||||
|
|
||||||
|
response.status(200);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
}
|
47
src/de/steamwar/bungeecore/api/v1/user/GetUuidEndPoint.java
Normale Datei
47
src/de/steamwar/bungeecore/api/v1/user/GetUuidEndPoint.java
Normale Datei
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bungeecore.api.v1.user;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import de.steamwar.bungeecore.api.AuthUtils;
|
||||||
|
import de.steamwar.bungeecore.api.EndPoint;
|
||||||
|
import de.steamwar.bungeecore.api.Token;
|
||||||
|
import spark.Request;
|
||||||
|
import spark.Response;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class GetUuidEndPoint implements EndPoint {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonObject result(Request request, Response response) {
|
||||||
|
Optional<Token> optionalToken = AuthUtils.isAuthorized(request, response);
|
||||||
|
if (!optionalToken.isPresent()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Token token = optionalToken.get();
|
||||||
|
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
jsonObject.addProperty("uuid", token.getUuid().toString());
|
||||||
|
|
||||||
|
response.status(200);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
}
|
33
src/de/steamwar/bungeecore/api/v1/website/LoginEndPoint.java
Normale Datei
33
src/de/steamwar/bungeecore/api/v1/website/LoginEndPoint.java
Normale Datei
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bungeecore.api.v1.website;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import de.steamwar.bungeecore.api.EndPoint;
|
||||||
|
import spark.Request;
|
||||||
|
import spark.Response;
|
||||||
|
|
||||||
|
public class LoginEndPoint implements EndPoint {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonObject result(Request request, Response response) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
33
src/de/steamwar/bungeecore/api/v1/website/LogoutEndPoint.java
Normale Datei
33
src/de/steamwar/bungeecore/api/v1/website/LogoutEndPoint.java
Normale Datei
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bungeecore.api.v1.website;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import de.steamwar.bungeecore.api.EndPoint;
|
||||||
|
import spark.Request;
|
||||||
|
import spark.Response;
|
||||||
|
|
||||||
|
public class LogoutEndPoint implements EndPoint {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonObject result(Request request, Response response) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
120
src/de/steamwar/bungeecore/sql/Statistics.java
Normale Datei
120
src/de/steamwar/bungeecore/sql/Statistics.java
Normale Datei
@ -0,0 +1,120 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bungeecore.sql;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Statistics {
|
||||||
|
|
||||||
|
private static final Statement fightsPerDayPerGameMode = new Statement("SELECT * FROM Punishments WHERE UserId = ? AND Type = ? ORDER BY PunishmentId DESC LIMIT 1");
|
||||||
|
|
||||||
|
public static Map<String, Map<String, Integer>> getFightsPerDayPerGameMode() {
|
||||||
|
return fightsPerDayPerGameMode.select(rs -> {
|
||||||
|
Map<String, Map<String, Integer>> counts = new HashMap<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
String date = rs.getString("Date");
|
||||||
|
String gameMode = rs.getString("GameMode");
|
||||||
|
int fightCount = rs.getInt("Fights");
|
||||||
|
|
||||||
|
counts.computeIfAbsent(date, s -> new HashMap<>()).put(gameMode, fightCount);
|
||||||
|
}
|
||||||
|
return counts;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
private static final Statement joinsPerDay = new Statement("SELECT * FROM Punishments WHERE UserId = ? AND Type = ? ORDER BY PunishmentId DESC LIMIT 1");
|
||||||
|
|
||||||
|
public static Map<String, Integer> getJoinsPerDay() {
|
||||||
|
return joinsPerDay.select(rs -> {
|
||||||
|
Map<String, Integer> counts = new HashMap<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
String date = rs.getString("Date");
|
||||||
|
int joins = rs.getInt("Joins");
|
||||||
|
|
||||||
|
counts.put(date, joins);
|
||||||
|
}
|
||||||
|
return counts;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static final Statement uniqueJoinsPerDay = new Statement("SELECT DATE(StartTime) as Date, COUNT(distinct UserID) as UniqueJoins FROM Session WHERE DATE(StartTime) > DATE(CURRENT_TIME) - 7 GROUP BY DATE(StartTime)");
|
||||||
|
|
||||||
|
public static Map<String, Integer> getUniqueJoinsPerDay() {
|
||||||
|
return uniqueJoinsPerDay.select(rs -> {
|
||||||
|
Map<String, Integer> counts = new HashMap<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
String date = rs.getString("Date");
|
||||||
|
int joins = rs.getInt("Joins");
|
||||||
|
|
||||||
|
counts.put(date, joins);
|
||||||
|
}
|
||||||
|
return counts;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement hoursPlayedPerDay = new Statement("SELECT DATE(StartTime) as Date, SUM(UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime)) / 60.0 / 60.0 as Hours FROM Session WHERE DATE(StartTime) > DATE(CURRENT_TIME) - 7 GROUP BY DATE(StartTime)");
|
||||||
|
|
||||||
|
public static Map<String, Double> getHoursPlayedPerDay() {
|
||||||
|
return hoursPlayedPerDay.select(rs -> {
|
||||||
|
Map<String, Double> counts = new HashMap<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
String date = rs.getString("Date");
|
||||||
|
double hours = rs.getInt("Hours");
|
||||||
|
|
||||||
|
counts.put(date, hours);
|
||||||
|
}
|
||||||
|
return counts;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement hoursContributedPerPlayer = new Statement("SELECT UserName, SUM(UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime)) / 60.0 / 60.0 as Hours FROM Session INNER JOIN UserData UD on Session.UserID = UD.id WHERE DATE(StartTime) > DATE(CURRENT_TIME) - 7 GROUP BY UserID ORDER BY HOURS DESC LIMIT 10");
|
||||||
|
|
||||||
|
public static Map<String, Double> getHoursContributedPerPlayer() {
|
||||||
|
return hoursContributedPerPlayer.select(rs -> {
|
||||||
|
Map<String, Double> counts = new HashMap<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
String date = rs.getString("Date");
|
||||||
|
double hours = rs.getInt("Hours");
|
||||||
|
|
||||||
|
counts.put(date, hours);
|
||||||
|
}
|
||||||
|
return counts;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement acceptedSchematicsPerDayPerGameMode = new Statement("SELECT DATE(StartTime) as Date, NodeType, COUNT(*) as Count FROM CheckedSchematic INNER JOIN SchematicNode SN on CheckedSchematic.NodeId = SN.NodeId WHERE DeclineReason = 'freigegeben' GROUP BY DATE(StartTime), NodeType");
|
||||||
|
|
||||||
|
public static Map<String, Map<String, Integer>> getAcceptedSchematicsPerDayPerGameMode() {
|
||||||
|
return acceptedSchematicsPerDayPerGameMode.select(rs -> {
|
||||||
|
Map<String, Map<String, Integer>> counts = new HashMap<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
String date = rs.getString("Date");
|
||||||
|
String gameMode = rs.getString("NodeType");
|
||||||
|
int acceptedCount = rs.getInt("Count");
|
||||||
|
|
||||||
|
counts.computeIfAbsent(date, s -> new HashMap<>()).put(gameMode, acceptedCount);
|
||||||
|
}
|
||||||
|
return counts;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -59,6 +59,8 @@ 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 Statement getServerTeam = new Statement("SELECT * FROM UserData WHERE UserGroup != 'Member' AND UserGroup != 'YouTuber'");
|
||||||
|
|
||||||
private static final Map<String, SteamwarUser> usersByName = new HashMap<>();
|
private static final Map<String, SteamwarUser> usersByName = new HashMap<>();
|
||||||
private static final Map<UUID, SteamwarUser> usersByUUID = new HashMap<>();
|
private static final Map<UUID, SteamwarUser> usersByUUID = new HashMap<>();
|
||||||
private static final Map<Integer, SteamwarUser> usersById = new HashMap<>();
|
private static final Map<Integer, SteamwarUser> usersById = new HashMap<>();
|
||||||
@ -390,4 +392,13 @@ public class SteamwarUser {
|
|||||||
updateLocale.update(locale.toLanguageTag(), manualLocale, id);
|
updateLocale.update(locale.toLanguageTag(), manualLocale, id);
|
||||||
new LocaleInvalidationPacket(id).send(getPlayer());
|
new LocaleInvalidationPacket(id).send(getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<SteamwarUser> getServerTeam() {
|
||||||
|
return getServerTeam.select(rs -> {
|
||||||
|
List<SteamwarUser> users = new ArrayList<>();
|
||||||
|
while(rs.next())
|
||||||
|
users.add(new SteamwarUser(rs));
|
||||||
|
return users;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren