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
This commit is contained in:
GreenXeMotion
2025-01-01 03:30:32 +06:00
committed by GitHub
parent 659d99aa0b
commit 8f65cacdda
6 changed files with 11 additions and 5 deletions

View File

@@ -9,6 +9,7 @@
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<IncludeNativeLibrariesForSelfExtract>True</IncludeNativeLibrariesForSelfExtract>
<NoWarn>$(NoWarn);SYSLIB0057</NoWarn>
<Version>0.1.4.2</Version>
</PropertyGroup>

View File

@@ -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();

View File

@@ -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)];
}
}
}

View File

@@ -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 =>

View File

@@ -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<ColorConsoleLoggerConfiguration> getCurrentConfig) : ILogger
public sealed class ColorConsoleLogger(Func<ColorConsoleLoggerConfiguration> getCurrentConfig) : ILogger
{
public IDisposable? BeginScope<TState>(TState state) where TState : notnull => default!;

View File

@@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<NoWarn>$(NoWarn);SYSLIB0057</NoWarn>
<LangVersion>latest</LangVersion>
</PropertyGroup>