Skip to content

Commit

Permalink
feat: use sealed classes for event and packet handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu1537 committed Dec 11, 2024
1 parent af46df4 commit 2b8b5c4
Show file tree
Hide file tree
Showing 34 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion WFDS.Server/Controllers/ActorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace WFDS.Server.Controllers;
[ApiController]
[Tags("actor")]
[Route("api/v1/actor")]
public class ActorController(IActorManager manager) : Controller
public sealed class ActorController(IActorManager manager) : Controller
{
[HttpGet("list")]
public IActionResult GetActors()
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/Controllers/ChalkController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace WFDS.Server.Controllers;
[ApiController]
[Route("api/v1/chalk")]
[Tags("chalk")]
public class ChalkController(ICanvasManager canvas) : Controller
public sealed class ChalkController(ICanvasManager canvas) : ControllerBase
{
[HttpDelete]
[SwaggerOperation("clear all chalk")]
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/Controllers/EventController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace WFDS.Server.Controllers;
[ApiController]
[Tags("event")]
[Route("api/v1/event")]
public class EventController(IActorSpawnManager manager) : Controller
public sealed class EventController(IActorSpawnManager manager) : Controller
{
[HttpPost("bird")]
[SwaggerOperation("spawn ambient bird actor")]
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/Controllers/ServerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace WFDS.Server.Controllers;
[ApiController]
[Tags("server")]
[Route("api/v1/server")]
public class ServerController(IHostApplicationLifetime lifetime) : Controller
public sealed class ServerController(IHostApplicationLifetime lifetime) : Controller
{
[HttpGet("status")]
public IActionResult GetStatus()
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/Controllers/SessionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace WFDS.Server.Controllers;
[Tags("session")]
[Route("api/v1/session")]

public class SessionController(SessionManager manager, LobbyManager lobby) : Controller
public sealed class SessionController(SessionManager manager, LobbyManager lobby) : Controller
{
[HttpGet("info")]
[SwaggerOperation("get lobby info")]
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/Core/Chalk/Canvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace WFDS.Server.Core.Chalk;

public class Canvas
public sealed class Canvas
{
public long CanvasId { get; init; }
private Dictionary<(int, int), long> Data { get; } = [];
Expand Down
6 changes: 3 additions & 3 deletions WFDS.Server/Core/WebExceptionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace WFDS.Server.Core;

public class WebExceptionHandler : IExceptionHandler
public sealed class WebExceptionHandler : IExceptionHandler
{
public async ValueTask<bool> TryHandleAsync(HttpContext httpContext, Exception ex, CancellationToken cancellationToken)
public async ValueTask<bool> TryHandleAsync(HttpContext httpContext, Exception exception, CancellationToken cancellationToken)
{
httpContext.Response.StatusCode = 500 ;
await httpContext.Response.WriteAsJsonAsync(new
{
error = ex.Message
error = exception.Message
}, cancellationToken);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/EventHandler/ActorCreateBroadcast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace WFDS.Server.EventHandler;

public class ActorCreateBroadcast(IActorManager actorManager, SessionManager sessionManager, LobbyManager lobby, SteamManager steam) : GameEventHandler<ActorCreateEvent>
public sealed class ActorCreateBroadcast(IActorManager actorManager, SessionManager sessionManager, LobbyManager lobby, SteamManager steam) : GameEventHandler<ActorCreateEvent>
{
protected override void Handle(ActorCreateEvent e)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/EventHandler/ActorRemoveBroadcast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace WFDS.Server.EventHandler;

public class ActorRemoveBroadcast(SessionManager sessionManager, LobbyManager lobby, SteamManager steam) : GameEventHandler<ActorRemoveEvent>
public sealed class ActorRemoveBroadcast(SessionManager sessionManager, LobbyManager lobby, SteamManager steam) : GameEventHandler<ActorRemoveEvent>
{
protected override void Handle(ActorRemoveEvent e)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/EventHandler/AddPlayerToDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace WFDS.Server.EventHandler;

public class AddPlayerToDb(DatabaseContext dbContext) : GameEventHandler<PlayerJoinedEvent>
public sealed class AddPlayerToDb(DatabaseContext dbContext) : GameEventHandler<PlayerJoinedEvent>
{
protected override void Handle(PlayerJoinedEvent e)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/EventHandler/CleanupLeavePlayerActors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace WFDS.Server.EventHandler;

public class CleanupLeavePlayerActors(ILogger<CleanupLeavePlayerActors> logger, IActorManager actorManager) : GameEventHandler<PlayerLeaveEvent>
public sealed class CleanupLeavePlayerActors(ILogger<CleanupLeavePlayerActors> logger, IActorManager actorManager) : GameEventHandler<PlayerLeaveEvent>
{
protected override void Handle(PlayerLeaveEvent e)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/EventHandler/LoadBanListFromDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace WFDS.Server.EventHandler;

public class LoadBanListFromDb(ILogger<LoadBanListFromDb> logger, DatabaseContext dbContext, SessionManager sessionManager) : GameEventHandler<LobbyCreatedEvent>
public sealed class LoadBanListFromDb(ILogger<LoadBanListFromDb> logger, DatabaseContext dbContext, SessionManager sessionManager) : GameEventHandler<LobbyCreatedEvent>
{
protected override void Handle(LobbyCreatedEvent e)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/EventHandler/PlayerJoinUpdateTitle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace WFDS.Server.EventHandler;

public class PlayerJoinUpdateTitle(LobbyManager lobby, SessionManager session) : GameEventHandler<PlayerJoinedEvent>
public sealed class PlayerJoinUpdateTitle(LobbyManager lobby, SessionManager session) : GameEventHandler<PlayerJoinedEvent>
{
protected override void Handle(PlayerJoinedEvent e)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/EventHandler/PlayerLeaveUpdateTitle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace WFDS.Server.EventHandler;

public class PlayerLeaveUpdateTitle(LobbyManager lobby, SessionManager session) : GameEventHandler<PlayerLeaveEvent>
public sealed class PlayerLeaveUpdateTitle(LobbyManager lobby, SessionManager session) : GameEventHandler<PlayerLeaveEvent>
{
protected override void Handle(PlayerLeaveEvent e)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/EventHandler/RainCloudInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace WFDS.Server.EventHandler;

public class RainCloudInitializer(IActorManager actorManager) : GameEventHandler<ActorCreateEvent>
public sealed class RainCloudInitializer(IActorManager actorManager) : GameEventHandler<ActorCreateEvent>
{
protected override void Handle(ActorCreateEvent e)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/EventHandler/RainCloudMove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace WFDS.Server.EventHandler;

public class RainCloudMove(IActorManager actorManager) : GameEventHandler<ActorTickEvent>
public sealed class RainCloudMove(IActorManager actorManager) : GameEventHandler<ActorTickEvent>
{
protected override void Handle(ActorTickEvent e)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/EventHandler/RemoveAmbientBirdNearPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace WFDS.Server.EventHandler;

public class RemoveAmbientBirdNearPlayer(ILogger<RemoveAmbientBirdNearPlayer> logger, IActorManager actorManager) : GameEventHandler<ActorTickEvent>
public sealed class RemoveAmbientBirdNearPlayer(ILogger<RemoveAmbientBirdNearPlayer> logger, IActorManager actorManager) : GameEventHandler<ActorTickEvent>
{
protected override void Handle(ActorTickEvent e)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/EventHandler/RemovePlayerFromBannedPlayers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace WFDS.Server.EventHandler;

public class RemovePlayerFromBannedPlayers(ILogger<RemovePlayerFromBannedPlayers> logger, DatabaseContext dbContext) : GameEventHandler<PlayerUnBanEvent>
public sealed class RemovePlayerFromBannedPlayers(ILogger<RemovePlayerFromBannedPlayers> logger, DatabaseContext dbContext) : GameEventHandler<PlayerUnBanEvent>
{
protected override void Handle(PlayerUnBanEvent e)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/EventHandler/UpdateActorTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace WFDS.Server.EventHandler;

public class UpdateActorTransform(IActorManager actorManager) : GameEventHandler<ActorTransformUpdateEvent>
public sealed class UpdateActorTransform(IActorManager actorManager) : GameEventHandler<ActorTransformUpdateEvent>
{
protected override void Handle(ActorTransformUpdateEvent e)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/EventHandler/UpdateActorZone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace WFDS.Server.EventHandler;

public class UpdateActorZone(IActorManager actorManager) : GameEventHandler<ActorZoneUpdateEvent>
public sealed class UpdateActorZone(IActorManager actorManager) : GameEventHandler<ActorZoneUpdateEvent>
{
protected override void Handle(ActorZoneUpdateEvent e)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/EventHandler/UpdateBannedPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace WFDS.Server.EventHandler;

public class UpdateBannedPlayer(DatabaseContext dbContext, ILogger<UpdateBannedPlayer> logger) : GameEventHandler<PlayerBanEvent>
public sealed class UpdateBannedPlayer(DatabaseContext dbContext, ILogger<UpdateBannedPlayer> logger) : GameEventHandler<PlayerBanEvent>
{
protected override void Handle(PlayerBanEvent e)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/EventHandler/UpdatePlayerCosmetics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace WFDS.Server.EventHandler;

public class UpdatePlayerCosmetics(IActorManager actorManager) : GameEventHandler<PlayerCosmeticsUpdateEvent>
public sealed class UpdatePlayerCosmetics(IActorManager actorManager) : GameEventHandler<PlayerCosmeticsUpdateEvent>
{
protected override void Handle(PlayerCosmeticsUpdateEvent e)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/EventHandler/UpdatePlayerHeldItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace WFDS.Server.EventHandler;

public class UpdatePlayerHeldItem(IActorManager actorManager) : GameEventHandler<PlayerHeldItemUpdateEvent>
public sealed class UpdatePlayerHeldItem(IActorManager actorManager) : GameEventHandler<PlayerHeldItemUpdateEvent>
{
protected override void Handle(PlayerHeldItemUpdateEvent e)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/PacketHandler/ActorActionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace WFDS.Server.PacketHandler;

[PacketType("actor_action")]
public class ActorActionHandler(ILogger<ActorActionHandler> logger, IActorManager actorManager, SteamManager steam) : PacketHandler<ActorActionPacket>
public sealed class ActorActionHandler(ILogger<ActorActionHandler> logger, IActorManager actorManager, SteamManager steam) : PacketHandler<ActorActionPacket>
{
protected override void Handle(Session sender, NetChannel channel, ActorActionPacket packet)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/PacketHandler/ActorRequestSendHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace WFDS.Server.PacketHandler;

[PacketType("actor_request_send")]
public class ActorRequestSendHandler(ILogger<ActorRequestSendHandler> logger, IActorManager actorManager, SessionManager sessionManager) : PacketHandler<ActorRequestSendPacket>
public sealed class ActorRequestSendHandler(ILogger<ActorRequestSendHandler> logger, IActorManager actorManager, SessionManager sessionManager) : PacketHandler<ActorRequestSendPacket>
{
protected override void Handle(Session sender, NetChannel channel, ActorRequestSendPacket packet)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/PacketHandler/ActorUpdateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace WFDS.Server.PacketHandler;

[PacketType("actor_update")]
public class ActorUpdateHandler(IActorManager actorManager) : PacketHandler<ActorUpdatePacket>
public sealed class ActorUpdateHandler(IActorManager actorManager) : PacketHandler<ActorUpdatePacket>
{
protected override void Handle(Session sender, NetChannel channel, ActorUpdatePacket packet)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/PacketHandler/ChalkPacketHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace WFDS.Server.PacketHandler;

[PacketType("chalk_packet")]
public class ChalkPacketHandler(ICanvasManager canvas, LobbyManager lobby, SessionManager session) : PacketHandler<ChalkPacket>
public sealed class ChalkPacketHandler(ICanvasManager canvas, LobbyManager lobby, SessionManager session) : PacketHandler<ChalkPacket>
{
protected override void Handle(Session sender, NetChannel channel, ChalkPacket packet)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/PacketHandler/HandshakeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace WFDS.Server.PacketHandler;

[PacketType("handshake")]
public class HandshakeHandler(ILogger<HandshakeHandler> logger) : PacketHandler<HandshakePacket>
public sealed class HandshakeHandler(ILogger<HandshakeHandler> logger) : PacketHandler<HandshakePacket>
{
protected override void Handle(Session sender, NetChannel channel, HandshakePacket packet)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/PacketHandler/InstanceActorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace WFDS.Server.PacketHandler;

[PacketType("instance_actor")]
public class InstanceActorHandler(ILogger<InstanceActorHandler> logger, IActorManager actorManager, SessionManager sessionManager) : PacketHandler<InstanceActorPacket>
public sealed class InstanceActorHandler(ILogger<InstanceActorHandler> logger, IActorManager actorManager, SessionManager sessionManager) : PacketHandler<InstanceActorPacket>
{
protected override void Handle(Session sender, NetChannel channel, InstanceActorPacket packet)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/PacketHandler/LetterReceivedHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace WFDS.Server.Handlers;

[PacketType("letter_recieved")]
public class LetterReceivedHandler(ILogger<LetterReceivedHandler> logger, SessionManager sessionManager, SteamManager steam) : PacketHandler<LetterReceivedPacket>
public sealed class LetterReceivedHandler(ILogger<LetterReceivedHandler> logger, SessionManager sessionManager, SteamManager steam) : PacketHandler<LetterReceivedPacket>
{
protected override void Handle(Session sender, NetChannel channel, LetterReceivedPacket packet)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/PacketHandler/MessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace WFDS.Server.PacketHandler;

[PacketType("message")]
public class MessageHandler(ILogger<MessageHandler> logger) : PacketHandler<MessagePacket>
public sealed class MessageHandler(ILogger<MessageHandler> logger) : PacketHandler<MessagePacket>
{
protected override void Handle(Session sender, NetChannel channel, MessagePacket packet)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/PacketHandler/NewPlayerJoinHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace WFDS.Server.PacketHandler;

[PacketType("new_player_join")]
public class NewPlayerJoinHandler(ILogger<NewPlayerJoinHandler> logger, ICanvasManager canvas, SessionManager session) : PacketHandler<NewPlayerJoinPacket>
public sealed class NewPlayerJoinHandler(ILogger<NewPlayerJoinHandler> logger, ICanvasManager canvas, SessionManager session) : PacketHandler<NewPlayerJoinPacket>
{
protected override void Handle(Session sender, NetChannel channel, NewPlayerJoinPacket packet)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/PacketHandler/RequestActorsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace WFDS.Server.PacketHandler;

[PacketType("request_actors")]
public class RequestActorsHandler(ILogger<RequestActorsHandler> logger, IActorManager actorManager, SessionManager sessionManager) : PacketHandler<RequestActorsPacket>
public sealed class RequestActorsHandler(ILogger<RequestActorsHandler> logger, IActorManager actorManager, SessionManager sessionManager) : PacketHandler<RequestActorsPacket>
{
protected override void Handle(Session sender, NetChannel channel, RequestActorsPacket _)
{
Expand Down
2 changes: 1 addition & 1 deletion WFDS.Server/PacketHandler/RequestPingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace WFDS.Server.PacketHandler;

[PacketType("request_ping")]
public class RequestPingHandler(SessionManager sessionManager, SteamManager steam) : PacketHandler<RequestPingPacket>
public sealed class RequestPingHandler(SessionManager sessionManager, SteamManager steam) : PacketHandler<RequestPingPacket>
{
protected override void Handle(Session sender, NetChannel channel, RequestPingPacket packet)
{
Expand Down

0 comments on commit 2b8b5c4

Please sign in to comment.