mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-31 01:59:52 -06:00
Migrate to SFML>=3.0.0
This commit is contained in:
@ -23,7 +23,7 @@ sf::Packet& operator>>(sf::Packet& packet, Common::BigEndianValue<u32>& data)
|
||||
|
||||
sf::Packet& operator>>(sf::Packet& packet, Common::BigEndianValue<u64>& data)
|
||||
{
|
||||
sf::Uint64 tmp;
|
||||
u64 tmp;
|
||||
packet >> tmp;
|
||||
data = tmp;
|
||||
return packet;
|
||||
@ -35,7 +35,7 @@ namespace Common
|
||||
// so we have this for cleaner code.
|
||||
u64 PacketReadU64(sf::Packet& packet)
|
||||
{
|
||||
sf::Uint64 value;
|
||||
u64 value;
|
||||
packet >> value;
|
||||
return value;
|
||||
}
|
||||
|
@ -4,6 +4,9 @@
|
||||
#include "Core/HW/EXI/BBA/BuiltIn.h"
|
||||
|
||||
#include <bit>
|
||||
#include <optional>
|
||||
#include "SFML/Network/IpAddress.hpp"
|
||||
#include "SFML/Network/Socket.hpp"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <ws2ipdef.h>
|
||||
@ -81,8 +84,9 @@ bool CEXIETHERNET::BuiltInBBAInterface::Activate()
|
||||
// Workaround to get the host IP (might not be accurate)
|
||||
// TODO: Fix the JNI crash and use GetSystemDefaultInterface()
|
||||
// - https://pastebin.com/BFpmnxby (see https://dolp.in/pr10920)
|
||||
const u32 ip = m_local_ip.empty() ? sf::IpAddress::getLocalAddress().toInteger() :
|
||||
sf::IpAddress(m_local_ip).toInteger();
|
||||
const u32 ip = sf::IpAddress::resolve(m_local_ip)
|
||||
.value_or(sf::IpAddress::getLocalAddress().value_or(sf::IpAddress::Any))
|
||||
.toInteger();
|
||||
m_current_ip = htonl(ip);
|
||||
m_current_mac = Common::BitCastPtr<Common::MACAddress>(&m_eth_ref->mBbaMem[BBA_NAFR_PAR0]);
|
||||
m_arp_table[m_current_ip] = m_current_mac;
|
||||
@ -92,7 +96,7 @@ bool CEXIETHERNET::BuiltInBBAInterface::Activate()
|
||||
|
||||
m_network_ref.Clear();
|
||||
|
||||
m_upnp_httpd.listen(Common::SSDP_PORT, sf::IpAddress(ip));
|
||||
(void)m_upnp_httpd.listen(Common::SSDP_PORT, sf::IpAddress(ip));
|
||||
m_upnp_httpd.setBlocking(false);
|
||||
|
||||
return RecvInit();
|
||||
@ -256,11 +260,12 @@ CEXIETHERNET::BuiltInBBAInterface::TryGetDataFromSocket(StackRef* ref)
|
||||
case IPPROTO_UDP:
|
||||
{
|
||||
std::array<u8, MAX_UDP_LENGTH> buffer;
|
||||
ref->udp_socket.receive(buffer.data(), MAX_UDP_LENGTH, datasize, ref->target, remote_port);
|
||||
std::optional<sf::IpAddress> target;
|
||||
(void)ref->udp_socket.receive(buffer.data(), MAX_UDP_LENGTH, datasize, target, remote_port);
|
||||
if (datasize > 0)
|
||||
{
|
||||
ref->from.sin_port = htons(remote_port);
|
||||
const u32 remote_ip = htonl(ref->target.toInteger());
|
||||
const u32 remote_ip = htonl(target->toInteger());
|
||||
ref->from.sin_addr.s_addr = remote_ip;
|
||||
ref->my_mac = ResolveAddress(remote_ip);
|
||||
const std::vector<u8> udp_data(buffer.begin(), buffer.begin() + datasize);
|
||||
@ -325,7 +330,7 @@ CEXIETHERNET::BuiltInBBAInterface::TryGetDataFromSocket(StackRef* ref)
|
||||
}
|
||||
if (GetTickCountStd() - ref->delay > 3000)
|
||||
{
|
||||
if (st == sf::Socket::Disconnected || st == sf::Socket::Error)
|
||||
if (st == sf::Socket::Status::Disconnected || st == sf::Socket::Status::Error)
|
||||
{
|
||||
ref->ip = 0;
|
||||
ref->tcp_socket.disconnect();
|
||||
@ -341,7 +346,6 @@ CEXIETHERNET::BuiltInBBAInterface::TryGetDataFromSocket(StackRef* ref)
|
||||
void CEXIETHERNET::BuiltInBBAInterface::HandleTCPFrame(const Common::TCPPacket& packet)
|
||||
{
|
||||
const auto& [hwdata, ip_header, tcp_header, ip_options, tcp_options, data] = packet;
|
||||
sf::IpAddress target;
|
||||
StackRef* ref = m_network_ref.GetTCPSlot(tcp_header.source_port, tcp_header.destination_port,
|
||||
std::bit_cast<u32>(ip_header.destination_addr));
|
||||
const u16 flags = ntohs(tcp_header.properties) & 0xfff;
|
||||
@ -354,7 +358,7 @@ void CEXIETHERNET::BuiltInBBAInterface::HandleTCPFrame(const Common::TCPPacket&
|
||||
WriteToQueue(BuildFINFrame(ref));
|
||||
ref->ip = 0;
|
||||
if (!data.empty())
|
||||
ref->tcp_socket.send(data.data(), data.size());
|
||||
(void)ref->tcp_socket.send(data.data(), data.size());
|
||||
ref->tcp_socket.disconnect();
|
||||
}
|
||||
else if (flags == (TCP_FLAG_SIN | TCP_FLAG_ACK))
|
||||
@ -395,7 +399,7 @@ void CEXIETHERNET::BuiltInBBAInterface::HandleTCPFrame(const Common::TCPPacket&
|
||||
ref->ready = false;
|
||||
ref->ip = std::bit_cast<u32>(ip_header.destination_addr);
|
||||
|
||||
target = sf::IpAddress(ntohl(destination_ip));
|
||||
sf::IpAddress target = sf::IpAddress(ntohl(destination_ip));
|
||||
ref->tcp_socket.Connect(target, ntohs(tcp_header.destination_port), m_current_ip);
|
||||
}
|
||||
else
|
||||
@ -414,7 +418,7 @@ void CEXIETHERNET::BuiltInBBAInterface::HandleTCPFrame(const Common::TCPPacket&
|
||||
if (static_cast<int>(this_seq - ref->ack_num) >= 0 &&
|
||||
data.size() >= static_cast<std::size_t>(size))
|
||||
{
|
||||
ref->tcp_socket.send(data.data(), size);
|
||||
(void)ref->tcp_socket.send(data.data(), size);
|
||||
ref->ack_num += size;
|
||||
}
|
||||
|
||||
@ -476,7 +480,7 @@ void CEXIETHERNET::BuiltInBBAInterface::InitUDPPort(u16 port)
|
||||
ref->to.sin_addr.s_addr = m_current_ip;
|
||||
ref->to.sin_port = htons(port);
|
||||
ref->udp_socket.setBlocking(false);
|
||||
if (ref->udp_socket.Bind(port, m_current_ip) != sf::Socket::Done)
|
||||
if (ref->udp_socket.Bind(port, m_current_ip) != sf::Socket::Status::Done)
|
||||
{
|
||||
ERROR_LOG_FMT(SP1, "Couldn't open UDP socket");
|
||||
PanicAlertFmt("Could't open port {:x}, this game might not work proprely in LAN mode.", port);
|
||||
@ -487,7 +491,7 @@ void CEXIETHERNET::BuiltInBBAInterface::InitUDPPort(u16 port)
|
||||
void CEXIETHERNET::BuiltInBBAInterface::HandleUDPFrame(const Common::UDPPacket& packet)
|
||||
{
|
||||
const auto& [hwdata, ip_header, udp_header, ip_options, data] = packet;
|
||||
sf::IpAddress target;
|
||||
sf::IpAddress target = sf::IpAddress::Any;
|
||||
const u32 destination_addr = ip_header.destination_addr == Common::IP_ADDR_ANY ?
|
||||
m_router_ip : // dns request
|
||||
std::bit_cast<u32>(ip_header.destination_addr);
|
||||
@ -506,12 +510,13 @@ void CEXIETHERNET::BuiltInBBAInterface::HandleUDPFrame(const Common::UDPPacket&
|
||||
ref->to.sin_addr.s_addr = std::bit_cast<u32>(ip_header.source_addr);
|
||||
ref->to.sin_port = udp_header.source_port;
|
||||
ref->udp_socket.setBlocking(false);
|
||||
if (ref->udp_socket.Bind(ntohs(udp_header.source_port), m_current_ip) != sf::Socket::Done)
|
||||
if (ref->udp_socket.Bind(ntohs(udp_header.source_port), m_current_ip) !=
|
||||
sf::Socket::Status::Done)
|
||||
{
|
||||
PanicAlertFmt(
|
||||
"Port {:x} is already in use, this game might not work as intented in LAN Mode.",
|
||||
htons(udp_header.source_port));
|
||||
if (ref->udp_socket.Bind(sf::Socket::AnyPort, m_current_ip) != sf::Socket::Done)
|
||||
if (ref->udp_socket.Bind(sf::Socket::AnyPort, m_current_ip) != sf::Socket::Status::Done)
|
||||
{
|
||||
ERROR_LOG_FMT(SP1, "Couldn't open UDP socket");
|
||||
return;
|
||||
@ -529,16 +534,18 @@ void CEXIETHERNET::BuiltInBBAInterface::HandleUDPFrame(const Common::UDPPacket&
|
||||
}
|
||||
}
|
||||
if (ntohs(udp_header.destination_port) == 53)
|
||||
target = sf::IpAddress(m_dns_ip.c_str()); // dns server ip
|
||||
// DNS server IP
|
||||
target = sf::IpAddress::resolve(m_dns_ip.c_str()).value_or(sf::IpAddress::Any);
|
||||
else
|
||||
target = sf::IpAddress(ntohl(std::bit_cast<u32>(ip_header.destination_addr)));
|
||||
ref->udp_socket.send(data.data(), data.size(), target, ntohs(udp_header.destination_port));
|
||||
|
||||
(void)ref->udp_socket.send(data.data(), data.size(), target, ntohs(udp_header.destination_port));
|
||||
}
|
||||
|
||||
void CEXIETHERNET::BuiltInBBAInterface::HandleUPnPClient()
|
||||
{
|
||||
StackRef* ref = m_network_ref.GetAvailableSlot(0);
|
||||
if (ref == nullptr || m_upnp_httpd.accept(ref->tcp_socket) != sf::Socket::Done)
|
||||
if (ref == nullptr || m_upnp_httpd.accept(ref->tcp_socket) != sf::Socket::Status::Done)
|
||||
return;
|
||||
|
||||
if (ref->tcp_socket.GetPeerName(&ref->from) != sf::Socket::Status::Done ||
|
||||
@ -795,7 +802,7 @@ sf::Socket::Status BbaTcpSocket::Connect(const sf::IpAddress& dest, u16 port, u3
|
||||
addr.sin_addr.s_addr = net_ip;
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = 0;
|
||||
::bind(getHandle(), reinterpret_cast<sockaddr*>(&addr), sizeof(addr));
|
||||
(void)::bind(getNativeHandle(), reinterpret_cast<sockaddr*>(&addr), sizeof(addr));
|
||||
m_connecting_state = ConnectingState::Connecting;
|
||||
return this->connect(dest, port);
|
||||
}
|
||||
@ -803,7 +810,7 @@ sf::Socket::Status BbaTcpSocket::Connect(const sf::IpAddress& dest, u16 port, u3
|
||||
sf::Socket::Status BbaTcpSocket::GetPeerName(sockaddr_in* addr) const
|
||||
{
|
||||
socklen_t size = sizeof(*addr);
|
||||
if (getpeername(getHandle(), reinterpret_cast<sockaddr*>(addr), &size) == -1)
|
||||
if (getpeername(getNativeHandle(), reinterpret_cast<sockaddr*>(addr), &size) == -1)
|
||||
{
|
||||
ERROR_LOG_FMT(SP1, "getpeername failed: {}", Common::StrNetworkError());
|
||||
return sf::Socket::Status::Error;
|
||||
@ -814,7 +821,7 @@ sf::Socket::Status BbaTcpSocket::GetPeerName(sockaddr_in* addr) const
|
||||
sf::Socket::Status BbaTcpSocket::GetSockName(sockaddr_in* addr) const
|
||||
{
|
||||
socklen_t size = sizeof(*addr);
|
||||
if (getsockname(getHandle(), reinterpret_cast<sockaddr*>(addr), &size) == -1)
|
||||
if (getsockname(getNativeHandle(), reinterpret_cast<sockaddr*>(addr), &size) == -1)
|
||||
{
|
||||
ERROR_LOG_FMT(SP1, "getsockname failed: {}", Common::StrNetworkError());
|
||||
return sf::Socket::Status::Error;
|
||||
@ -829,7 +836,7 @@ BbaTcpSocket::ConnectingState BbaTcpSocket::Connected(StackRef* ref)
|
||||
{
|
||||
case ConnectingState::Connecting:
|
||||
{
|
||||
const int fd = getHandle();
|
||||
const int fd = getNativeHandle();
|
||||
const s32 nfds = fd + 1;
|
||||
fd_set read_fds;
|
||||
fd_set write_fds;
|
||||
@ -914,20 +921,20 @@ sf::Socket::Status BbaUdpSocket::Bind(u16 port, u32 net_ip)
|
||||
// Handle SSDP multicast
|
||||
create();
|
||||
const int on = 1;
|
||||
if (setsockopt(getHandle(), SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<const char*>(&on),
|
||||
if (setsockopt(getNativeHandle(), SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<const char*>(&on),
|
||||
sizeof(on)) != 0)
|
||||
{
|
||||
ERROR_LOG_FMT(SP1, "setsockopt failed to reuse SSDP address: {}", Common::StrNetworkError());
|
||||
}
|
||||
#ifdef SO_REUSEPORT
|
||||
if (setsockopt(getHandle(), SOL_SOCKET, SO_REUSEPORT, reinterpret_cast<const char*>(&on),
|
||||
if (setsockopt(getNativeHandle(), SOL_SOCKET, SO_REUSEPORT, reinterpret_cast<const char*>(&on),
|
||||
sizeof(on)) != 0)
|
||||
{
|
||||
ERROR_LOG_FMT(SP1, "setsockopt failed to reuse SSDP port: {}", Common::StrNetworkError());
|
||||
}
|
||||
#endif
|
||||
if (const char loop = 1;
|
||||
setsockopt(getHandle(), IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop)) != 0)
|
||||
setsockopt(getNativeHandle(), IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop)) != 0)
|
||||
{
|
||||
ERROR_LOG_FMT(SP1, "setsockopt failed to set SSDP loopback: {}", Common::StrNetworkError());
|
||||
}
|
||||
@ -938,11 +945,11 @@ sf::Socket::Status BbaUdpSocket::Bind(u16 port, u32 net_ip)
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(Common::SSDP_PORT);
|
||||
Common::ScopeGuard error_guard([this] { close(); });
|
||||
if (::bind(getHandle(), reinterpret_cast<const sockaddr*>(&addr), sizeof(addr)) != 0)
|
||||
if (::bind(getNativeHandle(), reinterpret_cast<const sockaddr*>(&addr), sizeof(addr)) != 0)
|
||||
{
|
||||
WARN_LOG_FMT(SP1, "bind with SSDP port and INADDR_ANY failed: {}", Common::StrNetworkError());
|
||||
addr.sin_addr.s_addr = net_ip;
|
||||
if (::bind(getHandle(), reinterpret_cast<const sockaddr*>(&addr), sizeof(addr)) != 0)
|
||||
if (::bind(getNativeHandle(), reinterpret_cast<const sockaddr*>(&addr), sizeof(addr)) != 0)
|
||||
{
|
||||
ERROR_LOG_FMT(SP1, "bind with SSDP port failed: {}", Common::StrNetworkError());
|
||||
return sf::Socket::Status::Error;
|
||||
@ -955,7 +962,7 @@ sf::Socket::Status BbaUdpSocket::Bind(u16 port, u32 net_ip)
|
||||
INFO_LOG_FMT(SP1, "SSDP bind successful");
|
||||
|
||||
// Bind to the right interface
|
||||
if (setsockopt(getHandle(), IPPROTO_IP, IP_MULTICAST_IF,
|
||||
if (setsockopt(getNativeHandle(), IPPROTO_IP, IP_MULTICAST_IF,
|
||||
reinterpret_cast<const char*>(&addr.sin_addr), sizeof(addr.sin_addr)) != 0)
|
||||
{
|
||||
ERROR_LOG_FMT(SP1, "setsockopt failed to bind to the network interface: {}",
|
||||
@ -968,8 +975,8 @@ sf::Socket::Status BbaUdpSocket::Bind(u16 port, u32 net_ip)
|
||||
ip_mreq mreq;
|
||||
mreq.imr_multiaddr.s_addr = std::bit_cast<u32>(Common::IP_ADDR_SSDP);
|
||||
mreq.imr_interface.s_addr = net_ip;
|
||||
if (setsockopt(getHandle(), IPPROTO_IP, IP_ADD_MEMBERSHIP, reinterpret_cast<const char*>(&mreq),
|
||||
sizeof(mreq)) != 0)
|
||||
if (setsockopt(getNativeHandle(), IPPROTO_IP, IP_ADD_MEMBERSHIP,
|
||||
reinterpret_cast<const char*>(&mreq), sizeof(mreq)) != 0)
|
||||
{
|
||||
ERROR_LOG_FMT(SP1, "setsockopt failed to subscribe to SSDP multicast group: {}",
|
||||
Common::StrNetworkError());
|
||||
|
@ -76,7 +76,6 @@ struct StackRef
|
||||
u16 local;
|
||||
u16 remote;
|
||||
u16 type;
|
||||
sf::IpAddress target;
|
||||
u32 seq_num;
|
||||
u32 ack_num;
|
||||
u32 ack_base;
|
||||
|
@ -1,7 +1,9 @@
|
||||
// Copyright 2020 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <optional>
|
||||
#include "Core/HW/EXI/EXI_DeviceEthernet.h"
|
||||
#include "SFML/Network/IpAddress.hpp"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
@ -67,13 +69,14 @@ static int ConnectToDestination(const std::string& destination)
|
||||
}
|
||||
|
||||
sockaddr_in* sin = reinterpret_cast<sockaddr_in*>(&ss);
|
||||
const sf::IpAddress dest_ip(destination.substr(0, colon_offset));
|
||||
if (dest_ip == sf::IpAddress::None || dest_ip == sf::IpAddress::Any)
|
||||
const std::optional<sf::IpAddress> dest_ip =
|
||||
sf::IpAddress::resolve(destination.substr(0, colon_offset));
|
||||
if (!dest_ip)
|
||||
{
|
||||
ERROR_LOG_FMT(SP1, "Destination IP address is not valid\n");
|
||||
return -1;
|
||||
}
|
||||
sin->sin_addr.s_addr = htonl(dest_ip.toInteger());
|
||||
sin->sin_addr.s_addr = htonl(dest_ip->toInteger());
|
||||
sin->sin_family = AF_INET;
|
||||
const std::string port_str = destination.substr(colon_offset + 1);
|
||||
const int dest_port = std::atoi(port_str.c_str());
|
||||
|
@ -8,11 +8,13 @@
|
||||
#include "Core/HW/EXI/EXI_Device.h"
|
||||
#include "Core/HW/EXI/EXI_DeviceEthernet.h"
|
||||
|
||||
#include "SFML/Network/IpAddress.hpp"
|
||||
#include "VideoCommon/OnScreenDisplay.h"
|
||||
|
||||
#include <SFML/Network.hpp>
|
||||
|
||||
#include <cstring>
|
||||
#include <optional>
|
||||
|
||||
// BBA implementation with UDP interface to XLink Kai PC/MAC/RaspberryPi client
|
||||
// For more information please see: https://www.teamxlink.co.uk/wiki/Emulator_Integration_Protocol
|
||||
@ -26,13 +28,13 @@ bool CEXIETHERNET::XLinkNetworkInterface::Activate()
|
||||
if (IsActivated())
|
||||
return true;
|
||||
|
||||
if (m_sf_socket.bind(sf::Socket::AnyPort) != sf::Socket::Done)
|
||||
if (m_sf_socket.bind(sf::Socket::AnyPort) != sf::Socket::Status::Done)
|
||||
{
|
||||
ERROR_LOG_FMT(SP1, "Couldn't open XLink Kai UDP socket, unable to initialize BBA");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_sf_recipient_ip = m_dest_ip.c_str();
|
||||
m_sf_recipient_ip = sf::IpAddress::resolve(m_dest_ip.c_str()).value_or(sf::IpAddress::Any);
|
||||
|
||||
// Send connect command with unique local name
|
||||
// connect;locally_unique_name;emulator_name;optional_padding
|
||||
@ -45,7 +47,7 @@ bool CEXIETHERNET::XLinkNetworkInterface::Activate()
|
||||
|
||||
DEBUG_LOG_FMT(SP1, "SendCommandPayload {:x}\n{}", size, ArrayToString(buffer, size, 0x10));
|
||||
|
||||
if (m_sf_socket.send(buffer, size, m_sf_recipient_ip, m_dest_port) != sf::Socket::Done)
|
||||
if (m_sf_socket.send(buffer, size, m_sf_recipient_ip, m_dest_port) != sf::Socket::Status::Done)
|
||||
{
|
||||
ERROR_LOG_FMT(SP1, "Activate(): failed to send connect message to XLink Kai client");
|
||||
}
|
||||
@ -71,7 +73,7 @@ void CEXIETHERNET::XLinkNetworkInterface::Deactivate()
|
||||
|
||||
DEBUG_LOG_FMT(SP1, "SendCommandPayload {:x}\n{}", size, ArrayToString(buffer, size, 0x10));
|
||||
|
||||
if (m_sf_socket.send(buffer, size, m_sf_recipient_ip, m_dest_port) != sf::Socket::Done)
|
||||
if (m_sf_socket.send(buffer, size, m_sf_recipient_ip, m_dest_port) != sf::Socket::Status::Done)
|
||||
{
|
||||
ERROR_LOG_FMT(SP1, "Deactivate(): failed to send disconnect message to XLink Kai client");
|
||||
}
|
||||
@ -123,7 +125,8 @@ bool CEXIETHERNET::XLinkNetworkInterface::SendFrame(const u8* frame, u32 size)
|
||||
// Only uncomment for debugging, the performance hit is too big otherwise
|
||||
// INFO_LOG_FMT(SP1, "SendFrame {}\n{}", size, ArrayToString(m_out_frame, size, 0x10)));
|
||||
|
||||
if (m_sf_socket.send(m_out_frame, size, m_sf_recipient_ip, m_dest_port) != sf::Socket::Done)
|
||||
if (m_sf_socket.send(m_out_frame, size, m_sf_recipient_ip, m_dest_port) !=
|
||||
sf::Socket::Status::Done)
|
||||
{
|
||||
ERROR_LOG_FMT(SP1, "SendFrame(): expected to write {} bytes, but failed, errno {}", size,
|
||||
errno);
|
||||
@ -139,7 +142,7 @@ bool CEXIETHERNET::XLinkNetworkInterface::SendFrame(const u8* frame, u32 size)
|
||||
void CEXIETHERNET::XLinkNetworkInterface::ReadThreadHandler(
|
||||
CEXIETHERNET::XLinkNetworkInterface* self)
|
||||
{
|
||||
sf::IpAddress sender;
|
||||
std::optional<sf::IpAddress> sender;
|
||||
u16 port;
|
||||
|
||||
while (!self->m_read_thread_shutdown.IsSet())
|
||||
@ -151,7 +154,7 @@ void CEXIETHERNET::XLinkNetworkInterface::ReadThreadHandler(
|
||||
// *here* because XLink *could* send one
|
||||
std::size_t bytes_read = 0;
|
||||
if (self->m_sf_socket.receive(self->m_in_frame, std::size(self->m_in_frame), bytes_read, sender,
|
||||
port) != sf::Socket::Done &&
|
||||
port) != sf::Socket::Status::Done &&
|
||||
self->m_bba_link_up)
|
||||
{
|
||||
ERROR_LOG_FMT(SP1, "Failed to read from BBA, err={}", bytes_read);
|
||||
@ -218,7 +221,7 @@ void CEXIETHERNET::XLinkNetworkInterface::ReadThreadHandler(
|
||||
ArrayToString(buffer, size, 0x10));
|
||||
|
||||
if (self->m_sf_socket.send(buffer, size, self->m_sf_recipient_ip, self->m_dest_port) !=
|
||||
sf::Socket::Done)
|
||||
sf::Socket::Status::Done)
|
||||
{
|
||||
ERROR_LOG_FMT(
|
||||
SP1, "ReadThreadHandler(): failed to send setting message to XLink Kai client");
|
||||
@ -256,7 +259,7 @@ void CEXIETHERNET::XLinkNetworkInterface::ReadThreadHandler(
|
||||
|
||||
// Reply (using the message that came in!)
|
||||
if (self->m_sf_socket.send(self->m_in_frame, 10, self->m_sf_recipient_ip,
|
||||
self->m_dest_port) != sf::Socket::Done)
|
||||
self->m_dest_port) != sf::Socket::Status::Done)
|
||||
{
|
||||
ERROR_LOG_FMT(SP1, "ReadThreadHandler(): failed to reply to XLink Kai client keepalive");
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include "SFML/Network/IpAddress.hpp"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
@ -413,7 +414,7 @@ private:
|
||||
#if defined(WIN32) || defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
|
||||
defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__)
|
||||
sf::UdpSocket m_sf_socket;
|
||||
sf::IpAddress m_sf_recipient_ip;
|
||||
sf::IpAddress m_sf_recipient_ip = sf::IpAddress::Any;
|
||||
char m_in_frame[9004]{};
|
||||
char m_out_frame[9004]{};
|
||||
std::thread m_read_thread;
|
||||
|
@ -58,7 +58,7 @@ void GeckoSockServer::GeckoConnectionWaiter()
|
||||
server_port = 0xd6ec; // "dolphin gecko"
|
||||
for (int bind_tries = 0; bind_tries <= 10 && !server_running.IsSet(); bind_tries++)
|
||||
{
|
||||
server_running.Set(server.listen(server_port) == sf::Socket::Done);
|
||||
server_running.Set(server.listen(server_port) == sf::Socket::Status::Done);
|
||||
if (!server_running.IsSet())
|
||||
server_port++;
|
||||
}
|
||||
@ -73,7 +73,7 @@ void GeckoSockServer::GeckoConnectionWaiter()
|
||||
auto new_client = std::make_unique<sf::TcpSocket>();
|
||||
while (server_running.IsSet())
|
||||
{
|
||||
if (server.accept(*new_client) == sf::Socket::Done)
|
||||
if (server.accept(*new_client) == sf::Socket::Status::Done)
|
||||
{
|
||||
std::lock_guard lk(connection_lock);
|
||||
waiting_socks.push(std::move(new_client));
|
||||
@ -130,7 +130,7 @@ void GeckoSockServer::ClientThread()
|
||||
std::array<char, 128> buffer;
|
||||
std::size_t got = 0;
|
||||
|
||||
if (client->receive(buffer.data(), buffer.size(), got) == sf::Socket::Disconnected)
|
||||
if (client->receive(buffer.data(), buffer.size(), got) == sf::Socket::Status::Disconnected)
|
||||
client_running.Clear();
|
||||
|
||||
if (got != 0)
|
||||
@ -147,7 +147,7 @@ void GeckoSockServer::ClientThread()
|
||||
std::vector<char> packet(send_fifo.begin(), send_fifo.end());
|
||||
send_fifo.clear();
|
||||
|
||||
if (client->send(&packet[0], packet.size()) == sf::Socket::Disconnected)
|
||||
if (client->send(&packet[0], packet.size()) == sf::Socket::Status::Disconnected)
|
||||
client_running.Clear();
|
||||
}
|
||||
} // unlock transfer
|
||||
|
@ -49,11 +49,11 @@ static void GBAConnectionWaiter()
|
||||
sf::TcpListener clock_server;
|
||||
|
||||
// "dolphin gba"
|
||||
if (server.listen(0xd6ba) != sf::Socket::Done)
|
||||
if (server.listen(0xd6ba) != sf::Socket::Status::Done)
|
||||
return;
|
||||
|
||||
// "clock"
|
||||
if (clock_server.listen(0xc10c) != sf::Socket::Done)
|
||||
if (clock_server.listen(0xc10c) != sf::Socket::Status::Done)
|
||||
return;
|
||||
|
||||
server.setBlocking(false);
|
||||
@ -62,14 +62,14 @@ static void GBAConnectionWaiter()
|
||||
auto new_client = std::make_unique<sf::TcpSocket>();
|
||||
while (s_server_running.IsSet())
|
||||
{
|
||||
if (server.accept(*new_client) == sf::Socket::Done)
|
||||
if (server.accept(*new_client) == sf::Socket::Status::Done)
|
||||
{
|
||||
std::lock_guard lk(s_cs_gba);
|
||||
s_waiting_socks.push(std::move(new_client));
|
||||
|
||||
new_client = std::make_unique<sf::TcpSocket>();
|
||||
}
|
||||
if (clock_server.accept(*new_client) == sf::Socket::Done)
|
||||
if (clock_server.accept(*new_client) == sf::Socket::Status::Done)
|
||||
{
|
||||
std::lock_guard lk(s_cs_gba_clk);
|
||||
s_waiting_clocks.push(std::move(new_client));
|
||||
@ -170,7 +170,7 @@ void GBASockServer::ClockSync(Core::System& system)
|
||||
bytes[3] = time_slice & 0xff;
|
||||
|
||||
sf::Socket::Status status = m_clock_sync->send(bytes, 4);
|
||||
if (status == sf::Socket::Disconnected)
|
||||
if (status == sf::Socket::Status::Disconnected)
|
||||
{
|
||||
m_clock_sync->disconnect();
|
||||
m_clock_sync = nullptr;
|
||||
@ -210,7 +210,7 @@ void GBASockServer::Send(const u8* si_buffer)
|
||||
else
|
||||
status = m_client->send(send_data.data(), 1);
|
||||
|
||||
if (status == sf::Socket::Disconnected)
|
||||
if (status == sf::Socket::Status::Disconnected)
|
||||
Disconnect();
|
||||
}
|
||||
|
||||
@ -223,19 +223,19 @@ int GBASockServer::Receive(u8* si_buffer, u8 bytes)
|
||||
{
|
||||
sf::SocketSelector selector;
|
||||
selector.add(*m_client);
|
||||
selector.wait(sf::milliseconds(1000));
|
||||
(void)selector.wait(sf::milliseconds(1000));
|
||||
}
|
||||
|
||||
size_t num_received = 0;
|
||||
std::array<u8, RECV_MAX_SIZE> recv_data;
|
||||
sf::Socket::Status recv_stat = m_client->receive(recv_data.data(), bytes, num_received);
|
||||
if (recv_stat == sf::Socket::Disconnected)
|
||||
if (recv_stat == sf::Socket::Status::Disconnected)
|
||||
{
|
||||
Disconnect();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (recv_stat == sf::Socket::NotReady || num_received == 0)
|
||||
if (recv_stat == sf::Socket::Status::NotReady || num_received == 0)
|
||||
{
|
||||
m_booted = false;
|
||||
return 0;
|
||||
@ -257,7 +257,7 @@ void GBASockServer::Flush()
|
||||
while (num_received)
|
||||
{
|
||||
sf::Socket::Status recv_stat = m_client->receive(&byte, 1, num_received);
|
||||
if (recv_stat != sf::Socket::Done)
|
||||
if (recv_stat != sf::Socket::Status::Done)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -318,8 +318,8 @@ void Wiimote::Read()
|
||||
if (m_balance_board_dump_port > 0 && m_index == WIIMOTE_BALANCE_BOARD)
|
||||
{
|
||||
static sf::UdpSocket Socket;
|
||||
Socket.send((char*)rpt.data(), rpt.size(), sf::IpAddress::LocalHost,
|
||||
m_balance_board_dump_port);
|
||||
(void)Socket.send((char*)rpt.data(), rpt.size(), sf::IpAddress::LocalHost,
|
||||
m_balance_board_dump_port);
|
||||
}
|
||||
|
||||
// Add it to queue
|
||||
@ -339,7 +339,8 @@ bool Wiimote::Write()
|
||||
if (m_balance_board_dump_port > 0 && m_index == WIIMOTE_BALANCE_BOARD)
|
||||
{
|
||||
static sf::UdpSocket Socket;
|
||||
Socket.send((char*)rpt.data(), rpt.size(), sf::IpAddress::LocalHost, m_balance_board_dump_port);
|
||||
(void)Socket.send((char*)rpt.data(), rpt.size(), sf::IpAddress::LocalHost,
|
||||
m_balance_board_dump_port);
|
||||
}
|
||||
int ret = IOWrite(rpt.data(), rpt.size());
|
||||
|
||||
|
@ -325,7 +325,7 @@ bool NetPlayClient::Connect()
|
||||
static void ReceiveSyncIdentifier(sf::Packet& spac, SyncIdentifier& sync_identifier)
|
||||
{
|
||||
// We use a temporary variable here due to a potential long vs long long mismatch
|
||||
sf::Uint64 dol_elf_size;
|
||||
u64 dol_elf_size;
|
||||
spac >> dol_elf_size;
|
||||
sync_identifier.dol_elf_size = dol_elf_size;
|
||||
|
||||
@ -607,7 +607,7 @@ void NetPlayClient::OnChunkedDataPayload(sf::Packet& packet)
|
||||
sf::Packet progress_packet;
|
||||
progress_packet << MessageID::ChunkedDataProgress;
|
||||
progress_packet << cid;
|
||||
progress_packet << sf::Uint64{data_packet.getDataSize()};
|
||||
progress_packet << u64{data_packet.getDataSize()};
|
||||
Send(progress_packet, CHUNKED_DATA_CHANNEL);
|
||||
}
|
||||
|
||||
@ -2526,7 +2526,7 @@ void NetPlayClient::SendTimeBase()
|
||||
|
||||
if (netplay_client->m_timebase_frame % 60 == 0)
|
||||
{
|
||||
const sf::Uint64 timebase = Core::System::GetInstance().GetSystemTimers().GetFakeTimeBase();
|
||||
const u64 timebase = Core::System::GetInstance().GetSystemTimers().GetFakeTimeBase();
|
||||
|
||||
sf::Packet packet;
|
||||
packet << MessageID::TimeBase;
|
||||
|
@ -27,7 +27,7 @@ bool CompressFileIntoPacket(const std::string& file_path, sf::Packet& packet)
|
||||
return false;
|
||||
}
|
||||
|
||||
const sf::Uint64 size = file.GetSize();
|
||||
const u64 size = file.GetSize();
|
||||
packet << size;
|
||||
|
||||
if (size == 0)
|
||||
@ -89,7 +89,7 @@ bool CompressFileIntoPacket(const std::string& file_path, sf::Packet& packet)
|
||||
|
||||
static bool CompressFolderIntoPacketInternal(const File::FSTEntry& folder, sf::Packet& packet)
|
||||
{
|
||||
const sf::Uint64 size = folder.children.size();
|
||||
const u64 size = folder.children.size();
|
||||
packet << size;
|
||||
for (const auto& child : folder.children)
|
||||
{
|
||||
@ -118,7 +118,7 @@ bool CompressFolderIntoPacket(const std::string& folder_path, sf::Packet& packet
|
||||
|
||||
bool CompressBufferIntoPacket(const std::vector<u8>& in_buffer, sf::Packet& packet)
|
||||
{
|
||||
const sf::Uint64 size = in_buffer.size();
|
||||
const u64 size = in_buffer.size();
|
||||
packet << size;
|
||||
|
||||
if (size == 0)
|
||||
@ -224,7 +224,7 @@ static bool DecompressPacketIntoFolderInternal(sf::Packet& packet, const std::st
|
||||
if (!File::CreateFullPath(folder_path + "/"))
|
||||
return false;
|
||||
|
||||
sf::Uint64 size;
|
||||
u64 size;
|
||||
packet >> size;
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
|
@ -421,7 +421,7 @@ void NetPlayServer::ThreadFunc()
|
||||
static void SendSyncIdentifier(sf::Packet& spac, const SyncIdentifier& sync_identifier)
|
||||
{
|
||||
// We cast here due to a potential long vs long long mismatch
|
||||
spac << static_cast<sf::Uint64>(sync_identifier.dol_elf_size);
|
||||
spac << static_cast<u64>(sync_identifier.dol_elf_size);
|
||||
|
||||
spac << sync_identifier.game_id;
|
||||
spac << sync_identifier.revision;
|
||||
@ -1570,7 +1570,7 @@ bool NetPlayServer::StartGame()
|
||||
m_current_golfer = 1;
|
||||
m_pending_golfer = 0;
|
||||
|
||||
const sf::Uint64 initial_rtc = GetInitialNetPlayRTC();
|
||||
const u64 initial_rtc = GetInitialNetPlayRTC();
|
||||
|
||||
const std::string region = Config::GetDirectoryForRegion(
|
||||
Config::ToGameCubeRegion(m_dialog->FindGameFile(m_selected_game_identifier)->GetRegion()));
|
||||
@ -1847,7 +1847,7 @@ bool NetPlayServer::SyncSaveData(const SaveSyncInfo& sync_info)
|
||||
// No file, so we'll say the size is 0
|
||||
INFO_LOG_FMT(NETPLAY, "Sending empty marker for raw memcard {} in slot {}.", path,
|
||||
is_slot_a ? 'A' : 'B');
|
||||
pac << sf::Uint64{0};
|
||||
pac << u64{0};
|
||||
}
|
||||
|
||||
SendChunkedToClients(std::move(pac), 1,
|
||||
@ -1921,7 +1921,7 @@ bool NetPlayServer::SyncSaveData(const SaveSyncInfo& sync_info)
|
||||
|
||||
for (const auto& [title_id, storage] : sync_info.wii_saves)
|
||||
{
|
||||
pac << sf::Uint64{title_id};
|
||||
pac << u64{title_id};
|
||||
|
||||
if (storage->SaveExists())
|
||||
{
|
||||
@ -1938,7 +1938,7 @@ bool NetPlayServer::SyncSaveData(const SaveSyncInfo& sync_info)
|
||||
pac << true; // save exists
|
||||
|
||||
// Header
|
||||
pac << sf::Uint64{header->tid};
|
||||
pac << u64{header->tid};
|
||||
pac << header->banner_size << header->permissions << header->unk1;
|
||||
for (u8 byte : header->md5)
|
||||
pac << byte;
|
||||
@ -1952,7 +1952,7 @@ bool NetPlayServer::SyncSaveData(const SaveSyncInfo& sync_info)
|
||||
<< bk_header->total_size;
|
||||
for (u8 byte : bk_header->unk3)
|
||||
pac << byte;
|
||||
pac << sf::Uint64{bk_header->tid};
|
||||
pac << u64{bk_header->tid};
|
||||
for (u8 byte : bk_header->mac_address)
|
||||
pac << byte;
|
||||
|
||||
@ -2020,7 +2020,7 @@ bool NetPlayServer::SyncSaveData(const SaveSyncInfo& sync_info)
|
||||
{
|
||||
// No file, so we'll say the size is 0
|
||||
INFO_LOG_FMT(NETPLAY, "Sending empty marker for GBA save at {} for slot {}.", path, i);
|
||||
pac << sf::Uint64{0};
|
||||
pac << u64{0};
|
||||
}
|
||||
|
||||
SendChunkedToClients(std::move(pac), 1,
|
||||
@ -2406,7 +2406,7 @@ void NetPlayServer::ChunkedDataThreadFunc()
|
||||
|
||||
sf::Packet pac;
|
||||
pac << MessageID::ChunkedDataStart;
|
||||
pac << id << e.title << sf::Uint64{e.packet.getDataSize()};
|
||||
pac << id << e.title << u64{e.packet.getDataSize()};
|
||||
|
||||
ChunkedDataSend(std::move(pac), e.target_pid, e.target_mode);
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "Core/CoreTiming.h"
|
||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||
#include "InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPProto.h"
|
||||
#include "SFML/Network/IpAddress.hpp"
|
||||
|
||||
namespace ciface::DualShockUDPClient
|
||||
{
|
||||
@ -263,8 +264,9 @@ void InputBackend::HotplugThreadFunc()
|
||||
list_ports.pad_request_count = SERVER_ASKED_PADS;
|
||||
list_ports.pad_ids = {0, 1, 2, 3};
|
||||
msg.Finish();
|
||||
if (server.m_socket.send(&list_ports, sizeof list_ports, server.m_address, server.m_port) !=
|
||||
sf::Socket::Status::Done)
|
||||
if (server.m_socket.send(&list_ports, sizeof list_ports,
|
||||
sf::IpAddress::resolve(server.m_address).value(),
|
||||
server.m_port) != sf::Socket::Status::Done)
|
||||
{
|
||||
ERROR_LOG_FMT(CONTROLLERINTERFACE, "DualShockUDPClient HotplugThreadFunc send failed");
|
||||
}
|
||||
@ -304,7 +306,7 @@ void InputBackend::HotplugThreadFunc()
|
||||
|
||||
Proto::Message<Proto::MessageType::FromServer> msg;
|
||||
std::size_t received_bytes;
|
||||
sf::IpAddress sender;
|
||||
std::optional<sf::IpAddress> sender;
|
||||
u16 port;
|
||||
if (server.m_socket.receive(&msg, sizeof(msg), received_bytes, sender, port) !=
|
||||
sf::Socket::Status::Done)
|
||||
@ -627,8 +629,8 @@ Core::DeviceRemoval Device::UpdateInput()
|
||||
data_req.register_flags = Proto::RegisterFlags::PadID;
|
||||
data_req.pad_id_to_register = m_index;
|
||||
msg.Finish();
|
||||
if (m_socket.send(&data_req, sizeof(data_req), m_server_address, m_server_port) !=
|
||||
sf::Socket::Status::Done)
|
||||
if (m_socket.send(&data_req, sizeof(data_req), sf::IpAddress::resolve(m_server_address).value(),
|
||||
m_server_port) != sf::Socket::Status::Done)
|
||||
{
|
||||
ERROR_LOG_FMT(CONTROLLERINTERFACE, "DualShockUDPClient UpdateInput send failed");
|
||||
}
|
||||
@ -637,7 +639,7 @@ Core::DeviceRemoval Device::UpdateInput()
|
||||
// Receive and handle controller data
|
||||
Proto::Message<Proto::MessageType::FromServer> msg;
|
||||
std::size_t received_bytes;
|
||||
sf::IpAddress sender;
|
||||
std::optional<sf::IpAddress> sender;
|
||||
u16 port;
|
||||
while (m_socket.receive(&msg, sizeof msg, received_bytes, sender, port) ==
|
||||
sf::Socket::Status::Done)
|
||||
|
Reference in New Issue
Block a user