Add customizable server chat name and color
This commit is contained in:
@@ -18,6 +18,8 @@ namespace Torch
|
|||||||
bool ShouldUpdateTorch { get; }
|
bool ShouldUpdateTorch { get; }
|
||||||
int TickTimeout { get; set; }
|
int TickTimeout { get; set; }
|
||||||
string WaitForPID { get; set; }
|
string WaitForPID { get; set; }
|
||||||
|
string ChatName { get; set; }
|
||||||
|
string ChatColor { get; set; }
|
||||||
|
|
||||||
bool Save(string path = null);
|
bool Save(string path = null);
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,7 @@ using System.Windows;
|
|||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
using VRage.Game;
|
||||||
|
|
||||||
namespace Torch.Server
|
namespace Torch.Server
|
||||||
{
|
{
|
||||||
@@ -60,6 +61,10 @@ namespace Torch.Server
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public List<string> Plugins { get; set; } = new List<string>();
|
public List<string> Plugins { get; set; } = new List<string>();
|
||||||
|
|
||||||
|
public string ChatName { get; set; } = "Server";
|
||||||
|
|
||||||
|
public string ChatColor { get; set; } = "Red";
|
||||||
|
|
||||||
public bool EnableWhitelist { get; set; } = false;
|
public bool EnableWhitelist { get; set; } = false;
|
||||||
public HashSet<ulong> Whitelist { get; set; } = new HashSet<ulong>();
|
public HashSet<ulong> Whitelist { get; set; } = new HashSet<ulong>();
|
||||||
|
|
||||||
|
@@ -17,8 +17,8 @@
|
|||||||
<ColumnDefinition/>
|
<ColumnDefinition/>
|
||||||
<ColumnDefinition Width="Auto"/>
|
<ColumnDefinition Width="Auto"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<Button Grid.Column="1" x:Name="Send" Content="Send" DockPanel.Dock="Right" Width="50" Margin="5,5,5,5" Click="SendButton_Click"></Button>
|
<Button Grid.Column="1" Content="Send" DockPanel.Dock="Right" Width="50" Margin="5" Click="SendButton_Click"></Button>
|
||||||
<TextBox Grid.Column="0" x:Name="Message" DockPanel.Dock="Left" Margin="5,5,5,5" KeyDown="Message_OnKeyDown"></TextBox>
|
<TextBox Grid.Column="0" x:Name="Message" Margin="5" KeyDown="Message_OnKeyDown"></TextBox>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
@@ -55,10 +55,17 @@ namespace Torch.Commands
|
|||||||
Args = args ?? new List<string>();
|
Args = args ?? new List<string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Respond(string message, string sender = "Server", string font = MyFontEnum.Blue)
|
public virtual void Respond(string message, string sender = null, string font = MyFontEnum.Blue)
|
||||||
{
|
{
|
||||||
Torch.CurrentSession.Managers.GetManager<IChatManagerServer>()
|
var chat = Torch.CurrentSession.Managers.GetManager<IChatManagerServer>();
|
||||||
?.SendMessageAsOther(sender, message, font, _steamIdSender);
|
if (sender != null)
|
||||||
|
{
|
||||||
|
chat?.SendMessageAsOther(sender, message, font, _steamIdSender);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
chat?.SendMessageAsSelf(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -38,10 +38,18 @@ namespace Torch.Managers.ChatManager
|
|||||||
{
|
{
|
||||||
if (Sandbox.Engine.Platform.Game.IsDedicated)
|
if (Sandbox.Engine.Platform.Game.IsDedicated)
|
||||||
{
|
{
|
||||||
|
// Sending invalid color to clients will crash them. KEEEN
|
||||||
|
var color = Torch.Config.ChatColor;
|
||||||
|
if (!StringUtils.IsFontEnum(Torch.Config.ChatColor))
|
||||||
|
{
|
||||||
|
_log.Warn("Invalid chat font color! Defaulting to 'Red'");
|
||||||
|
color = MyFontEnum.Red;
|
||||||
|
}
|
||||||
|
|
||||||
var scripted = new ScriptedChatMsg()
|
var scripted = new ScriptedChatMsg()
|
||||||
{
|
{
|
||||||
Author = "Server",
|
Author = Torch.Config.ChatName,
|
||||||
Font = MyFontEnum.Red,
|
Font = color,
|
||||||
Text = message,
|
Text = message,
|
||||||
Target = 0
|
Target = 0
|
||||||
};
|
};
|
||||||
|
@@ -1,8 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using VRage.Game;
|
||||||
|
|
||||||
namespace Torch.Utils
|
namespace Torch.Utils
|
||||||
{
|
{
|
||||||
@@ -60,5 +62,11 @@ namespace Torch.Utils
|
|||||||
}
|
}
|
||||||
return builder?.ToString() ?? "";
|
return builder?.ToString() ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static readonly string[] _fontEnumValues = typeof(MyFontEnum).GetFields(BindingFlags.Public | BindingFlags.Static).Where(x => x.IsLiteral && !x.IsInitOnly).Select(x => (string)x.GetValue(null)).ToArray();
|
||||||
|
public static bool IsFontEnum(string str)
|
||||||
|
{
|
||||||
|
return _fontEnumValues.Contains(str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user