5a5e18f568
* Initial work on adding https support * Updated logging * More logging * Added support for a certificate password Replaced method used for getting path to cert * Reduce duplication of logic in program.cs * Cleanup of `HttpServer` * More https stuff * https * Fixed remote IP stuff * Fixed non-local request logging * Updated assets * Replaced `singleplayer/bossconvert` to `singleplayer/bosstypes` * Updated map loot * Asset update * Stop storing a bots inventory and other values to save memory --------- Co-authored-by: Chomp <dev@dev.sp-tarkov.com> Co-authored-by: clodan <clodan@clodan.com>
50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
using System.Collections.Concurrent;
|
|
using Core.Models.Eft.Common.Tables;
|
|
using Core.Models.Utils;
|
|
using SptCommon.Annotations;
|
|
|
|
namespace Core.Services;
|
|
|
|
[Injectable(InjectionType.Singleton)]
|
|
public class MatchBotDetailsCacheService(
|
|
ISptLogger<MatchBotDetailsCacheService> _logger,
|
|
LocalisationService _localisationService
|
|
)
|
|
{
|
|
protected ConcurrentDictionary<string, BotBase> _botDetailsCache = new();
|
|
|
|
public void CacheBot(BotBase botToCache)
|
|
{
|
|
if (botToCache.Info.Nickname is null)
|
|
{
|
|
_logger.Warning($"Unable to cache: {botToCache.Info.Settings.Role} bot with id: {botToCache.Id} as it lacks a nickname");
|
|
return;
|
|
}
|
|
|
|
botToCache.Inventory = null;
|
|
botToCache.Skills = null;
|
|
botToCache.Stats = null;
|
|
|
|
var key = $"{botToCache.Info.Nickname.Trim()}{botToCache.Info.Side}";
|
|
_botDetailsCache.TryAdd(key, botToCache);
|
|
}
|
|
|
|
public void ClearCache()
|
|
{
|
|
_botDetailsCache.Clear();
|
|
}
|
|
|
|
public BotBase? GetBotByNameAndSide(string botName, string botSide)
|
|
{
|
|
var botInCache = _botDetailsCache.GetValueOrDefault($"{botName}{botSide}`", null);
|
|
if (botInCache is null)
|
|
{
|
|
_logger.Warning($"Bot not found in match bot cache: {botName.ToLower()} {botSide}");
|
|
|
|
return null;
|
|
}
|
|
|
|
return botInCache;
|
|
}
|
|
}
|