mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-01-18 22:56:15 +01:00
server doc
This commit is contained in:
parent
957bf8ffcc
commit
95b9da9377
@ -70,7 +70,7 @@ import pp.monopoly.model.fields.TestStreckeField;
|
||||
import pp.monopoly.model.fields.WacheField;
|
||||
|
||||
/**
|
||||
* Server implementing the visitor pattern as MessageReceiver for ClientMessages
|
||||
* MonopolyServer implementing the visitor pattern as MessageReceiver for ClientMessages
|
||||
*/
|
||||
public class MonopolyServer implements MessageListener<HostedConnection>, ConnectionListener, ServerSender {
|
||||
private static final Logger LOGGER = System.getLogger(MonopolyServer.class.getName());
|
||||
@ -109,12 +109,18 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
||||
logic = new ServerGameLogic(this, config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run is executed on StartUp
|
||||
*/
|
||||
public void run() {
|
||||
startServer();
|
||||
while (true)
|
||||
processNextMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the Server
|
||||
*/
|
||||
private void startServer() {
|
||||
try {
|
||||
LOGGER.log(Level.INFO, "Starting server..."); //NON-NLS
|
||||
@ -130,6 +136,9 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processesthe next incoming message
|
||||
*/
|
||||
private void processNextMessage() {
|
||||
try {
|
||||
pendingMessages.take().process(logic);
|
||||
@ -140,6 +149,9 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize alls Messages and Classes that need to be sent
|
||||
*/
|
||||
private void initializeSerializables() {
|
||||
Serializer.registerClass(IntPoint.class);
|
||||
Serializer.registerClass(BuyPropertyResponse.class);
|
||||
@ -182,6 +194,9 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
||||
Serializer.registerClass(GameOver.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all message listeners
|
||||
*/
|
||||
private void registerListeners() {
|
||||
myServer.addMessageListener(this, BuyPropertyResponse.class);
|
||||
myServer.addMessageListener(this, EndTurn.class);
|
||||
@ -220,6 +235,10 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the server
|
||||
* @param exitValue the exit code to throw
|
||||
*/
|
||||
private void exit(int exitValue) { //NON-NLS
|
||||
LOGGER.log(Level.INFO, "close request"); //NON-NLS
|
||||
if (myServer != null)
|
||||
|
@ -10,6 +10,9 @@ package pp.monopoly.server;
|
||||
import pp.monopoly.message.client.ClientInterpreter;
|
||||
import pp.monopoly.message.client.ClientMessage;
|
||||
|
||||
/**
|
||||
* Record to process incoming Client Messages
|
||||
*/
|
||||
record ReceivedMessage(ClientMessage message, int from) {
|
||||
void process(ClientInterpreter interpreter) {
|
||||
message.accept(interpreter, from);
|
||||
|
Loading…
Reference in New Issue
Block a user