1
0

BwoinkSystem.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #nullable enable
  2. using Content.Shared.Administration;
  3. using JetBrains.Annotations;
  4. using Robust.Shared.Network;
  5. using Robust.Shared.Timing;
  6. namespace Content.Client.Administration.Systems
  7. {
  8. [UsedImplicitly]
  9. public sealed class BwoinkSystem : SharedBwoinkSystem
  10. {
  11. [Dependency] private readonly IGameTiming _timing = default!;
  12. public event EventHandler<BwoinkTextMessage>? OnBwoinkTextMessageRecieved;
  13. private (TimeSpan Timestamp, bool Typing) _lastTypingUpdateSent;
  14. protected override void OnBwoinkTextMessage(BwoinkTextMessage message, EntitySessionEventArgs eventArgs)
  15. {
  16. OnBwoinkTextMessageRecieved?.Invoke(this, message);
  17. }
  18. public void Send(NetUserId channelId, string text, bool playSound, bool adminOnly)
  19. {
  20. // Reuse the channel ID as the 'true sender'.
  21. // Server will ignore this and if someone makes it not ignore this (which is bad, allows impersonation!!!), that will help.
  22. RaiseNetworkEvent(new BwoinkTextMessage(channelId, channelId, text, playSound: playSound, adminOnly: adminOnly));
  23. SendInputTextUpdated(channelId, false);
  24. }
  25. public void SendInputTextUpdated(NetUserId channel, bool typing)
  26. {
  27. if (_lastTypingUpdateSent.Typing == typing &&
  28. _lastTypingUpdateSent.Timestamp + TimeSpan.FromSeconds(1) > _timing.RealTime)
  29. {
  30. return;
  31. }
  32. _lastTypingUpdateSent = (_timing.RealTime, typing);
  33. RaiseNetworkEvent(new BwoinkClientTypingUpdated(channel, typing));
  34. }
  35. }
  36. }