mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-25 15:08:47 -07:00
fix: address review on the notification pushes
- Force-join's RoomUpdate carries the room's role grants, so it no longer wipes them from the client's cached room. - The consumable push reports IsTransferable the same as the inventory list does. - A rejected private-instance join sends the owner at most one "wants to join" message per requester and instance every 5 minutes. - SubscribeToPlayers ignores sets over 5,000 ids and keeps the current subscriptions. - The subscriber exclusion list looks up online friends' connections in one pipelined Redis batch instead of one call per friend.
This commit is contained in:
@@ -148,6 +148,34 @@ public class OnlinePresenceService
|
||||
lock (set) return set.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>Connection ids of every player in <paramref name="playerIds"/>,
|
||||
/// in one go: the Redis lookups are issued together, so the multiplexer
|
||||
/// pipelines them into one round trip instead of one per player.</summary>
|
||||
public async Task<IReadOnlyCollection<string>> GetConnectionsAsync(IEnumerable<long> playerIds)
|
||||
{
|
||||
var ids = playerIds.Distinct().ToArray();
|
||||
if (ids.Length == 0) return Array.Empty<string>();
|
||||
if (_redis is { } mux)
|
||||
{
|
||||
try
|
||||
{
|
||||
var db = mux.GetDatabase();
|
||||
var sets = await Task.WhenAll(ids.Select(id => db.SetMembersAsync(ConnsKey(id))));
|
||||
return sets.SelectMany(s => s).Select(v => v.ToString()).ToArray();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Redis sick → fall through to the local fallback, as
|
||||
// GetConnections does.
|
||||
}
|
||||
}
|
||||
var result = new List<string>();
|
||||
foreach (var id in ids)
|
||||
if (_localConns.TryGetValue(id, out var set))
|
||||
lock (set) result.AddRange(set);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>Snapshot of currently-online player ids across the
|
||||
/// cluster. Returns an empty array when nobody's online; never null.
|
||||
/// Callers typically <c>.ToHashSet()</c> the result for membership
|
||||
|
||||
@@ -143,8 +143,11 @@ public sealed class PresenceBroadcastService(
|
||||
// offline frame otherwise. Friends were served above and the
|
||||
// subject must never get a frame about themselves, so their
|
||||
// connections are excluded.
|
||||
var exclude = connections.GetConnections(playerId)
|
||||
.Concat(friendIds.SelectMany(connections.GetConnections))
|
||||
// Only friends who are online have connections; one call for the
|
||||
// online set, then one pipelined lookup for all of them.
|
||||
var onlineIds = connections.OnlinePlayerIds().ToHashSet();
|
||||
var exclude = (await connections.GetConnectionsAsync(
|
||||
friendIds.Where(onlineIds.Contains).Append(playerId)))
|
||||
.Distinct()
|
||||
.ToList();
|
||||
var publicToAll = visibility == PresenceVisibility.Public && online;
|
||||
|
||||
Reference in New Issue
Block a user