From 09024dbfada3d91ee25384f6ab593696329b95fe Mon Sep 17 00:00:00 2001 From: Seraina Date: Sat, 9 Apr 2022 08:38:59 +0200 Subject: [PATCH] Parser sets the clientHandler fields vote and hasVoted after a vote from a client has come in --- .../multiplayer/server/JServerProtocolParser.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java index bd8ae30..eddceed 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java @@ -70,10 +70,18 @@ public class JServerProtocolParser { LOGGER.debug(Protocol.listLobbies + " command received from: " + h.getClientUserName()); break; case Protocol.votedFor: - int vote = Integer.parseInt(msg.substring(6)); - if(vote != Integer.MAX_VALUE) { - //TODO(SERAINA): do smt + int vote = Integer.MAX_VALUE; + try { + vote = Integer.parseInt(msg.substring(6)); + } catch (Exception e) { + LOGGER.warn("Invalid vote " + e.getMessage()); + } finally { + if(vote != Integer.MAX_VALUE) { //gets MAX_VALUE when the vote wasn't valid + h.setVote(vote); + h.setHasVoted(true); + } } + break; case Protocol.startANewGame: try {