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) { } catch (IndexOutOfBoundsException e) {
System.out.println("Received unknown command"); System.out.println("Received unknown command");
} }
//System.out.println(header); helpful for debugging
switch (header) { switch (header) {
case "SPING": case "SPING":
//sends a pingback to the server
c.sendMsgToServer("PINGB"); c.sendMsgToServer("PINGB");
break; break;
case "PINGB": case "PINGB":
//registers pingback from server
c.clientPinger.setGotPingBack(true); c.clientPinger.setGotPingBack(true);
break; break;
case "CHATM": 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)); System.out.println(msg.substring(6));
break; break;
default: default:

View File

@ -16,21 +16,26 @@ public class JServerProtocolParser {
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
System.out.println("Received unknown command"); System.out.println("Received unknown command");
} }
//System.out.println(header); //helpful for debugging
switch (header) { switch (header) {
case "CHATA": case "CHATA":
//sends chat message to all connected clients
h.broadcastMessage(msg.substring(6)); h.broadcastMessage(msg.substring(6));
break; break;
case "NAMEC": 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)); h.changeUsername(msg.substring(6));
break; break;
case "CPING": case "CPING":
//sends a pingback to the client
h.sendMsgToClient("PINGB"); h.sendMsgToClient("PINGB");
break; break;
case "PINGB": case "PINGB":
//registers pingback from client
h.serverPinger.setGotPingBack(true); h.serverPinger.setGotPingBack(true);
break; break;
case "QUITS": case "QUITS":
//safely disconnects the user
h.closeEverything(h.getSocket(), h.getIn(), h.getOut()); h.closeEverything(h.getSocket(), h.getIn(), h.getOut());
break; break;
default: default: