@@ -31,10 +31,11 @@ class GameProtocolServer {
3131 * serialization of data and the socket communication. It should be paired at the other end
3232 * with a GameProtocolClient
3333 *
34- * For GameProtocolServer to be fully constructed it will wait for an inbound socket
35- * connection. This means that until a client connects, this class will not be fully
36- * constructed. A GameProtocolServer already instantiated object naturally means it has
37- * previously established a connection with a client
34+ * It has the ownership of the main socket of the server
35+ * It serves as a translation layer for other classes that has ownership of their own sockets
36+ *
37+ * A mutex is used to ensure that a race condition is not possible when reading the state of
38+ * the main socket
3839 */
3940 explicit GameProtocolServer (const std::string& servname);
4041
@@ -53,42 +54,63 @@ class GameProtocolServer {
5354 GameProtocolServer& operator =(GameProtocolServer&&) = default ;
5455
5556 /*
56- * Receives action codes from inbound_client until the end_of_sequence action code is sent
57+ * Returns the Socket of an accepted connection to the main server socket
5758 */
58- // const std::vector<std::string> get_action_sequence ();
59+ Socket accept_client ();
5960
6061 /*
61- * Returns true if the connection with the inbound_client is still alive. Return false
62- * if it has closed
62+ * Returns true if the main server socket is closed or false otherwise
6363 */
64- // const bool is_client_connection_alive() const ;
64+ const bool is_socket_closed () ;
6565
6666 /*
67- * Sends to inbound_client as a halfword (2 bytes) the header of the payload (size of the
68- * payload) and then sends bytewise the payload (binary representation of a string)
67+ * Returns true if the input command string is an attack command, returns false otherwise
6968 */
70- // void send_action_sequence_with_combos(const std::string& combo_response);
71-
72- Socket accept_client ();
73-
74- const bool is_socket_closed ();
75-
7669 const bool is_command_attack (const std::string& command) const ;
7770
71+ /*
72+ * Builds and returns a GameMessage that represents a death event with the corresponding
73+ * parameters
74+ */
7875 const GameMessage get_message_for_death_event (const uint16_t enemies_alive,
7976 const uint16_t enemies_dead) const ;
8077
78+ /*
79+ * Builds and returns a GameMessage that represents a revival event with the corresponding
80+ * parameters
81+ */
8182 const GameMessage get_message_for_revival_event (const uint16_t enemies_alive,
8283 const uint16_t enemies_dead) const ;
8384
85+ /*
86+ * Sends a complete message to the client. First a byte for signaling the beginning of the
87+ * broadcast then it sends 2 halfwords (each one of 2 bytes) representing the number of enemies
88+ * alive and dead, in that order, and finally it sends a byte for signaling if an enemy has been
89+ * killed or has revived
90+ */
8491 void send_message_to_client (Socket& client_skt, const GameMessage& message, bool & was_closed);
8592
93+ /*
94+ * Receives a byte from the client_skt that represents the desired command. Returns that
95+ * command name
96+ */
8697 const std::string receive_message_from_client (Socket& client_skt, bool & was_closed);
8798
99+ /*
100+ * Prints to std::out the current death event with the number of enemies alive and dead
101+ * represented by the params
102+ */
88103 void print_death_in_server (const uint16_t & enemies_alive, const uint16_t & enemies_dead) const ;
89104
105+ /*
106+ * Prints to std::out the current revival event with the number of enemies alive and dead
107+ * represented by the params
108+ */
90109 void print_revival_in_server (const uint16_t & enemies_alive, const uint16_t & enemies_dead) const ;
91110
111+ /*
112+ * Shutdowns and closes the main server socket
113+ */
92114 void turn_off_connections ();
93115};
94116
0 commit comments