Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Refresh.Core/Configuration/GameServerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Refresh.Core.Configuration;
[SuppressMessage("ReSharper", "RedundantDefaultMemberInitializer")]
public class GameServerConfig : Config
{
public override int CurrentConfigVersion => 25;
public override int CurrentConfigVersion => 26;
public override int Version { get; set; } = 0;

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

/// <summary>
/// Whether to unconditionally print data like token, token owner, remote IP, request URI etc during authentication outside of exceptions
/// </summary>
public bool PrintAuthenticationData { get; set; } = false;

public string[] Sha1DigestKeys = ["CustomServerDigest"];
public string[] HmacDigestKeys = ["CustomServerDigest"];

Expand Down
2 changes: 1 addition & 1 deletion Refresh.Database/GameDatabaseContext.Tokens.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public Token GenerateTokenForUser(GameUser user, TokenType type, TokenGame game,
#if DEBUG
if(Debugger.IsAttached) Debugger.Break();
#endif
throw new InvalidDataException($"GetTokenFromTokenData - Token data or type does not match!");
throw new InvalidDataException($"GetTokenFromTokenData - Token data or type does not match (expected {tokenData} | {type}, got {token.TokenData} | {token.TokenType} by {token.User})!");
}

return token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ public GameAuthenticationProvider(GameServerConfig? config, Logger logger)
if ((this._config?.MaintenanceMode ?? false) && user.Role != GameUserRole.Admin)
return null;

if (this._config?.PrintAuthenticationData ?? false)
this._logger.LogInfo(BunkumCategory.Authentication, $"Authenticating request from {request.RemoteEndpoint} to {request.Uri.AbsolutePath} by {user} using token {tokenData}");

// Additional validation of the token gotten from DB. Exceptions will be caught, logged and InternalServerError will be returned automatically.
if (token.TokenData != tokenData)
{
#if DEBUG
if(Debugger.IsAttached) Debugger.Break();
#endif
throw new InvalidDataException($"{typeof(GameAuthenticationProvider)} - Token from DB does not match token received from client!");
throw new InvalidDataException($"{typeof(GameAuthenticationProvider)} - Token from DB ({token.TokenData}) does not match token received from client ({tokenData})!");
}

if (token.User.UserId != token.UserId)
Expand Down
Loading