From 514ac3553ff975650bb6da49348d3c930ac351e6 Mon Sep 17 00:00:00 2001 From: "DESKTOP-IDUS0DU\\georg" Date: Tue, 5 Jan 2021 16:14:13 +0100 Subject: [PATCH] Bug Fixes --- src/main/java/at/reisinger/obj/Battle.java | 6 +- .../at/reisinger/server/DBConnection.java | 10 +-- .../at/reisinger/server/objects/Response.java | 75 +++++++++++-------- 3 files changed, 48 insertions(+), 43 deletions(-) diff --git a/src/main/java/at/reisinger/obj/Battle.java b/src/main/java/at/reisinger/obj/Battle.java index 029f78b..733e68f 100644 --- a/src/main/java/at/reisinger/obj/Battle.java +++ b/src/main/java/at/reisinger/obj/Battle.java @@ -56,7 +56,7 @@ public class Battle { while(counter 0 && this.d2.size() > 0 && counter<=maxroundcount) { @@ -295,7 +295,7 @@ public class Battle { this.d2.remove(c2); this.scorePlayer1 += 3; this.scorePlayer2 -= 5; - this.log.add("Player 1 gewinnt!\n" + c1.getElementTyp() + c1.getCardType() + " ist stärker! " + c1.getElementTyp() + c1.getCardType() + ": " + damageKnight + " vs " + c2.getElementTyp() + c2.getCardType() + ": " + damageOther + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2); + this.log.add("Player 1 gewinnt!\n" + c1.getElementTyp() + c1.getCardType() + " ist stärker! " + c1.getElementTyp() + c1.getCardType() + ": " + c1.getDamage() + " vs " + c2.getElementTyp() + c2.getCardType() + ": " + c2.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2); } /** @@ -308,7 +308,7 @@ public class Battle { this.d1.remove(c1); this.scorePlayer2 += 3; this.scorePlayer1 -= 5; - this.log.add("Player 2 gewinnt!\n" + c2.getElementTyp() + c2.getCardType() + " ist stärker! " + c2.getElementTyp() + c2.getCardType() + ": " + damageKnight + " vs " + c1.getElementTyp() + c1.getCardType() + ": " + damageOther + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2); + this.log.add("Player 2 gewinnt!\n" + c2.getElementTyp() + c2.getCardType() + " ist stärker! " + c2.getElementTyp() + c2.getCardType() + ": " + c1.getDamage() + " vs " + c1.getElementTyp() + c1.getCardType() + ": " + c2.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2); } /** diff --git a/src/main/java/at/reisinger/server/DBConnection.java b/src/main/java/at/reisinger/server/DBConnection.java index 4c6bb73..b116c72 100644 --- a/src/main/java/at/reisinger/server/DBConnection.java +++ b/src/main/java/at/reisinger/server/DBConnection.java @@ -359,7 +359,7 @@ public class DBConnection { return false; } } catch (SQLException throwables) { - throwables.printStackTrace(); + System.err.println(throwables.getMessage()); return false; } } @@ -438,14 +438,6 @@ public class DBConnection { * @return Das Package aus dem Shop, null falls ein Fehler auftritt */ public Package userAcquirePackage(String username) { - int coins = checkCoins(username); - if (!(coins - 5 >= 0)) { - return null; - } - if(!updateCoins(coins - 5, username)){ - return null; - } - this.c = PostgresHelper.con(); String id = ""; try { diff --git a/src/main/java/at/reisinger/server/objects/Response.java b/src/main/java/at/reisinger/server/objects/Response.java index 9efaa68..d16add9 100644 --- a/src/main/java/at/reisinger/server/objects/Response.java +++ b/src/main/java/at/reisinger/server/objects/Response.java @@ -87,7 +87,7 @@ public class Response { sendResponse(userJson, "200"); } }else{ - sendResponse("", "500"); + sendResponse("Get User Error", "500"); } } else if (this.url.startsWith("/cards")) { String username = basicAuthGetUsername(this.authString); @@ -96,7 +96,7 @@ public class Response { if (jsonCards != null && !jsonCards.isEmpty()){ sendResponse(jsonCards, "200"); }else{ - sendResponse("", "500"); + sendResponse("Cards to Json error", "500"); } }else if(this.url.startsWith("/deck")) { String format = this.url.substring(this.url.lastIndexOf('?') + 1); @@ -123,10 +123,10 @@ public class Response { if(json != null && !json.equals("")){ sendResponse(json, "200"); }else{ - sendResponse("", "500"); + sendResponse("Trading Deals to Json error", "500"); } }else{ - sendResponse("", "500"); + sendResponse("Keine Trading Deals gefunden", "500"); } }else if(this.url.startsWith("/score")) { String username = basicAuthGetUsername(this.authString); @@ -274,15 +274,24 @@ public class Response { }else if (this.url.startsWith("/transactions/packages")) { if (login()) { DBConnection db = new DBConnection(); - Package newPackage = db.userAcquirePackage(basicAuthGetUsername(this.authString)); - if (newPackage == null) { - sendResponse("", "500"); - } else { - String packageJson = JsonHelper.objToJson(newPackage); - if (packageJson == null) { - sendResponse("", "500"); + String username = basicAuthGetUsername(this.authString); + int coins = new DBConnection().checkCoins(username); + if (!(coins - 5 >= 0)) { + sendResponse("Nur " + coins + " von 5 coins vorhanden", "500"); + }else { + Package newPackage = db.userAcquirePackage(username); + if (newPackage == null) { + sendResponse("Kein Package mehr vorhanden", "500"); } else { - sendResponse(packageJson, "200"); + String packageJson = JsonHelper.objToJson(newPackage); + if (packageJson == null) { + sendResponse("Package to Json error", "500"); + } else { + if(!new DBConnection().updateCoins(coins - 5, username)){ + sendResponse("User coins konnten ned gesetzt werden", "500"); + } + sendResponse(packageJson, "200"); + } } } }else{ @@ -306,35 +315,39 @@ public class Response { Card card = new DBConnection().getCardFromID(this.payload); if (card != null) { if (tradingDeal != null) { - if (tradingDeal.cardOk(card)) { - String json = JsonHelper.objToJson(card); - if (json != null && !json.isEmpty()) { - if (new DBConnection().addUserCard(username, tradingDeal.getCardToTrade().getName())) { - if (new DBConnection().delUserCard(tradingDeal.getUsername(), tradingDeal.getCardToTrade().getName())) { - if (new DBConnection().deleteTradingDeal(tradingDeal.getId())) { - if (new DBConnection().delUserCard(username, card.getName())) { - if (new DBConnection().addUserCard(tradingDeal.getUsername(), card.getName())) { - sendResponse(json, "200"); + if (!tradingDeal.getUsername().equals(username)){ + if (tradingDeal.cardOk(card)) { + String json = JsonHelper.objToJson(card); + if (json != null && !json.isEmpty()) { + if (new DBConnection().addUserCard(username, tradingDeal.getCardToTrade().getName())) { + if (new DBConnection().delUserCard(tradingDeal.getUsername(), tradingDeal.getCardToTrade().getName())) { + if (new DBConnection().deleteTradingDeal(tradingDeal.getId())) { + if (new DBConnection().delUserCard(username, card.getName())) { + if (new DBConnection().addUserCard(tradingDeal.getUsername(), card.getName())) { + sendResponse(json, "200"); + } else { + sendResponse("ERROR --> Add Card to: " + tradingDeal.getUsername(), "500"); + } } else { - sendResponse("ERROR --> Add Card to: " + tradingDeal.getUsername(), "500"); + sendResponse("ERROR --> Del Card from: " + username, "500"); } } else { - sendResponse("ERROR --> Del Card from: " + username, "500"); + sendResponse("Error --> Del Trading Deal", "500"); } } else { - sendResponse("Error --> Del Trading Deal", "500"); + sendResponse("ERROR --> Del Card from: " + tradingDeal.getUsername(), "500"); } } else { - sendResponse("ERROR --> Del Card from: " + tradingDeal.getUsername(), "500"); + sendResponse("ERROR --> Add Card to: " + username, "500"); } } else { - sendResponse("ERROR --> Add Card to: " + username, "500"); + sendResponse("ERROR --> JSON Empty", "500"); } } else { - sendResponse("ERROR --> JSON Empty", "500"); + sendResponse("ERROR --> Trading Deal not ok", "500"); } - } else { - sendResponse("ERROR --> Trading Deal not ok", "500"); + }else { + sendResponse("ERROR --> Kann nicht mit sich selbst traden", "500"); } } else { sendResponse("ERROR --> Trading Deal not exist", "500"); @@ -542,10 +555,10 @@ public class Response { if (deck != null && deckJson != null){ sendResponse(deckJson, "200"); }else { - sendResponse("", "500"); + sendResponse("Deck konnte nicht aus der DB geholt werden", "500"); } }else { - sendResponse("", "500"); + sendResponse("Deck konnte nicht gesetzt werden", "500"); } }else{ sendResponse(Objects.requireNonNull(deckIds).size() + " von 4 Karten sind im Deck.","500");