Remove chat from the engine. (#790)

* Remove chat from the engine.

* I could've sworn I ran tests
This commit is contained in:
Pieter-Jan Briers
2019-04-13 09:41:28 +02:00
committed by GitHub
parent a2c1ddb22c
commit e9b45adf1c
27 changed files with 29 additions and 1015 deletions

View File

@@ -1,162 +0,0 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://Engine/Fonts/CALIBRI.TTF" type="DynamicFontData" id=1]
[sub_resource type="StyleBoxFlat" id=3]
content_margin_left = -1.0
content_margin_right = -1.0
content_margin_top = -1.0
content_margin_bottom = -1.0
bg_color = Color( 0.501961, 0.501961, 0.501961, 0.501961 )
draw_center = true
border_width_left = 1
border_width_top = 1
border_width_right = 1
border_width_bottom = 1
border_color = Color( 0, 0, 0, 0.501961 )
border_blend = false
corner_radius_top_left = 0
corner_radius_top_right = 0
corner_radius_bottom_right = 0
corner_radius_bottom_left = 0
corner_detail = 8
expand_margin_left = 1.0
expand_margin_right = 1.0
expand_margin_top = 1.0
expand_margin_bottom = 1.0
shadow_color = Color( 0, 0, 0, 0.6 )
shadow_size = 0
anti_aliasing = true
anti_aliasing_size = 1
_sections_unfolded = [ "Anti Aliasing", "Border Width", "Corner Radius", "Expand Margin", "Shadow" ]
[sub_resource type="DynamicFont" id=1]
size = 16
use_mipmaps = false
use_filter = false
font_data = ExtResource( 1 )
_sections_unfolded = [ "Extra Spacing", "Font/fallback", "Settings" ]
[sub_resource type="StyleBoxFlat" id=2]
content_margin_left = 2.0
content_margin_right = -1.0
content_margin_top = -1.0
content_margin_bottom = -1.0
bg_color = Color( 0.0234375, 0.0234375, 0.0234375, 0.501961 )
draw_center = true
border_width_left = 0
border_width_top = 0
border_width_right = 0
border_width_bottom = 0
border_color = Color( 0.8, 0.8, 0.8, 1 )
border_blend = false
corner_radius_top_left = 1
corner_radius_top_right = 1
corner_radius_bottom_right = 0
corner_radius_bottom_left = 0
corner_detail = 8
expand_margin_left = 0.0
expand_margin_right = 0.0
expand_margin_top = 0.0
expand_margin_bottom = 0.0
shadow_color = Color( 0, 0, 0, 0.6 )
shadow_size = 0
anti_aliasing = true
anti_aliasing_size = 1
_sections_unfolded = [ "Content Margin", "Corner Radius", "Expand Margin" ]
[node name="ChatBox" type="PanelContainer" index="0"]
anchor_left = 1.0
anchor_top = 0.0
anchor_right = 1.0
anchor_bottom = 0.0
margin_left = -475.0
margin_top = 10.0
margin_right = -10.0
margin_bottom = 185.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
custom_styles/panel = SubResource( 3 )
_sections_unfolded = [ "Anchor", "Grow Direction", "Margin", "Rect", "custom_styles" ]
[node name="VBoxContainer" type="VBoxContainer" parent="." index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 1.0
margin_top = 1.0
margin_right = 464.0
margin_bottom = 174.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
alignment = 0
[node name="Contents" type="RichTextLabel" parent="VBoxContainer" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 463.0
margin_bottom = 153.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = true
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 3
custom_fonts/normal_font = SubResource( 1 )
bbcode_enabled = false
bbcode_text = ""
visible_characters = -1
percent_visible = 1.0
meta_underlined = true
tab_size = 4
text = ""
scroll_active = true
scroll_following = false
selection_enabled = false
override_selected_font_color = false
_sections_unfolded = [ "BBCode", "Size Flags", "custom_fonts" ]
[node name="Input" type="LineEdit" parent="VBoxContainer" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 157.0
margin_right = 463.0
margin_bottom = 173.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 1
size_flags_horizontal = 1
size_flags_vertical = 1
custom_styles/normal = SubResource( 2 )
custom_fonts/font = SubResource( 1 )
focus_mode = 2
context_menu_enabled = true
placeholder_alpha = 0.6
caret_blink = true
caret_blink_speed = 0.5
caret_position = 0
_sections_unfolded = [ "Margin", "custom_colors", "custom_constants", "custom_fonts", "custom_styles" ]

View File

@@ -1,152 +0,0 @@
using System.Collections.Generic;
using SS14.Client.Interfaces.GameObjects;
using SS14.Client.Player;
using SS14.Client.UserInterface.CustomControls;
using SS14.Shared.Console;
using SS14.Shared.GameObjects;
using SS14.Shared.IoC;
using SS14.Shared.Maths;
using SS14.Shared.Network.Messages;
using SS14.Shared.Log;
namespace SS14.Client.Console
{
/// <summary>
/// Expands the console to support chat, channels, and emotes.
/// </summary>
public class ClientChatConsole : ClientConsole, IClientChatConsole
{
private const char ConCmdSlash = '/';
private const char OocAlias = '[';
private const char MeAlias = '@';
private readonly Dictionary<ChatChannel, Color> _chatColors;
[Dependency]
private readonly IClientEntityManager _entityManager;
[Dependency]
private readonly IPlayerManager _players;
/// <summary>
/// Default Constructor.
/// </summary>
public ClientChatConsole()
{
_chatColors = new Dictionary<ChatChannel, Color>
{
[ChatChannel.Default] = Color.Gray,
[ChatChannel.Damage] = Color.Red,
[ChatChannel.Radio] = new Color(0, 100, 0),
[ChatChannel.Server] = Color.Blue,
[ChatChannel.Player] = new Color(0, 128, 0),
[ChatChannel.Local] = new Color(0, 200, 0),
[ChatChannel.OOC] = Color.White,
[ChatChannel.Emote] = Color.Cyan,
[ChatChannel.Visual] = Color.Yellow,
};
}
/// <summary>
/// Initializes the console into a useable state.
/// </summary>
public override void Initialize()
{
base.Initialize();
_network.RegisterNetMessage<MsgChat>(MsgChat.NAME, HandleChatMsg);
}
/// <inheritdoc />
public void ParseChatMessage(Chatbox chatBox, string text)
{
ParseChatMessage(text, chatBox.DefaultChatFormat);
}
/// <inheritdoc />
public void ParseChatMessage(string text, string defaultFormat = null)
{
if (string.IsNullOrWhiteSpace(text))
return;
switch (text[0])
{
case ConCmdSlash:
{
// run locally
var conInput = text.Substring(1);
ProcessCommand(conInput);
break;
}
case OocAlias:
{
var conInput = text.Substring(2);
ProcessCommand($"ooc \"{conInput}\"");
break;
}
case MeAlias:
{
var conInput = text.Substring(2);
ProcessCommand($"me \"{conInput}\"");
break;
}
default:
{
var conInput = defaultFormat != null ? string.Format(defaultFormat, text) : text;
Logger.Debug(conInput);
ProcessCommand(conInput);
break;
}
}
}
private void HandleChatMsg(MsgChat msg)
{
Logger.Debug($"Got it! {msg.Text}");
var channel = msg.Channel;
var text = msg.Text;
var index = msg.SessionId;
var entityId = msg.EntityId;
switch (channel)
{
case ChatChannel.Local:
case ChatChannel.Server:
case ChatChannel.OOC:
case ChatChannel.Radio:
{
string name;
if (index.HasValue && _players.SessionsDict.TryGetValue(index.Value, out var session))
{
name = session.Name;
}
else if (entityId.HasValue)
{
var ent = _entityManager.GetEntity(entityId.Value);
name = ent.Name ?? ent.ToString();
}
else
{
name = "<TERU-SAMA>";
}
text = $"[{channel}] {name}: {text}";
break;
}
}
AddLine(text, channel, GetChannelColor(channel));
if (entityId.HasValue && _entityManager.TryGetEntity(entityId.Value, out var a))
a.SendMessage(null, new SaidSomethingMsg(channel, text));
}
private Color GetChannelColor(ChatChannel channel)
{
if (_chatColors.TryGetValue(channel, out var color))
return color;
return Color.White;
}
}
}

View File

@@ -21,13 +21,11 @@ namespace SS14.Client.Console
{
public string Text { get; }
public Color Color { get; }
public ChatChannel Channel { get; }
public AddStringArgs(string text, Color color, ChatChannel channel)
public AddStringArgs(string text, Color color)
{
Text = text;
Color = color;
Channel = channel;
}
}
@@ -41,7 +39,7 @@ namespace SS14.Client.Console
}
}
public class ClientConsole : IClientConsole, IDebugConsole
internal sealed class ClientConsole : IClientConsole, IDebugConsole
{
private static readonly Color MsgColor = new Color(65, 105, 225);
@@ -56,7 +54,7 @@ namespace SS14.Client.Console
private bool _requestedCommands;
/// <inheritdoc />
public virtual void Initialize()
public void Initialize()
{
_network.RegisterNetMessage<MsgConCmdReg>(MsgConCmdReg.NAME, HandleConCmdReg);
_network.RegisterNetMessage<MsgConCmdAck>(MsgConCmdAck.NAME, HandleConCmdAck);
@@ -67,7 +65,7 @@ namespace SS14.Client.Console
}
/// <inheritdoc />
public virtual void Reset()
public void Reset()
{
_commands.Clear();
_requestedCommands = false;
@@ -90,19 +88,14 @@ namespace SS14.Client.Console
public IReadOnlyDictionary<string, IConsoleCommand> Commands => _commands;
public void AddLine(string text, ChatChannel channel, Color color)
{
AddString?.Invoke(this, new AddStringArgs(text, color, channel));
}
public void AddLine(string text, Color color)
{
AddLine(text, ChatChannel.Default, color);
AddString?.Invoke(this, new AddStringArgs(text, color));
}
public void AddLine(string text)
{
AddLine(text, ChatChannel.Default, Color.White);
AddLine(text, Color.White);
}
public void Clear()
@@ -116,7 +109,7 @@ namespace SS14.Client.Console
private void HandleConCmdAck(MsgConCmdAck msg)
{
AddLine("< " + msg.Text, ChatChannel.Default, MsgColor);
AddLine("< " + msg.Text, MsgColor);
}
private void HandleConCmdReg(MsgConCmdReg msg)
@@ -147,7 +140,7 @@ namespace SS14.Client.Console
return;
// echo the command locally
AddLine("> " + text, ChatChannel.Default, Color.Lime);
AddLine("> " + text, Color.Lime);
//Commands are processed locally and then sent to the server to be processed there again.
var args = new List<string>();
@@ -165,7 +158,7 @@ namespace SS14.Client.Console
}
else if (!_network.IsConnected)
{
AddLine("Unknown command: " + commandname, ChatChannel.Default, Color.Red);
AddLine("Unknown command: " + commandname, Color.Red);
return;
}

View File

@@ -34,7 +34,7 @@ namespace SS14.Client.Console.Commands
Random random = new Random();
for (int x = 0; x < 50; x++)
{
console.AddLine("filling...", ChatChannel.Default, colors[random.Next(0, colors.Length)]);
console.AddLine("filling...", colors[random.Next(0, colors.Length)]);
}
return false;
}

View File

@@ -47,8 +47,7 @@ namespace SS14.Client.Console.Commands
foreach (var e in entityManager.GetEntities())
{
console.AddLine($"entity {e.Uid}, {e.Prototype.ID}, {e.Transform.GridPosition}.", ChatChannel.Default,
Color.White);
console.AddLine($"entity {e.Uid}, {e.Prototype.ID}, {e.Transform.GridPosition}.", Color.White);
}
return false;

View File

@@ -1,23 +0,0 @@
using System;
using SS14.Client.UserInterface.CustomControls;
namespace SS14.Client.Console
{
/// <summary>
/// Interface for a chat compatible console.
/// </summary>
public interface IClientChatConsole : IClientConsole
{
/// <summary>
/// Parses a raw chat message the player has submitted.
/// </summary>
/// <param name="text">Raw unsanitized string the player submitted.</param>
/// <param name="defaultFormat"></param>
void ParseChatMessage(string text, string defaultFormat = null);
/// <summary>
/// Parses a raw chat message the player has submitted.
/// </summary>
void ParseChatMessage(Chatbox chatBox, string text);
}
}

View File

@@ -78,7 +78,7 @@ namespace SS14.Client
[Dependency] private readonly IUserInterfaceManagerInternal _userInterfaceManager;
[Dependency] private readonly IBaseClient _client;
[Dependency] private readonly IInputManager _inputManager;
[Dependency] private readonly IClientChatConsole _console;
[Dependency] private readonly IClientConsole _console;
[Dependency] private readonly ILightManager _lightManager;
[Dependency] private readonly IDisplayManager _displayManager;
[Dependency] private readonly ITimerManager _timerManager;

View File

@@ -130,10 +130,9 @@ namespace SS14.Client
IoCManager.Register<IGameControllerProxy, GameControllerProxy>();
IoCManager.Register<IGameControllerProxyInternal, GameControllerProxy>();
IoCManager.Register<IDebugDrawing, DebugDrawing>();
IoCManager.Register<IClientConsole, ClientChatConsole>();
IoCManager.Register<IClientChatConsole, ClientChatConsole>();
IoCManager.Register<ILightManager, LightManager>();
IoCManager.Register<IDiscordRichPresence, DiscordRichPresence>();
IoCManager.Register<IClientConsole, ClientConsole>();
switch (Mode)
{
case DisplayMode.Headless:

View File

@@ -15,7 +15,6 @@ namespace SS14.Client.Input
{
var common = contexts.GetContext(InputContextContainer.DefaultContextName);
common.AddFunction(EngineKeyFunctions.EscapeMenu);
common.AddFunction(EngineKeyFunctions.FocusChat);
common.AddFunction(EngineKeyFunctions.HideUI);
common.AddFunction(EngineKeyFunctions.ShowDebugMonitors);
common.AddFunction(EngineKeyFunctions.MoveUp);

View File

@@ -14,8 +14,6 @@ namespace SS14.Client.Interfaces.Console
/// <summary>
/// Write a line with a specific color to the console window.
/// </summary>
void AddLine(string text, ChatChannel channel, Color color);
void AddLine(string text, Color color);
void AddLine(string text);

View File

@@ -100,10 +100,8 @@
<Compile Include="Animations\Animation.cs" />
<Compile Include="Audio\AudioStream.cs" />
<Compile Include="BaseClient.cs" />
<Compile Include="Console\ClientChatConsole.cs" />
<Compile Include="Console\ClientConsole.cs" />
<Compile Include="Console\Commands\LogCommands.cs" />
<Compile Include="Console\IClientChatConsole.cs" />
<Compile Include="Console\IClientConsole.cs" />
<Compile Include="GameController.cs" />
<Compile Include="GameController\FrameEventArgs.cs" />
@@ -244,7 +242,6 @@
<Compile Include="UserInterface\Controls\TabContainer.cs" />
<Compile Include="UserInterface\Controls\VScrollBar.cs" />
<Compile Include="UserInterface\Controls\VSplitContainer.cs" />
<Compile Include="UserInterface\CustomControls\Chatbox.cs" />
<Compile Include="UserInterface\CustomControls\DebugTimePanel.cs" />
<Compile Include="UserInterface\CustomControls\FrameGraph.cs" />
<Compile Include="UserInterface\CustomControls\Tooltip.cs" />

View File

@@ -1,181 +0,0 @@
using System.Collections.Generic;
using SS14.Client.Console;
using SS14.Client.Graphics.Drawing;
using SS14.Client.Input;
using SS14.Client.UserInterface.Controls;
using SS14.Client.Utility;
using SS14.Shared.Console;
using SS14.Shared.Maths;
using SS14.Shared.Utility;
namespace SS14.Client.UserInterface.CustomControls
{
public class Chatbox : PanelContainer
{
protected override ResourcePath ScenePath => new ResourcePath("/Scenes/ChatBox/ChatBox.tscn");
public delegate void TextSubmitHandler(Chatbox chatbox, string text);
private const int MaxLinePixelLength = 500;
private readonly IList<string> _inputHistory = new List<string>();
public LineEdit Input { get; private set; }
private OutputPanel contents;
/// <summary>
/// Index while cycling through the input history. -1 means not going through history.
/// </summary>
private int _inputIndex = -1;
/// <summary>
/// Message that WAS being input before going through history began.
/// </summary>
private string _inputTemp;
/// <summary>
/// Default formatting string for the ClientChatConsole.
/// </summary>
public string DefaultChatFormat { get; set; }
/// <summary>
/// Blacklists channels from being displayed.
/// </summary>
public List<ChatChannel> ChannelBlacklist { get; set; } = new List<ChatChannel>()
{
ChatChannel.Default,
};
protected override void Initialize()
{
base.Initialize();
Input = GetChild<LineEdit>("VBoxContainer/Input");
Input.OnKeyDown += InputKeyDown;
Input.OnTextEntered += Input_OnTextEntered;
GetChild<Control>("VBoxContainer/Contents").Dispose();
contents = new OutputPanel
{
SizeFlagsVertical = SizeFlags.FillExpand,
};
GetChild("VBoxContainer").AddChild(contents);
contents.SetPositionInParent(0);
if (!GameController.OnGodot)
{
PanelOverride = new StyleBoxFlat { BackgroundColor = Color.Gray.WithAlpha(0.5f)};
}
}
protected internal override void MouseDown(GUIMouseButtonEventArgs e)
{
base.MouseDown(e);
Input.GrabKeyboardFocus();
}
private void InputKeyDown(GUIKeyEventArgs e)
{
if (e.Key == Keyboard.Key.Escape)
{
Input.ReleaseKeyboardFocus();
e.Handle();
return;
}
if (e.Key == Keyboard.Key.Up)
{
if (_inputIndex == -1 && _inputHistory.Count != 0)
{
_inputTemp = Input.Text;
_inputIndex++;
}
else if (_inputIndex + 1 < _inputHistory.Count)
{
_inputIndex++;
}
if (_inputIndex != -1)
{
Input.Text = _inputHistory[_inputIndex];
}
e.Handle();
return;
}
if (e.Key == Keyboard.Key.Down)
{
if (_inputIndex == 0)
{
Input.Text = _inputTemp;
_inputTemp = "";
_inputIndex--;
}
else if (_inputIndex != -1)
{
_inputIndex--;
Input.Text = _inputHistory[_inputIndex];
}
e.Handle();
}
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
TextSubmitted = null;
Input = null;
contents = null;
}
}
public event TextSubmitHandler TextSubmitted;
public void AddLine(string message, ChatChannel channel, Color color)
{
if (Disposed)
{
return;
}
if (ChannelBlacklist.Contains(channel))
return;
var formatted = new FormattedMessage(3);
formatted.PushColor(color);
formatted.AddText(message);
formatted.Pop();
contents.AddMessage(formatted);
}
public void AddLine(string text, Color color)
{
AddLine(text, ChatChannel.Default, color);
}
private void Input_OnTextEntered(LineEdit.LineEditEventArgs args)
{
if (!string.IsNullOrWhiteSpace(args.Text))
{
TextSubmitted?.Invoke(this, args.Text);
_inputHistory.Insert(0, args.Text);
}
_inputIndex = -1;
Input.Clear();
Input.ReleaseKeyboardFocus();
}
public void AddLine(object sender, AddStringArgs e)
{
AddLine(e.Text, e.Channel, e.Color);
}
}
}

View File

@@ -76,7 +76,7 @@ namespace SS14.Client.UserInterface.CustomControls
CommandBar.OnTextEntered += CommandEntered;
CommandBar.OnTextChanged += CommandBarOnOnTextChanged;
_console.AddString += (_, args) => AddLine(args.Text, args.Channel, args.Color);
_console.AddString += (_, args) => AddLine(args.Text, args.Color);
_console.AddFormatted += (_, args) => AddFormattedLine(args.Message);
_console.ClearText += (_, args) => Clear();
@@ -127,7 +127,7 @@ namespace SS14.Client.UserInterface.CustomControls
}
}
public void AddLine(string text, ChatChannel channel, Color color)
public void AddLine(string text, Color color)
{
var formatted = new FormattedMessage(3);
formatted.PushColor(color);
@@ -136,14 +136,9 @@ namespace SS14.Client.UserInterface.CustomControls
AddFormattedLine(formatted);
}
public void AddLine(string text, Color color)
{
AddLine(text, ChatChannel.Default, color);
}
public void AddLine(string text)
{
AddLine(text, ChatChannel.Default, Color.White);
AddLine(text, Color.White);
}
public void AddFormattedLine(FormattedMessage message)

View File

@@ -9,7 +9,6 @@ using System.Threading;
using SS14.Server.Console;
using SS14.Server.GameStates;
using SS14.Server.Interfaces;
using SS14.Server.Interfaces.Chat;
using SS14.Server.Interfaces.Console;
using SS14.Server.Interfaces.GameObjects;
using SS14.Server.Interfaces.GameState;
@@ -212,7 +211,6 @@ namespace SS14.Server
// Initialize Tier 2 services
_stateManager.Initialize();
_entities.Initialize();
IoCManager.Resolve<IChatManager>().Initialize();
IoCManager.Resolve<IPlayerManager>().Initialize(MaxPlayers);
_mapManager.Initialize();
IoCManager.Resolve<IPlacementManager>().Initialize();

View File

@@ -1,114 +0,0 @@
using System.Collections.Generic;
using System.Xml.Serialization;
using SS14.Server.Interfaces.Chat;
using SS14.Server.Interfaces.Player;
using SS14.Shared.Console;
using SS14.Shared.GameObjects;
using SS14.Shared.Interfaces;
using SS14.Shared.Interfaces.Network;
using SS14.Shared.Interfaces.Resources;
using SS14.Shared.IoC;
using SS14.Shared.Network;
using SS14.Shared.Network.Messages;
using SS14.Shared.Players;
using SS14.Shared.Utility;
namespace SS14.Server.Chat
{
/// <summary>
/// Dispatches chat messages to clients.
/// </summary>
public class ChatManager : IChatManager
{
private const string DefaultPronoun = "their";
[Dependency]
private readonly IServerNetManager _network;
[Dependency]
private readonly IResourceManager _resources;
private readonly Dictionary<string, Emote> _emotes = new Dictionary<string, Emote>();
/// <inheritdoc />
public void Initialize()
{
_network.RegisterNetMessage<MsgChat>(MsgChat.NAME);
LoadEmotes();
}
/// <inheritdoc />
public void DispatchMessage(INetChannel client, ChatChannel channel, string text, NetSessionId? index = null, EntityUid? entityUid = null)
{
var msg = BuildChatMessage(channel, text, index, entityUid);
_network.ServerSendMessage(msg, client);
}
/// <inheritdoc />
public void DispatchMessage(List<INetChannel> clients, ChatChannel channel, string text, NetSessionId? index = null, EntityUid? entityUid = null)
{
var msg = BuildChatMessage(channel, text, index, entityUid);
_network.ServerSendToMany(msg, clients);
}
/// <inheritdoc />
public void DispatchMessage(ChatChannel channel, string text, NetSessionId? index = null, EntityUid? entityUid = null)
{
var msg = BuildChatMessage(channel, text, index, entityUid);
_network.ServerSendToAll(msg);
}
/// <inheritdoc />
public bool ExpandEmote(string input, IPlayerSession session, out string self, out string other)
{
if (_emotes.TryGetValue(input, out var emote))
{
//TODO: Notify content, allow it to override expansion
// args: session, Emote
self = string.Format(emote.SelfText);
other = string.Format(emote.OtherText, session.Name, DefaultPronoun);
return true;
}
self = string.Empty;
other = string.Empty;
return false;
}
private MsgChat BuildChatMessage(ChatChannel channel, string text, NetSessionId? index, EntityUid? entityUid)
{
var message = _network.CreateNetMessage<MsgChat>();
message.Channel = channel;
message.Text = text;
message.SessionId = index;
message.EntityId = entityUid;
return message;
}
private void LoadEmotes()
{
if (!_resources.TryContentFileRead(new ResourcePath(@"/emotes.xml"), out var emoteFileStream))
return;
var serializer = new XmlSerializer(typeof(List<Emote>));
var emotes = (List<Emote>)serializer.Deserialize(emoteFileStream);
emoteFileStream.Close();
foreach (var emote in emotes)
{
_emotes.Add(emote.Command, emote);
}
}
// xml serializer requires this to be public
public struct Emote
{
public string Command { get; set; }
public string SelfText { get; set; }
public string OtherText { get; set; }
}
}
}

View File

@@ -1,135 +0,0 @@
using System.Linq;
using SS14.Server.Interfaces.Chat;
using SS14.Server.Interfaces.Console;
using SS14.Server.Interfaces.Player;
using SS14.Shared.Console;
using SS14.Shared.Enums;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Interfaces.GameObjects.Components;
using SS14.Shared.IoC;
namespace SS14.Server.Console.Commands
{
internal class SayCommand : IClientCommand
{
private const char RadioChar = ':'; // first char of first argument to designate radio messages
private const int VoiceRange = 7; // how far voice goes in world units
public string Command => "say";
public string Description => "Send chat messages to the local channel or a specified radio channel.";
public string Help => "say [<:channel>] <text>";
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
{
if (player.Status != SessionStatus.InGame || !player.AttachedEntityUid.HasValue)
return;
if (args.Length < 1)
return;
var sessions = IoCManager.Resolve<IPlayerManager>();
var ents = IoCManager.Resolve<IEntityManager>();
var chat = IoCManager.Resolve<IChatManager>();
var message = args[0];
string text;
if (message[0] == RadioChar)
{
// all they sent was the channel
if (args.Length < 2)
return;
var channel = args[0];
var listArgs = args.ToList();
listArgs.RemoveAt(0);
text = string.Concat(listArgs);
//TODO: Parse channel and broadcast over radio.
}
else
{
text = string.Concat(args);
}
var pos = ents.GetEntity(player.AttachedEntityUid.Value).Transform.GridPosition;
var clients = sessions.GetPlayersInRange(pos, VoiceRange).Select(p => p.ConnectedClient);
chat.DispatchMessage(clients.ToList(), ChatChannel.Local, text, player.SessionId);
}
}
internal class WhisperCommand : IClientCommand
{
private const int WhisperRange = 1; // how far voice goes in world units
public string Command => "whisper";
public string Description => "Send chat messages to the local channel in a 1 meter radius.";
public string Help => "whisper <text>";
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
{
if (player.Status != SessionStatus.InGame || !player.AttachedEntityUid.HasValue)
return;
var sessions = IoCManager.Resolve<IPlayerManager>();
var ents = IoCManager.Resolve<IEntityManager>();
var chat = IoCManager.Resolve<IChatManager>();
var pos = ents.GetEntity(player.AttachedEntityUid.Value).Transform.GridPosition;
var clients = sessions.GetPlayersInRange(pos, WhisperRange).Select(p => p.ConnectedClient);
chat.DispatchMessage(clients.ToList(), ChatChannel.Local, args[0], player.SessionId);
}
}
internal class MeCommand : IClientCommand
{
private const int VoiceRange = 7;
public string Command => "me";
public string Description => "Send third person chat messages to the local channel.";
public string Help => "me <text>";
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
{
if (player.Status != SessionStatus.InGame || !player.AttachedEntityUid.HasValue)
return;
var sessions = IoCManager.Resolve<IPlayerManager>();
var ents = IoCManager.Resolve<IEntityManager>();
var chat = IoCManager.Resolve<IChatManager>();
if (chat.ExpandEmote(args[0], player, out var self, out var other))
{
//TODO: Dispatch in PVS range instead
var pos = ents.GetEntity(player.AttachedEntityUid.Value).Transform.GridPosition;
var clients = sessions.GetPlayersInRange(pos, VoiceRange).Where(p => p != player).Select(p => p.ConnectedClient);
chat.DispatchMessage(player.ConnectedClient, ChatChannel.Emote, self, player.SessionId);
chat.DispatchMessage(clients.ToList(), ChatChannel.Emote, other, player.SessionId);
}
else
{
//TODO: Dispatch in PVS range instead
var pos = ents.GetEntity(player.AttachedEntityUid.Value).Transform.GridPosition;
var clients = sessions.GetPlayersInRange(pos, VoiceRange).Select(p => p.ConnectedClient);
chat.DispatchMessage(clients.ToList(), ChatChannel.Emote, $"{player.Name} {args[0]}", player.SessionId);
}
}
}
internal class OocCommand : IClientCommand
{
public string Command => "ooc";
public string Description => "Send Out of Character chat messages.";
public string Help => "ooc <text>";
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
{
var chat = IoCManager.Resolve<IChatManager>();
chat.DispatchMessage(ChatChannel.OOC, args[0], player.SessionId);
}
}
}

View File

@@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SS14.Shared.Console;
using SS14.Shared.Interfaces.Network;
using SS14.Shared.IoC;
using SS14.Shared.Network;
namespace SS14.Server.Interfaces.Chat
{
public interface IChatCommand : ICommand
{
void Execute(IChatManager manager, INetChannel client, params string[] args);
}
}

View File

@@ -1,57 +0,0 @@
using System.Collections.Generic;
using SS14.Server.Interfaces.Player;
using SS14.Shared.Console;
using SS14.Shared.GameObjects;
using SS14.Shared.Interfaces.Network;
using SS14.Shared.Network;
using SS14.Shared.Players;
namespace SS14.Server.Interfaces.Chat
{
public interface IChatManager
{
/// <summary>
/// Sets up the ChatManager into a usable state.
/// </summary>
void Initialize();
/// <summary>
/// Sends a chat message to a single client.
/// </summary>
/// <param name="client">Clients to send the message to.</param>
/// <param name="channel">Channel that the chat is broadcast on.</param>
/// <param name="text">Text to broadcast.</param>
/// <param name="index">Optional PlayerIndex of the client that the message is bound to.</param>
/// <param name="entityUid">Optional entity Uid that the message is bound to.</param>
void DispatchMessage(INetChannel client, ChatChannel channel, string text, NetSessionId? index = null, EntityUid? entityUid = null);
/// <summary>
/// Sends a chat message to multiple clients.
/// </summary>
/// <param name="clients"></param>
/// <param name="channel">Channel that the chat is broadcast on.</param>
/// <param name="text">Text to broadcast.</param>
/// <param name="index">Optional PlayerIndex of the client that the message is bound to.</param>
/// <param name="entityUid">Optional entity Uid that the message is bound to.</param>
void DispatchMessage(List<INetChannel> clients, ChatChannel channel, string text, NetSessionId? index = null, EntityUid? entityUid = null);
/// <summary>
/// Sends a chat message to all connected clients.
/// </summary>
/// <param name="channel">Channel that the chat is broadcast on.</param>
/// <param name="text">Text to broadcast.</param>
/// <param name="index">Optional PlayerIndex of the client that the message is bound to.</param>
/// <param name="entityUid">Optional entity Uid that the message is bound to.</param>
void DispatchMessage(ChatChannel channel, string text, NetSessionId? index = null, EntityUid? entityUid = null);
/// <summary>
/// Checks a string to see if it is an emote, and expands it to self/other chat.
/// </summary>
/// <param name="input">String to check.</param>
/// <param name="session">Player that the emote is acting on.</param>
/// <param name="self">First person emote text.</param>
/// <param name="other">Third person emote text.</param>
/// <returns>If the string was a valid emote.</returns>
bool ExpandEmote(string input, IPlayerSession session, out string self, out string other);
}
}

View File

@@ -1,8 +1,6 @@
using SS14.Server.Chat;
using SS14.Server.GameObjects;
using SS14.Server.GameObjects;
using SS14.Server.GameStates;
using SS14.Server.Interfaces;
using SS14.Server.Interfaces.Chat;
using SS14.Server.Interfaces.GameObjects;
using SS14.Server.Interfaces.GameState;
using SS14.Server.Interfaces.Maps;
@@ -124,7 +122,6 @@ namespace SS14.Server
IoCManager.Register<IEntityManager, ServerEntityManager>();
IoCManager.Register<IServerEntityManager, ServerEntityManager>();
IoCManager.Register<IServerEntityManagerInternal, ServerEntityManager>();
IoCManager.Register<IChatManager, ChatManager>();
IoCManager.Register<IServerNetManager, NetManager>();
IoCManager.Register<IMapManager, MapManager>();
IoCManager.Register<IPlacementManager, PlacementManager>();

View File

@@ -134,7 +134,6 @@
<Compile Include="Console\Commands\SpawnCommand.cs" />
<Compile Include="AI\AiLogicProcessor.cs" />
<Compile Include="AI\AiLogicProcessorAttribute.cs" />
<Compile Include="Console\Commands\ChatCommands.cs" />
<Compile Include="Console\Commands\MapCommands.cs" />
<Compile Include="Console\Commands\PlayerCommands.cs" />
<Compile Include="Console\Commands\SysCommands.cs" />
@@ -164,7 +163,6 @@
</Content>
<None Include="app.config" />
<Compile Include="CommandLineArgs.cs" />
<Compile Include="Chat\ChatManager.cs" />
<Compile Include="Console\Commands\ListCommands.cs" />
<Compile Include="Console\ConsoleShell.cs" />
<Compile Include="GameObjects\ServerComponentFactory.cs" />
@@ -182,8 +180,6 @@
<Compile Include="GameStates\ServerGameStateManager.cs" />
<Compile Include="Interfaces\ICommandLineArgs.cs" />
<Compile Include="Interfaces\IBaseServer.cs" />
<Compile Include="Interfaces\Chat\IChatCommand.cs" />
<Compile Include="Interfaces\Chat\IChatManager.cs" />
<Compile Include="Interfaces\Console\IClientCommand.cs" />
<Compile Include="Interfaces\Console\IConsoleShell.cs" />
<Compile Include="Interfaces\GameObjects\IActorComponent.cs" />

View File

@@ -1,50 +0,0 @@
namespace SS14.Shared.Console
{
public enum ChatChannel
{
/// <summary>
/// Default, unspecified
/// </summary>
Default = 0,
/// <summary>
/// Chat heard by players within earshot
/// </summary>
Local,
/// <summary>
/// Messages from the server
/// </summary>
Server,
/// <summary>
/// Damage messages
/// </summary>
Damage,
/// <summary>
/// Messages that are sent by the player directly
/// </summary>
Player,
/// <summary>
/// Radio messages
/// </summary>
Radio,
/// <summary>
/// Emotes
/// </summary>
Emote,
/// <summary>
/// Out-of-character channel
/// </summary>
OOC,
/// <summary>
/// Things the character can see
/// </summary>
Visual
}
}

View File

@@ -6,19 +6,6 @@ using SS14.Shared.Serialization;
namespace SS14.Shared.GameObjects
{
[Serializable, NetSerializable]
public class SaidSomethingMsg : ComponentMessage
{
public ChatChannel Channel { get; }
public string Text { get; }
public SaidSomethingMsg(ChatChannel channel, string text)
{
Channel = channel;
Text = text;
}
}
[Serializable, NetSerializable]
public class BumpedEntMsg : ComponentMessage
{

View File

@@ -21,7 +21,6 @@ namespace SS14.Shared.Input
public static readonly BoundKeyFunction ShowDebugMonitors = "ShowDebugMonitors";
public static readonly BoundKeyFunction HideUI = "HideUI";
public static readonly BoundKeyFunction EscapeMenu = "ShowEscapeMenu";
public static readonly BoundKeyFunction FocusChat = "FocusChatWindow";
public static readonly BoundKeyFunction EditorLinePlace = "EditorLinePlace";
public static readonly BoundKeyFunction EditorGridPlace = "EditorGridPlace";

View File

@@ -1,57 +0,0 @@
using Lidgren.Network;
using SS14.Shared.Console;
using SS14.Shared.GameObjects;
using SS14.Shared.Interfaces.Network;
using SS14.Shared.Players;
namespace SS14.Shared.Network.Messages
{
public class MsgChat : NetMessage
{
#region REQUIRED
public static readonly MsgGroups GROUP = MsgGroups.String;
public static readonly string NAME = nameof(MsgChat);
public MsgChat(INetChannel channel) : base(NAME, GROUP) { }
#endregion
public ChatChannel Channel { get; set; }
public string Text { get; set; }
public NetSessionId? SessionId { get; set; }
public EntityUid? EntityId { get; set; }
public override void ReadFromBuffer(NetIncomingMessage buffer)
{
Channel = (ChatChannel)buffer.ReadByte();
Text = buffer.ReadString();
var index = buffer.ReadString();
if (index == "")
SessionId = null;
else
SessionId = new NetSessionId(index);
var id = buffer.ReadInt32();
if (id == -1)
EntityId = null;
else
EntityId = new EntityUid(id);
}
public override void WriteToBuffer(NetOutgoingMessage buffer)
{
buffer.Write((byte)Channel);
buffer.Write(Text);
if (!SessionId.HasValue)
buffer.Write("");
else
buffer.Write(SessionId.Value.Username);
if (EntityId == null)
buffer.Write(-1);
else
buffer.Write((int)EntityId);
}
}
}

View File

@@ -1,4 +1,5 @@
using Lidgren.Network;
using SS14.Shared.GameObjects;
using SS14.Shared.Map;
using SS14.Shared.Maths;
@@ -33,5 +34,15 @@ namespace SS14.Shared.Network
message.Write(vector2.X);
message.Write(vector2.Y);
}
public static EntityUid ReadEntityUid(this NetIncomingMessage message)
{
return new EntityUid(message.ReadInt32());
}
public static void Write(this NetOutgoingMessage message, EntityUid entityUid)
{
message.Write((int)entityUid);
}
}
}

