Merge branch 'main' of https://github.com/sp-tarkov/server-csharp
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
using Core.Models.Eft.Common.Tables;
|
||||
using Core.Models.Eft.Profile;
|
||||
using Core.Models.Enums;
|
||||
@@ -63,7 +63,7 @@ public class Gift
|
||||
public SeasonalEventType AssociatedEvent { get; set; }
|
||||
|
||||
[JsonPropertyName("collectionTimeHours")]
|
||||
public int CollectionTimeHours { get; set; }
|
||||
public int? CollectionTimeHours { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional, can be used to change profile settings like level/skills
|
||||
|
||||
@@ -7,10 +7,11 @@ public interface ILogger
|
||||
// TODO: Removing these 4 methods for now, revisit in the future
|
||||
// void WriteToLogFile(string data);
|
||||
// void Log(string data, LogTextColor? color, string? backgroundColor = null);
|
||||
// void LogWithColor(string data, LogTextColor textColor, LogBackgroundColor? backgroundColor = null);
|
||||
void LogWithColor(string data, LogTextColor? textColor = null, LogBackgroundColor? backgroundColor = null);
|
||||
void Success(string data);
|
||||
void Error(string data);
|
||||
void Warning(string data);
|
||||
void Info(string data);
|
||||
void Debug(string data);
|
||||
void Critical(string data);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,32 @@
|
||||
using Core.Annotations;
|
||||
using Core.Annotations;
|
||||
using Core.Helpers;
|
||||
using Core.Models.Enums;
|
||||
using Core.Models.Spt.Config;
|
||||
using Core.Servers;
|
||||
using ILogger = Core.Models.Utils.ILogger;
|
||||
|
||||
namespace Core.Services;
|
||||
|
||||
[Injectable(InjectionType.Singleton)]
|
||||
public class GiftService
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ConfigServer _configServer;
|
||||
private readonly ProfileHelper _profileHelper;
|
||||
private readonly GiftsConfig _giftConfig;
|
||||
|
||||
public GiftService(
|
||||
ILogger logger,
|
||||
ConfigServer configServer,
|
||||
ProfileHelper profileHelper)
|
||||
{
|
||||
_logger = logger;
|
||||
_configServer = configServer;
|
||||
_profileHelper = profileHelper;
|
||||
|
||||
_giftConfig = _configServer.GetConfig<GiftsConfig>(ConfigTypes.GIFTS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a gift with a specific ID exist in db
|
||||
* @param giftId Gift id to check for
|
||||
@@ -19,7 +39,9 @@ public class GiftService
|
||||
|
||||
public Gift GetGiftById(string giftId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
_giftConfig.Gifts.TryGetValue(giftId, out var gift);
|
||||
|
||||
return gift;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,6 +70,26 @@ public class GiftService
|
||||
*/
|
||||
public GiftSentResult SendGiftToPlayer(string playerId, string giftId)
|
||||
{
|
||||
var giftData = GetGiftById(giftId);
|
||||
if (giftData is null)
|
||||
{
|
||||
return GiftSentResult.FAILED_GIFT_DOESNT_EXIST;
|
||||
}
|
||||
|
||||
var maxGiftsToSendCount = giftData.MaxToSendPlayer ?? 1;
|
||||
|
||||
if (_profileHelper.PlayerHasRecievedMaxNumberOfGift(playerId, giftId, maxGiftsToSendCount))
|
||||
{
|
||||
_logger.Debug($"Player already received gift: {giftId}");
|
||||
|
||||
return GiftSentResult.FAILED_GIFT_ALREADY_RECEIVED;
|
||||
}
|
||||
|
||||
if (giftData.Items?.Count > 0 && giftData.CollectionTimeHours is not null)
|
||||
{
|
||||
_logger.Warning($"Gift {giftId} has items but no collection time limit, defaulting to 48 hours");
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -78,6 +120,20 @@ public class GiftService
|
||||
*/
|
||||
public void SendPraporStartingGift(string sessionId, int day)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var giftId = day switch
|
||||
{
|
||||
1 => "PraporGiftDay1",
|
||||
2 => "PraporGiftDay2",
|
||||
_ => null
|
||||
};
|
||||
|
||||
if (giftId is not null)
|
||||
{
|
||||
//var giftData = GetGiftById(giftId);
|
||||
if (!_profileHelper.PlayerHasRecievedMaxNumberOfGift(sessionId, giftId, 1))
|
||||
{
|
||||
SendGiftToPlayer(sessionId, giftId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
using Core.Models.Logging;
|
||||
using Core.Annotations;
|
||||
using ILogger = Core.Models.Utils.ILogger;
|
||||
|
||||
namespace Core.Utils.Logging;
|
||||
|
||||
// [Injectable(InjectionType.Singleton)]
|
||||
public class SimpleTextLogger : ILogger
|
||||
{
|
||||
public void Success(string data)
|
||||
{
|
||||
Console.WriteLine(data);
|
||||
}
|
||||
|
||||
public void Error(string data)
|
||||
{
|
||||
Console.WriteLine(data);
|
||||
}
|
||||
|
||||
public void Warning(string data)
|
||||
{
|
||||
Console.WriteLine(data);
|
||||
}
|
||||
|
||||
public void Info(string data)
|
||||
{
|
||||
Console.WriteLine(data);
|
||||
}
|
||||
|
||||
public void Debug(string data)
|
||||
{
|
||||
Console.WriteLine(data);
|
||||
}
|
||||
}
|
||||
@@ -182,7 +182,7 @@ public class Watermark {
|
||||
|
||||
// Log watermark to screen
|
||||
foreach (var text in result) {
|
||||
_logger.Warning(text);
|
||||
_logger.LogWithColor(text, LogTextColor.Yellow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Core.Annotations;
|
||||
using Core.Models.Logging;
|
||||
using ILogger = Core.Models.Utils.ILogger;
|
||||
|
||||
namespace Server.Logger;
|
||||
@@ -12,19 +13,43 @@ public class WebApplicationLogger : ILogger
|
||||
_logger = provider.CreateLogger("SptLogger");
|
||||
}
|
||||
|
||||
public void LogWithColor(string data, LogTextColor? textColor = null, LogBackgroundColor? backgroundColor = null)
|
||||
{
|
||||
if (textColor != null || backgroundColor != null)
|
||||
{
|
||||
_logger.LogInformation(GetColorizedText(data, textColor, backgroundColor));
|
||||
}
|
||||
else
|
||||
_logger.LogInformation(data);
|
||||
}
|
||||
|
||||
private string GetColorizedText(string data, LogTextColor? textColor = null, LogBackgroundColor? backgroundColor = null)
|
||||
{
|
||||
var colorString = string.Empty;
|
||||
if (textColor != null)
|
||||
colorString += ((int)textColor.Value).ToString();
|
||||
|
||||
if (backgroundColor != null)
|
||||
colorString += string.IsNullOrEmpty(colorString)
|
||||
? ((int)backgroundColor.Value).ToString()
|
||||
: $";{((int)backgroundColor.Value).ToString()}";
|
||||
|
||||
return $"\x1b[{colorString}m{data}\x1b[0m";
|
||||
}
|
||||
|
||||
public void Success(string data)
|
||||
{
|
||||
_logger.LogInformation(data);
|
||||
_logger.LogInformation(GetColorizedText(data, LogTextColor.Green));
|
||||
}
|
||||
|
||||
public void Error(string data)
|
||||
{
|
||||
_logger.LogError(data);
|
||||
_logger.LogError(GetColorizedText(data, LogTextColor.Red));
|
||||
}
|
||||
|
||||
public void Warning(string data)
|
||||
{
|
||||
_logger.LogWarning(data);
|
||||
_logger.LogWarning(GetColorizedText(data, LogTextColor.Yellow));
|
||||
}
|
||||
|
||||
public void Info(string data)
|
||||
@@ -36,4 +61,9 @@ public class WebApplicationLogger : ILogger
|
||||
{
|
||||
_logger.LogDebug(data);
|
||||
}
|
||||
|
||||
public void Critical(string data)
|
||||
{
|
||||
_logger.LogCritical(GetColorizedText(data, LogTextColor.Black, LogBackgroundColor.Red));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user