#include "client.h" #include #include #include #include #include #include #include #include #include #include "net.h" #include "game.h" #include "filesystem.h" int runClient(int argc, char* argv[]) { player_t myPlayer = player_t::NUM_INVALID; // My player int sockfd; // socket File descriptor int portno; // Port number int n = 0; // return value for read and write calls struct sockaddr_in serv_addr; // Server address struct hostent *server; // pointer to host information char buffer[1028]; // buffer for socket read memset(buffer,0,sizeof(buffer)); // must provide information if (argc < 2) { fprintf(stderr,"usage %s hostname\n", argv[0]); exit(0); } // Get port number portno = TTRTS_PORT; // Create a new socket // AF_INET is general internetsocket domain // SOCK_STREAM as messages will be read in on this socket, SOCK_DGRAM would be for packets // 0 is for default protocol sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) fatal_perror("ERROR opening socket"); // Get the hostent information for the host by name server = gethostbyname(argv[1]); if (server == NULL) fatal_error("ERROR, no such host"); std::cout<<"TTRTS: Connecting to "<h_addr, server->h_length); // Set our server address port to the port number provided serv_addr.sin_port = htons(portno); // Attempt to connect to the server using the socket and server address info if (connect(sockfd, (const sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) fatal_perror("ERROR connecting"); unsigned int player; std::string gameNameString; PerformClientHandshake(sockfd, player, gameNameString); myPlayer = (player_t)player; std::cout<<"TTRTS: I am player "<= 0 ) { std::cout<<"TTRTS: Waiting for gamestate"<