diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs
index a7dfef83..138892e8 100755
--- a/TShockAPI/Commands.cs
+++ b/TShockAPI/Commands.cs
@@ -4811,7 +4811,7 @@ namespace TShockAPI
private static void Rules(CommandArgs args)
{
- TShock.Utils.ShowFileToUser(args.Player, "rules.txt");
+ TShock.Utils.ShowFileToUser(args.Player, FileTools.RulesPath);
}
private static void Whisper(CommandArgs args)
diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs
index 6af27068..d6fc4a3b 100644
--- a/TShockAPI/Utils.cs
+++ b/TShockAPI/Utils.cs
@@ -50,7 +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*%");
+ /// This regex will look for the old MotD format for colors and replace them with the new chat format.
+ private Regex motdColorRegex = new Regex(@"\%\s*(?\d{1,3})\s*,\s*(?\d{1,3})\s*,\s*(?\d{1,3})\s*\%(?((?!\%\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\%).)*)");
/// Utils - Creates a utilities object.
private Utils() {}
@@ -193,7 +194,7 @@ namespace TShockAPI
TSPlayer.Server.SendMessage(log, color);
foreach (TSPlayer player in TShock.Players)
{
- if (player != null && player != excludedPlayer && player.Active && player.HasPermission(Permissions.logs) &&
+ if (player != null && player != excludedPlayer && player.Active && player.HasPermission(Permissions.logs) &&
player.DisplayLogs && TShock.Config.DisableSpewLogs == false)
player.SendMessage(log, color);
}
@@ -502,7 +503,7 @@ namespace TShockAPI
}
return found;
}
-
+
///
/// Gets a prefix by ID or name
///
@@ -557,7 +558,7 @@ namespace TShockAPI
}
///
- /// Stops the server after kicking all players with a reason message, and optionally saving the world then attempts to
+ /// Stops the server after kicking all players with a reason message, and optionally saving the world then attempts to
/// restart it.
///
/// bool perform a world save before stop (default: true)
@@ -683,7 +684,7 @@ namespace TShockAPI
{
TShock.Bans.RemoveBan(ban.IP, false, false, false);
}
-
+
return true;
}
@@ -699,7 +700,7 @@ namespace TShockAPI
{
string foo = "";
bool containsOldFormat = false;
- using (var tr = new StreamReader(Path.Combine(TShock.SavePath, file)))
+ using (var tr = new StreamReader(file))
{
while ((foo = tr.ReadLine()) != null)
{
@@ -710,18 +711,40 @@ namespace TShockAPI
foo = foo.Replace("%map%", (TShock.Config.UseServerName ? TShock.Config.ServerName : Main.worldName));
foo = foo.Replace("%players%", String.Join(",", GetPlayers(false)));
- if (byteRegex.IsMatch(foo) && !containsOldFormat)
+
+ string newFoo = ReplaceDeprecatedColorCodes(foo);
+ if (newFoo != foo && !containsOldFormat)
{
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;
}
+ foo = newFoo;
+
player.SendMessage(foo, Color.White);
}
}
}
+ ///
+ /// Returns a string with deprecated %###,###,###% formats replaced with the new chat format colors.
+ ///
+ /// The input string
+ /// A replaced version of the input with the new chat color format.
+ private string ReplaceDeprecatedColorCodes(string input)
+ {
+ String tempString = input;
+ Match match = null;
+
+ while ((match = motdColorRegex.Match(tempString)).Success)
+ {
+ tempString = tempString.Replace(match.Groups[0].Value, String.Format("[c/{0:X2}{1:X2}{2:X2}:{3}]", Int32.Parse(match.Groups["r"].Value), Int32.Parse(match.Groups["g"].Value), Int32.Parse(match.Groups["b"].Value), match.Groups["text"]));
+ }
+
+ return tempString;
+ }
+
///
/// Returns a Group from the name of the group
///
@@ -874,7 +897,7 @@ namespace TShockAPI
int num;
if (!int.TryParse(sb.ToString(), out num))
return false;
-
+
sb.Clear();
switch (str[i])
{