Skip to content

Commit

Permalink
Core: ChatReader: fix empty character in message and log entry!
Browse files Browse the repository at this point in the history
  • Loading branch information
Xian55 committed Sep 22, 2023
1 parent 16f56b9 commit d076472
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions Core/Chat/ChatReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.ObjectModel;
using System.Text;

using Microsoft.Extensions.Logging;

namespace Core;

public enum ChatMessageType
Expand All @@ -20,15 +22,22 @@ public sealed class ChatReader : IReader
private const int cMsg = 98;
private const int cMeta = 99;

public ObservableCollection<ChatMessageEntry> Messages { get; } = new();
private readonly ILogger<ChatReader> logger;

// 12 character name
// 1 space
// 256 maximum message length
private readonly StringBuilder sb = new(12 + 1 + 256);

public ObservableCollection<ChatMessageEntry> Messages { get; } = new();

private int _head;

public ChatReader(ILogger<ChatReader> logger)
{
this.logger = logger;
}

public void Update(IAddonDataProvider reader)
{
int meta = reader.GetInt(cMeta);
Expand Down Expand Up @@ -57,10 +66,12 @@ public void Update(IAddonDataProvider reader)
string text = sb.ToString().ToLowerInvariant();
sb.Clear();

int firstSpaceIdx = text.IndexOf(" ");
int firstSpaceIdx = text.AsSpan().IndexOf(' ');
string author = text.AsSpan(0, firstSpaceIdx).ToString();
text = text.AsSpan(firstSpaceIdx).ToString();
text = text.AsSpan(firstSpaceIdx + 1).ToString();

Messages.Add(new(DateTime.Now, type, author, text));
ChatMessageEntry entry = new(DateTime.Now, type, author, text);
Messages.Add(entry);
logger.LogInformation(entry.ToString());
}
}

0 comments on commit d076472

Please sign in to comment.