fix(core): Streamlines text encoding (#407)
- [X] Streamlines text encoding
This commit is contained in:
parent
5631c1da6d
commit
211c2ba8ee
25 changed files with 274 additions and 137 deletions
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Server.Text;
|
||||
|
||||
namespace Server.Accounting.Security
|
||||
{
|
||||
|
|
@ -28,10 +28,7 @@ namespace Server.Accounting.Security
|
|||
|
||||
public string EncryptPassword(string plainPassword)
|
||||
{
|
||||
var password = plainPassword.AsSpan(0, Math.Min(256, plainPassword.Length));
|
||||
var bytes = GC.AllocateUninitializedArray<byte>(Encoding.ASCII.GetByteCount(password));
|
||||
Encoding.ASCII.GetBytes(password, bytes);
|
||||
|
||||
byte[] bytes = plainPassword.AsSpan(0, Math.Min(256, plainPassword.Length)).GetBytesAscii();
|
||||
return m_MD5HashProvider.ComputeHash(bytes).ToHexString();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
using System;
|
||||
using System.Buffers.Binary;
|
||||
using System.Security.Cryptography;
|
||||
using Server.Text;
|
||||
|
||||
namespace Server.Accounting.Security
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Server.Text;
|
||||
|
||||
namespace Server.Accounting.Security
|
||||
{
|
||||
|
|
@ -28,10 +28,7 @@ namespace Server.Accounting.Security
|
|||
|
||||
public string EncryptPassword(string plainPassword)
|
||||
{
|
||||
var password = plainPassword.AsSpan(0, Math.Min(256, plainPassword.Length));
|
||||
var bytes = GC.AllocateUninitializedArray<byte>(Encoding.ASCII.GetByteCount(password));
|
||||
Encoding.ASCII.GetBytes(password, bytes);
|
||||
|
||||
byte[] bytes = plainPassword.AsSpan(0, Math.Min(256, plainPassword.Length)).GetBytesAscii();
|
||||
return m_SHA1HashProvider.ComputeHash(bytes).ToHexString();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Server.Text;
|
||||
|
||||
namespace Server.Accounting.Security
|
||||
{
|
||||
|
|
@ -26,10 +27,7 @@ namespace Server.Accounting.Security
|
|||
|
||||
public string EncryptPassword(string plainPassword)
|
||||
{
|
||||
var password = plainPassword.AsSpan(0, Math.Min(256, plainPassword.Length));
|
||||
var bytes = GC.AllocateUninitializedArray<byte>(Encoding.ASCII.GetByteCount(password));
|
||||
Encoding.ASCII.GetBytes(password, bytes);
|
||||
|
||||
byte[] bytes = plainPassword.AsSpan(0, Math.Min(256, plainPassword.Length)).GetBytesAscii();
|
||||
return m_SHA2HashProvider.ComputeHash(bytes).ToHexString();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using Server.ContextMenus;
|
|||
using Server.Gumps;
|
||||
using Server.Multis;
|
||||
using Server.Network;
|
||||
using Server.Text;
|
||||
|
||||
namespace Server.Items
|
||||
{
|
||||
|
|
@ -501,7 +502,7 @@ namespace Server.Items
|
|||
|
||||
for (var j = 0; j < page.Lines.Length; ++j)
|
||||
{
|
||||
var buffer = Utility.UTF8.GetBytes(page.Lines[j]);
|
||||
var buffer = page.Lines[j].GetBytesUtf8();
|
||||
|
||||
Stream.Write(buffer, 0, buffer.Length);
|
||||
Stream.Write((byte)0);
|
||||
|
|
@ -517,8 +518,8 @@ namespace Server.Items
|
|||
var title = book.Title ?? "";
|
||||
var author = book.Author ?? "";
|
||||
|
||||
var titleBuffer = Utility.UTF8.GetBytes(title);
|
||||
var authorBuffer = Utility.UTF8.GetBytes(author);
|
||||
var titleBuffer = title.GetBytesUtf8();
|
||||
var authorBuffer = author.GetBytesUtf8();
|
||||
|
||||
EnsureCapacity(15 + titleBuffer.Length + authorBuffer.Length);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using Server.Network;
|
||||
using Server.Targeting;
|
||||
using Server.Text;
|
||||
|
||||
namespace Server.Items
|
||||
{
|
||||
|
|
@ -517,7 +518,7 @@ namespace Server.Items
|
|||
{
|
||||
EnsureCapacity(38);
|
||||
|
||||
var buffer = Utility.UTF8.GetBytes(board.BoardName ?? "");
|
||||
var buffer = TextEncoding.UTF8.GetBytes(board.BoardName ?? "");
|
||||
|
||||
Stream.Write((byte)0x00); // PacketID
|
||||
Stream.Write(board.Serial); // Bulletin board serial
|
||||
|
|
@ -568,7 +569,7 @@ namespace Server.Items
|
|||
|
||||
public void WriteString(string v)
|
||||
{
|
||||
var buffer = Utility.UTF8.GetBytes(v);
|
||||
var buffer = TextEncoding.UTF8.GetBytes(v);
|
||||
var len = buffer.Length + 1;
|
||||
|
||||
if (len > 255)
|
||||
|
|
@ -644,7 +645,7 @@ namespace Server.Items
|
|||
|
||||
public void WriteString(string v, bool padding)
|
||||
{
|
||||
var buffer = Utility.UTF8.GetBytes(v);
|
||||
var buffer = TextEncoding.UTF8.GetBytes(v);
|
||||
var tail = padding ? 2 : 1;
|
||||
var len = buffer.Length + tail;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue