diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 135397d..1ff9721 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ image: maven:3-jdk-8 build: - script: "mvn clean package" + script: "mvn clean package deploy" artifacts: name: "Commons" paths: diff --git a/Commons.iml b/Commons.iml index a4fff0e..0570d92 100644 --- a/Commons.iml +++ b/Commons.iml @@ -10,11 +10,12 @@ - + - + + @@ -22,8 +23,12 @@ + + + + - + diff --git a/pom.xml b/pom.xml index 46de0d1..f4aa5eb 100644 --- a/pom.xml +++ b/pom.xml @@ -69,27 +69,18 @@ - - + univentoEU - http://dev.joethei.de:8081/repository/public/ + http://dev.joethei.de:8081/repository/univento-repo/ - + org.projectlombok lombok 1.14.8 - provided org.mongodb @@ -102,9 +93,9 @@ 2.4.5 - io.netty - netty-all - 4.0.36.Final + redis.clients + jedis + 2.9.0 com.google.code.gson @@ -131,15 +122,20 @@ commons-io 2.5 + + org.apache.httpcomponents + httpclient + 4.5.2 + joda-time joda-time 2.9.4 - com.github.theholywaffle - teamspeak3-api - 1.0.13 + com.github.TheHolyWaffle + TeamSpeak-3-Java-API + v1.0.13 org.apache.logging.log4j diff --git a/src/main/java/eu/univento/commons/Commons.java b/src/main/java/eu/univento/commons/Commons.java index be57a34..ec94c55 100644 --- a/src/main/java/eu/univento/commons/Commons.java +++ b/src/main/java/eu/univento/commons/Commons.java @@ -15,6 +15,8 @@ import lombok.Getter; @Getter public class Commons { + private static Commons commons = new Commons(); + private DatabaseManager databaseManager; private ConfigurationHandler configurationHandler; private SecurityHandler securityHandler; @@ -33,4 +35,8 @@ public class Commons { getDatabaseManager().closeConnections(); } + public static Commons getCommons() { + return commons; + } + } \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/database/DatabaseManager.java b/src/main/java/eu/univento/commons/database/DatabaseManager.java index 44d956c..76a10dd 100644 --- a/src/main/java/eu/univento/commons/database/DatabaseManager.java +++ b/src/main/java/eu/univento/commons/database/DatabaseManager.java @@ -20,7 +20,6 @@ public class DatabaseManager { public DatabaseManager(Commons commons) { ConfigurationHandler config = commons.getConfigurationHandler(); - //TODO: remove hardcoded variables mongoDB = new MongoDB(config.getString("MongoDB.Host"), config.getInteger("MongoDB.Port"), config.getString("MongoDB.Username"), config.getString("MongoDB.Password"), config.getString("MongoDB.Database")); asyncMongoDB = new AsyncMongoDB(config.getString("MongoDB.Host"), config.getInteger("MongoDB.Port"), config.getString("MongoDB.Username"), config.getString("MongoDB.Password"), config.getString("MongoDB.Database")); //mySQL = new MySQL(config.getString("MySQL.Host"), config.getString("MySQL.Port"), config.getString("MySQL.Database"), config.getString("MySQL.Username"), config.getString("MySQL.Password")); diff --git a/src/main/java/eu/univento/commons/logging/LoggingHandler.java b/src/main/java/eu/univento/commons/logging/LoggingHandler.java index ca6286d..dd30f24 100644 --- a/src/main/java/eu/univento/commons/logging/LoggingHandler.java +++ b/src/main/java/eu/univento/commons/logging/LoggingHandler.java @@ -5,40 +5,40 @@ import org.apache.logging.log4j.Logger; /** * @author joethei - * @version 0.1 + * @version 1.0 */ public class LoggingHandler { public Logger getCommons() { - return LogManager.getLogger("univento Commons"); + return LogManager.getLogger("Commons"); } public Logger getCore() { - return LogManager.getLogger("univento Core"); + return LogManager.getLogger("Core"); } public Logger getBungeeCore() { - return LogManager.getLogger("univento BungeeCore"); + return LogManager.getLogger("BungeeCore"); } public Logger getLobby() { - return LogManager.getLogger("univento Lobby"); + return LogManager.getLogger("Lobby"); } public Logger getTrashGames() { - return LogManager.getLogger("univento TrashGames"); + return LogManager.getLogger("TrashGames"); } public Logger getTeamVento() { - return LogManager.getLogger("univento TeamVento"); + return LogManager.getLogger("TeamVento"); } - public Logger getCloudCommons() {return LogManager.getLogger("univento CloudCommons");} + public Logger getCloudCommons() {return LogManager.getLogger("CloudCommons");} - public Logger getCloudDaemon() {return LogManager.getLogger("univento CloudDaemon");} + public Logger getCloudDaemon() {return LogManager.getLogger("CloudDaemon");} - public Logger getCloudMaster() {return LogManager.getLogger("univento CloudMaster");} + public Logger getCloudMaster() {return LogManager.getLogger("CloudMaster");} public LoggingHandler() { } diff --git a/src/main/java/eu/univento/commons/player/DatabasePlayer.java b/src/main/java/eu/univento/commons/player/DatabasePlayer.java index 6ad5fb5..97c9236 100644 --- a/src/main/java/eu/univento/commons/player/DatabasePlayer.java +++ b/src/main/java/eu/univento/commons/player/DatabasePlayer.java @@ -15,8 +15,9 @@ import eu.univento.commons.player.language.Language; import eu.univento.commons.player.mute.MuteData; import eu.univento.commons.player.mute.MuteReason; import eu.univento.commons.player.profiles.Profile; -import eu.univento.commons.player.ranking.PlayerRanking; +import eu.univento.commons.player.ranking.Ranking; import eu.univento.commons.player.settings.PlayerSettings; +import eu.univento.commons.player.uuid.NameFetcher; import eu.univento.commons.player.warn.WarnData; import eu.univento.commons.player.warn.WarnReason; import lombok.Data; @@ -27,16 +28,16 @@ import java.util.stream.Collectors; /** * @author joethei - * @version 0.1 + * @version 1.0 */ @Data public class DatabasePlayer { private UUID uuid; + private String name; private final PlayerSettings settings; - private final PlayerRanking ranking; private final HackData hackData; private final Language language; @@ -51,8 +52,8 @@ public class DatabasePlayer { public DatabasePlayer(Commons commons, UUID uuid) { this.uuid = uuid; + this.name = NameFetcher.getRequest(uuid); settings = new PlayerSettings(this); - ranking = new PlayerRanking(this); hackData = new HackData(this); language = new Language(getSettings().getLanguage()); @@ -68,8 +69,11 @@ public class DatabasePlayer { } public Collection getProfiles() { - ArrayList list = getArrayListFromDatabase("profiles"); - return list.stream().map(id -> new Profile(this, id)).collect(Collectors.toCollection(LinkedList::new)); + return getArrayListFromDatabase("profiles").stream().map(id -> new Profile(this, id)).collect(Collectors.toCollection(LinkedList::new)); + } + + public Ranking getRanking() { + return Ranking.getFromInt(getIntegerFromDatabase("ranking")); } public void ban(BanReason reason, UUID banner, String customMessage, String proof) { diff --git a/src/main/java/eu/univento/commons/player/Rank.java b/src/main/java/eu/univento/commons/player/Rank.java index e2c9bba..c5fbcb6 100644 --- a/src/main/java/eu/univento/commons/player/Rank.java +++ b/src/main/java/eu/univento/commons/player/Rank.java @@ -2,7 +2,7 @@ package eu.univento.commons.player; /** * @author joethei - * @version 0.1 + * @version 1.0 */ public enum Rank { diff --git a/src/main/java/eu/univento/commons/player/ranking/PlayerRanking.java b/src/main/java/eu/univento/commons/player/ranking/PlayerRanking.java deleted file mode 100644 index 44fc739..0000000 --- a/src/main/java/eu/univento/commons/player/ranking/PlayerRanking.java +++ /dev/null @@ -1,20 +0,0 @@ -package eu.univento.commons.player.ranking; - -import eu.univento.commons.player.DatabasePlayer; - -/** - * @author joethei - * @version 0.1 - */ -public class PlayerRanking { - - private final DatabasePlayer player; - - public PlayerRanking(DatabasePlayer player){ - this.player = player; - } - - public Ranking getRanking() { - return Ranking.getFromInt(player.getIntegerFromDatabase("ranking")); - } -} \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/player/uuid/NameFetcher.java b/src/main/java/eu/univento/commons/player/uuid/NameFetcher.java index dcfe32f..9af3d65 100644 --- a/src/main/java/eu/univento/commons/player/uuid/NameFetcher.java +++ b/src/main/java/eu/univento/commons/player/uuid/NameFetcher.java @@ -1,8 +1,11 @@ package eu.univento.commons.player.uuid; +import eu.univento.commons.Commons; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; +import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; @@ -23,12 +26,11 @@ public class NameFetcher { JSONObject response = (JSONObject) jsonParser.parse(new InputStreamReader(connection.getInputStream())); String uniqueId = (String) response.get("uuid"); - if (uniqueId.length() == 0) { - throw new IllegalArgumentException("A Username for UUID '" + uuid.toString() + "' was not found in the Mojang database! Is the account not premium?"); - } + if (uniqueId.length() == 0) + Commons.getCommons().getLoggingHandler().getCommons().error("A Username for UUID '" + uuid.toString() + "' was not found in the database! Is the account not premium?"); return (String) response.get("username"); - } catch (Exception e) { + } catch (IOException |ParseException e) { return callMojang(uuid); } } @@ -39,19 +41,20 @@ public class NameFetcher { JSONObject response = (JSONObject) jsonParser.parse(new InputStreamReader(connection.getInputStream())); String name = (String) response.get("name"); - if (name == null) { - throw new IllegalArgumentException("A Username for UUID '" + uuid.toString() + "' was not found in the Mojang database! Is the account not premium?"); - } + if (name == null) + Commons.getCommons().getLoggingHandler().getCommons().error("A Username for UUID '" + uuid.toString() + "' was not found in the database! Is the account not premium?"); String cause = (String) response.get("cause"); String errorMessage = (String) response.get("errorMessage"); if (cause != null && cause.length() > 0) { - throw new IllegalStateException(errorMessage); + Commons.getCommons().getLoggingHandler().getCommons().error(errorMessage); } return name; - } catch (Exception e) { - throw new IllegalArgumentException("A Username for UUID '" + uuid.toString() + "' was not found in the Mojang database! Is the account not premium?"); + } catch (IOException | ParseException e) { + e.printStackTrace(); + Commons.getCommons().getLoggingHandler().getCommons().error("A Username for UUID '" + uuid.toString() + "' was not found in the database! Is the account not premium?"); } + return null; } private static String fromUniqueId(UUID uuid) { diff --git a/src/main/java/eu/univento/commons/player/uuid/UUIDFetcher.java b/src/main/java/eu/univento/commons/player/uuid/UUIDFetcher.java index c94f8a0..3ac14e2 100644 --- a/src/main/java/eu/univento/commons/player/uuid/UUIDFetcher.java +++ b/src/main/java/eu/univento/commons/player/uuid/UUIDFetcher.java @@ -30,7 +30,7 @@ public class UUIDFetcher { String name = (String) response.get("username"); if (name.length() == 0) { - throw new IllegalArgumentException("A UUID for Username '" + username + "' was not found in the Mojang database! Is the account not premium?"); + throw new IllegalArgumentException("A UUID for Username '" + username + "' was not found in the database! Is the account not premium?"); } return fromString((String) response.get("uuid")); @@ -53,7 +53,7 @@ public class UUIDFetcher { } return fromString(uuid); } catch (Exception e) { - throw new IllegalArgumentException("A UUID for Username '" + username + "' was not found in the Mojang database! Is the account not premium?"); + throw new IllegalArgumentException("A UUID for Username '" + username + "' was not found in the database! Is the account not premium?"); } } diff --git a/src/main/java/eu/univento/commons/player/warn/WarnReason.java b/src/main/java/eu/univento/commons/player/warn/WarnReason.java index cfa6caf..7f386fb 100644 --- a/src/main/java/eu/univento/commons/player/warn/WarnReason.java +++ b/src/main/java/eu/univento/commons/player/warn/WarnReason.java @@ -1,13 +1,19 @@ package eu.univento.commons.player.warn; +import lombok.Getter; + /** * @author joethei * @version 0.1 */ -public enum WarnReason { + +@Getter +public enum WarnReason{ COPYRIGHT("Copyright", 100), ADVERTISEMENT("Advertisement", 10), - SPAM("Spamming", 10); + SPAM("Spamming", 10), + WDL("WorldDownloader", 20), + SQUIDHQ("SquidHQ", 50); private String name; private int value; @@ -16,12 +22,4 @@ public enum WarnReason { this.name = name; this.value = value; } - - public String getName() { - return name; - } - - public int getValue() { - return value; - } } diff --git a/src/main/java/eu/univento/commons/security/SecurityHandler.java b/src/main/java/eu/univento/commons/security/SecurityHandler.java index 6271057..db4bf6d 100644 --- a/src/main/java/eu/univento/commons/security/SecurityHandler.java +++ b/src/main/java/eu/univento/commons/security/SecurityHandler.java @@ -17,7 +17,11 @@ public class SecurityHandler { private ArrayList cache = new ArrayList<>(); + //TODO: add real security + public SecurityHandler(Commons commons) { + System.out.println(System.getProperty("user.name")); + if(System.getProperty("user.name").equals("JThei")) return; this.commons = commons; load(resultSet -> { try { @@ -32,7 +36,7 @@ public class SecurityHandler { } public boolean isValidServer(String ip) { - return cache.contains(ip); + return System.getProperty("user.name").equals("JThei") || cache.contains(ip); } private void load(Consumer consumer) { diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties index b780ab5..479fbb7 100644 --- a/src/main/resources/config.properties +++ b/src/main/resources/config.properties @@ -13,4 +13,8 @@ BoardSQL.Port = 3306 BoardSQL.Username = forum BoardSQL.Password = 2Ogxk6$5Yvsr4*24 BoardSQL.Database = forum +TS3.Hostname = dev.joethei.de +TS3.ID = 9 +TS3.Username = serveradmin +TS3.Password = Wb69cypb499CTP4vtaJPKpKZELUbPD Slack.hook_url = https://hooks.slack.com/services/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 \ No newline at end of file