|
@@ -36,14 +36,14 @@ bool MultiPlayer_alloc(
|
|
|
struct protoent *proto = getprotobyname("tcp");
|
|
struct protoent *proto = getprotobyname("tcp");
|
|
|
mp->sock = socket(AF_INET, SOCK_STREAM, proto->p_proto);
|
|
mp->sock = socket(AF_INET, SOCK_STREAM, proto->p_proto);
|
|
|
if (mp->sock == -1) {
|
|
if (mp->sock == -1) {
|
|
|
- LOG_FATALF("socket failed: %d %s", errno, strerror(errno));
|
|
|
|
|
|
|
+ SE_LOG_FATALF("socket failed: %d %s", errno, strerror(errno));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
struct in_addr server_addr;
|
|
struct in_addr server_addr;
|
|
|
int res = inet_aton(server_host, &server_addr);
|
|
int res = inet_aton(server_host, &server_addr);
|
|
|
if (res == 0) {
|
|
if (res == 0) {
|
|
|
close(mp->sock);
|
|
close(mp->sock);
|
|
|
- LOG_FATAL("inet_aton failed");
|
|
|
|
|
|
|
+ SE_LOG_FATAL("inet_aton failed");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
struct sockaddr_in server_sockaddr = {
|
|
struct sockaddr_in server_sockaddr = {
|
|
@@ -59,16 +59,16 @@ bool MultiPlayer_alloc(
|
|
|
);
|
|
);
|
|
|
if (res == -1) {
|
|
if (res == -1) {
|
|
|
close(mp->sock);
|
|
close(mp->sock);
|
|
|
- LOG_ERRORF("connect failed: %d %s", errno, strerror(errno));
|
|
|
|
|
|
|
+ SE_LOG_ERRORF("connect failed: %d %s", errno, strerror(errno));
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- LOG("Connected to server");
|
|
|
|
|
|
|
+ SE_LOG("Connected to server");
|
|
|
|
|
|
|
|
mp->conn_s = fdopen(mp->sock, "r+");
|
|
mp->conn_s = fdopen(mp->sock, "r+");
|
|
|
if (mp->conn_s == nullptr) {
|
|
if (mp->conn_s == nullptr) {
|
|
|
close(mp->sock);
|
|
close(mp->sock);
|
|
|
- LOG_ERRORF("fdopen failed: (%d) %s", errno, strerror(errno));
|
|
|
|
|
|
|
+ SE_LOG_ERRORF("fdopen failed: (%d) %s", errno, strerror(errno));
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -76,78 +76,78 @@ bool MultiPlayer_alloc(
|
|
|
if (recv_msg_type(mp->conn_s, &msg_type) == ECONNRESET) {
|
|
if (recv_msg_type(mp->conn_s, &msg_type) == ECONNRESET) {
|
|
|
fclose(mp->conn_s);
|
|
fclose(mp->conn_s);
|
|
|
close(mp->sock);
|
|
close(mp->sock);
|
|
|
- LOG_ERROR("Connection reset");
|
|
|
|
|
|
|
+ SE_LOG_ERROR("Connection reset");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
if (msg_type != NET_MSG_IS_PLAYER_1) {
|
|
if (msg_type != NET_MSG_IS_PLAYER_1) {
|
|
|
fclose(mp->conn_s);
|
|
fclose(mp->conn_s);
|
|
|
close(mp->sock);
|
|
close(mp->sock);
|
|
|
- LOG_ERRORF("Did not get IS_PLAYER_1 msg, got: %u", msg_type);
|
|
|
|
|
|
|
+ SE_LOG_ERRORF("Did not get IS_PLAYER_1 msg, got: %u", msg_type);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
IsPlayer1Msg p1_msg = { 0 };
|
|
IsPlayer1Msg p1_msg = { 0 };
|
|
|
if (!recv_msg(mp->conn_s, NET_MSG_IS_PLAYER_1, (uint8_t *) &p1_msg)) {
|
|
if (!recv_msg(mp->conn_s, NET_MSG_IS_PLAYER_1, (uint8_t *) &p1_msg)) {
|
|
|
fclose(mp->conn_s);
|
|
fclose(mp->conn_s);
|
|
|
close(mp->sock);
|
|
close(mp->sock);
|
|
|
- LOG_ERROR("Connection reset");
|
|
|
|
|
|
|
+ SE_LOG_ERROR("Connection reset");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
mp->is_player_1 = (bool) p1_msg.player1;
|
|
mp->is_player_1 = (bool) p1_msg.player1;
|
|
|
if (mp->is_player_1) {
|
|
if (mp->is_player_1) {
|
|
|
- LOG("I am player 1");
|
|
|
|
|
|
|
+ SE_LOG("I am player 1");
|
|
|
} else {
|
|
} else {
|
|
|
- LOG("I am player 2");
|
|
|
|
|
|
|
+ SE_LOG("I am player 2");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- LOG("Waiting for game start");
|
|
|
|
|
|
|
+ SE_LOG("Waiting for game start");
|
|
|
|
|
|
|
|
mp->state = GameState_new(game_default_params, false);
|
|
mp->state = GameState_new(game_default_params, false);
|
|
|
|
|
|
|
|
if (recv_msg_type(mp->conn_s, &msg_type) == ECONNRESET) {
|
|
if (recv_msg_type(mp->conn_s, &msg_type) == ECONNRESET) {
|
|
|
fclose(mp->conn_s);
|
|
fclose(mp->conn_s);
|
|
|
close(mp->sock);
|
|
close(mp->sock);
|
|
|
- LOG_ERROR("Connection reset");
|
|
|
|
|
|
|
+ SE_LOG_ERROR("Connection reset");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
if (msg_type != NET_MSG_GAME_STATE) {
|
|
if (msg_type != NET_MSG_GAME_STATE) {
|
|
|
fclose(mp->conn_s);
|
|
fclose(mp->conn_s);
|
|
|
close(mp->sock);
|
|
close(mp->sock);
|
|
|
- LOG_FATALF("[MultiPlayer_alloc] Did not get GAME_STATE msg, got: %u", msg_type);
|
|
|
|
|
|
|
+ SE_LOG_FATALF("[MultiPlayer_alloc] Did not get GAME_STATE msg, got: %u", msg_type);
|
|
|
}
|
|
}
|
|
|
if (!handle_game_state_msg(mp)) {
|
|
if (!handle_game_state_msg(mp)) {
|
|
|
fclose(mp->conn_s);
|
|
fclose(mp->conn_s);
|
|
|
close(mp->sock);
|
|
close(mp->sock);
|
|
|
- LOG_ERROR("Connection reset");
|
|
|
|
|
|
|
+ SE_LOG_ERROR("Connection reset");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (recv_msg_type(mp->conn_s, &msg_type) == ECONNRESET) {
|
|
if (recv_msg_type(mp->conn_s, &msg_type) == ECONNRESET) {
|
|
|
fclose(mp->conn_s);
|
|
fclose(mp->conn_s);
|
|
|
close(mp->sock);
|
|
close(mp->sock);
|
|
|
- LOG_ERROR("Connection reset");
|
|
|
|
|
|
|
+ SE_LOG_ERROR("Connection reset");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
if (msg_type != NET_MSG_GAME_START) {
|
|
if (msg_type != NET_MSG_GAME_START) {
|
|
|
fclose(mp->conn_s);
|
|
fclose(mp->conn_s);
|
|
|
close(mp->sock);
|
|
close(mp->sock);
|
|
|
- LOG_FATALF("[MultiPlayer_alloc] Did not get GAME_START msg, got: %u", msg_type);
|
|
|
|
|
|
|
+ SE_LOG_FATALF("[MultiPlayer_alloc] Did not get GAME_START msg, got: %u", msg_type);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!send_msg(mp->conn_s, NET_MSG_GAME_START, nullptr)) {
|
|
if (!send_msg(mp->conn_s, NET_MSG_GAME_START, nullptr)) {
|
|
|
fclose(mp->conn_s);
|
|
fclose(mp->conn_s);
|
|
|
close(mp->sock);
|
|
close(mp->sock);
|
|
|
- LOG_ERROR("Connection reset");
|
|
|
|
|
|
|
+ SE_LOG_ERROR("Connection reset");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (fcntl(mp->sock, F_SETFL, O_NONBLOCK) != 0) {
|
|
if (fcntl(mp->sock, F_SETFL, O_NONBLOCK) != 0) {
|
|
|
fclose(mp->conn_s);
|
|
fclose(mp->conn_s);
|
|
|
close(mp->sock);
|
|
close(mp->sock);
|
|
|
- LOG_ERRORF("fcntl failed on mp->sock: (%d) %s", errno, strerror(errno));
|
|
|
|
|
|
|
+ SE_LOG_ERRORF("fcntl failed on mp->sock: (%d) %s", errno, strerror(errno));
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- LOG("Game started");
|
|
|
|
|
|
|
+ SE_LOG("Game started");
|
|
|
|
|
|
|
|
mp->screen_w = screen_w;
|
|
mp->screen_w = screen_w;
|
|
|
mp->screen_h = screen_h;
|
|
mp->screen_h = screen_h;
|
|
@@ -190,7 +190,7 @@ static void handle_score_update_msg(MultiPlayer *const mp) {
|
|
|
recv_msg(mp->conn_s, NET_MSG_SCORE_UPDATE, (uint8_t *) &msg);
|
|
recv_msg(mp->conn_s, NET_MSG_SCORE_UPDATE, (uint8_t *) &msg);
|
|
|
mp->state.score_l = msg.l_score;
|
|
mp->state.score_l = msg.l_score;
|
|
|
mp->state.score_r = msg.r_score;
|
|
mp->state.score_r = msg.r_score;
|
|
|
- LOGF("score_l: %d score_r: %d", mp->state.score_l, mp->state.score_r);
|
|
|
|
|
|
|
+ SE_LOGF("score_l: %d score_r: %d", mp->state.score_l, mp->state.score_r);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void handle_input(
|
|
static void handle_input(
|
|
@@ -249,15 +249,15 @@ Screen MultiPlayer_tick(MultiPlayer *const mp, const double delta) {
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
} else if (res == ECONNRESET) {
|
|
} else if (res == ECONNRESET) {
|
|
|
- LOG_ERROR("Connection reset");
|
|
|
|
|
|
|
+ SE_LOG_ERROR("Connection reset");
|
|
|
return PONG_MAIN_MENU;
|
|
return PONG_MAIN_MENU;
|
|
|
} else if (res == EWOULDBLOCK) {
|
|
} else if (res == EWOULDBLOCK) {
|
|
|
break;
|
|
break;
|
|
|
} else {
|
|
} else {
|
|
|
- LOG_FATALF("[MultiPlayer_tick] Unhandled return value: %d", res);
|
|
|
|
|
|
|
+ SE_LOG_FATALF("[MultiPlayer_tick] Unhandled return value: %d", res);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // LOGF("Got message: %s", NetMsgType_to_str(msg_type));
|
|
|
|
|
|
|
+ // SE_LOGF("Got message: %s", NetMsgType_to_str(msg_type));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool dir_changed = false;
|
|
bool dir_changed = false;
|
|
@@ -275,7 +275,7 @@ Screen MultiPlayer_tick(MultiPlayer *const mp, const double delta) {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
if (!send_msg(mp->conn_s, NET_MSG_PADDLE_CHANGE_DIR, (uint8_t *) &msg)) {
|
|
if (!send_msg(mp->conn_s, NET_MSG_PADDLE_CHANGE_DIR, (uint8_t *) &msg)) {
|
|
|
- LOG_ERROR("Connection reset");
|
|
|
|
|
|
|
+ SE_LOG_ERROR("Connection reset");
|
|
|
return PONG_MAIN_MENU;
|
|
return PONG_MAIN_MENU;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|