From c6fc8e45ff48f3d537f3254d1eceda3d02200c63 Mon Sep 17 00:00:00 2001 From: Themaister Date: Wed, 11 Jan 2012 21:08:44 +0100 Subject: [PATCH] Log more clearly disconnects. --- netplay.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/netplay.c b/netplay.c index 9df2c93db0..fd43730a6b 100644 --- a/netplay.c +++ b/netplay.c @@ -156,7 +156,7 @@ int16_t input_state_net(bool port, unsigned device, unsigned index, unsigned id) return netplay_callbacks(g_extern.netplay)->state_cb(port, device, index, id); } -static void log_connection(const struct sockaddr_storage *their_addr) +static void log_connection(const struct sockaddr_storage *their_addr, unsigned slot) { union { @@ -195,7 +195,7 @@ static void log_connection(const struct sockaddr_storage *their_addr) if (str) { char msg[512]; - snprintf(msg, sizeof(msg), "Got connection from: \"%s\"", str); + snprintf(msg, sizeof(msg), "Got connection from: \"%s\" (#%u)", str, slot); msg_queue_push(g_extern.msg_queue, msg, 1, 180); } } @@ -282,7 +282,7 @@ static bool init_tcp_socket(netplay_t *handle, const char *server, uint16_t port close(handle->fd); handle->fd = new_fd; - log_connection(&their_addr); + log_connection(&their_addr, 0); } freeaddrinfo(res); @@ -586,7 +586,9 @@ static bool send_chunk(netplay_t *handle) if (addr) { - if (sendto(handle->udp_fd, CONST_CAST handle->packet_buffer, sizeof(handle->packet_buffer), 0, addr, sizeof(struct sockaddr)) != sizeof(handle->packet_buffer)) + if (sendto(handle->udp_fd, CONST_CAST handle->packet_buffer, + sizeof(handle->packet_buffer), 0, addr, + sizeof(struct sockaddr)) != sizeof(handle->packet_buffer)) { warn_hangup(); handle->has_connection = false; @@ -782,8 +784,6 @@ static bool netplay_poll(netplay_t *handle) } } - //fprintf(stderr, "After poll: Other ptr: %lu, Read ptr: %lu, Self ptr: %lu\n", handle->other_ptr, handle->read_ptr, handle->self_ptr); - if (handle->read_ptr != handle->self_ptr) simulate_input(handle); else @@ -983,7 +983,7 @@ static void netplay_pre_frame_spectate(netplay_t *handle) free(header); handle->spectate_fds[index] = new_fd; - log_connection(&their_addr); + log_connection(&their_addr, index); } void netplay_pre_frame(netplay_t *handle) @@ -1055,7 +1055,12 @@ static void netplay_post_frame_spectate(netplay_t *handle) ssize_t ret = send(handle->spectate_fds[i], CONST_CAST tmp_buf, send_size, 0); if (ret <= 0) { - SSNES_LOG("Client disconnected ...\n"); + SSNES_LOG("Client (#%u) disconnected ...\n", i); + + char msg[512]; + snprintf(msg, sizeof(msg), "Client (#%u) disconnected!", i); + msg_queue_push(g_extern.msg_queue, msg, 1, 180); + close(handle->spectate_fds[i]); handle->spectate_fds[i] = -1; break;