초기커밋

This commit is contained in:
2025-05-01 07:20:41 +09:00
commit 98bb2e3c5c
2747 changed files with 646947 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
namespace BrokerCore.Common;
public class ApiException: Exception
{
public int ErrorCode { get; init; }
public ApiException(int errorCode, string message) : base(message)
{
ErrorCode = errorCode;
}
public ApiException(ServerErrorCode errorCode, string message) : base(message)
{
ErrorCode = (int)errorCode;
}
}

View File

@@ -0,0 +1,27 @@
namespace BrokerCore.Common;
using ApiModels;
using DbEntity;
public static class ApiExtensions
{
public static PlanetItemExchangeOrderDto toDto( this PlanetItemExchangeOrder order ) => new()
{
OrderId = order.OrderId,
OrderStatus = order.OrderStatus,
ExchangeMetaId = order.ExchangeMetaId,
ExchangeMetaAmount = order.ExchangeMetaAmount,
AccountId = order.AccountId,
UserGuid = order.UserGuid,
PlanetId = order.PlanetId,
CaliverseItemType = order.CaliverseItemType,
CaliverseItemId = order.CaliverseItemId,
CaliverseItemDeltaAmount = order.CaliverseItemDeltaAmount,
PlanetItemType = order.PlanetItemType,
PlanetItemId = order.PlanetItemId,
PlanetItemDeltaAmount = order.PlanetItemDeltaAmount,
CreatedAt = order.CreatedAt,
CompletedAt = order.CompletedAt
};
}

View File

@@ -0,0 +1,139 @@
using System;
using System.Diagnostics.CodeAnalysis;
using ServerCore;
using ServerBase;
using ServerCommon;
namespace BrokerCore.Common;
public static class Guard
{
public static class Against
{
// 기존 메서드를 유지하면서 zero allocation 버전 추가
public static void resultFail(Result result, Func<string>? messageFactory = null)
{
if (result.isFail())
{
throw new ResultFailException(result, messageFactory?.Invoke());
}
}
// Func<string> 활용 지연 평가 버전 추가
// public static void resultFail(Result result, Func<string> messageFactory)
// {
// if (result.isFail())
// {
// throw new ResultFailException(result, messageFactory());
// }
// }
public static void resultFail(Result result, ServerErrorCode code, string message)
{
if (result.isFail())
{
throw new ResultFailException(code, message);
}
}
// Func<string> 활용 지연 평가 버전 추가
public static void resultFail(Result result, ServerErrorCode code, Func<string> messageFactory)
{
if (result.isFail())
{
throw new ResultFailException(code, messageFactory());
}
}
public static void isNull([NotNull] object? value, ServerErrorCode code, string message)
{
if (value is null)
{
throw new ApiException(code, message);
}
}
// Func<string> 활용 지연 평가 버전 추가
public static void isNull([NotNull] object? value, ServerErrorCode code, Func<string> messageFactory)
{
if (value is null)
{
throw new ApiException(code, messageFactory());
}
}
public static void isFalse(bool value, ServerErrorCode code, string message)
{
if (!value)
{
throw new ApiException(code, message);
}
}
// Func<string> 활용 지연 평가 버전 추가
public static void isFalse(bool value, ServerErrorCode code, Func<string> messageFactory)
{
if (!value)
{
throw new ApiException(code, messageFactory());
}
}
public static void isTrue(bool value, ServerErrorCode code, string message)
{
if (value)
{
throw new ApiException(code, message);
}
}
// Func<string> 활용 지연 평가 버전 추가
public static void isTrue(bool value, ServerErrorCode code, Func<string> messageFactory)
{
if (value)
{
throw new ApiException(code, messageFactory());
}
}
public static void isNullOrEmptyOrWhiteSpace([NotNull] string? value, ServerErrorCode code, string message)
{
if (value is null || string.IsNullOrEmpty(value) || string.IsNullOrWhiteSpace(value))
{
throw new ApiException(code, message);
}
}
// Func<string> 활용 지연 평가 버전 추가
public static void isNullOrEmptyOrWhiteSpace([NotNull] string? value, ServerErrorCode code, Func<string> messageFactory)
{
if (value is null || string.IsNullOrEmpty(value) || string.IsNullOrWhiteSpace(value))
{
throw new ApiException(code, messageFactory());
}
}
// ReadOnlySpan<char> 버전 추가
public static void isNullOrEmptyOrWhiteSpace([NotNull] string? value, ServerErrorCode code, ReadOnlySpan<char> message)
{
if (value is null || string.IsNullOrEmpty(value) || string.IsNullOrWhiteSpace(value))
{
throw new ApiException(code, message.ToString());
}
}
public static void throwException(ServerErrorCode code, string message)
{
throw new ApiException((int)code, message);
}
// Func<string> 활용 지연 평가 버전 추가
public static void throwException(ServerErrorCode code, Func<string> messageFactory)
{
throw new ApiException((int)code, messageFactory());
}
}
}

