Files
SENG302/racevisionGame/src/main/java/visualiser/Commands/ConnectionToServerCommands/JoinSuccessParticipantCommand.java
T
fjc40 7366aba5ec Added empty data sources, to be used by VisualiserRace.
Created FrameRateTracker which can be used to track framerate.
Updated RequestToJoinEnum and JoinAcceptanceEnum to match the agreed connection API.
Added AssignPlayerBoat message, which is used internally on the client to assign the player a source ID once they have connected.
Fixed some race conditions in the MessageRouter.
Updated ConnectionAcceptor.CheckClientConnection to wait slightly longer before removing connection (there was a slight race condition before).
Race no longer has a reference to LatestMessages. LatestMessages no longer has specific messages types in it.
Created RaceState class, which contains the state that is shared between VisualiserRaceState and MockRaceState (currently only used on visualiser).
Split VisualiserRace into VisualiserRaceState and VisualiserRaceService.
Added the VisualiserRace commands (BoatLocatonCommand, RaceStatusCommand, etc...).
Slightly increased the preferred width of race.fxml table columns.
issues #27 #37 #35
#story[1095]
2017-08-14 00:53:05 +12:00

58 lines
1.8 KiB
Java

package visualiser.Commands.ConnectionToServerCommands;
import mock.model.commandFactory.Command;
import network.Messages.AssignPlayerBoat;
import network.Messages.JoinAcceptance;
import visualiser.enums.ConnectionToServerState;
import visualiser.network.ConnectionToServer;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Command created when a {@link network.Messages.Enums.JoinAcceptanceEnum#JOIN_SUCCESSFUL_PARTICIPANT} {@link network.Messages.JoinAcceptance} message is received.
*/
public class JoinSuccessParticipantCommand implements Command {
/**
* The message to operate on.
*/
private JoinAcceptance joinAcceptance;
/**
* The context to operate on.
*/
private ConnectionToServer connectionToServer;
/**
* Creates a new {@link JoinSuccessParticipantCommand}, which operates on a given {@link ConnectionToServer}.
* @param joinAcceptance The message to operate on.
* @param connectionToServer The context to operate on.
*/
public JoinSuccessParticipantCommand(JoinAcceptance joinAcceptance, ConnectionToServer connectionToServer) {
this.joinAcceptance = joinAcceptance;
this.connectionToServer = connectionToServer;
}
@Override
public void execute() {
connectionToServer.setJoinAcceptance(joinAcceptance);
connectionToServer.setConnectionState(ConnectionToServerState.CONNECTED);
AssignPlayerBoat assignPlayerBoat = new AssignPlayerBoat(joinAcceptance.getSourceID());
try {
connectionToServer.send(assignPlayerBoat);
} catch (InterruptedException e) {
Logger.getGlobal().log(Level.WARNING, "JoinSuccessParticipantCommand: " + this + " was interrupted on thread: " + Thread.currentThread() + " while sending AssignPlayerBoat message.", e);
}
}
}