SharedBwoinkSystem.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #nullable enable
  2. using Robust.Shared.Network;
  3. using Robust.Shared.Serialization;
  4. namespace Content.Shared.Administration
  5. {
  6. public abstract class SharedBwoinkSystem : EntitySystem
  7. {
  8. // System users
  9. public static NetUserId SystemUserId { get; } = new NetUserId(Guid.Empty);
  10. public override void Initialize()
  11. {
  12. base.Initialize();
  13. SubscribeNetworkEvent<BwoinkTextMessage>(OnBwoinkTextMessage);
  14. }
  15. protected virtual void OnBwoinkTextMessage(BwoinkTextMessage message, EntitySessionEventArgs eventArgs)
  16. {
  17. // Specific side code in target.
  18. }
  19. protected void LogBwoink(BwoinkTextMessage message)
  20. {
  21. }
  22. [Serializable, NetSerializable]
  23. public sealed class BwoinkTextMessage : EntityEventArgs
  24. {
  25. public DateTime SentAt { get; }
  26. public NetUserId UserId { get; }
  27. // This is ignored from the client.
  28. // It's checked by the client when receiving a message from the server for bwoink noises.
  29. // This could be a boolean "Incoming", but that would require making a second instance.
  30. public NetUserId TrueSender { get; }
  31. public string Text { get; }
  32. public bool PlaySound { get; }
  33. public readonly bool AdminOnly;
  34. public BwoinkTextMessage(NetUserId userId, NetUserId trueSender, string text, DateTime? sentAt = default, bool playSound = true, bool adminOnly = false)
  35. {
  36. SentAt = sentAt ?? DateTime.Now;
  37. UserId = userId;
  38. TrueSender = trueSender;
  39. Text = text;
  40. PlaySound = playSound;
  41. AdminOnly = adminOnly;
  42. }
  43. }
  44. }
  45. /// <summary>
  46. /// Sent by the server to notify all clients when the webhook url is sent.
  47. /// The webhook url itself is not and should not be sent.
  48. /// </summary>
  49. [Serializable, NetSerializable]
  50. public sealed class BwoinkDiscordRelayUpdated : EntityEventArgs
  51. {
  52. public bool DiscordRelayEnabled { get; }
  53. public BwoinkDiscordRelayUpdated(bool enabled)
  54. {
  55. DiscordRelayEnabled = enabled;
  56. }
  57. }
  58. /// <summary>
  59. /// Sent by the client to notify the server when it begins or stops typing.
  60. /// </summary>
  61. [Serializable, NetSerializable]
  62. public sealed class BwoinkClientTypingUpdated : EntityEventArgs
  63. {
  64. public NetUserId Channel { get; }
  65. public bool Typing { get; }
  66. public BwoinkClientTypingUpdated(NetUserId channel, bool typing)
  67. {
  68. Channel = channel;
  69. Typing = typing;
  70. }
  71. }
  72. /// <summary>
  73. /// Sent by server to notify admins when a player begins or stops typing.
  74. /// </summary>
  75. [Serializable, NetSerializable]
  76. public sealed class BwoinkPlayerTypingUpdated : EntityEventArgs
  77. {
  78. public NetUserId Channel { get; }
  79. public string PlayerName { get; }
  80. public bool Typing { get; }
  81. public BwoinkPlayerTypingUpdated(NetUserId channel, string playerName, bool typing)
  82. {
  83. Channel = channel;
  84. PlayerName = playerName;
  85. Typing = typing;
  86. }
  87. }
  88. }