Removed IP version checking code (since this is handled in the Sock constructor), and allowed server (but not client, yet) to quit game before round start

master
Aadhavan Srinivasan 10 months ago
parent 727aeafdb9
commit 66d7585297

@ -100,16 +100,9 @@ GameType check_server_client(int argc, char** argv) {
try { try {
addr_port = connect_code::decode(connect_code); addr_port = connect_code::decode(connect_code);
/* Check IP address version */ /* Check IP address version */
int ip_ver = 0;
if (check_ip_ver(addr_port[0].data()) < 0) { if (check_ip_ver(addr_port[0].data()) < 0) {
throw std::invalid_argument("Invalid code entered."); throw std::invalid_argument("Invalid code entered.");
} }
/* From here, assume address is either IPv4 or IPv6 */
if (check_ip_ver(addr_port[0].data()) == 4) {
ip_ver = 4;
} else {
ip_ver = 6;
}
Client* client = new Client(ES_UDP, addr_port[0].data(), std::stoi(addr_port[1])); Client* client = new Client(ES_UDP, addr_port[0].data(), std::stoi(addr_port[1]));
client->create_socket(); client->create_socket();
/* Send a specific message to the server, and wait for the appropriate response, to know that the server is ready */ /* Send a specific message to the server, and wait for the appropriate response, to know that the server is ready */
@ -387,11 +380,18 @@ int main(int argc, char** argv) {
} }
} }
/* For client (wait for start message from server) */ /* For client (wait for start or quit message from server): When the peer quits the
game, it sends a serialized struct, containing all zeros, with the last bit turned
on as a flag. We catch this zero bit, as it indicates that the peer quit the game. */
if (type.mode == M_CLIENT) { if (type.mode == M_CLIENT) {
do { do {
response = type.netsock->recvAll(); response = type.netsock->recvAll();
} while (response[0] != 'S'); } while (response[0] != 'S' && response[0] != 0);
if (response[0] == 0) {
CloseWindow();
std::cout << "Peer unexpectedly quit game." << std::endl;
return -1;
}
game_started = true; game_started = true;
std::cout << "Game has been started by server." << std::endl; std::cout << "Game has been started by server." << std::endl;
} }

Loading…
Cancel
Save