mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-07-31 01:59:59 -06:00

These changes allow players to matchmake for local wireless using a LDN server. The network implementation originates from Berry's public TCP RyuLDN fork. Logo and unrelated changes have been removed. Additionally displays LDN game status in the game selection window when RyuLDN is enabled. Functionality is only enabled while network mode is set to "RyuLDN" in the settings.
75 lines
2.7 KiB
C#
75 lines
2.7 KiB
C#
using Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Proxy;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.Sockets;
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Proxy
|
|
{
|
|
static class SocketHelpers
|
|
{
|
|
private static LdnProxy _proxy;
|
|
|
|
public static void Select(List<ISocketImpl> readEvents, List<ISocketImpl> writeEvents, List<ISocketImpl> errorEvents, int timeout)
|
|
{
|
|
var readDefault = readEvents.Select(x => (x as DefaultSocket)?.BaseSocket).Where(x => x != null).ToList();
|
|
var writeDefault = writeEvents.Select(x => (x as DefaultSocket)?.BaseSocket).Where(x => x != null).ToList();
|
|
var errorDefault = errorEvents.Select(x => (x as DefaultSocket)?.BaseSocket).Where(x => x != null).ToList();
|
|
|
|
if (readDefault.Count != 0 || writeDefault.Count != 0 || errorDefault.Count != 0)
|
|
{
|
|
Socket.Select(readDefault, writeDefault, errorDefault, timeout);
|
|
}
|
|
|
|
void FilterSockets(List<ISocketImpl> removeFrom, List<Socket> selectedSockets, Func<LdnProxySocket, bool> ldnCheck)
|
|
{
|
|
removeFrom.RemoveAll(socket =>
|
|
{
|
|
switch (socket)
|
|
{
|
|
case DefaultSocket dsocket:
|
|
return !selectedSockets.Contains(dsocket.BaseSocket);
|
|
case LdnProxySocket psocket:
|
|
return !ldnCheck(psocket);
|
|
default:
|
|
throw new NotImplementedException();
|
|
}
|
|
});
|
|
};
|
|
|
|
FilterSockets(readEvents, readDefault, (socket) => socket.Readable);
|
|
FilterSockets(writeEvents, writeDefault, (socket) => socket.Writable);
|
|
FilterSockets(errorEvents, errorDefault, (socket) => socket.Error);
|
|
}
|
|
|
|
public static void RegisterProxy(LdnProxy proxy)
|
|
{
|
|
if (_proxy != null)
|
|
{
|
|
UnregisterProxy();
|
|
}
|
|
|
|
_proxy = proxy;
|
|
}
|
|
|
|
public static void UnregisterProxy()
|
|
{
|
|
_proxy?.Dispose();
|
|
_proxy = null;
|
|
}
|
|
|
|
public static ISocketImpl CreateSocket(AddressFamily domain, SocketType type, ProtocolType protocol, string lanInterfaceId)
|
|
{
|
|
if (_proxy != null)
|
|
{
|
|
if (_proxy.Supported(domain, type, protocol))
|
|
{
|
|
return new LdnProxySocket(domain, type, protocol, _proxy);
|
|
}
|
|
}
|
|
|
|
return new DefaultSocket(domain, type, protocol, lanInterfaceId);
|
|
}
|
|
}
|
|
}
|