fix: Fixes string interpolation in value string builder (#1339)

This commit is contained in:
Kamron Batman 2023-02-13 23:09:50 -08:00 • committed by GitHub
parent b46544d752
commit f24c6a08dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 87 additions and 242 deletions

View file

@ -96,13 +96,22 @@ namespace Server.Compression
new FileInfo(destinationArchiveFileName).EnsureDirectory();
using var builder = ValueStringBuilder.Create();
var sb = ValueStringBuilder.Create();
var i = 0;
foreach (var path in paths)
{
builder.Append($"{(i++ > 0 ? " " : "")}\"{Path.GetRelativePath(relativeTo, path)}\"");
var relativePath = Path.GetRelativePath(relativeTo, path);
if (i++ > 0)
{
sb.Append($" \"{relativePath}\"");
}
else
{
sb.Append($"\"{relativePath}\"");
}
}
var pathsToCompress = builder.ToString();
var pathsToCompress = sb.ToString();
sb.Dispose();
var tarFlags = compressCommand == null ? "-acf" : "-cf";
var useExternalCompression = compressCommand != null ? $"--use-compress-program \"{compressCommand}\" " : "";

View file

@ -939,7 +939,7 @@ public partial class ConditionTeleporter : Teleporter
{
base.GetProperties(list);
using var props = new ValueStringBuilder(stackalloc char[128]);
using var props = ValueStringBuilder.Create(128);
if (GetFlag(ConditionFlag.DenyMounted))
{

View file

@ -83,7 +83,7 @@ namespace Server.Misc
private static void EventSink_ClientVersionReceived(NetState state, ClientVersion version)
{
using var message = ValueStringBuilder.Create();
var sb = ValueStringBuilder.Create();
if (!_enable || state.Mobile?.AccessLevel != AccessLevel.Player)
{
@ -100,47 +100,47 @@ namespace Server.Misc
if (MinRequired != null && version < MinRequired)
{
message.Append($"This server doesn't support clients older than {MinRequired}.");
sb.Append($"This server doesn't support clients older than {MinRequired}.");
shouldKick = strictRequirement;
}
else if (MaxRequired != null && version > MaxRequired)
{
message.Append($"This server doesn't support clients newer than {MaxRequired}.");
sb.Append($"This server doesn't support clients newer than {MaxRequired}.");
shouldKick = strictRequirement;
}
else if (!AllowRegular || !AllowUOTD)
{
if (!AllowRegular && version.Type == ClientType.Regular)
{
message.Append("This server does not allow regular clients to connect.");
sb.Append("This server does not allow regular clients to connect.");
shouldKick = true;
}
else if (!AllowUOTD && state.IsUOTDClient)
{
message.Append("This server does not allow UO:TD clients to connect.");
sb.Append("This server does not allow UO:TD clients to connect.");
shouldKick = true;
}
if (message.Length > 0)
if (sb.Length > 0)
{
if (AllowRegular && AllowUOTD)
{
message.Append(" You can use regular or UO:TD clients.");
sb.Append(" You can use regular or UO:TD clients.");
}
else if (AllowRegular)
{
message.Append(" You can use regular clients.");
sb.Append(" You can use regular clients.");
}
else if (AllowUOTD)
{
message.Append(" You can use UO:TD clients.");
sb.Append(" You can use UO:TD clients.");
}
}
}
if (message.Length > 0)
if (sb.Length > 0)
{
state.Mobile.SendMessage(0x22, message.ToString());
state.Mobile.SendMessage(0x22, sb.ToString());
}
if (shouldKick)
@ -150,7 +150,7 @@ namespace Server.Misc
return;
}
if (message.Length > 0)
if (sb.Length > 0)
{
switch (_invalidClientResponse)
{
@ -170,6 +170,8 @@ namespace Server.Misc
}
}
}
sb.Dispose();
}
private static void OnKick(NetState ns)

View file

@ -71,7 +71,7 @@ namespace Server.SkillHandlers
if (c.Looters.Count > 0)
{
using var sb = new ValueStringBuilder(stackalloc char[128]);
var sb = ValueStringBuilder.Create(128);
int i = 0;
foreach (var looter in c.Looters)
{
@ -93,6 +93,7 @@ namespace Server.SkillHandlers
// This body has been disturbed by ~1_PLAYER_NAMES~
from.SendLocalizedMessage(1042752, sb.ToString());
sb.Dispose();
}
else
{