From 3dd6c91493aae16d16fea312e127703777ed011e Mon Sep 17 00:00:00 2001 From: radius Date: Thu, 19 Jan 2017 08:56:56 -0500 Subject: [PATCH] start populating the list --- menu/cbs/menu_cbs_ok.c | 63 +++++++++++++---------------- menu/menu_displaylist.c | 16 ++++++++ network/netplay/netplay_discovery.h | 19 +++++++++ 3 files changed, 62 insertions(+), 36 deletions(-) diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 7026b04a64..5de72e1ca1 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -3262,19 +3262,7 @@ static int action_ok_push_content_list(const char *path, entry_idx, ACTION_OK_DL_CONTENT_LIST); } -/* data is ordered like this on the server, I left it in this ordered - for reference */ -struct room -{ - char nickname [PATH_MAX_LENGTH]; - char address [PATH_MAX_LENGTH]; - int port; - char corename [PATH_MAX_LENGTH]; - char coreversion [PATH_MAX_LENGTH]; - char gamename [PATH_MAX_LENGTH]; - int gamecrc; - int timestamp; -}; + static int action_ok_push_scan_file(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx) @@ -3303,17 +3291,20 @@ finish: if (!err && !strstr(buf, file_path_str(FILE_PATH_NETPLAY_ROOM_LIST_URL))) { if (string_is_empty(buf)) + { + netplay_room_count = 0; RARCH_LOG("Room list empty\n"); + } else { - int rooms, i, j = 0; + int i, j = 0; char tmp[PATH_MAX_LENGTH]; - struct string_list *room_data = NULL; + static struct string_list *room_data = NULL; + room_data = string_split(buf, "\n"); - rooms = room_data->size / 8; - struct room *room_list = NULL; - room_list = (struct room*)malloc(sizeof(struct room) * rooms); + netplay_room_count = room_data->size / 8; + netplay_room_list = (struct netplay_room*)malloc(sizeof(struct netplay_room) * netplay_room_count); /*for (int i = 0; i < room_data->size; i++) { @@ -3323,17 +3314,17 @@ finish: }*/ - RARCH_LOG ("Found %d rooms\n", rooms); - for (i = 0; i < rooms; i++) + RARCH_LOG ("Found %d rooms\n", netplay_room_count); + for (i = 0; i < netplay_room_count; i++) { - strlcpy(room_list[i].nickname, room_data->elems[j + 0].data, sizeof(room_list[i].nickname)); - strlcpy(room_list[i].address, room_data->elems[j + 1].data, sizeof(room_list[i].address)); - strlcpy(room_list[i].corename, room_data->elems[j + 3].data, sizeof(room_list[i].corename)); - strlcpy(room_list[i].coreversion, room_data->elems[j + 4].data, sizeof(room_list[i].coreversion)); - strlcpy(room_list[i].gamename, room_data->elems[j + 5].data, sizeof(room_list[i].coreversion)); - room_list[i].port = atoi(room_data->elems[j + 2].data); - room_list[i].gamecrc = atoi(room_data->elems[j + 6].data); - room_list[i].timestamp = atoi(room_data->elems[j + 7].data); + strlcpy(netplay_room_list[i].nickname, room_data->elems[j + 0].data, sizeof(netplay_room_list[i].nickname)); + strlcpy(netplay_room_list[i].address, room_data->elems[j + 1].data, sizeof(netplay_room_list[i].address)); + strlcpy(netplay_room_list[i].corename, room_data->elems[j + 3].data, sizeof(netplay_room_list[i].corename)); + strlcpy(netplay_room_list[i].coreversion, room_data->elems[j + 4].data, sizeof(netplay_room_list[i].coreversion)); + strlcpy(netplay_room_list[i].gamename, room_data->elems[j + 5].data, sizeof(netplay_room_list[i].coreversion)); + netplay_room_list[i].port = atoi(room_data->elems[j + 2].data); + netplay_room_list[i].gamecrc = atoi(room_data->elems[j + 6].data); + netplay_room_list[i].timestamp = atoi(room_data->elems[j + 7].data); RARCH_LOG("Room Data: \n" "Nickname: %s\n" @@ -3344,14 +3335,14 @@ finish: "Game: %s\n" "Game CRC: %d\n" "Timestamp: %d\n", - room_list[i].nickname, - room_list[i].address, - room_list[i].port, - room_list[i].corename, - room_list[i].coreversion, - room_list[i].gamename, - room_list[i].gamecrc, - room_list[i].timestamp); + netplay_room_list[i].nickname, + netplay_room_list[i].address, + netplay_room_list[i].port, + netplay_room_list[i].corename, + netplay_room_list[i].coreversion, + netplay_room_list[i].gamename, + netplay_room_list[i].gamecrc, + netplay_room_list[i].timestamp); j+=8; } } diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 9fc439adf2..9e2eb89e59 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -2958,6 +2958,22 @@ static int menu_displaylist_parse_netplay_room_list( msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_REFRESH_ROOMS), MENU_ENUM_LABEL_NETPLAY_REFRESH_ROOMS, MENU_SETTING_ACTION, 0, 0); + + if (netplay_room_count > 0) + { + unsigned i; + for (i = 0; i < netplay_room_count; i++) + { + char s[PATH_MAX_LENGTH]; + snprintf(s, sizeof(s), "Nickname: %s", netplay_room_list[i].nickname); + const char *label = s; + menu_entries_append_enum(info->list, + label, + msg_hash_to_str(MENU_ENUM_LABEL_CONNECT_WIFI), + MENU_ENUM_LABEL_CONNECT_WIFI, + MENU_WIFI, 0, 0); + } + } #endif return 0; diff --git a/network/netplay/netplay_discovery.h b/network/netplay/netplay_discovery.h index f0b7358c78..9548b88cb9 100644 --- a/network/netplay/netplay_discovery.h +++ b/network/netplay/netplay_discovery.h @@ -18,6 +18,7 @@ #define __RARCH_NETPLAY_DISCOVERY_H #include +#include #define NETPLAY_HOST_STR_LEN 32 @@ -44,6 +45,24 @@ struct netplay_host_list { size_t size; }; +/* data is ordered like this on the server, I left it in this ordered + for reference */ +struct netplay_room +{ + char nickname [PATH_MAX_LENGTH]; + char address [PATH_MAX_LENGTH]; + int port; + char corename [PATH_MAX_LENGTH]; + char coreversion [PATH_MAX_LENGTH]; + char gamename [PATH_MAX_LENGTH]; + int gamecrc; + int timestamp; +}; + +struct netplay_room *netplay_room_list; + +int netplay_room_count; + /** Initialize Netplay discovery */ bool init_netplay_discovery(void);