Fix that awful code that parses colors to use a regex. This likely fixes the issue Icy mentioned.
This commit is contained in:
parent
39e1d9ced8
commit
9b477e461d
1 changed files with 18 additions and 20 deletions
|
|
@ -24,6 +24,7 @@ using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using Terraria;
|
using Terraria;
|
||||||
using TShockAPI.DB;
|
using TShockAPI.DB;
|
||||||
|
|
||||||
|
|
@ -717,7 +718,7 @@ namespace TShockAPI
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Shows a file to the user.
|
/// Shows a file to the user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ply">int player</param>
|
/// <param name="ply">TSPlayer player</param>
|
||||||
/// <param name="file">string filename reletave to savedir</param>
|
/// <param name="file">string filename reletave to savedir</param>
|
||||||
public void ShowFileToUser(TSPlayer player, string file)
|
public void ShowFileToUser(TSPlayer player, string file)
|
||||||
{
|
{
|
||||||
|
|
@ -726,31 +727,28 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
while ((foo = tr.ReadLine()) != null)
|
while ((foo = tr.ReadLine()) != null)
|
||||||
{
|
{
|
||||||
foo = foo.Replace("%map%", Main.worldName);
|
if (string.IsNullOrWhiteSpace(foo))
|
||||||
foo = foo.Replace("%players%", GetPlayers());
|
|
||||||
//foo = SanitizeString(foo);
|
|
||||||
if (foo.Substring(0, 1) == "%" && foo.Substring(12, 1) == "%") //Look for a beginning color code.
|
|
||||||
{
|
{
|
||||||
string possibleColor = foo.Substring(0, 13);
|
|
||||||
foo = foo.Remove(0, 13);
|
|
||||||
float[] pC = {0, 0, 0};
|
|
||||||
possibleColor = possibleColor.Replace("%", "");
|
|
||||||
string[] pCc = possibleColor.Split(',');
|
|
||||||
if (pCc.Length == 3)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
player.SendMessage(foo, (byte) Convert.ToInt32(pCc[0]), (byte) Convert.ToInt32(pCc[1]),
|
|
||||||
(byte) Convert.ToInt32(pCc[2]));
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
|
foo = foo.Replace("%map%", Main.worldName);
|
||||||
|
foo = foo.Replace("%players%", GetPlayers());
|
||||||
|
Regex reg = new Regex("%\\s*(?<r>\\d{0,3})\\s*,\\s*(?<g>\\d{0,3})\\s*,\\s*(?<b>\\d{0,3})\\s*%");
|
||||||
|
var matches = reg.Matches(foo);
|
||||||
|
Color c = Color.White;
|
||||||
|
foreach (Match match in matches)
|
||||||
{
|
{
|
||||||
Log.Error(e.ToString());
|
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);
|
||||||
}
|
}
|
||||||
}
|
player.SendMessage(foo, c);
|
||||||
player.SendMessage(foo);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue