From a72c5239ff04c2dbbe0eac461aefdf557ea687d4 Mon Sep 17 00:00:00 2001 From: Jonas Date: Mon, 28 Mar 2022 00:04:06 +0200 Subject: [PATCH] Added in-code documentation for client & server protocol parsers. --- .../cs108/multiplayer/client/JClientProtocolParser.java | 7 ++++++- .../cs108/multiplayer/server/JServerProtocolParser.java | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java index 2755778..91f0c4e 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java @@ -17,15 +17,20 @@ public class JClientProtocolParser { } catch (IndexOutOfBoundsException e) { System.out.println("Received unknown command"); } - //System.out.println(header); helpful for debugging switch (header) { case "SPING": + //sends a pingback to the server c.sendMsgToServer("PINGB"); break; case "PINGB": + //registers pingback from server c.clientPinger.setGotPingBack(true); break; case "CHATM": + /* prints out incoming chat messages / announcements into the user's console. + * any string that follows CHATM$ is printed as is, so the message that follows + * already has to be formatted the way it should be shown to the client. + */ System.out.println(msg.substring(6)); break; default: 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 c5ef1f1..c82ec9d 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 @@ -16,21 +16,26 @@ public class JServerProtocolParser { } catch (IndexOutOfBoundsException e) { System.out.println("Received unknown command"); } - //System.out.println(header); //helpful for debugging switch (header) { case "CHATA": + //sends chat message to all connected clients h.broadcastMessage(msg.substring(6)); break; case "NAMEC": + //changes name to whatever follows NAMEC$. If the new name is already in use, it will append + //random numbers to the name. h.changeUsername(msg.substring(6)); break; case "CPING": + //sends a pingback to the client h.sendMsgToClient("PINGB"); break; case "PINGB": + //registers pingback from client h.serverPinger.setGotPingBack(true); break; case "QUITS": + //safely disconnects the user h.closeEverything(h.getSocket(), h.getIn(), h.getOut()); break; default: