changed LobbyConnection construction, and changed Lobby and DisconnectSegment according to new API
This commit is contained in:
parent
c5e8bd6ece
commit
2f2bbea213
@ -111,7 +111,7 @@ public class Lobby {
|
||||
badRequests ++;
|
||||
//if the player sends 2 bad messages after one another, the player gets kicked out of the lobby.
|
||||
if(badRequests == 2){
|
||||
connection.removePlayer(source);
|
||||
connection.removeParticipant(source);
|
||||
if(connection.hasPlayer1()){
|
||||
generateWin(connection.getPlayer1());
|
||||
}
|
||||
@ -139,7 +139,7 @@ public class Lobby {
|
||||
connection.sendEvents(
|
||||
source,
|
||||
new EventBuilder(EventType.TimeoutEvent).buildGameStateEvent());
|
||||
connection.removePlayer(source);
|
||||
connection.removeParticipant(source);
|
||||
|
||||
if(connection.hasPlayer1()){
|
||||
generateWin(connection.getPlayer1());
|
||||
|
@ -23,7 +23,7 @@ public class DisconnectSegment implements Segment {
|
||||
Logger.trace("DisconnectSegment received {} requests.", packet.size());
|
||||
if (packet.containsRequestOfType(RequestType.DisconnectRequest)) {
|
||||
Logger.debug("Player of Type {} sent DisconnectRequest", packet.getOrigin().type);
|
||||
parent.getConnection().removePlayer(packet.getOrigin());
|
||||
parent.getConnection().removeParticipant(packet.getOrigin());
|
||||
|
||||
if (packet.getOrigin().type != ParticipantType.Spectator) {
|
||||
if(parent.getConnection().hasPlayer1()){
|
||||
|
@ -1,5 +1,9 @@
|
||||
package uulm.teamname.marvelous.server.lobbymanager;
|
||||
|
||||
import org.tinylog.Logger;
|
||||
import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig;
|
||||
import uulm.teamname.marvelous.gamelibrary.config.PartyConfig;
|
||||
import uulm.teamname.marvelous.gamelibrary.config.ScenarioConfig;
|
||||
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
||||
import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType;
|
||||
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
||||
@ -17,19 +21,26 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
*/
|
||||
public class LobbyConnection implements Runnable {
|
||||
private final Lobby lobby;
|
||||
public final String lobbyID;
|
||||
public final String gameID;
|
||||
private Participant player1, player2;
|
||||
private final HashSet<Participant> spectators;
|
||||
private final BlockingQueue<Request[]> incomingRequests;
|
||||
|
||||
// TODO: FIX THIS JAVADOC
|
||||
/**
|
||||
* Creates a new LobbyConnection from a given lobby
|
||||
* @param lobby is the lobby that will be connected to
|
||||
* @param lobbyID
|
||||
* Creates a new LobbyConnection, whereby a new {@link Lobby} is initialized.
|
||||
*/
|
||||
public LobbyConnection(Lobby lobby, String lobbyID) {
|
||||
this.lobby = lobby;
|
||||
this.lobbyID = lobbyID;
|
||||
public LobbyConnection(String gameID,
|
||||
PartyConfig partyConfig,
|
||||
CharacterConfig characterConfig,
|
||||
ScenarioConfig scenarioConfig) {
|
||||
this.lobby = new Lobby(
|
||||
gameID,
|
||||
this,
|
||||
partyConfig,
|
||||
characterConfig,
|
||||
scenarioConfig);
|
||||
this.gameID = gameID;
|
||||
this.spectators = new HashSet<>(10);
|
||||
this.incomingRequests = new LinkedBlockingQueue<>();
|
||||
}
|
||||
@ -48,6 +59,11 @@ public class LobbyConnection implements Runnable {
|
||||
return player2 != null;
|
||||
}
|
||||
|
||||
/** @return whether a player can join the lobby */
|
||||
public boolean hasFreePlayerSpot() {
|
||||
return !(hasPlayer1() && hasPlayer2());
|
||||
}
|
||||
|
||||
public Participant getPlayer1() {
|
||||
return player1;
|
||||
}
|
||||
@ -96,13 +112,26 @@ public class LobbyConnection implements Runnable {
|
||||
* @return true if added successfully, and false otherwise
|
||||
*/
|
||||
public boolean addPlayer(Participant player) {
|
||||
if (!player.type.equals(ParticipantType.PlayerOne) && !player.type.equals(ParticipantType.PlayerTwo)) {
|
||||
Logger.warn("addPlayer called with non-player. This is very probably a bug.");
|
||||
return false;
|
||||
}
|
||||
if (!addPlayer1(player)) {
|
||||
return addPlayer2(player);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean removePlayer(Participant player) {
|
||||
public boolean addSpectator(Participant spectator) {
|
||||
if (!spectator.type.equals(ParticipantType.Spectator)) {
|
||||
Logger.warn("addSpectator called with non-spectator. This is very probably a bug.");
|
||||
return false;
|
||||
} else {
|
||||
return spectators.add(spectator);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean removeParticipant(Participant player) {
|
||||
if (player1 == player) {
|
||||
player1 = null;
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user