Bug Fixes
This commit is contained in:
		@@ -56,7 +56,7 @@ public class Battle {
 | 
				
			|||||||
            while(counter<maxroundcount) {
 | 
					            while(counter<maxroundcount) {
 | 
				
			||||||
                counter++;
 | 
					                counter++;
 | 
				
			||||||
                counter2++;
 | 
					                counter2++;
 | 
				
			||||||
                if(counter2 < this.d1.size()-1 || counter2 < this.d2.size()-1){
 | 
					                if(counter2 < this.d1.size() || counter2 < this.d2.size()){
 | 
				
			||||||
                    counter2 = 0;
 | 
					                    counter2 = 0;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                if (this.d1.size() > 0 && this.d2.size() > 0 && counter<=maxroundcount) {
 | 
					                if (this.d1.size() > 0 && this.d2.size() > 0 && counter<=maxroundcount) {
 | 
				
			||||||
@@ -295,7 +295,7 @@ public class Battle {
 | 
				
			|||||||
        this.d2.remove(c2);
 | 
					        this.d2.remove(c2);
 | 
				
			||||||
        this.scorePlayer1 += 3;
 | 
					        this.scorePlayer1 += 3;
 | 
				
			||||||
        this.scorePlayer2 -= 5;
 | 
					        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.d1.remove(c1);
 | 
				
			||||||
        this.scorePlayer2 += 3;
 | 
					        this.scorePlayer2 += 3;
 | 
				
			||||||
        this.scorePlayer1 -= 5;
 | 
					        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);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -359,7 +359,7 @@ public class DBConnection {
 | 
				
			|||||||
                    return false;
 | 
					                    return false;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            } catch (SQLException throwables) {
 | 
					            } catch (SQLException throwables) {
 | 
				
			||||||
                throwables.printStackTrace();
 | 
					                System.err.println(throwables.getMessage());
 | 
				
			||||||
                return false;
 | 
					                return false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -438,14 +438,6 @@ public class DBConnection {
 | 
				
			|||||||
     * @return Das Package aus dem Shop, null falls ein Fehler auftritt
 | 
					     * @return Das Package aus dem Shop, null falls ein Fehler auftritt
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public Package userAcquirePackage(String username) {
 | 
					    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();
 | 
					        this.c = PostgresHelper.con();
 | 
				
			||||||
        String id = "";
 | 
					        String id = "";
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -87,7 +87,7 @@ public class Response {
 | 
				
			|||||||
                    sendResponse(userJson, "200");
 | 
					                    sendResponse(userJson, "200");
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }else{
 | 
					            }else{
 | 
				
			||||||
                sendResponse("", "500");
 | 
					                sendResponse("Get User Error", "500");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else if (this.url.startsWith("/cards")) {
 | 
					        } else if (this.url.startsWith("/cards")) {
 | 
				
			||||||
            String username = basicAuthGetUsername(this.authString);
 | 
					            String username = basicAuthGetUsername(this.authString);
 | 
				
			||||||
@@ -96,7 +96,7 @@ public class Response {
 | 
				
			|||||||
            if (jsonCards != null && !jsonCards.isEmpty()){
 | 
					            if (jsonCards != null && !jsonCards.isEmpty()){
 | 
				
			||||||
                sendResponse(jsonCards, "200");
 | 
					                sendResponse(jsonCards, "200");
 | 
				
			||||||
            }else{
 | 
					            }else{
 | 
				
			||||||
                sendResponse("", "500");
 | 
					                sendResponse("Cards to Json error", "500");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }else if(this.url.startsWith("/deck")) {
 | 
					        }else if(this.url.startsWith("/deck")) {
 | 
				
			||||||
            String format = this.url.substring(this.url.lastIndexOf('?') + 1);
 | 
					            String format = this.url.substring(this.url.lastIndexOf('?') + 1);
 | 
				
			||||||
@@ -123,10 +123,10 @@ public class Response {
 | 
				
			|||||||
                if(json != null && !json.equals("")){
 | 
					                if(json != null && !json.equals("")){
 | 
				
			||||||
                    sendResponse(json, "200");
 | 
					                    sendResponse(json, "200");
 | 
				
			||||||
                }else{
 | 
					                }else{
 | 
				
			||||||
                    sendResponse("", "500");
 | 
					                    sendResponse("Trading Deals to Json error", "500");
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }else{
 | 
					            }else{
 | 
				
			||||||
                sendResponse("", "500");
 | 
					                sendResponse("Keine Trading Deals gefunden", "500");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }else if(this.url.startsWith("/score")) {
 | 
					        }else if(this.url.startsWith("/score")) {
 | 
				
			||||||
            String username = basicAuthGetUsername(this.authString);
 | 
					            String username = basicAuthGetUsername(this.authString);
 | 
				
			||||||
@@ -274,15 +274,24 @@ public class Response {
 | 
				
			|||||||
        }else if (this.url.startsWith("/transactions/packages")) {
 | 
					        }else if (this.url.startsWith("/transactions/packages")) {
 | 
				
			||||||
            if (login()) {
 | 
					            if (login()) {
 | 
				
			||||||
                DBConnection db = new DBConnection();
 | 
					                DBConnection db = new DBConnection();
 | 
				
			||||||
                Package newPackage = db.userAcquirePackage(basicAuthGetUsername(this.authString));
 | 
					                String username = basicAuthGetUsername(this.authString);
 | 
				
			||||||
                if (newPackage == null) {
 | 
					                int coins = new DBConnection().checkCoins(username);
 | 
				
			||||||
                    sendResponse("", "500");
 | 
					                if (!(coins - 5 >= 0)) {
 | 
				
			||||||
                } else {
 | 
					                    sendResponse("Nur " + coins + " von 5 coins vorhanden", "500");
 | 
				
			||||||
                    String packageJson = JsonHelper.objToJson(newPackage);
 | 
					                }else {
 | 
				
			||||||
                    if (packageJson == null) {
 | 
					                    Package newPackage = db.userAcquirePackage(username);
 | 
				
			||||||
                        sendResponse("", "500");
 | 
					                    if (newPackage == null) {
 | 
				
			||||||
 | 
					                        sendResponse("Kein Package mehr vorhanden", "500");
 | 
				
			||||||
                    } else {
 | 
					                    } 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{
 | 
					            }else{
 | 
				
			||||||
@@ -306,35 +315,39 @@ public class Response {
 | 
				
			|||||||
                            Card card = new DBConnection().getCardFromID(this.payload);
 | 
					                            Card card = new DBConnection().getCardFromID(this.payload);
 | 
				
			||||||
                            if (card != null) {
 | 
					                            if (card != null) {
 | 
				
			||||||
                                if (tradingDeal != null) {
 | 
					                                if (tradingDeal != null) {
 | 
				
			||||||
                                    if (tradingDeal.cardOk(card)) {
 | 
					                                    if (!tradingDeal.getUsername().equals(username)){
 | 
				
			||||||
                                        String json = JsonHelper.objToJson(card);
 | 
					                                        if (tradingDeal.cardOk(card)) {
 | 
				
			||||||
                                        if (json != null && !json.isEmpty()) {
 | 
					                                            String json = JsonHelper.objToJson(card);
 | 
				
			||||||
                                            if (new DBConnection().addUserCard(username, tradingDeal.getCardToTrade().getName())) {
 | 
					                                            if (json != null && !json.isEmpty()) {
 | 
				
			||||||
                                                if (new DBConnection().delUserCard(tradingDeal.getUsername(), tradingDeal.getCardToTrade().getName())) {
 | 
					                                                if (new DBConnection().addUserCard(username, tradingDeal.getCardToTrade().getName())) {
 | 
				
			||||||
                                                    if (new DBConnection().deleteTradingDeal(tradingDeal.getId())) {
 | 
					                                                    if (new DBConnection().delUserCard(tradingDeal.getUsername(), tradingDeal.getCardToTrade().getName())) {
 | 
				
			||||||
                                                        if (new DBConnection().delUserCard(username, card.getName())) {
 | 
					                                                        if (new DBConnection().deleteTradingDeal(tradingDeal.getId())) {
 | 
				
			||||||
                                                            if (new DBConnection().addUserCard(tradingDeal.getUsername(), card.getName())) {
 | 
					                                                            if (new DBConnection().delUserCard(username, card.getName())) {
 | 
				
			||||||
                                                                sendResponse(json, "200");
 | 
					                                                                if (new DBConnection().addUserCard(tradingDeal.getUsername(), card.getName())) {
 | 
				
			||||||
 | 
					                                                                    sendResponse(json, "200");
 | 
				
			||||||
 | 
					                                                                } else {
 | 
				
			||||||
 | 
					                                                                    sendResponse("ERROR --> Add Card to: " + tradingDeal.getUsername(), "500");
 | 
				
			||||||
 | 
					                                                                }
 | 
				
			||||||
                                                            } else {
 | 
					                                                            } else {
 | 
				
			||||||
                                                                sendResponse("ERROR --> Add Card to: " + tradingDeal.getUsername(), "500");
 | 
					                                                                sendResponse("ERROR --> Del Card from: " + username, "500");
 | 
				
			||||||
                                                            }
 | 
					                                                            }
 | 
				
			||||||
                                                        } else {
 | 
					                                                        } else {
 | 
				
			||||||
                                                            sendResponse("ERROR --> Del Card from: " + username, "500");
 | 
					                                                            sendResponse("Error --> Del Trading Deal", "500");
 | 
				
			||||||
                                                        }
 | 
					                                                        }
 | 
				
			||||||
                                                    } else {
 | 
					                                                    } else {
 | 
				
			||||||
                                                        sendResponse("Error --> Del Trading Deal", "500");
 | 
					                                                        sendResponse("ERROR --> Del Card from: " + tradingDeal.getUsername(), "500");
 | 
				
			||||||
                                                    }
 | 
					                                                    }
 | 
				
			||||||
                                                } else {
 | 
					                                                } else {
 | 
				
			||||||
                                                    sendResponse("ERROR --> Del Card from: " + tradingDeal.getUsername(), "500");
 | 
					                                                    sendResponse("ERROR --> Add Card to: " + username, "500");
 | 
				
			||||||
                                                }
 | 
					                                                }
 | 
				
			||||||
                                            } else {
 | 
					                                            } else {
 | 
				
			||||||
                                                sendResponse("ERROR --> Add Card to: " + username, "500");
 | 
					                                                sendResponse("ERROR --> JSON Empty", "500");
 | 
				
			||||||
                                            }
 | 
					                                            }
 | 
				
			||||||
                                        } else {
 | 
					                                        } else {
 | 
				
			||||||
                                            sendResponse("ERROR --> JSON Empty", "500");
 | 
					                                            sendResponse("ERROR --> Trading Deal not ok", "500");
 | 
				
			||||||
                                        }
 | 
					                                        }
 | 
				
			||||||
                                    } else {
 | 
					                                    }else {
 | 
				
			||||||
                                        sendResponse("ERROR --> Trading Deal not ok", "500");
 | 
					                                        sendResponse("ERROR --> Kann nicht mit sich selbst traden", "500");
 | 
				
			||||||
                                    }
 | 
					                                    }
 | 
				
			||||||
                                } else {
 | 
					                                } else {
 | 
				
			||||||
                                    sendResponse("ERROR --> Trading Deal not exist", "500");
 | 
					                                    sendResponse("ERROR --> Trading Deal not exist", "500");
 | 
				
			||||||
@@ -542,10 +555,10 @@ public class Response {
 | 
				
			|||||||
                    if (deck != null && deckJson != null){
 | 
					                    if (deck != null && deckJson != null){
 | 
				
			||||||
                        sendResponse(deckJson, "200");
 | 
					                        sendResponse(deckJson, "200");
 | 
				
			||||||
                    }else {
 | 
					                    }else {
 | 
				
			||||||
                        sendResponse("", "500");
 | 
					                        sendResponse("Deck konnte nicht aus der DB geholt werden", "500");
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }else {
 | 
					                }else {
 | 
				
			||||||
                    sendResponse("", "500");
 | 
					                    sendResponse("Deck konnte nicht gesetzt werden", "500");
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }else{
 | 
					            }else{
 | 
				
			||||||
                sendResponse(Objects.requireNonNull(deckIds).size() + " von 4 Karten sind im Deck.","500");
 | 
					                sendResponse(Objects.requireNonNull(deckIds).size() + " von 4 Karten sind im Deck.","500");
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user