Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability for beta builds to have their own isolated space #368

Merged
merged 7 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Refresh.GameServer/Authentication/TokenGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum TokenGame
LittleBigPlanetVita = 3,
LittleBigPlanetPSP = 4,
Website = 5,
BetaBuild = 6,
}

public static class TokenGameExtensions
Expand All @@ -22,6 +23,7 @@ public static int ToSerializedGame(this TokenGame game)
TokenGame.LittleBigPlanet3 => 2,
TokenGame.LittleBigPlanetVita => 1,
TokenGame.LittleBigPlanetPSP => 0,
TokenGame.BetaBuild => 1, // treat beta levels as LBP2 for now.
TokenGame.Website => throw new InvalidOperationException("https://osuhow.com/"),
_ => throw new ArgumentOutOfRangeException(),
};
Expand Down Expand Up @@ -59,6 +61,12 @@ public static bool CanPlay(this TokenGame game, GameLevel level)
if (level.GameVersion != TokenGame.LittleBigPlanetPSP)
return false;

break;
// Isolate beta builds' levels
case TokenGame.BetaBuild:
if (level.GameVersion != TokenGame.BetaBuild)
return false;

break;
//Allow all for website
case TokenGame.Website:
Expand Down
36 changes: 20 additions & 16 deletions Refresh.GameServer/Authentication/TokenGameUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ public static class TokenGameUtility

"NPJA00052", // JP Digital
"BCJS30018", // JP Disc

// Betas/Debug/Prerelease
"BCET70002", // EU "Online Trial" Beta Test
"BCET70011", // EU Water Beta Test
"NPUA70045", // US Demo
};

private static readonly string[] LittleBigPlanet2Titles =
Expand All @@ -53,11 +48,6 @@ public static class TokenGameUtility

"BCJS30058", // JP Disc
// missing japan digital?

// Betas/Debug/Prerelease
"NPUA70117", // US Private Beta
"BCET70055", // LBP Hub (real title id)
"NPEA00449", // LBP HUB (sent title id)
};

// PS4 title ids are not here on purpose.
Expand Down Expand Up @@ -86,11 +76,6 @@ public static class TokenGameUtility

"NPJG00073", // JP Digital
"NPHG00033", // Asia Digital

// Betas/Debug/Prerelease
"NPUG70064", // US Demo
"NPEG90019", // EU Demo
"NPHG00035", // Asia Demo
};

private static readonly string[] LittleBigPlanetVitaTitles =
Expand All @@ -106,8 +91,26 @@ public static class TokenGameUtility

"PCSC00013", // JP Digital
"VCJS10006", // JP Cartridge
};

private static readonly string[] BetaBuildTitles =
{
// LBP1
"BCET70002", // EU "Online Trial" Beta Test
"BCET70011", // EU Water Beta Test
"NPUA70045", // US Demo

// LBP2
"NPUA70117", // US Private Beta
"BCET70055", // LBP Hub (real title id)
"NPEA00449", // LBP HUB (sent title id)

// PSP
"NPUG70064", // US Demo
"NPEG90019", // EU Demo
"NPHG00035", // Asia Demo

// Betas/Debug/Prerelease
// Vita
"PCSA00061", // US Beta
"PCSF00152", // EU Beta
};
Expand All @@ -119,6 +122,7 @@ public static class TokenGameUtility
if (LittleBigPlanet3Titles.Contains(titleId)) return TokenGame.LittleBigPlanet3;
if (LittleBigPlanetPSPTitles.Contains(titleId)) return TokenGame.LittleBigPlanetPSP;
if (LittleBigPlanetVitaTitles.Contains(titleId)) return TokenGame.LittleBigPlanetVita;
if (BetaBuildTitles.Contains(titleId)) return TokenGame.BetaBuild;

return null;
}
Expand Down
2 changes: 0 additions & 2 deletions Refresh.GameServer/Database/GameDatabaseContext.Users.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ public void SetForceMatch(GameUser user, GameUser target)
});
}

