Add: Added TCP Client Handling Logic in TCPClient.java + Refactoring.
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.TCP;
|
package it.polimi.ingsw.gc14.Network;
|
||||||
|
|
||||||
public enum EventType {
|
public enum EventType {
|
||||||
ADD_PLAYER,
|
ADD_PLAYER,
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
import it.polimi.ingsw.gc14.Network.EventType;
|
||||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
import it.polimi.ingsw.gc14.View.IView;
|
import it.polimi.ingsw.gc14.View.IView;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
import it.polimi.ingsw.gc14.Network.EventType;
|
||||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
import it.polimi.ingsw.gc14.View.IView;
|
import it.polimi.ingsw.gc14.View.IView;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
import it.polimi.ingsw.gc14.Network.EventType;
|
||||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
import it.polimi.ingsw.gc14.View.IView;
|
import it.polimi.ingsw.gc14.View.IView;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
import it.polimi.ingsw.gc14.Network.EventType;
|
||||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
import it.polimi.ingsw.gc14.View.IView;
|
import it.polimi.ingsw.gc14.View.IView;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
import it.polimi.ingsw.gc14.Network.EventType;
|
||||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
import it.polimi.ingsw.gc14.View.IView;
|
import it.polimi.ingsw.gc14.View.IView;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
import it.polimi.ingsw.gc14.Network.EventType;
|
||||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
import it.polimi.ingsw.gc14.View.IView;
|
import it.polimi.ingsw.gc14.View.IView;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
import it.polimi.ingsw.gc14.Network.EventType;
|
||||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
import it.polimi.ingsw.gc14.View.IView;
|
import it.polimi.ingsw.gc14.View.IView;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
import it.polimi.ingsw.gc14.Network.EventType;
|
||||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
import it.polimi.ingsw.gc14.View.IView;
|
import it.polimi.ingsw.gc14.View.IView;
|
||||||
|
|
||||||
|
|||||||
@@ -1,37 +1,69 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.TCP.Client;
|
package it.polimi.ingsw.gc14.Network.TCP.Client;
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.View.IView;
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
|
import it.polimi.ingsw.gc14.Network.NetworkEvents.AddPlayer;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
|
||||||
public class TCPClient implements Serializable {
|
public class TCPClient implements Serializable{
|
||||||
public TCPClient(IView view) {
|
Socket communicationSocket = null;
|
||||||
IView iView = view;
|
ObjectInputStream socketReceive;
|
||||||
|
ObjectOutputStream socketSend;
|
||||||
|
|
||||||
|
GameController controller;
|
||||||
|
String hostname;
|
||||||
|
int port;
|
||||||
|
|
||||||
|
public TCPClient(GameController controller, String hostname, int port){
|
||||||
|
this.controller = controller;
|
||||||
|
this.hostname = hostname;
|
||||||
|
this.port = port;
|
||||||
}
|
}
|
||||||
public static void main(String[] args) {
|
|
||||||
String hostName = "127.0.0.1";
|
public boolean start(String user){
|
||||||
int portNumber = 5200;
|
try{
|
||||||
Socket communicationSocket = null;
|
communicationSocket = new Socket(hostname, port);
|
||||||
try {
|
socketSend = new ObjectOutputStream(communicationSocket.getOutputStream());
|
||||||
communicationSocket = new Socket(hostName, portNumber);
|
socketReceive = new ObjectInputStream(communicationSocket.getInputStream());
|
||||||
|
|
||||||
|
socketSend.writeObject(new AddPlayer(user));
|
||||||
|
if(communicationSocket.getInputStream().read() == -1){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Thread listener = new Thread(() -> ReceiveMessage());
|
||||||
|
listener.start();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReceiveMessage(){
|
||||||
|
while(true){
|
||||||
|
try{
|
||||||
|
((NetworkEvent)(socketReceive.readObject())).apply(controller);
|
||||||
|
}
|
||||||
|
catch(IOException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
catch(ClassNotFoundException e){
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SendEvent(NetworkEvent event){
|
||||||
|
try{
|
||||||
|
socketSend.writeObject(event);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
System.err.println(e.toString() + " " + hostName);
|
e.printStackTrace();
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
PrintWriter out = null;
|
|
||||||
BufferedReader in = null;
|
|
||||||
try {
|
|
||||||
out = new PrintWriter(communicationSocket.getOutputStream(), true);
|
|
||||||
in = new BufferedReader(new InputStreamReader(communicationSocket.getInputStream()));
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.err.println(e.toString() + " " + hostName);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
String userInput = "";
|
|
||||||
while (true) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.TCP;
|
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
public abstract class NetworkEvent implements Serializable {
|
|
||||||
|
|
||||||
public abstract boolean apply(GameController gameController);
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.TCP.NetworkEvents;
|
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent;
|
|
||||||
import it.polimi.ingsw.gc14.View.IView;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
public class AddPlayer extends NetworkEvent implements Serializable {
|
|
||||||
private String username;
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-29
@@ -1,29 +0,0 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.TCP.NetworkEvents;
|
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent;
|
|
||||||
import it.polimi.ingsw.gc14.View.IView;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
public class DrawLowerBuildingCard extends NetworkEvent implements Serializable{
|
|
||||||
private String username;
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.TCP.NetworkEvents;
|
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent;
|
|
||||||
import it.polimi.ingsw.gc14.View.IView;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
public class DrawLowerTribeCard extends NetworkEvent implements Serializable{
|
|
||||||
private String username;
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-29
@@ -1,29 +0,0 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.TCP.NetworkEvents;
|
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent;
|
|
||||||
import it.polimi.ingsw.gc14.View.IView;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
public class DrawUpperBuildingCard extends NetworkEvent implements Serializable{
|
|
||||||
private String username;
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.TCP.NetworkEvents;
|
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent;
|
|
||||||
import it.polimi.ingsw.gc14.View.IView;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
public class DrawUpperTribeCard extends NetworkEvent implements Serializable{
|
|
||||||
private String username;
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-29
@@ -1,29 +0,0 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.TCP.NetworkEvents;
|
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent;
|
|
||||||
import it.polimi.ingsw.gc14.View.IView;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
public class PickOptionalBuildingCard extends NetworkEvent implements Serializable{
|
|
||||||
private String username;
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-29
@@ -1,29 +0,0 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.TCP.NetworkEvents;
|
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent;
|
|
||||||
import it.polimi.ingsw.gc14.View.IView;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
public class PickOptionalTribeCard extends NetworkEvent implements Serializable{
|
|
||||||
private String username;
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.TCP.NetworkEvents;
|
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.EventType;
|
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent;
|
|
||||||
import it.polimi.ingsw.gc14.View.IView;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
public class SlotChoice extends NetworkEvent implements Serializable{
|
|
||||||
private String username;
|
|
||||||
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,8 +1,8 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.TCP.Server;
|
package it.polimi.ingsw.gc14.Network.TCP.Server;
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
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.Network.TCP.NetworkEvent;
|
import it.polimi.ingsw.gc14.Network.EventType;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
@@ -40,7 +40,7 @@ public class ClientHandler implements Runnable {
|
|||||||
}
|
}
|
||||||
while(true){
|
while(true){
|
||||||
try{
|
try{
|
||||||
input = (NetworkEvent)(in.readObject());
|
input = (NetworkEvent) (in.readObject());
|
||||||
if(input.apply(gameController)){
|
if(input.apply(gameController)){
|
||||||
server.broadcastUpdate(input);
|
server.broadcastUpdate(input);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.TCP.Server;
|
package it.polimi.ingsw.gc14.Network.TCP.Server;
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent;
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
@@ -41,9 +41,13 @@ public class TCPServer {
|
|||||||
try{
|
try{
|
||||||
clientSocket = serverTCP.accept();
|
clientSocket = serverTCP.accept();
|
||||||
if(!gameController.addPlayer(clientSocket.getInputStream().toString()) || ConnectedPlayers > gameController.getModel().getNPlayers()){
|
if(!gameController.addPlayer(clientSocket.getInputStream().toString()) || ConnectedPlayers > gameController.getModel().getNPlayers()){
|
||||||
|
clientSocket.getOutputStream().write((int)(-1));
|
||||||
clientSocket.close();
|
clientSocket.close();
|
||||||
System.out.println("Invalid parameters. Connection terminated.\n");
|
System.out.println("Invalid parameters. Connection terminated.\n");
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
clientSocket.getOutputStream().write((int)(1));
|
||||||
|
}
|
||||||
// gestione di ADD_PLAYER
|
// gestione di ADD_PLAYER
|
||||||
}
|
}
|
||||||
catch (IOException e){
|
catch (IOException e){
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package it.polimi.ingsw.gc14.View;
|
package it.polimi.ingsw.gc14.View;
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent;
|
|
||||||
|
|
||||||
public interface IView {
|
public interface IView {
|
||||||
// --- Setup ---
|
// --- Setup ---
|
||||||
void showWelcome();
|
void showWelcome();
|
||||||
|
|||||||
Reference in New Issue
Block a user