mirror of
				https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
				synced 2025-11-02 22:21:04 +01:00 
			
		
		
		
	Server bug fix. Add player did not correspond with the params
This commit is contained in:
		@@ -95,6 +95,31 @@ public class ServerGameLogic implements ClientInterpreter {
 | 
			
		||||
        return player;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Adds a new player to the game if the game is in the LOBBY state and the maximum
 | 
			
		||||
     * player limit has not been reached.
 | 
			
		||||
     *
 | 
			
		||||
     * @param id the id of the player to add to the game
 | 
			
		||||
     * @return the added Player, or null if the player could not be added
 | 
			
		||||
     */
 | 
			
		||||
    public Player addPlayer(int id) {
 | 
			
		||||
        Player player = new Player(id, playerHandler);
 | 
			
		||||
        if (state != ServerState.LOBBY) {
 | 
			
		||||
            LOGGER.log(Level.WARNING, "Cannot add player; game is not in LOBBY state.");
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (playerHandler.getPlayerCount() >= MAX_PLAYERS) {
 | 
			
		||||
            LOGGER.log(Level.WARNING, "Cannot add player; maximum player limit reached.");
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        playerHandler.addPlayer(player);
 | 
			
		||||
        LOGGER.log(Level.DEBUG, "Player added: {0}", player.getId());
 | 
			
		||||
 | 
			
		||||
        return player;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Handles a BuyPropertyRequest from a player, allowing the player to purchase a property
 | 
			
		||||
     * if it is unowned and they have sufficient funds.
 | 
			
		||||
@@ -223,4 +248,8 @@ public class ServerGameLogic implements ClientInterpreter {
 | 
			
		||||
    public BoardManager getBoardManager() {
 | 
			
		||||
        return boardManager;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Player getPlayerById(int id) {
 | 
			
		||||
        return playerHandler.getPlayerById(id);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -120,7 +120,7 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
 | 
			
		||||
    @Override
 | 
			
		||||
    public void connectionAdded(Server server, HostedConnection hostedConnection) {
 | 
			
		||||
        LOGGER.log(Level.INFO, "new connection {0}", hostedConnection); //NON-NLS
 | 
			
		||||
        logic.addPlayer(new Player(hostedConnection.getId()));
 | 
			
		||||
        logic.addPlayer(hostedConnection.getId());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user