From b5d0f70b41fdc56a2e32166e60f20aa1fa81a786 Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Tue, 5 May 2026 15:53:59 +0200 Subject: [PATCH 1/6] Fix: RMI use different method to send data --- .../gc14/Controller/ClientController.java | 21 ++-- .../it/polimi/ingsw/gc14/Network/IClient.java | 27 +++- .../gc14/Network/RMI/Client/RMIClient.java | 116 +++++++++++++++-- .../gc14/Network/RMI/Common/IGameServer.java | 22 ++++ .../gc14/Network/RMI/Server/RMIServer.java | 117 ++++++++++++++++++ .../gc14/Network/TCP/Client/TCPClient.java | 109 +++++++++++++++- 6 files changed, 389 insertions(+), 23 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java b/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java index d51891c..18b3a70 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java +++ b/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java @@ -77,7 +77,7 @@ public class ClientController { } else { - client.doEvent(new DrawUpperTribeCard(playerUsername,pos)); + client.drawUpperTribeCard(playerUsername, pos); } } @@ -92,7 +92,7 @@ public class ClientController { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); else - client.doEvent(new DrawLowerTribeCard(playerUsername,pos)); + client.drawLowerTribeCard(playerUsername,pos); } @@ -106,7 +106,7 @@ public class ClientController { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); else - client.doEvent(new DrawUpperBuildingCard(playerUsername,pos)); + client.drawUpperBuildingCard(playerUsername,pos); } @@ -121,7 +121,7 @@ public class ClientController { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); else - client.doEvent(new DrawLowerBuildingCard(playerUsername,pos)); + client.drawLowerBuildingCard(playerUsername,pos); } @@ -134,7 +134,7 @@ public class ClientController { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); else - client.doEvent(new SkipUpper(playerUsername)); + client.skipUpper(playerUsername); } @@ -147,7 +147,8 @@ public class ClientController { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); else - client.doEvent(new SkipLower(playerUsername));} + client.skipLower(playerUsername); + } /** @@ -160,7 +161,7 @@ public class ClientController { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); else - client.doEvent(new PickOptionalTribeCard(playerUsername,pos)); + client.pickOptionalTribeCard(playerUsername,pos); } @@ -174,7 +175,7 @@ public class ClientController { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); else - client.doEvent(new PickOptionalBuildingCard(playerUsername,pos)); + client.pickOptionalBuildingCard(playerUsername,pos); } @@ -187,7 +188,7 @@ public class ClientController { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); else - client.doEvent(new NoOptionalCard(playerUsername)); + client.noOptionalCard(playerUsername); } @@ -200,7 +201,7 @@ public class ClientController { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); else - client.doEvent(new SlotChoice(playerUsername,pos)); + client.slotChoice(playerUsername,pos); } } diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/IClient.java b/src/main/java/it/polimi/ingsw/gc14/Network/IClient.java index 86f6435..f52aaba 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/IClient.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/IClient.java @@ -1,8 +1,33 @@ package it.polimi.ingsw.gc14.Network; +import it.polimi.ingsw.gc14.Network.NetworkEvents.*; + import java.rmi.RemoteException; +import java.util.Objects; public interface IClient { public boolean connect(String username,int preferredInt); - public void doEvent(NetworkEvent event) ; + + public void drawUpperTribeCard(String playerUsername, int pos) ; + + public void drawLowerTribeCard(String playerUsername,int pos) ; + + public void drawUpperBuildingCard(String playerUsername,int pos); + + + public void drawLowerBuildingCard(String playerUsername,int pos) ; + + public void skipUpper(String playerUsername) ; + + public void skipLower(String playerUsername) ; + + + public void pickOptionalTribeCard(String playerUsername,int pos) ; + + public void pickOptionalBuildingCard(String playerUsername,int pos); + + + public void noOptionalCard(String playerUsername) ; + + public void slotChoice(String playerUsername,int pos) ; } diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java index be92164..deb8d15 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java @@ -2,10 +2,12 @@ package it.polimi.ingsw.gc14.Network.RMI.Client; import java.rmi.RemoteException; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; +import java.util.Objects; import it.polimi.ingsw.gc14.Controller.ClientController; import it.polimi.ingsw.gc14.Network.IClient; import it.polimi.ingsw.gc14.Network.NetworkEvent; +import it.polimi.ingsw.gc14.Network.NetworkEvents.*; import it.polimi.ingsw.gc14.Network.RMI.Common.IClientCallback; import it.polimi.ingsw.gc14.Network.RMI.Common.IGameServer; import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer; @@ -64,17 +66,111 @@ public class RMIClient implements IClient { } - /** - * Sends a {@link NetworkEvent} to the server. - * @param event the event to send - * @throws RemoteException if any RMI error occurs - */ - public void doEvent(NetworkEvent event) { - try { - stub.doEvent(event); - }catch (Exception e) { - } + /** + * Requests to draw a tribe card from the upper list. + * Creates a NetworkEvent and sends it through the network client. + * @param playerUsername the name of the player performing the action + * @param pos the index of the card to draw + */ + public void drawUpperTribeCard(String playerUsername, int pos) { + stub.drawUpperTribeCard(playerUsername,pos); } + + /** + * Requests to draw a tribe card from the lower list. + * Creates a NetworkEvent and sends it through the network client. + * @param playerUsername the name of the player performing the action + * @param pos the index of the card to draw + */ + public void drawLowerTribeCard(String playerUsername,int pos) { + stub.drawLowerTribeCard(playerUsername,pos); + } + + + /** + * Requests to draw a building card from the upper list. + * Creates a NetworkEvent and sends it through the network client. + * @param playerUsername the name of the player performing the action + * @param pos the index of the card to draw + */ + public void drawUpperBuildingCard(String playerUsername,int pos) { + stub.drawUpperBuildingCard(playerUsername,pos); + } + + + /** + * Requests to draw a building card from the lower list. + * Creates a NetworkEvent and sends it through the network client. + * @param playerUsername the name of the player performing the action + * @param pos the index of the card to draw + */ + public void drawLowerBuildingCard(String playerUsername,int pos) { + stub.drawLowerBuildingCard(playerUsername,pos); + } + + + /** + * Requests to skip drawing from the upper list. + * This action is available only when the upper list is empty or the player cannot draw any card. + * @param playerUsername the name of the player performing the action + */ + public void skipUpper(String playerUsername) { + stub.skipUpper(playerUsername); + } + + + /** + * Requests to skip drawing from the lower list. + * This action is available only when the lower list is empty or the player cannot draw any card. + * @param playerUsername the name of the player performing the action + */ + public void skipLower(String playerUsername) { + stub.skipLower(playerUsername); + } + + + /** + * Used to draw a tribe card from the upper list. + * Available only if the player owns the building 12. + * @param playerUsername the name of the player performing the action + * @param pos the index of the card to draw + */ + public void pickOptionalTribeCard(String playerUsername,int pos) { + stub.pickOptionalTribeCard(playerUsername,pos); + } + + + /** + * Used to draw a building card from the upper list. + * Available only if the player owns the building 12. + * @param playerUsername the name of the player performing the action + * @param pos the index of the card to draw + */ + public void pickOptionalBuildingCard(String playerUsername,int pos) { + stub.pickOptionalBuildingCard(playerUsername,pos); + } + + + /** + * Used to skip the action of drawing a card from the upper list. + * Available only if the player owns the building 12. + * @param playerUsername the name of the player performing the action + */ + public void noOptionalCard(String playerUsername) { + stub.noOptionalCard(playerUsername); + } + + + /** + * Used to perform the slot choice action for the specified player at the specified position. + * @param playerUsername the name of the player performing the action + * @param pos the index of the selected slot + */ + public void slotChoice(String playerUsername,int pos) { + stub.slotChoice(playerUsername,pos); + } + + } \ No newline at end of file diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Common/IGameServer.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Common/IGameServer.java index 7a1ef25..24bd19a 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Common/IGameServer.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Common/IGameServer.java @@ -8,5 +8,27 @@ public interface IGameServer extends Remote { boolean joinGame(String username,int preferredInt, IClientCallback callback) throws RemoteException; boolean doEvent(NetworkEvent event) throws RemoteException; + void drawUpperTribeCard(String playerUsername, int pos) ; + + void drawLowerTribeCard(String playerUsername,int pos) ; + + void drawUpperBuildingCard(String playerUsername,int pos); + + + void drawLowerBuildingCard(String playerUsername,int pos) ; + + void skipUpper(String playerUsername) ; + + void skipLower(String playerUsername) ; + + + void pickOptionalTribeCard(String playerUsername,int pos) ; + + void pickOptionalBuildingCard(String playerUsername,int pos); + + + void noOptionalCard(String playerUsername) ; + + void slotChoice(String playerUsername,int pos) ; } diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java index 66daa9d..664a686 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java @@ -4,6 +4,7 @@ import it.polimi.ingsw.gc14.Controller.GameController; import it.polimi.ingsw.gc14.LimitedList; import it.polimi.ingsw.gc14.Model.Game; import it.polimi.ingsw.gc14.Network.NetworkEvent; +import it.polimi.ingsw.gc14.Network.NetworkEvents.*; import it.polimi.ingsw.gc14.Network.RMI.Common.IClientCallback; import it.polimi.ingsw.gc14.Network.RMI.Common.IGameServer; @@ -12,6 +13,7 @@ import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import java.rmi.server.UnicastRemoteObject; import java.util.Map; +import java.util.Objects; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ConcurrentHashMap; @@ -109,6 +111,121 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { return actionQueue.offer(action); } + /** + * Requests to draw a tribe card from the upper list. + * Creates a NetworkEvent and sends it through the network client. + * @param playerUsername the name of the player performing the action + * @param pos the index of the card to draw + */ + @Override + public void drawUpperTribeCard(String playerUsername, int pos) { + + actionQueue.offer(new DrawUpperTribeCard(playerUsername,pos)); + } + + + /** + * Requests to draw a tribe card from the lower list. + * Creates a NetworkEvent and sends it through the network client. + * @param playerUsername the name of the player performing the action + * @param pos the index of the card to draw + */ + @Override + public void drawLowerTribeCard(String playerUsername,int pos) { + actionQueue.offer(new DrawLowerTribeCard(playerUsername,pos)); + } + + + /** + * Requests to draw a building card from the upper list. + * Creates a NetworkEvent and sends it through the network client. + * @param playerUsername the name of the player performing the action + * @param pos the index of the card to draw + */ + @Override + public void drawUpperBuildingCard(String playerUsername,int pos) { + actionQueue.offer(new DrawUpperBuildingCard(playerUsername,pos)); + } + + + /** + * Requests to draw a building card from the lower list. + * Creates a NetworkEvent and sends it through the network client. + * @param playerUsername the name of the player performing the action + * @param pos the index of the card to draw + */ + @Override + public void drawLowerBuildingCard(String playerUsername,int pos) { + actionQueue.offer(new DrawLowerBuildingCard(playerUsername,pos)); + } + + + /** + * Requests to skip drawing from the upper list. + * This action is available only when the upper list is empty or the player cannot draw any card. + * @param playerUsername the name of the player performing the action + */ + @Override + public void skipUpper(String playerUsername) { + actionQueue.offer(new SkipUpper(playerUsername)); + } + + + /** + * Requests to skip drawing from the lower list. + * This action is available only when the lower list is empty or the player cannot draw any card. + * @param playerUsername the name of the player performing the action + */ + @Override + public void skipLower(String playerUsername) { + actionQueue.offer(new SkipLower(playerUsername)); + } + + + /** + * Used to draw a tribe card from the upper list. + * Available only if the player owns the building 12. + * @param playerUsername the name of the player performing the action + * @param pos the index of the card to draw + */ + @Override + public void pickOptionalTribeCard(String playerUsername,int pos) { + actionQueue.offer(new PickOptionalTribeCard(playerUsername,pos)); + } + + + /** + * Used to draw a building card from the upper list. + * Available only if the player owns the building 12. + * @param playerUsername the name of the player performing the action + * @param pos the index of the card to draw + */ + @Override + public void pickOptionalBuildingCard(String playerUsername,int pos) { + actionQueue.offer(new PickOptionalBuildingCard(playerUsername,pos)); + } + + + /** + * Used to skip the action of drawing a card from the upper list. + * Available only if the player owns the building 12. + * @param playerUsername the name of the player performing the action + */ + @Override + public void noOptionalCard(String playerUsername) { + actionQueue.offer(new NoOptionalCard(playerUsername)); + } + + + /** + * Used to perform the slot choice action for the specified player at the specified position. + * @param playerUsername the name of the player performing the action + * @param pos the index of the selected slot + */ + @Override + public void slotChoice(String playerUsername,int pos) { + actionQueue.offer(new SlotChoice(playerUsername,pos)); + } // RMI's internal methods diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java index c7b1aac..e9ef147 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java @@ -4,7 +4,7 @@ import it.polimi.ingsw.gc14.Controller.ClientController; import it.polimi.ingsw.gc14.Model.Game; import it.polimi.ingsw.gc14.Network.IClient; import it.polimi.ingsw.gc14.Network.NetworkEvent; -import it.polimi.ingsw.gc14.Network.NetworkEvents.AddPlayer; +import it.polimi.ingsw.gc14.Network.NetworkEvents.*; import java.io.*; import java.net.*; @@ -113,12 +113,117 @@ public class TCPClient implements IClient { } } + /** + * Requests to draw a tribe card from the upper list. + * Creates a NetworkEvent and sends it through the network client. + * @param playerUsername the name of the player performing the action + * @param pos the index of the card to draw + */ + public void drawUpperTribeCard(String playerUsername, int pos) { + doEvent(new DrawUpperTribeCard(playerUsername,pos)); + } + + + /** + * Requests to draw a tribe card from the lower list. + * Creates a NetworkEvent and sends it through the network client. + * @param playerUsername the name of the player performing the action + * @param pos the index of the card to draw + */ + public void drawLowerTribeCard(String playerUsername,int pos) { + doEvent(new DrawLowerTribeCard(playerUsername,pos)); + } + + + /** + * Requests to draw a building card from the upper list. + * Creates a NetworkEvent and sends it through the network client. + * @param playerUsername the name of the player performing the action + * @param pos the index of the card to draw + */ + public void drawUpperBuildingCard(String playerUsername,int pos) { + doEvent(new DrawUpperBuildingCard(playerUsername,pos)); + + } + + + /** + * Requests to draw a building card from the lower list. + * Creates a NetworkEvent and sends it through the network client. + * @param playerUsername the name of the player performing the action + * @param pos the index of the card to draw + */ + public void drawLowerBuildingCard(String playerUsername,int pos) { + doEvent(new DrawLowerBuildingCard(playerUsername,pos)); + } + + + /** + * Requests to skip drawing from the upper list. + * This action is available only when the upper list is empty or the player cannot draw any card. + * @param playerUsername the name of the player performing the action + */ + public void skipUpper(String playerUsername) { + doEvent(new SkipUpper(playerUsername)); + } + + + /** + * Requests to skip drawing from the lower list. + * This action is available only when the lower list is empty or the player cannot draw any card. + * @param playerUsername the name of the player performing the action + */ + public void skipLower(String playerUsername) { + doEvent(new SkipLower(playerUsername)); + } + + + /** + * Used to draw a tribe card from the upper list. + * Available only if the player owns the building 12. + * @param playerUsername the name of the player performing the action + * @param pos the index of the card to draw + */ + public void pickOptionalTribeCard(String playerUsername,int pos) { + doEvent(new PickOptionalTribeCard(playerUsername,pos)); + } + + + /** + * Used to draw a building card from the upper list. + * Available only if the player owns the building 12. + * @param playerUsername the name of the player performing the action + * @param pos the index of the card to draw + */ + public void pickOptionalBuildingCard(String playerUsername,int pos) { + doEvent(new PickOptionalBuildingCard(playerUsername,pos)); + } + + + /** + * Used to skip the action of drawing a card from the upper list. + * Available only if the player owns the building 12. + * @param playerUsername the name of the player performing the action + */ + public void noOptionalCard(String playerUsername) { + doEvent(new NoOptionalCard(playerUsername)); + } + + + /** + * Used to perform the slot choice action for the specified player at the specified position. + * @param playerUsername the name of the player performing the action + * @param pos the index of the selected slot + */ + public void slotChoice(String playerUsername,int pos) { + doEvent(new SlotChoice(playerUsername,pos)); + } /** * Sends a {@link NetworkEvent} to the server. * @param event The NetworkEvent to send. */ - public void doEvent(NetworkEvent event) { + private void doEvent(NetworkEvent event) { try { socketSend.writeObject(event); } catch (IOException e) { From 20ba64ea466ae219eb2873b902bfe2582316c2c6 Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Tue, 5 May 2026 16:46:55 +0200 Subject: [PATCH 2/6] Fix: ServerRMI interface bug --- .../gc14/Controller/ClientController.java | 85 +++++++++++++++---- .../it/polimi/ingsw/gc14/Network/IClient.java | 20 ++--- .../gc14/Network/RMI/Client/RMIClient.java | 20 ++--- .../gc14/Network/RMI/Common/IGameServer.java | 20 ++--- .../gc14/Network/RMI/Server/RMIServer.java | 13 --- 5 files changed, 97 insertions(+), 61 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java b/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java index 18b3a70..d79aa90 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java +++ b/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java @@ -5,6 +5,7 @@ import it.polimi.ingsw.gc14.Network.IClient; import it.polimi.ingsw.gc14.Network.NetworkEvents.*; import it.polimi.ingsw.gc14.View.IView; +import java.rmi.RemoteException; import java.util.Objects; /** @@ -77,7 +78,11 @@ public class ClientController { } else { - client.drawUpperTribeCard(playerUsername, pos); + try { + client.drawUpperTribeCard(playerUsername, pos); + } catch (RemoteException e) { + throw new RuntimeException(e); + } } } @@ -92,7 +97,11 @@ public class ClientController { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); else - client.drawLowerTribeCard(playerUsername,pos); + try { + client.drawLowerTribeCard(playerUsername, pos); + } catch (RemoteException e) { + throw new RuntimeException(e); + } } @@ -105,8 +114,13 @@ public class ClientController { public void drawUpperBuildingCard(String playerUsername,int pos) { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); - else - client.drawUpperBuildingCard(playerUsername,pos); + else { + try { + client.drawUpperBuildingCard(playerUsername,pos); + } catch (RemoteException e) { + throw new RuntimeException(e); + } + } } @@ -120,8 +134,13 @@ public class ClientController { public void drawLowerBuildingCard(String playerUsername,int pos) { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); - else - client.drawLowerBuildingCard(playerUsername,pos); + else { + try { + client.drawLowerBuildingCard(playerUsername,pos); + } catch (RemoteException e) { + throw new RuntimeException(e); + } + } } @@ -133,8 +152,13 @@ public class ClientController { public void skipUpper(String playerUsername) { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); - else - client.skipUpper(playerUsername); + else { + try { + client.skipUpper(playerUsername); + } catch (RemoteException e) { + throw new RuntimeException(e); + } + } } @@ -146,8 +170,13 @@ public class ClientController { public void skipLower(String playerUsername) { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); - else - client.skipLower(playerUsername); + else { + try { + client.skipLower(playerUsername); + } catch (RemoteException e) { + throw new RuntimeException(e); + } + } } @@ -160,8 +189,13 @@ public class ClientController { public void pickOptionalTribeCard(String playerUsername,int pos) { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); - else - client.pickOptionalTribeCard(playerUsername,pos); + else { + try { + client.pickOptionalTribeCard(playerUsername,pos); + } catch (RemoteException e) { + throw new RuntimeException(e); + } + } } @@ -174,8 +208,13 @@ public class ClientController { public void pickOptionalBuildingCard(String playerUsername,int pos) { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); - else - client.pickOptionalBuildingCard(playerUsername,pos); + else { + try { + client.pickOptionalBuildingCard(playerUsername,pos); + } catch (RemoteException e) { + throw new RuntimeException(e); + } + } } @@ -187,8 +226,13 @@ public class ClientController { public void noOptionalCard(String playerUsername) { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); - else - client.noOptionalCard(playerUsername); + else { + try { + client.noOptionalCard(playerUsername); + } catch (RemoteException e) { + throw new RuntimeException(e); + } + } } @@ -200,8 +244,13 @@ public class ClientController { public void slotChoice(String playerUsername,int pos) { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); - else - client.slotChoice(playerUsername,pos); + else { + try { + client.slotChoice(playerUsername,pos); + } catch (RemoteException e) { + throw new RuntimeException(e); + } + } } } diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/IClient.java b/src/main/java/it/polimi/ingsw/gc14/Network/IClient.java index f52aaba..a38a329 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/IClient.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/IClient.java @@ -8,26 +8,26 @@ import java.util.Objects; public interface IClient { public boolean connect(String username,int preferredInt); - public void drawUpperTribeCard(String playerUsername, int pos) ; + public void drawUpperTribeCard(String playerUsername, int pos) throws RemoteException; - public void drawLowerTribeCard(String playerUsername,int pos) ; + public void drawLowerTribeCard(String playerUsername,int pos) throws RemoteException; - public void drawUpperBuildingCard(String playerUsername,int pos); + public void drawUpperBuildingCard(String playerUsername,int pos) throws RemoteException; - public void drawLowerBuildingCard(String playerUsername,int pos) ; + public void drawLowerBuildingCard(String playerUsername,int pos) throws RemoteException; - public void skipUpper(String playerUsername) ; + public void skipUpper(String playerUsername) throws RemoteException; - public void skipLower(String playerUsername) ; + public void skipLower(String playerUsername) throws RemoteException; - public void pickOptionalTribeCard(String playerUsername,int pos) ; + public void pickOptionalTribeCard(String playerUsername,int pos) throws RemoteException; - public void pickOptionalBuildingCard(String playerUsername,int pos); + public void pickOptionalBuildingCard(String playerUsername,int pos) throws RemoteException; - public void noOptionalCard(String playerUsername) ; + public void noOptionalCard(String playerUsername) throws RemoteException; - public void slotChoice(String playerUsername,int pos) ; + public void slotChoice(String playerUsername,int pos) throws RemoteException; } diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java index deb8d15..77c6945 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java @@ -73,7 +73,7 @@ public class RMIClient implements IClient { * @param playerUsername the name of the player performing the action * @param pos the index of the card to draw */ - public void drawUpperTribeCard(String playerUsername, int pos) { + public void drawUpperTribeCard(String playerUsername, int pos) throws RemoteException { stub.drawUpperTribeCard(playerUsername,pos); } @@ -84,7 +84,7 @@ public class RMIClient implements IClient { * @param playerUsername the name of the player performing the action * @param pos the index of the card to draw */ - public void drawLowerTribeCard(String playerUsername,int pos) { + public void drawLowerTribeCard(String playerUsername,int pos) throws RemoteException { stub.drawLowerTribeCard(playerUsername,pos); } @@ -95,7 +95,7 @@ public class RMIClient implements IClient { * @param playerUsername the name of the player performing the action * @param pos the index of the card to draw */ - public void drawUpperBuildingCard(String playerUsername,int pos) { + public void drawUpperBuildingCard(String playerUsername,int pos) throws RemoteException { stub.drawUpperBuildingCard(playerUsername,pos); } @@ -106,7 +106,7 @@ public class RMIClient implements IClient { * @param playerUsername the name of the player performing the action * @param pos the index of the card to draw */ - public void drawLowerBuildingCard(String playerUsername,int pos) { + public void drawLowerBuildingCard(String playerUsername,int pos) throws RemoteException { stub.drawLowerBuildingCard(playerUsername,pos); } @@ -116,7 +116,7 @@ public class RMIClient implements IClient { * This action is available only when the upper list is empty or the player cannot draw any card. * @param playerUsername the name of the player performing the action */ - public void skipUpper(String playerUsername) { + public void skipUpper(String playerUsername) throws RemoteException { stub.skipUpper(playerUsername); } @@ -126,7 +126,7 @@ public class RMIClient implements IClient { * This action is available only when the lower list is empty or the player cannot draw any card. * @param playerUsername the name of the player performing the action */ - public void skipLower(String playerUsername) { + public void skipLower(String playerUsername) throws RemoteException { stub.skipLower(playerUsername); } @@ -137,7 +137,7 @@ public class RMIClient implements IClient { * @param playerUsername the name of the player performing the action * @param pos the index of the card to draw */ - public void pickOptionalTribeCard(String playerUsername,int pos) { + public void pickOptionalTribeCard(String playerUsername,int pos) throws RemoteException { stub.pickOptionalTribeCard(playerUsername,pos); } @@ -148,7 +148,7 @@ public class RMIClient implements IClient { * @param playerUsername the name of the player performing the action * @param pos the index of the card to draw */ - public void pickOptionalBuildingCard(String playerUsername,int pos) { + public void pickOptionalBuildingCard(String playerUsername,int pos) throws RemoteException { stub.pickOptionalBuildingCard(playerUsername,pos); } @@ -158,7 +158,7 @@ public class RMIClient implements IClient { * Available only if the player owns the building 12. * @param playerUsername the name of the player performing the action */ - public void noOptionalCard(String playerUsername) { + public void noOptionalCard(String playerUsername) throws RemoteException { stub.noOptionalCard(playerUsername); } @@ -168,7 +168,7 @@ public class RMIClient implements IClient { * @param playerUsername the name of the player performing the action * @param pos the index of the selected slot */ - public void slotChoice(String playerUsername,int pos) { + public void slotChoice(String playerUsername,int pos) throws RemoteException { stub.slotChoice(playerUsername,pos); } diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Common/IGameServer.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Common/IGameServer.java index 24bd19a..26eb348 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Common/IGameServer.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Common/IGameServer.java @@ -8,27 +8,27 @@ public interface IGameServer extends Remote { boolean joinGame(String username,int preferredInt, IClientCallback callback) throws RemoteException; boolean doEvent(NetworkEvent event) throws RemoteException; - void drawUpperTribeCard(String playerUsername, int pos) ; + void drawUpperTribeCard(String playerUsername, int pos) throws RemoteException; - void drawLowerTribeCard(String playerUsername,int pos) ; + void drawLowerTribeCard(String playerUsername,int pos) throws RemoteException; - void drawUpperBuildingCard(String playerUsername,int pos); + void drawUpperBuildingCard(String playerUsername,int pos) throws RemoteException; - void drawLowerBuildingCard(String playerUsername,int pos) ; + void drawLowerBuildingCard(String playerUsername,int pos) throws RemoteException; - void skipUpper(String playerUsername) ; + void skipUpper(String playerUsername) throws RemoteException; - void skipLower(String playerUsername) ; + void skipLower(String playerUsername) throws RemoteException; - void pickOptionalTribeCard(String playerUsername,int pos) ; + void pickOptionalTribeCard(String playerUsername,int pos) throws RemoteException; - void pickOptionalBuildingCard(String playerUsername,int pos); + void pickOptionalBuildingCard(String playerUsername,int pos) throws RemoteException; - void noOptionalCard(String playerUsername) ; + void noOptionalCard(String playerUsername) throws RemoteException; - void slotChoice(String playerUsername,int pos) ; + void slotChoice(String playerUsername,int pos) throws RemoteException; } diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java index 664a686..4a83a09 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java @@ -78,7 +78,6 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { * @param callback The client's callback interface * @return true if the player successfully joined the game, false otherwise */ - @Override public boolean joinGame(String username, int preferredInt, IClientCallback callback) { if (preferredInt<2 || preferredInt>5) { return false; @@ -106,7 +105,6 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { * @param action The desired actio * @return true if the action was successfully added, false otherwise */ - @Override public boolean doEvent(NetworkEvent action) { return actionQueue.offer(action); } @@ -117,9 +115,7 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { * @param playerUsername the name of the player performing the action * @param pos the index of the card to draw */ - @Override public void drawUpperTribeCard(String playerUsername, int pos) { - actionQueue.offer(new DrawUpperTribeCard(playerUsername,pos)); } @@ -130,7 +126,6 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { * @param playerUsername the name of the player performing the action * @param pos the index of the card to draw */ - @Override public void drawLowerTribeCard(String playerUsername,int pos) { actionQueue.offer(new DrawLowerTribeCard(playerUsername,pos)); } @@ -142,7 +137,6 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { * @param playerUsername the name of the player performing the action * @param pos the index of the card to draw */ - @Override public void drawUpperBuildingCard(String playerUsername,int pos) { actionQueue.offer(new DrawUpperBuildingCard(playerUsername,pos)); } @@ -154,7 +148,6 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { * @param playerUsername the name of the player performing the action * @param pos the index of the card to draw */ - @Override public void drawLowerBuildingCard(String playerUsername,int pos) { actionQueue.offer(new DrawLowerBuildingCard(playerUsername,pos)); } @@ -165,7 +158,6 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { * This action is available only when the upper list is empty or the player cannot draw any card. * @param playerUsername the name of the player performing the action */ - @Override public void skipUpper(String playerUsername) { actionQueue.offer(new SkipUpper(playerUsername)); } @@ -176,7 +168,6 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { * This action is available only when the lower list is empty or the player cannot draw any card. * @param playerUsername the name of the player performing the action */ - @Override public void skipLower(String playerUsername) { actionQueue.offer(new SkipLower(playerUsername)); } @@ -188,7 +179,6 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { * @param playerUsername the name of the player performing the action * @param pos the index of the card to draw */ - @Override public void pickOptionalTribeCard(String playerUsername,int pos) { actionQueue.offer(new PickOptionalTribeCard(playerUsername,pos)); } @@ -200,7 +190,6 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { * @param playerUsername the name of the player performing the action * @param pos the index of the card to draw */ - @Override public void pickOptionalBuildingCard(String playerUsername,int pos) { actionQueue.offer(new PickOptionalBuildingCard(playerUsername,pos)); } @@ -211,7 +200,6 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { * Available only if the player owns the building 12. * @param playerUsername the name of the player performing the action */ - @Override public void noOptionalCard(String playerUsername) { actionQueue.offer(new NoOptionalCard(playerUsername)); } @@ -222,7 +210,6 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { * @param playerUsername the name of the player performing the action * @param pos the index of the selected slot */ - @Override public void slotChoice(String playerUsername,int pos) { actionQueue.offer(new SlotChoice(playerUsername,pos)); } From 836ed59c4c2b9a88016620e60a4110a8652e9aed Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Tue, 5 May 2026 18:56:41 +0200 Subject: [PATCH 3/6] Fix: RMI no localhost --- .../it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java | 3 +++ .../it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java index 77c6945..4bc8a21 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java @@ -1,4 +1,5 @@ package it.polimi.ingsw.gc14.Network.RMI.Client; +import java.net.InetAddress; import java.rmi.RemoteException; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; @@ -53,6 +54,8 @@ public class RMIClient implements IClient { */ public boolean connect(String username,int preferredInt) { try { + String ip = InetAddress.getLocalHost().getHostAddress(); + System.setProperty("java.rmi.server.hostname", ip); Registry registry = LocateRegistry.getRegistry(host, port); this.stub = (IGameServer) registry.lookup("RMIGameServer"); ClientCallbackImpl callback = new ClientCallbackImpl(controller); diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java index 4a83a09..cf5d600 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java @@ -8,12 +8,14 @@ import it.polimi.ingsw.gc14.Network.NetworkEvents.*; import it.polimi.ingsw.gc14.Network.RMI.Common.IClientCallback; import it.polimi.ingsw.gc14.Network.RMI.Common.IGameServer; +import java.net.InetAddress; import java.rmi.RemoteException; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import java.rmi.server.UnicastRemoteObject; import java.util.Map; import java.util.Objects; +import java.util.Properties; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ConcurrentHashMap; @@ -247,6 +249,9 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { */ public boolean start() { try { + String ip = InetAddress.getLocalHost().getHostAddress(); + System.out.println("Starting RMI Server on IP: " + ip); + System.setProperty("java.rmi.server.hostname", "10.8.0.3"); // o il tuo IP/hostname registry = LocateRegistry.createRegistry(nPort); registry.rebind("RMIGameServer", this); System.out.println("RMI Server started on port: "+nPort); From cbe6447b7595110df66ed194714aff9473cf9b00 Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Tue, 5 May 2026 19:26:33 +0200 Subject: [PATCH 4/6] Fix: RMI no localhost --- .../polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java index cf5d600..fdcc868 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java @@ -26,7 +26,7 @@ import java.rmi.*; * Server RMI. Exposes a method to join the game and one to execute an event. */ public class RMIServer extends UnicastRemoteObject implements IGameServer { - + private String host; /** Server game's controller */ private GameController controller; @@ -60,11 +60,12 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { * @param playerList The player's usernames list * @throws RemoteException if an RMI error occurs */ - public RMIServer(GameController controller, int nPort, BlockingQueue actionQueue,LimitedList playerList) throws RemoteException { + public RMIServer(GameController controller, int nPort, BlockingQueue actionQueue,LimitedList playerList,String host) throws RemoteException { this.controller = controller; this.nPort = nPort; this.actionQueue = actionQueue; this.playerList = playerList; + this.host = host; } @@ -249,9 +250,7 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { */ public boolean start() { try { - String ip = InetAddress.getLocalHost().getHostAddress(); - System.out.println("Starting RMI Server on IP: " + ip); - System.setProperty("java.rmi.server.hostname", "10.8.0.3"); // o il tuo IP/hostname + System.setProperty("java.rmi.server.hostname", host); // o il tuo IP/hostname registry = LocateRegistry.createRegistry(nPort); registry.rebind("RMIGameServer", this); System.out.println("RMI Server started on port: "+nPort); From 7cba416a5a43f4c72689a1ecd19ac7042c0fef68 Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Tue, 5 May 2026 19:27:11 +0200 Subject: [PATCH 5/6] Fix: RMI no localhost --- .../it/polimi/ingsw/gc14/ServerLauncher.java | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java b/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java index 252a9da..0f43343 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java +++ b/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java @@ -10,8 +10,10 @@ import it.polimi.ingsw.gc14.Network.TCP.Server.TCPServer; import it.polimi.ingsw.gc14.View.TUI.TUI; import java.rmi.RemoteException; +import java.util.*; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; +import java.net.*; /** @@ -107,7 +109,14 @@ public class ServerLauncher { playerList = new LimitedList<>(5, ()->{}); BlockingQueue actionQueue = new LinkedBlockingQueue<>(); GameController gameController = new GameController(); - RMIServer serverRMI = new RMIServer(gameController, 1099, actionQueue, playerList); + String IP; + try { + IP=chooseNetworkInterface(new Scanner(System.in)); + } catch (Exception e) { + throw new RuntimeException(e); + } + + RMIServer serverRMI = new RMIServer(gameController, 1099, actionQueue, playerList,IP); TCPServer serverTCP = new TCPServer(gameController, 8080, actionQueue, playerList); ServerLauncher launcher = new ServerLauncher(actionQueue, gameController, serverRMI, serverTCP); @@ -156,4 +165,36 @@ public class ServerLauncher { } } } + public static String chooseNetworkInterface(Scanner scanner) throws Exception { + List ips = new ArrayList<>(); + + // Lista tutte le interfacce attive con IP reale + Enumeration interfaces = NetworkInterface.getNetworkInterfaces(); + while (interfaces.hasMoreElements()) { + NetworkInterface ni = interfaces.nextElement(); + + // Salta loopback, interfacce spente o virtuali + if (!ni.isUp() || ni.isLoopback() || ni.isVirtual()) continue; + + Enumeration addresses = ni.getInetAddresses(); + while (addresses.hasMoreElements()) { + InetAddress addr = addresses.nextElement(); + // Solo IPv4 + if (addr instanceof Inet4Address) { + System.out.println("[" + ips.size() + "] " + ni.getDisplayName() + " -> " + addr.getHostAddress()); + ips.add(addr.getHostAddress()); + } + } + } + + if (ips.isEmpty()) throw new Exception("Nessuna interfaccia disponibile"); + if (ips.size() == 1) { + System.out.println("Una sola interfaccia trovata, uso: " + ips.get(0)); + return ips.get(0); + } + + System.out.print("Scegli interfaccia: "); + int choice = Integer.parseInt(scanner.nextLine().trim()); + return ips.get(choice); + } } From 384df3c0a60a860f52d7925852a9611cb0fe8c39 Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Tue, 5 May 2026 19:34:43 +0200 Subject: [PATCH 6/6] Fix: ClientLauncher local IP select --- .../polimi/ingsw/gc14/ClientLauncherTUI.java | 45 ++++++++++++++++++- .../gc14/Network/RMI/Client/RMIClient.java | 7 +-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java index 8ff7bf9..f6f70c1 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java +++ b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java @@ -5,7 +5,11 @@ import it.polimi.ingsw.gc14.Network.RMI.Client.RMIClient; import it.polimi.ingsw.gc14.Network.TCP.Client.TCPClient; import it.polimi.ingsw.gc14.View.TUI.TUI; +import java.net.Inet4Address; +import java.net.InetAddress; +import java.net.NetworkInterface; import java.util.ArrayList; +import java.util.Enumeration; import java.util.List; import java.util.Scanner; @@ -65,7 +69,13 @@ public class ClientLauncherTUI { // RMI if (networkType == 0) { // Connect - RMIClient client = new RMIClient(controller, IP, 1099); + String myIP; + try { + myIP = chooseNetworkInterface(scanner); + } catch (Exception e) { + throw new RuntimeException(e); + } + RMIClient client = new RMIClient(controller, IP, 1099, myIP); if (client.connect(username, proposedNumPlayers)) { System.out.println("Succesfully connected to RMI server\n\n"); } else { @@ -159,4 +169,37 @@ public class ClientLauncherTUI { view.showError("ERROR: Invalid input(action not valid)"); } } + + public static String chooseNetworkInterface(Scanner scanner) throws Exception { + List ips = new ArrayList<>(); + + // Lista tutte le interfacce attive con IP reale + Enumeration interfaces = NetworkInterface.getNetworkInterfaces(); + while (interfaces.hasMoreElements()) { + NetworkInterface ni = interfaces.nextElement(); + + // Salta loopback, interfacce spente o virtuali + if (!ni.isUp() || ni.isLoopback() || ni.isVirtual()) continue; + + Enumeration addresses = ni.getInetAddresses(); + while (addresses.hasMoreElements()) { + InetAddress addr = addresses.nextElement(); + // Solo IPv4 + if (addr instanceof Inet4Address) { + System.out.println("[" + ips.size() + "] " + ni.getDisplayName() + " -> " + addr.getHostAddress()); + ips.add(addr.getHostAddress()); + } + } + } + + if (ips.isEmpty()) throw new Exception("Nessuna interfaccia disponibile"); + if (ips.size() == 1) { + System.out.println("Una sola interfaccia trovata, uso: " + ips.get(0)); + return ips.get(0); + } + + System.out.print("Scegli interfaccia: "); + int choice = scanner.nextInt(); + return ips.get(choice); + } } \ No newline at end of file diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java index 4bc8a21..141e01e 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java @@ -30,6 +30,7 @@ public class RMIClient implements IClient { /** Client game's controller */ ClientController controller; + private String myIP; /** * Class constructor. @@ -37,10 +38,11 @@ public class RMIClient implements IClient { * @param host the host address of the RMI server * @param port the port of the RMI server */ - public RMIClient(ClientController controller, String host, int port) { + public RMIClient(ClientController controller, String host, int port, String myIP) { this.controller=controller; this.host = host; this.port = port; + this.myIP = myIP; } @@ -54,8 +56,7 @@ public class RMIClient implements IClient { */ public boolean connect(String username,int preferredInt) { try { - String ip = InetAddress.getLocalHost().getHostAddress(); - System.setProperty("java.rmi.server.hostname", ip); + System.setProperty("java.rmi.server.hostname", this.myIP); Registry registry = LocateRegistry.getRegistry(host, port); this.stub = (IGameServer) registry.lookup("RMIGameServer"); ClientCallbackImpl callback = new ClientCallbackImpl(controller);