Added in-code documentation for client & server protocol parsers.

This commit is contained in:
Jonas 2022-03-28 00:04:06 +02:00
parent ae7bff2a6f
commit a72c5239ff
2 changed files with 12 additions and 2 deletions

View File

@ -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:

View File

@ -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: