Updated class param formatting
This commit is contained in:
@@ -2,7 +2,6 @@ using Microsoft.Extensions.Hosting;
|
||||
using SPTarkov.DI.Annotations;
|
||||
using SPTarkov.Server.Core.DI;
|
||||
using SPTarkov.Server.Core.Extensions;
|
||||
using SPTarkov.Server.Core.Models.Spt.Config;
|
||||
using SPTarkov.Server.Core.Models.Utils;
|
||||
using SPTarkov.Server.Core.Servers;
|
||||
using SPTarkov.Server.Core.Services;
|
||||
@@ -13,47 +12,45 @@ namespace SPTarkov.Server.Core.Utils;
|
||||
|
||||
[Injectable(InjectionType.Singleton)]
|
||||
public class App(
|
||||
IServiceProvider _serviceProvider,
|
||||
ISptLogger<App> _logger,
|
||||
TimeUtil _timeUtil,
|
||||
RandomUtil _randomUtil,
|
||||
ServerLocalisationService _serverLocalisationService,
|
||||
ConfigServer _configServer,
|
||||
HttpServer _httpServer,
|
||||
DatabaseService _databaseService,
|
||||
IHostApplicationLifetime _appLifeTime,
|
||||
IEnumerable<IOnLoad> _onLoadComponents,
|
||||
IEnumerable<IOnUpdate> _onUpdateComponents
|
||||
IServiceProvider serviceProvider,
|
||||
ISptLogger<App> logger,
|
||||
TimeUtil timeUtil,
|
||||
RandomUtil randomUtil,
|
||||
ServerLocalisationService serverLocalisationService,
|
||||
HttpServer httpServer,
|
||||
DatabaseService databaseService,
|
||||
IHostApplicationLifetime appLifeTime,
|
||||
IEnumerable<IOnLoad> onLoadComponents,
|
||||
IEnumerable<IOnUpdate> onUpdateComponents
|
||||
)
|
||||
{
|
||||
protected readonly CoreConfig _coreConfig = _configServer.GetConfig<CoreConfig>();
|
||||
protected readonly Dictionary<string, long> _onUpdateLastRun = new();
|
||||
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
ServiceLocator.SetServiceProvider(_serviceProvider);
|
||||
ServiceLocator.SetServiceProvider(serviceProvider);
|
||||
|
||||
if (_logger.IsLogEnabled(LogLevel.Debug))
|
||||
if (logger.IsLogEnabled(LogLevel.Debug))
|
||||
{
|
||||
_logger.Debug($"OS: {Environment.OSVersion.Version} | {Environment.OSVersion.Platform}");
|
||||
_logger.Debug($"Ran as admin: {Environment.IsPrivilegedProcess}");
|
||||
_logger.Debug($"CPU cores: {Environment.ProcessorCount}");
|
||||
_logger.Debug($"PATH: {(Environment.ProcessPath ?? "null returned").Encode(EncodeType.BASE64)}");
|
||||
_logger.Debug($"Server: {ProgramStatics.SPT_VERSION()}");
|
||||
logger.Debug($"OS: {Environment.OSVersion.Version} | {Environment.OSVersion.Platform}");
|
||||
logger.Debug($"Ran as admin: {Environment.IsPrivilegedProcess}");
|
||||
logger.Debug($"CPU cores: {Environment.ProcessorCount}");
|
||||
logger.Debug($"PATH: {(Environment.ProcessPath ?? "null returned").Encode(EncodeType.BASE64)}");
|
||||
logger.Debug($"Server: {ProgramStatics.SPT_VERSION()}");
|
||||
|
||||
// _logger.Debug($"RAM: {(os.totalmem() / 1024 / 1024 / 1024).toFixed(2)}GB");
|
||||
|
||||
if (ProgramStatics.BUILD_TIME() != 0)
|
||||
{
|
||||
_logger.Debug($"Date: {ProgramStatics.BUILD_TIME()}");
|
||||
logger.Debug($"Date: {ProgramStatics.BUILD_TIME()}");
|
||||
}
|
||||
|
||||
_logger.Debug($"Commit: {ProgramStatics.COMMIT()}");
|
||||
logger.Debug($"Commit: {ProgramStatics.COMMIT()}");
|
||||
}
|
||||
|
||||
// execute onLoad callbacks
|
||||
_logger.Info(_serverLocalisationService.GetText("executing_startup_callbacks"));
|
||||
foreach (var onLoad in _onLoadComponents)
|
||||
logger.Info(serverLocalisationService.GetText("executing_startup_callbacks"));
|
||||
foreach (var onLoad in onLoadComponents)
|
||||
{
|
||||
await onLoad.OnLoad();
|
||||
}
|
||||
@@ -61,36 +58,36 @@ public class App(
|
||||
// Discard here, as this task will run indefinitely
|
||||
_ = Task.Run(Update);
|
||||
|
||||
_logger.Success(_serverLocalisationService.GetText("started_webserver_success", _httpServer.ListeningUrl()));
|
||||
_logger.Success(_serverLocalisationService.GetText("websocket-started", _httpServer.ListeningUrl().Replace("https://", "wss://")));
|
||||
logger.Success(serverLocalisationService.GetText("started_webserver_success", httpServer.ListeningUrl()));
|
||||
logger.Success(serverLocalisationService.GetText("websocket-started", httpServer.ListeningUrl().Replace("https://", "wss://")));
|
||||
|
||||
_logger.Success(GetRandomisedStartMessage());
|
||||
logger.Success(GetRandomisedStartMessage());
|
||||
}
|
||||
|
||||
protected string GetRandomisedStartMessage()
|
||||
{
|
||||
if (_randomUtil.GetInt(1, 1000) > 999)
|
||||
if (randomUtil.GetInt(1, 1000) > 999)
|
||||
{
|
||||
return _serverLocalisationService.GetRandomTextThatMatchesPartialKey("server_start_meme_");
|
||||
return serverLocalisationService.GetRandomTextThatMatchesPartialKey("server_start_meme_");
|
||||
}
|
||||
|
||||
return _serverLocalisationService.GetText("server_start_success");
|
||||
return serverLocalisationService.GetText("server_start_success");
|
||||
}
|
||||
|
||||
protected async Task Update()
|
||||
{
|
||||
while (!_appLifeTime.ApplicationStopping.IsCancellationRequested)
|
||||
while (!appLifeTime.ApplicationStopping.IsCancellationRequested)
|
||||
{
|
||||
// If the server has failed to start, skip any update calls
|
||||
if (!_databaseService.IsDatabaseValid())
|
||||
if (!databaseService.IsDatabaseValid())
|
||||
{
|
||||
await Task.Delay(5000, _appLifeTime.ApplicationStopping);
|
||||
await Task.Delay(5000, appLifeTime.ApplicationStopping);
|
||||
|
||||
// Skip forward to the next loop
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var updateable in _onUpdateComponents)
|
||||
foreach (var updateable in onUpdateComponents)
|
||||
{
|
||||
var updateableName = updateable.GetType().FullName;
|
||||
if (string.IsNullOrEmpty(updateableName))
|
||||
@@ -99,13 +96,13 @@ public class App(
|
||||
}
|
||||
|
||||
var lastRunTimeTimestamp = _onUpdateLastRun.GetValueOrDefault(updateableName, 0);
|
||||
var secondsSinceLastRun = _timeUtil.GetTimeStamp() - lastRunTimeTimestamp;
|
||||
var secondsSinceLastRun = timeUtil.GetTimeStamp() - lastRunTimeTimestamp;
|
||||
|
||||
try
|
||||
{
|
||||
if (await updateable.OnUpdate(secondsSinceLastRun))
|
||||
{
|
||||
_onUpdateLastRun[updateableName] = _timeUtil.GetTimeStamp();
|
||||
_onUpdateLastRun[updateableName] = timeUtil.GetTimeStamp();
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
@@ -114,13 +111,13 @@ public class App(
|
||||
}
|
||||
}
|
||||
|
||||
await Task.Delay(5000, _appLifeTime.ApplicationStopping);
|
||||
await Task.Delay(5000, appLifeTime.ApplicationStopping);
|
||||
}
|
||||
}
|
||||
|
||||
protected void LogUpdateException(Exception err, IOnUpdate updateable)
|
||||
{
|
||||
_logger.Error(_serverLocalisationService.GetText("scheduled_event_failed_to_run", updateable.GetType().FullName));
|
||||
_logger.Error(err.ToString());
|
||||
logger.Error(serverLocalisationService.GetText("scheduled_event_failed_to_run", updateable.GetType().FullName));
|
||||
logger.Error(err.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ using SPTarkov.Server.Core.Utils.Json;
|
||||
namespace SPTarkov.Server.Core.Utils;
|
||||
|
||||
[Injectable(InjectionType.Singleton)]
|
||||
public class ImporterUtil(ISptLogger<ImporterUtil> _logger, FileUtil _fileUtil, JsonUtil _jsonUtil)
|
||||
public class ImporterUtil(ISptLogger<ImporterUtil> logger, FileUtil fileUtil, JsonUtil jsonUtil)
|
||||
{
|
||||
private readonly FrozenSet<string> _directoriesToIgnore = ["./SPT_Data/database/locales/server"];
|
||||
private readonly FrozenSet<string> _filesToIgnore = ["bearsuits.json", "usecsuits.json", "archivedquests.json"];
|
||||
@@ -46,15 +46,15 @@ public class ImporterUtil(ISptLogger<ImporterUtil> _logger, FileUtil _fileUtil,
|
||||
var result = Activator.CreateInstance(loadedType);
|
||||
|
||||
// get all filepaths
|
||||
var files = _fileUtil.GetFiles(filePath);
|
||||
var directories = _fileUtil.GetDirectories(filePath);
|
||||
var files = fileUtil.GetFiles(filePath);
|
||||
var directories = fileUtil.GetDirectories(filePath);
|
||||
|
||||
// Process files
|
||||
foreach (var file in files)
|
||||
{
|
||||
if (
|
||||
_fileUtil.GetFileExtension(file) != "json"
|
||||
|| _filesToIgnore.Contains(_fileUtil.GetFileNameAndExtension(file).ToLowerInvariant())
|
||||
fileUtil.GetFileExtension(file) != "json"
|
||||
|| _filesToIgnore.Contains(fileUtil.GetFileNameAndExtension(file).ToLowerInvariant())
|
||||
)
|
||||
{
|
||||
continue;
|
||||
@@ -98,7 +98,7 @@ public class ImporterUtil(ISptLogger<ImporterUtil> _logger, FileUtil _fileUtil,
|
||||
|
||||
// Get the set method to update the object
|
||||
var setMethod = GetSetMethod(
|
||||
_fileUtil.StripExtension(file).ToLowerInvariant(),
|
||||
fileUtil.StripExtension(file).ToLowerInvariant(),
|
||||
loadedType,
|
||||
out var propertyType,
|
||||
out var isDictionary
|
||||
@@ -113,7 +113,7 @@ public class ImporterUtil(ISptLogger<ImporterUtil> _logger, FileUtil _fileUtil,
|
||||
|
||||
lock (dictionaryLock)
|
||||
{
|
||||
setMethod.Invoke(result, isDictionary ? [_fileUtil.StripExtension(file), fileDeserialized] : [fileDeserialized]);
|
||||
setMethod.Invoke(result, isDictionary ? [fileUtil.StripExtension(file), fileDeserialized] : [fileDeserialized]);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -179,7 +179,7 @@ public class ImporterUtil(ISptLogger<ImporterUtil> _logger, FileUtil _fileUtil,
|
||||
return CreateLazyLoadDeserialization(file, propertyType);
|
||||
}
|
||||
|
||||
return await _jsonUtil.DeserializeFromFileAsync(file, propertyType);
|
||||
return await jsonUtil.DeserializeFromFileAsync(file, propertyType);
|
||||
}
|
||||
|
||||
private object CreateLazyLoadDeserialization(string file, Type propertyType)
|
||||
@@ -187,7 +187,7 @@ public class ImporterUtil(ISptLogger<ImporterUtil> _logger, FileUtil _fileUtil,
|
||||
var genericArgument = propertyType.GetGenericArguments()[0];
|
||||
|
||||
var deserializeCall = Expression.Call(
|
||||
Expression.Constant(_jsonUtil),
|
||||
Expression.Constant(jsonUtil),
|
||||
"DeserializeFromFile",
|
||||
Type.EmptyTypes,
|
||||
Expression.Constant(file),
|
||||
@@ -220,14 +220,14 @@ public class ImporterUtil(ISptLogger<ImporterUtil> _logger, FileUtil _fileUtil,
|
||||
.FirstOrDefault(prop =>
|
||||
string.Equals(
|
||||
prop.Name.ToLowerInvariant(),
|
||||
_fileUtil.StripExtension(propertyName).ToLowerInvariant(),
|
||||
fileUtil.StripExtension(propertyName).ToLowerInvariant(),
|
||||
StringComparison.Ordinal
|
||||
)
|
||||
);
|
||||
|
||||
if (matchedProperty == null)
|
||||
{
|
||||
throw new Exception($"Unable to find property '{_fileUtil.StripExtension(propertyName)}' for type '{type.Name}'");
|
||||
throw new Exception($"Unable to find property '{fileUtil.StripExtension(propertyName)}' for type '{type.Name}'");
|
||||
}
|
||||
|
||||
propertyType = matchedProperty.PropertyType;
|
||||
|
||||
@@ -12,10 +12,10 @@ namespace SPTarkov.Server.Core.Utils;
|
||||
|
||||
[Injectable(InjectionType.Singleton)]
|
||||
public class RagfairOfferHolder(
|
||||
ISptLogger<RagfairOfferHolder> _logger,
|
||||
RagfairServerHelper _ragfairServerHelper,
|
||||
ServerLocalisationService _serverLocalisationService,
|
||||
ItemHelper _itemHelper
|
||||
ISptLogger<RagfairOfferHolder> logger,
|
||||
RagfairServerHelper ragfairServerHelper,
|
||||
ServerLocalisationService serverLocalisationService,
|
||||
ItemHelper itemHelper
|
||||
)
|
||||
{
|
||||
/// <summary>
|
||||
@@ -146,7 +146,7 @@ public class RagfairOfferHolder(
|
||||
!itemTpl.IsEmpty // Has tpl
|
||||
&& offer.IsFakePlayerOffer()
|
||||
&& _fakePlayerOffers.TryGetValue(itemTpl, out var offers)
|
||||
&& offers?.Count >= _ragfairServerHelper.GetOfferCountByBaseType(_itemHelper.GetItem(itemTpl).Value.Parent)
|
||||
&& offers?.Count >= ragfairServerHelper.GetOfferCountByBaseType(itemHelper.GetItem(itemTpl).Value.Parent)
|
||||
)
|
||||
{
|
||||
// If it is an NPC PMC offer AND we have already reached the maximum amount of possible offers
|
||||
@@ -156,7 +156,7 @@ public class RagfairOfferHolder(
|
||||
|
||||
if (!_offersById.TryAdd(offer.Id, offer))
|
||||
{
|
||||
_logger.Warning($"Offer: {offer.Id} already exists");
|
||||
logger.Warning($"Offer: {offer.Id} already exists");
|
||||
}
|
||||
|
||||
if (offer.IsTraderOffer())
|
||||
@@ -182,14 +182,14 @@ public class RagfairOfferHolder(
|
||||
{
|
||||
if (!_offersById.TryGetValue(offerId, out var offer))
|
||||
{
|
||||
_logger.Warning(_serverLocalisationService.GetText("ragfair-unable_to_remove_offer_doesnt_exist", offerId));
|
||||
logger.Warning(serverLocalisationService.GetText("ragfair-unable_to_remove_offer_doesnt_exist", offerId));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_offersById.TryRemove(offer.Id, out _))
|
||||
{
|
||||
_logger.Warning($"Unable to remove offer by id: {offer.Id} not found");
|
||||
logger.Warning($"Unable to remove offer by id: {offer.Id} not found");
|
||||
}
|
||||
|
||||
if (checkTraderOffers && _offersByTrader.TryGetValue(offer.User.Id, out var traderOfferIds))
|
||||
@@ -202,7 +202,7 @@ public class RagfairOfferHolder(
|
||||
// Users with no offers were never cleaned up
|
||||
if (!_offersByTrader.TryRemove(offer.User.Id, out _))
|
||||
{
|
||||
_logger.Warning($"Unable to remove Trader offer: {offer.Id} not found");
|
||||
logger.Warning($"Unable to remove Trader offer: {offer.Id} not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,7 +235,7 @@ public class RagfairOfferHolder(
|
||||
{
|
||||
if (!_offersById.TryRemove(offerId, out _))
|
||||
{
|
||||
_logger.Warning($"Unable to remove offer: {offerId}");
|
||||
logger.Warning($"Unable to remove offer: {offerId}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ public class RagfairOfferHolder(
|
||||
return true;
|
||||
}
|
||||
|
||||
_logger.Warning($"Unable to add offer: {offerId} to _offersByTemplate");
|
||||
logger.Warning($"Unable to add offer: {offerId} to _offersByTemplate");
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -292,7 +292,7 @@ public class RagfairOfferHolder(
|
||||
return true;
|
||||
}
|
||||
|
||||
_logger.Error($"Unable to add offer: {offerId} to _offersByTrader");
|
||||
logger.Error($"Unable to add offer: {offerId} to _offersByTrader");
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -313,7 +313,7 @@ public class RagfairOfferHolder(
|
||||
return true;
|
||||
}
|
||||
|
||||
_logger.Error($"Unable to add offer: {offerId} to _fakePlayerOffers");
|
||||
logger.Error($"Unable to add offer: {offerId} to _fakePlayerOffers");
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -328,7 +328,7 @@ public class RagfairOfferHolder(
|
||||
{
|
||||
if (!_expiredOfferIds.Add(staleOfferId))
|
||||
{
|
||||
_logger.Warning($"Unable to add offer: {staleOfferId} to expired offers");
|
||||
logger.Warning($"Unable to add offer: {staleOfferId} to expired offers");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -364,13 +364,13 @@ public class RagfairOfferHolder(
|
||||
var offer = GetOfferById(expiredOfferId);
|
||||
if (offer is null)
|
||||
{
|
||||
_logger.Warning($"Expired offerId: {expiredOfferId} not found, skipping");
|
||||
logger.Warning($"Expired offerId: {expiredOfferId} not found, skipping");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (offer.Items?.Count == 0)
|
||||
{
|
||||
_logger.Error($"Expired offerId: {expiredOfferId} has no items, skipping");
|
||||
logger.Error($"Expired offerId: {expiredOfferId} has no items, skipping");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -401,7 +401,7 @@ public class RagfairOfferHolder(
|
||||
{
|
||||
foreach (var offer in GetOffers())
|
||||
{
|
||||
if (_expiredOfferIds.Contains(offer.Id) || _ragfairServerHelper.IsTrader(offer.User.Id))
|
||||
if (_expiredOfferIds.Contains(offer.Id) || ragfairServerHelper.IsTrader(offer.User.Id))
|
||||
{
|
||||
// Already flagged or trader offer (handled separately), skip
|
||||
continue;
|
||||
@@ -411,7 +411,7 @@ public class RagfairOfferHolder(
|
||||
{
|
||||
if (!_expiredOfferIds.Add(offer.Id))
|
||||
{
|
||||
_logger.Warning($"Unable to add offer: {offer.Id} to expired offers as it already exists");
|
||||
logger.Warning($"Unable to add offer: {offer.Id} to expired offers as it already exists");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace SPTarkov.Server.Core.Utils;
|
||||
|
||||
// TODO: Finish porting this class
|
||||
[Injectable(InjectionType.Singleton)]
|
||||
public class RandomUtil(ISptLogger<RandomUtil> _logger, ICloner _cloner)
|
||||
public class RandomUtil(ISptLogger<RandomUtil> logger, ICloner cloner)
|
||||
{
|
||||
private const int DecimalPointRandomPrecision = 6;
|
||||
|
||||
@@ -257,7 +257,7 @@ public class RandomUtil(ISptLogger<RandomUtil> _logger, ICloner _cloner)
|
||||
|
||||
if (!replacement)
|
||||
{
|
||||
list = _cloner.Clone(originalList);
|
||||
list = cloner.Clone(originalList);
|
||||
// Adjust drawCount to avoid drawing more elements than available
|
||||
if (drawCount > list.Count)
|
||||
{
|
||||
@@ -324,13 +324,13 @@ public class RandomUtil(ISptLogger<RandomUtil> _logger, ICloner _cloner)
|
||||
|
||||
if (max < min)
|
||||
{
|
||||
_logger.Error($"Invalid argument, Bounded random number generation max is smaller than min({max} < {min}");
|
||||
logger.Error($"Invalid argument, Bounded random number generation max is smaller than min({max} < {min}");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (n < 1)
|
||||
{
|
||||
_logger.Error($"Invalid argument, 'n' must be 1 or greater(received {n})");
|
||||
logger.Error($"Invalid argument, 'n' must be 1 or greater(received {n})");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -346,10 +346,10 @@ public class RandomUtil(ISptLogger<RandomUtil> _logger, ICloner _cloner)
|
||||
// A shift that is equal to the available range only has a 50% chance of rolling correctly, theoretically halving performance.
|
||||
// Shifting even further drops the success chance very rapidly - so we want to warn against that
|
||||
|
||||
_logger.Warning(
|
||||
logger.Warning(
|
||||
"Bias shift for random number generation is greater than the range of available numbers. This will have a severe performance impact"
|
||||
);
|
||||
_logger.Warning($"min-> {min}; max-> {max}; shift-> {shift}");
|
||||
logger.Warning($"min-> {min}; max-> {max}; shift-> {shift}");
|
||||
}
|
||||
|
||||
var biasedMin = shift >= 0 ? min - shift : min;
|
||||
|
||||
Reference in New Issue
Block a user