Show debug info on announce screen

This commit is contained in:
jvyden 2021-12-13 20:52:58 -05:00
parent 78e3bad38e
commit adb5dbef45
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
2 changed files with 30 additions and 7 deletions

View file

@ -51,7 +51,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
// Get an existing token from the IP & username
GameToken? token = await this.database.GameTokens.Include
(t => t.User)
.FirstOrDefaultAsync(t => t.UserLocation == ipAddress && t.User.Username == loginData.Username && t.Approved && !t.Used);
.FirstOrDefaultAsync(t => t.UserLocation == ipAddress && t.User.Username == loginData.Username && !t.Used);
if (token == null) // If we cant find an existing token, try to generate a new one
{
@ -79,10 +79,10 @@ namespace LBPUnion.ProjectLighthouse.Controllers
}
}
if (this.database.UserApprovedIpAddresses.Where
(a => a.UserId == user.UserId)
.Select(a => a.IpAddress)
.Contains(ipAddress)) token.Approved = true;
if (this.database.UserApprovedIpAddresses.Where(a => a.UserId == user.UserId).Select(a => a.IpAddress).Contains(ipAddress))
{
token.Approved = true;
}
else
{
AuthenticationAttempt authAttempt = new()

View file

@ -34,10 +34,33 @@ namespace LBPUnion.ProjectLighthouse.Controllers
[HttpGet("announce")]
public async Task<IActionResult> Announce()
{
#if !DEBUG
User? user = await this.database.UserFromGameRequest(this.Request);
if (user == null) return this.StatusCode(403, "");
#else
(User, GameToken)? userAndToken = await this.database.UserAndGameTokenFromRequest(this.Request);
return this.Ok($"You are now logged in as {user.Username} (id: {user.UserId}).\n\n" + ServerSettings.Instance.EulaText);
if (userAndToken == null) return this.StatusCode(403, "");
// ReSharper disable once PossibleInvalidOperationException
User user = userAndToken.Value.Item1;
GameToken gameToken = userAndToken.Value.Item2;
#endif
return this.Ok
(
$"You are now logged in as {user.Username}.\n\n" +
#if DEBUG
"---DEBUG INFO---\n" +
$"user.UserId: {user.UserId}\n" +
$"token.Approved: {gameToken.Approved}\n" +
$"token.Used: {gameToken.Used}\n" +
$"token.UserLocation: {gameToken.UserLocation}\n" +
$"token.GameVersion: {gameToken.GameVersion}\n" +
"---DEBUG INFO---\n\n" +
#endif
ServerSettings.Instance.EulaText
);
}
[HttpGet("notification")]
@ -49,7 +72,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
[HttpPost("filter")]
public async Task<IActionResult> Filter()
{
User user = await this.database.UserFromGameRequest(this.Request);
User? user = await this.database.UserFromGameRequest(this.Request);
if (user == null) return this.StatusCode(403, "");
string loggedText = await new StreamReader(this.Request.Body).ReadToEndAsync();