mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
Fix GuidebookDataSystem late MsgEntity warning (#45298)
Send GuidebookData automatically to new clients.
This commit is contained in:
parent
8dc5621836
commit
7389733a0f
3 changed files with 14 additions and 15 deletions
|
|
@ -17,9 +17,6 @@ public sealed class GuidebookDataSystem : EntitySystem
|
|||
base.Initialize();
|
||||
|
||||
SubscribeNetworkEvent<UpdateGuidebookDataEvent>(OnServerUpdated);
|
||||
|
||||
// Request data from the server
|
||||
RaiseNetworkEvent(new RequestGuidebookDataEvent());
|
||||
}
|
||||
|
||||
private void OnServerUpdated(UpdateGuidebookDataEvent args)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
using System.Reflection;
|
||||
using Content.Shared.Guidebook;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
|
|
@ -11,6 +14,8 @@ namespace Content.Server.Guidebook;
|
|||
/// </summary>
|
||||
public sealed partial class GuidebookDataSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private IPlayerManager _player = default!;
|
||||
|
||||
private readonly Dictionary<string, List<MemberInfo>> _tagged = [];
|
||||
private GuidebookData _cachedData = new();
|
||||
|
||||
|
|
@ -18,18 +23,21 @@ public sealed partial class GuidebookDataSystem : EntitySystem
|
|||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeNetworkEvent<RequestGuidebookDataEvent>(OnRequestRules);
|
||||
SubscribeLocalEvent<PrototypesReloadedEventArgs>(OnPrototypesReloaded);
|
||||
_player.PlayerStatusChanged += OnPlayerStatusChanged;
|
||||
|
||||
// Build initial cache
|
||||
GatherData(ref _cachedData);
|
||||
}
|
||||
|
||||
private void OnRequestRules(RequestGuidebookDataEvent ev, EntitySessionEventArgs args)
|
||||
private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e)
|
||||
{
|
||||
// Send cached data to requesting client
|
||||
if (e.NewStatus != SessionStatus.Connected)
|
||||
return;
|
||||
|
||||
// Send cached data to newly-connected client.
|
||||
var sendEv = new UpdateGuidebookDataEvent(_cachedData);
|
||||
RaiseNetworkEvent(sendEv, args.SenderSession);
|
||||
RaiseNetworkEvent(sendEv, e.Session);
|
||||
}
|
||||
|
||||
private void OnPrototypesReloaded(PrototypesReloadedEventArgs args)
|
||||
|
|
|
|||
|
|
@ -3,14 +3,8 @@ using Robust.Shared.Serialization;
|
|||
namespace Content.Shared.Guidebook;
|
||||
|
||||
/// <summary>
|
||||
/// Raised by the client on GuidebookDataSystem Initialize to request a
|
||||
/// full set of guidebook data from the server.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class RequestGuidebookDataEvent : EntityEventArgs { }
|
||||
|
||||
/// <summary>
|
||||
/// Raised by the server at a specific client in response to <see cref="RequestGuidebookDataEvent"/>.
|
||||
/// Sends all extracted prototype data needed by GuidebookDataSystem.
|
||||
/// Raised by the server directed at newly-connected clients.
|
||||
/// Also raised by the server at ALL clients when prototype data is hot-reloaded.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue