src/server.c

changeset 34
c4d4b8a8f902
parent 30
a285ee393860
child 46
4dcfb4c58b6d
equal deleted inserted replaced
33:866025982aa9 34:c4d4b8a8f902
33 33
34 static int server_open(Server *server, char *port) { 34 static int server_open(Server *server, char *port) {
35 printw("\nListening for client...\n"); 35 printw("\nListening for client...\n");
36 refresh(); 36 refresh();
37 if (net_create(server, port)) { 37 if (net_create(server, port)) {
38 perror("Server creation failed"); 38 addstr("Server creation failed");
39 return 1; 39 return 1;
40 } 40 }
41 41
42 if (net_listen(server)) { 42 if (net_listen(server)) {
43 perror("Listening for client failed"); 43 addstr("Listening for client failed");
44 return 1; 44 return 1;
45 } 45 }
46 46
47 return 0; 47 return 0;
48 } 48 }
49 49
50 static int server_handshake(Client *client) { 50 static int server_handshake(Client *client) {
51 net_send_code(client->fd, NETCODE_VERSION); 51 net_send_code(client->fd, NETCODE_VERSION);
52 if (net_recieve_code(client->fd) != NETCODE_VERSION) { 52 if (net_recieve_code(client->fd) != NETCODE_VERSION) {
53 fprintf(stderr, "Client uses an incompatible software version.\n"); 53 addstr("Client uses an incompatible software version.");
54 return 1; 54 return 1;
55 } 55 }
56 56
57 printw("Client connected - transmitting gameinfo..."); 57 printw("Client connected - transmitting gameinfo...");
58 refresh(); 58 refresh();
88 game_start(settings, fd); 88 game_start(settings, fd);
89 } else if (code == NETCODE_DECLINE) { 89 } else if (code == NETCODE_DECLINE) {
90 printw("\rClient connected - challenge declined."); 90 printw("\rClient connected - challenge declined.");
91 clrtoeol(); 91 clrtoeol();
92 } else { 92 } else {
93 fprintf(stderr, "Invalid client response\n"); 93 addstr("\rInvalid client response");
94 clrtoeol();
95
94 net_destroy(&server); 96 net_destroy(&server);
95 return EXIT_FAILURE; 97 return EXIT_FAILURE;
96 } 98 }
97 99
98 net_destroy(&server); 100 net_destroy(&server);

mercurial