View File

@@ -0,0 +1,92 @@
namespace BrokerCore.Common;
using System.Security.Cryptography;
using BrokerBusinessLog;
using DbEntity;
using Entity.Actions;
using MetaAssets;
using ServerCommon;
using ServerCore; using ServerBase;
public class Helpers
{
public static string generateSecureKey(int keySizeInBytes = 32, bool isBase64 = true)
{
// 32바이트는 256비트 키를 의미합니다. (AES-256과 같은 암호화 알고리즘에 적합)
using var random_number_generator = RandomNumberGenerator.Create();
byte[] key = new byte[keySizeInBytes];
random_number_generator.GetBytes(key);
return isBase64 ? Convert.ToBase64String(key) : Convert.ToHexString(key);
}
public static MailSendOption createMailOptionByProductMeta(
ProductMetaData productMeta,
SystemMailMetaData mailMeta,
string receiverUserGuid,
string receiverNickName)
{
DateTime now = DateTimeHelper.Current;
var expire_date = now.AddSeconds(MetaHelper.GameConfigMeta.SystemMailStoragePeriod);
// if (productMeta.Storage_Period_First != 0)
// {
// expire_date = DateTime.UtcNow.AddMinutes(productMeta.Storage_Period_First);
// }
var mail_send_option = new MailSendOption
{
ReceiverUserGuid = receiverUserGuid,
ReceiverNickName = receiverNickName,
IsSystemMail = true,
IsTextByMetaData = true,
Title = mailMeta.Mail_Title,
Text = mailMeta.Mail_Desc,
ExpireDate = expire_date,
ItemList = getMailItems(productMeta).ToList(),
PackageOrderId = string.Empty,
};
return mail_send_option;
}
public static IEnumerable<MailItem> getMailItems(ProductMetaData productMetaData)
{
if (productMetaData.ItemID_First != 0)
{
return productMetaData.First_List.Select(itemMeta => new MailItem()
{
ItemId = (UInt32)itemMeta.Id,
Count = itemMeta.Value,
ProductId = (UInt32)productMetaData.Id,
isRepeatProduct = false
});
}
return new List<MailItem>();
}
public static PlanetItemExchangeLogData createFromExchangeOrderLog(PlanetItemExchangeOrder order)
{
return new PlanetItemExchangeLogData
{
OrderId = order.OrderId,
OrderStatus = order.OrderStatus.ToString(),
ExchangeMetaId = order.ExchangeMetaId,
ExchangeMetaAmount = order.ExchangeMetaAmount,
AccountId = order.AccountId,
UserGuid = order.UserGuid,
PlanetId = order.PlanetId,
SeasonId = order.SeasonId,
CaliverseItemType = order.CaliverseItemType.ToString(),
CaliverseItemId = order.CaliverseItemId,
CaliverseItemDeltaAmount = order.CaliverseItemDeltaAmount,
PlanetItemType = order.PlanetItemType.ToString(),
PlanetItemId = order.PlanetItemId,
PlanetItemDeltaAmount = order.PlanetItemDeltaAmount,
CreatedAt = order.CreatedAt,
CompletedAt = order.CompletedAt
};
}
}

View File

@@ -0,0 +1,12 @@
//==============================================================
// JWT 설정 정보를 담고있는 클래스입니다.
//==============================================================
namespace BrokerCore.Common;
public class JwtOption
{
public string ValidIssuer { get; set; } = string.Empty;
public string ValidAudience { get; set; } = string.Empty;
public required string Secret { get; init; } // JWT 토큰 서명에 사용되는 비밀키
public int TokenValidityInMinutes { get; init; } = 1440; // 토큰의 유효 기간(분)
public string JwtTestPassToken => "p8qcZBraFCGfm2QeIGkJBynb6ULKhi6wGlnCDXvKTnM";
}

View File

@@ -0,0 +1,12 @@
namespace BrokerCore.Common;
public class ResultFailException : ApiException
{
public ResultFailException(Result result, string? message = null) : base((int)result.ErrorCode,
message ?? result.ResultString)
{
}
public ResultFailException(ServerErrorCode code, string message) : base((int)code, message)
{
}
}