mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Kaster ut spillere som prøver å bli med etter at spillet har startet
This commit is contained in:
parent
6e3f95e5a6
commit
509759fdd1
@ -27,6 +27,7 @@ class RoboRallyServerListener extends Listener {
|
|||||||
private Connection host;
|
private Connection host;
|
||||||
private Map<Connection, Boolean> stayInPowerDown;
|
private Map<Connection, Boolean> stayInPowerDown;
|
||||||
private Map<Connection, ProgramAndPowerdownRequest> programs;
|
private Map<Connection, ProgramAndPowerdownRequest> programs;
|
||||||
|
private boolean gameStarted = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Robo Rally server listener
|
* Instantiates a new Robo Rally server listener
|
||||||
@ -75,6 +76,7 @@ class RoboRallyServerListener extends Listener {
|
|||||||
deadPlayers.add(connection);
|
deadPlayers.add(connection);
|
||||||
connection.close();
|
connection.close();
|
||||||
}
|
}
|
||||||
|
this.gameStarted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -174,6 +176,11 @@ class RoboRallyServerListener extends Listener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connected(Connection connection) {
|
public void connected(Connection connection) {
|
||||||
|
//Prevent players from joining after the game has started
|
||||||
|
if (gameStarted) {
|
||||||
|
connection.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
//The first client to connect is assumed to be the host
|
//The first client to connect is assumed to be the host
|
||||||
if (host == null) {
|
if (host == null) {
|
||||||
host = connection;
|
host = connection;
|
||||||
@ -191,7 +198,7 @@ class RoboRallyServerListener extends Listener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnected(Connection connection) {
|
public void disconnected(Connection connection) {
|
||||||
if (deadPlayers.contains(connection)) {
|
if (deadPlayers.contains(connection) || !clients.keySet().contains(connection)) {
|
||||||
//Remove all traces of the player ever existing
|
//Remove all traces of the player ever existing
|
||||||
clients.remove(connection);
|
clients.remove(connection);
|
||||||
playerNames.remove(connection);
|
playerNames.remove(connection);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user