tabs->spaces etc
This commit is contained in:
@@ -6,29 +6,29 @@ namespace MareSynchronos.Utils;
|
||||
|
||||
public static class ChatUtils
|
||||
{
|
||||
// Based on https://git.anna.lgbt/anna/ExtraChat/src/branch/main/client/ExtraChat/Util/PayloadUtil.cs
|
||||
// This must store a Guid (16 bytes), as Chat 2 converts the data back to one
|
||||
// Based on https://git.anna.lgbt/anna/ExtraChat/src/branch/main/client/ExtraChat/Util/PayloadUtil.cs
|
||||
// This must store a Guid (16 bytes), as Chat 2 converts the data back to one
|
||||
|
||||
public static RawPayload CreateExtraChatTagPayload(Guid guid)
|
||||
{
|
||||
var header = (byte[])[
|
||||
0x02, // Payload.START_BYTE
|
||||
0x27, // SeStringChunkType.Interactable
|
||||
2 + 16, // remaining length: ExtraChat sends 19 here but I think its an error
|
||||
0x20 // Custom ExtraChat InfoType
|
||||
];
|
||||
public static RawPayload CreateExtraChatTagPayload(Guid guid)
|
||||
{
|
||||
var header = (byte[])[
|
||||
0x02, // Payload.START_BYTE
|
||||
0x27, // SeStringChunkType.Interactable
|
||||
2 + 16, // remaining length: ExtraChat sends 19 here but I think its an error
|
||||
0x20 // Custom ExtraChat InfoType
|
||||
];
|
||||
|
||||
var footer = (byte)0x03; // Payload.END_BYTE
|
||||
var footer = (byte)0x03; // Payload.END_BYTE
|
||||
|
||||
return new RawPayload([..header, ..guid.ToByteArray(), footer]);
|
||||
}
|
||||
return new RawPayload([..header, ..guid.ToByteArray(), footer]);
|
||||
}
|
||||
|
||||
// We have a unique identifier in the form of a GID, which can be consistently mapped to the same GUID
|
||||
public static RawPayload CreateExtraChatTagPayload(string gid)
|
||||
{
|
||||
var gidBytes = UTF8Encoding.UTF8.GetBytes(gid);
|
||||
var hashedBytes = MD5.HashData(gidBytes);
|
||||
var guid = new Guid(hashedBytes);
|
||||
return CreateExtraChatTagPayload(guid);
|
||||
}
|
||||
// We have a unique identifier in the form of a GID, which can be consistently mapped to the same GUID
|
||||
public static RawPayload CreateExtraChatTagPayload(string gid)
|
||||
{
|
||||
var gidBytes = UTF8Encoding.UTF8.GetBytes(gid);
|
||||
var hashedBytes = MD5.HashData(gidBytes);
|
||||
var guid = new Guid(hashedBytes);
|
||||
return CreateExtraChatTagPayload(guid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace MareSynchronosStaticFilesServer.Utils;
|
||||
namespace MareSynchronos.Utils;
|
||||
|
||||
// Calculates the hash of content read or written to a stream
|
||||
public class HashingStream : Stream
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace MareSynchronos.Utils;
|
||||
public class LimitedStream : Stream
|
||||
{
|
||||
private readonly Stream _stream;
|
||||
public long _estimatedPosition = 0;
|
||||
public long MaxPosition { get; private init; }
|
||||
public long _estimatedPosition = 0;
|
||||
public long MaxPosition { get; private init; }
|
||||
public bool DisposeUnderlying = true;
|
||||
|
||||
public Stream UnderlyingStream { get => _stream; }
|
||||
@@ -13,12 +13,12 @@ public class LimitedStream : Stream
|
||||
public LimitedStream(Stream underlyingStream, long byteLimit)
|
||||
{
|
||||
_stream = underlyingStream;
|
||||
try
|
||||
{
|
||||
_estimatedPosition = Position;
|
||||
}
|
||||
catch { }
|
||||
MaxPosition = _estimatedPosition + byteLimit;
|
||||
try
|
||||
{
|
||||
_estimatedPosition = Position;
|
||||
}
|
||||
catch { }
|
||||
MaxPosition = _estimatedPosition + byteLimit;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
@@ -42,33 +42,33 @@ public class LimitedStream : Stream
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
int remainder = (int)long.Clamp(MaxPosition - _estimatedPosition, 0, int.MaxValue);
|
||||
int remainder = (int)long.Clamp(MaxPosition - _estimatedPosition, 0, int.MaxValue);
|
||||
|
||||
if (count > remainder)
|
||||
count = remainder;
|
||||
if (count > remainder)
|
||||
count = remainder;
|
||||
|
||||
int n = _stream.Read(buffer, offset, count);
|
||||
_estimatedPosition += n;
|
||||
return n;
|
||||
_estimatedPosition += n;
|
||||
return n;
|
||||
}
|
||||
|
||||
public async override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
int remainder = (int)long.Clamp(MaxPosition - _estimatedPosition, 0, int.MaxValue);
|
||||
int remainder = (int)long.Clamp(MaxPosition - _estimatedPosition, 0, int.MaxValue);
|
||||
|
||||
if (count > remainder)
|
||||
count = remainder;
|
||||
if (count > remainder)
|
||||
count = remainder;
|
||||
|
||||
int n = await _stream.ReadAsync(buffer, offset, count, cancellationToken);
|
||||
_estimatedPosition += n;
|
||||
return n;
|
||||
_estimatedPosition += n;
|
||||
return n;
|
||||
}
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
long result = _stream.Seek(offset, origin);
|
||||
_estimatedPosition = result;
|
||||
return result;
|
||||
_estimatedPosition = result;
|
||||
return result;
|
||||
}
|
||||
|
||||
public override void SetLength(long value)
|
||||
@@ -78,23 +78,23 @@ public class LimitedStream : Stream
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
int remainder = (int)long.Clamp(MaxPosition - _estimatedPosition, 0, int.MaxValue);
|
||||
int remainder = (int)long.Clamp(MaxPosition - _estimatedPosition, 0, int.MaxValue);
|
||||
|
||||
if (count > remainder)
|
||||
count = remainder;
|
||||
if (count > remainder)
|
||||
count = remainder;
|
||||
|
||||
_stream.Write(buffer, offset, count);
|
||||
_estimatedPosition += count;
|
||||
_estimatedPosition += count;
|
||||
}
|
||||
|
||||
public async override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
int remainder = (int)long.Clamp(MaxPosition - _estimatedPosition, 0, int.MaxValue);
|
||||
int remainder = (int)long.Clamp(MaxPosition - _estimatedPosition, 0, int.MaxValue);
|
||||
|
||||
if (count > remainder)
|
||||
count = remainder;
|
||||
if (count > remainder)
|
||||
count = remainder;
|
||||
|
||||
await _stream.WriteAsync(buffer, offset, count, cancellationToken);
|
||||
_estimatedPosition += count;
|
||||
_estimatedPosition += count;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user