mirror of
https://github.com/libretro/RetroArch
synced 2025-03-29 22:20:21 +00:00
Netplay discovery LAN scanning task (incomplete)
This commit is contained in:
parent
826afd137c
commit
addff325d0
@ -1100,6 +1100,7 @@ ifeq ($(HAVE_NETWORKING), 1)
|
||||
$(LIBRETRO_COMM_DIR)/net/net_natt.o \
|
||||
network/net_http_special.o \
|
||||
tasks/task_http.o \
|
||||
tasks/task_netplay_lan_scan.o \
|
||||
tasks/task_wifi.o
|
||||
|
||||
ifneq ($(HAVE_SOCKET_LEGACY),1)
|
||||
|
@ -183,6 +183,7 @@ enum menu_settings_type
|
||||
MENU_SETTING_SUBGROUP,
|
||||
MENU_SETTING_HORIZONTAL_MENU,
|
||||
MENU_WIFI,
|
||||
MENU_NETPLAY_LAN_SCAN,
|
||||
MENU_INFO_MESSAGE,
|
||||
MENU_SETTINGS_SHADER_PARAMETER_0,
|
||||
MENU_SETTINGS_SHADER_PARAMETER_LAST = MENU_SETTINGS_SHADER_PARAMETER_0 + (GFX_MAX_PARAMETERS - 1),
|
||||
|
@ -141,6 +141,7 @@ enum msg_hash_enums
|
||||
MSG_NETPLAY_USERS_HAS_FLIPPED,
|
||||
MSG_UNKNOWN_NETPLAY_COMMAND_RECEIVED,
|
||||
MSG_CONNECTING_TO_NETPLAY_HOST,
|
||||
MSG_NETPLAY_LAN_SCANNING,
|
||||
MSG_WAITING_FOR_CLIENT,
|
||||
MSG_AUTODETECT,
|
||||
MSG_AUDIO_VOLUME,
|
||||
@ -809,6 +810,7 @@ enum msg_hash_enums
|
||||
MENU_ENUM_LABEL_DEFERRED_UPDATER_SETTINGS_LIST,
|
||||
MENU_ENUM_LABEL_DEFERRED_WIFI_SETTINGS_LIST,
|
||||
MENU_ENUM_LABEL_DEFERRED_NETWORK_SETTINGS_LIST,
|
||||
MENU_ENUM_LABEL_DEFERRED_NETPLAY_LAN_SCAN_SETTINGS_LIST,
|
||||
MENU_ENUM_LABEL_DEFERRED_LAKKA_SERVICES_LIST,
|
||||
MENU_ENUM_LABEL_DEFERRED_USER_SETTINGS_LIST,
|
||||
MENU_ENUM_LABEL_DEFERRED_DIRECTORY_SETTINGS_LIST,
|
||||
@ -875,6 +877,7 @@ enum msg_hash_enums
|
||||
MENU_LABEL(NETPLAY_ENABLE_CLIENT),
|
||||
MENU_LABEL(NETPLAY_DISCONNECT),
|
||||
MENU_LABEL(NETPLAY_SETTINGS),
|
||||
MENU_LABEL(NETPLAY_CONNECT_TO),
|
||||
|
||||
MENU_ENUM_LABEL_RESET,
|
||||
MENU_ENUM_LABEL_SLOWMOTION,
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2016 - Daniel De Matteis
|
||||
* Copyright (C) 2016 - Gregor Richards
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
|
@ -471,6 +471,7 @@ bool netplay_ad_server(netplay_t *netplay, int ad_fd)
|
||||
break;
|
||||
|
||||
/* Somebody queried, so check that it's valid */
|
||||
addr_size = sizeof(their_addr);
|
||||
if (recvfrom(ad_fd, (char*)ad_packet_buffer, AD_PACKET_MAX_SIZE, 0,
|
||||
&their_addr, &addr_size) >= (ssize_t) (2*sizeof(uint32_t)))
|
||||
{
|
||||
|
56
network/netplay/netplay_discovery.h
Normal file
56
network/netplay/netplay_discovery.h
Normal file
@ -0,0 +1,56 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2016 - Gregor Richards
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __RARCH_NETPLAY_DISCOVERY_H
|
||||
#define __RARCH_NETPLAY_DISCOVERY_H
|
||||
|
||||
#include <net/net_compat.h>
|
||||
|
||||
#define NETPLAY_HOST_STR_LEN 32
|
||||
|
||||
enum rarch_netplay_discovery_ctl_state
|
||||
{
|
||||
RARCH_NETPLAY_DISCOVERY_CTL_NONE = 0,
|
||||
RARCH_NETPLAY_DISCOVERY_CTL_LAN_SEND_QUERY,
|
||||
RARCH_NETPLAY_DISCOVERY_CTL_LAN_GET_RESPONSES,
|
||||
RARCH_NETPLAY_DISCOVERY_CTL_LAN_CLEAR_RESPONSES
|
||||
};
|
||||
|
||||
struct netplay_host {
|
||||
struct sockaddr addr;
|
||||
socklen_t addrlen;
|
||||
|
||||
char nick[NETPLAY_HOST_STR_LEN];
|
||||
char core[NETPLAY_HOST_STR_LEN];
|
||||
char core_version[NETPLAY_HOST_STR_LEN];
|
||||
char content[NETPLAY_HOST_STR_LEN];
|
||||
};
|
||||
|
||||
struct netplay_host_list {
|
||||
struct netplay_host *hosts;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
/** Initialize Netplay discovery */
|
||||
bool init_netplay_discovery(void);
|
||||
|
||||
/** Deinitialize and free Netplay discovery */
|
||||
void deinit_netplay_discovery(void);
|
||||
|
||||
/** Discovery control */
|
||||
bool netplay_discovery_driver_ctl(enum rarch_netplay_discovery_ctl_state state, void *data);
|
||||
|
||||
#endif
|
@ -1,6 +1,7 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2016 - Daniel De Matteis
|
||||
* Copyright (C) 2016 - Gregor Richards
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
|
96
tasks/task_netplay_lan_scan.c
Normal file
96
tasks/task_netplay_lan_scan.c
Normal file
@ -0,0 +1,96 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2016 - Jean-André Santoni
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string/stdstring.h>
|
||||
|
||||
#include "tasks_internal.h"
|
||||
#include "../verbosity.h"
|
||||
#include "../network/netplay/netplay_discovery.h"
|
||||
#include "../menu/menu_entries.h"
|
||||
#include "../menu/menu_driver.h"
|
||||
|
||||
static void netplay_lan_scan_callback(void *task_data,
|
||||
void *user_data, const char *error)
|
||||
{
|
||||
unsigned i;
|
||||
unsigned menu_type = 0;
|
||||
const char *path = NULL;
|
||||
const char *label = NULL;
|
||||
enum msg_hash_enums enum_idx = MSG_UNKNOWN;
|
||||
file_list_t *file_list = NULL;
|
||||
struct netplay_host_list *netplay_hosts = NULL;
|
||||
|
||||
menu_entries_get_last_stack(&path, &label, &menu_type, &enum_idx, NULL);
|
||||
|
||||
/* Don't push the results if we left the LAN scan menu */
|
||||
if (!string_is_equal(label,
|
||||
msg_hash_to_str(MENU_ENUM_LABEL_DEFERRED_NETPLAY_LAN_SCAN_SETTINGS_LIST)))
|
||||
return;
|
||||
|
||||
file_list = menu_entries_get_selection_buf_ptr(0);
|
||||
|
||||
menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, file_list);
|
||||
|
||||
if (netplay_discovery_driver_ctl(RARCH_NETPLAY_DISCOVERY_CTL_LAN_GET_RESPONSES, (void *) &netplay_hosts))
|
||||
{
|
||||
for (i = 0; i < netplay_hosts->size; i++)
|
||||
{
|
||||
struct netplay_host *host = &netplay_hosts->hosts[i];
|
||||
menu_entries_append_enum(file_list,
|
||||
host->nick,
|
||||
msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_CONNECT_TO),
|
||||
MENU_ENUM_LABEL_NETPLAY_CONNECT_TO,
|
||||
MENU_NETPLAY_LAN_SCAN, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void task_netplay_lan_scan_handler(retro_task_t *task)
|
||||
{
|
||||
if (init_netplay_discovery())
|
||||
{
|
||||
netplay_discovery_driver_ctl(RARCH_NETPLAY_DISCOVERY_CTL_LAN_CLEAR_RESPONSES, NULL);
|
||||
netplay_discovery_driver_ctl(RARCH_NETPLAY_DISCOVERY_CTL_LAN_SEND_QUERY, NULL);
|
||||
}
|
||||
|
||||
task->progress = 100;
|
||||
task->title = strdup(msg_hash_to_str(MSG_NETPLAY_LAN_SCANNING));
|
||||
task->finished = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool task_push_netplay_lan_scan(void)
|
||||
{
|
||||
retro_task_t *task = (retro_task_t*)calloc(1, sizeof(*task));
|
||||
|
||||
if (!task)
|
||||
goto error;
|
||||
|
||||
task->type = TASK_TYPE_BLOCKING;
|
||||
task->handler = task_netplay_lan_scan_handler;
|
||||
task->callback = netplay_lan_scan_callback;
|
||||
task->title = strdup(msg_hash_to_str(MSG_NETPLAY_LAN_SCANNING));
|
||||
|
||||
task_queue_ctl(TASK_QUEUE_CTL_PUSH, task);
|
||||
|
||||
return true;
|
||||
|
||||
error:
|
||||
if (task)
|
||||
free(task);
|
||||
|
||||
return false;
|
||||
}
|
@ -95,6 +95,8 @@ task_retriever_info_t *http_task_get_transfer_list(void);
|
||||
|
||||
bool task_push_wifi_scan(void);
|
||||
|
||||
bool task_push_netplay_lan_scan(void);
|
||||
|
||||
#endif
|
||||
|
||||
bool task_push_image_load(const char *fullpath,
|
||||
|
Loading…
x
Reference in New Issue
Block a user