Merge pull request #4 from ProfessorFartsalot/main

Fix connection issues once and for all
This commit is contained in:
2025-09-09 21:54:41 +01:00
committed by GitHub
2 changed files with 10 additions and 4 deletions

View File

@@ -202,6 +202,8 @@ public partial class MareHub
private async Task UpdateUserOnRedis() private async Task UpdateUserOnRedis()
{ {
await _redis.AddAsync("UID:" + UserUID, UserCharaIdent, TimeSpan.FromSeconds(60), StackExchange.Redis.When.Always, StackExchange.Redis.CommandFlags.FireAndForget).ConfigureAwait(false); await _redis.AddAsync("UID:" + UserUID, UserCharaIdent, TimeSpan.FromSeconds(60), StackExchange.Redis.When.Always, StackExchange.Redis.CommandFlags.FireAndForget).ConfigureAwait(false);
await _redis.SetAddAsync($"connections:{UserCharaIdent}", Context.ConnectionId).ConfigureAwait(false);
await _redis.UpdateExpiryAsync($"connections:{UserCharaIdent}", TimeSpan.FromSeconds(60)).ConfigureAwait(false);
} }
private async Task UserGroupLeave(GroupPair groupUserPair, List<PausedEntry> allUserPairs, string userIdent, string? uid = null) private async Task UserGroupLeave(GroupPair groupUserPair, List<PausedEntry> allUserPairs, string userIdent, string? uid = null)

View File

@@ -139,11 +139,15 @@ public partial class MareHub : Hub<IMareHub>, IMareHub
_logger.LogCallInfo(MareHubLogger.Args(_contextAccessor.GetIpAddress(), UserCharaIdent)); _logger.LogCallInfo(MareHubLogger.Args(_contextAccessor.GetIpAddress(), UserCharaIdent));
if (exception != null) if (exception != null)
_logger.LogCallWarning(MareHubLogger.Args(_contextAccessor.GetIpAddress(), exception.Message, exception.StackTrace)); _logger.LogCallWarning(MareHubLogger.Args(_contextAccessor.GetIpAddress(), exception.Message, exception.StackTrace));
await _redis.SetRemoveAsync($"connections:{UserCharaIdent}", Context.ConnectionId).ConfigureAwait(false);
var connections = await _redis.SetMembersAsync<string>($"connections:{UserCharaIdent}").ConfigureAwait(false);
if (connections.Length == 0)
{
await GposeLobbyLeave().ConfigureAwait(false); await GposeLobbyLeave().ConfigureAwait(false);
await RemoveUserFromRedis().ConfigureAwait(false); await RemoveUserFromRedis().ConfigureAwait(false);
await SendOfflineToAllPairedUsers().ConfigureAwait(false); await SendOfflineToAllPairedUsers().ConfigureAwait(false);
} }
}
catch { } catch { }
await base.OnDisconnectedAsync(exception).ConfigureAwait(false); await base.OnDisconnectedAsync(exception).ConfigureAwait(false);