초기커밋

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,212 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Concurrent;
using NLog.Layouts;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Microsoft.AspNetCore.Components;
using Axion.Collections.Concurrent;
using Amazon.DynamoDBv2.Model;
using ServerCore; using ServerBase;
using DYNAMO_DB_TABLE_NAME = System.String;
using DYNAMO_DB_TABLE_FULL_NAME = System.String;
namespace ServerBase;
public static partial class ServerConfigHelper
{
private static ServerConfig? m_server_config;
private static Flags<AuthRule.FlagType> m_auth_rules_flags = new();
private static Dictionary<Tuple<ServerType, ServerType>, LoadBalancingRule.Config> m_load_balancing_rule_configs = new();
public static void init(ServerConfig serverConfig)
{
m_server_config = serverConfig;
initAuthRule(serverConfig);
initLoadBalancingRule(serverConfig);
}
public static int getDefaultMaxUser()
{
NullReferenceCheckHelper.throwIfNull(m_server_config, () => $"m_server_config is null !!!");
return m_server_config.DefaultMaxUser;
}
private static void initAuthRule(ServerConfig serverConfig)
{
var auth_rule = serverConfig.AuthRule;
m_auth_rules_flags.setFlag(AuthRule.FlagType.BotIdAllow, auth_rule.BotIdAllow);
m_auth_rules_flags.setFlag(AuthRule.FlagType.TestIdAllow, auth_rule.TestIdAllow);
m_auth_rules_flags.setFlag(AuthRule.FlagType.ClientStandaloneAllow, auth_rule.ClientStandaloneAllow);
m_auth_rules_flags.setFlag(AuthRule.FlagType.ClientBySsoAccountAuthWithLauncherAllow, auth_rule.ClientBySsoAccountAuthWithLauncherAllow);
}
public static string getSsoAccountDbConnectionString(this ServerConfig serverConfig)
{
return serverConfig.SsoAccountDb;
}
private static void initLoadBalancingRule(ServerConfig serverConfig)
{
var load_balancing_rule = serverConfig.LoadBalancingRule;
m_load_balancing_rule_configs.Add(Tuple.Create<ServerType, ServerType>(ServerType.Login, ServerType.Channel), load_balancing_rule.AuthToGameRule);
m_load_balancing_rule_configs.Add(Tuple.Create<ServerType, ServerType>(ServerType.Channel, ServerType.Indun), load_balancing_rule.ChannelToInstanceDungeonRule);
m_load_balancing_rule_configs.Add(Tuple.Create<ServerType, ServerType>(ServerType.Indun, ServerType.Channel), load_balancing_rule.InstanceDungeonToChannelRule);
m_load_balancing_rule_configs.Add(Tuple.Create<ServerType, ServerType>(ServerType.Channel, ServerType.Channel), load_balancing_rule.ChannelToChannelRule);
}
public static LoadBalancingRule.Config? getLoadBalancingRuleType(ServerType fromServerType, ServerType toServerType)
{
m_load_balancing_rule_configs.TryGetValue(Tuple.Create<ServerType, ServerType>(fromServerType, toServerType), out var rule_config);
if(null == rule_config)
{
rule_config = m_server_config?.LoadBalancingRule.ToEtcServerRule;
}
return rule_config;
}
public static string geAccountNftDbConnectionString(this ServerConfig serverConfig)
{
return serverConfig.AccountNftDb;
}
public static List<PlatformType> toPlatformTypeAllows(this string platformTypeAllows)
{
var platform_type_allows = new List<PlatformType>();
var splitted_value = platformTypeAllows.Split(",");
for(int i = 0; i < splitted_value.Length; i++)
{
var enum_string = splitted_value[i];
var platform_type = EnumHelper.convertEnumValueStringToEnum(enum_string, PlatformType.None);
if(PlatformType.None != platform_type)
{
if(true == platform_type_allows.Exists(x => x == platform_type))
{
continue;
}
platform_type_allows.Add(platform_type);
}
}
return platform_type_allows;
}
public static ServiceType toServiceType( this string serviceType, ServiceType defaultType)
{
return EnumHelper.convertEnumValueStringToEnum(serviceType, defaultType);
}
public static DYNAMO_DB_TABLE_NAME makeDynamoDbTableFullName(string tableName, ServiceType serviceType)
{
ConditionValidCheckHelper.throwIfFalseWithCondition(() => false == tableName.isNullOrWhiteSpace(), () => $"Invalid tableName !!!");
return tableName + "-" + serviceType.ToString();
}
public static (ServerErrorCode, ConcurrentDictionary<DYNAMO_DB_TABLE_NAME, DYNAMO_DB_TABLE_FULL_NAME>) getDynamoDbTableNamesWithServiceType( string serviceType )
{
var target_table_names = new ConcurrentDictionary<DYNAMO_DB_TABLE_NAME, DYNAMO_DB_TABLE_FULL_NAME>();
// 서비스 타입 체크
var enum_service_type = serviceType.convertEnumTypeAndValueStringToEnum<ServiceType>(ServiceType.None);
if ( enum_service_type != ServiceType.Dev
&& enum_service_type != ServiceType.Qa
&& enum_service_type != ServiceType.Stage
&& enum_service_type != ServiceType.Live )
{
return (ServerErrorCode.ServiceTypeInvalid, target_table_names);
}
//=========================================================================================
// 기본 메인 테이블
//=========================================================================================
{
var main_table_name = DynamoDbDefine.TableNames.Main;
var table_full_name = ServerConfigHelper.makeDynamoDbTableFullName(main_table_name, enum_service_type);
if(false == target_table_names.TryAdd(main_table_name, table_full_name)) { return (ServerErrorCode.DynamoDbTableNameDuplicated, target_table_names); }
}
//=========================================================================================
// 기타 추가 DB
//=========================================================================================
return (ServerErrorCode.Success, target_table_names);
}
public static string toClientListenIP(this ServerConfig _this)
{
return AwsHelper.getAwsPublicIPv4OrEthernetIPv4();
}
public static UInt16 toClientListenPort(this ServerConfig _this)
{
if (0 >= _this.ClientListenPort)
{
return _this.getAppParamPort();
}
return _this.ClientListenPort;
}
public static ServerErrorCode fillupCloudWatchLogLayout(this JObject jsonObject, out JsonLayout jsonLayout)
{
JObject? json_object_with_layout = null;
if (JTokenType.Object == jsonObject.Type)
{
json_object_with_layout = jsonObject["Layout"] as JObject;
}
if ( null == json_object_with_layout )
{
jsonLayout = new JsonLayout
{
Attributes =
{
new JsonAttribute("logTime", "${date:universalTime=true:format=yyyy-MM-ddTHH\\:mm\\:ss.fffZ}"),
new JsonAttribute("server", "${event-properties:server}"),
new JsonAttribute("ip/port", "${event-properties:ip/port}"),
new JsonAttribute("threadId", "${threadid}"),
new JsonAttribute("level", "${level:upperCase=true}"),
new JsonAttribute("message", "${message}"),
new JsonAttribute("function", "${event-properties:memberName}"),
new JsonAttribute("filePath", "${event-properties:filePath}"),
new JsonAttribute("lineNumber", "${event-properties:lineNumber}"),
}
};
}
else
{
jsonLayout = new JsonLayout();
var ref_attributes = jsonLayout.Attributes;
foreach (var property in json_object_with_layout.Properties())
{
if (JTokenType.Object != jsonObject.Type)
{
return ServerErrorCode.JsonTypeInvalid;
}
ref_attributes.Add(new JsonAttribute(property.Name, property.Value.ToString()));
}
}
return ServerErrorCode.Success;
}
}