View File

@@ -209,7 +209,6 @@
<Compile Include="Network\NetChannelArgs.cs" />
<Compile Include="Network\NetManager.ClientConnect.cs" />
<Compile Include="Network\NetMessageArgs.cs" />
<Compile Include="Network\Messages\MsgChat.cs" />
<Compile Include="Network\Messages\MsgConCmd.cs" />
<Compile Include="Network\Messages\MsgConCmdAck.cs" />
<Compile Include="Network\Messages\MsgConCmdReg.cs" />
@@ -271,7 +270,6 @@
<Compile Include="Utility\CollectionExtensions.cs" />
<Compile Include="Enums\NetworkEnums.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Console\ChatChannel.cs" />
<Compile Include="Enums\VectorEventArgs.cs" />
<Compile Include="IoC\IoCManager.cs" />
<Compile Include="IoC\IPostInjectInit.cs" />

View File

@@ -30,12 +30,10 @@ using SS14.Client.UserInterface;
using SS14.Client.ViewVariables;
using SS14.Client.Utility;
using SS14.Server;
using SS14.Server.Chat;
using SS14.Server.Console;
using SS14.Server.GameObjects;
using SS14.Server.GameStates;
using SS14.Server.Interfaces;
using SS14.Server.Interfaces.Chat;
using SS14.Server.Interfaces.Console;
using SS14.Server.Interfaces.GameObjects;
using SS14.Server.Interfaces.GameState;
@@ -218,8 +216,6 @@ namespace SS14.UnitTesting
IoCManager.Register<IGameControllerProxyInternal, GameControllerProxyDummy>();
IoCManager.Register<IInputManager, InputManager>();
IoCManager.Register<IDebugDrawing, DebugDrawing>();
IoCManager.Register<IClientConsole, ClientChatConsole>();
IoCManager.Register<IClientChatConsole, ClientChatConsole>();
//IoCManager.Register<ILightManager, LightManager>();
IoCManager.Register<IDisplayManager, DisplayManagerHeadless>();
//IoCManager.Register<IEyeManager, EyeManager>();
@@ -230,6 +226,7 @@ namespace SS14.UnitTesting
IoCManager.Register<IClipboardManager, ClipboardManagerUnsupported>();
IoCManager.Register<IDiscordRichPresence, DiscordRichPresence>();
IoCManager.Register<IEyeManager, EyeManager>();
IoCManager.Register<IClientConsole, ClientConsole>();
break;
case UnitTestProject.Server:
@@ -237,7 +234,6 @@ namespace SS14.UnitTesting
IoCManager.Register<IResourceManagerInternal, ResourceManager>();
IoCManager.Register<IEntityManager, ServerEntityManager>();
IoCManager.Register<IServerEntityManager, ServerEntityManager>();
IoCManager.Register<IChatManager, ChatManager>();
IoCManager.Register<IServerNetManager, NetManager>();
IoCManager.Register<IMapManager, MapManager>();
IoCManager.Register<IPlacementManager, PlacementManager>();