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
build:
script: "mvn clean package"
script: "mvn clean package deploy"
artifacts:
name: "Commons"
paths:

View File

@ -10,11 +10,12 @@
</content>
<orderEntry type="inheritedJdk" />
<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: 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: 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.googlecode.json-simple:json-simple:1.1.1" 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: 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: 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: 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-core:2.6.2" 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>
</build>
<repositories>
<!--<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>-->
<distributionManagement>
<repository>
<id>univentoEU</id>
<url>http://dev.joethei.de:8081/repository/public/</url>
<url>http://dev.joethei.de:8081/repository/univento-repo/</url>
</repository>
</repositories>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.14.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
@ -102,9 +93,9 @@
<version>2.4.5</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.0.36.Final</version>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
@ -131,15 +122,20 @@
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.4</version>
</dependency>
<dependency>
<groupId>com.github.theholywaffle</groupId>
<artifactId>teamspeak3-api</artifactId>
<version>1.0.13</version>
<groupId>com.github.TheHolyWaffle</groupId>
<artifactId>TeamSpeak-3-Java-API</artifactId>
<version>v1.0.13</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>

View File

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

View File

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

View File

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

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.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<Profile> getProfiles() {
ArrayList<String> 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) {

View File

@ -2,7 +2,7 @@ package eu.univento.commons.player;
/**
* @author joethei
* @version 0.1
* @version 1.0
*/
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;
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) {

View File

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

View File

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

View File

@ -17,7 +17,11 @@ public class SecurityHandler {
private ArrayList<String> 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<ResultSet> consumer) {

View File

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