/**
* @return the next message from input-stream (client-socket)
*/
public ServerMessage getNextMessage() throws IOException {
ServerMessage messageObject = null;
synchronized (bufferedReader) {
messageString = "";
messageString = this.bufferedReader.readLine();
}
if (messageString.length() < 1) {
System.out.println(messageString);
messageString = "I catched a verry silly bug!";
}
logger.info("MSG:" + messageString);
if (BuildTowerRoundMessage.PATTERN.matcher(messageString).matches()) {
messageObject = new BuildTowerRoundMessage();
} else if (BuildCreepRoundMessage.PATTERN.matcher(messageString)
.matches()) {
messageObject = new BuildCreepRoundMessage();
} else if (CreateGameResponseMessage.PATTERN.matcher(messageString)
.matches()) {
messageObject = new CreateGameResponseMessage();
} else if (ErrorMessage.PATTERN.matcher(messageString).matches()) {
messageObject = new ErrorMessage();
} else if (GamesMessage.PATTERN.matcher(messageString).matches()) {
messageObject = new GamesMessage();
} else if (HighscoreResponseMessage.PATTERN.matcher(messageString)
.matches()) {
messageObject = new HighscoreResponseMessage();
} else if (JoinGameResponseMessage.PATTERN.matcher(messageString)
.matches()) {
messageObject = new JoinGameResponseMessage();
} else if (LoginResponseMessage.PATTERN.matcher(messageString)
.matches()) {
messageObject = new LoginResponseMessage();
} else if (MessageMessage.PATTERN.matcher(messageString).matches()) {
messageObject = new MessageMessage();
} else if (PlayerJoinedMessage.PATTERN.matcher(messageString)
.matches()) {
messageObject = new PlayerJoinedMessage();
} else if (PlayerQuitMessage.PATTERN.matcher(messageString)
.matches()) {
messageObject = new PlayerQuitMessage();
} else if (PlayersMessage.PATTERN.matcher(messageString).matches()) {
messageObject = new PlayersMessage();
} else if (RegistrationResponseMessage.PATTERN.matcher(
messageString).matches()) {
messageObject = new RegistrationResponseMessage();
} else if (RoundMessage.PATTERN.matcher(messageString).matches()) {
messageObject = new RoundMessage();
} else if (SellTowerRoundMessage.PATTERN.matcher(messageString)
.matches()) {
messageObject = new SellTowerRoundMessage();
}else if (ChangeStrategyRoundMessage.PATTERN.matcher(messageString)
.matches()) {
messageObject = new ChangeStrategyRoundMessage();
}else if (StartGameMessage.PATTERN.matcher(messageString)
.matches()) {
messageObject = new StartGameMessage();
} else if (StartGameResponseMessage.PATTERN.matcher(messageString)
.matches()) {
messageObject = new StartGameResponseMessage();
} else if (UpgradeTowerRoundMessage.PATTERN.matcher(messageString)
.matches()) {
messageObject = new UpgradeTowerRoundMessage();
} else if (KickedMessage.PATTERN.matcher(messageString).matches()) {
messageObject = new KickedMessage();
} else if (KickPlayerResponseMessage.PATTERN.matcher(messageString)
.matches()) {
messageObject = new KickPlayerResponseMessage();
} else if (PingMessage.PATTERN.matcher(messageString).matches()) {
messageObject = new PingMessage();
} else if (UpdateDataResponseMessage.PATTERN.matcher(messageString)
.matches()) {
messageObject = new UpdateDataResponseMessage();
} else if (ScoreResponseMessage.PATTERN.matcher(messageString)
.matches()) {
messageObject = new ScoreResponseMessage();
} else if (DeleteResponseMessage.PATTERN.matcher(messageString)
.matches()) {
messageObject = new DeleteResponseMessage();
} else if (PasswordResetResponseMessage.PATTERN.matcher(messageString)
.matches()) {
messageObject = new PasswordResetResponseMessage();
} else {
// TODO logging
System.err.println("Invalid message:\"" + messageString + "\"");
}
if (messageObject != null) {
messageObject.initWithMessage(messageString);
System.out.println(messageObject.getMessageString());
}
return messageObject;
}