Avoid login kick broadcast during reconnect

This commit is contained in:
Alexa
2026-06-15 00:20:05 +03:00
parent 9342e2da99
commit 3755593dbb
@@ -20,7 +20,6 @@ namespace DorkNet.Server.Controllers.Match;
[ApiController] [ApiController]
public class MatchPlayerController( public class MatchPlayerController(
PlayerPresenceService presence, PlayerPresenceService presence,
NotificationService notifications,
RoomService rooms, RoomService rooms,
PrivateInstanceService privateInstances, PrivateInstanceService privateInstances,
IConfiguration config, IConfiguration config,
@@ -37,7 +36,7 @@ public class MatchPlayerController(
/// </summary> /// </summary>
[HttpPost("/player/login")] [HttpPost("/player/login")]
[Consumes("application/x-www-form-urlencoded", "multipart/form-data")] [Consumes("application/x-www-form-urlencoded", "multipart/form-data")]
public async Task<IActionResult> PlayerLogin([FromForm(Name = "LoginLock")] string? loginLock) public IActionResult PlayerLogin([FromForm(Name = "LoginLock")] string? loginLock)
{ {
var playerId = TryGetCurrentPlayerId(); var playerId = TryGetCurrentPlayerId();
if (playerId != 0 && !string.IsNullOrWhiteSpace(loginLock)) if (playerId != 0 && !string.IsNullOrWhiteSpace(loginLock))
@@ -46,17 +45,15 @@ public class MatchPlayerController(
if (replaced) if (replaced)
{ {
log.LogWarning( log.LogWarning(
"[player-login] concurrent session for player={PlayerId}; kicking old session(s) via ModerationKick push", "[player-login] concurrent session marker replaced for player={PlayerId}; stale SignalR connections will be evicted on hub connect",
playerId); playerId);
// The new session hasn't opened its SignalR socket yet // Do not broadcast ModerationKick to the whole player group
// (negotiate fires AFTER /player/login on the watch's // here. During reconnects the active watch can already have a
// boot sequence — verified in the live trace), so the // SignalR connection in that group, and the 2020 client crashes
// ModerationKick push hits only the OLDER session's // hard if it receives a malformed/stale moderation payload.
// existing connections. They'll show the "you've been // NotifyHub.OnConnectedAsync snapshots existing connection ids
// kicked" dialog and gracefully disconnect via the // before adding the new connection and sends a targeted kick to
// watch's LocalModerationKickSelf path. // those ids only.
await notifications.KickStaleSession(playerId,
"Your account was signed in on another device.");
} }
} }
return Ok(Array.Empty<object>()); return Ok(Array.Empty<object>());