-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Basic API Implementation * Update Bunkum to 1.0.4 * API endpoints for getting levels * Category system Future-proofs some stuff for when we add LBP3 categories & more LBP2 categories, as well as API support * Add more details to categories, add endpoint for getting categories * Add skip/count parameters for level api * Cleanup usages * Add ByUserLevelCategory * Allow game to use new category system * Add level search category * Match GameRoute instead of ApiRoute in LevelEndpoints I don't know how I almost let that slip by. * Mark workaround as FIXME
- Loading branch information
Showing
28 changed files
with
313 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Net; | ||
using Bunkum.HttpServer; | ||
using Bunkum.HttpServer.Endpoints; | ||
using Refresh.GameServer.Database; | ||
using Refresh.GameServer.Types.Levels; | ||
using Refresh.GameServer.Types.Levels.Categories; | ||
using Refresh.GameServer.Types.UserData; | ||
|
||
namespace Refresh.GameServer.Endpoints.Api; | ||
|
||
public class LevelApiEndpoints : EndpointGroup | ||
{ | ||
[ApiEndpoint("levels/{route}")] | ||
[Authentication(false)] | ||
[NullStatusCode(HttpStatusCode.NotFound)] | ||
public IEnumerable<GameLevel>? GetLevels(RequestContext context, RealmDatabaseContext database, GameUser? user, string route) | ||
=> CategoryHandler.Categories | ||
.FirstOrDefault(c => c.ApiRoute.StartsWith(route))? | ||
.Fetch(context, database, user); | ||
|
||
[ApiEndpoint("levels")] | ||
[Authentication(false)] | ||
public IEnumerable<LevelCategory> GetCategories(RequestContext context) => CategoryHandler.Categories; | ||
|
||
[ApiEndpoint("level/id/{idStr}")] | ||
[Authentication(false)] | ||
public GameLevel? GetLevelById(RequestContext context, RealmDatabaseContext database, string idStr) | ||
{ | ||
int.TryParse(idStr, out int id); | ||
if (id == default) return null; | ||
|
||
return database.GetLevelById(id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Bunkum.HttpServer; | ||
using Bunkum.HttpServer.Endpoints; | ||
using Refresh.GameServer.Database; | ||
using Refresh.GameServer.Types.UserData; | ||
|
||
namespace Refresh.GameServer.Endpoints.Api; | ||
|
||
public class UserApiEndpoints : EndpointGroup | ||
{ | ||
[ApiEndpoint("user/name/{username}")] | ||
[Authentication(false)] | ||
public GameUser? GetUserByName(RequestContext context, RealmDatabaseContext database, string username) | ||
=> database.GetUserByUsername(username); | ||
|
||
[ApiEndpoint("user/uuid/{uuid}")] | ||
[Authentication(false)] | ||
public GameUser? GetUserByUuid(RequestContext context, RealmDatabaseContext database, string uuid) | ||
=> database.GetUserByUuid(uuid); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Bunkum.HttpServer.Endpoints; | ||
using Bunkum.HttpServer.Responses; | ||
using JetBrains.Annotations; | ||
|
||
namespace Refresh.GameServer.Endpoints; | ||
|
||
[MeansImplicitUse] | ||
public class ApiEndpointAttribute : EndpointAttribute | ||
{ | ||
// v2, since maybe we want to add add v1 for backwards compatibility with project lighthouse? | ||
// LegacyApiEndpointAttribute for lighthouse api | ||
private const string BaseRoute = "/api/v2/"; | ||
|
||
public ApiEndpointAttribute(string route, Method method = Method.Get, ContentType contentType = ContentType.Json) | ||
: base(BaseRoute + route, method, contentType) | ||
{} | ||
|
||
public ApiEndpointAttribute(string route, ContentType contentType, Method method = Method.Get) | ||
: base(BaseRoute + route, contentType, method) | ||
{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
...r/Endpoints/Handshake/LicenseEndpoints.cs → ...points/Game/Handshake/LicenseEndpoints.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
.../Endpoints/Handshake/MetadataEndpoints.cs → ...oints/Game/Handshake/MetadataEndpoints.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
Refresh.GameServer/Endpoints/Game/Levels/LevelEndpoints.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Net; | ||
using Bunkum.HttpServer; | ||
using Bunkum.HttpServer.Endpoints; | ||
using Bunkum.HttpServer.Responses; | ||
using Refresh.GameServer.Database; | ||
using Refresh.GameServer.Types.Levels; | ||
using Refresh.GameServer.Types.Levels.Categories; | ||
using Refresh.GameServer.Types.Lists; | ||
using Refresh.GameServer.Types.UserData; | ||
|
||
namespace Refresh.GameServer.Endpoints.Game.Levels; | ||
|
||
public class LevelEndpoints : EndpointGroup | ||
{ | ||
// FIXME: Workaround shitty routing - see https://github.com/LittleBigRefresh/Refresh/pull/13#discussion_r1086131790 for details | ||
[GameEndpoint("slots", ContentType.Xml)] | ||
public GameMinimalLevelList NewestLevels(RequestContext context, RealmDatabaseContext database, GameUser? user) | ||
=> this.GetLevels(context, database, user, "newest"); | ||
|
||
[GameEndpoint("slots/{route}", ContentType.Xml)] | ||
public GameMinimalLevelList GetLevels(RequestContext context, RealmDatabaseContext database, GameUser? user, string route) => | ||
new(CategoryHandler.Categories | ||
.FirstOrDefault(c => c.GameRoute.StartsWith(route))? | ||
.Fetch(context, database, user)? | ||
.Select(GameMinimalLevel.FromGameLevel), database.GetTotalLevelCount()); // TODO: proper level count | ||
|
||
[GameEndpoint("s/user/{idStr}", ContentType.Xml)] | ||
[NullStatusCode(HttpStatusCode.NotFound)] | ||
public GameLevel? LevelById(RequestContext context, RealmDatabaseContext database, string idStr) | ||
{ | ||
int.TryParse(idStr, out int id); | ||
if (id == default) return null; | ||
|
||
return database.GetLevelById(id); | ||
} | ||
} |
8 changes: 4 additions & 4 deletions
8
...rver/Endpoints/Levels/PublishEndpoints.cs → ...Endpoints/Game/Levels/PublishEndpoints.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...GameServer/Endpoints/PresenceEndpoints.cs → ...erver/Endpoints/Game/PresenceEndpoints.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...GameServer/Endpoints/ResourceEndpoints.cs → ...erver/Endpoints/Game/ResourceEndpoints.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
Refresh.GameServer/GameEndpointAttribute.cs → ...Server/Endpoints/GameEndpointAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.