Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into recent-activity
Browse files Browse the repository at this point in the history
  • Loading branch information
Slendy committed Nov 2, 2024
2 parents 02fbd73 + f1fe542 commit 7f1b1b2
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 19 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/qodana_code_quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Qodana
on:
workflow_dispatch:
pull_request_target:
branches:
- main
push:
branches: # Specify your branches here
- main # The 'main' branch
- 'releases/*' # The release branches

jobs:
qodana:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
checks: write
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit
fetch-depth: 0 # a full history is required for pull request analysis
- name: 'Qodana Scan'
uses: JetBrains/[email protected]
with:
pr-mode: false
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN_1488465344 }}
QODANA_ENDPOINT: 'https://qodana.cloud'
- uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: ${{ runner.temp }}/qodana/results/qodana.sarif.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#nullable enable
using System.Net;
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
Expand All @@ -21,12 +20,10 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Login;
public class LoginController : ControllerBase
{
private readonly DatabaseContext database;

public LoginController(DatabaseContext database)

Check notice on line 23 in ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Convert constructor into primary constructor

Convert into primary constructor
{
this.database = database;
}

[HttpPost]
public async Task<IActionResult> Login()
{
Expand Down Expand Up @@ -57,9 +54,9 @@ public async Task<IActionResult> Login()

string ipAddress = remoteIpAddress.ToString();

string? username = npTicket.Username;
string username = npTicket.Username;

if (username == null)
if (string.IsNullOrEmpty(username))
{
Logger.Warn("Unable to determine username, rejecting login", LogArea.Login);
return this.Forbid();
Expand All @@ -77,7 +74,7 @@ public async Task<IActionResult> Login()
case Platform.PS3:
case Platform.Vita:
case Platform.UnitTest:
user = await this.database.Users.FirstOrDefaultAsync(u => u.LinkedPsnId == npTicket.UserId);
user = await database.Users.FirstOrDefaultAsync(u => u.LinkedPsnId == npTicket.UserId);

Check notice on line 77 in ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Add/remove 'this.' qualifier

Qualifier 'this.' is missing
break;
case Platform.PSP:
case Platform.Unknown:
Expand All @@ -89,7 +86,7 @@ public async Task<IActionResult> Login()
if (user == null)
{
// Check if there is an account with that username already
UserEntity? targetUsername = await this.database.Users.FirstOrDefaultAsync(u => u.Username == npTicket.Username);
UserEntity? targetUsername = await database.Users.FirstOrDefaultAsync(u => u.Username == npTicket.Username);

Check notice on line 89 in ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Add/remove 'this.' qualifier

Qualifier 'this.' is missing
if (targetUsername != null)
{
ulong targetPlatform = npTicket.Platform == Platform.RPCS3
Expand All @@ -104,7 +101,7 @@ public async Task<IActionResult> Login()
}

// if there is already a pending link request don't create another
bool linkAttemptExists = await this.database.PlatformLinkAttempts.AnyAsync(p =>
bool linkAttemptExists = await database.PlatformLinkAttempts.AnyAsync(p =>

Check notice on line 104 in ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Add/remove 'this.' qualifier

Qualifier 'this.' is missing
p.Platform == npTicket.Platform &&
p.PlatformId == npTicket.UserId &&
p.UserId == targetUsername.UserId);
Expand All @@ -119,8 +116,8 @@ public async Task<IActionResult> Login()
Timestamp = TimeHelper.TimestampMillis,
PlatformId = npTicket.UserId,
};
this.database.PlatformLinkAttempts.Add(linkAttempt);
await this.database.SaveChangesAsync();
database.PlatformLinkAttempts.Add(linkAttempt);

Check notice on line 119 in ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Add/remove 'this.' qualifier

Qualifier 'this.' is missing
await database.SaveChangesAsync();

Check notice on line 120 in ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Add/remove 'this.' qualifier

Qualifier 'this.' is missing
Logger.Success($"User '{npTicket.Username}' tried to login but platform isn't linked, platform={npTicket.Platform}", LogArea.Login);
return this.Forbid();
}
Expand All @@ -130,12 +127,31 @@ public async Task<IActionResult> Login()
Logger.Warn($"Unknown user tried to connect username={username}", LogArea.Login);
return this.Forbid();
}

// Block RPCN signups if forbidden in config
if (npTicket.Platform == Platform.RPCS3 && !ServerConfiguration.Instance.Authentication.AllowRPCNSignup)
{
Logger.Warn(
$"New user tried to sign up via RPCN, and that is forbidden in the config, username={username}, remoteIpAddress={remoteIpAddress}",
LogArea.Login);
return this.Forbid();
}

// Block PSN signups if forbidden in config
if (npTicket.Platform.IsPSN() && !ServerConfiguration.Instance.Authentication.AllowPSNSignup)
{
Logger.Warn(
$"New user tried to sign up via PSN, and that is forbidden in the config, username={username}, remoteIpAddress={remoteIpAddress}",
LogArea.Login);
return this.Forbid();
}

// create account for user if they don't exist
user = await this.database.CreateUser(username, "$");
user = await database.CreateUser(username, "$");

Check notice on line 150 in ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Add/remove 'this.' qualifier

Qualifier 'this.' is missing
user.Password = null;
user.LinkedRpcnId = npTicket.Platform == Platform.RPCS3 ? npTicket.UserId : 0;
user.LinkedPsnId = npTicket.Platform != Platform.RPCS3 ? npTicket.UserId : 0;
await this.database.SaveChangesAsync();
await database.SaveChangesAsync();

Check notice on line 154 in ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Add/remove 'this.' qualifier

Qualifier 'this.' is missing

if (DiscordConfiguration.Instance.DiscordIntegrationEnabled)
{
Expand All @@ -155,7 +171,7 @@ public async Task<IActionResult> Login()
// automatically change username if it doesn't match
else if (user.Username != npTicket.Username)
{
bool usernameExists = await this.database.Users.AnyAsync(u => u.Username == npTicket.Username);
bool usernameExists = await database.Users.AnyAsync(u => u.Username == npTicket.Username);

Check notice on line 174 in ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Add/remove 'this.' qualifier

Qualifier 'this.' is missing
if (usernameExists)
{
Logger.Warn($"{npTicket.Platform} user changed their name to a name that is already taken," +
Expand All @@ -164,17 +180,17 @@ public async Task<IActionResult> Login()
}
Logger.Info($"User's username has changed, old='{user.Username}', new='{npTicket.Username}', platform={npTicket.Platform}", LogArea.Login);
user.Username = username;
await this.database.PlatformLinkAttempts.RemoveWhere(p => p.UserId == user.UserId);
await database.PlatformLinkAttempts.RemoveWhere(p => p.UserId == user.UserId);

Check notice on line 183 in ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Add/remove 'this.' qualifier

Qualifier 'this.' is missing
// unlink other platforms because the names no longer match
if (npTicket.Platform == Platform.RPCS3)
user.LinkedPsnId = 0;
else
user.LinkedRpcnId = 0;

await this.database.SaveChangesAsync();
await database.SaveChangesAsync();

Check notice on line 190 in ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Add/remove 'this.' qualifier

Qualifier 'this.' is missing
}

GameTokenEntity? token = await this.database.GameTokens.Include(t => t.User)
GameTokenEntity? token = await database.GameTokens.Include(t => t.User)

Check notice on line 193 in ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Add/remove 'this.' qualifier

Qualifier 'this.' is missing
.FirstOrDefaultAsync(t => t.User.Username == npTicket.Username && t.TicketHash == npTicket.TicketHash);

if (token != null)
Expand All @@ -183,7 +199,7 @@ public async Task<IActionResult> Login()
return this.Forbid();
}

token = await this.database.AuthenticateUser(user, npTicket, ipAddress);
token = await database.AuthenticateUser(user, npTicket, ipAddress);

Check notice on line 202 in ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Add/remove 'this.' qualifier

Qualifier 'this.' is missing
if (token == null)
{
Logger.Warn($"Unable to find/generate a token for username {npTicket.Username}", LogArea.Login);
Expand All @@ -200,7 +216,7 @@ public async Task<IActionResult> Login()

user.LastLogin = TimeHelper.TimestampMillis;

await this.database.SaveChangesAsync();
await database.SaveChangesAsync();

Check notice on line 219 in ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Add/remove 'this.' qualifier

Qualifier 'this.' is missing

// Create a new room on LBP2/3/Vita
if (token.GameVersion != GameVersion.LittleBigPlanet1) RoomHelper.CreateRoom(user.UserId, token.GameVersion, token.Platform);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ public class AuthenticationConfiguration
public bool RegistrationEnabled { get; set; } = true;
public bool AutomaticAccountCreation { get; set; } = true;

Check notice on line 6 in ProjectLighthouse/Configuration/ConfigurationCategories/AuthenticationConfiguration.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Auto-property can be made get-only (non-private accessibility)

Auto-property can be made get-only
public bool VerifyTickets { get; set; } = true;

Check notice on line 7 in ProjectLighthouse/Configuration/ConfigurationCategories/AuthenticationConfiguration.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Auto-property can be made get-only (non-private accessibility)

Auto-property can be made get-only

public bool AllowRPCNSignup { get; set; } = true;

Check notice on line 9 in ProjectLighthouse/Configuration/ConfigurationCategories/AuthenticationConfiguration.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Auto-property can be made get-only (non-private accessibility)

Auto-property can be made get-only

public bool AllowPSNSignup { get; set; } = true;

Check notice on line 11 in ProjectLighthouse/Configuration/ConfigurationCategories/AuthenticationConfiguration.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Auto-property can be made get-only (non-private accessibility)

Auto-property can be made get-only

}
2 changes: 1 addition & 1 deletion ProjectLighthouse/Configuration/ServerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ServerConfiguration : ConfigurationBase<ServerConfiguration>
// This is so Lighthouse can properly identify outdated configurations and update them with newer settings accordingly.
// If you are modifying anything here, this value MUST be incremented.
// Thanks for listening~
public override int ConfigVersion { get; set; } = 26;
public override int ConfigVersion { get; set; } = 27;

public override string ConfigName { get; set; } = "lighthouse.yml";
public string WebsiteListenUrl { get; set; } = "http://localhost:10060";

Check notice on line 17 in ProjectLighthouse/Configuration/ServerConfiguration.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Auto-property can be made get-only (non-private accessibility)

Auto-property can be made get-only
Expand Down
9 changes: 9 additions & 0 deletions ProjectLighthouse/Types/Users/Platform.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
namespace LBPUnion.ProjectLighthouse.Types.Users;

public static class PlatformExtensions
{

public static bool IsPSN(this Platform platform)
{
return platform == Platform.PS3 || platform == Platform.PSP || platform == Platform.Vita;

Check notice on line 8 in ProjectLighthouse/Types/Users/Platform.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Use preferred body style (convert into method or operator with preferred body style)

Code body does not conform to code style settings: use expression body

Check notice on line 8 in ProjectLighthouse/Types/Users/Platform.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Merge null/pattern/value checks into 'or'/'and' patterns

Merge into logical pattern
}
}

public enum Platform
{
PS3 = 0,
Expand Down
11 changes: 11 additions & 0 deletions qodana.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "1.0"
linter: jetbrains/qodana-dotnet:2024.1
profile:
name: qodana.recommended
include:
- name: CheckDependencyLicenses
exclude:
- name: All
paths:
- ProjectLighthouse.Localization
- ProjectLighthouse/Migrations

0 comments on commit 7f1b1b2

Please sign in to comment.