초기커밋
This commit is contained in:
@@ -0,0 +1,401 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
using META_ID = System.UInt32;
|
||||
|
||||
|
||||
namespace GameServer;
|
||||
|
||||
public class TestUserInitializer : SimpleEventTriggerBase
|
||||
{
|
||||
private readonly Player m_owner;
|
||||
|
||||
private bool m_is_completed_prepare_intialize = false;
|
||||
|
||||
private readonly List<QueryExecutorBase> m_query_executor_bases = new();
|
||||
|
||||
private bool m_is_test_user = false;
|
||||
|
||||
private ServerCommon.BusinessLogDomain.UserInitialLogInfo m_user_initial_log = new();
|
||||
private ServerCommon.BusinessLogDomain.UserLogInfo m_user_log = new();
|
||||
|
||||
public TestUserInitializer(Player owner)
|
||||
{
|
||||
m_owner = owner;
|
||||
}
|
||||
|
||||
public async Task<Result> onPrepareInitializer()
|
||||
{
|
||||
var owner = getOwner();
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
var dynamo_db_connector = server_logic.getDynamoDbClient();
|
||||
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var account_attribute = owner.getEntityAttribute<AccountAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(account_attribute, () => $"account_attribute is null !!! - {owner.toBasicString()}");
|
||||
var user_attribute = owner.getEntityAttribute<UserAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(user_attribute, () => $"user_attribute is null !!! - {owner.toBasicString()}");
|
||||
var inventory_action_base = owner.getEntityAction<InventoryActionBase>();
|
||||
NullReferenceCheckHelper.throwIfNull(inventory_action_base, () => $"inventory_action_base is null !!! - {owner.toBasicString()}");
|
||||
|
||||
var account_id = account_attribute.AccountId;
|
||||
var user_guid = user_attribute.UserGuid;
|
||||
var selected_character_guid = user_attribute.SelectedCharacterGuid;
|
||||
|
||||
foreach (var meta_data in MetaData.Instance.m_test_user_initial_meta_datas.Values)
|
||||
{
|
||||
if (false == account_id.StartsWith(meta_data.IdPattern, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//=================================================================================
|
||||
// Intialize Items of Inventories
|
||||
//=================================================================================
|
||||
if (true == meta_data.IsInventoryInitialize)
|
||||
{
|
||||
inventory_action_base.onClear();
|
||||
|
||||
m_query_executor_bases.Add(new DBQEntityDeleteAfterReadAll<ItemDoc>(user_guid));
|
||||
|
||||
var inventory_action = owner.getEntityAction<InventoryActionBase>();
|
||||
NullReferenceCheckHelper.throwIfNull(inventory_action, () => $"inventory_action is null !!! - {owner.toBasicString()}");
|
||||
|
||||
await inventory_action.clearItemAllFromMemory();
|
||||
}
|
||||
|
||||
//=================================================================================
|
||||
// Intialize Mails
|
||||
//=================================================================================
|
||||
if (meta_data.IsMailInitialize)
|
||||
{
|
||||
m_query_executor_bases.Add(new DBQEntityDeleteAfterReadAll<ReceivedMailDoc>(user_guid));
|
||||
m_query_executor_bases.Add(new DBQEntityDeleteAfterReadAll<SentMailDoc>(user_guid));
|
||||
m_query_executor_bases.Add(new DBQEntityDeleteAfterReadAll<MailProfileDoc>(user_guid));
|
||||
}
|
||||
|
||||
//=================================================================================
|
||||
// Intialize SocialActionDoc
|
||||
//=================================================================================
|
||||
if (meta_data.IsSocialActionInitialize)
|
||||
{
|
||||
m_query_executor_bases.Add(new DBQEntityDeleteAfterReadAll<SocialActionDoc>(user_guid));
|
||||
}
|
||||
|
||||
//=================================================================================
|
||||
// Intialize Customize State of CharacterBaseDoc
|
||||
//=================================================================================
|
||||
if (meta_data.IsAvatarCustomize)
|
||||
{
|
||||
if (true == selected_character_guid.isNullOrWhiteSpace())
|
||||
{
|
||||
err_msg = $"Not selected Character !!!, to Customize - {toBasicString()}, {owner.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBQEntityWriteAfterRead<CharacterBaseDoc>.FnEntityWrite entity_write_func = async delegate (List<CharacterBaseDoc> readCharacterBaseDocs)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
if (0 >= readCharacterBaseDocs.Count)
|
||||
{
|
||||
err_msg = $"No read CharacterBaseDoc !!!";
|
||||
Log.getLogger().warn(err_msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
var found_character_base_doc = readCharacterBaseDocs.Find(x => x.getAttrib<CharacterBaseAttrib>()?.CharacterGuid == selected_character_guid);
|
||||
if (null == found_character_base_doc)
|
||||
{
|
||||
err_msg = $"Not found CharacterBaseDoc !!! - {owner.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.CharacterNotFound, err_msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
var character_base_attrib = found_character_base_doc.getAttrib<CharacterBaseAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(character_base_attrib, () => $"character_base_attrib is null - {owner.toBasicString()}");
|
||||
|
||||
character_base_attrib.ApperanceProfileValue.IsCustomCompleted = false;
|
||||
await found_character_base_doc.updateDoc4Query();
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
m_query_executor_bases.Add(new DBQEntityWriteAfterRead<CharacterBaseDoc>(user_guid, selected_character_guid, entity_write_func));
|
||||
}
|
||||
}
|
||||
|
||||
//=================================================================================
|
||||
// Create Items of TestUserCreate Meta
|
||||
//=================================================================================
|
||||
if (meta_data.IsResetToItemsOfTestUserCreate)
|
||||
{
|
||||
if(false == meta_data.IsInventoryInitialize)
|
||||
{
|
||||
m_query_executor_bases.Add(new DBQEntityDeleteAfterReadAll<ItemDoc>(user_guid));
|
||||
|
||||
var inventory_action = owner.getEntityAction<InventoryActionBase>();
|
||||
NullReferenceCheckHelper.throwIfNull(inventory_action, () => $"inventory_action is null !!! - {owner.toBasicString()}");
|
||||
|
||||
await inventory_action.clearItemAllFromMemory();
|
||||
}
|
||||
|
||||
(result, var found_test_user_create_data) = await MetaHelper.getTestUserCreateDataByAccountId(account_id);
|
||||
if (result.isSuccess())
|
||||
{
|
||||
NullReferenceCheckHelper.throwIfNull(found_test_user_create_data, () => $"found_test_user_create_data is null !!! - {owner.toBasicString()}");
|
||||
|
||||
(result, var created_item_docs) = await TestUserCreator.createItemDocsByTestUserCreateData(owner, found_test_user_create_data);
|
||||
if(result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
NullReferenceCheckHelper.throwIfNull(created_item_docs, () => $"created_item_docs is null - {owner.toBasicString()}");
|
||||
|
||||
m_query_executor_bases.Add(new DBQEntityWrite(created_item_docs));
|
||||
}
|
||||
}
|
||||
|
||||
//=================================================================================
|
||||
// Intialize MoneyDoc
|
||||
//=================================================================================
|
||||
{
|
||||
DBQEntityWriteAfterRead<MoneyDoc>.FnEntityWrite entity_write_func = async delegate (List<MoneyDoc> readMoneyDocs)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
if (0 >= readMoneyDocs.Count)
|
||||
{
|
||||
err_msg = $"No read readMoneyDocs !!!";
|
||||
Log.getLogger().warn(err_msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
var found_money_doc = readMoneyDocs.Find(x => x.getAttrib<MoneyAttrib>()?.OwnerGuid == user_guid);
|
||||
if (null == found_money_doc)
|
||||
{
|
||||
err_msg = $"Not found found_money_doc !!! - {owner.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.UserMoneyDocEmpty, err_msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
var money_attrib = found_money_doc.getAttrib<MoneyAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(money_attrib, () => $"money_attrib is null - {owner.toBasicString()}");
|
||||
|
||||
if (true == CurrencyType.Gold.isBalanceWithinMaxCurrency(meta_data.CurrencyGold))
|
||||
{
|
||||
money_attrib.Gold = meta_data.CurrencyGold;
|
||||
}
|
||||
if (true == CurrencyType.Gold.isBalanceWithinMaxCurrency(meta_data.currency_sapphire))
|
||||
{
|
||||
money_attrib.Sapphire = meta_data.currency_sapphire;
|
||||
}
|
||||
if (true == CurrencyType.Gold.isBalanceWithinMaxCurrency(meta_data.currency_calium))
|
||||
{
|
||||
money_attrib.Calium = meta_data.currency_calium;
|
||||
}
|
||||
if (true == CurrencyType.Gold.isBalanceWithinMaxCurrency(meta_data.currency_ruby))
|
||||
{
|
||||
money_attrib.Ruby = meta_data.currency_ruby;
|
||||
}
|
||||
await found_money_doc.updateDoc4Query();
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
m_query_executor_bases.Add(new DBQEntityWriteAfterRead<MoneyDoc>(user_guid, "", entity_write_func));
|
||||
}
|
||||
|
||||
//=================================================================================
|
||||
// Intialize LocationDoc
|
||||
//=================================================================================
|
||||
{
|
||||
DBQEntityWriteAfterRead<LocationDoc>.FnEntityWrite entity_write_func = async delegate (List<LocationDoc> readLocationDocs)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
if (0 >= readLocationDocs.Count)
|
||||
{
|
||||
err_msg = $"No read readLocationDocs !!!";
|
||||
Log.getLogger().warn(err_msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (readLocationDocs.Count > 1)
|
||||
{
|
||||
err_msg = $"More than One registered LocationDoc !!! : TgtDoc:{typeof(LocationDoc).Name} - {owner.toBasicString()}";
|
||||
Log.getLogger().warn(result.toBasicString());
|
||||
}
|
||||
|
||||
var found_location_doc = readLocationDocs[0];
|
||||
|
||||
var location_attrib = found_location_doc.getAttrib<LocationAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(location_attrib, () => $"location_attrib is null - {owner.toBasicString()}");
|
||||
|
||||
location_attrib.LastConnectedChannelServerLocation.fromPos(new Pos() { X = meta_data.StartX, Y = meta_data.StartY, Z = meta_data.StartZ, Angle = meta_data.StartAngle });
|
||||
|
||||
await found_location_doc.updateDoc4Query();
|
||||
|
||||
// 테스트 유저 입장 처리를 위해 설정 한다. !!!
|
||||
setTestUser(true);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
m_query_executor_bases.Add(new DBQEntityWriteAfterRead<LocationDoc>(user_guid, "", entity_write_func));
|
||||
}
|
||||
|
||||
//=================================================================================
|
||||
// Intialize Myhomes
|
||||
//=================================================================================
|
||||
if (meta_data.IsMyHomeInitialize)
|
||||
{
|
||||
MyhomeUgcInfo? myhome_ugc_info;
|
||||
|
||||
if (meta_data.MyhomeFile == string.Empty)
|
||||
{
|
||||
var default_myhome_ugc_info_file_name = MetaHelper.GameConfigMeta.MyHomeDefaultSaveFileName;
|
||||
if (!MapManager.Instance.getDefaultMyhomeUgcInfo(default_myhome_ugc_info_file_name, out myhome_ugc_info))
|
||||
{
|
||||
err_msg = $"Failed to getDefaultMyhomeUgcInfo() !!! : {default_myhome_ugc_info_file_name} : {this.getTypeName()}";
|
||||
result.setFail(ServerErrorCode.MyhomeUgcInfoFileNotFoune, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!MapManager.Instance.getDefaultMyhomeUgcInfo(meta_data.MyhomeFile, out myhome_ugc_info))
|
||||
{
|
||||
err_msg = $"Failed to getDefaultMyhomeUgcInfo() !!! : {meta_data.MyhomeFile} : {this.getTypeName()}";
|
||||
result.setFail(ServerErrorCode.MyhomeUgcInfoFileNotFoune, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
m_query_executor_bases.Add(new DBQMyhomeInitializeForTestUser(user_guid, myhome_ugc_info));
|
||||
}
|
||||
|
||||
(result, var user_doc) = await user_attribute.toDocBase(false);
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to toDocBase() !!! : {result.toBasicString()} - {owner.toBasicString()}";
|
||||
Log.getLogger().warn(err_msg);
|
||||
|
||||
return result;
|
||||
}
|
||||
NullReferenceCheckHelper.throwIfNull(user_doc, () => $"user_doc is null !!! - {owner.toBasicString()}");
|
||||
|
||||
// UserCreate 로그 설정
|
||||
m_user_initial_log.UserGuid = user_attribute.UserGuid;
|
||||
m_user_initial_log.UserPK = user_doc.getPK();
|
||||
m_user_initial_log.UserSK = user_doc.getSK();
|
||||
m_user_initial_log.UserInitialMetaType = meta_data.getTypeName();
|
||||
m_user_initial_log.UserInitialMetaId = (META_ID)meta_data.MetaId;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
setCompetedPrepareInitialize(true);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override async Task<Result> onTriggerEffect()
|
||||
{
|
||||
var owner = getOwner();
|
||||
ArgumentNullException.ThrowIfNull(owner, $"owner is null");
|
||||
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
NullReferenceCheckHelper.throwIfNull(server_logic, () => $"server_logic is null !!! - {owner.toBasicString()}");
|
||||
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
if (false == isCompletedPrepareInitialize())
|
||||
{
|
||||
err_msg = $"Not completed isCompletedPrepareLoad() !!! - {toBasicString()}, {owner.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.UserPrepareLoadNotCompleted, err_msg);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
var batch = new QueryBatchEx<QueryRunnerWithDocument>( owner, LogActionType.TestUserInitial
|
||||
, server_logic.getDynamoDbClient()
|
||||
, false );
|
||||
{
|
||||
foreach(var query_executor in m_query_executor_bases)
|
||||
{
|
||||
batch.addQuery(query_executor);
|
||||
}
|
||||
|
||||
batch.addQuery(new QueryFinal(), completedTestUserInitial);
|
||||
}
|
||||
result = await QueryHelper.sendQueryAndBusinessLog(batch);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
setCompleted();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<QueryBatchBase.QueryResultType> completedTestUserInitial(QueryExecutorBase queryExecutorBase)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
var owner = getOwner();
|
||||
|
||||
var err_msg = string.Empty;
|
||||
|
||||
setCompleted();
|
||||
|
||||
// 생성시 DBEntityWrite 처리 후 DB 에서 다시 로딩하게 되어있다.
|
||||
// 나중에 최적화 목적으로 DBEntityWrite 처리 후 각각의 EntityAttribute 에 적재하는 방안도 고려 하자 !!! - kangms
|
||||
|
||||
var query_batch = queryExecutorBase.getQueryBatch();
|
||||
NullReferenceCheckHelper.throwIfNull(query_batch, () => $"query_batch is null !!! - {owner.toBasicString()}");
|
||||
var log_action = query_batch.getLogAction();
|
||||
NullReferenceCheckHelper.throwIfNull(log_action, () => $"log_action is null !!! - {owner.toBasicString()}");
|
||||
|
||||
m_user_log.setInfo(owner.toUserLogInfo());
|
||||
|
||||
// 비즈니스 로그 추가
|
||||
query_batch.appendBusinessLog(new UserInitialBusinessLog(log_action, m_user_initial_log));
|
||||
query_batch.appendBusinessLog(new UserBusinessLog(log_action, m_user_log));
|
||||
|
||||
return QueryBatchBase.QueryResultType.Success;
|
||||
}
|
||||
|
||||
public bool isCompletedPrepareInitialize() => m_is_completed_prepare_intialize;
|
||||
|
||||
public void setCompetedPrepareInitialize(bool isTrue) => m_is_completed_prepare_intialize = isTrue;
|
||||
|
||||
public bool isTestUser() => m_is_test_user;
|
||||
|
||||
public void setTestUser(bool isTrue) => m_is_test_user = isTrue;
|
||||
|
||||
public Player getOwner() => m_owner;
|
||||
}
|
||||
Reference in New Issue
Block a user