From 8f65cacdda076c83e6c9ab6c1e29838da87127a7 Mon Sep 17 00:00:00 2001
From: GreenXeMotion <97885053+GreenXeMotion@users.noreply.github.com>
Date: Wed, 1 Jan 2025 03:30:32 +0600
Subject: [PATCH] Enhance project configurations and improve error handling
(#22)
* Enhance project configurations and improve error handling
- Added DebugType and NoWarn settings to project files for EpinelPS, ServerSelector, and ServerSelector.Desktop.
- Updated ServerCertificate initialization in Program.cs to read from file bytes for better reliability.
- Improved error handling in DoLimitBreak.cs and ExecuteEventGacha.cs by throwing exceptions for null references and unavailable characters, respectively.
- Refactored ColorConsoleLoggerProvider to simplify logger creation.
These changes aim to enhance debugging capabilities and ensure more robust error management across the application.
* Remove DebugType and DebugSymbols
---
EpinelPS/EpinelPS.csproj | 1 +
EpinelPS/LobbyServer/Character/DoLimitBreak.cs | 2 +-
EpinelPS/LobbyServer/Gacha/ExecuteEventGacha.cs | 6 +++++-
EpinelPS/Program.cs | 2 +-
EpinelPS/Utils/ColorConsoleLoggerProvider.cs | 4 ++--
ServerSelector/ServerSelector.csproj | 1 +
6 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/EpinelPS/EpinelPS.csproj b/EpinelPS/EpinelPS.csproj
index 5623047..ec90aca 100644
--- a/EpinelPS/EpinelPS.csproj
+++ b/EpinelPS/EpinelPS.csproj
@@ -9,6 +9,7 @@
true
true
True
+ $(NoWarn);SYSLIB0057
0.1.4.2
diff --git a/EpinelPS/LobbyServer/Character/DoLimitBreak.cs b/EpinelPS/LobbyServer/Character/DoLimitBreak.cs
index c714c52..898ed90 100644
--- a/EpinelPS/LobbyServer/Character/DoLimitBreak.cs
+++ b/EpinelPS/LobbyServer/Character/DoLimitBreak.cs
@@ -17,7 +17,7 @@ namespace EpinelPS.LobbyServer.Character
// Get all character data from the game's character table
var fullchardata = GameData.Instance.characterTable.Values.ToList();
- var targetCharacter = user.GetCharacterBySerialNumber(req.Csn);
+ var targetCharacter = user.GetCharacterBySerialNumber(req.Csn) ?? throw new NullReferenceException();
// Find the element with the current csn from the request
var currentCharacter = fullchardata.FirstOrDefault(c => c.id == targetCharacter.Tid) ?? throw new NullReferenceException();
diff --git a/EpinelPS/LobbyServer/Gacha/ExecuteEventGacha.cs b/EpinelPS/LobbyServer/Gacha/ExecuteEventGacha.cs
index b4e3ffb..41c9edf 100644
--- a/EpinelPS/LobbyServer/Gacha/ExecuteEventGacha.cs
+++ b/EpinelPS/LobbyServer/Gacha/ExecuteEventGacha.cs
@@ -207,7 +207,11 @@ namespace EpinelPS.LobbyServer.Gacha
}
// Fallback to a random R character if somehow no SSR characters are left after exclusion
- return availableRCharacters.Any() ? availableRCharacters[random.Next(availableRCharacters.Count)] : null;
+ if (!availableRCharacters.Any())
+ {
+ throw new InvalidOperationException("No available characters found for gacha pull");
+ }
+ return availableRCharacters[random.Next(availableRCharacters.Count)];
}
}
}
\ No newline at end of file
diff --git a/EpinelPS/Program.cs b/EpinelPS/Program.cs
index 12cff9e..8271088 100644
--- a/EpinelPS/Program.cs
+++ b/EpinelPS/Program.cs
@@ -39,7 +39,7 @@ namespace EpinelPS
{
SslProtocols = System.Security.Authentication.SslProtocols.Tls12,
ClientCertificateMode = ClientCertificateMode.AllowCertificate,
- ServerCertificate = new X509Certificate2(AppDomain.CurrentDomain.BaseDirectory + @"site.pfx")
+ ServerCertificate = new X509Certificate2(File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "site.pfx")))
};
builder.WebHost.ConfigureKestrel(serverOptions =>
diff --git a/EpinelPS/Utils/ColorConsoleLoggerProvider.cs b/EpinelPS/Utils/ColorConsoleLoggerProvider.cs
index 3a15d7b..2b0b9b9 100644
--- a/EpinelPS/Utils/ColorConsoleLoggerProvider.cs
+++ b/EpinelPS/Utils/ColorConsoleLoggerProvider.cs
@@ -21,7 +21,7 @@ namespace EpinelPS.Utils
}
public ILogger CreateLogger(string categoryName) =>
- _loggers.GetOrAdd(categoryName, name => new ColorConsoleLogger(name, GetCurrentConfig));
+ _loggers.GetOrAdd(categoryName, _ => new ColorConsoleLogger(GetCurrentConfig));
private ColorConsoleLoggerConfiguration GetCurrentConfig() => _currentConfig;
@@ -40,7 +40,7 @@ namespace EpinelPS.Utils
[LogLevel.Information] = ConsoleColor.Green
};
}
- public sealed class ColorConsoleLogger(string name, Func getCurrentConfig) : ILogger
+ public sealed class ColorConsoleLogger(Func getCurrentConfig) : ILogger
{
public IDisposable? BeginScope(TState state) where TState : notnull => default!;
diff --git a/ServerSelector/ServerSelector.csproj b/ServerSelector/ServerSelector.csproj
index 2fd1568..959916d 100644
--- a/ServerSelector/ServerSelector.csproj
+++ b/ServerSelector/ServerSelector.csproj
@@ -2,6 +2,7 @@
net9.0
enable
+ $(NoWarn);SYSLIB0057
latest