(Netplay/Menu) Add client devices info to the kick sub-menu (#14138)

This commit is contained in:
Cthulhu-throwaway 2022-07-03 08:44:46 -03:00 committed by GitHub
parent 61bf5fba91
commit 42f75e7f72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 60 additions and 4 deletions

View File

@ -11679,6 +11679,10 @@ MSG_HASH(
MSG_NETPLAY_STATUS_SPECTATING,
"Spectating"
)
MSG_HASH(
MSG_NETPLAY_CLIENT_DEVICES,
"Devices"
)
MSG_HASH(
MSG_NETPLAY_CHAT_SUPPORTED,
"Chat Supported"

View File

@ -1547,7 +1547,7 @@ static int action_bind_sublabel_netplay_kick_client(file_list_t *list,
const char *label, const char *path,
char *s, size_t len)
{
char buf[256];
char buf[512];
netplay_client_info_t *client;
const char *status = NULL;
size_t idx = list->list[i].entry_idx;
@ -1580,6 +1580,54 @@ static int action_bind_sublabel_netplay_kick_client(file_list_t *list,
strlcat(s, buf, len);
}
if (client->devices)
{
int written = snprintf(buf, sizeof(buf), "%s:",
msg_hash_to_str(MSG_NETPLAY_CLIENT_DEVICES));
/* Ensure that at least one device can be written. */
if (written > 0 && written < (sizeof(buf) - STRLEN_CONST(" 16\n")))
{
uint32_t device;
char *buf_written = buf + written;
for (device = 0; device < (sizeof(client->devices) << 3); device++)
{
if (client->devices & (1 << device))
{
int tmp_written = snprintf(buf_written, sizeof(buf) - written,
" %u,", (unsigned)(device + 1));
/* Write nothing on error. */
if (tmp_written <= 0)
{
written = -1;
break;
}
written += tmp_written;
if (written >= (sizeof(buf) - 1))
break;
buf_written += tmp_written;
}
}
if (written > 0)
{
/* Now convert the last comma into a newline. */
buf_written = strrchr(buf, ',');
if (buf_written)
{
*buf_written++ = '\n';
*buf_written = '\0';
strlcat(s, buf, len);
}
}
}
}
snprintf(buf, sizeof(buf), "%s: %s",
msg_hash_to_str(MSG_NETPLAY_CHAT_SUPPORTED),
msg_hash_to_str((client->protocol >= 6) ?

View File

@ -220,6 +220,7 @@ enum msg_hash_enums
MSG_NETPLAY_FAILED_TO_KICK_CLIENT_S,
MSG_NETPLAY_STATUS_PLAYING,
MSG_NETPLAY_STATUS_SPECTATING,
MSG_NETPLAY_CLIENT_DEVICES,
MSG_NETPLAY_CHAT_SUPPORTED,
MSG_RESAMPLER_QUALITY_LOWEST,
MSG_RESAMPLER_QUALITY_LOWER,

View File

@ -139,6 +139,7 @@ typedef struct netplay netplay_t;
typedef struct netplay_client_info
{
uint32_t protocol;
uint32_t devices;
int32_t ping;
int id;
enum rarch_netplay_connection_mode mode;

View File

@ -8595,11 +8595,13 @@ static size_t retrieve_client_info(netplay_t *netplay, netplay_client_info_t *bu
if (connection->active && connection->mode >= NETPLAY_CONNECTION_CONNECTED)
{
netplay_client_info_t *info = &buf[j++];
info->id = (int)i;
strlcpy(info->name, connection->nick, sizeof(info->name));
info->id = (int)i;
info->protocol = connection->netplay_protocol;
info->mode = connection->mode;
info->ping = connection->ping;
info->devices = netplay->client_devices[i];
strlcpy(info->name, connection->nick, sizeof(info->name));
}
}
@ -8728,7 +8730,7 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
break;
case RARCH_NETPLAY_CTL_REFRESH_CLIENT_INFO:
if (!netplay)
if (!netplay || !netplay->is_server)
{
ret = false;
break;