2021-10-06 16:25:27 +01:00
|
|
|
|
#nullable enable
|
|
|
|
|
|
using Content.Shared.Administration;
|
|
|
|
|
|
using JetBrains.Annotations;
|
2021-12-22 13:34:09 +01:00
|
|
|
|
using Robust.Shared.Network;
|
2023-08-13 16:03:17 -07:00
|
|
|
|
using Robust.Shared.Timing;
|
2021-10-06 16:25:27 +01:00
|
|
|
|
|
2022-07-21 17:30:00 -05:00
|
|
|
|
namespace Content.Client.Administration.Systems
|
2021-10-06 16:25:27 +01:00
|
|
|
|
{
|
|
|
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class BwoinkSystem : SharedBwoinkSystem
|
2021-10-06 16:25:27 +01:00
|
|
|
|
{
|
2023-08-13 16:03:17 -07:00
|
|
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
|
|
|
|
|
2022-10-12 01:16:23 -07:00
|
|
|
|
public event EventHandler<BwoinkTextMessage>? OnBwoinkTextMessageRecieved;
|
2023-08-13 16:03:17 -07:00
|
|
|
|
private (TimeSpan Timestamp, bool Typing) _lastTypingUpdateSent;
|
2022-09-14 20:42:35 -07:00
|
|
|
|
|
2021-10-06 16:25:27 +01:00
|
|
|
|
protected override void OnBwoinkTextMessage(BwoinkTextMessage message, EntitySessionEventArgs eventArgs)
|
|
|
|
|
|
{
|
2022-10-12 01:16:23 -07:00
|
|
|
|
OnBwoinkTextMessageRecieved?.Invoke(this, message);
|
2021-10-06 16:25:27 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-21 00:52:03 -06:00
|
|
|
|
public void Send(NetUserId channelId, string text, bool playSound)
|
2021-10-06 16:25:27 +01:00
|
|
|
|
{
|
|
|
|
|
|
// Reuse the channel ID as the 'true sender'.
|
|
|
|
|
|
// Server will ignore this and if someone makes it not ignore this (which is bad, allows impersonation!!!), that will help.
|
2024-02-21 00:52:03 -06:00
|
|
|
|
RaiseNetworkEvent(new BwoinkTextMessage(channelId, channelId, text, playSound: playSound));
|
2023-08-13 16:03:17 -07:00
|
|
|
|
SendInputTextUpdated(channelId, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SendInputTextUpdated(NetUserId channel, bool typing)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_lastTypingUpdateSent.Typing == typing &&
|
|
|
|
|
|
_lastTypingUpdateSent.Timestamp + TimeSpan.FromSeconds(1) > _timing.RealTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_lastTypingUpdateSent = (_timing.RealTime, typing);
|
|
|
|
|
|
RaiseNetworkEvent(new BwoinkClientTypingUpdated(channel, typing));
|
2021-10-06 16:25:27 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|