mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
Preserve time spent when teleporting within game
This commit is contained in:
parent
f28d956367
commit
b89bb0a140
@ -17,6 +17,7 @@ namespace Bloxstrap.Helpers
|
||||
private const string GameJoiningUDMUXEntry = "[FLog::Network] UDMUX Address = ";
|
||||
private const string GameJoinedEntry = "[FLog::Network] serverId:";
|
||||
private const string GameDisconnectedEntry = "[FLog::Network] Time to disconnect replication data:";
|
||||
private const string GameTeleportingEntry = "[FLog::SingleSurfaceApp] initiateTeleport";
|
||||
|
||||
private const string GameJoiningEntryPattern = @"! Joining game '([0-9a-f\-]{36})' place ([0-9]+) at ([0-9\.]+)";
|
||||
private const string GameJoiningUDMUXPattern = @"UDMUX Address = ([0-9\.]+), Port = [0-9]+ \| RCC Server Address = ([0-9\.]+), Port = [0-9]+";
|
||||
@ -28,11 +29,14 @@ namespace Bloxstrap.Helpers
|
||||
public event EventHandler? OnGameLeave;
|
||||
|
||||
// these are values to use assuming the player isn't currently in a game
|
||||
// keep in mind ActivityIsTeleport is only reset by DiscordRichPresence when it's done accessing it
|
||||
// because of the weird chronology of where the teleporting entry is outputted, there's no way to reset it in here
|
||||
public bool ActivityInGame = false;
|
||||
public long ActivityPlaceId = 0;
|
||||
public string ActivityJobId = "";
|
||||
public string ActivityMachineAddress = "";
|
||||
public bool ActivityMachineUDMUX = false;
|
||||
public bool ActivityIsTeleport = false;
|
||||
|
||||
public bool IsDisposed = false;
|
||||
|
||||
@ -163,17 +167,25 @@ namespace Bloxstrap.Helpers
|
||||
OnGameJoin?.Invoke(this, new EventArgs());
|
||||
}
|
||||
}
|
||||
else if (ActivityInGame && ActivityPlaceId != 0 && entry.Contains(GameDisconnectedEntry))
|
||||
else if (ActivityInGame && ActivityPlaceId != 0)
|
||||
{
|
||||
App.Logger.WriteLine($"[GameActivityWatcher::ExamineLogEntry] Disconnected from Game ({ActivityPlaceId}/{ActivityJobId}/{ActivityMachineAddress})");
|
||||
if (entry.Contains(GameDisconnectedEntry))
|
||||
{
|
||||
App.Logger.WriteLine($"[GameActivityWatcher::ExamineLogEntry] Disconnected from Game ({ActivityPlaceId}/{ActivityJobId}/{ActivityMachineAddress})");
|
||||
|
||||
ActivityInGame = false;
|
||||
ActivityPlaceId = 0;
|
||||
ActivityJobId = "";
|
||||
ActivityMachineAddress = "";
|
||||
ActivityMachineUDMUX = false;
|
||||
ActivityInGame = false;
|
||||
ActivityPlaceId = 0;
|
||||
ActivityJobId = "";
|
||||
ActivityMachineAddress = "";
|
||||
ActivityMachineUDMUX = false;
|
||||
|
||||
OnGameLeave?.Invoke(this, new EventArgs());
|
||||
OnGameLeave?.Invoke(this, new EventArgs());
|
||||
}
|
||||
else if (entry.Contains(GameTeleportingEntry))
|
||||
{
|
||||
App.Logger.WriteLine($"[GameActivityWatcher::ExamineLogEntry] Initiating teleport to server ({ActivityPlaceId}/{ActivityJobId}/{ActivityMachineAddress})");
|
||||
ActivityIsTeleport = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Bloxstrap.Helpers;
|
||||
@ -18,6 +15,9 @@ namespace Bloxstrap.Integrations
|
||||
private readonly DiscordRpcClient _rpcClient = new("1005469189907173486");
|
||||
private readonly GameActivityWatcher _activityWatcher;
|
||||
|
||||
private long _currentUniverseId;
|
||||
private DateTime? _timeStartedUniverse;
|
||||
|
||||
public DiscordRichPresence(GameActivityWatcher activityWatcher)
|
||||
{
|
||||
_activityWatcher = activityWatcher;
|
||||
@ -67,6 +67,13 @@ namespace Bloxstrap.Integrations
|
||||
long universeId = universeIdResponse.UniverseId;
|
||||
App.Logger.WriteLine($"[DiscordRichPresence::SetPresence] Got Universe ID as {universeId}");
|
||||
|
||||
// preserve time spent playing if we're teleporting between places in the same universe
|
||||
if (_timeStartedUniverse is null || !_activityWatcher.ActivityIsTeleport || universeId != _currentUniverseId)
|
||||
_timeStartedUniverse = DateTime.UtcNow;
|
||||
|
||||
_activityWatcher.ActivityIsTeleport = false;
|
||||
_currentUniverseId = universeId;
|
||||
|
||||
var gameDetailResponse = await Utilities.GetJson<ApiArrayResponse<GameDetailResponse>>($"https://games.roblox.com/v1/games?universeIds={universeId}");
|
||||
if (gameDetailResponse is null || !gameDetailResponse.Data.Any())
|
||||
{
|
||||
@ -110,7 +117,7 @@ namespace Bloxstrap.Integrations
|
||||
{
|
||||
Details = universeDetails.Name,
|
||||
State = $"by {universeDetails.Creator.Name}" + (universeDetails.Creator.HasVerifiedBadge ? " ☑️" : ""),
|
||||
Timestamps = new Timestamps { Start = DateTime.UtcNow },
|
||||
Timestamps = new Timestamps { Start = _timeStartedUniverse },
|
||||
Buttons = buttons.ToArray(),
|
||||
Assets = new Assets
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user