From 966335e367f5b40856065bb4036b57b2d9557e2a Mon Sep 17 00:00:00 2001 From: Cthulhu-throwaway <96153783+Cthulhu-throwaway@users.noreply.github.com> Date: Tue, 21 Dec 2021 11:58:25 -0300 Subject: [PATCH] Smaller Netplay Changes (#13387) Lobby Viewer: Filter out rooms that are not running RetroArch Lobby Viewer: Display a non-connectable tag to non-connectable rooms. Host: Display warning if we are announcing to the internet but our room isn't connectable from there. --- intl/msg_hash_us.h | 8 ++++++++ menu/cbs/menu_cbs_ok.c | 2 ++ menu/menu_displaylist.c | 8 +++++++- msg_hash.h | 2 ++ network/netplay/netplay.h | 2 ++ network/netplay/netplay_frontend.c | 15 +++++++++++++++ network/netplay/netplay_room_parse.c | 11 +++++++++++ 7 files changed, 47 insertions(+), 1 deletion(-) diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 56b06c0241..760d30f1ce 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -10869,6 +10869,10 @@ MSG_HASH( MSG_WAITING_FOR_CLIENT, "Waiting for client ..." ) +MSG_HASH( + MSG_ROOM_NOT_CONNECTABLE, + "Your room is not connectable from the internet." + ) MSG_HASH( MSG_NETPLAY_YOU_HAVE_LEFT_THE_GAME, "You have left the game" @@ -12771,6 +12775,10 @@ MSG_HASH( MSG_INTERNET_RELAY, "Internet (Relay)" ) +MSG_HASH( + MSG_INTERNET_NOT_CONNECTABLE, + "Internet (Not Connectable)" + ) MSG_HASH( MSG_LOCAL, "Local" diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index a8b44c00d5..e78ca0750a 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -5927,6 +5927,8 @@ static void netplay_refresh_lan_cb(retro_task_t *task, sizeof(room->address)); room->has_password = host->has_password; room->has_spectate_password = host->has_spectate_password; + room->connectable = true; + room->is_retroarch = true; room->lan = true; } } diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 1d860a982c..d832eca565 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -9740,6 +9740,10 @@ unsigned menu_displaylist_netplay_refresh_rooms(file_list_t *list) const char *room_type; struct netplay_room *room = &net_st->room_list[i]; + /* Get rid of any room that is not running RetroArch. */ + if (!room->is_retroarch) + continue; + if (room->has_password || room->has_spectate_password) snprintf(passworded, sizeof(passworded), "[%s] ", msg_hash_to_str(MSG_ROOM_PASSWORDED)); @@ -9756,8 +9760,10 @@ unsigned menu_displaylist_netplay_refresh_rooms(file_list_t *list) room_type = msg_hash_to_str(MSG_LOCAL); else if (room->host_method == NETPLAY_HOST_METHOD_MITM) room_type = msg_hash_to_str(MSG_INTERNET_RELAY); - else + else if (room->connectable) room_type = msg_hash_to_str(MSG_INTERNET); + else + room_type = msg_hash_to_str(MSG_INTERNET_NOT_CONNECTABLE); snprintf(buf, sizeof(buf), "%s%s: %s%s", passworded, room_type, diff --git a/msg_hash.h b/msg_hash.h index 66b751964a..30dd45cd18 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -170,6 +170,7 @@ enum msg_hash_enums MSG_ROOM_PASSWORDED, MSG_INTERNET, MSG_INTERNET_RELAY, + MSG_INTERNET_NOT_CONNECTABLE, MSG_READ_WRITE, MSG_READ_ONLY, MSG_LOCAL, @@ -186,6 +187,7 @@ enum msg_hash_enums MSG_NETPLAY_LAN_SCAN_COMPLETE, MSG_NETPLAY_LAN_SCANNING, MSG_WAITING_FOR_CLIENT, + MSG_ROOM_NOT_CONNECTABLE, MSG_NETPLAY_YOU_HAVE_LEFT_THE_GAME, MSG_NETPLAY_YOU_HAVE_JOINED_AS_PLAYER_N, MSG_NETPLAY_YOU_HAVE_JOINED_WITH_INPUT_DEVICES_S, diff --git a/network/netplay/netplay.h b/network/netplay/netplay.h index 1482345663..9c3f97b311 100644 --- a/network/netplay/netplay.h +++ b/network/netplay/netplay.h @@ -164,6 +164,8 @@ struct netplay_room char mitm_session [33]; bool has_password; bool has_spectate_password; + bool connectable; + bool is_retroarch; bool lan; }; diff --git a/network/netplay/netplay_frontend.c b/network/netplay/netplay_frontend.c index 81fcfe3a5f..2dbc450911 100644 --- a/network/netplay/netplay_frontend.c +++ b/network/netplay/netplay_frontend.c @@ -7747,6 +7747,7 @@ static void netplay_announce_cb(retro_task_t *task, net_driver_state_t *net_st = &networking_driver_st; struct netplay_room *host_room = &net_st->host_room; http_transfer_data_t *data = task_data; + bool first = !host_room->id; if (error) return; @@ -7813,6 +7814,9 @@ static void netplay_announce_cb(retro_task_t *task, sizeof(host_room->retroarch_version)); else if (string_is_equal(key, "country")) strlcpy(host_room->country, value, sizeof(host_room->country)); + else if (string_is_equal(key, "connectable")) + host_room->connectable = string_is_equal_noncase(value, "true") || + string_is_equal(value, "1"); } } @@ -7822,6 +7826,16 @@ static void netplay_announce_cb(retro_task_t *task, free(buf_start); + /* Warn only on the first announce. */ + if (!host_room->connectable && first) + { + const char *dmsg = msg_hash_to_str(MSG_ROOM_NOT_CONNECTABLE); + + RARCH_WARN("[Netplay] %s\n", dmsg); + runloop_msg_queue_push(dmsg, 1, 180, false, NULL, + MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); + } + #ifdef HAVE_DISCORD if (discord_state_get_ptr()->inited) { @@ -8239,6 +8253,7 @@ bool init_netplay(const char *server, unsigned port, const char *mitm_session) struct netplay_room *host_room = &net_st->host_room; memset(host_room, 0, sizeof(*host_room)); + host_room->connectable = true; server = NULL; diff --git a/network/netplay/netplay_room_parse.c b/network/netplay/netplay_room_parse.c index 9422297b3e..2ab4056c71 100644 --- a/network/netplay/netplay_room_parse.c +++ b/network/netplay/netplay_room_parse.c @@ -109,6 +109,9 @@ static bool netplay_json_start_object(void* ctx) net_st->rooms_data->cur->next = (struct netplay_room*)calloc(1, sizeof(*net_st->rooms_data->cur->next)); net_st->rooms_data->cur = net_st->rooms_data->cur->next; } + + net_st->rooms_data->cur->connectable = true; + net_st->rooms_data->cur->is_retroarch = true; } else if (p_ctx->state == STATE_ARRAY_START) p_ctx->state = STATE_OBJECT_START; @@ -227,6 +230,14 @@ static bool netplay_json_object_member(void *ctx, const char *p_value, p_ctx->cur_member_string = net_st->rooms_data->cur->subsystem_name; p_ctx->cur_member_size = sizeof(net_st->rooms_data->cur->subsystem_name); } + else if (string_is_equal(p_value, "connectable")) + { + p_ctx->cur_member_bool = &net_st->rooms_data->cur->connectable; + } + else if (string_is_equal(p_value, "is_retroarch")) + { + p_ctx->cur_member_bool = &net_st->rooms_data->cur->is_retroarch; + } } }