Merge branch 'main' of github.com:rubenpirreram/ing-sw-2026-pirrera-radice-pagani-pellegrino into RMI
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
package it.polimi.ingsw.gc14.Network;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public abstract class NetworkEvent implements Serializable {
|
||||||
|
protected String username;
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
public NetworkEvent()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public NetworkEvent(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
public abstract boolean apply(GameController gameController);
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
|
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
||||||
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
|
import it.polimi.ingsw.gc14.View.IView;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class AddPlayer extends NetworkEvent implements Serializable {
|
||||||
|
private EventType eventType;
|
||||||
|
public AddPlayer(String username) {
|
||||||
|
this.username = username;
|
||||||
|
this.eventType = EventType.ADD_PLAYER;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean apply(GameController gameController)
|
||||||
|
{
|
||||||
|
return gameController.addPlayer(username);
|
||||||
|
}
|
||||||
|
public String apply(IView gameController)
|
||||||
|
{
|
||||||
|
return gameController.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
|
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
||||||
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
|
import it.polimi.ingsw.gc14.View.IView;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class DrawLowerBuildingCard extends NetworkEvent implements Serializable{
|
||||||
|
|
||||||
|
private EventType eventType;
|
||||||
|
private int pos;
|
||||||
|
|
||||||
|
public DrawLowerBuildingCard(String username, int pos){
|
||||||
|
this.username = username;
|
||||||
|
this.eventType = EventType.DRAW_LOWER_BUILD;
|
||||||
|
this.pos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(GameController gameController){
|
||||||
|
return gameController.drawLowerBuildingCard(username, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String apply(IView gameController){
|
||||||
|
return gameController.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
|
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
||||||
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
|
import it.polimi.ingsw.gc14.View.IView;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class DrawLowerTribeCard extends NetworkEvent implements Serializable{
|
||||||
|
private EventType eventType;
|
||||||
|
private int pos;
|
||||||
|
|
||||||
|
public DrawLowerTribeCard(String username, int pos){
|
||||||
|
this.username = username;
|
||||||
|
this.eventType = EventType.DRAW_LOWER_TRIBE;
|
||||||
|
this.pos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(GameController gameController){
|
||||||
|
return gameController.drawLowerTribeCard(username, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String apply(IView gameController){
|
||||||
|
return gameController.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
|
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
||||||
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
|
import it.polimi.ingsw.gc14.View.IView;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class DrawUpperBuildingCard extends NetworkEvent implements Serializable{
|
||||||
|
private EventType eventType;
|
||||||
|
private int pos;
|
||||||
|
|
||||||
|
public DrawUpperBuildingCard(String username, int pos){
|
||||||
|
this.username = username;
|
||||||
|
this.eventType = EventType.DRAW_UPPER_BUILD;
|
||||||
|
this.pos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(GameController gameController){
|
||||||
|
return gameController.drawUpperBuildingCard(username, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String apply(IView gameController){
|
||||||
|
return gameController.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
|
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
||||||
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
|
import it.polimi.ingsw.gc14.View.IView;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class DrawUpperTribeCard extends NetworkEvent implements Serializable{
|
||||||
|
private EventType eventType;
|
||||||
|
private int pos;
|
||||||
|
|
||||||
|
public DrawUpperTribeCard(String username, int pos){
|
||||||
|
this.username = username;
|
||||||
|
this.eventType = EventType.DRAW_UPPER_TRIBE;
|
||||||
|
this.pos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(GameController gameController){
|
||||||
|
return gameController.drawUpperTribeCard(username, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String apply(IView gameController){
|
||||||
|
return gameController.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
|
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
||||||
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
|
import it.polimi.ingsw.gc14.View.IView;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class PickOptionalBuildingCard extends NetworkEvent implements Serializable{
|
||||||
|
private EventType eventType;
|
||||||
|
private int pos;
|
||||||
|
|
||||||
|
public PickOptionalBuildingCard(String username, int pos){
|
||||||
|
this.username = username;
|
||||||
|
this.eventType = EventType.PICK_OPTIONAL_BUILD;
|
||||||
|
this.pos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(GameController gameController){
|
||||||
|
return gameController.pickOptionalBuildingCard(username, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String apply(IView gameController){
|
||||||
|
return gameController.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
|
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
||||||
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
|
import it.polimi.ingsw.gc14.View.IView;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class PickOptionalTribeCard extends NetworkEvent implements Serializable{
|
||||||
|
private EventType eventType;
|
||||||
|
private int pos;
|
||||||
|
|
||||||
|
public PickOptionalTribeCard(String username, int pos){
|
||||||
|
this.username = username;
|
||||||
|
this.eventType = EventType.PICK_OPTIONAL_TRIBE;
|
||||||
|
this.pos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(GameController gameController){
|
||||||
|
return gameController.pickOptionalTribeCard(username, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String apply(IView gameController){
|
||||||
|
return gameController.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
|
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
||||||
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
|
import it.polimi.ingsw.gc14.View.IView;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class SlotChoice extends NetworkEvent implements Serializable {
|
||||||
|
private EventType eventType;
|
||||||
|
private int pos;
|
||||||
|
|
||||||
|
public SlotChoice(String username, int pos) {
|
||||||
|
this.username = username;
|
||||||
|
this.eventType = EventType.SLOT_CHOICE;
|
||||||
|
this.pos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(GameController gameController) {
|
||||||
|
return gameController.slotChoice(username, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String apply(IView gameController) {
|
||||||
|
return gameController.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.RMI.Client;
|
package it.polimi.ingsw.gc14.Network.RMI.Client;
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Model.Game;
|
import it.polimi.ingsw.gc14.Model.Game;
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent;
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
|
|
||||||
import java.rmi.*;
|
import java.rmi.*;
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,13 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.RMI.Server;
|
package it.polimi.ingsw.gc14.Network.RMI.Server;
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Network.RMI.Client.IClientCallback;
|
import it.polimi.ingsw.gc14.Network.RMI.Client.IClientCallback;
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent;
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
|
|
||||||
import java.rmi.*;
|
import java.rmi.*;
|
||||||
|
|
||||||
public interface IGameServer extends Remote {
|
public interface IGameServer extends Remote {
|
||||||
// Connessione
|
|
||||||
String joinGame(String username, IClientCallback callback) throws RemoteException;
|
|
||||||
|
|
||||||
// Azioni di gioco — specchio dei tuoi metodi GameController
|
String joinGame(String username, IClientCallback callback) throws RemoteException;
|
||||||
boolean drawUpperTribeCard(String playerUsername, int pos) throws RemoteException;
|
boolean doEvent(NetworkEvent event) throws RemoteException;
|
||||||
boolean drawLowerTribeCard(String playerUsername, int pos) throws RemoteException;
|
|
||||||
boolean drawUpperBuildingCard(String playerUsername, int pos) throws RemoteException;
|
|
||||||
boolean drawLowerBuildingCard(String playerUsername, int pos) throws RemoteException;
|
|
||||||
boolean pickOptionalTribeCard(String playerUsername, int pos) throws RemoteException;
|
|
||||||
boolean pickOptionalBuildingCard(String playerUsername, int pos) throws RemoteException;
|
|
||||||
boolean slotChoice(String playerUsername, int pos) throws RemoteException;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ package it.polimi.ingsw.gc14.Network.RMI.Server;
|
|||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
import it.polimi.ingsw.gc14.Network.RMI.Client.IClientCallback;
|
import it.polimi.ingsw.gc14.Network.RMI.Client.IClientCallback;
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent;
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
|
import it.polimi.ingsw.gc14.Network.NetworkEvents.DrawUpperBuildingCard;
|
||||||
|
|
||||||
import java.rmi.*;
|
import java.rmi.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@@ -10,7 +11,7 @@ import java.util.*;
|
|||||||
|
|
||||||
public class RMIGameController implements IGameServer {
|
public class RMIGameController implements IGameServer {
|
||||||
|
|
||||||
private final GameController controller; // delega tutto qui
|
private final GameController controller;
|
||||||
private final Map<String, IClientCallback> clients = new ConcurrentHashMap<>();
|
private final Map<String, IClientCallback> clients = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public RMIGameController(GameController controller) {
|
public RMIGameController(GameController controller) {
|
||||||
@@ -27,19 +28,17 @@ public class RMIGameController implements IGameServer {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean drawUpperTribeCard(String username, int pos) throws RemoteException {
|
public void doEvent(NetworkEvent event) throws RemoteException {
|
||||||
boolean result = controller.drawUpperTribeCard(username, pos);
|
boolean result = event.apply(controller);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
notifyError(username, "Mossa non valida");
|
notifyError("","Mossa non valida");
|
||||||
} else {
|
} else {
|
||||||
notifyAll(new NetworkEvent(Action.ActionType.DRAW_UPPER_TRIBE, username, pos));
|
notifyAll(new DrawUpperBuildingCard(username, pos));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void notifyAll(NetworkEvent action) throws RemoteException {
|
||||||
|
|
||||||
private void notifyAll(Action action) throws RemoteException {
|
|
||||||
for (IClientCallback cb : clients.values()) {
|
for (IClientCallback cb : clients.values()) {
|
||||||
cb.onAction(action);
|
cb.onAction(action);
|
||||||
}
|
}
|
||||||
@@ -49,3 +48,4 @@ public class RMIGameController implements IGameServer {
|
|||||||
IClientCallback cb = clients.get(username);
|
IClientCallback cb = clients.get(username);
|
||||||
if (cb != null) cb.onError(message);
|
if (cb != null) cb.onError(message);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user