diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Persistence.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Persistence.java index 3e24e0eb7201fd59a20b9913e926f3c2029b0ff0..638529da884c6bd83ae1f34bf67c653b6c73b89e 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Persistence.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Persistence.java @@ -22,8 +22,6 @@ public class Persistence { private PlayerStatistics statistics; private PlayerAccount account; private AppSettings settings; - //protected ArrayList<String> coreMapsListLocal; //for drop-down list -- kommt eigentlich eher in RuntimeInfo - //protected ArrayList<String> communityMapsListLocal; //for drop-down list -- kommt eigentlich eher in RuntimeInfo protected ArrayList<MapInfo> communityMapsListRemote; //for community map browser @@ -172,8 +170,7 @@ public class Persistence { } } - public MapData getGameMap(String mapSelected, boolean choseCoremaps) throws DatabaseException{ - +/* public MapData getGameMap(String mapSelected, boolean choseCoremaps) throws DatabaseException{ String mapID = mapSelected.substring(mapSelected.indexOf("(") + 1, mapSelected.length() - 1); if (choseCoremaps) { for (int index = 0; index < coreMaps.size(); index++) { @@ -189,6 +186,15 @@ public class Persistence { } } throw new DatabaseException("Database error - Map not found!"); + }*/ + + public void saveSettings(){ + try{ + gsonHandler.saveSettings(settings); + } + catch(Exception e){ + log.error(e); + } } public void savePlayerStatistics() throws DatabaseException{ //on shutdown of game @@ -312,21 +318,6 @@ public class Persistence { } } - //kommen beide eigentlich eher in die RuntimeInfo -/* public void createCoreMapsList(){ //for dropdown list in "create" scene - coreMapsListLocal = new ArrayList<String>(); - for(int i = 0; i < coreMaps.size(); i++){ - coreMapsListLocal.add(coreMaps.get(i).getMapName() + " (" + coreMaps.get(i).getMapID() + ")"); - } - } - - public void createLocalCommunityMapsList(){ //for dropdown list in "create" scene - communityMapsListLocal = new ArrayList<String>(); - for (int i = 0; i < communityMaps.size(); i++) { - communityMapsListLocal.add(communityMaps.get(i).getMapName() + " (" + communityMaps.get(i).getMapID() + ")"); - } - }*/ - public void verifyPlayerAccount() throws DatabaseException { try { if (account.getAccountType() == AccountType.NONE) { @@ -340,7 +331,7 @@ public class Persistence { throw new DatabaseException("Locally stored password does not match online password. Please reenter credentials!"); } } - else{ + else{ //überflüssig, da GSON schon beim laden der Daten meckern würde, wenn er den Accounttype nicht finden kann throw new DatabaseException("AccountType invalid - accountData corrupted! Please create new Account or login with existing!"); } log.info("Player account successfully verified!"); @@ -415,13 +406,24 @@ public class Persistence { } } + public void resetPlayerAccount() throws DatabaseException{ + try{ + account = new PlayerAccount("", "", AccountType.NONE); + gsonHandler.saveAccount(account); + log.info("Player account successfully reset!"); + } + catch(Exception e){ + log.error(e); + } + } + public void resetPlayerStatistics() throws DatabaseException{ try { - verifyPlayerAccount(); if (account.getAccountType() == AccountType.LOCAL) { statistics = new PlayerStatistics(0, 0, 0, 0, 0, 0); gsonHandler.saveStats(statistics); } else if (account.getAccountType() == AccountType.ONLINE) { + verifyPlayerAccount(); db.resetPlayerStats(account); statistics = new PlayerStatistics(0, 0, 0, 0, 0, 0); } @@ -433,8 +435,8 @@ public class Persistence { } public void resetSettings(){ - settings = new AppSettings(50, 50); try { + settings = new AppSettings(50, 50); gsonHandler.saveSettings(settings); } catch(Exception e){ diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/RuntimeInfo.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/RuntimeInfo.java index bc2625856682cb2c90e56e0c5d57d8e1f602db8b..14d1a3995c5cc6e831b18324cd91f745b58bdc1b 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/RuntimeInfo.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/RuntimeInfo.java @@ -13,7 +13,6 @@ public class RuntimeInfo { private static final Logger log = LogManager.getLogger(RuntimeInfo.class); private static final RuntimeInfo runtimeInfoSingleton = new RuntimeInfo(); - private final Persistence persistenceInst = Persistence.getInstance(); private String mapDataGame; private MapData mapGame; private boolean offlineMode; //if Account-Type is online but no SQL connection: start game without stats tracking @@ -47,10 +46,10 @@ public class RuntimeInfo { } } - public void setGameMap(String mapSelected, boolean choseCoremaps){ + public void setGameMap(MapData mapSelected){ //Create Game Scene Dropdown list directly gives reference to selected map try { - mapGame = persistenceInst.getGameMap(mapSelected, choseCoremaps); - mapDataGame = mapGame.getMapData(); + mapGame = mapSelected; + mapDataGame = mapSelected.getMapData(); } catch(Exception e){ log.error(e); diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/Parser.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/Parser.java index 29639d0bbadd65532cfa8b4b99c247c36ca1f634..b7a04381a3f69ba1c3083c64986b73794d6ac51c 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/Parser.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/Parser.java @@ -78,14 +78,14 @@ public class Parser { int hashLength = 40; if(mapID.length() != hashLength){ - throw new ParserException("Map-ID length not correct. Must have length of " + hashLength + " characters!"); + throw new ParserException("SHA1 hash length not correct. Must have length of " + hashLength + " characters!"); } Pattern pat = Pattern.compile("[^a-f0-9]"); //maybe make case-insensitive -> letters can be uppercase and still be valid hex number Matcher mat = pat.matcher(mapID); boolean result = mat.find(); if(result){ - throw new ParserException("Forbidden characters used! Map ID only consists out of letters a-f and/or numbers 0-9!"); + throw new ParserException("Forbidden characters used! SHA1 hash only consists out of letters a-f and/or numbers 0-9!"); } } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Scripts/DDL_Script_AzureDB.sql b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Scripts/DDL_Script_AzureDB.sql index 3ee29cb25e3cc97a8a8f53e352dd1f90ff5a5707..bd3b7cc0344912f98142b0a01760952356a327b7 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Scripts/DDL_Script_AzureDB.sql +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Scripts/DDL_Script_AzureDB.sql @@ -64,7 +64,7 @@ VALUES ('1c23b362fd666c5fb7ed60ca611b17246424e49f', INSERT INTO players (player_name, player_pw, games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time) VALUES ('Player1', - 'password', + '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', --Hash of password "password" 18, 0, 80, @@ -74,7 +74,7 @@ VALUES ('Player1', INSERT INTO players (player_name, player_pw, games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time) VALUES ('Player2', - 'password', + '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', --Hash of password "password" 15, 3, 50, diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Scripts/DDL_Script_Oracle.sql b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Scripts/DDL_Script_Oracle.sql index 2e1959bf86f5d739a14878f45ae62ca8b2d04344..22de38024bc74b449f2ca80e2afa3cc063aea840 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Scripts/DDL_Script_Oracle.sql +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Scripts/DDL_Script_Oracle.sql @@ -73,7 +73,7 @@ VALUES ('1c23b362fd666c5fb7ed60ca611b17246424e49f', INSERT INTO battlearenadata.players (player_name, player_pw, games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time) VALUES ('Player1', - 'password', + '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', --Hash of password "password" 18, 0, 80, @@ -83,7 +83,7 @@ VALUES ('Player1', INSERT INTO battlearenadata.players (player_name, player_pw, games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time) VALUES ('Player2', - 'password', + '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', --Hash of password "password" 15, 3, 50, diff --git a/src/test/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/ParserTest.java b/src/test/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/ParserTest.java index 07406e5ea3be3324dd621c19aa1748b53f37acaa..6cbf6fc345bc7da7639d7b61c0299c9b89ac6930 100644 --- a/src/test/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/ParserTest.java +++ b/src/test/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/ParserTest.java @@ -73,21 +73,21 @@ class ParserTest { @ValueSource(strings = {"a593cafd1d061f0f463a2d2051bf4718aaaf5c48", "e559d8fbb53b333f5839cb3c6c0c515395afe344", "a593cafd1d061f0f463a2d2051bf4718aaaf5c48"}) - void mapIDValid(String test){ + void sha1HashValid(String test){ assertDoesNotThrow(() -> Parser.sha1HexHashValid(test)); } @Test - void mapIDInvalid() { + void sha1HashInvalid() { ParserException testMe = assertThrows(ParserException.class, () -> Parser.sha1HexHashValid("01234567890123456789012345678901234567890")); - assertTrue(testMe.getMessage().contains("Map-ID length not correct. Must have length of 40 characters!")); + assertTrue(testMe.getMessage().contains("SHA1 hash length not correct. Must have length of 40 characters!")); testMe = assertThrows(ParserException.class, () -> Parser.sha1HexHashValid("012345678901234567890123456789012345678")); - assertTrue(testMe.getMessage().contains("Map-ID length not correct. Must have length of 40 characters!")); + assertTrue(testMe.getMessage().contains("SHA1 hash length not correct. Must have length of 40 characters!")); testMe = assertThrows(ParserException.class, () -> Parser.sha1HexHashValid("XYZ3cafd1d061f0f463a2d2051bf4718aaaf5c48")); - assertTrue(testMe.getMessage().contains("Forbidden characters used! Map ID only consists out of letters a-f and/or numbers 0-9!")); + assertTrue(testMe.getMessage().contains("Forbidden characters used! SHA1 hash only consists out of letters a-f and/or numbers 0-9!")); } @ParameterizedTest