Skip to content

Commit 68e23bb

Browse files
authored
Merge branch 'LittleBigRefresh:main' into email-domain
2 parents f6c0a00 + ef7a165 commit 68e23bb

29 files changed

Lines changed: 363 additions & 60 deletions

Refresh.Core/Configuration/GameServerConfig.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Refresh.Core.Configuration;
1010
[SuppressMessage("ReSharper", "RedundantDefaultMemberInitializer")]
1111
public class GameServerConfig : Config
1212
{
13-
public override int CurrentConfigVersion => 25;
13+
public override int CurrentConfigVersion => 26;
1414
public override int Version { get; set; } = 0;
1515

1616
protected override void Migrate(int oldVer, dynamic oldConfig)
@@ -117,6 +117,11 @@ protected override void Migrate(int oldVer, dynamic oldConfig)
117117
/// </summary>
118118
public bool PrintRoomStateWhenNoFoundRooms { get; set; } = true;
119119

120+
/// <summary>
121+
/// Whether to unconditionally print data like token, token owner, remote IP, request URI etc during authentication outside of exceptions
122+
/// </summary>
123+
public bool PrintAuthenticationData { get; set; } = false;
124+
120125
public string[] Sha1DigestKeys = ["CustomServerDigest"];
121126
public string[] HmacDigestKeys = ["CustomServerDigest"];
122127

Refresh.Core/RateLimits/Levels/SingleLevelEndpointLimits.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public static class SingleLevelEndpointLimits
44
{
55
public const int TimeoutDuration = 300;
66
public const int ApiRequestAmount = 50;
7-
public const int GameRequestAmount = 170; // Game likes to request them a lot
7+
public const int GameRequestAmount = 280; // Game likes to request them a lot
88
public const int BlockDuration = 240;
99
public const string ApiRequestBucket = "single-level-api";
1010
public const string GameRequestBucket = "single-level-game";

Refresh.Core/RateLimits/Presence/GamePresenceEndpointLimits.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace Refresh.Core.RateLimits.Presence;
55
/// </summary>
66
public static class GamePresenceEndpointLimits
77
{
8-
public const int TimeoutDuration = 450;
9-
public const int RequestAmount = 30;
10-
public const int BlockDuration = 300;
8+
public const int TimeoutDuration = 300;
9+
public const int RequestAmount = 80;
10+
public const int BlockDuration = 240;
1111
public const string RequestBucket = "game-presence";
1212
}

Refresh.Core/RateLimits/Relations/PlayLevelEndpointLimits.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace Refresh.Core.RateLimits.Relations;
33
public static class PlayLevelEndpointLimits
44
{
55
public const int TimeoutDuration = 300;
6-
public const int RequestAmount = 20;
6+
public const int RequestAmount = 40;
77
public const int BlockDuration = 240;
88
public const string RequestBucket = "play-level";
99
}

Refresh.Core/RateLimits/Users/NotificationsEndpointLimits.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace Refresh.Core.RateLimits.Users;
33
public static class NotificationsEndpointLimits
44
{
55
public const int TimeoutDuration = 180;
6-
public const int GameRequestAmount = 4;
6+
public const int GameRequestAmount = 8;
77
public const int ApiRequestAmount = 20;
88
public const int BlockDuration = 150;
99
public const string GameRequestBucket = "notifications-game";

Refresh.Core/Services/CacheService.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ public override void Initialize()
5353

5454
// periodically automatically remove expired data if it hasn't been removed somehow else before,
5555
// to not keep unused data for a potentially undefined time
56-
Thread expirationThread = new(() =>
56+
Task expirationTask = new(async () =>
5757
{
5858
while(true)
5959
{
60-
Thread.Sleep(1000 * 60 * 2);
60+
await Task.Delay(1000 * 60 * 2);
6161
this.RemoveExpiredCache();
6262
}
6363
});
64-
expirationThread.Start();
64+
65+
expirationTask.Start();
6566
}
6667

6768
private void RemoveExpiredCache()

Refresh.Database/GameDatabaseContext.Tokens.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public Token GenerateTokenForUser(GameUser user, TokenType type, TokenGame game,
9090
#if DEBUG
9191
if(Debugger.IsAttached) Debugger.Break();
9292
#endif
93-
throw new InvalidDataException($"GetTokenFromTokenData - Token data or type does not match!");
93+
throw new InvalidDataException($"GetTokenFromTokenData - Token data or type does not match (expected {tokenData} | {type}, got {token.TokenData} | {token.TokenType} by {token.User})!");
9494
}
9595

9696
return token;

Refresh.GameServer/Authentication/GameAuthenticationProvider.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,16 @@ public GameAuthenticationProvider(GameServerConfig? config, Logger logger)
7676
if ((this._config?.MaintenanceMode ?? false) && user.Role != GameUserRole.Admin)
7777
return null;
7878

79+
if (this._config?.PrintAuthenticationData ?? false)
80+
this._logger.LogInfo(BunkumCategory.Authentication, $"Authenticating request from {request.RemoteEndpoint} to {request.Uri.AbsolutePath} by {user} using token {tokenData}");
81+
7982
// Additional validation of the token gotten from DB. Exceptions will be caught, logged and InternalServerError will be returned automatically.
8083
if (token.TokenData != tokenData)
8184
{
8285
#if DEBUG
8386
if(Debugger.IsAttached) Debugger.Break();
8487
#endif
85-
throw new InvalidDataException($"{typeof(GameAuthenticationProvider)} - Token from DB does not match token received from client!");
88+
throw new InvalidDataException($"{typeof(GameAuthenticationProvider)} - Token from DB ({token.TokenData}) does not match token received from client ({tokenData})!");
8689
}
8790

8891
if (token.User.UserId != token.UserId)

Refresh.Interfaces.APIv3/Endpoints/ApiTypes/Errors/ApiAuthenticationError.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ public class ApiAuthenticationError : ApiError
99
public const string NoPermissionsForCreationWhen = "You lack the permissions to create this type of resource.";
1010
public static readonly ApiAuthenticationError NoPermissionsForCreation = new(NoPermissionsForCreationWhen);
1111

12+
public const string ReadOnlyErrorWhen = "The server is currently in read-only mode.";
13+
public static readonly ApiAuthenticationError ReadOnlyError = new(ReadOnlyErrorWhen);
14+
1215
public const string NotAuthenticatedWhen = "You are not authenticated.";
1316
public static readonly ApiAuthenticationError NotAuthenticated = new(NotAuthenticatedWhen);
1417

Refresh.Interfaces.APIv3/Endpoints/AuthenticationApiEndpoints.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,15 @@ public ApiOkResponse ResendVerificationCode(RequestContext context, GameUser use
425425
}
426426

427427
[ApiV3Endpoint("users/me", HttpMethods.Delete), MinimumRole(GameUserRole.Restricted)]
428-
[DocSummary("Deletes your own account. This action is non-reversible.")]
429-
public ApiOkResponse DeleteMyAccount(RequestContext context, GameUser user, GameDatabaseContext database)
428+
[DocSummary("Deletes your own account. This action is non-reversible. This endpoint now requires you to include your own password while being authenticated.")]
429+
public ApiOkResponse DeleteMyAccount(RequestContext context, GameUser user, ApiOwnUserDeletionRequest body, GameDatabaseContext database)
430430
{
431+
if (string.IsNullOrWhiteSpace(body.PasswordSha512))
432+
return new ApiValidationError("You must enter your password to delete your account.");
433+
434+
if (!BC.Verify(body.PasswordSha512, user.PasswordBcrypt))
435+
return new ApiValidationError("The password was incorrect.");
436+
431437
database.DeleteUser(user);
432438
return new ApiOkResponse();
433439
}

0 commit comments

Comments
 (0)