Fix connection issues once and for all
+ Theory behind this is that on connect, they get a connection ID. On disconnect, that connection id is removed from their redis set. If they have no remaining keys, they're disposed, otherwise we can be sure they've reconnected and should not be disposed.
This commit is contained in:
@@ -202,6 +202,8 @@ public partial class MareHub
|
||||
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.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)
|
||||
|
@@ -136,13 +136,17 @@ public partial class MareHub : Hub<IMareHub>, IMareHub
|
||||
_mareMetrics.DecGaugeWithLabels(MetricsAPI.GaugeConnections, labels: Continent);
|
||||
try
|
||||
{
|
||||
_logger.LogCallInfo(MareHubLogger.Args(_contextAccessor.GetIpAddress(), UserCharaIdent));
|
||||
if (exception != null)
|
||||
_logger.LogCallWarning(MareHubLogger.Args(_contextAccessor.GetIpAddress(), exception.Message, exception.StackTrace));
|
||||
|
||||
_logger.LogCallInfo(MareHubLogger.Args(_contextAccessor.GetIpAddress(), UserCharaIdent));
|
||||
if (exception != null)
|
||||
_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 RemoveUserFromRedis().ConfigureAwait(false);
|
||||
await SendOfflineToAllPairedUsers().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
|
Reference in New Issue
Block a user