Skip to content

Commit

Permalink
Alter how game teleports are detected
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaboxer committed Jul 20, 2023
1 parent 9d7f9f7 commit 5205287
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
7 changes: 3 additions & 4 deletions Bloxstrap/Integrations/DiscordRichPresence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public async Task<bool> SetCurrentGame()

App.Logger.WriteLine($"[DiscordRichPresence::SetCurrentGame] Setting presence for Place ID {_activityWatcher.ActivityPlaceId}");

var universeIdResponse = await Utility.Http.GetJson<UniverseIdResponse>($"https://apis.roblox.com/universes/v1/places/{_activityWatcher.ActivityPlaceId}/universe");
var universeIdResponse = await Http.GetJson<UniverseIdResponse>($"https://apis.roblox.com/universes/v1/places/{_activityWatcher.ActivityPlaceId}/universe");
if (universeIdResponse is null)
{
App.Logger.WriteLine($"[DiscordRichPresence::SetCurrentGame] Could not get Universe ID!");
Expand All @@ -131,10 +131,9 @@ public async Task<bool> SetCurrentGame()
if (_timeStartedUniverse is null || !_activityWatcher.ActivityIsTeleport || universeId != _currentUniverseId)
_timeStartedUniverse = DateTime.UtcNow;

_activityWatcher.ActivityIsTeleport = false;
_currentUniverseId = universeId;

var gameDetailResponse = await Utility.Http.GetJson<ApiArrayResponse<GameDetailResponse>>($"https://games.roblox.com/v1/games?universeIds={universeId}");
var gameDetailResponse = await Http.GetJson<ApiArrayResponse<GameDetailResponse>>($"https://games.roblox.com/v1/games?universeIds={universeId}");
if (gameDetailResponse is null || !gameDetailResponse.Data.Any())
{
App.Logger.WriteLine($"[DiscordRichPresence::SetCurrentGame] Could not get Universe info!");
Expand All @@ -144,7 +143,7 @@ public async Task<bool> SetCurrentGame()
GameDetailResponse universeDetails = gameDetailResponse.Data.ToArray()[0];
App.Logger.WriteLine($"[DiscordRichPresence::SetCurrentGame] Got Universe details");

var universeThumbnailResponse = await Utility.Http.GetJson<ApiArrayResponse<ThumbnailResponse>>($"https://thumbnails.roblox.com/v1/games/icons?universeIds={universeId}&returnPolicy=PlaceHolder&size=512x512&format=Png&isCircular=false");
var universeThumbnailResponse = await Http.GetJson<ApiArrayResponse<ThumbnailResponse>>($"https://thumbnails.roblox.com/v1/games/icons?universeIds={universeId}&returnPolicy=PlaceHolder&size=512x512&format=Png&isCircular=false");
if (universeThumbnailResponse is null || !universeThumbnailResponse.Data.Any())
{
App.Logger.WriteLine($"[DiscordRichPresence::SetCurrentGame] Could not get Universe thumbnail info!");
Expand Down
15 changes: 12 additions & 3 deletions Bloxstrap/RobloxActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class RobloxActivity : IDisposable
private const string GameJoinedEntryPattern = @"serverId: ([0-9\.]+)\|[0-9]+";

private int _logEntriesRead = 0;
private bool _teleportMarker = false;

public event EventHandler<string>? OnLogEntry;
public event EventHandler? OnGameJoin;
Expand All @@ -27,8 +28,6 @@ public class RobloxActivity : IDisposable
public string LogFilename = null!;

// 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 = "";
Expand Down Expand Up @@ -130,6 +129,16 @@ private void ExamineLogEntry(string entry)
ActivityJobId = match.Groups[1].Value;
ActivityMachineAddress = match.Groups[3].Value;

if (_teleportMarker)
{
ActivityIsTeleport = true;
_teleportMarker = false;
}
else
{
ActivityIsTeleport = false;
}

App.Logger.WriteLine($"[RobloxActivity::ExamineLogEntry] Joining Game ({ActivityPlaceId}/{ActivityJobId}/{ActivityMachineAddress})");
}
else if (!ActivityInGame && ActivityPlaceId != 0)
Expand Down Expand Up @@ -184,7 +193,7 @@ private void ExamineLogEntry(string entry)
else if (entry.Contains(GameTeleportingEntry))
{
App.Logger.WriteLine($"[RobloxActivity::ExamineLogEntry] Initiating teleport to server ({ActivityPlaceId}/{ActivityJobId}/{ActivityMachineAddress})");
ActivityIsTeleport = true;
_teleportMarker = true;
}
else if (entry.Contains(GameMessageEntry))
{
Expand Down

0 comments on commit 5205287

Please sign in to comment.