Skip to content

Commit

Permalink
Fix: Core: ChatReader: Dont attempt to search for the Author name whe…
Browse files Browse the repository at this point in the history
…n 'Space' character was not found in the payload.
  • Loading branch information
Xian55 committed Dec 19, 2024
1 parent f62006a commit a949543
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions Core/Chat/ChatReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,19 @@ public void Update(IAddonDataProvider reader)

string text = sb.ToString().ToLowerInvariant();
sb.Clear();
try
{
int firstSpaceIdx = text.AsSpan().IndexOf(' ');
string author = text.AsSpan(0, firstSpaceIdx).ToString();
string msg = text.AsSpan(firstSpaceIdx + 1).ToString();

ChatMessageEntry entry = new(DateTime.Now, type, author, msg);
Messages.Add(entry);
logger.LogInformation(entry.ToString());
} catch (Exception e)

int firstSpaceIdx = text.AsSpan().IndexOf(' ');
if (firstSpaceIdx == -1)
{
logger.LogError("ChatEntryError: " + e.ToString());
logger.LogError($"Malformed payload: {text}");
return;
}

string author = text.AsSpan(0, firstSpaceIdx).ToString();
string msg = text.AsSpan(firstSpaceIdx + 1).ToString();

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

0 comments on commit a949543

Please sign in to comment.