ShowFileToUser shouldn't assume the file is in the TShock folder. Use the file path variables where we can. Use smart text instead of removing color parsing.
This commit is contained in:
parent
998bf71b96
commit
31794b6a27
2 changed files with 32 additions and 9 deletions
|
|
@ -50,7 +50,8 @@ namespace TShockAPI
|
|||
/// <summary>instance - an instance of the utils class</summary>
|
||||
private static readonly Utils instance = new Utils();
|
||||
|
||||
private Regex byteRegex = new Regex("%\\s*(?<r>\\d{1,3})\\s*,\\s*(?<g>\\d{1,3})\\s*,\\s*(?<b>\\d{1,3})\\s*%");
|
||||
/// <summary> This regex will look for the old MotD format for colors and replace them with the new chat format. </summary>
|
||||
private Regex motdColorRegex = new Regex(@"\%\s*(?<r>\d{1,3})\s*,\s*(?<g>\d{1,3})\s*,\s*(?<b>\d{1,3})\s*\%(?<text>((?!\%\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\%).)*)");
|
||||
|
||||
/// <summary>Utils - Creates a utilities object.</summary>
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets a prefix by ID or name
|
||||
/// </summary>
|
||||
|
|
@ -557,7 +558,7 @@ namespace TShockAPI
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="save">bool perform a world save before stop (default: true)</param>
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string with deprecated %###,###,###% formats replaced with the new chat format colors.
|
||||
/// </summary>
|
||||
/// <param name="input">The input string</param>
|
||||
/// <returns>A replaced version of the input with the new chat color format.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a Group from the name of the group
|
||||
/// </summary>
|
||||
|
|
@ -874,7 +897,7 @@ namespace TShockAPI
|
|||
int num;
|
||||
if (!int.TryParse(sb.ToString(), out num))
|
||||
return false;
|
||||
|
||||
|
||||
sb.Clear();
|
||||
switch (str[i])
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue