Merge pull request #4707 from fr500/master

LAN scanning into rooms
This commit is contained in:
Twinaphex 2017-02-28 05:47:49 +01:00 committed by GitHub
commit 59f5c596d6
10 changed files with 68 additions and 37 deletions

View File

@ -2400,6 +2400,8 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_REFRESH_ROOMS,
"Aktualisieren")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_ROOM_NICKNAME,
"Nickname: %s")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_ROOM_NICKNAME_LAN,
"Nickname (lan): %s")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_COMPAT_CONTENT_FOUND,
"Kompatibler Inhalt gefunden")
MSG_HASH(MENU_ENUM_SUBLABEL_VIDEO_CROP_OVERSCAN,

View File

@ -2279,3 +2279,5 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_REFRESH_ROOMS,
"Refresh Room List")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_ROOM_NICKNAME,
"Nickname: %s")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_ROOM_NICKNAME_LAN,
"Nickname (lan): %s")

View File

@ -2402,6 +2402,8 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_REFRESH_ROOMS,
"ルーム表を更新")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_ROOM_NICKNAME,
"ニックネーム: %s")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_ROOM_NICKNAME_LAN,
"Nickname (lan): %s")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_COMPAT_CONTENT_FOUND,
"対応するコンテンツが見つかりました")
MSG_HASH(MENU_ENUM_SUBLABEL_VIDEO_CROP_OVERSCAN,

View File

@ -2398,6 +2398,8 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_REFRESH_ROOMS,
"Atualizar")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_ROOM_NICKNAME,
"Apelido: %s")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_ROOM_NICKNAME_LAN,
"Nickname (lan): %s")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_COMPAT_CONTENT_FOUND,
"Conteúdo compatível encontrado")
MSG_HASH(MENU_ENUM_SUBLABEL_VIDEO_CROP_OVERSCAN,

View File

@ -2406,6 +2406,8 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_REFRESH_ROOMS,
"Refresh")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_ROOM_NICKNAME,
"Nickname: %s")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_ROOM_NICKNAME_LAN,
"Nickname (lan): %s")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_COMPAT_CONTENT_FOUND,
"Compatible content found")
MSG_HASH(MENU_ENUM_SUBLABEL_VIDEO_CROP_OVERSCAN,

View File

@ -3389,6 +3389,7 @@ static int action_ok_push_scan_file(const char *path,
static void netplay_refresh_rooms_cb(void *task_data, void *user_data, const char *err)
{
char buf[PATH_MAX_LENGTH];
int lan_room_count = 0;
http_transfer_data_t *data = (http_transfer_data_t*)task_data;
@ -3422,8 +3423,12 @@ finish:
file_list_t *file_list = menu_entries_get_selection_buf_ptr(0);
struct netplay_host_list *lan_hosts;
if (!netplay_discovery_driver_ctl(RARCH_NETPLAY_DISCOVERY_CTL_LAN_GET_RESPONSES, &lan_hosts))
lan_hosts = NULL;
//netplay_discovery_driver_ctl(RARCH_NETPLAY_DISCOVERY_CTL_LAN_GET_RESPONSES, &lan_hosts);
if (lan_hosts)
lan_room_count = lan_hosts->size;
else
lan_room_count = 0;
menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, file_list);
@ -3435,7 +3440,7 @@ finish:
netplay_room_count = (int)(room_data->size / 8);
netplay_room_list = (struct netplay_room*)
malloc(sizeof(struct netplay_room) * netplay_room_count +
lan_hosts->size);
lan_room_count);
#if 0
for (int i = 0; i < room_data->size; i++)
@ -3512,44 +3517,42 @@ finish:
MENU_ROOM, 0, 0);
}
struct netplay_host *host = &lan_hosts->hosts[k];
for (; i < netplay_room_count + lan_hosts->size; i++)
if (lan_room_count != 0)
{
strlcpy(netplay_room_list[i].nickname,
host->nick,
sizeof(netplay_room_list[i].nickname));
/* to-do: get address fron host-> addr */
strlcpy(netplay_room_list[i].address,
"",
sizeof(netplay_room_list[i].address));
strlcpy(netplay_room_list[i].corename,
host->core,
sizeof(netplay_room_list[i].corename));
strlcpy(netplay_room_list[i].coreversion,
host->core_version,
sizeof(netplay_room_list[i].coreversion));
strlcpy(netplay_room_list[i].gamename,
host->content,
sizeof(netplay_room_list[i].coreversion));
struct netplay_host *host = &lan_hosts->hosts[k];
for (; i < netplay_room_count + lan_room_count; i++)
{
strlcpy(netplay_room_list[i].nickname,
host->nick,
sizeof(netplay_room_list[i].nickname));
struct sockaddr* address = &host->addr;
strlcpy(netplay_room_list[i].address,
inet_ntoa(((struct sockaddr_in*)(address))->sin_addr),
sizeof(netplay_room_list[i].address));
strlcpy(netplay_room_list[i].corename,
host->core,
sizeof(netplay_room_list[i].corename));
strlcpy(netplay_room_list[i].coreversion,
host->core_version,
sizeof(netplay_room_list[i].coreversion));
strlcpy(netplay_room_list[i].gamename,
host->content,
sizeof(netplay_room_list[i].coreversion));
/* to-do: this will only work with default port os
we should have a start LAN game entry that always
uses that port
*/
netplay_room_list[i].port = 55435;
/* to-do: lan announce doesn't announce CRC */
netplay_room_list[i].gamecrc = 0;
netplay_room_list[i].timestamp = 0;
netplay_room_list[i].port = 55435;
netplay_room_list[i].gamecrc = host->content_crc;
netplay_room_list[i].timestamp = 0;
snprintf(s, sizeof(s), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_ROOM_NICKNAME),
netplay_room_list[i].nickname);
snprintf(s, sizeof(s), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_ROOM_NICKNAME_LAN),
netplay_room_list[i].nickname);
menu_entries_append_enum(file_list,
s,
msg_hash_to_str(MENU_ENUM_LABEL_CONNECT_NETPLAY_ROOM),
MENU_ENUM_LABEL_CONNECT_NETPLAY_ROOM,
MENU_ROOM, 0, 0);
k++;
menu_entries_append_enum(file_list,
s,
msg_hash_to_str(MENU_ENUM_LABEL_CONNECT_NETPLAY_ROOM),
MENU_ENUM_LABEL_CONNECT_NETPLAY_ROOM,
MENU_ROOM, 0, 0);
k++;
}
}
}
}

