mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-26 23:48:45 -07:00
Fix live room and account updates
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using DorkNet.Models.Notification;
|
||||
using DorkNet.Server.Controllers.Match;
|
||||
using DorkNet.Models.Auth;
|
||||
using DorkNet.Server.Data.Entities;
|
||||
using DorkNet.Server.Hubs;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using System.Text.Json;
|
||||
@@ -158,6 +160,48 @@ public class NotificationService(
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Push fresh account payloads to the affected player's
|
||||
/// watch. The 2020 client caches Account/SelfAccount objects in memory;
|
||||
/// without this, username and display-name edits persist server-side
|
||||
/// but the current session keeps rendering the stale cached names until
|
||||
/// a full relog rebuilds the account cache.</summary>
|
||||
public Task AccountChanged(PlayerEntity player)
|
||||
{
|
||||
var account = new RecNetAccount
|
||||
{
|
||||
AccountId = (int)player.Id,
|
||||
RawUsername = player.Username,
|
||||
Username = player.Username,
|
||||
DisplayName = string.IsNullOrWhiteSpace(player.DisplayName) ? player.Username : player.DisplayName,
|
||||
ProfileImage = player.ProfileImageName ?? string.Empty,
|
||||
TreatAsJunior = player.IsJunior,
|
||||
HasBirthday = true,
|
||||
Platforms = 1,
|
||||
CreatedAt = player.CreatedAt,
|
||||
};
|
||||
var selfAccount = new RecNetSelfAccount
|
||||
{
|
||||
AccountId = account.AccountId,
|
||||
RawUsername = account.RawUsername,
|
||||
Username = account.Username,
|
||||
DisplayName = account.DisplayName,
|
||||
ProfileImage = account.ProfileImage,
|
||||
TreatAsJunior = account.TreatAsJunior,
|
||||
HasBirthday = account.HasBirthday,
|
||||
Platforms = account.Platforms,
|
||||
CreatedAt = account.CreatedAt,
|
||||
Email = player.Email ?? string.Empty,
|
||||
Phone = player.Phone ?? string.Empty,
|
||||
Birthday = player.Birthday ?? new DateTime(2000, 1, 1),
|
||||
JuniorState = player.IsJunior ? 1 : 0,
|
||||
ParentAccountId = null,
|
||||
};
|
||||
|
||||
return Task.WhenAll(
|
||||
NotifyAsync(player.Id, PushNotificationId.SubscriptionUpdateProfile, account),
|
||||
NotifyTypedAsync(player.Id, "SelfAccountUpdate", selfAccount));
|
||||
}
|
||||
|
||||
/// <summary>Push a notification to every currently-connected
|
||||
/// player. Used for global announcements and admin broadcasts.</summary>
|
||||
public async Task BroadcastAsync(PushNotificationId id, object? msg = null)
|
||||
|
||||
@@ -30,10 +30,28 @@ public class RoomDataBlobService
|
||||
/// startup beats rebuilding on every download request.
|
||||
/// </summary>
|
||||
private readonly byte[] _allPermsBlob = BuildAllPermsBlob();
|
||||
private readonly RoomRoleCollectionData _allPermsRoleData = BuildAllPermsRoleData();
|
||||
|
||||
public byte[] GetDefaultBlob() => _allPermsBlob;
|
||||
|
||||
public byte[] OverlayAllPermsRoleData(byte[] existingBlob)
|
||||
{
|
||||
var msg = PersistedRoomData.Parser.ParseFrom(existingBlob);
|
||||
msg.RoomRoleData = _allPermsRoleData.Clone();
|
||||
return msg.ToByteArray();
|
||||
}
|
||||
|
||||
private static byte[] BuildAllPermsBlob()
|
||||
{
|
||||
var msg = new PersistedRoomData
|
||||
{
|
||||
RoomRoleData = BuildAllPermsRoleData(),
|
||||
};
|
||||
|
||||
return msg.ToByteArray();
|
||||
}
|
||||
|
||||
private static RoomRoleCollectionData BuildAllPermsRoleData()
|
||||
{
|
||||
// OverridableBoolData(overrides=true, inner_value=true) — used for
|
||||
// every Can* field on the role.
|
||||
@@ -101,11 +119,6 @@ public class RoomDataBlobService
|
||||
var collection = new RoomRoleCollectionData();
|
||||
collection.RoomRoles.Add(role);
|
||||
|
||||
var msg = new PersistedRoomData
|
||||
{
|
||||
RoomRoleData = collection,
|
||||
};
|
||||
|
||||
return msg.ToByteArray();
|
||||
return collection;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user