changing some stuff up

This commit is contained in:
Johannes Theiner 2016-12-06 19:17:13 +01:00
parent 57bf6dc7e3
commit 0c4e8bdcc0
14 changed files with 82 additions and 83 deletions

View File

@ -1,7 +1,7 @@
image: maven:3-jdk-8 image: maven:3-jdk-8
build: build:
script: "mvn clean package" script: "mvn clean package deploy"
artifacts: artifacts:
name: "Commons" name: "Commons"
paths: paths:

View File

@ -10,11 +10,12 @@
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.14.8" level="project" /> <orderEntry type="library" name="Maven: org.projectlombok:lombok:1.14.8" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:3.2.2" level="project" /> <orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:3.2.2" level="project" />
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:2.4.5" level="project" /> <orderEntry type="library" name="Maven: com.zaxxer:HikariCP:2.4.5" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.16" level="project" /> <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.16" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-all:4.0.36.Final" level="project" /> <orderEntry type="library" name="Maven: redis.clients:jedis:2.9.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.4.2" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.3.1" level="project" /> <orderEntry type="library" name="Maven: com.google.code.gson:gson:2.3.1" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" /> <orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" /> <orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
@ -22,8 +23,12 @@
<orderEntry type="library" name="Maven: com.google.guava:guava:19.0" level="project" /> <orderEntry type="library" name="Maven: com.google.guava:guava:19.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.1" level="project" /> <orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.1" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.5" level="project" /> <orderEntry type="library" name="Maven: commons-io:commons-io:2.5" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.4" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.9" level="project" />
<orderEntry type="library" name="Maven: joda-time:joda-time:2.9.4" level="project" /> <orderEntry type="library" name="Maven: joda-time:joda-time:2.9.4" level="project" />
<orderEntry type="library" name="Maven: com.github.theholywaffle:teamspeak3-api:1.0.13" level="project" /> <orderEntry type="library" name="Maven: com.github.TheHolyWaffle:TeamSpeak-3-Java-API:v1.0.13" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.6.2" level="project" /> <orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.6.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.6.2" level="project" /> <orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.6.2" level="project" />
<orderEntry type="library" name="Maven: net.gpedro.integrations.slack:slack-webhook:1.2.1" level="project" /> <orderEntry type="library" name="Maven: net.gpedro.integrations.slack:slack-webhook:1.2.1" level="project" />

32
pom.xml
View File

@ -69,27 +69,18 @@
</plugins> </plugins>
</build> </build>
<repositories> <distributionManagement>
<!--<repository>
<id>TeamSpeak-3-Java-API-mvn-repo</id>
<url>https://raw.githubusercontent.com/TheHolyWaffle/TeamSpeak-3-Java-API/mvn-repo/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>-->
<repository> <repository>
<id>univentoEU</id> <id>univentoEU</id>
<url>http://dev.joethei.de:8081/repository/public/</url> <url>http://dev.joethei.de:8081/repository/univento-repo/</url>
</repository> </repository>
</repositories> </distributionManagement>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>1.14.8</version> <version>1.14.8</version>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mongodb</groupId> <groupId>org.mongodb</groupId>
@ -102,9 +93,9 @@
<version>2.4.5</version> <version>2.4.5</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.netty</groupId> <groupId>redis.clients</groupId>
<artifactId>netty-all</artifactId> <artifactId>jedis</artifactId>
<version>4.0.36.Final</version> <version>2.9.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.code.gson</groupId> <groupId>com.google.code.gson</groupId>
@ -131,15 +122,20 @@
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
<version>2.5</version> <version>2.5</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
<dependency> <dependency>
<groupId>joda-time</groupId> <groupId>joda-time</groupId>
<artifactId>joda-time</artifactId> <artifactId>joda-time</artifactId>
<version>2.9.4</version> <version>2.9.4</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.theholywaffle</groupId> <groupId>com.github.TheHolyWaffle</groupId>
<artifactId>teamspeak3-api</artifactId> <artifactId>TeamSpeak-3-Java-API</artifactId>
<version>1.0.13</version> <version>v1.0.13</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>

View File

