From 68b0a885ba1a4ba68b0d30ff976ceea70654cb64 Mon Sep 17 00:00:00 2001 From: Martin <ms618@hdm-stuttgart.de> Date: Sun, 17 Dec 2023 18:03:40 +0100 Subject: [PATCH] Add: communityMaps.json Add: playerStats.json Add: OracleDB.java (OracleDB communication added) Update: AzureDB.java (Methods changed) Update: DDL Script (optimised for OracleDB) Update: GsonHandler.java (removed instance of "Persistence" Singleton as attribute Update: module-info.java (added lines for OracleDB) Update: Persistence.java (added methods for loading and saving data) Update: pom.xml (added OracleDB as dependency) Update: RuntimeInfo.java (added methods for analysing and utilizing data from persistence) Update: MapData.java (changed attributes) --- .idea/sqldialects.xml | 2 +- pom.xml | 6 + .../battlearena/Exceptions/DatabaseError.java | 12 + .../battlearena/Exceptions/ParserError.java | 12 - .../Persistance/Classes/AzureDB.java | 211 +++++------------- .../Persistance/Classes/DBalt.java | 191 ++++++++++++++++ .../Persistance/Classes/GsonHandler.java | 19 +- .../Persistance/Classes/IDataBase.java | 38 +--- .../Persistance/Classes/IDataBasealt.java | 42 ++++ .../Persistance/Classes/MapData.java | 60 +---- .../Persistance/Classes/OracleDB.java | 139 ++++++++++++ .../Persistance/Classes/Persistence.java | 70 ++++-- .../Persistance/Classes/PlayerStatistics.java | 1 - .../Persistance/Classes/RuntimeInfo.java | 62 +++-- .../Persistance/Scripts/DDL_Script.sql | 69 ++++-- src/main/java/module-info.java | 2 + src/main/resources/maps/communityMaps.json | 0 src/main/resources/maps/coreMaps.json | 16 ++ src/main/resources/maps/localMaps.json | 14 -- src/main/resources/player/playerStats.json | 0 20 files changed, 637 insertions(+), 329 deletions(-) create mode 100644 src/main/java/de/hdm_stuttgart/battlearena/Exceptions/DatabaseError.java delete mode 100644 src/main/java/de/hdm_stuttgart/battlearena/Exceptions/ParserError.java create mode 100644 src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/DBalt.java create mode 100644 src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/IDataBasealt.java create mode 100644 src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/OracleDB.java create mode 100644 src/main/resources/maps/communityMaps.json create mode 100644 src/main/resources/maps/coreMaps.json delete mode 100644 src/main/resources/maps/localMaps.json create mode 100644 src/main/resources/player/playerStats.json diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml index f07b3a85..1a51ae13 100644 --- a/.idea/sqldialects.xml +++ b/.idea/sqldialects.xml @@ -5,6 +5,6 @@ <file url="PROJECT" dialect="AZURE" /> </component> <component name="SqlResolveMappings"> - <file url="file://$PROJECT_DIR$/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/AzureDB.java" scope="{"node":{ "@negative":"1", "group":{ "@kind":"root", "node":{ "@negative":"1" } } }}" /> + <file url="file://$PROJECT_DIR$/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/DBalt.java" scope="{"node":{ "@negative":"1", "group":{ "@kind":"root", "node":{ "@negative":"1" } } }}" /> </component> </project> \ No newline at end of file diff --git a/pom.xml b/pom.xml index f9950c34..36eb916d 100644 --- a/pom.xml +++ b/pom.xml @@ -51,6 +51,12 @@ <version>19.0.2.1</version> </dependency> + <dependency> + <groupId>com.oracle.database.jdbc</groupId> + <artifactId>ojdbc11</artifactId> + <version>23.3.0.23.09</version> + </dependency> + <dependency> <groupId>com.microsoft.sqlserver</groupId> <artifactId>mssql-jdbc</artifactId> diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Exceptions/DatabaseError.java b/src/main/java/de/hdm_stuttgart/battlearena/Exceptions/DatabaseError.java new file mode 100644 index 00000000..3c2e9535 --- /dev/null +++ b/src/main/java/de/hdm_stuttgart/battlearena/Exceptions/DatabaseError.java @@ -0,0 +1,12 @@ +package de.hdm_stuttgart.battlearena.Exceptions; + +public class DatabaseError extends Exception{ + + public DatabaseError() {} + + public DatabaseError(String message2) + { + super(message2); + } + +} diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Exceptions/ParserError.java b/src/main/java/de/hdm_stuttgart/battlearena/Exceptions/ParserError.java deleted file mode 100644 index 0516d22c..00000000 --- a/src/main/java/de/hdm_stuttgart/battlearena/Exceptions/ParserError.java +++ /dev/null @@ -1,12 +0,0 @@ -package de.hdm_stuttgart.battlearena.Exceptions; - -public class ParserError extends Exception{ - - public ParserError() {} - - public ParserError(String message2) - { - super(message2); - } - -} diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/AzureDB.java b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/AzureDB.java index 96f9f2f1..7fca7c40 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/AzureDB.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/AzureDB.java @@ -1,189 +1,84 @@ package de.hdm_stuttgart.battlearena.Persistance.Classes; -import org.apache.logging.log4j.Logger; +import de.hdm_stuttgart.battlearena.Exceptions.DatabaseError; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.ArrayList; -import java.io.IOException; -import java.util.LinkedHashMap; -import java.util.Properties; -import java.sql.*; - -public class AzureDB implements IDataBase { +public class AzureDB implements IDataBase{ - private static final Logger log = LogManager.getLogger(AzureDB.class); + /*this class is only here for showcasing the interchangeability of the DBMS*/ + private static final Logger log = LogManager.getLogger(OracleDB.class); @Override - public Connection connect() throws IOException, SQLException { - - log.info("Loading the properties File!"); - Properties properties = new Properties(); - properties.load(getClass().getClassLoader().getResourceAsStream("config.properties")); + public Connection connect() throws DatabaseError { + try { + String url = "jdbc:sqlserver://battlearena.database.windows.net;encrypt=true;user=battleArenaAdmin;password=krassesRPGGame23#;databaseName=battleArena;"; - log.info("Connecting to the database!"); - Connection connection = DriverManager.getConnection(properties.getProperty("url"), properties.getProperty("user"), properties.getProperty("password")); - log.info("Database connection test" + connection.getCatalog()); - - connection.setAutoCommit(true); - - return connection; - } + log.info("Connecting to the database!"); + Connection connection = DriverManager.getConnection(url); + log.info("Database connection test" + connection.getCatalog()); + connection.setAutoCommit(true); - @Override - public void createNewPlayer(String playerName) throws SQLException, IOException { - try(Connection connection = connect()) { - String sql = "INSERT INTO players (player_name, games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time)" + "VALUES (?,?,?,?,?,?,?)"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, playerName); - preparedStatement.setInt(2, 0); - preparedStatement.setInt(3, 0); - preparedStatement.setInt(4, 0); - preparedStatement.setInt(5, 0); - preparedStatement.setInt(6, 0); - preparedStatement.setInt(7, 0); - - log.info("Inserting new player"); - preparedStatement.execute(); + return connection; } - } - - @Override - public void createMap(String name, int length, int width, String mapData) throws SQLException, IOException { - try(Connection connection = connect()) { - String mapSize = length + "X" + width; - - String sql = "INSERT INTO battleArena.dbo.maps (map_name, map_size, map_data, map_version, map_hash) VALUES(?,?,?,?,?)"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, name); - preparedStatement.setString(2, mapSize); - preparedStatement.setString(3, mapData); - - log.info("Inserting new map"); - preparedStatement.execute(); + catch(Exception e){ + log.error(e); + throw new DatabaseError("SQL Connection Error"); } } @Override - public LinkedHashMap<String, String> getMapNames() throws SQLException, IOException { - LinkedHashMap<String, String> mapNames = new LinkedHashMap<>(); - + public ArrayList<MapData> getCoreMaps() throws DatabaseError{ try(Connection connection = connect()) { - String sql = "SELECT maps.map_id, maps.map_name FROM maps"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - ResultSet results = preparedStatement.executeQuery(); - log.info("Getting map names"); - while (results.next()) { - mapNames.put(results.getString("map_id"), results.getString("map_name")); - } - connection.close(); - return mapNames; - } - } + ArrayList<MapData> newMaps = new ArrayList<MapData>(); + String sql = "SELECT * FROM CoreMaps"; + PreparedStatement stmt = connection.prepareStatement(sql); - @Override - public String getMapByID(String ID) throws SQLException, IOException { - try(Connection connection = connect()) { - String sql = "SELECT map_name FROM maps WHERE map_id = ?"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, ID); - log.info("Getting Map..."); - String map = preparedStatement.executeQuery().toString(); - return map; - } - } + log.info("Sending SQL statement"); + ResultSet rs = stmt.executeQuery(); - @Override - public String getMapSizeByID(String ID) throws SQLException, IOException { - try(Connection connection = connect()) { - String sql = "SELECT map_size FROM maps WHERE battleArena.dbo.maps.map_id=?"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, ID); - ResultSet result = preparedStatement.executeQuery(); - log.info("getting map size..."); - String mapSize = result.getString("map_size"); - return mapSize; + while(rs.next()){ + newMaps.add(new MapData(rs.getString("map_id"), rs.getString("map_name"), rs.getInt("map_width"), rs.getInt("map_height"), rs.getString("map_data"))); + } + log.info("SQL query successful"); + rs.close(); + stmt.close(); + return newMaps; } - } - - @Override - public ResultSet getStatistics(String playerName) throws SQLException, IOException { - try(Connection connection = connect()){ - String sql = "SELECT * FROM players where player_name = ?"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, playerName); - ResultSet resultSet = preparedStatement.executeQuery(); - log.info("getting statistics..."); - return resultSet; + catch(Exception e){ + log.error(e); + throw new DatabaseError("Error retrieving Coremaps"); } } - @Override - public void updateMap(String mapID, String mapName, String mapData) throws SQLException, IOException { + public ArrayList<String> getCommunityMapsList() throws DatabaseError{ try(Connection connection = connect()) { - String sql = "UPDATE maps SET map_name = ?, map_data = ? WHERE map_id = ?"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, mapName); - preparedStatement.setString(2, mapData); - preparedStatement.setString(3, mapID); - preparedStatement.execute(); - log.info("updating map in Database"); - } - } + ArrayList<String> tempList = new ArrayList<String>(); + String sql = "SELECT map_name FROM CommunityMaps"; + PreparedStatement stmt = connection.prepareStatement(sql); + log.info("Sending SQL statement"); + ResultSet rs = stmt.executeQuery(); - @Override - public void updatePlayerName(String playerNameNew, String playerNameOld) throws SQLException, IOException { - try(Connection connection = connect()){ - String sql = "UPDATE players SET player_name = ? WHERE player_name = ?"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, playerNameNew); - preparedStatement.setString(2, playerNameOld); - preparedStatement.execute(); - log.info("updating player name in Database..."); - } - } - - @Override - public void updatePlayerStatistics(String playerName, int gamesWon, int gamesLost, int kills, int deaths, int blocksDestroyed, int gameTime) throws SQLException, IOException { - try (Connection connection = connect()){ - String sql = "UPDATE players SET games_won = ?, games_lost = ?, kills = ?, " + "deaths = ?, blocks_destroyed = ?, ingame_time = ? WHERE player_name = ?"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setInt(1, gamesWon); - preparedStatement.setInt(2, gamesLost); - preparedStatement.setInt(3, kills); - preparedStatement.setInt(4, deaths); - preparedStatement.setInt(5, blocksDestroyed); - preparedStatement.setInt(6, gameTime); - preparedStatement.setString(7, playerName); - preparedStatement.execute(); - log.info("updating player statistics"); - - } - } - - - @Override - public void deletePlayer(String playerName) throws IOException, SQLException { - try(Connection connection = connect()) { - String sql = "DELETE FROM players WHERE player_name=?"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, playerName); - preparedStatement.execute(); - log.info("deleting player"); - + while(rs.next()){ + tempList.add(rs.getString("map_name")); + } + log.info("SQL query successful"); + rs.close(); + stmt.close(); + return tempList; } - } - - @Override - public void deleteMap(String mapID) throws SQLException, IOException { - try(Connection connection = connect()) { - String sql = "DELETE * FROM maps WHERE map_id = ?"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, mapID); - preparedStatement.execute(); - log.info("deleting map..."); + catch(Exception e){ + log.error(e); + throw new DatabaseError("Error retrieving MapList"); } } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/DBalt.java b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/DBalt.java new file mode 100644 index 00000000..ddb1c2ba --- /dev/null +++ b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/DBalt.java @@ -0,0 +1,191 @@ +package de.hdm_stuttgart.battlearena.Persistance.Classes; + +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; + + +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.Properties; +import java.sql.*; + +public class DBalt implements IDataBasealt { + + private static final Logger log = LogManager.getLogger(DBalt.class); + + + @Override + public Connection connect() throws IOException, SQLException { + + log.info("Loading the properties File!"); + Properties properties = new Properties(); + properties.load(getClass().getClassLoader().getResourceAsStream("config.properties")); + + log.info("Connecting to the database!"); + Connection connection = DriverManager.getConnection(properties.getProperty("url"), properties.getProperty("user"), properties.getProperty("password")); + log.info("Database connection test" + connection.getCatalog()); + + connection.setAutoCommit(true); + + return connection; + } + + + @Override + public void createNewPlayer(String playerName) throws SQLException, IOException { + try(Connection connection = connect()) { + String sql = "INSERT INTO players (player_name, games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time)" + "VALUES (?,?,?,?,?,?,?)"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, playerName); + preparedStatement.setInt(2, 0); + preparedStatement.setInt(3, 0); + preparedStatement.setInt(4, 0); + preparedStatement.setInt(5, 0); + preparedStatement.setInt(6, 0); + preparedStatement.setInt(7, 0); + + log.info("Inserting new player"); + preparedStatement.execute(); + } + } + + @Override + public void createMap(String name, int length, int width, String mapData) throws SQLException, IOException { + try(Connection connection = connect()) { + String mapSize = length + "X" + width; + + String sql = "INSERT INTO battleArena.dbo.maps (map_name, map_size, map_data, map_version, map_hash) VALUES(?,?,?,?,?)"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, name); + preparedStatement.setString(2, mapSize); + preparedStatement.setString(3, mapData); + + log.info("Inserting new map"); + preparedStatement.execute(); + } + } + + @Override + public LinkedHashMap<String, String> getMapNames() throws SQLException, IOException { + LinkedHashMap<String, String> mapNames = new LinkedHashMap<>(); + + try(Connection connection = connect()) { + String sql = "SELECT maps.map_id, maps.map_name FROM maps"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + ResultSet results = preparedStatement.executeQuery(); + log.info("Getting map names"); + while (results.next()) { + mapNames.put(results.getString("map_id"), results.getString("map_name")); + } + connection.close(); + return mapNames; + } + } + + @Override + public String getMapByID(String ID) throws SQLException, IOException { + try(Connection connection = connect()) { + String sql = "SELECT map_name FROM maps WHERE map_id = ?"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, ID); + log.info("Getting Map..."); + String map = preparedStatement.executeQuery().toString(); + return map; + } + } + + @Override + public String getMapSizeByID(String ID) throws SQLException, IOException { + try(Connection connection = connect()) { + String sql = "SELECT map_size FROM maps WHERE battleArena.dbo.maps.map_id=?"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, ID); + ResultSet result = preparedStatement.executeQuery(); + log.info("getting map size..."); + String mapSize = result.getString("map_size"); + return mapSize; + } + } + + @Override + public ResultSet getStatistics(String playerName) throws SQLException, IOException { + try(Connection connection = connect()){ + String sql = "SELECT * FROM players where player_name = ?"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, playerName); + ResultSet resultSet = preparedStatement.executeQuery(); + log.info("getting statistics..."); + return resultSet; + } + } + + @Override + public void updateMap(String mapID, String mapName, String mapData) throws SQLException, IOException { + try(Connection connection = connect()) { + String sql = "UPDATE maps SET map_name = ?, map_data = ? WHERE map_id = ?"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, mapName); + preparedStatement.setString(2, mapData); + preparedStatement.setString(3, mapID); + preparedStatement.execute(); + log.info("updating map in Database"); + } + } + + + @Override + public void updatePlayerName(String playerNameNew, String playerNameOld) throws SQLException, IOException { + try(Connection connection = connect()){ + String sql = "UPDATE players SET player_name = ? WHERE player_name = ?"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, playerNameNew); + preparedStatement.setString(2, playerNameOld); + preparedStatement.execute(); + log.info("updating player name in Database..."); + } + } + + @Override + public void updatePlayerStatistics(String playerName, int gamesWon, int gamesLost, int kills, int deaths, int blocksDestroyed, int gameTime) throws SQLException, IOException { + try (Connection connection = connect()){ + String sql = "UPDATE players SET games_won = ?, games_lost = ?, kills = ?, " + "deaths = ?, blocks_destroyed = ?, ingame_time = ? WHERE player_name = ?"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setInt(1, gamesWon); + preparedStatement.setInt(2, gamesLost); + preparedStatement.setInt(3, kills); + preparedStatement.setInt(4, deaths); + preparedStatement.setInt(5, blocksDestroyed); + preparedStatement.setInt(6, gameTime); + preparedStatement.setString(7, playerName); + preparedStatement.execute(); + log.info("updating player statistics"); + + } + } + + + @Override + public void deletePlayer(String playerName) throws IOException, SQLException { + try(Connection connection = connect()) { + String sql = "DELETE FROM players WHERE player_name=?"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, playerName); + preparedStatement.execute(); + log.info("deleting player"); + + } + } + + @Override + public void deleteMap(String mapID) throws SQLException, IOException { + try(Connection connection = connect()) { + String sql = "DELETE * FROM maps WHERE map_id = ?"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, mapID); + preparedStatement.execute(); + log.info("deleting map..."); + } + } + + +} diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/GsonHandler.java b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/GsonHandler.java index 76962674..f0ae2281 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/GsonHandler.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/GsonHandler.java @@ -1,7 +1,9 @@ package de.hdm_stuttgart.battlearena.Persistance.Classes; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; +import de.hdm_stuttgart.battlearena.Exceptions.DatabaseError; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -11,13 +13,13 @@ import java.lang.reflect.Type; import java.util.ArrayList; public class GsonHandler { - Gson gson = new Gson(); + Gson gson = new GsonBuilder().setPrettyPrinting().create(); private static final Logger log = LogManager.getLogger(GsonHandler.class); Type mapDataType = new TypeToken<ArrayList<MapData>>(){}.getType(); - public ArrayList<MapData> loadMaps() throws RuntimeException{ - try (FileReader reader = new FileReader("src/main/resources/maps/localMaps.json")) { + public ArrayList<MapData> loadMaps(String filePath) throws DatabaseError{ + try (FileReader reader = new FileReader(filePath)) { ArrayList<MapData> maps = new ArrayList<MapData>(); maps = gson.fromJson(reader, mapDataType); log.info("GSON - Maps successfully loaded from JSON"); @@ -25,18 +27,19 @@ public class GsonHandler { } catch (Exception e) { log.info(e); log.info("GSON - Loading Maps from JSON failed"); - throw new RuntimeException("Error Loading Maps!"); + throw new DatabaseError("Error Loading Maps!"); } } - public void updateMaps(ArrayList<MapData> maps) { - try (FileWriter writer = new FileWriter("src/main/resources/maps/localMaps.json")) { + public void saveMaps(ArrayList<MapData> maps, String filePath) throws DatabaseError{ + try (FileWriter writer = new FileWriter(filePath)) { gson.toJson(maps, writer); - log.info("GSON - Maps successfully written to JSON"); + log.info("GSON - Maps successfully saved to JSON"); } catch ( Exception e) { log.info(e); - log.info("GSON - Saving SingleBookings to JSON failed"); + log.info("GSON - Saving Maps to JSON failed"); + throw new DatabaseError("Error Loading Maps!"); } } } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/IDataBase.java b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/IDataBase.java index 3f325e9c..cab1ba14 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/IDataBase.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/IDataBase.java @@ -1,42 +1,14 @@ package de.hdm_stuttgart.battlearena.Persistance.Classes; -import java.io.IOException; +import de.hdm_stuttgart.battlearena.Exceptions.DatabaseError; + import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.LinkedHashMap; +import java.util.ArrayList; public interface IDataBase { - //connection-Methods - Connection connect() throws IOException, SQLException; - - - //CRUD Operations - - //Create Operations - void createNewPlayer(String playerName) throws SQLException, IOException; - - void createMap(String name, int length, int width, String mapData) throws SQLException, IOException; - - //Read-operations - LinkedHashMap<String, String> getMapNames() throws SQLException, IOException; - String getMapByID(String ID) throws SQLException, IOException; - String getMapSizeByID(String ID) throws SQLException, IOException; - - - - ResultSet getStatistics(String playerName) throws SQLException, IOException; - - //Update-operations - void updateMap(String mapID , String mapName, String mapData) throws SQLException, IOException; - - void updatePlayerName(String playerNameNew, String PlayerNameOld) throws SQLException, IOException; - - void updatePlayerStatistics(String playerName, int gamesWon, int gamesLost, int kills, int deaths, int blocksDestroyed, int gameTime) throws SQLException, IOException; + Connection connect() throws DatabaseError; + ArrayList<MapData> getCoreMaps() throws DatabaseError; - //Delete-operations - void deletePlayer(String playerName) throws IOException, SQLException; - void deleteMap(String mapID) throws SQLException, IOException; } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/IDataBasealt.java b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/IDataBasealt.java new file mode 100644 index 00000000..fbd43943 --- /dev/null +++ b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/IDataBasealt.java @@ -0,0 +1,42 @@ +package de.hdm_stuttgart.battlearena.Persistance.Classes; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.LinkedHashMap; + +public interface IDataBasealt { + + //connection-Methods + Connection connect() throws IOException, SQLException; + + + //CRUD Operations + + //Create Operations + void createNewPlayer(String playerName) throws SQLException, IOException; + + void createMap(String name, int length, int width, String mapData) throws SQLException, IOException; + + //Read-operations + LinkedHashMap<String, String> getMapNames() throws SQLException, IOException; + String getMapByID(String ID) throws SQLException, IOException; + String getMapSizeByID(String ID) throws SQLException, IOException; + + + + ResultSet getStatistics(String playerName) throws SQLException, IOException; + + //Update-operations + void updateMap(String mapID , String mapName, String mapData) throws SQLException, IOException; + + void updatePlayerName(String playerNameNew, String PlayerNameOld) throws SQLException, IOException; + + void updatePlayerStatistics(String playerName, int gamesWon, int gamesLost, int kills, int deaths, int blocksDestroyed, int gameTime) throws SQLException, IOException; + + + //Delete-operations + void deletePlayer(String playerName) throws IOException, SQLException; + void deleteMap(String mapID) throws SQLException, IOException; +} diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/MapData.java b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/MapData.java index d24c8bc9..d395c69f 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/MapData.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/MapData.java @@ -1,6 +1,5 @@ package de.hdm_stuttgart.battlearena.Persistance.Classes; -import de.hdm_stuttgart.battlearena.Exceptions.ParserError; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -9,20 +8,20 @@ public class MapData { private String mapID; private String mapName; - private int mapHeight; private int mapWidth; + private int mapHeight; private String mapData; - protected MapData(String mapID, String mapName, String mapSize, String mapData) { + protected MapData(String mapID, String mapName, int mapWidth, int mapHeight, String mapData) { try { this.mapID = mapID; this.mapName = mapName; + this.mapWidth = mapWidth; + this.mapHeight = mapHeight; this.mapData = mapData; - - sizeParser(mapSize); } - catch (Exception ParserError){ - log.error(ParserError); + catch (Exception e){ + log.error(e); } } @@ -34,55 +33,16 @@ public class MapData { return mapName; } - public int getMapHeight() { - return mapHeight; - } - public int getMapWidth() { return mapWidth; } + public int getMapHeight() { + return mapHeight; + } + public String getMapData() { return mapData; } - private void sizeParser(String mapSize) throws ParserError { - try { - if (mapSize.length() < 3) { - throw new ParserError("Incomplete data"); - } - - if (mapSize.length() % 2 == 0) { - throw new ParserError("Width and height don't match!"); - } - - boolean noX = true; - for (int i = 0; i < mapSize.length(); i++) { - if (mapSize.charAt(i) == 'x' | mapSize.charAt(i) == 'X') { - noX = false; - break; - } - } - if (noX) { - throw new ParserError("X divider missing!"); - } - - int whereX = 0; - for (int i = 0; i < mapSize.length(); i++) { - if (mapSize.charAt(i) == 'x' | mapSize.charAt(i) == 'X') { - whereX = i; - break; - } - } - - mapHeight = Integer.parseInt(mapSize.substring(0, whereX)); - mapWidth = Integer.parseInt(mapSize.substring(whereX)); - - } - catch (Exception e){ - log.error(e); - throw new ParserError("Parser error!"); - } - - } } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/OracleDB.java b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/OracleDB.java new file mode 100644 index 00000000..363c42bc --- /dev/null +++ b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/OracleDB.java @@ -0,0 +1,139 @@ +package de.hdm_stuttgart.battlearena.Persistance.Classes; + +import de.hdm_stuttgart.battlearena.Exceptions.DatabaseError; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.sql.*; +import java.util.ArrayList; +import java.util.Properties; + +import oracle.jdbc.pool.OracleDataSource; +import oracle.jdbc.OracleConnection; + +public class OracleDB implements IDataBase { + + private static final Logger log = LogManager.getLogger(OracleDB.class); + @Override + public Connection connect() throws DatabaseError{ + try { + OracleDataSource ods = new OracleDataSource(); + ods.setURL("jdbc:oracle:thin:@(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=adb.eu-frankfurt-1.oraclecloud.com))(connect_data=(service_name=g093caf2cf1fea4_battlearena_high.adb.oraclecloud.com))(security=(ssl_server_dn_match=yes)))"); + ods.setUser("battlearenaplayer"); + ods.setPassword("jo3+++w3rw+s##AA"); + Connection conn = ods.getConnection(); + + log.info("Connecting to the database!"); + + return conn; + } + catch(Exception e){ + log.error(e); + throw new DatabaseError("SQL connection error"); + } + } + + @Override + public ArrayList<MapData> getCoreMaps() throws DatabaseError{ + try(Connection connection = connect()) { + ArrayList<MapData> newMaps = new ArrayList<MapData>(); + String sql = "SELECT * FROM battlearenadata.coremaps"; + PreparedStatement stmt = connection.prepareStatement(sql); + + log.info("Sending SQL statement"); + ResultSet rs = stmt.executeQuery(); + + while(rs.next()){ + newMaps.add(new MapData(rs.getString("map_id"), rs.getString("map_name"), rs.getInt("map_width"), rs.getInt("map_height"), rs.getString("map_data"))); + } + rs.close(); + stmt.close(); + log.info("Coremaps retrieved successfully"); + return newMaps; + } + catch(Exception e){ + log.error(e); + throw new DatabaseError("Error retrieving coremaps"); + } + } + + public ArrayList<String> getCommunityMapsList() throws DatabaseError{ + try(Connection connection = connect()) { + ArrayList<String> tempList = new ArrayList<String>(); + String sql = "SELECT map_name FROM battlearenadata.communitymaps"; + PreparedStatement stmt = connection.prepareStatement(sql); + + log.info("Sending SQL statement"); + ResultSet rs = stmt.executeQuery(); + + while(rs.next()){ + tempList.add(rs.getString("map_name")); + } + rs.close(); + stmt.close(); + log.info("Community map names retrieved successfully"); + return tempList; + } + catch(Exception e){ + log.error(e); + throw new DatabaseError("Error retrieving community map names"); + } + } + + public MapData getCommunityMapByID(String mapID) throws DatabaseError{ + try(Connection connection = connect()) { + String sql = "SELECT * FROM battlearenadata.communitymaps WHERE map_ID = ?"; + PreparedStatement stmt = connection.prepareStatement(sql); + stmt.setString(1, mapID); + + log.info("Sending SQL statement"); + ResultSet rs = stmt.executeQuery(); + + MapData mapChosen = new MapData(rs.getString("map_id"), rs.getString("map_name"), rs.getInt("map_width"), rs.getInt("map_height"), rs.getString("map_data")); + + rs.close(); + stmt.close(); + log.info("Community map retrieved successfully"); + return mapChosen; + } + catch(Exception e){ + log.error(e); + throw new DatabaseError("Error retrieving community map"); + } + } + + public void uploadCommunityMapByID(MapData map) throws DatabaseError{ + try(Connection connection = connect()) { + String sql = "INSERT INTO battlearenadata.communitymaps (map_id, map_name, map_width, map_height, map_data) VALUES (?, ?, ?, ?, ?)"; + PreparedStatement stmt = connection.prepareStatement(sql); + stmt.setString(1, map.getMapID()); + stmt.setString(2, map.getMapName()); + stmt.setInt(3, map.getMapWidth()); + stmt.setInt(4, map.getMapHeight()); + stmt.setString(5, map.getMapData()); + + log.info("Sending SQL statement"); + stmt.executeQuery(); + + stmt.close(); + log.info("Community Map retrieved successfully"); + } + catch(Exception e){ + log.error(e); + throw new DatabaseError("Error uploading created community map"); + } + } + +/* + public void createCommunityMap(Persistence persistence){ + //try to insert new entry in CommunityMaps Table - if check by unique-id fails, error message that map already exists! + //make hash of madata before trying to insert + //save data in communityMaps Arraylist + } + + public void updateCommunityStats(Persistence persistence){ + //Update the commulative Stats + } +*/ + +} diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/Persistence.java b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/Persistence.java index d9dc0682..f2a4fe12 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/Persistence.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/Persistence.java @@ -5,47 +5,83 @@ import org.apache.logging.log4j.LogManager; import java.sql.Connection; import java.util.ArrayList; -import java.util.LinkedHashMap; public class Persistence { private static final Logger log = LogManager.getLogger(Persistence.class); - private static final Persistence persistence = new Persistence(); - private GsonHandler gsonHandler = new GsonHandler(); - private AzureDB sqlHandler = new AzureDB(); + private static final Persistence persistenceSingleton = new Persistence(); + private final GsonHandler gsonHandler = new GsonHandler(); + private final DBalt sqlHandler = new DBalt(); //?? private Connection connection; //?? - protected ArrayList<MapData> maps; + protected ArrayList<MapData> coreMaps; + protected ArrayList<MapData> communityMaps; + private final String filePathCoreMaps = "src/main/resources/maps/coreMaps.json"; + private final String filePathCommunityMaps = "src/main/resources/maps/communityMaps.json"; private int[] sizeArrayInt; //?? private String sizeString; //?? protected static PlayerStatistics statistics = new PlayerStatistics("", 0,0,0,0,0,0); + //suggestion: rename to "playerData" - - + OracleDB db = new OracleDB(); //for testing purposes; evtl. Methoden von OracleDB static machen und von GSON Handler private Persistence (){} - public void createPlayer(String player){ - statistics.setPlayerName(player); + public static Persistence getInstance(){ + return persistenceSingleton; + } + public void loadCoreMaps(){ + try { + coreMaps = gsonHandler.loadMaps(filePathCoreMaps); + log.info("Maps successfully loaded from file"); + //log.info(coreMaps.get(0).getMapName()); //for testing purposes + } + catch(Exception e){ + log.error(e); + } } - public static Persistence getInstance(){ - return persistence; + public void updateCoreMaps(){ + try { + coreMaps = db.getCoreMaps(); + gsonHandler.saveMaps(coreMaps, filePathCoreMaps); + log.info("Maps successfully updated from SQL-Server"); + //log.info(coreMaps.get(0).getMapName()); //for testing purposes + } + catch(Exception e){ + log.error(e); + } + } + + public void getCommunityMap(String mapSelected){ + try { + communityMaps.add(db.getCommunityMapByID(mapSelected)); + gsonHandler.saveMaps(communityMaps, filePathCommunityMaps); + log.info("Community Map successfully retrieved from SQL-Server!"); + } + catch(Exception e){ + log.error(e); + } } - public void updateMaps(){ - //load maps from SQL and put them into "maps" ArrayList and JSON File (using "updateMaps" Method from "GsonHandler") - //connect this method to button "Update Maps" in Controller from "? Scene" + public void uploadCommunityMap(MapData map){ + try { + db.uploadCommunityMapByID(map); + communityMaps.add(map); //hier noch prüfen, ob die Map lokal bereits existiert (falls eine Verbindung zur DB scheitern sollte, kann man sie dennoch lokal speichern + gsonHandler.saveMaps(communityMaps, filePathCommunityMaps); + log.info("Maps successfully updated from SQL-Server!"); + } + catch(Exception e){ + log.error(e); + } } - public void loadMaps(){ - maps = gsonHandler.loadMaps(); + public void createPlayer (){ } public void loadStatistics(){ - //load Statistics from SQL into instance "statistics" of class "PlayerStatistics" } } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/PlayerStatistics.java b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/PlayerStatistics.java index bd1b087b..fc462051 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/PlayerStatistics.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/PlayerStatistics.java @@ -6,7 +6,6 @@ import org.apache.logging.log4j.LogManager; public class PlayerStatistics { private static final Logger log = LogManager.getLogger(PlayerStatistics.class); - private String playerID; private String playerName; private int gamesLost; private int gamesWon; diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/RuntimeInfo.java b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/RuntimeInfo.java index 509453c6..c37c7409 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/RuntimeInfo.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/RuntimeInfo.java @@ -3,42 +3,76 @@ package de.hdm_stuttgart.battlearena.Persistance.Classes; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.ArrayList; import java.util.LinkedHashMap; public class RuntimeInfo { private static final Logger log = LogManager.getLogger(RuntimeInfo.class); - private static final RuntimeInfo runtimeinfo = new RuntimeInfo(); - private final Persistence persistence = Persistence.getInstance(); + private static final RuntimeInfo runtimeInfoSingleton = new RuntimeInfo(); + private final Persistence persistenceInst = Persistence.getInstance(); private LinkedHashMap<String, String> mapNames; + public MapData mapCreated; //to store parsed Data from MapCreator for Upload to SQL + public String communityMapSelected; + protected ArrayList<String> coreMapsListLocal; + protected ArrayList<String> communityMapsListLocal; + protected ArrayList<String> communityMapsListRemote; - - - private RuntimeInfo (){}; + private RuntimeInfo(){}; public static RuntimeInfo getInstance(){ - return runtimeinfo; + return runtimeInfoSingleton; } private String getMap(String mapSelected) throws RuntimeException{ - for(int i = 0; i < persistence.maps.size(); i++){ - if(persistence.maps.get(i).getMapID().equals("mapSelected")){ - return persistence.maps.get(i).getMapID(); + for(int i = 0; i < persistenceInst.coreMaps.size(); i++){ + if(persistenceInst.coreMaps.get(i).getMapID().equals("mapSelected")){ + return persistenceInst.coreMaps.get(i).getMapID(); } } throw new RuntimeException("no Map found"); } + public void getCommunityMap(){ + persistenceInst.getCommunityMap(communityMapSelected); + } + + public void uploadMapCreated(){ + persistenceInst.uploadCommunityMap(mapCreated); + } + //add Hash-Creator for creating map_ID and parse if map_data is according to specs + private void updateStats(String outcome, String kills, String deaths, int gameTime){ //update PlayerStatistics //update SQL } - public void createMapList(){ - for(int i = 0; i < persistence.maps.size(); i++){ - //fill "mapNames" LinkedHashMap with Names from instances of "MapData" from "maps" ArrayList - //include exception for if "maps" is empty - //call method a program start + public void createCoreMapsList(){ + for(int i = 0; i < persistenceInst.coreMaps.size(); i++){ + coreMapsListLocal.add(persistenceInst.coreMaps.get(i).getMapName()); + } + } + + public void createCommunityMapsListLocal(){ + try { + for (int i = 0; i < persistenceInst.communityMaps.size(); i++) { + communityMapsListLocal.add(persistenceInst.communityMaps.get(i).getMapName()); + } + } + catch (Exception e){ + log.info(e); + } + } + //if no Data in JSON throw Exception and inform user + + public void fetchCommunityMapListRemote(){ + try { + communityMapsListRemote = persistenceInst.db.getCommunityMapsList(); + log.info("MapList successfully retrieved from server!"); + log.info(communityMapsListRemote.get(0)); //for testing purposes + } + catch(Exception e){ + log.error(e); } } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Scripts/DDL_Script.sql b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Scripts/DDL_Script.sql index 20052896..aab3ddae 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Scripts/DDL_Script.sql +++ b/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Scripts/DDL_Script.sql @@ -1,21 +1,48 @@ -DROP TABLE maps; -DROP TABLE players; - - -CREATE TABLE maps( - map_id uniqueidentifier NOT NULL DEFAULT newid(), - map_name VARCHAR(30) NOT NULL, - map_size VARCHAR(6) NOT NULL, - map_data VARCHAR(1369) NOT NULL, -- Calculated With max. column range 18X18 -); - -CREATE TABLE players( - player_id uniqueidentifier NOT NULL DEFAULT newid(), - player_name VARCHAR(30) NOT NULL, - games_won INTEGER NOT NULL, - games_lost INTEGER NOT NULL, - kills INTEGER NOT NULL, - deaths INTEGER NOT NULL, - blocks_destroyed INTEGER NOT NULL, - ingame_time INTEGER NOT NULL -); \ No newline at end of file +--Note: DDL to be run as admin on OracleDB; Passwords for user accounts are not included and must be inserted before execution + +DROP TABLE battlearenadata.coremaps; +DROP TABLE battlearenadata.communitymaps; + +DROP USER battlearenaplayer; +DROP USER battlearenadata; + +CREATE USER battlearenaplayer IDENTIFIED BY "insertPasswordHere"; +CREATE USER battlearenadata IDENTIFIED BY "insertPasswordHere"; + +GRANT CONNECT TO battlearenaplayer; + +CREATE TABLE battlearenadata.coremaps( + map_id CHAR(40) NOT NULL UNIQUE, --SHA1 hash is 40 chars length in hex + map_name VARCHAR(30) NOT NULL, + map_width INTEGER NOT NULL, + map_height INTEGER NOT NULL, + map_data VARCHAR(1682) NOT NULL); --allows for map size up to 29x29 + +CREATE TABLE battlearenadata.communitymaps( + map_id CHAR(40) NOT NULL UNIQUE, --SHA1 hash is 40 chars length in hex + map_name VARCHAR(30) NOT NULL, + map_width INTEGER NOT NULL, + map_height INTEGER NOT NULL, + map_data VARCHAR(1682) NOT NULL); --allows for map size up to 29x29 + +ALTER USER battlearenadata QUOTA 500M ON coremaps; +ALTER USER battlearenadata QUOTA 500M ON communitymaps; + +INSERT INTO battlearenadata.coremaps (map_id, map_name, map_width, map_height, map_data) +VALUES ('a593cafd1d061f0f463a2d2051bf4718aaaf5c48', + 'Arena1', + 18, + 18, + '4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 2 1 1 1 1 1 2 2 2 1 1 1 1 2 1 1 3 4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 2 3 4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 1 2 3 4 1 1 1 2 2 4 1 3 3 3 1 1 1 3 2 2 3 4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 2 1 3 4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 1 3 4 1 1 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 1 3 4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 1 1 3 4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 2 2 3 4 1 1 1 1 1 4 3 3 1 3 3 3 3 3 1 2 3 4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 2 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3'); + +INSERT INTO battlearenadata.coremaps (map_id, map_name, map_width, map_height, map_data) +VALUES ('e559d8fbb53b333f5839cb3c6c0c515395afe344', + 'Arena2', + 18, + 18, + '4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 2 4 2 1 1 1 1 1 2 2 2 1 1 1 1 2 3 1 3 4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 2 3 4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 1 2 3 4 1 1 1 2 2 4 1 3 3 3 1 1 1 3 2 2 3 4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 2 1 3 4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 1 3 4 1 1 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 1 3 4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 1 1 3 4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 2 2 3 4 1 1 1 1 1 4 3 3 1 3 3 3 3 3 1 2 3 4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 2 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3'); + + +GRANT SELECT ON battlearenadata.coremaps TO battlearenaplayer; + +GRANT SELECT, INSERT ON battlearenadata.communitymaps TO battlearenaplayer; \ No newline at end of file diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 185f1837..e006608a 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -5,6 +5,8 @@ module gui { requires org.apache.logging.log4j; requires java.sql; requires com.google.gson; + requires com.oracle.database.jdbc; + requires java.naming; opens de.hdm_stuttgart.battlearena to javafx.fxml; exports de.hdm_stuttgart.battlearena.Main; diff --git a/src/main/resources/maps/communityMaps.json b/src/main/resources/maps/communityMaps.json new file mode 100644 index 00000000..e69de29b diff --git a/src/main/resources/maps/coreMaps.json b/src/main/resources/maps/coreMaps.json new file mode 100644 index 00000000..84828ae2 --- /dev/null +++ b/src/main/resources/maps/coreMaps.json @@ -0,0 +1,16 @@ +[ + { + "mapID": "a593cafd1d061f0f463a2d2051bf4718aaaf5c48", + "mapName": "Arena1", + "mapWidth": 18, + "mapHeight": 18, + "mapData": "4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 2 1 1 1 1 1 2 2 2 1 1 1 1 2 1 1 3 4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 2 3 4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 1 2 3 4 1 1 1 2 2 4 1 3 3 3 1 1 1 3 2 2 3 4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 2 1 3 4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 1 3 4 1 1 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 1 3 4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 1 1 3 4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 2 2 3 4 1 1 1 1 1 4 3 3 1 3 3 3 3 3 1 2 3 4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 2 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3" + }, + { + "mapID": "e559d8fbb53b333f5839cb3c6c0c515395afe344", + "mapName": "Arena2", + "mapWidth": 18, + "mapHeight": 18, + "mapData": "4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 2 4 2 1 1 1 1 1 2 2 2 1 1 1 1 2 3 1 3 4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 2 3 4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 1 2 3 4 1 1 1 2 2 4 1 3 3 3 1 1 1 3 2 2 3 4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 2 1 3 4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 1 3 4 1 1 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 1 3 4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 1 1 3 4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 2 2 3 4 1 1 1 1 1 4 3 3 1 3 3 3 3 3 1 2 3 4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 2 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3" + } +] \ No newline at end of file diff --git a/src/main/resources/maps/localMaps.json b/src/main/resources/maps/localMaps.json deleted file mode 100644 index 60a2aa12..00000000 --- a/src/main/resources/maps/localMaps.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "mapID": "a593cafd1d061f0f463a2d2051bf4718aaaf5c48", - "mapName": "Arena1", - "mapSize": "18x18", - "mapData": "4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 2 1 1 1 1 1 2 2 2 1 1 1 1 2 1 1 3 4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 2 3 4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 1 2 3 4 1 1 1 2 2 4 1 3 3 3 1 1 1 3 2 2 3 4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 2 1 3 4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 1 3 4 1 1 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 1 3 4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 1 1 3 4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 2 2 3 4 1 1 1 1 1 4 3 3 1 3 3 3 3 3 1 2 3 4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 2 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3" - }, - { - "mapID": "e559d8fbb53b333f5839cb3c6c0c515395afe344", - "mapName": "Arena2", - "mapSize": "18x18", - "mapData": "4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 2 4 2 1 1 1 1 1 2 2 2 1 1 1 1 2 3 1 3 4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 2 3 4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 1 2 3 4 1 1 1 2 2 4 1 3 3 3 1 1 1 3 2 2 3 4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 2 1 3 4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 1 3 4 1 1 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 1 3 4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 1 1 3 4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 2 2 3 4 1 1 1 1 1 4 3 3 1 3 3 3 3 3 1 2 3 4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 2 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3" - } -] \ No newline at end of file diff --git a/src/main/resources/player/playerStats.json b/src/main/resources/player/playerStats.json new file mode 100644 index 00000000..e69de29b -- GitLab