diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs index 7e3baeb9..3eb709ed 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs @@ -22,6 +22,8 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers; public class CommentController : ControllerBase { private readonly DatabaseContext database; + + private static readonly bool emailEnforcementEnabled = EnforceEmailConfiguration.Instance.EnableEmailEnforcement; public CommentController(DatabaseContext database) { this.database = database; @@ -33,9 +35,13 @@ public class CommentController : ControllerBase { GameTokenEntity token = this.GetToken(); + UserEntity? user = await this.database.UserFromGameToken(token); + // Return bad request if both are true or both are false if ((slotId == 0 || SlotHelper.IsTypeInvalid(slotType)) == (username == null)) return this.BadRequest(); + if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest(); + bool success = await this.database.RateComment(token.UserId, commentId, rating); if (!success) return this.BadRequest(); @@ -53,6 +59,8 @@ public class CommentController : ControllerBase if ((slotId == 0 || SlotHelper.IsTypeInvalid(slotType)) == (username == null)) return this.BadRequest(); + if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest(); + int originalSlotId = slotId; if (slotType == "developer") slotId = await SlotHelper.GetPlaceholderSlotId(this.database, slotId, SlotType.Developer); @@ -117,9 +125,13 @@ public class CommentController : ControllerBase { GameTokenEntity token = this.GetToken(); + UserEntity? user = await this.database.UserFromGameToken(token); + // Deny request if in read-only mode if (ServerConfiguration.Instance.UserGeneratedContentLimits.ReadOnlyMode) return this.BadRequest(); + if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest(); + GameComment? comment = await this.DeserializeBody(); if (comment?.Message == null) return this.BadRequest(); @@ -156,11 +168,15 @@ public class CommentController : ControllerBase { GameTokenEntity token = this.GetToken(); + UserEntity? user = await this.database.UserFromGameToken(token); + // Deny request if in read-only mode if (ServerConfiguration.Instance.UserGeneratedContentLimits.ReadOnlyMode) return this.BadRequest(); if ((slotId == 0 || SlotHelper.IsTypeInvalid(slotType)) == (username == null)) return this.BadRequest(); + if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest(); + CommentEntity? comment = await this.database.Comments.FirstOrDefaultAsync(c => c.CommentId == commentId); if (comment == null) return this.NotFound(); diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Matching/EnterLevelController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Matching/EnterLevelController.cs index e8b2aa37..bda3a349 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Matching/EnterLevelController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Matching/EnterLevelController.cs @@ -1,9 +1,13 @@ #nullable enable +using System.Runtime.CompilerServices; using LBPUnion.ProjectLighthouse.Database; using LBPUnion.ProjectLighthouse.Extensions; using LBPUnion.ProjectLighthouse.Helpers; +using LBPUnion.ProjectLighthouse.Configuration; +using LBPUnion.ProjectLighthouse.Migrations; using LBPUnion.ProjectLighthouse.Types.Entities.Interaction; using LBPUnion.ProjectLighthouse.Types.Entities.Level; +using LBPUnion.ProjectLighthouse.Types.Entities.Profile; using LBPUnion.ProjectLighthouse.Types.Entities.Token; using LBPUnion.ProjectLighthouse.Types.Users; using Microsoft.AspNetCore.Authorization; @@ -20,6 +24,8 @@ public class EnterLevelController : ControllerBase { private readonly DatabaseContext database; + private static readonly bool emailEnforcementEnabled = EnforceEmailConfiguration.Instance.EnableEmailEnforcement; + public EnterLevelController(DatabaseContext database) { this.database = database; @@ -30,8 +36,13 @@ public class EnterLevelController : ControllerBase { GameTokenEntity token = this.GetToken(); + UserEntity? user = await this.database.UserFromGameToken(token); + if (SlotHelper.IsTypeInvalid(slotType)) return this.BadRequest(); + // Return bad request on unverified email if enforcement is enabled + if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest(); + // don't count plays for developer slots if (slotType == "developer") return this.Ok(); @@ -100,8 +111,13 @@ public class EnterLevelController : ControllerBase { GameTokenEntity token = this.GetToken(); + UserEntity? user = await this.database.UserFromGameToken(token); + if (SlotHelper.IsTypeInvalid(slotType)) return this.BadRequest(); + // Return bad request on unverified email if enforcement is enabled + if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest(); + if (slotType == "developer") return this.Ok(); SlotEntity? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == slotId); diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Matching/MatchController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Matching/MatchController.cs index 2b3b295b..59703116 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Matching/MatchController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Matching/MatchController.cs @@ -25,6 +25,8 @@ public class MatchController : ControllerBase { private readonly DatabaseContext database; + private static readonly bool emailEnforcementEnabled = EnforceEmailConfiguration.Instance.EnableEmailEnforcement; + public MatchController(DatabaseContext database) { this.database = database; @@ -43,6 +45,8 @@ public class MatchController : ControllerBase UserEntity? user = await this.database.UserFromGameToken(token); if (user == null) return this.Forbid(); + if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest(); + await LastContactHelper.SetLastContact(this.database, user, token.GameVersion, token.Platform); // Do not allow matchmaking if it has been disabled