@ -15,6 +15,8 @@ import lombok.Getter;
@Getter @Getter
public class Commons { public class Commons {
private static Commons commons = new Commons();
private DatabaseManager databaseManager; private DatabaseManager databaseManager;
private ConfigurationHandler configurationHandler; private ConfigurationHandler configurationHandler;
private SecurityHandler securityHandler; private SecurityHandler securityHandler;
@ -33,4 +35,8 @@ public class Commons {
getDatabaseManager().closeConnections(); getDatabaseManager().closeConnections();
} }
public static Commons getCommons() {
return commons;
}
} }

View File

@ -20,7 +20,6 @@ public class DatabaseManager {
public DatabaseManager(Commons commons) { public DatabaseManager(Commons commons) {
ConfigurationHandler config = commons.getConfigurationHandler(); 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")); 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")); 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")); //mySQL = new MySQL(config.getString("MySQL.Host"), config.getString("MySQL.Port"), config.getString("MySQL.Database"), config.getString("MySQL.Username"), config.getString("MySQL.Password"));

View File

@ -5,40 +5,40 @@ import org.apache.logging.log4j.Logger;
/** /**
* @author joethei * @author joethei
* @version 0.1 * @version 1.0
*/ */
public class LoggingHandler { public class LoggingHandler {
public Logger getCommons() { public Logger getCommons() {
return LogManager.getLogger("univento Commons"); return LogManager.getLogger("Commons");
} }
public Logger getCore() { public Logger getCore() {
return LogManager.getLogger("univento Core"); return LogManager.getLogger("Core");
} }
public Logger getBungeeCore() { public Logger getBungeeCore() {
return LogManager.getLogger("univento BungeeCore"); return LogManager.getLogger("BungeeCore");
} }
public Logger getLobby() { public Logger getLobby() {
return LogManager.getLogger("univento Lobby"); return LogManager.getLogger("Lobby");
} }
public Logger getTrashGames() { public Logger getTrashGames() {
return LogManager.getLogger("univento TrashGames"); return LogManager.getLogger("TrashGames");
} }
public Logger getTeamVento() { 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() { public LoggingHandler() {
} }

View File

@ -15,8 +15,9 @@ import eu.univento.commons.player.language.Language;
import eu.univento.commons.player.mute.MuteData; import eu.univento.commons.player.mute.MuteData;
import eu.univento.commons.player.mute.MuteReason; import eu.univento.commons.player.mute.MuteReason;
import eu.univento.commons.player.profiles.Profile; 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.settings.PlayerSettings;
import eu.univento.commons.player.uuid.NameFetcher;
import eu.univento.commons.player.warn.WarnData; import eu.univento.commons.player.warn.WarnData;
import eu.univento.commons.player.warn.WarnReason; import eu.univento.commons.player.warn.WarnReason;
import lombok.Data; import lombok.Data;
@ -27,16 +28,16 @@ import java.util.stream.Collectors;
/** /**
* @author joethei * @author joethei
* @version 0.1 * @version 1.0
*/ */
@Data @Data
public class DatabasePlayer { public class DatabasePlayer {
private UUID uuid; private UUID uuid;
private String name;
private final PlayerSettings settings; private final PlayerSettings settings;
private final PlayerRanking ranking;
private final HackData hackData; private final HackData hackData;
private final Language language; private final Language language;
@ -51,8 +52,8 @@ public class DatabasePlayer {
public DatabasePlayer(Commons commons, UUID uuid) { public DatabasePlayer(Commons commons, UUID uuid) {
this.uuid = uuid; this.uuid = uuid;
this.name = NameFetcher.getRequest(uuid);
settings = new PlayerSettings(this); settings = new PlayerSettings(this);
ranking = new PlayerRanking(this);
hackData = new HackData(this); hackData = new HackData(this);
language = new Language(getSettings().getLanguage()); language = new Language(getSettings().getLanguage());
@ -68,8 +69,11 @@ public class DatabasePlayer {
} }
public Collection<Profile> getProfiles() { public Collection<Profile> getProfiles() {
ArrayList<String> list = getArrayListFromDatabase("profiles"); return getArrayListFromDatabase("profiles").stream().map(id -> new Profile(this, id)).collect(Collectors.toCollection(LinkedList::new));
return list.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) { public void ban(BanReason reason, UUID banner, String customMessage, String proof) {

View File

@ -2,7 +2,7 @@ package eu.univento.commons.player;
/** /**
* @author joethei * @author joethei
* @version 0.1 * @version 1.0
*/ */
public enum Rank { public enum Rank {

View File

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

View File

@ -1,8 +1,11 @@
package eu.univento.commons.player.uuid; package eu.univento.commons.player.uuid;
import eu.univento.commons.Commons;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
@ -23,12 +26,11 @@ public class NameFetcher {
JSONObject response = (JSONObject) jsonParser.parse(new InputStreamReader(connection.getInputStream())); JSONObject response = (JSONObject) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
String uniqueId = (String) response.get("uuid"); String uniqueId = (String) response.get("uuid");
if (uniqueId.length() == 0) { 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?"); 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"); return (String) response.get("username");
} catch (Exception e) { } catch (IOException |ParseException e) {
return callMojang(uuid); return callMojang(uuid);
} }
} }
@ -39,19 +41,20 @@ public class NameFetcher {
JSONObject response = (JSONObject) jsonParser.parse(new InputStreamReader(connection.getInputStream())); JSONObject response = (JSONObject) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
String name = (String) response.get("name"); String name = (String) response.get("name");
if (name == null) { if (name == null)
throw new IllegalArgumentException("A Username for UUID '" + uuid.toString() + "' was not found in the Mojang database! Is the account not premium?"); 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 cause = (String) response.get("cause");
String errorMessage = (String) response.get("errorMessage"); String errorMessage = (String) response.get("errorMessage");
if (cause != null && cause.length() > 0) { if (cause != null && cause.length() > 0) {
throw new IllegalStateException(errorMessage); Commons.getCommons().getLoggingHandler().getCommons().error(errorMessage);
} }
return name; return name;
} catch (Exception e) { } catch (IOException | ParseException e) {
throw new IllegalArgumentException("A Username for UUID '" + uuid.toString() + "' was not found in the Mojang database! Is the account not premium?"); 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) { private static String fromUniqueId(UUID uuid) {

View File

@ -30,7 +30,7 @@ public class UUIDFetcher {
String name = (String) response.get("username"); String name = (String) response.get("username");
if (name.length() == 0) { 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")); return fromString((String) response.get("uuid"));
@ -53,7 +53,7 @@ public class UUIDFetcher {
} }
return fromString(uuid); return fromString(uuid);
} catch (Exception e) { } 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?");
} }
} }

View File

@ -1,13 +1,19 @@
package eu.univento.commons.player.warn; package eu.univento.commons.player.warn;
import lombok.Getter;
/** /**
* @author joethei * @author joethei
* @version 0.1 * @version 0.1
*/ */
public enum WarnReason {
@Getter
public enum WarnReason{
COPYRIGHT("Copyright", 100), COPYRIGHT("Copyright", 100),
ADVERTISEMENT("Advertisement", 10), ADVERTISEMENT("Advertisement", 10),
SPAM("Spamming", 10); SPAM("Spamming", 10),
WDL("WorldDownloader", 20),
SQUIDHQ("SquidHQ", 50);
private String name; private String name;
private int value; private int value;
@ -16,12 +22,4 @@ public enum WarnReason {
this.name = name; this.name = name;
this.value = value; this.value = value;
} }
public String getName() {
return name;
}
public int getValue() {
return value;
}
} }

View File

@ -17,7 +17,11 @@ public class SecurityHandler {
private ArrayList<String> cache = new ArrayList<>(); private ArrayList<String> cache = new ArrayList<>();
//TODO: add real security
public SecurityHandler(Commons commons) { public SecurityHandler(Commons commons) {
System.out.println(System.getProperty("user.name"));
if(System.getProperty("user.name").equals("JThei")) return;
this.commons = commons; this.commons = commons;
load(resultSet -> { load(resultSet -> {
try { try {
@ -32,7 +36,7 @@ public class SecurityHandler {
} }
public boolean isValidServer(String ip) { public boolean isValidServer(String ip) {
return cache.contains(ip); return System.getProperty("user.name").equals("JThei") || cache.contains(ip);
} }
private void load(Consumer<ResultSet> consumer) { private void load(Consumer<ResultSet> consumer) {

View File

@ -13,4 +13,8 @@ BoardSQL.Port = 3306
BoardSQL.Username = forum BoardSQL.Username = forum
BoardSQL.Password = 2Ogxk6$5Yvsr4*24 BoardSQL.Password = 2Ogxk6$5Yvsr4*24
BoardSQL.Database = forum 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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 Slack.hook_url = https://hooks.slack.com/services/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