From 09bbf8abe8d6156f64f619f7cf3442dc42da4f26 Mon Sep 17 00:00:00 2001 From: White Date: Thu, 20 Oct 2016 21:03:25 +1030 Subject: [PATCH] Removed colour parsing from the ShowFileToUser method. Also added an info log message if a file contains the old format. Fixes #1314 --- TShockAPI/Utils.cs | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 0cd9c0a8..6af27068 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -50,6 +50,8 @@ namespace TShockAPI /// instance - an instance of the utils class private static readonly Utils instance = new Utils(); + private Regex byteRegex = new Regex("%\\s*(?\\d{1,3})\\s*,\\s*(?\\d{1,3})\\s*,\\s*(?\\d{1,3})\\s*%"); + /// Utils - Creates a utilities object. private Utils() {} @@ -691,11 +693,12 @@ namespace TShockAPI /// /// Shows a file to the user. /// - /// TSPlayer player - /// string filename reletave to savedir + /// Player the file contents will be sent to + /// Filename relative to public void ShowFileToUser(TSPlayer player, string file) { string foo = ""; + bool containsOldFormat = false; using (var tr = new StreamReader(Path.Combine(TShock.SavePath, file))) { while ((foo = tr.ReadLine()) != null) @@ -707,21 +710,14 @@ namespace TShockAPI foo = foo.Replace("%map%", (TShock.Config.UseServerName ? TShock.Config.ServerName : Main.worldName)); foo = foo.Replace("%players%", String.Join(",", GetPlayers(false))); - Regex reg = new Regex("%\\s*(?\\d{1,3})\\s*,\\s*(?\\d{1,3})\\s*,\\s*(?\\d{1,3})\\s*%"); - var matches = reg.Matches(foo); - Color c = Color.White; - foreach (Match match in matches) + if (byteRegex.IsMatch(foo) && !containsOldFormat) { - byte r, g, b; - if (byte.TryParse(match.Groups["r"].Value, out r) && - byte.TryParse(match.Groups["g"].Value, out g) && - byte.TryParse(match.Groups["b"].Value, out b)) - { - c = new Color(r, g, b); - } - foo = foo.Remove(match.Index, match.Length); + TShock.Log.ConsoleInfo($"You are using an old color format in file {file}."); + TShock.Log.ConsoleInfo("To send coloured text please use Terraria's inbuilt format of: [c/#hex:text]."); + TShock.Log.ConsoleInfo("For example: [c/ff00aa:This is a message!]."); + containsOldFormat = true; } - player.SendMessage(foo, c); + player.SendMessage(foo, Color.White); } } }