feat: add disconnect and reconnect methods to lobby
This commit is contained in:
parent
ca0999d06b
commit
0d1af0ed62
@ -72,9 +72,7 @@ public class Lobby {
|
||||
partyConfig.maxRoundTime,
|
||||
this::turnTimeout);
|
||||
|
||||
var eventsDescribingGameStart = this.game.startGame(player1Characters, player2Characters);
|
||||
|
||||
this.connection.broadcastEvents(eventsDescribingGameStart);
|
||||
this.connection.broadcastEvents(this.game.startGame(player1Characters, player2Characters));
|
||||
|
||||
updateTimer();
|
||||
}
|
||||
@ -115,6 +113,22 @@ public class Lobby {
|
||||
updateTimer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by {@link LobbyConnection} when a client disconnects
|
||||
* @param source the player disconnecting
|
||||
*/
|
||||
public synchronized void handleDisconnect(Participant source) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by {@link LobbyConnection} when a client reconnects
|
||||
* @param source the player reconnecting
|
||||
*/
|
||||
public synchronized void handleReconnect(Participant source) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called at the end of receiveRequests, to start a timer. The active player has now a specific
|
||||
* amount of time to do his moves.
|
||||
|
@ -14,6 +14,8 @@ import uulm.teamname.marvelous.server.lobby.Lobby;
|
||||
import uulm.teamname.marvelous.server.netconnector.SUID;
|
||||
import uulm.teamname.marvelous.server.netconnector.UserManager;
|
||||
|
||||
import javax.management.MBeanParameterInfo;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
@ -89,6 +91,7 @@ public class LobbyConnection implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Participant getPlayer1() {
|
||||
return player1;
|
||||
}
|
||||
@ -116,10 +119,16 @@ public class LobbyConnection implements Runnable {
|
||||
|
||||
public void handleDisconnect(Participant participant) {
|
||||
participant.disconnected = true;
|
||||
if(lobby != null) {
|
||||
lobby.handleDisconnect(participant);
|
||||
}
|
||||
}
|
||||
|
||||
public void handleReconnect(Participant participant) {
|
||||
participant.disconnected = false;
|
||||
if(lobby != null) {
|
||||
lobby.handleReconnect(participant);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -160,6 +169,7 @@ public class LobbyConnection implements Runnable {
|
||||
state = LobbyConnectionState.Aborted;
|
||||
}
|
||||
|
||||
|
||||
private void sendGameStructure() {
|
||||
GameStructureMessage gameStructureMessage = new GameStructureMessage();
|
||||
gameStructureMessage.playerOneName = player1.id.getName();
|
||||
@ -211,6 +221,17 @@ public class LobbyConnection implements Runnable {
|
||||
spectators.forEach(spectator -> spectator.sendMessage(message));
|
||||
}
|
||||
|
||||
private void broadcastToAllExcept(Participant except, BasicMessage message) {
|
||||
if (!except.equals(player1)) player1.sendMessage(message);
|
||||
if (!except.equals(player2)) player2.sendMessage(message);
|
||||
for(Participant spectator: spectators) {
|
||||
if(!except.equals(spectator)) {
|
||||
spectator.sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void sendEvents(Participant recipient, Event... events) {
|
||||
EventMessage message = new EventMessage();
|
||||
message.messages = events;
|
||||
@ -235,12 +256,4 @@ public class LobbyConnection implements Runnable {
|
||||
|
||||
broadcastToAllExcept(except, message);
|
||||
}
|
||||
|
||||
private void broadcastToAllExcept(Participant except, BasicMessage message) {
|
||||
if (!except.equals(player1)) player1.sendMessage(message);
|
||||
if (!except.equals(player2)) player2.sendMessage(message);
|
||||
spectators.stream()
|
||||
.filter(spectator -> !except.equals(spectator))
|
||||
.forEach(spectator -> spectator.sendMessage(message));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user