mirror of
https://github.com/JustArchiNET/ArchiSteamFarm
synced 2024-11-10 07:04:27 +00:00
Misc cleanup
This commit is contained in:
parent
807db7f365
commit
ef0509998e
2 changed files with 10 additions and 5 deletions
|
@ -50,9 +50,6 @@ namespace ArchiSteamFarm.Tests {
|
|||
[TestMethod]
|
||||
public void ContinuationCharacterSizeIsProperlyCalculated() => Assert.AreEqual(ContinuationCharacterBytes, Encoding.UTF8.GetByteCount(ContinuationCharacter.ToString()));
|
||||
|
||||
[TestMethod]
|
||||
public void ParagraphCharacterSizeIsLessOrEqualToContinuationCharacterSize() => Assert.IsTrue(ContinuationCharacterBytes >= Encoding.UTF8.GetByteCount(ParagraphCharacter.ToString()));
|
||||
|
||||
[TestMethod]
|
||||
public async Task DoesntSkipEmptyNewlines() {
|
||||
string message = "asdf" + Environment.NewLine + Environment.NewLine + "asdf";
|
||||
|
@ -148,6 +145,9 @@ namespace ArchiSteamFarm.Tests {
|
|||
Assert.AreEqual(message, output.First());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ParagraphCharacterSizeIsLessOrEqualToContinuationCharacterSize() => Assert.IsTrue(ContinuationCharacterBytes >= Encoding.UTF8.GetByteCount(ParagraphCharacter.ToString()));
|
||||
|
||||
[TestMethod]
|
||||
public async Task ProperlyEscapesCharacters() {
|
||||
const string message = @"[b]bold[/b] \n";
|
||||
|
|
|
@ -33,11 +33,11 @@ namespace ArchiSteamFarm.Steam.Integration {
|
|||
internal static class SteamChatMessage {
|
||||
internal const char ContinuationCharacter = '…'; // A character used for indicating that the next newline part is a continuation of the previous line
|
||||
internal const byte ContinuationCharacterBytes = 3; // The continuation character specified above uses 3 bytes in UTF-8
|
||||
internal const char ParagraphCharacter = '¶'; // A character used for indicating that this is not the last part of message (2 bytes, so it fits in ContinuationCharacterBytes)
|
||||
internal const ushort MaxMessageBytesForLimitedAccounts = 1945; // This is a limitation enforced by Steam
|
||||
internal const ushort MaxMessageBytesForUnlimitedAccounts = 6340; // This is a limitation enforced by Steam
|
||||
internal const ushort MaxMessagePrefixBytes = MaxMessageBytesForLimitedAccounts - ReservedContinuationMessageBytes - ReservedEscapeMessageBytes; // Simplified calculation, nobody should be using prefixes even close to that anyway
|
||||
internal const byte NewlineWeight = 61; // This defines how much weight a newline character is adding to the output, limitation enforced by Steam
|
||||
internal const char ParagraphCharacter = '¶'; // A character used for indicating that this is not the last part of message (2 bytes, so it fits in ContinuationCharacterBytes)
|
||||
internal const byte ReservedContinuationMessageBytes = ContinuationCharacterBytes * 2; // Up to 2 optional continuation characters
|
||||
internal const byte ReservedEscapeMessageBytes = 5; // 2 characters total, escape one '\' of 1 byte and real one of up to 4 bytes
|
||||
|
||||
|
@ -108,6 +108,7 @@ namespace ArchiSteamFarm.Steam.Integration {
|
|||
if (messagePart.Length > prefixLength) {
|
||||
if (messagePartBytes + NewlineWeight + lineBytes.Length > maxMessageBytes) {
|
||||
messagePart.Append(ParagraphCharacter);
|
||||
|
||||
yield return messagePart.ToString();
|
||||
|
||||
messagePartBytes = prefixBytes;
|
||||
|
@ -156,7 +157,11 @@ namespace ArchiSteamFarm.Steam.Integration {
|
|||
charPool.Return(lineChunk);
|
||||
}
|
||||
|
||||
bool midLineSplitting = false;
|
||||
|
||||
if (lineBytesRead < lineBytes.Length) {
|
||||
midLineSplitting = true;
|
||||
|
||||
messagePartBytes += ContinuationCharacterBytes;
|
||||
messagePart.Append(ContinuationCharacter);
|
||||
}
|
||||
|
@ -166,7 +171,7 @@ namespace ArchiSteamFarm.Steam.Integration {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (stringReader.Peek() != -1 && messagePart[messagePart.Length-1] != ContinuationCharacter) {
|
||||
if ((stringReader.Peek() != -1) && !midLineSplitting) {
|
||||
messagePart.Append(ParagraphCharacter);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue