Merge branch 'main' of https://github.com/sp-tarkov/server-csharp
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
using SptCommon.Annotations;
|
||||
using Core.Helpers;
|
||||
using Core.Models.Eft.Notifier;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
using Core.Services;
|
||||
using System.Diagnostics.Tracing;
|
||||
|
||||
namespace Core.Controllers;
|
||||
|
||||
@@ -8,7 +11,7 @@ namespace Core.Controllers;
|
||||
public class NotifierController(
|
||||
HttpServerHelper _httpServerHelper,
|
||||
NotifierHelper _notifierHelper
|
||||
)
|
||||
)
|
||||
{
|
||||
/// <summary>
|
||||
/// Resolve an array of session notifications.
|
||||
@@ -20,7 +23,47 @@ public class NotifierController(
|
||||
/// <param name="sessionId"></param>
|
||||
public async Task NotifyAsync(string sessionId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
// TODO: Finish implementation of the NotifyAsync method
|
||||
//
|
||||
//return new Promise((resolve) => {
|
||||
// // keep track of our timeout
|
||||
// let counter = 0;
|
||||
|
||||
// /**
|
||||
// * Check for notifications, resolve if any, otherwise poll
|
||||
// * intermittently for a period of time.
|
||||
// */
|
||||
// var checkNotifications = () => {
|
||||
// /**
|
||||
// * If there are no pending messages we should either check again later
|
||||
// * or timeout now with a default response.
|
||||
// */
|
||||
// if (!_notificationService.Has(sessionID)) {
|
||||
// // have we exceeded timeout? if so reply with default ping message
|
||||
// if (counter > _timeout) {
|
||||
// return resolve([_notifierHelper.getDefaultNotification()]);
|
||||
// }
|
||||
|
||||
// // check again
|
||||
// setTimeout(checkNotifications, _pollInterval);
|
||||
|
||||
// // update our timeout counter
|
||||
// counter += _pollInterval;
|
||||
// return;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Maintaining array reference is not necessary, so we can just copy and reinitialize
|
||||
// */
|
||||
// var messages = _notificationService.Get(sessionID);
|
||||
|
||||
// _notificationService.UpdateMessageOnQueue(sessionID, []);
|
||||
// resolve(messages);
|
||||
//};
|
||||
|
||||
// immediately check
|
||||
// checkNotifications();
|
||||
//});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -230,7 +230,7 @@ public class BotGenerator(
|
||||
|
||||
bot.Info.Experience = botLevel.Exp;
|
||||
bot.Info.Level = botLevel.Level;
|
||||
bot.Info.Settings.Experience = GetExperienceRewardForKillByDifficulty(
|
||||
bot.Info.Settings.Experience = (int)GetExperienceRewardForKillByDifficulty(
|
||||
botJsonTemplate.BotExperience.Reward,
|
||||
botGenerationDetails.BotDifficulty,
|
||||
botGenerationDetails.Role
|
||||
|
||||
@@ -196,7 +196,7 @@ public record BotInfoSettings
|
||||
{
|
||||
public string? Role { get; set; }
|
||||
public string? BotDifficulty { get; set; }
|
||||
public double? Experience { get; set; }
|
||||
public int? Experience { get; set; }
|
||||
public double? StandingForKill { get; set; }
|
||||
public double? AggressorBonus { get; set; }
|
||||
public bool? UseSimpleAnimator { get; set; }
|
||||
|
||||
@@ -13,6 +13,7 @@ public class BotGenerationCacheService(
|
||||
{
|
||||
protected Dictionary<string, List<BotBase>> _storedBots = new Dictionary<string, List<BotBase>>();
|
||||
protected Queue<BotBase> _activeBotsInRaid = [];
|
||||
protected Lock _lock = new Lock();
|
||||
|
||||
|
||||
/**
|
||||
@@ -21,11 +22,14 @@ public class BotGenerationCacheService(
|
||||
*/
|
||||
public void StoreBots(string key, List<BotBase> botsToStore)
|
||||
{
|
||||
foreach (var bot in botsToStore)
|
||||
lock (_lock)
|
||||
{
|
||||
if (!_storedBots.TryAdd(key, [bot]))
|
||||
foreach (var bot in botsToStore)
|
||||
{
|
||||
_storedBots[key].Add(bot);
|
||||
if (!_storedBots.TryAdd(key, [bot]))
|
||||
{
|
||||
_storedBots[key].Add(bot);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,21 +42,24 @@ public class BotGenerationCacheService(
|
||||
*/
|
||||
public BotBase? GetBot(string key)
|
||||
{
|
||||
if (_storedBots.TryGetValue(key, out var bots))
|
||||
lock (_lock)
|
||||
{
|
||||
if (bots.Count > 0)
|
||||
if (_storedBots.TryGetValue(key, out var bots))
|
||||
{
|
||||
try
|
||||
if (bots.Count > 0)
|
||||
{
|
||||
return bots.Pop();
|
||||
}
|
||||
catch (Exception _)
|
||||
{
|
||||
_logger.Error(_localisationService.GetText("bot-cache_has_zero_bots_of_requested_type", key));
|
||||
return bots.PopFirst();
|
||||
try
|
||||
{
|
||||
}
|
||||
catch (Exception _)
|
||||
{
|
||||
_logger.Error(_localisationService.GetText("bot-cache_has_zero_bots_of_requested_type", key));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_logger.Error(_localisationService.GetText("bot-no_bot_type_in_cache", key));
|
||||
return null;
|
||||
}
|
||||
@@ -63,7 +70,10 @@ public class BotGenerationCacheService(
|
||||
*/
|
||||
public void StoreUsedBot(BotBase botToStore)
|
||||
{
|
||||
_activeBotsInRaid.Enqueue(botToStore);
|
||||
lock (_lock)
|
||||
{
|
||||
_activeBotsInRaid.Enqueue(botToStore);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +84,10 @@ public class BotGenerationCacheService(
|
||||
*/
|
||||
public BotBase? GetUsedBot(string profileId)
|
||||
{
|
||||
return _activeBotsInRaid.FirstOrDefault(x => x.Id == profileId);
|
||||
lock (_lock)
|
||||
{
|
||||
return _activeBotsInRaid.FirstOrDefault(x => x.Id == profileId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,8 +95,11 @@ public class BotGenerationCacheService(
|
||||
*/
|
||||
public void ClearStoredBots()
|
||||
{
|
||||
_storedBots.Clear();
|
||||
_activeBotsInRaid = [];
|
||||
lock (_lock)
|
||||
{
|
||||
_storedBots.Clear();
|
||||
_activeBotsInRaid = [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,10 +9,10 @@ public static class ListExtensions
|
||||
return items;
|
||||
}
|
||||
|
||||
public static T Pop<T>(this List<T> source)
|
||||
public static T PopFirst<T>(this List<T> source)
|
||||
{
|
||||
T r = source.Last();
|
||||
source.Remove(source.Last());
|
||||
T r = source.First();
|
||||
source.Remove(source.First());
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user