|
|
@ -99,7 +99,18 @@ GameType check_server_client(int argc, char** argv) {
|
|
|
|
connect_code = std::string(argv[2]); /* The connect code is a special string, that contains the server address and port. It is given by the server. */
|
|
|
|
connect_code = std::string(argv[2]); /* The connect code is a special string, that contains the server address and port. It is given by the server. */
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
addr_port = connect_code::decode(connect_code);
|
|
|
|
addr_port = connect_code::decode(connect_code);
|
|
|
|
Client* client = new Client(4, ES_UDP, addr_port[0].data(), std::stoi(addr_port[1]));
|
|
|
|
/* Check IP address version */
|
|
|
|
|
|
|
|
int ip_ver = 0;
|
|
|
|
|
|
|
|
if (check_ip_ver(addr_port[0].data()) < 0) {
|
|
|
|
|
|
|
|
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->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 */
|
|
|
|
client->sendAll("GG");
|
|
|
|
client->sendAll("GG");
|
|
|
@ -148,7 +159,7 @@ GameType check_server_client(int argc, char** argv) {
|
|
|
|
std::cout << "Your code is " << code << std::endl;
|
|
|
|
std::cout << "Your code is " << code << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
/* Create server socket and wait for client to connect */
|
|
|
|
/* Create server socket and wait for client to connect */
|
|
|
|
Server* server = new Server(4, ES_UDP, addr.data(), port);
|
|
|
|
Server* server = new Server(ES_UDP, addr.data(), port);
|
|
|
|
server->create_socket();
|
|
|
|
server->create_socket();
|
|
|
|
std::cout << "Waiting for connection..." << std::endl;
|
|
|
|
std::cout << "Waiting for connection..." << std::endl;
|
|
|
|
std::string response = "";
|
|
|
|
std::string response = "";
|
|
|
|