siegebreak/client/Assets/Scripts/Cards/CardDeploymentManager.cs
caelum0x e1d0aed4c3 feat: real 1v1 PvP relay transport for matched sessions
Matchmaking and session allocation were real but nothing carried gameplay
frames between the two matched clients for the actual match - the
documented gap in the Mobidictum Ventures application and ARCHITECTURE.md.
Photon Fusion itself needs an account signup/PHOTON_APP_ID this agent can't
do unattended, so build the real transport behind the SESSION_PROVIDER=local
default that every session already allocates: a WebSocket relay.

- services/src/modules/sessions/relay.ts + GET /sessions/:id/relay (WS):
  registers both participants' sockets, forwards frames between them,
  fans out across API instances via Redis pub/sub (same shape as the
  matchmaking notifier), assigns a deterministic host/guest role via
  sessionStore.hostPlayerId so both sides agree with no election.
- client/.../Services/MatchRelayClient.cs: Unity-side transport over
  ClientWebSocket, same shape as the existing MatchSubscription.
- NetworkBootstrap actually starts this transport for the local provider
  now (photon cleanly no-ops with photon_not_wired until its account
  blocker clears); CardDeploymentManager sends real deploy_input frames
  over it instead of a bare TODO.

Verified against the real running server (real local Postgres + Redis, no
mocks): two real guest signups -> real matchmaking queue/tick pairs them ->
both connect to the real relay -> server assigns exactly one host -> a real
gameplay frame sent by each side arrives byte-identical on the other.
Existing 115 unit + 14 integration tests still green, tsc --noEmit clean.
2026-10-24 00:21:52 +03:00

60 lines
2.1 KiB
C#

using System;
using UnityEngine;
using Siegebreak.Networking;
namespace Siegebreak.Cards
{
[Serializable]
internal class DeployInputFrame
{
public string type = "deploy_input";
public string cardId;
public float x;
public float y;
public float z;
// Wall-clock-independent ordering hint for the receiving simulation
// (host or server) to resolve near-simultaneous deploys deterministically
// once a real queue exists there; harmless no-op until then.
public float clientTimeSeconds;
}
/// <summary>
/// Handles card selection + placement in Command View. Sends a deploy
/// request over the active match transport (<see cref="NetworkBootstrap"/>
/// -> MatchRelayClient for the "local" provider, Photon Fusion once that's
/// wired); the server/host is authoritative on whether the deploy is valid
/// (elixir, placement zone, timing) and spawns the unit. This class never
/// spawns anything locally first — only sends the request — so a rejected
/// deploy can never desync the client's hand/elixir from the authority's.
/// </summary>
public class CardDeploymentManager : MonoBehaviour
{
[SerializeField] private NetworkBootstrap network;
/// <summary>Raised if a deploy request couldn't be sent at all (no live transport).</summary>
public event Action<CardData> OnDeploySendFailed;
public async void RequestDeploy(CardData card, Vector3 worldPosition)
{
if (card == null) return;
if (network == null || !network.IsRelayConnected)
{
OnDeploySendFailed?.Invoke(card);
return;
}
var frame = new DeployInputFrame
{
cardId = card.cardId,
x = worldPosition.x,
y = worldPosition.y,
z = worldPosition.z,
clientTimeSeconds = Time.realtimeSinceStartup,
};
await network.SendMatchFrame(JsonUtility.ToJson(frame));
}
}
}