#if DEBUG
public void ForceUserTokenGame(Token token, TokenGame game)
{
this._realm.Write(() =>
Expand All @@ -347,5 +346,4 @@ public void ForceUserTokenPlatform(Token token, TokenPlatform platform)
token.TokenPlatform = platform;
});
}
#endif
}
1 change: 1 addition & 0 deletions Refresh.GameServer/Database/GameDatabaseProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ protected override void Migrate(Migration migration, ulong oldVersion)
TokenGame.LittleBigPlanet3 => TokenPlatform.PS3,
TokenGame.LittleBigPlanetVita => TokenPlatform.Vita,
TokenGame.LittleBigPlanetPSP => TokenPlatform.PSP,
TokenGame.BetaBuild => TokenPlatform.RPCS3,
TokenGame.Website => throw new InvalidOperationException($"what? score id {newScore.ScoreId} by {newScore.Players[0].Username} is fucked"),
_ => throw new ArgumentOutOfRangeException(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ private void FillInExtraData(GameUser old, TokenGame gameVersion, GameDatabaseCo
TokenGame.LittleBigPlanetVita => old.VitaPlanetsHash,
TokenGame.LittleBigPlanetPSP => "0",
TokenGame.Website => "0",
TokenGame.BetaBuild => old.Lbp2PlanetsHash, // TODO: Planet hash for beta builds
_ => throw new ArgumentOutOfRangeException(nameof(gameVersion), gameVersion, null),
};

Expand All @@ -130,6 +131,7 @@ private void FillInExtraData(GameUser old, TokenGame gameVersion, GameDatabaseCo
//Fill out LBP2/LBP1 levels
goto case TokenGame.LittleBigPlanet2;
}
case TokenGame.BetaBuild:
jvyden marked this conversation as resolved.
Show resolved Hide resolved
case TokenGame.LittleBigPlanet2: {
//Match all LBP2 levels
this.UsedSlotsLBP2 = old.PublishedLevels.Count(x => x._GameVersion == (int)TokenGame.LittleBigPlanet2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,13 @@ public class AuthenticationEndpoints : EndpointGroup
}
}

TokenGame? game = TokenGameUtility.FromTitleId(ticket.TitleId);
TokenGame? game = null;

// check if we're connecting from a beta build
bool parsedBeta = byte.TryParse(context.QueryString.Get("beta"), out byte isBeta);
if (parsedBeta && isBeta == 1) game = TokenGame.BetaBuild;

game ??= TokenGameUtility.FromTitleId(ticket.TitleId);

if (platform == null)
{
Expand Down
40 changes: 24 additions & 16 deletions Refresh.GameServer/Extensions/LevelEnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static IEnumerable<GameLevel> FilterByGameVersion(this IEnumerable<GameLe
TokenGame.LittleBigPlanet3 => levels.Where(l => l._GameVersion <= (int)TokenGame.LittleBigPlanet3),
TokenGame.LittleBigPlanetVita => levels.Where(l => l._GameVersion == (int)TokenGame.LittleBigPlanetVita),
TokenGame.LittleBigPlanetPSP => levels.Where(l => l._GameVersion == (int)TokenGame.LittleBigPlanetPSP),
TokenGame.BetaBuild => levels.Where(l => l._GameVersion == (int)TokenGame.BetaBuild),
TokenGame.Website => levels,
_ => throw new ArgumentOutOfRangeException(nameof(gameVersion), gameVersion, null),
};
Expand All @@ -27,6 +28,7 @@ public static IQueryable<GameLevel> FilterByGameVersion(this IQueryable<GameLeve
TokenGame.LittleBigPlanet3 => levels.Where(l => l._GameVersion <= (int)TokenGame.LittleBigPlanet3),
TokenGame.LittleBigPlanetVita => levels.Where(l => l._GameVersion == (int)TokenGame.LittleBigPlanetVita),
TokenGame.LittleBigPlanetPSP => levels.Where(l => l._GameVersion == (int)TokenGame.LittleBigPlanetPSP),
TokenGame.BetaBuild => levels.Where(l => l._GameVersion == (int)TokenGame.BetaBuild),
TokenGame.Website => levels,
_ => throw new ArgumentOutOfRangeException(nameof(gameVersion), gameVersion, null),
};
Expand All @@ -36,14 +38,17 @@ public static IQueryable<GameLevel> FilterByLevelFilterSettings(this IQueryable<
if (levelFilterSettings.ExcludeMyLevels && user != null)
levels = levels.Where(l => l.Publisher != user);

levels = levelFilterSettings.GameFilterType switch {
GameFilterType.LittleBigPlanet1 => levels.Where(l => l._GameVersion == (int)TokenGame.LittleBigPlanet1),
GameFilterType.LittleBigPlanet2 => levels.Where(l => l._GameVersion == (int)TokenGame.LittleBigPlanet2),
//NOTE: ideally this should be .Where(l => l._GameVersion == (int)TokenGame.LittleBigPlane1 || l._GameVersion == (int)TokenGame.LittleBigPlane2)
// however, there should be no differences in all real-world cases
GameFilterType.Both => levels,
_ => throw new ArgumentOutOfRangeException(),
};
if (levelFilterSettings.GameVersion != TokenGame.BetaBuild)
{
levels = levelFilterSettings.GameFilterType switch {
GameFilterType.LittleBigPlanet1 => levels.Where(l => l._GameVersion == (int)TokenGame.LittleBigPlanet1),
GameFilterType.LittleBigPlanet2 => levels.Where(l => l._GameVersion == (int)TokenGame.LittleBigPlanet2),
//NOTE: ideally this should be .Where(l => l._GameVersion == (int)TokenGame.LittleBigPlane1 || l._GameVersion == (int)TokenGame.LittleBigPlane2)
// however, there should be no differences in all real-world cases
GameFilterType.Both => levels,
_ => throw new ArgumentOutOfRangeException(),
};
}
jvyden marked this conversation as resolved.
Show resolved Hide resolved

if (levelFilterSettings.Players != 0)
levels = levels.Where(l => l.MaxPlayers >= levelFilterSettings.Players && l.MinPlayers <= levelFilterSettings.Players);
Expand All @@ -68,14 +73,17 @@ public static IEnumerable<GameLevel> FilterByLevelFilterSettings(this IEnumerabl
if (levelFilterSettings.ExcludeMyLevels && user != null)
levels = levels.Where(l => l.Publisher != user);

levels = levelFilterSettings.GameFilterType switch {
GameFilterType.LittleBigPlanet1 => levels.Where(l => l._GameVersion == (int)TokenGame.LittleBigPlanet1),
GameFilterType.LittleBigPlanet2 => levels.Where(l => l._GameVersion == (int)TokenGame.LittleBigPlanet2),
//NOTE: ideally this should be .Where(l => l._GameVersion == (int)TokenGame.LittleBigPlane1 || l._GameVersion == (int)TokenGame.LittleBigPlane2)
// however, there should be no differences in all real-world cases
GameFilterType.Both => levels,
_ => throw new ArgumentOutOfRangeException(),
};
if (levelFilterSettings.GameVersion != TokenGame.BetaBuild)
{
levels = levelFilterSettings.GameFilterType switch {
GameFilterType.LittleBigPlanet1 => levels.Where(l => l._GameVersion == (int)TokenGame.LittleBigPlanet1),
GameFilterType.LittleBigPlanet2 => levels.Where(l => l._GameVersion == (int)TokenGame.LittleBigPlanet2),
//NOTE: ideally this should be .Where(l => l._GameVersion == (int)TokenGame.LittleBigPlane1 || l._GameVersion == (int)TokenGame.LittleBigPlane2)
// however, there should be no differences in all real-world cases
GameFilterType.Both => levels,
_ => throw new ArgumentOutOfRangeException(),
};
}

if (levelFilterSettings.Players != 0)
levels = levels.Where(l => l.MaxPlayers >= levelFilterSettings.Players && l.MinPlayers <= levelFilterSettings.Players);
Expand Down
10 changes: 10 additions & 0 deletions Refresh.GameServer/Services/CommandService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ public void HandleCommand(CommandInvocation command, GameDatabaseContext databas
}
break;
}
case "beta":
{
database.ForceUserTokenGame(token, TokenGame.BetaBuild);
break;
}
case "revoketoken":
{
database.RevokeToken(token);
break;
}
#if DEBUG
case "tokengame":
{
Expand Down
1 change: 1 addition & 0 deletions Refresh.GameServer/Services/GuidCheckerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public bool IsTextureGuid(TokenGame game, long guid)
TokenGame.LittleBigPlanet3 => this._validMainlineTextureGuids.TryGetValue(guid, out _),
TokenGame.LittleBigPlanetVita => this._validVitaTextureGuids.TryGetValue(guid, out _),
TokenGame.LittleBigPlanetPSP => guid is >= 0 and <= 63, //PSP avatar GUIDs can be g0 - g63
TokenGame.BetaBuild => this._validMainlineTextureGuids.TryGetValue(guid, out _),
_ => throw new ArgumentOutOfRangeException(nameof(game), game, null),
};
}
Expand Down
Loading