Skip to content

Commit

Permalink
Add UserId parsing on player joined or left (#943)
Browse files Browse the repository at this point in the history
  • Loading branch information
DubyaDude authored Oct 21, 2024
1 parent 458c00f commit ddc1604
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
32 changes: 28 additions & 4 deletions Dotnet/LogWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ private bool ParseLogOnPlayerJoinedOrLeft(FileInfo fileInfo, LogContext logConte
// 2021.12.12 11:47:22 Log - [Behaviour] OnPlayerJoined:Unnamed
// 2021.12.12 11:53:14 Log - [Behaviour] OnPlayerLeftRoom

// Future logs will be formatted like this: [Behaviour] OnPlayerJoined Natsumi-sama (usr_032383a7-748c-4fb2-94e4-bcb928e5de6b)

if (line.Contains("[Behaviour] OnPlayerJoined") && !line.Contains("] OnPlayerJoined:"))
{
var lineOffset = line.LastIndexOf("] OnPlayerJoined");
Expand All @@ -464,14 +466,15 @@ private bool ParseLogOnPlayerJoinedOrLeft(FileInfo fileInfo, LogContext logConte
if (lineOffset > line.Length)
return true;

var userDisplayName = line.Substring(lineOffset);
var userInfo = ParseUserInfo(line.Substring(lineOffset));

AppendLog(new[]
{
fileInfo.Name,
ConvertLogTimeToISO8601(line),
"player-joined",
userDisplayName
userInfo.DisplayName,
userInfo.UserId
});

return true;
Expand All @@ -486,14 +489,15 @@ private bool ParseLogOnPlayerJoinedOrLeft(FileInfo fileInfo, LogContext logConte
if (lineOffset > line.Length)
return true;

var userDisplayName = line.Substring(lineOffset);
var userInfo = ParseUserInfo(line.Substring(lineOffset));

AppendLog(new[]
{
fileInfo.Name,
ConvertLogTimeToISO8601(line),
"player-left",
userDisplayName
userInfo.DisplayName,
userInfo.UserId
});

return true;
Expand Down Expand Up @@ -1285,6 +1289,26 @@ public string[][] Get()
return new string[][] { };
}

private static (string DisplayName, string UserId) ParseUserInfo(string userInfo)
{
string userDisplayName;
string userId;

int pos = userInfo.LastIndexOf(" (");
if (pos >= 0)
{
userDisplayName = userInfo.Substring(0, pos);
userId = userInfo.Substring(pos + 2, userInfo.LastIndexOf(')') - (pos + 3));
}
else
{
userDisplayName = userInfo;
userId = null;
}

return (userDisplayName, userId);
}

private class LogContext
{
public bool AudioDeviceChanged;
Expand Down
2 changes: 1 addition & 1 deletion html/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11245,7 +11245,7 @@ speechSynthesis.getVoices();
var joinTime = Date.parse(gameLog.dt);
var userMap = {
displayName: gameLog.displayName,
userId,
userId : gameLog.userId,
joinTime,
lastAvatar: ''
};
Expand Down
2 changes: 2 additions & 0 deletions html/src/service/gamelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ class GameLogService {

case 'player-joined':
gameLog.displayName = args[0];
gameLog.userId = args[1];
break;

case 'player-left':
gameLog.displayName = args[0];
gameLog.userId = args[1];
break;

case 'notification':
Expand Down

0 comments on commit ddc1604

Please sign in to comment.