Merge pull request #544 from sp-tarkov/remove-warnings
Remove unused dependencies and improve code quality
This commit is contained in:
@@ -9,3 +9,8 @@ Changes before the CSharp rewrite (less than version 4) are not documented withi
|
||||
## [Unreleased]
|
||||
|
||||
[unreleased]: https://github.com/sp-tarkov/server-csharp/compare/47b6c3426e6f7db2e1b6d97281d850c89466aba0..HEAD
|
||||
### Changed
|
||||
- Removed unused dependencies and improved documentation grammar.
|
||||
|
||||
### Fixed
|
||||
- Added error handling for profile loading failures and adjusted nullable return types for better type safety.
|
||||
|
||||
@@ -116,7 +116,7 @@ public static class ObjectExtensions
|
||||
return resultDict;
|
||||
}
|
||||
|
||||
public static T ToObject<T>(this JsonElement element)
|
||||
public static T? ToObject<T>(this JsonElement element)
|
||||
{
|
||||
var json = element.GetRawText();
|
||||
return JsonSerializer.Deserialize<T>(json);
|
||||
|
||||
@@ -132,7 +132,7 @@ public class GameCallbacks(
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle /client/report/send & /client/reports/lobby/send
|
||||
/// Handle /client/report/send and handle /client/reports/lobby/send
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ValueTask<string> ReportNickname(string url, UIDRequestData request, MongoId sessionID)
|
||||
|
||||
@@ -425,7 +425,7 @@ public class DialogueController(
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle client/mail/dialog/pin && Handle client/mail/dialog/unpin
|
||||
/// Handle client/mail/dialog/pin and handle client/mail/dialog/unpin
|
||||
/// </summary>
|
||||
/// <param name="dialogueId"></param>
|
||||
/// <param name="shouldPin"></param>
|
||||
|
||||
@@ -3,14 +3,12 @@ using SPTarkov.Server.Core.Helpers;
|
||||
using SPTarkov.Server.Core.Models.Common;
|
||||
using SPTarkov.Server.Core.Models.Eft.InRaid;
|
||||
using SPTarkov.Server.Core.Models.Spt.Config;
|
||||
using SPTarkov.Server.Core.Models.Utils;
|
||||
using SPTarkov.Server.Core.Servers;
|
||||
|
||||
namespace SPTarkov.Server.Core.Controllers;
|
||||
|
||||
[Injectable]
|
||||
public class InRaidController(
|
||||
ISptLogger<InRaidController> logger,
|
||||
ProfileHelper profileHelper,
|
||||
//ApplicationContext _applicationContext,
|
||||
ConfigServer configServer
|
||||
|
||||
@@ -16,7 +16,6 @@ namespace SPTarkov.Server.Core.Controllers;
|
||||
|
||||
[Injectable]
|
||||
public class LauncherController(
|
||||
ISptLogger<LauncherController> logger,
|
||||
IReadOnlyList<SptMod> loadedMods,
|
||||
HashUtil hashUtil,
|
||||
SaveServer saveServer,
|
||||
|
||||
@@ -4,7 +4,6 @@ using SPTarkov.Server.Core.Models.Eft.Launcher;
|
||||
using SPTarkov.Server.Core.Models.Eft.Profile;
|
||||
using SPTarkov.Server.Core.Models.Spt.Config;
|
||||
using SPTarkov.Server.Core.Models.Spt.Mod;
|
||||
using SPTarkov.Server.Core.Models.Utils;
|
||||
using SPTarkov.Server.Core.Servers;
|
||||
using SPTarkov.Server.Core.Services;
|
||||
using SPTarkov.Server.Core.Utils;
|
||||
@@ -14,7 +13,6 @@ namespace SPTarkov.Server.Core.Controllers;
|
||||
|
||||
[Injectable]
|
||||
public class LauncherV2Controller(
|
||||
ISptLogger<LauncherV2Controller> logger,
|
||||
IReadOnlyList<SptMod> loadedMods,
|
||||
HashUtil hashUtil,
|
||||
SaveServer saveServer,
|
||||
|
||||
@@ -3,7 +3,6 @@ using SPTarkov.Server.Core.Helpers;
|
||||
using SPTarkov.Server.Core.Models.Common;
|
||||
using SPTarkov.Server.Core.Models.Eft.Match;
|
||||
using SPTarkov.Server.Core.Models.Spt.Config;
|
||||
using SPTarkov.Server.Core.Models.Utils;
|
||||
using SPTarkov.Server.Core.Servers;
|
||||
using SPTarkov.Server.Core.Services;
|
||||
using static SPTarkov.Server.Core.Services.MatchLocationService;
|
||||
@@ -12,7 +11,6 @@ namespace SPTarkov.Server.Core.Controllers;
|
||||
|
||||
[Injectable]
|
||||
public class MatchController(
|
||||
ISptLogger<MatchController> logger,
|
||||
MatchLocationService matchLocationService,
|
||||
ConfigServer configServer,
|
||||
LocationLifecycleService locationLifecycleService,
|
||||
|
||||
@@ -4,19 +4,13 @@ using SPTarkov.Server.Core.Models.Common;
|
||||
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
|
||||
using SPTarkov.Server.Core.Models.Eft.Prestige;
|
||||
using SPTarkov.Server.Core.Models.Eft.Profile;
|
||||
using SPTarkov.Server.Core.Models.Utils;
|
||||
using SPTarkov.Server.Core.Servers;
|
||||
using SPTarkov.Server.Core.Services;
|
||||
|
||||
namespace SPTarkov.Server.Core.Controllers;
|
||||
|
||||
[Injectable]
|
||||
public class PrestigeController(
|
||||
ISptLogger<PrestigeController> logger,
|
||||
ProfileHelper profileHelper,
|
||||
DatabaseService databaseService,
|
||||
SaveServer saveServer
|
||||
)
|
||||
public class PrestigeController(ProfileHelper profileHelper, DatabaseService databaseService, SaveServer saveServer)
|
||||
{
|
||||
/// <summary>
|
||||
/// Handle /client/prestige/list
|
||||
|
||||
@@ -27,7 +27,6 @@ public class TradeController(
|
||||
TimeUtil timeUtil,
|
||||
RandomUtil randomUtil,
|
||||
ItemHelper itemHelper,
|
||||
ProfileHelper profileHelper,
|
||||
RagfairOfferHelper ragfairOfferHelper,
|
||||
RagfairServer ragfairServer,
|
||||
HttpResponseUtil httpResponseUtil,
|
||||
|
||||
@@ -5,7 +5,6 @@ using SPTarkov.Server.Core.Models.Eft.Weather;
|
||||
using SPTarkov.Server.Core.Models.Enums;
|
||||
using SPTarkov.Server.Core.Models.Spt.Config;
|
||||
using SPTarkov.Server.Core.Models.Spt.Weather;
|
||||
using SPTarkov.Server.Core.Models.Utils;
|
||||
using SPTarkov.Server.Core.Servers;
|
||||
using SPTarkov.Server.Core.Services;
|
||||
|
||||
@@ -13,7 +12,6 @@ namespace SPTarkov.Server.Core.Controllers;
|
||||
|
||||
[Injectable]
|
||||
public class WeatherController(
|
||||
ISptLogger<WeatherController> logger,
|
||||
WeatherGenerator weatherGenerator,
|
||||
SeasonalEventService seasonalEventService,
|
||||
RaidWeatherService raidWeatherService,
|
||||
|
||||
@@ -172,7 +172,7 @@ public static class ProfileExtensions
|
||||
/// <param name="expTable">Experience table from globals.json</param>
|
||||
/// <returns>
|
||||
/// The calculated level of the player as an integer, or null if the level cannot be determined.
|
||||
/// This value is also assigned to <see cref="PmcData.Info.Level" /> within the provided profile.
|
||||
/// This value is also assigned to <see cref="Info.Level" /> within the provided profile.
|
||||
/// </returns>
|
||||
public static int? CalculateLevel(this PmcData pmcData, ExpTable[] expTable)
|
||||
{
|
||||
|
||||
@@ -3,14 +3,13 @@ using SPTarkov.Server.Core.Models.Common;
|
||||
using SPTarkov.Server.Core.Models.Eft.Bot;
|
||||
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
|
||||
using SPTarkov.Server.Core.Models.Spt.Bots;
|
||||
using SPTarkov.Server.Core.Models.Utils;
|
||||
using SPTarkov.Server.Core.Services;
|
||||
using SPTarkov.Server.Core.Utils;
|
||||
|
||||
namespace SPTarkov.Server.Core.Generators;
|
||||
|
||||
[Injectable]
|
||||
public class BotLevelGenerator(ISptLogger<BotLevelGenerator> logger, RandomUtil randomUtil, DatabaseService databaseService)
|
||||
public class BotLevelGenerator(RandomUtil randomUtil, DatabaseService databaseService)
|
||||
{
|
||||
/// <summary>
|
||||
/// Return a randomised bot level and exp value
|
||||
|
||||
@@ -4,7 +4,6 @@ using SPTarkov.Server.Core.Models.Common;
|
||||
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
|
||||
using SPTarkov.Server.Core.Models.Enums;
|
||||
using SPTarkov.Server.Core.Models.Spt.Config;
|
||||
using SPTarkov.Server.Core.Models.Utils;
|
||||
using SPTarkov.Server.Core.Servers;
|
||||
using SPTarkov.Server.Core.Services;
|
||||
|
||||
@@ -12,7 +11,6 @@ namespace SPTarkov.Server.Core.Generators;
|
||||
|
||||
[Injectable]
|
||||
public class PMCLootGenerator(
|
||||
ISptLogger<PMCLootGenerator> logger,
|
||||
DatabaseService databaseService,
|
||||
ItemHelper itemHelper,
|
||||
ItemFilterService itemFilterService,
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
using SPTarkov.DI.Annotations;
|
||||
using SPTarkov.Server.Core.Models.Eft.Common;
|
||||
using SPTarkov.Server.Core.Models.Spt.Config;
|
||||
using SPTarkov.Server.Core.Models.Utils;
|
||||
using SPTarkov.Server.Core.Servers;
|
||||
using SPTarkov.Server.Core.Services;
|
||||
|
||||
namespace SPTarkov.Server.Core.Generators;
|
||||
|
||||
[Injectable]
|
||||
public class PmcWaveGenerator(ISptLogger<PmcWaveGenerator> logger, DatabaseService databaseService, ConfigServer configServer)
|
||||
public class PmcWaveGenerator(DatabaseService databaseService, ConfigServer configServer)
|
||||
{
|
||||
protected readonly PmcConfig _pmcConfig = configServer.GetConfig<PmcConfig>();
|
||||
|
||||
|
||||
+1
-8
@@ -5,8 +5,6 @@ using SPTarkov.Server.Core.Models.Eft.Common.Tables;
|
||||
using SPTarkov.Server.Core.Models.Enums;
|
||||
using SPTarkov.Server.Core.Models.Spt.Config;
|
||||
using SPTarkov.Server.Core.Models.Spt.Repeatable;
|
||||
using SPTarkov.Server.Core.Models.Utils;
|
||||
using SPTarkov.Server.Core.Services;
|
||||
using SPTarkov.Server.Core.Utils;
|
||||
using SPTarkov.Server.Core.Utils.Json;
|
||||
|
||||
@@ -14,14 +12,9 @@ namespace SPTarkov.Server.Core.Generators.RepeatableQuestGeneration;
|
||||
|
||||
[Injectable]
|
||||
public class PickupQuestGenerator(
|
||||
ISptLogger<PickupQuestGenerator> logger,
|
||||
RepeatableQuestHelper repeatableQuestHelper,
|
||||
RepeatableQuestRewardGenerator repeatableQuestRewardGenerator,
|
||||
DatabaseService databaseService,
|
||||
ServerLocalisationService localisationService,
|
||||
RandomUtil randomUtil,
|
||||
MathUtil mathUtil,
|
||||
HashUtil hashUtil
|
||||
RandomUtil randomUtil
|
||||
) : IRepeatableQuestGenerator
|
||||
{
|
||||
// TODO: This isn't really implemented, not in the current pool.
|
||||
|
||||
@@ -28,8 +28,7 @@ public class HideoutHelper(
|
||||
ProfileHelper profileHelper,
|
||||
InventoryHelper inventoryHelper,
|
||||
ItemHelper itemHelper,
|
||||
ICloner cloner,
|
||||
MathUtil mathUtil
|
||||
ICloner cloner
|
||||
)
|
||||
{
|
||||
public static readonly MongoId BitcoinProductionId = new("5d5c205bd582a50d042a3c0e");
|
||||
|
||||
@@ -29,7 +29,7 @@ public class NotifierHelper(HttpServerHelper httpServerHelper)
|
||||
EventIdentifier = dialogueMessage.Id,
|
||||
OfferId = ragfairData.OfferId,
|
||||
HandbookId = ragfairData.HandbookId,
|
||||
Count = (int)ragfairData.Count,
|
||||
Count = Convert.ToInt32(ragfairData.Count),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ using SPTarkov.Server.Core.Models.Common;
|
||||
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
|
||||
using SPTarkov.Server.Core.Models.Enums;
|
||||
using SPTarkov.Server.Core.Models.Spt.Config;
|
||||
using SPTarkov.Server.Core.Models.Utils;
|
||||
using SPTarkov.Server.Core.Servers;
|
||||
using SPTarkov.Server.Core.Services;
|
||||
using SPTarkov.Server.Core.Utils;
|
||||
@@ -14,7 +13,6 @@ namespace SPTarkov.Server.Core.Helpers;
|
||||
|
||||
[Injectable]
|
||||
public class RagfairServerHelper(
|
||||
ISptLogger<RagfairServerHelper> logger,
|
||||
RandomUtil randomUtil,
|
||||
TimeUtil timeUtil,
|
||||
DatabaseService databaseService,
|
||||
|
||||
@@ -15,9 +15,7 @@ public record TemplateItem
|
||||
|
||||
private string? _name;
|
||||
|
||||
private string? _parent;
|
||||
|
||||
private string _prototype;
|
||||
private string? _prototype;
|
||||
|
||||
private string? _type;
|
||||
|
||||
@@ -78,9 +76,9 @@ public record Props
|
||||
[JsonExtensionData]
|
||||
public Dictionary<string, object>? ExtensionData { get; set; }
|
||||
|
||||
private string _backgroundColor;
|
||||
private string? _backgroundColor;
|
||||
|
||||
private string _itemSound;
|
||||
private string? _itemSound;
|
||||
private string? _metascoreGroup;
|
||||
|
||||
private string? _rarityPvE;
|
||||
|
||||
@@ -10,10 +10,6 @@ public record RagfairOffer
|
||||
[JsonExtensionData]
|
||||
public Dictionary<string, object>? ExtensionData { get; set; }
|
||||
|
||||
private string? _id;
|
||||
|
||||
private string? _root;
|
||||
|
||||
[JsonPropertyName("sellResult")]
|
||||
public List<SellResult>? SellResults { get; set; }
|
||||
|
||||
|
||||
@@ -4,14 +4,13 @@ using SPTarkov.Server.Core.Models.Common;
|
||||
using SPTarkov.Server.Core.Models.Eft.Common;
|
||||
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
|
||||
using SPTarkov.Server.Core.Models.Eft.ItemEvent;
|
||||
using SPTarkov.Server.Core.Models.Utils;
|
||||
using SPTarkov.Server.Core.Utils;
|
||||
using SPTarkov.Server.Core.Utils.Cloners;
|
||||
|
||||
namespace SPTarkov.Server.Core.Routers;
|
||||
|
||||
[Injectable]
|
||||
public class EventOutputHolder(ISptLogger<EventOutputHolder> logger, ProfileHelper profileHelper, TimeUtil timeUtil, ICloner cloner)
|
||||
public class EventOutputHolder(ProfileHelper profileHelper, TimeUtil timeUtil, ICloner cloner)
|
||||
{
|
||||
protected readonly Dictionary<MongoId, Dictionary<string, bool>> _clientActiveSessionStorage = new();
|
||||
protected readonly Dictionary<MongoId, ItemEventRouterResponse> _outputStore = new();
|
||||
|
||||
@@ -210,7 +210,15 @@ public class SaveServer(
|
||||
|
||||
if (profile is not null)
|
||||
{
|
||||
profiles[sessionID] = profileValidatorService.MigrateAndValidateProfile(profile);
|
||||
try
|
||||
{
|
||||
profiles[sessionID] = profileValidatorService.MigrateAndValidateProfile(profile);
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
logger.Critical($"Failed to load profile with ID '{sessionID}'");
|
||||
logger.Critical(ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,6 +300,13 @@ public class SaveServer(
|
||||
return !fileUtil.FileExists(file);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified profile is marked as invalid or cannot be loaded.
|
||||
/// </summary>
|
||||
/// <param name="sessionID">The ID of the profile to check.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the profile is invalid or unloadable; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public bool IsProfileInvalidOrUnloadable(MongoId sessionID)
|
||||
{
|
||||
if (
|
||||
|
||||
+2
-1
@@ -8,8 +8,9 @@ namespace SPTarkov.Server.Core.Servers.Ws.Message;
|
||||
[Injectable]
|
||||
public class DefaultSptWebSocketMessageHandler(ISptLogger<DefaultSptWebSocketMessageHandler> logger) : ISptWebSocketMessageHandler
|
||||
{
|
||||
public async Task OnSptMessage(string sessionID, WebSocket client, byte[] rawData)
|
||||
public Task OnSptMessage(string sessionID, WebSocket client, byte[] rawData)
|
||||
{
|
||||
logger.Debug($"[{sessionID}] SPT message received: {Encoding.UTF8.GetString(rawData)}");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public class SptWebSocketConnectionHandler(
|
||||
}
|
||||
}
|
||||
|
||||
public async Task OnClose(WebSocket ws, HttpContext context, string sessionIdContext)
|
||||
public Task OnClose(WebSocket ws, HttpContext context, string sessionIdContext)
|
||||
{
|
||||
var splitUrl = context.Request.Path.Value.Split("/");
|
||||
var sessionID = splitUrl.Last();
|
||||
@@ -144,6 +144,8 @@ public class SptWebSocketConnectionHandler(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public void SendMessageToAll(WsNotificationEvent output)
|
||||
|
||||
@@ -20,6 +20,12 @@ public class ProfileValidatorService(
|
||||
{
|
||||
private readonly IEnumerable<IProfileMigration> _sortedMigrations = profileMigrations.Sort();
|
||||
|
||||
/// <summary>
|
||||
/// Migrates and verifies if profiles are compatible
|
||||
/// </summary>
|
||||
/// <param name="profile">The profile as a <see cref="JsonObject"/> to verify and migrate</param>
|
||||
/// <returns>The migrated and validated profile</returns>
|
||||
/// <exception cref="InvalidOperationException">Thrown if a profile file cannot be loaded at all</exception>
|
||||
public SptProfile MigrateAndValidateProfile(JsonObject profile)
|
||||
{
|
||||
var profileId = profile["info"]?["id"]?.GetValue<string>();
|
||||
|
||||
Reference in New Issue
Block a user