Skip to content

Commit

Permalink
Merge branch 'main' into highest-rated-lbp1psp
Browse files Browse the repository at this point in the history
  • Loading branch information
Beyley authored Oct 1, 2023
2 parents 822c6d7 + 50be1e8 commit e7a5a02
Show file tree
Hide file tree
Showing 95 changed files with 456 additions and 454 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System.Diagnostics;
using Bunkum.CustomHttpListener.Request;
using Bunkum.Listener.Request;
using Refresh.GameServer.Database;
using Refresh.GameServer.Types.UserData;
using Bunkum.HttpServer.Authentication;
using Bunkum.HttpServer.Database;
using Bunkum.Core.Authentication;
using Bunkum.Core.Database;
using Refresh.GameServer.Configuration;
using Refresh.GameServer.Types.Roles;

namespace Refresh.GameServer.Authentication;

public class GameAuthenticationProvider : IAuthenticationProvider<GameUser, Token>
public class GameAuthenticationProvider : IAuthenticationProvider<Token>
{
private readonly GameServerConfig? _config;

Expand Down
4 changes: 2 additions & 2 deletions Refresh.GameServer/Authentication/Token.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Xml.Serialization;
using Bunkum.HttpServer.Authentication;
using Bunkum.Core.Authentication;
using MongoDB.Bson;
using Realms;
using Refresh.GameServer.Types.UserData;
Expand All @@ -9,7 +9,7 @@ namespace Refresh.GameServer.Authentication;
#nullable disable

[JsonObject(MemberSerialization.OptIn)]
public partial class Token : IRealmObject, IToken
public partial class Token : IRealmObject, IToken<GameUser>
{
[PrimaryKey]
public ObjectId TokenId { get; set; } = ObjectId.GenerateNewId();
Expand Down
3 changes: 1 addition & 2 deletions Refresh.GameServer/CommandLineManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using Bunkum.HttpServer;
using CommandLine;
using NotEnoughLogs;
using Refresh.GameServer.Documentation;
Expand Down Expand Up @@ -67,7 +66,7 @@ private void StartWithOptions(Options options)

if (options.GenerateDocumentation)
{
DocumentationService service = new(new LoggerContainer<BunkumContext>());
DocumentationService service = new(new Logger());
service.Initialize();

string json = JsonConvert.SerializeObject(service.Documentation, Formatting.Indented);
Expand Down
2 changes: 1 addition & 1 deletion Refresh.GameServer/Configuration/GameServerConfig.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using Bunkum.HttpServer.Configuration;
using Bunkum.Core.Configuration;
using Refresh.GameServer.Types.Assets;

namespace Refresh.GameServer.Configuration;
Expand Down
2 changes: 1 addition & 1 deletion Refresh.GameServer/Configuration/IntegrationConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Bunkum.HttpServer.Configuration;
using Bunkum.Core.Configuration;

namespace Refresh.GameServer.Configuration;

Expand Down
2 changes: 1 addition & 1 deletion Refresh.GameServer/Configuration/RichPresenceConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Bunkum.HttpServer.Configuration;
using Bunkum.Core.Configuration;

namespace Refresh.GameServer.Configuration;

Expand Down
5 changes: 2 additions & 3 deletions Refresh.GameServer/Documentation/DocumentationService.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using System.Reflection;
using Bunkum.HttpServer;
using Bunkum.HttpServer.Services;
using Bunkum.Core.Services;
using NotEnoughLogs;
using Refresh.GameServer.Endpoints.ApiV3.DataTypes.Response;

namespace Refresh.GameServer.Documentation;

public class DocumentationService : EndpointService
{
internal DocumentationService(LoggerContainer<BunkumContext> logger) : base(logger)
internal DocumentationService(Logger logger) : base(logger)
{}

public override void Initialize()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Reflection;
using AttribDoc;
using Bunkum.HttpServer.Endpoints;
using Bunkum.HttpServer.Extensions;
using Bunkum.Core.Endpoints;
using Bunkum.Core.Extensions;
using Refresh.GameServer.Endpoints;

namespace Refresh.GameServer.Documentation;
Expand Down
4 changes: 2 additions & 2 deletions Refresh.GameServer/Endpoints/ApiV3/ActivityApiEndpoints.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using AttribDoc.Attributes;
using Bunkum.HttpServer;
using Bunkum.HttpServer.Endpoints;
using Bunkum.Core;
using Bunkum.Core.Endpoints;
using Refresh.GameServer.Database;
using Refresh.GameServer.Documentation.Attributes;
using Refresh.GameServer.Endpoints.ApiV3.ApiTypes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using AttribDoc.Attributes;
using Bunkum.CustomHttpListener.Parsing;
using Bunkum.HttpServer;
using Bunkum.HttpServer.Endpoints;
using Bunkum.Core;
using Bunkum.Core.Endpoints;
using Bunkum.Listener.Protocol;
using Bunkum.Protocols.Http;
using MongoDB.Bson;
using Refresh.GameServer.Database;
using Refresh.GameServer.Endpoints.ApiV3.ApiTypes;
Expand All @@ -15,15 +16,15 @@ namespace Refresh.GameServer.Endpoints.ApiV3.Admin;

public class AdminAnnouncementsApiEndpoints : EndpointGroup
{
[ApiV3Endpoint("admin/announcements", Method.Post), MinimumRole(GameUserRole.Admin)]
[ApiV3Endpoint("admin/announcements", HttpMethods.Post), MinimumRole(GameUserRole.Admin)]
[DocSummary("Creates an announcement that shows up in the Instance API endpoint")]
public ApiResponse<ApiGameAnnouncementResponse> CreateAnnouncement(RequestContext context, GameDatabaseContext database, ApiGameAnnouncementRequest body)
{
GameAnnouncement announcement = database.AddAnnouncement(body.Title, body.Text);
return ApiGameAnnouncementResponse.FromOld(announcement);
}

[ApiV3Endpoint("admin/announcements/{idStr}", Method.Delete), MinimumRole(GameUserRole.Admin)]
[ApiV3Endpoint("admin/announcements/{idStr}", HttpMethods.Delete), MinimumRole(GameUserRole.Admin)]
[DocError(typeof(ApiValidationError), ApiValidationError.ObjectIdParseErrorWhen)]
[DocError(typeof(ApiNotFoundError), "The announcement could not be found")]
[DocSummary("Removes an announcement")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using AttribDoc.Attributes;
using Bunkum.CustomHttpListener.Parsing;
using Bunkum.HttpServer;
using Bunkum.HttpServer.Endpoints;
using Bunkum.Core;
using Bunkum.Core.Endpoints;
using Bunkum.Listener.Protocol;
using Bunkum.Protocols.Http;
using Refresh.GameServer.Database;
using Refresh.GameServer.Endpoints.ApiV3.ApiTypes;
using Refresh.GameServer.Endpoints.ApiV3.ApiTypes.Errors;
Expand All @@ -13,7 +14,7 @@ namespace Refresh.GameServer.Endpoints.ApiV3.Admin;

public class AdminLevelApiEndpoints : EndpointGroup
{
[ApiV3Endpoint("admin/levels/id/{id}/teamPick", Method.Post), MinimumRole(GameUserRole.Admin)]
[ApiV3Endpoint("admin/levels/id/{id}/teamPick", HttpMethods.Post), MinimumRole(GameUserRole.Admin)]
[DocSummary("Marks a level as team picked.")]
[DocError(typeof(ApiNotFoundError), ApiNotFoundError.LevelMissingErrorWhen)]
public ApiOkResponse AddTeamPickToLevel(RequestContext context, GameDatabaseContext database, GameUser user, int id)
Expand All @@ -26,7 +27,7 @@ public ApiOkResponse AddTeamPickToLevel(RequestContext context, GameDatabaseCont
return new ApiOkResponse();
}

[ApiV3Endpoint("admin/levels/id/{id}/removeTeamPick", Method.Post), MinimumRole(GameUserRole.Admin)]
[ApiV3Endpoint("admin/levels/id/{id}/removeTeamPick", HttpMethods.Post), MinimumRole(GameUserRole.Admin)]
[DocSummary("Removes a level's team pick status.")]
[DocError(typeof(ApiNotFoundError), ApiNotFoundError.LevelMissingErrorWhen)]
public ApiOkResponse RemoveTeamPickFromLevel(RequestContext context, GameDatabaseContext database, int id)
Expand All @@ -38,7 +39,7 @@ public ApiOkResponse RemoveTeamPickFromLevel(RequestContext context, GameDatabas
return new ApiOkResponse();
}

[ApiV3Endpoint("admin/levels/id/{id}", Method.Delete), MinimumRole(GameUserRole.Admin)]
[ApiV3Endpoint("admin/levels/id/{id}", HttpMethods.Delete), MinimumRole(GameUserRole.Admin)]
[DocSummary("Deletes a level.")]
[DocError(typeof(ApiNotFoundError), ApiNotFoundError.LevelMissingErrorWhen)]
public ApiOkResponse DeleteLevel(RequestContext context, GameDatabaseContext database, int id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using AttribDoc.Attributes;
using Bunkum.CustomHttpListener.Parsing;
using Bunkum.HttpServer;
using Bunkum.HttpServer.Endpoints;
using Bunkum.Core;
using Bunkum.Core.Endpoints;
using Bunkum.Listener.Protocol;
using Bunkum.Protocols.Http;
using MongoDB.Bson;
using Refresh.GameServer.Database;
using Refresh.GameServer.Endpoints.ApiV3.ApiTypes;
Expand Down Expand Up @@ -35,7 +36,7 @@ public ApiResponse<ApiAdminQueuedRegistrationResponse> GetQueuedRegistrationByUu
return ApiAdminQueuedRegistrationResponse.FromOld(registration);
}

[ApiV3Endpoint("admin/registrations/{uuid}", Method.Delete), MinimumRole(GameUserRole.Admin)]
[ApiV3Endpoint("admin/registrations/{uuid}", HttpMethods.Delete), MinimumRole(GameUserRole.Admin)]
[DocSummary("Deletes a registration by its UUID.")]
[DocError(typeof(ApiValidationError), ApiValidationError.ObjectIdParseErrorWhen)]
[DocError(typeof(ApiNotFoundError), "The registration could not be found")]
Expand All @@ -51,7 +52,7 @@ public ApiOkResponse DeleteQueuedRegistrationByUuid(RequestContext context, Game
return new ApiOkResponse();
}

[ApiV3Endpoint("admin/registrations", Method.Delete), MinimumRole(GameUserRole.Admin)]
[ApiV3Endpoint("admin/registrations", HttpMethods.Delete), MinimumRole(GameUserRole.Admin)]
[DocSummary("Clears all queued registrations from the server.")]
public ApiOkResponse DeleteAllQueuedRegistrations(RequestContext context, GameDatabaseContext database)
{
Expand Down
19 changes: 10 additions & 9 deletions Refresh.GameServer/Endpoints/ApiV3/Admin/AdminUserApiEndpoints.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using AttribDoc.Attributes;
using Bunkum.CustomHttpListener.Parsing;
using Bunkum.HttpServer;
using Bunkum.HttpServer.Endpoints;
using Bunkum.Core;
using Bunkum.Core.Endpoints;
using Bunkum.Listener.Protocol;
using Bunkum.Protocols.Http;
using Refresh.GameServer.Database;
using Refresh.GameServer.Documentation.Attributes;
using Refresh.GameServer.Endpoints.ApiV3.ApiTypes;
Expand Down Expand Up @@ -61,7 +62,7 @@ private static ApiOkResponse ResetUserPassword(GameDatabaseContext database, Api
return new ApiOkResponse();
}

[ApiV3Endpoint("admin/users/uuid/{uuid}/resetPassword", Method.Put), MinimumRole(GameUserRole.Admin)]
[ApiV3Endpoint("admin/users/uuid/{uuid}/resetPassword", HttpMethods.Put), MinimumRole(GameUserRole.Admin)]
[DocSummary("Reset's a user password by their UUID.")]
[DocError(typeof(ApiNotFoundError), ApiNotFoundError.UserMissingErrorWhen)]
[DocRequestBody(typeof(ApiResetUserPasswordRequest))]
Expand All @@ -73,7 +74,7 @@ public ApiOkResponse ResetUserPasswordByUuid(RequestContext context, GameDatabas
return ResetUserPassword(database, body, user);
}

[ApiV3Endpoint("admin/users/name/{username}/resetPassword", Method.Put), MinimumRole(GameUserRole.Admin)]
[ApiV3Endpoint("admin/users/name/{username}/resetPassword", HttpMethods.Put), MinimumRole(GameUserRole.Admin)]
[DocSummary("Reset's a user password by their username.")]
[DocError(typeof(ApiNotFoundError), ApiNotFoundError.UserMissingErrorWhen)]
[DocRequestBody(typeof(ApiResetUserPasswordRequest))]
Expand Down Expand Up @@ -117,7 +118,7 @@ public ApiResponse<ApiAdminUserPlanetsResponse> GetUserPlanetsByUsername(Request
};
}

[ApiV3Endpoint("admin/users/uuid/{uuid}/planets", Method.Delete), MinimumRole(GameUserRole.Admin)]
[ApiV3Endpoint("admin/users/uuid/{uuid}/planets", HttpMethods.Delete), MinimumRole(GameUserRole.Admin)]
[DocSummary("Resets a user's planets. Gets user by their UUID.")]
[DocError(typeof(ApiNotFoundError), ApiNotFoundError.UserMissingErrorWhen)]
public ApiOkResponse ResetUserPlanetsByUuid(RequestContext context, GameDatabaseContext database, string uuid)
Expand All @@ -129,7 +130,7 @@ public ApiOkResponse ResetUserPlanetsByUuid(RequestContext context, GameDatabase
return new ApiOkResponse();
}

[ApiV3Endpoint("admin/users/name/{username}/planets", Method.Delete), MinimumRole(GameUserRole.Admin)]
[ApiV3Endpoint("admin/users/name/{username}/planets", HttpMethods.Delete), MinimumRole(GameUserRole.Admin)]
[DocSummary("Resets a user's planets. Gets user by their username.")]
[DocError(typeof(ApiNotFoundError), ApiNotFoundError.UserMissingErrorWhen)]
public ApiOkResponse ResetUserPlanetsByUsername(RequestContext context, GameDatabaseContext database, string username)
Expand All @@ -141,7 +142,7 @@ public ApiOkResponse ResetUserPlanetsByUsername(RequestContext context, GameData
return new ApiOkResponse();
}

[ApiV3Endpoint("admin/users/uuid/{uuid}", Method.Delete), MinimumRole(GameUserRole.Admin)]
[ApiV3Endpoint("admin/users/uuid/{uuid}", HttpMethods.Delete), MinimumRole(GameUserRole.Admin)]
[DocSummary("Deletes a user user by their UUID.")]
[DocError(typeof(ApiNotFoundError), ApiNotFoundError.UserMissingErrorWhen)]
public ApiOkResponse DeleteUserByUuid(RequestContext context, GameDatabaseContext database, string uuid)
Expand All @@ -153,7 +154,7 @@ public ApiOkResponse DeleteUserByUuid(RequestContext context, GameDatabaseContex
return new ApiOkResponse();
}

[ApiV3Endpoint("admin/users/name/{username}", Method.Delete), MinimumRole(GameUserRole.Admin)]
[ApiV3Endpoint("admin/users/name/{username}", HttpMethods.Delete), MinimumRole(GameUserRole.Admin)]
[DocSummary("Deletes a user user by their UUID.")]
[DocError(typeof(ApiNotFoundError), ApiNotFoundError.UserMissingErrorWhen)]
public ApiOkResponse DeleteUserByUsername(RequestContext context, GameDatabaseContext database, string username)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using AttribDoc.Attributes;
using Bunkum.CustomHttpListener.Parsing;
using Bunkum.HttpServer;
using Bunkum.HttpServer.Endpoints;
using Bunkum.Core;
using Bunkum.Core.Endpoints;
using Bunkum.Protocols.Http;
using Refresh.GameServer.Database;
using Refresh.GameServer.Endpoints.ApiV3.ApiTypes;
using Refresh.GameServer.Endpoints.ApiV3.ApiTypes.Errors;
Expand Down Expand Up @@ -37,41 +37,41 @@ private static ApiOkResponse PardonUser(GameUser? user, GameDatabaseContext data
return new ApiOkResponse();
}

[ApiV3Endpoint("admin/users/name/{username}/ban", Method.Post), MinimumRole(GameUserRole.Admin)]
[ApiV3Endpoint("admin/users/name/{username}/ban", HttpMethods.Post), MinimumRole(GameUserRole.Admin)]
[DocSummary("Bans a user for the specified reason until the given date.")]
[DocError(typeof(ApiNotFoundError), ApiNotFoundError.UserMissingErrorWhen)]
[DocRequestBody(typeof(ApiPunishUserRequest))]
public ApiOkResponse BanByUsername(RequestContext context, GameDatabaseContext database, string username, ApiPunishUserRequest body)
=> BanUser(database.GetUserByUsername(username), database, body);

[ApiV3Endpoint("admin/users/uuid/{uuid}/ban", Method.Post), MinimumRole(GameUserRole.Admin)]
[ApiV3Endpoint("admin/users/uuid/{uuid}/ban", HttpMethods.Post), MinimumRole(GameUserRole.Admin)]
[DocSummary("Bans a user for the specified reason until the given date.")]
[DocError(typeof(ApiNotFoundError), ApiNotFoundError.UserMissingErrorWhen)]
[DocRequestBody(typeof(ApiPunishUserRequest))]
public ApiOkResponse BanByUuid(RequestContext context, GameDatabaseContext database, string uuid, ApiPunishUserRequest body)
=> BanUser(database.GetUserByUuid(uuid), database, body);

[ApiV3Endpoint("admin/users/name/{username}/restrict", Method.Post), MinimumRole(GameUserRole.Admin)]
[ApiV3Endpoint("admin/users/name/{username}/restrict", HttpMethods.Post), MinimumRole(GameUserRole.Admin)]
[DocSummary("Restricts a user for the specified reason until the given date.")]
[DocError(typeof(ApiNotFoundError), ApiNotFoundError.UserMissingErrorWhen)]
[DocRequestBody(typeof(ApiPunishUserRequest))]
public ApiOkResponse RestrictByUsername(RequestContext context, GameDatabaseContext database, string username, ApiPunishUserRequest body)
=> RestrictUser(database.GetUserByUsername(username), database, body);

[ApiV3Endpoint("admin/users/uuid/{uuid}/restrict", Method.Post), MinimumRole(GameUserRole.Admin)]
[ApiV3Endpoint("admin/users/uuid/{uuid}/restrict", HttpMethods.Post), MinimumRole(GameUserRole.Admin)]
[DocSummary("Restricts a user for the specified reason until the given date.")]
[DocError(typeof(ApiNotFoundError), ApiNotFoundError.UserMissingErrorWhen)]
[DocRequestBody(typeof(ApiPunishUserRequest))]
public ApiOkResponse RestrictByUuid(RequestContext context, GameDatabaseContext database, string uuid, ApiPunishUserRequest body)
=> RestrictUser(database.GetUserByUuid(uuid), database, body);

[ApiV3Endpoint("admin/users/name/{username}/pardon", Method.Post), MinimumRole(GameUserRole.Admin)]
[ApiV3Endpoint("admin/users/name/{username}/pardon", HttpMethods.Post), MinimumRole(GameUserRole.Admin)]
[DocSummary("Pardons all punishments for the given user.")]
[DocError(typeof(ApiNotFoundError), ApiNotFoundError.UserMissingErrorWhen)]
public ApiOkResponse PardonByUsername(RequestContext context, GameDatabaseContext database, string username)
=> PardonUser(database.GetUserByUsername(username), database);

[ApiV3Endpoint("admin/users/uuid/{uuid}/pardon", Method.Post), MinimumRole(GameUserRole.Admin)]
[ApiV3Endpoint("admin/users/uuid/{uuid}/pardon", HttpMethods.Post), MinimumRole(GameUserRole.Admin)]
[DocSummary("Pardons all punishments for the given user.")]
[DocError(typeof(ApiNotFoundError), ApiNotFoundError.UserMissingErrorWhen)]
public ApiOkResponse PardonByUuid(RequestContext context, GameDatabaseContext database, string uuid)
Expand Down
5 changes: 3 additions & 2 deletions Refresh.GameServer/Endpoints/ApiV3/ApiTypes/ApiError.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Net;
using Bunkum.CustomHttpListener.Parsing;
using Bunkum.Core.Responses;
using Bunkum.Listener.Protocol;

namespace Refresh.GameServer.Endpoints.ApiV3.ApiTypes;

Expand Down Expand Up @@ -31,6 +32,6 @@ public ApiError(string message, HttpStatusCode code = BadRequest)
/// </summary>
public HttpStatusCode StatusCode { get; set; }

public static implicit operator Bunkum.HttpServer.Responses.Response(ApiError error)
public static implicit operator Response(ApiError error)
=> new(error, ContentType.Json, error.StatusCode);
}
2 changes: 1 addition & 1 deletion Refresh.GameServer/Endpoints/ApiV3/ApiTypes/ApiResponse.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Net;
using Bunkum.HttpServer.Responses;
using Bunkum.Core.Responses;

namespace Refresh.GameServer.Endpoints.ApiV3.ApiTypes;

Expand Down
Loading

0 comments on commit e7a5a02

Please sign in to comment.