Re-implement chat in content. (#198)

* OOC is a word.

* Re-implement chat in content.
This commit is contained in:
Pieter-Jan Briers
2019-04-13 09:45:09 +02:00
committed by GitHub
parent 51caae7ebe
commit 52af7d27da
25 changed files with 770 additions and 37 deletions

View File

@@ -0,0 +1,54 @@
using System;
namespace Content.Shared.Chat
{
/// <summary>
/// Represents chat channels that the player can filter chat tabs by.
/// </summary>
[Flags]
public enum ChatChannel : byte
{
None = 0,
/// <summary>
/// Chat heard by players within earshot
/// </summary>
Local = 1,
/// <summary>
/// Messages from the server
/// </summary>
Server = 2,
/// <summary>
/// Damage messages
/// </summary>
Damage = 4,
/// <summary>
/// Radio messages
/// </summary>
Radio = 8,
/// <summary>
/// Out-of-character channel
/// </summary>
OOC = 16,
/// <summary>
/// Visual events the player can see.
/// Basically like visual_message in SS13.
/// </summary>
Visual = 32,
/// <summary>
/// Emotes
/// </summary>
Emotes = 64,
/// <summary>
/// Unspecified.
/// </summary>
Unspecified = 128,
}
}

View File

@@ -0,0 +1,74 @@
using System;
using Lidgren.Network;
using SS14.Shared.GameObjects;
using SS14.Shared.Interfaces.Network;
using SS14.Shared.Network;
using SS14.Shared.Network.Messages;
namespace Content.Shared.Chat
{
/// <summary>
/// Sent from server to client to notify the client about a new chat message.
/// </summary>
public sealed class MsgChatMessage : NetMessage
{
#region REQUIRED
public const MsgGroups GROUP = MsgGroups.Command;
public const string NAME = nameof(MsgChatMessage);
public MsgChatMessage(INetChannel channel) : base(NAME, GROUP) { }
#endregion
/// <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>
public string Message { get; set; }
/// <summary>
/// What to "wrap" the message contents with. Example is stuff like 'Joe says: "{0}"'
/// </summary>
public string MessageWrap { get; set; }
/// <summary>
/// The sending entity.
/// Only applies to <see cref="ChatChannel.Local"/> and <see cref="ChatChannel.Emotes"/>.
/// </summary>
public EntityUid SenderEntity { get; set; }
public override void ReadFromBuffer(NetIncomingMessage buffer)
{
Channel = (ChatChannel) buffer.ReadByte();
Message = buffer.ReadString();
MessageWrap = buffer.ReadString();
switch (Channel)
{
case ChatChannel.Local:
case ChatChannel.Emotes:
SenderEntity = buffer.ReadEntityUid();
break;
}
}
public override void WriteToBuffer(NetOutgoingMessage buffer)
{
buffer.Write((byte)Channel);
buffer.Write(Message);
buffer.Write(MessageWrap);
switch (Channel)
{
case ChatChannel.Local:
case ChatChannel.Emotes:
buffer.Write(SenderEntity);
break;
}
}
}
}