초기커밋

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,39 @@
using ServerCommon;
using ServerCore; using ServerBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GameServer
{
internal class OwnedBuildingAction : EntityActionBase
{
public OwnedBuildingAction(OwnedBuilding owner)
: base(owner)
{ }
public override async Task<Result> onInit()
{
var result = new Result();
return await Task.FromResult(result);
}
public override void onClear()
{
return;
}
public void DeleteOwnedBuilding()
{
var owned_building = getOwner() as OwnedBuilding;
NullReferenceCheckHelper.throwIfNull(owned_building, () => $"owned_building is null !!!");
var owned_building_attribute = owned_building.getEntityAttribute<OwnedBuildingAttribute>();
NullReferenceCheckHelper.throwIfNull(owned_building_attribute, () => $"owned_building_attribute is null !!!");
owned_building_attribute.deleteEntityAttribute();
}
}
}

View File

@@ -0,0 +1,87 @@
using ServerCommon;
using ServerCore; using ServerBase;
using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
namespace GameServer
{
internal class OwnedBuildingAgentAction : EntityActionBase
{
ConcurrentDictionary<int, OwnedBuilding> m_owned_buildings = new();
public OwnedBuildingAgentAction(Player owner)
: base(owner)
{ }
public override async Task<Result> onInit()
{
var result = new Result();
return await Task.FromResult(result);
}
public override void onClear()
{
m_owned_buildings.Clear();
}
public bool tryGetOwnedBuilding(int buildingMetaId, [MaybeNullWhen(false)] out OwnedBuilding ownedBuilding)
{
return m_owned_buildings.TryGetValue(buildingMetaId, out ownedBuilding);
}
public List<OwnedBuilding> getOwnedBuildings()
{
return m_owned_buildings.Values.ToList();
}
public bool isOwnedBuilding(int buildingMetaId)
{
return m_owned_buildings.ContainsKey(buildingMetaId);
}
public void addOwnedBuilding(int buildingMetaId, OwnedBuilding ownedBuilding)
{
m_owned_buildings[buildingMetaId] = ownedBuilding;
}
public void removeOwnedBuilding(int buildingMetaId)
{
m_owned_buildings.TryRemove(buildingMetaId, out _);
}
public async Task<Result> tryAddOwnedBuildingFromDoc(OwnedBuildingDoc ownedBuildingDoc)
{
var result = new Result();
var err_msg = string.Empty;
var player = getOwner() as Player;
ArgumentNullException.ThrowIfNull(player);
OwnedBuilding owned_building = new(player);
await owned_building.onInit();
var owned_building_attribute = owned_building.getEntityAttribute<OwnedBuildingAttribute>();
ArgumentNullException.ThrowIfNull(owned_building_attribute);
if (!owned_building_attribute.copyEntityAttributeFromDoc(ownedBuildingDoc))
{
err_msg = $"Failed to copyEntityAttributeFromDoc() !!! to:{owned_building_attribute.getTypeName()}, from:{ownedBuildingDoc.getTypeName()} : {this.getTypeName()}";
result.setFail(ServerErrorCode.DynamoDbDocCopyToEntityAttributeFailed, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
if (!m_owned_buildings.TryAdd((int)owned_building_attribute.BuildingMetaId, owned_building))
{
err_msg = $"Failed to TryAdd() !!! : {owned_building_attribute.toBasicString()} : {this.getTypeName()}";
result.setFail(ServerErrorCode.BuildingDocLoadDuplicatedBuilding, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
return result;
}
}
}

View File

@@ -0,0 +1,114 @@
using ServerCommon;
using ServerCore; using ServerBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GameServer
{
internal class DBQOwnedBuildingReadAll : QueryExecutorBase
{
private string m_combination_key_for_pk = string.Empty;
private string m_pk = string.Empty;
private readonly List<OwnedBuildingDoc> m_to_read_owned_building_docs = new();
public DBQOwnedBuildingReadAll(string combinationKeyForPK)
: base(typeof(DBQOwnedBuildingReadAll).Name)
{
m_combination_key_for_pk = combinationKeyForPK;
}
//=====================================================================================
// DB 쿼리 직전에 준비해야 할 로직들을 작성한다.
//=====================================================================================
public override async Task<Result> onPrepareQuery()
{
var result = new Result();
var err_msg = string.Empty;
var owner = getOwner() as Player;
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
var doc = new OwnedBuildingDoc();
doc.setCombinationKeyForPK(m_combination_key_for_pk);
var error_code = doc.onApplyPKSK();
if (error_code.isFail())
{
err_msg = $"Failed to onApplyPKSK() !!! : {error_code.toBasicString()} - {toBasicString()}, {owner.toBasicString()}";
result.setFail(error_code, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
m_pk = doc.getPK();
return await Task.FromResult(result);
}
//=====================================================================================
// onPrepareQuery()를 성공할 경우 호출된다.
//=====================================================================================
public override async Task<Result> onQuery()
{
var result = new Result();
var err_msg = string.Empty;
var owner = getOwner() as Player;
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
var query_batch = getQueryBatch();
NullReferenceCheckHelper.throwIfNull(query_batch, () => $"query_batch is null !!!");
var db_connector = query_batch.getDynamoDbConnector();
var query_config = db_connector.makeQueryConfigForReadByPKOnly(m_pk);
(result, var read_docs) = await db_connector.simpleQueryDocTypesWithQueryOperationConfig<OwnedBuildingDoc>(query_config, eventTid: query_batch.getTransId());
if (result.isFail())
{
return result;
}
var owned_building_agent_action = owner.getEntityAction<OwnedBuildingAgentAction>();
NullReferenceCheckHelper.throwIfNull(owned_building_agent_action, () => $"owned_building_agent_action is null !!!");
foreach (var read_doc in read_docs)
{
result = await owned_building_agent_action.tryAddOwnedBuildingFromDoc(read_doc);
if (result.isFail())
{
return result;
}
m_to_read_owned_building_docs.Add(read_doc);
}
return await Task.FromResult(result);
}
public List<OwnedBuildingDoc> getToReadOwnedBuildingDocs() => m_to_read_owned_building_docs;
//=====================================================================================
// DB 쿼리를 성공하고, doFnCommit()가 QueryResultType.NotCalledQueryFunc를 반환할 경우 호출된다.
//=====================================================================================
public override async Task onQueryResponseCommit()
{
await Task.CompletedTask;
return;
}
//=====================================================================================
// DB 쿼리를 실패하고, doFnRollback()가 QueryResultType.NotCalledQueryFunc를 반환할 경우 호출된다.
//=====================================================================================
public override async Task onQueryResponseRollback(Result errorResult)
{
await Task.CompletedTask;
return;
}
}
}

View File

@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ServerCore; using ServerBase;
using ServerCommon;
namespace GameServer
{
public static class OwnedBuildingHelper
{
public static async Task<(Result, OwnedBuilding)> createOwnedBuilding(Player player, int buildingMetaId, OwnedType ownedType)
{
var result = new Result();
var err_msg = string.Empty;
var owned_building = new OwnedBuilding(player);
result = await owned_building.onInit();
if (result.isFail())
{
err_msg = $"Failed to OwnedBuilding.onInit() !!! : {result.toBasicString()}";
Log.getLogger().error(err_msg);
return (result, owned_building);
}
var owned_building_attribute = owned_building.getEntityAttribute<OwnedBuildingAttribute>();
NullReferenceCheckHelper.throwIfNull(owned_building_attribute, () => $"owned_building_attribute is null !!!");
owned_building_attribute.BuildingMetaId = (uint)buildingMetaId;
owned_building_attribute.OwnedType = ownedType;
owned_building_attribute.newEntityAttribute();
return (result, owned_building);
}
public static int getBuildingMetaId(this OwnedBuilding ownedBuilding)
{
var owned_building_attribute = ownedBuilding.getEntityAttribute<OwnedBuildingAttribute>();
NullReferenceCheckHelper.throwIfNull(owned_building_attribute, () => $"owned_building_attribute is null !!!");
return (int)owned_building_attribute.BuildingMetaId;
}
}
}

View File

@@ -0,0 +1,54 @@
using ServerCommon;
using ServerCore; using ServerBase;
using static ClientToGameMessage.Types;
namespace GameServer
{
internal static class OwnedBuildingNotifyHelper
{
public static bool send_S2C_NTF_OWNED_BUILDING_INFOS(this Player player)
{
var owned_building_agent_action = player.getEntityAction<OwnedBuildingAgentAction>();
ArgumentNullException.ThrowIfNull(owned_building_agent_action, $"building_agent_action is null !!!");
var ntf_packet = new ClientToGame();
ntf_packet.Message = new ClientToGameMessage();
ntf_packet.Message.NtfOwnedBuildingInfos = new GS2C_NTF_OWNED_BUILDING_INFOS();
var owned_buildings = owned_building_agent_action.getOwnedBuildings();
foreach (var owned_building in owned_buildings)
{
var owned_building_attribute = owned_building.getEntityAttribute<OwnedBuildingAttribute>();
NullReferenceCheckHelper.throwIfNull(owned_building_attribute, () => $"owned_building_attribute is null !!! - {player.toBasicString()}");
ntf_packet.Message.NtfOwnedBuildingInfos.OwnedBuildingInfos.Add((int)owned_building_attribute.BuildingMetaId);
}
if (false == GameServerApp.getServerLogic().onSendPacket(player, ntf_packet))
{
return false;
}
return true;
}
public static bool send_S2C_NTF_OWNED_BUILDING_INFOS(this Player player, OwnedBuilding ownedBuilding)
{
var owned_building_attribute = ownedBuilding.getEntityAttribute<OwnedBuildingAttribute>();
NullReferenceCheckHelper.throwIfNull(owned_building_attribute, () => $"owned_building_attribute is null !!! - {player.toBasicString()}");
var ntf_packet = new ClientToGame();
ntf_packet.Message = new ClientToGameMessage();
ntf_packet.Message.NtfOwnedBuildingInfos = new GS2C_NTF_OWNED_BUILDING_INFOS();
ntf_packet.Message.NtfOwnedBuildingInfos.OwnedBuildingInfos.Add((int)owned_building_attribute.BuildingMetaId);
if (false == GameServerApp.getServerLogic().onSendPacket(player, ntf_packet))
{
return false;
}
return true;
}
}
}

View File

@@ -0,0 +1,38 @@
using ServerCommon;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ServerCore; using ServerBase;
namespace GameServer
{
public class OwnedBuilding : EntityBase
{
public OwnedBuilding(Player parent)
: base(EntityType.OwnedBuilding, parent)
{
}
public override async Task<Result> onInit()
{
var parent = getDirectParent();
NullReferenceCheckHelper.throwIfNull(parent, () => $"parent is null !!!");
addEntityAttribute(new OwnedBuildingAttribute(this, parent));
addEntityAction(new OwnedBuildingAction(this));
return await base.onInit();
}
public override string toBasicString()
{
return $"{this.getTypeName()}, BuildingMetaId:{getOriginEntityAttribute<OwnedBuildingAttribute>()?.BuildingMetaId}";
}
public override string toSummaryString()
{
return $"{this.getTypeName()}, {getEntityAttribute<OwnedBuildingAttribute>()?.toBasicString()}";
}
}
}

View File

@@ -0,0 +1,60 @@
using Google.Protobuf;
using Google.Protobuf.WellKnownTypes;
using ServerCore;
using ServerBase;
using ServerCommon;
using ServerCommon.BusinessLogDomain;
using MetaAssets;
using static ClientToGameReq.Types;
using static ClientToGameRes.Types;
namespace GameServer.PacketHandler;
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.ExchangeBuildingLFPropReq), typeof(ExchangeBuildingLFPropPacketHandler), typeof(GameLoginListener))]
internal class ExchangeBuildingLFPropPacketHandler : PacketRecvHandler
{
public static bool send_S2C_ACK_EXCHANGE_BUILDING_LF_PROP(Player owner, Result result)
{
var ack_packet = new ClientToGame();
ack_packet.Response = new ClientToGameRes();
ack_packet.Response.ErrorCode = result.ErrorCode;
ack_packet.Response.ExchangeBuildingLFPropRes = new ExchangeBuildingLFPropRes();
if (false == GameServerApp.getServerLogic().onSendPacket(owner, ack_packet))
{
return false;
}
return true;
}
public override async Task<Result> onProcessPacket(ISession entityWithSession, Google.Protobuf.IMessage recvMessage)
{
var result = new Result();
var err_msg = string.Empty;
var server_logic = GameServerApp.getServerLogic();
var player = entityWithSession as Player;
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!!");
var req_msg = recvMessage as ClientToGame;
NullReferenceCheckHelper.throwIfNull(req_msg, () => $"req_msg is null !!! - {player.toBasicString()}");
var request = req_msg.Request.ExchangeBuildingLFPropReq;
// 미사용 패킷 정리
result.setFail(ServerErrorCode.FunctionNotImplemented);
send_S2C_ACK_EXCHANGE_BUILDING_LF_PROP(player, result);
await Task.CompletedTask;
return result;
}
}

View File

@@ -0,0 +1,60 @@
using Google.Protobuf;
using Google.Protobuf.WellKnownTypes;
using ServerCore;
using ServerBase;
using ServerCommon;
using ServerCommon.BusinessLogDomain;
using MetaAssets;
using static ClientToGameReq.Types;
using static ClientToGameRes.Types;
namespace GameServer.PacketHandler;
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.ExchangeInstanceReq), typeof(ExchangeInstancePacketHandler), typeof(GameLoginListener))]
internal class ExchangeInstancePacketHandler : PacketRecvHandler
{
public static bool send_S2C_ACK_EXCHANGE_INSTANCE(Player owner, Result result)
{
var ack_packet = new ClientToGame();
ack_packet.Response = new ClientToGameRes();
ack_packet.Response.ErrorCode = result.ErrorCode;
ack_packet.Response.ExchangeInstanceRes = new ExchangeInstanceRes();
if (false == GameServerApp.getServerLogic().onSendPacket(owner, ack_packet))
{
return false;
}
return true;
}
public override async Task<Result> onProcessPacket(ISession entityWithSession, Google.Protobuf.IMessage recvMessage)
{
var result = new Result();
var err_msg = string.Empty;
var server_logic = GameServerApp.getServerLogic();
var player = entityWithSession as Player;
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!!");
var req_msg = recvMessage as ClientToGame;
NullReferenceCheckHelper.throwIfNull(req_msg, () => $"req_msg is null !!! - {player.toBasicString()}");
var request = req_msg.Request.ExchangeInstanceReq;
// 미사용 패킷 정리
result.setFail(ServerErrorCode.FunctionNotImplemented);
send_S2C_ACK_EXCHANGE_INSTANCE(player, result);
await Task.CompletedTask;
return result;
}
}