초기커밋

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,181 @@

using ServerCore;
using ServerBase;
using ServerCommon;
namespace BrokerCore;
using NLog.Config;
using MODULE_ID = System.UInt32;
public sealed class BrokerServerLogic : IServerLogic, IWithLogActor, IInitializer
{
private ServerProgramVersion m_server_program_version = new ServerProgramVersion();
private readonly DynamoDbClient m_dynamo_db_client = new();
private readonly ServerConfigMetaverseBroker m_server_config;
private readonly ServerType m_server_type = ServerType.BrokerApi;
private readonly string m_server_name = ServerType.BrokerApi.ToString();
private bool m_is_initialized = false;
public BrokerServerLogic(ServerConfigMetaverseBroker serverConfig)
{
m_server_config = serverConfig;
}
public IModule getModule(MODULE_ID moduleId) { throw new NullReferenceException(); }
public Result registerEntityTicker(EntityTicker entityTicker) { throw new NullReferenceException(); }
public async Task<Result> onInit()
{
if (m_is_initialized)
{
return new Result();
}
m_is_initialized = true;
Log.initLog(ServerType.BrokerApi.ToString(), "Developer", onNLogConfigurationChanged);
onInitBusinessLog();
var result = await onInitDynamoDb();
return result;
}
private async Task<Result> onInitDynamoDb()
{
var result = new Result();
var server_config = getServerConfig();
(var error_code, var to_load_table_names) = ServerConfigHelper.getDynamoDbTableNamesWithServiceType(server_config.ServiceType);
if (error_code.isFail())
{
var err_msg = $"Failed to DynamoDbClient.getDynamoDbTableNameWithServiceType() !!! : {server_config.toBasicString()} - {toBasicString()}";
result.setFail(error_code, err_msg);
Log.getLogger().error(err_msg);
return result;
}
var dynamo_db_client = getDynamoDbClient();
result = dynamo_db_client.connectToDb( to_load_table_names
, server_config.AWS.LocalDynamoDB, server_config.Dynamodb
, server_config.AWS.AccessKey, server_config.AWS.SecretKey, server_config.AWS.Region );
if (result.isFail())
{
Log.getLogger().error($"Failed to connectToDb !!! ");
return result;
}
if (false == await dynamo_db_client.createDBIfNotExists(false))
{
var err_msg = $"Failed to create DB Table !!! - {toBasicString()}";
result.setFail(ServerErrorCode.DynamoDbTableCreateFailed, err_msg);
Log.getLogger().fatal(result.toBasicString());
return result;
}
Log.getLogger().info($"Success ServerLogicBase.onInitDatabase() - {toBasicString()}");
return result;
}
private void onInitBusinessLog()
{
BusinessLogger.setup(new NLogAppender()
, new JsonText()
, LogTransToOutputType.TransToMultyLine);
Log.getLogger().info($"Success ServerLogicBase.onInitBusinessLog() - {toBasicString()}");
}
private void onNLogConfigurationChanged(object? sender, LoggingConfigurationChangedEventArgs e)
{
var result = new Result();
var err_msg = string.Empty;
var server_config = getServerConfig();
if (server_config.AWS.CloudWatchLog.Enable)
{
result = setupCloudwatchLog(server_config);
if (result.isFail())
{
err_msg = $"Failed to setupCloudwatchLog() !!! in onNLogConfigurationChanged() : {result.toBasicString()} - {toBasicString()}";
Log.getLogger().fatal(err_msg);
}
}
return;
Result setupCloudwatchLog(ServerConfig serverConfig)
{
var result = new Result();
var err_msg = string.Empty;
if(false == CloudWatchLog.isOpened())
{
return result;
}
if (false == CloudWatchLog.setup( serverConfig.AWS.CloudWatchLog.CloudWatchLogGroup
, serverConfig.AWS.CloudWatchLog.CloudWatchLogNamePattern
, serverConfig.AWS.CloudWatchLog.CloudWatchLogLevel
, serverConfig.AWS.Region
, serverConfig.AWS.AccessKey
, serverConfig.AWS.SecretKey
, serverConfig.AWS.CloudWatchLog.CloudWatchLogLayout) )
{
err_msg = $"Failed to CloudWatchLog.setup() !!! - {toBasicString()}";
result.setFail(ServerErrorCode.NlogWithAwsCloudWatchSetupFailed, err_msg);
Log.getLogger().fatal(result.toBasicString());
return result;
}
return result;
}
}
public ILogActor toLogActor()
{
var log_info = new LogicActorLog();
log_info.initLogInfo(
this.getServerConfig().getRegionId()
, this.getServerConfig().getWorldId()
, this.getServerType().toServerType()
, this.getServerName()
);
return log_info;
}
public string toBasicString()
{
return $"{m_server_name}({m_server_type})";
}
public string getServerType()
{
return m_server_type.ToString();
}
public string getServerName()
{
return m_server_name;
}
public ServerConfig getServerConfig()
{
return m_server_config;
}
public RedisConnector getRedisConnector()
{
throw new NotImplementedException();
}
public DynamoDbClient getDynamoDbClient()
{
return m_dynamo_db_client;
}
}