public class ConnectionManager extends Object implements IServer, Runnable
ConnectionManager
implements the Runnable
interface and needs
to be started as a thread.
It acts as a TCP server listening on port 33098 and implements the IServer interface.
As soon as a new connection is opened, it initializes a new ServerToClientConnection
containing the TCP stream.Constructor and Description |
---|
ConnectionManager(EngineControl engineControl)
Constructor of the ConnectionManager.
|
Modifier and Type | Method and Description |
---|---|
void |
addGame(de.smarten.tsuro.shared.gamemodel.GameModel game,
GameControl control)
Adds a gameModel to the gameModelToClientListMap and initializes it's clientList
with it's Player Objects.
|
void |
addSpectatorToGame(de.smarten.tsuro.shared.gamemodel.Client client,
de.smarten.tsuro.shared.gamemodel.GameModel game) |
void |
connectionResetCallback(de.smarten.tsuro.engine.controller.ConnectionManager.ServerToClientConnection connection,
de.smarten.tsuro.engine.controller.ConnectionManager.ConnectionClient client)
Is called by a connection if it was reset (not if it was closed
via the close method).
|
void |
endGame(de.smarten.tsuro.shared.gamemodel.GameModel game)
Puts the connections of all the clients from the game passed back into the connection pool
and deletes the game from the gameModelToClientListMap.
|
void |
run()
listens on the specified TCP port until stopListening is called.
|
void |
sendFinishedNotification(de.smarten.tsuro.shared.gamemodel.GameModel gameModel)
Sends a FinishedNotification to the clients, informing them about the end of the game
|
void |
sendGameContinueNotification(de.smarten.tsuro.shared.gamemodel.GameModel gameModel)
Sends a ContinueNotification to the clients, acknowledging them that the game continues
|
void |
sendGamePauseNotification(de.smarten.tsuro.shared.gamemodel.GameModel gameModel)
Sends a PauseNotification to the clients, acknowledging them that the game was paused by the host
|
void |
sendGameStartNotification(de.smarten.tsuro.shared.gamemodel.GameModel gameModel)
Used at the beginning of a game to inform all Clients about the game start.
|
void |
sendGameStateNotification(de.smarten.tsuro.shared.gamemodel.GameModel gameModel)
Sends a GameStateNotification to the clients.
|
void |
sendKickNotification(de.smarten.tsuro.shared.gamemodel.GameModel gameModel,
List<de.smarten.tsuro.shared.gamemodel.Player> playerList)
Sends a KickNotification to the clients, telling them that one or more players lost the game
|
void |
sendProcessingRequestReply(de.smarten.tsuro.shared.gamemodel.Client client,
de.smarten.tsuro.shared.gamemodel.JoinResponse state)
Sends a JoinProcessingReply to the client and sets the clientId,
if the state parameter is JOINED_QUEUE or SUCCESS and the client has
no clientId yet.
|
void |
sendTurnNotification(de.smarten.tsuro.shared.gamemodel.GameModel gameModel,
boolean setToken)
Sends a TurnNotification to the clients, notifying them about the beginning of a new turn
|
void |
shutdown()
closes the TCP port and makes the run method terminate
|
void |
start()
Starts the ConnectionManager in a new thread and thus makes it listen
on the specified port.
|
public ConnectionManager(EngineControl engineControl)
engineControl
- the EngineControl initializing the ConnectionManagerpublic void start()
public void run()
public void shutdown()
public void connectionResetCallback(de.smarten.tsuro.engine.controller.ConnectionManager.ServerToClientConnection connection, de.smarten.tsuro.engine.controller.ConnectionManager.ConnectionClient client)
connection
- the connection that was resetclient
- the ConnectionClient belonging to the connection (if the connection has a client object), null otherwisepublic void addGame(de.smarten.tsuro.shared.gamemodel.GameModel game, GameControl control)
game
- the GameModel that should be added to the gameModelToClientListMapcontrol
- the control GameModelpublic void addSpectatorToGame(de.smarten.tsuro.shared.gamemodel.Client client, de.smarten.tsuro.shared.gamemodel.GameModel game) throws IncompleteInputException
IncompleteInputException
public void endGame(de.smarten.tsuro.shared.gamemodel.GameModel game)
game
- the game that should be deletedpublic void sendProcessingRequestReply(de.smarten.tsuro.shared.gamemodel.Client client, de.smarten.tsuro.shared.gamemodel.JoinResponse state)
client
- the client to be notifiedstate
- gives the state of the JoinRequestpublic void sendGameStateNotification(de.smarten.tsuro.shared.gamemodel.GameModel gameModel)
IServer
sendGameStateNotification
in interface IServer
gameModel
- the GameModel of the game in which the clients shall be notifiedpublic void sendGamePauseNotification(de.smarten.tsuro.shared.gamemodel.GameModel gameModel)
IServer
sendGamePauseNotification
in interface IServer
gameModel
- the GameModel of the game in which the clients shall be notifiedpublic void sendGameContinueNotification(de.smarten.tsuro.shared.gamemodel.GameModel gameModel)
IServer
sendGameContinueNotification
in interface IServer
gameModel
- the GameModel of the game in which the clients shall be notifiedpublic void sendFinishedNotification(de.smarten.tsuro.shared.gamemodel.GameModel gameModel)
IServer
sendFinishedNotification
in interface IServer
gameModel
- the GameModel of the game in which the clients shall be notifiedpublic void sendKickNotification(de.smarten.tsuro.shared.gamemodel.GameModel gameModel, List<de.smarten.tsuro.shared.gamemodel.Player> playerList)
IServer
sendKickNotification
in interface IServer
gameModel
- the GameModel of the game in which the clients shall be notifiedplayerList
- the list of players who were kickedpublic void sendTurnNotification(de.smarten.tsuro.shared.gamemodel.GameModel gameModel, boolean setToken)
IServer
sendTurnNotification
in interface IServer
gameModel
- the GameModel of the game in which the clients shall be notifiedsetToken
- whether to ask the client for a token position instead of a placementpublic void sendGameStartNotification(de.smarten.tsuro.shared.gamemodel.GameModel gameModel)
IServer
sendGameStartNotification
in interface IServer
gameModel
- the GameModel of the game in which the clients shall be notifiedCopyright © 2017 smarTen. All rights reserved.