feat: Add unix sockets

- Unix sockets run parallel to Named Pipes
  - Named Pipes will only run on non-Wine
  - If the game crashes, the next run will clean up an orphaned socket.
- Restructure RPC to be a bit tidier
This commit is contained in:
Kaz Wolfe 2025-11-18 15:18:16 -08:00
parent 6a69a6e197
commit 71927a8bf6
No known key found for this signature in database
GPG key ID: 258813F53A16EBB4
14 changed files with 487 additions and 91 deletions

View file

@ -0,0 +1,120 @@
using System.Threading.Tasks;
using Dalamud.Data;
using Dalamud.Game;
using Dalamud.Game.ClientState;
using Dalamud.Utility;
using Lumina.Excel.Sheets;
namespace Dalamud.Networking.Rpc.Service;
/// <summary>
/// A minimal service to respond with information about this client.
/// </summary>
[ServiceManager.EarlyLoadedService]
internal sealed class ClientHelloService : IInternalDisposableService
{
/// <summary>
/// Initializes a new instance of the <see cref="ClientHelloService"/> class.
/// </summary>
/// <param name="rpcHostService">Injected host service.</param>
[ServiceManager.ServiceConstructor]
public ClientHelloService(RpcHostService rpcHostService)
{
rpcHostService.AddMethod("hello", this.HandleHello);
}
/// <summary>
/// Handle a hello request.
/// </summary>
/// <param name="request">.</param>
/// <returns>Respond with information.</returns>
public async Task<ClientHelloResponse> HandleHello(ClientHelloRequest request)
{
var dalamud = await Service<Dalamud>.GetAsync();
return new ClientHelloResponse
{
ApiVersion = "1.0",
DalamudVersion = Util.GetScmVersion(),
GameVersion = dalamud.StartInfo.GameVersion?.ToString() ?? "Unknown",
ClientIdentifier = await this.GetClientIdentifier(),
};
}
/// <inheritdoc/>
public void DisposeService()
{
}
private async Task<string> GetClientIdentifier()
{
var framework = await Service<Framework>.GetAsync();
var clientState = await Service<ClientState>.GetAsync();
var dataManager = await Service<DataManager>.GetAsync();
var clientIdentifier = $"FFXIV Process ${Environment.ProcessId}";
await framework.RunOnFrameworkThread(() =>
{
if (clientState.IsLoggedIn)
{
var player = clientState.LocalPlayer;
if (player != null)
{
var world = dataManager.GetExcelSheet<World>().GetRow(player.HomeWorld.RowId);
clientIdentifier = $"Logged in as {player.Name.TextValue} @ {world.Name.ExtractText()}";
}
}
else
{
clientIdentifier = "On login screen";
}
});
return clientIdentifier;
}
}
/// <summary>
/// A request from a client to say hello.
/// </summary>
internal record ClientHelloRequest
{
/// <summary>
/// Gets the API version this client is expecting.
/// </summary>
public string ApiVersion { get; init; } = string.Empty;
/// <summary>
/// Gets the user agent of the client.
/// </summary>
public string UserAgent { get; init; } = string.Empty;
}
/// <summary>
/// A response from Dalamud to a hello request.
/// </summary>
internal record ClientHelloResponse
{
/// <summary>
/// Gets the API version this server has offered.
/// </summary>
public string? ApiVersion { get; init; }
/// <summary>
/// Gets the current Dalamud version.
/// </summary>
public string? DalamudVersion { get; init; }
/// <summary>
/// Gets the current game version.
/// </summary>
public string? GameVersion { get; init; }
/// <summary>
/// Gets an identifier for this client.
/// </summary>
public string? ClientIdentifier { get; init; }
}