Fix Zaprit suggestions

This commit is contained in:
FeTetra 2025-05-26 18:27:00 -04:00
parent b77b7b3fb9
commit ef5bfd47eb
5 changed files with 5 additions and 12 deletions

View file

@ -215,7 +215,7 @@ public class LoginController : ControllerBase
if (ServerConfiguration.Instance.Authentication.RequirePatchworkUserAgent) if (ServerConfiguration.Instance.Authentication.RequirePatchworkUserAgent)
{ {
if (!PatchworkHelper.UserHasValidPatchworkUserAgent(token, this.Request.Headers.UserAgent.ToString())) if (!PatchworkHelper.UserHasValidPatchworkUserAgent(this.Request.Headers.UserAgent.ToString()))
{ {
return this.Forbid(); return this.Forbid();
} }

View file

@ -54,10 +54,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.";
public async Task<IActionResult> Announce() public async Task<IActionResult> Announce()
{ {
GameTokenEntity token = this.GetToken(); GameTokenEntity token = this.GetToken();
UserEntity? user = await this.database.UserFromGameToken(token);
if (user == null)
return this.Forbid();
string username = await this.database.UsernameFromGameToken(token); string username = await this.database.UsernameFromGameToken(token);

View file

@ -9,7 +9,7 @@ public static class PatchworkHelper
{ {
static int patchworkMajorVer = ServerConfiguration.Instance.Authentication.PatchworkMajorVersionMinimum; static int patchworkMajorVer = ServerConfiguration.Instance.Authentication.PatchworkMajorVersionMinimum;
static int patchworkMinorVer = ServerConfiguration.Instance.Authentication.PatchworkMinorVersionMinimum; static int patchworkMinorVer = ServerConfiguration.Instance.Authentication.PatchworkMinorVersionMinimum;
public static bool UserHasValidPatchworkUserAgent(GameTokenEntity token, string userAgent) public static bool UserHasValidPatchworkUserAgent(string userAgent)
{ {
string userAgentPrefix = "PatchworkLBP"; string userAgentPrefix = "PatchworkLBP";
char gameVersion = userAgent[userAgentPrefix.Length]; char gameVersion = userAgent[userAgentPrefix.Length];
@ -27,10 +27,7 @@ public static class PatchworkHelper
numericVersion = gameVersion - '0'; numericVersion = gameVersion - '0';
// Don't want it to be 0 still because of Unknown (-1) in GameVersion // Don't want it to be 0 still because of Unknown (-1) in GameVersion
if (numericVersion == 0) if (numericVersion - 1 == 0 || !Enum.IsDefined(typeof(GameVersion), numericVersion))
return false;
if (numericVersion - 1 != (int)token.GameVersion && !Enum.IsDefined(typeof(GameVersion), numericVersion))
return false; return false;
string[] patchworkVer = userAgent.Split(' ')[1].Split('.'); string[] patchworkVer = userAgent.Split(' ')[1].Split('.');

View file

@ -13,7 +13,7 @@ public class AuthenticationConfiguration
// Require use of Zaprit's "Patchwork" prx plugin's user agent when connecting to the server // Require use of Zaprit's "Patchwork" prx plugin's user agent when connecting to the server
// Major and minor version minimums can be left alone if patchwork is not required // Major and minor version minimums can be left alone if patchwork is not required
public bool RequirePatchworkUserAgent { get; set; } = false; public bool RequirePatchworkUserAgent { get; set; } = false;
public int PatchworkMajorVersionMinimum { get; set; } = 0; public int PatchworkMajorVersionMinimum { get; set; } = 1;
public int PatchworkMinorVersionMinimum { get; set; } = 0; public int PatchworkMinorVersionMinimum { get; set; } = 0;
} }

View file

@ -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. // 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. // If you are modifying anything here, this value MUST be incremented.
// Thanks for listening~ // Thanks for listening~
public override int ConfigVersion { get; set; } = 29; public override int ConfigVersion { get; set; } = 30;
public override string ConfigName { get; set; } = "lighthouse.yml"; public override string ConfigName { get; set; } = "lighthouse.yml";
public string WebsiteListenUrl { get; set; } = "http://localhost:10060"; public string WebsiteListenUrl { get; set; } = "http://localhost:10060";