2021-02-14 11:59:56 -03:00
|
|
|
using JetBrains.Annotations;
|
2019-04-13 09:45:09 +02:00
|
|
|
using Lidgren.Network;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-02-14 11:59:56 -03:00
|
|
|
using Robust.Shared.Maths;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Shared.Network;
|
2019-04-13 09:45:09 +02:00
|
|
|
|
|
|
|
|
namespace Content.Shared.Chat
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sent from server to client to notify the client about a new chat message.
|
|
|
|
|
/// </summary>
|
2021-02-14 11:59:56 -03:00
|
|
|
[UsedImplicitly]
|
2019-04-13 09:45:09 +02:00
|
|
|
public sealed class MsgChatMessage : NetMessage
|
|
|
|
|
{
|
2021-06-20 22:43:54 -07:00
|
|
|
public override MsgGroups MsgGroup => MsgGroups.Command;
|
2019-04-13 09:45:09 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The channel the message is on. This can also change whether certain params are used.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ChatChannel Channel { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The actual message contents.
|
|
|
|
|
/// </summary>
|
2021-02-27 04:12:09 +01:00
|
|
|
public string Message { get; set; } = string.Empty;
|
2019-04-13 09:45:09 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// What to "wrap" the message contents with. Example is stuff like 'Joe says: "{0}"'
|
|
|
|
|
/// </summary>
|
2021-02-27 04:12:09 +01:00
|
|
|
public string MessageWrap { get; set; } = string.Empty;
|
2019-04-13 09:45:09 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The sending entity.
|
2020-04-09 03:31:40 +02:00
|
|
|
/// Only applies to <see cref="ChatChannel.Local"/>, <see cref="ChatChannel.Dead"/> and <see cref="ChatChannel.Emotes"/>.
|
2019-04-13 09:45:09 +02:00
|
|
|
/// </summary>
|
|
|
|
|
public EntityUid SenderEntity { get; set; }
|
|
|
|
|
|
2021-02-14 11:59:56 -03:00
|
|
|
/// <summary>
|
|
|
|
|
/// The override color of the message
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Color MessageColorOverride { get; set; } = Color.Transparent;
|
|
|
|
|
|
2021-11-19 07:36:25 +01:00
|
|
|
public bool HideChat { get; set; }
|
|
|
|
|
|
2021-02-14 11:59:56 -03:00
|
|
|
|
2019-04-13 09:45:09 +02:00
|
|
|
public override void ReadFromBuffer(NetIncomingMessage buffer)
|
|
|
|
|
{
|
2020-07-08 05:18:16 -05:00
|
|
|
Channel = (ChatChannel) buffer.ReadInt16();
|
2019-04-13 09:45:09 +02:00
|
|
|
Message = buffer.ReadString();
|
|
|
|
|
MessageWrap = buffer.ReadString();
|
|
|
|
|
|
|
|
|
|
switch (Channel)
|
|
|
|
|
{
|
|
|
|
|
case ChatChannel.Local:
|
2022-01-11 06:48:18 -08:00
|
|
|
case ChatChannel.Whisper:
|
2020-04-09 03:31:40 +02:00
|
|
|
case ChatChannel.Dead:
|
2021-07-20 10:29:09 +02:00
|
|
|
case ChatChannel.Admin:
|
2019-04-13 09:45:09 +02:00
|
|
|
case ChatChannel.Emotes:
|
|
|
|
|
SenderEntity = buffer.ReadEntityUid();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-02-14 11:59:56 -03:00
|
|
|
MessageColorOverride = buffer.ReadColor();
|
2021-11-19 07:36:25 +01:00
|
|
|
HideChat = buffer.ReadBoolean();
|
2019-04-13 09:45:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void WriteToBuffer(NetOutgoingMessage buffer)
|
|
|
|
|
{
|
2020-07-08 05:18:16 -05:00
|
|
|
buffer.Write((short)Channel);
|
2019-04-13 09:45:09 +02:00
|
|
|
buffer.Write(Message);
|
|
|
|
|
buffer.Write(MessageWrap);
|
|
|
|
|
|
|
|
|
|
switch (Channel)
|
|
|
|
|
{
|
|
|
|
|
case ChatChannel.Local:
|
2022-01-11 06:48:18 -08:00
|
|
|
case ChatChannel.Whisper:
|
2020-04-09 03:31:40 +02:00
|
|
|
case ChatChannel.Dead:
|
2021-07-20 10:29:09 +02:00
|
|
|
case ChatChannel.Admin:
|
2019-04-13 09:45:09 +02:00
|
|
|
case ChatChannel.Emotes:
|
|
|
|
|
buffer.Write(SenderEntity);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-02-14 11:59:56 -03:00
|
|
|
buffer.Write(MessageColorOverride);
|
2021-11-19 07:36:25 +01:00
|
|
|
buffer.Write(HideChat);
|
2019-04-13 09:45:09 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|