View File

@ -870,6 +870,7 @@ enum msg_hash_enums
MENU_LABEL(SCAN_FILE),
MENU_LABEL(NETPLAY_REFRESH_ROOMS),
MENU_LABEL(NETPLAY_ROOM_NICKNAME),
MENU_LABEL(NETPLAY_ROOM_NICKNAME_LAN),
MENU_LABEL(ADD_CONTENT_LIST),
MENU_LABEL(CONFIGURATIONS_LIST),

View File

@ -34,6 +34,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string/stdstring.h>
#include <file/file_path.h>
#include "../../file_path_special.h"
#include "../../paths.h"
#include "../../content.h"
#include <compat/strl.h>
#include <net/net_compat.h>
@ -58,6 +63,7 @@ struct ad_packet
char core[NETPLAY_HOST_STR_LEN];
char core_version[NETPLAY_HOST_STR_LEN];
char content[NETPLAY_HOST_STR_LEN];
char content_crc[NETPLAY_HOST_STR_LEN];
};
bool netplay_lan_ad_client(void);
@ -240,6 +246,8 @@ bool netplay_lan_ad_server(netplay_t *netplay)
runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &info);
/* Now build our response */
uint32_t *content_crc_ptr = NULL;
content_get_crc(&content_crc_ptr);
memset(&ad_packet_buffer, 0, sizeof(struct ad_packet));
memcpy(&ad_packet_buffer, "RANS", 4);
ad_packet_buffer.protocol_version =
@ -247,6 +255,8 @@ bool netplay_lan_ad_server(netplay_t *netplay)
ad_packet_buffer.port = htonl(netplay->tcp_port);
strlcpy(ad_packet_buffer.retroarch_version, PACKAGE_VERSION,
NETPLAY_HOST_STR_LEN);
strlcpy(ad_packet_buffer.content, !string_is_empty(path_basename(path_get(RARCH_PATH_BASENAME))) ? path_basename(path_get(RARCH_PATH_BASENAME)) : "N/A",
NETPLAY_HOST_STR_LEN);
strlcpy(ad_packet_buffer.nick, netplay->nick, NETPLAY_HOST_STR_LEN);
if (info)
{
@ -255,6 +265,10 @@ bool netplay_lan_ad_server(netplay_t *netplay)
strlcpy(ad_packet_buffer.core_version, info->info.library_version,
NETPLAY_HOST_STR_LEN);
}
char s[NETPLAY_HOST_STR_LEN];
snprintf(s, sizeof(s), "%d", *content_crc_ptr);
strlcpy(ad_packet_buffer.content_crc, s,
NETPLAY_HOST_STR_LEN);
/* And send it */
sendto(lan_ad_server_fd, (const char*)&ad_packet_buffer,
@ -372,6 +386,7 @@ bool netplay_lan_ad_client(void)
NETPLAY_HOST_STR_LEN);
strlcpy(host->content, ad_packet_buffer.content,
NETPLAY_HOST_STR_LEN);
host->content_crc = atoi(ad_packet_buffer.content_crc);
host->nick[NETPLAY_HOST_STR_LEN-1] =
host->core[NETPLAY_HOST_STR_LEN-1] =
host->core_version[NETPLAY_HOST_STR_LEN-1] =

View File

@ -39,6 +39,7 @@ struct netplay_host
char core[NETPLAY_HOST_STR_LEN];
char core_version[NETPLAY_HOST_STR_LEN];
char content[NETPLAY_HOST_STR_LEN];
int content_crc;
};
struct netplay_host_list

View File

@ -15,6 +15,7 @@
#include <lists/file_list.h>
#include <string/stdstring.h>
#include "../paths.h"
#include "tasks_internal.h"