Don't use config option

This commit is contained in:
kuroppoi 2024-01-10 01:39:34 +01:00
parent 774794f751
commit 8e614e0d27
5 changed files with 19 additions and 20 deletions

View File

@ -8,8 +8,7 @@ public record Configuration(
boolean clearPlayerDreamInfoOnWake,
boolean allowOverwritingPlayerDreamInfo,
boolean allowPlayerGameVersionMismatch,
boolean allowWfcRegistrationThroughLogin,
boolean logSensitiveInfo) {
boolean allowWfcRegistrationThroughLogin) {
public static final Configuration DEFAULT = new Configuration("local", true, false, false, true, false);
public static final Configuration DEFAULT = new Configuration("local", true, false, false, true);
}

View File

@ -21,11 +21,14 @@ public class User {
}
public String getFormattedId() {
return getFormattedId(false);
return "%s000".formatted(id).replaceAll("(.{4})(?!$)", "$1-");
}
public String getFormattedId(boolean redact) {
return redact ? "%s-XXXX-XXXX-XXXX".formatted(id.substring(0, 4)) : "%s000".formatted(id).replaceAll("(.{4})(?!$)", "$1-");
/**
* @return The user's id, redacted for logging.
*/
public String getRedactedId() {
return "%s-XXXX-XXXX-XXXX".formatted(id.substring(0, 4));
}
public String getId() {

View File

@ -8,7 +8,6 @@ import java.util.function.Supplier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import entralinked.Configuration;
import entralinked.Entralinked;
import entralinked.model.user.GameProfile;
import entralinked.model.user.ServiceSession;
@ -38,7 +37,6 @@ public class GameSpyHandler extends SimpleChannelInboundHandler<GameSpyRequest>
private static final Logger logger = LogManager.getLogger();
private final SecureRandom secureRandom = new SecureRandom();
private final Configuration configuration;
private final UserManager userManager;
private Channel channel;
private String serverChallenge;
@ -47,7 +45,6 @@ public class GameSpyHandler extends SimpleChannelInboundHandler<GameSpyRequest>
private GameProfile profile;
public GameSpyHandler(Entralinked entralinked) {
this.configuration = entralinked.getConfiguration();
this.userManager = entralinked.getUserManager();
}
@ -65,7 +62,7 @@ public class GameSpyHandler extends SimpleChannelInboundHandler<GameSpyRequest>
@Override
public void channelInactive(ChannelHandlerContext ctx) {
logger.debug("User {} disconnected from GameSpy server", user == null ? null : user.getFormattedId(!configuration.logSensitiveInfo()));
logger.debug("User {} disconnected from GameSpy server", user == null ? null : user.getRedactedId());
// Clear data
serverChallenge = null;
@ -89,7 +86,7 @@ public class GameSpyHandler extends SimpleChannelInboundHandler<GameSpyRequest>
// Handle timeout
if(cause instanceof ReadTimeoutException) {
logger.debug("User {} timed out", user == null ? null : user.getFormattedId(!configuration.logSensitiveInfo()));
logger.debug("User {} timed out", user == null ? null : user.getRedactedId());
return;
}
@ -145,7 +142,7 @@ public class GameSpyHandler extends SimpleChannelInboundHandler<GameSpyRequest>
userManager.saveUser(user); // It's not too big of a deal if this fails for some reason
}
logger.info("User {} logged in with profile {}", user.getFormattedId(!configuration.logSensitiveInfo()), profile.getId());
logger.info("User {} logged in with profile {}", user.getRedactedId(), profile.getId());
// Prepare and send response
sessionKey = secureRandom.nextInt(Integer.MAX_VALUE);
@ -200,7 +197,7 @@ public class GameSpyHandler extends SimpleChannelInboundHandler<GameSpyRequest>
}
public void handleLogout() {
logger.info("User {} logged out of profile {}", user.getFormattedId(!configuration.logSensitiveInfo()), profile.getId());
logger.info("User {} logged out of profile {}", user.getRedactedId(), profile.getId());
sessionKey = -1; // Is there a point?
}

View File

@ -91,12 +91,12 @@ public class NasHandler implements HttpHandler {
// Should *never* return null in this location
user = userManager.authenticateUser(userId, request.password());
logger.info("Created account for user {}", user.getFormattedId(!configuration.logSensitiveInfo()));
logger.info("Created account for user {}", user.getRedactedId());
}
// Prepare GameSpy server credentials
ServiceCredentials credentials = userManager.createServiceSession(user, "gamespy", request.branchCode());
logger.info("Created GameSpy session for user {}", user.getFormattedId(!configuration.logSensitiveInfo()));
logger.info("Created GameSpy session for user {}", user.getRedactedId());
result(ctx, new NasLoginResponse("gamespy.com", credentials.authToken(), credentials.challenge()));
}
@ -120,7 +120,7 @@ public class NasHandler implements HttpHandler {
return;
}
logger.info("Created account for user {}", user.getFormattedId(!configuration.logSensitiveInfo()));
logger.info("Created account for user {}", user.getRedactedId());
result(ctx, NasReturnCode.REGISTRATION_SUCCESS);
}
@ -148,7 +148,7 @@ public class NasHandler implements HttpHandler {
// Prepare user credentials
ServiceCredentials credentials = userManager.createServiceSession(user, service, null);
logger.info("Created {} session for user {}",
type.equals("0000") ? "PGL" : type.equals("9000") ? "DLS1" : "this should never be logged", user.getFormattedId(!configuration.logSensitiveInfo()));
type.equals("0000") ? "PGL" : type.equals("9000") ? "DLS1" : "this should never be logged", user.getRedactedId());
result(ctx, new NasServiceLocationResponse(true, service, credentials.authToken()));
}

View File

@ -201,7 +201,7 @@ public class PglHandler implements HttpHandler {
return;
}
logger.info("Player {} is downloading save data as user {}", player.getGameSyncId(), user.getFormattedId(!configuration.logSensitiveInfo()));
logger.info("Player {} is downloading save data as user {}", player.getGameSyncId(), user.getRedactedId());
// Write status code
writeStatusCode(outputStream, 0);
@ -369,7 +369,7 @@ public class PglHandler implements HttpHandler {
return;
}
logger.info("User {} is Memory Linking with player {}", user.getFormattedId(!configuration.logSensitiveInfo()), player.getGameSyncId());
logger.info("User {} is Memory Linking with player {}", user.getRedactedId(), player.getGameSyncId());
// Send the save data!
try(FileInputStream inputStream = new FileInputStream(file)) {
@ -450,7 +450,7 @@ public class PglHandler implements HttpHandler {
return;
}
logger.info("Player {} is uploading save data as user {}", player.getGameSyncId(), user.getFormattedId(!configuration.logSensitiveInfo()));
logger.info("Player {} is uploading save data as user {}", player.getGameSyncId(), user.getRedactedId());
// Try to store save data
if(!playerManager.storePlayerGameSaveFile(player, ctx.bodyInputStream())) {