From 8e825101c8514642583409c8513e4b2650bb88fa Mon Sep 17 00:00:00 2001 From: Raphiiko Date: Sun, 3 Nov 2024 02:10:05 +0100 Subject: [PATCH] Fixed vrc log parsing --- CHANGELOG.md | 4 +++ src-ui/app/models/vrchat-log-event.ts | 2 ++ src-ui/app/services/vrchat-log.service.ts | 33 ++++++++++++++++++++--- src-ui/app/services/vrchat.service.ts | 4 +-- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b3858b7..7b9d5121 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - GPU acceleration for SteamVR overlays (Community contribution by [BenjaminZehowlt](https://github.com/BenjaminZehowlt)) +### Fixed + +- Fixed parsing of new VRChat join/leave log format + ## [1.14.5] ### Fixed diff --git a/src-ui/app/models/vrchat-log-event.ts b/src-ui/app/models/vrchat-log-event.ts index 57ba5b95..326641ba 100644 --- a/src-ui/app/models/vrchat-log-event.ts +++ b/src-ui/app/models/vrchat-log-event.ts @@ -14,11 +14,13 @@ interface VRChatLogEventBase { export interface VRChatOnPlayerJoinedEvent extends VRChatLogEventBase { type: 'OnPlayerJoined'; displayName: string; + userId: string; } export interface VRChatOnPlayerLeftEvent extends VRChatLogEventBase { type: 'OnPlayerLeft'; displayName: string; + userId: string; } export interface VRChatOnLocationChangeEvent extends VRChatLogEventBase { diff --git a/src-ui/app/services/vrchat-log.service.ts b/src-ui/app/services/vrchat-log.service.ts index 0f8d928e..178f1336 100644 --- a/src-ui/app/services/vrchat-log.service.ts +++ b/src-ui/app/services/vrchat-log.service.ts @@ -33,22 +33,28 @@ export class VRChatLogService { case 'InitialLoadComplete': this._initialLoadComplete.next(true); break; - case 'OnPlayerJoined': + case 'OnPlayerJoined': { + const { displayName, userId } = this.parseNameAndId(event.data); this._logEvents.next({ type: 'OnPlayerJoined', timestamp: moment.unix(event.time).toDate(), - displayName: event.data, initialLoad: event.initialLoad, + displayName, + userId, }); break; - case 'OnPlayerLeft': + } + case 'OnPlayerLeft': { + const { displayName, userId } = this.parseNameAndId(event.data); this._logEvents.next({ type: 'OnPlayerLeft', timestamp: moment.unix(event.time).toDate(), - displayName: event.data, initialLoad: event.initialLoad, + displayName, + userId, }); break; + } case 'OnLocationChange': this._logEvents.next({ type: 'OnLocationChange', @@ -58,4 +64,23 @@ export class VRChatLogService { }); } } + + private parseNameAndId(data: string): { displayName: string; userId: string } { + const parts = data.split(' '); + if ( + parts.length > 1 && + parts[parts.length - 1].startsWith('(') && + parts[parts.length - 1].endsWith(')') + ) { + return { + displayName: parts.slice(0, parts.length - 1).join(' '), + userId: parts[parts.length - 1].slice(1, -1), + }; + } else { + return { + displayName: data, + userId: '', + }; + } + } } diff --git a/src-ui/app/services/vrchat.service.ts b/src-ui/app/services/vrchat.service.ts index 7390225d..b88782ba 100644 --- a/src-ui/app/services/vrchat.service.ts +++ b/src-ui/app/services/vrchat.service.ts @@ -690,7 +690,7 @@ export class VRChatService { ...structuredClone(this._world.value), playerCount: this._world.value.playerCount + 1, }; - if (event.displayName === this._user.value?.displayName) context.loaded = true; + if (event.userId === this._user.value?.id) context.loaded = true; this._world.next(context); break; } @@ -699,7 +699,7 @@ export class VRChatService { ...structuredClone(this._world.value), playerCount: Math.max(this._world.value.playerCount - 1, 0), }; - if (event.displayName === this._user.value?.displayName) context.loaded = false; + if (event.userId === this._user.value?.id) context.loaded = false; this._world.next(context); break; }