초기커밋
This commit is contained in:
30
GameServer/Entity/Land/Helper/LandBusinessLogHelper.cs
Normal file
30
GameServer/Entity/Land/Helper/LandBusinessLogHelper.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using ServerCore; using ServerBase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
internal static class LandBusinessLogHelper
|
||||
{
|
||||
public static LandLogInfo toLandLogInfo(this Land land)
|
||||
{
|
||||
var land_attribue = land.getEntityAttribute<LandAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(land_attribue, () => $"land_attribue is null !!!");
|
||||
|
||||
var land_log_info = new LandLogInfo();
|
||||
land_log_info.setLandInfo(land_attribue);
|
||||
|
||||
return land_log_info;
|
||||
}
|
||||
|
||||
public static void setLandInfo(this LandLogInfo log, LandAttribute landAttribute)
|
||||
{
|
||||
log.setLogProperty((int)landAttribute.LandMetaId, landAttribute.OwnerUserGuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
216
GameServer/Entity/Land/Helper/LandHelper.cs
Normal file
216
GameServer/Entity/Land/Helper/LandHelper.cs
Normal file
@@ -0,0 +1,216 @@
|
||||
using Amazon.Runtime.Internal;
|
||||
using Org.BouncyCastle.Asn1.Ocsp;
|
||||
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 static class LandHelper
|
||||
{
|
||||
public static async Task<LandInfo> toLandInfo(this Land land)
|
||||
{
|
||||
var land_attribute = land.getEntityAttribute<LandAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(land_attribute, () => $"land_attribute is null !!!");
|
||||
|
||||
var land_info = new LandInfo();
|
||||
|
||||
land_info.LandMetaId = (int)land_attribute.LandMetaId;
|
||||
land_info.LandName = land_attribute.LandName;
|
||||
land_info.LandDescription = land_attribute.Description;
|
||||
land_info.OwnerUserGuid = land_attribute.OwnerUserGuid;
|
||||
|
||||
if (land_attribute.OwnerUserGuid != string.Empty)
|
||||
{
|
||||
var (result, nickname_attrib) = await NicknameDoc.findNicknameFromGuid(land_attribute.OwnerUserGuid);
|
||||
if (result.isSuccess() && nickname_attrib != null)
|
||||
{
|
||||
land_info.OwnerUserNickname = nickname_attrib.Nickname;
|
||||
}
|
||||
}
|
||||
|
||||
return land_info;
|
||||
}
|
||||
|
||||
public static async Task<(Result, Land?, OwnedLand?, DynamoDbDocBase?)> tryGainLand(Player player, int landMetaId)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
if (!MetaData.Instance._LandTable.TryGetValue(landMetaId, out var land_meta_data))
|
||||
{
|
||||
err_msg = $"Failed to MetaData.TryGetValue() !!! : LandMetaId:{landMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandMetaDataNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return (result, null, null, null);
|
||||
}
|
||||
|
||||
if (land_meta_data.Editor != MetaAssets.EditorType.USER)
|
||||
{
|
||||
err_msg = $"Land EditorType is NOT USER !!! : LandMetaId:{landMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandEditorIsNotUser, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return (result, null, null, null);
|
||||
}
|
||||
|
||||
if (!MapManager.Instance.GetLandMapTree(landMetaId, out var land_map_tree))
|
||||
{
|
||||
err_msg = $"Failed to GetLandMapTree() !!! : LandMetaId:{landMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandMapTreeDataNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return (result, null, null, null);
|
||||
}
|
||||
|
||||
var land_manager = server_logic.getLandManager();
|
||||
if (!land_manager.tryGetLand(landMetaId, out var land))
|
||||
{
|
||||
err_msg = $"Failed to tryGetLand() !!! : landMetaId:{landMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return (result, null, null, null);
|
||||
}
|
||||
|
||||
var land_action = land.getEntityAction<LandAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(land_action, () => $"land_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
if (land_action.isExistOwner())
|
||||
{
|
||||
err_msg = $"Land Exist Owner !!! : landMetaId:{landMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandExistOwner, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return (result, null, null, null);
|
||||
}
|
||||
|
||||
var user_guid = player.getUserGuid();
|
||||
land_action.setLandOwner(landMetaId, user_guid);
|
||||
|
||||
var land_attribute = land.getEntityAttribute<LandAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(land_attribute, () => $"land_attribute is null !!! - {player.toBasicString()}");
|
||||
|
||||
(result, var land_doc_base) = await land_attribute.toDocBase();
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to toDocBase() !!! : {result.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
return (result, null, null, null);
|
||||
}
|
||||
NullReferenceCheckHelper.throwIfNull(land_doc_base, () => $"land_doc_base is null !!! - {player.toBasicString()}");
|
||||
|
||||
(result, var owned_land) = await OwnedLandHelper.createOwnedLand(player, landMetaId, OwnedType.Own);
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to createOwnedLand() !!! : {result.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
return (result, null, null, null);
|
||||
}
|
||||
NullReferenceCheckHelper.throwIfNull(owned_land, () => $"owned_land is null !!! - {player.toBasicString()}");
|
||||
|
||||
return (result, land, owned_land, land_doc_base);
|
||||
}
|
||||
|
||||
public static async Task<(Result, Land?, OwnedLand?, DynamoDbDocBase?)> tryInitMyLandOwnership(Player player, int landMetaId)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
if (!MetaData.Instance._LandTable.TryGetValue(landMetaId, out var land_meta_data))
|
||||
{
|
||||
err_msg = $"Failed to MetaData.TryGetValue() !!! : LandMetaId:{landMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandMetaDataNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return (result, null, null, null);
|
||||
}
|
||||
|
||||
if (land_meta_data.Editor != MetaAssets.EditorType.USER)
|
||||
{
|
||||
err_msg = $"Land EditorType is NOT USER !!! : LandMetaId:{landMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandEditorIsNotUser, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return (result, null, null, null);
|
||||
}
|
||||
|
||||
if (!MapManager.Instance.GetLandMapTree(landMetaId, out var land_map_tree))
|
||||
{
|
||||
err_msg = $"Failed to GetLandMapTree() !!! : LandMetaId:{landMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandMapTreeDataNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return (result, null, null, null);
|
||||
}
|
||||
|
||||
var land_manager = server_logic.getLandManager();
|
||||
if (!land_manager.tryGetLand(landMetaId, out var land))
|
||||
{
|
||||
err_msg = $"Failed to tryGetLand() !!! : landMetaId:{landMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return (result, null, null, null);
|
||||
}
|
||||
|
||||
var land_action = land.getEntityAction<LandAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(land_action, () => $"land_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
var user_guid = player.getUserGuid();
|
||||
if (!land_action.isLandOwner(user_guid))
|
||||
{
|
||||
err_msg = $"Land Owner is Not Match !!! : landMetaId:{landMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandOwnerIsNotMatch, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return (result, null, null, null);
|
||||
}
|
||||
|
||||
land_action.initOwner();
|
||||
|
||||
var land_attribute = land.getEntityAttribute<LandAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(land_attribute, () => $"land_attribute is null !!! - {player.toBasicString()}");
|
||||
|
||||
(result, var land_doc_base) = await land_attribute.toDocBase();
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to toDocBase() !!! : {result.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
return (result, null, null, null);
|
||||
}
|
||||
NullReferenceCheckHelper.throwIfNull(land_doc_base, () => $"land_doc_base is null !!! - {player.toBasicString()}");
|
||||
|
||||
var owned_land_agent_action = player.getEntityAction<OwnedLandAgentAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(owned_land_agent_action, () => $"owned_land_agent_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
if (!owned_land_agent_action.tryGetOwnedLand(landMetaId, out var owned_land))
|
||||
{
|
||||
err_msg = $"Failed to tryGetOwnedLand() !!! : landMetaId:{landMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.OwnedLandNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return (result, null, null, null);
|
||||
}
|
||||
|
||||
var owned_land_action = owned_land.getEntityAction<OwnedLandAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(owned_land_action, () => $"owned_land_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
owned_land_action.DeleteOwnedLand();
|
||||
|
||||
return (result, land, owned_land, land_doc_base);
|
||||
}
|
||||
}
|
||||
}
|
||||
130
GameServer/Entity/Land/Helper/LandNotifyHelper.cs
Normal file
130
GameServer/Entity/Land/Helper/LandNotifyHelper.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ServerCommon;
|
||||
using ServerCore; using ServerBase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.WebSockets;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static ClientToGameMessage.Types;
|
||||
using static ServerMessage.Types;
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
internal static class LandNotifyHelper
|
||||
{
|
||||
public static async Task<bool> send_S2C_NTF_LAND_INFOS(this Player player)
|
||||
{
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
var land_manager = server_logic.getLandManager();
|
||||
|
||||
var ntf_packet = new ClientToGame();
|
||||
ntf_packet.Message = new ClientToGameMessage();
|
||||
ntf_packet.Message.NtfLandInfos = new GS2C_NTF_LAND_INFOS();
|
||||
|
||||
var land_infos = await land_manager.getLandInfos();
|
||||
foreach (var land_info in land_infos)
|
||||
{
|
||||
ntf_packet.Message.NtfLandInfos.LandInfos.Add(land_info.LandMetaId, land_info);
|
||||
}
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(player, ntf_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool broadcast_S2C_NTF_LAND_INFOS(LandInfo landInfo)
|
||||
{
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
var users = server_logic.getPlayerManager().getUsers();
|
||||
var players = users.Values.ToArray();
|
||||
|
||||
if (players.Length == 0)
|
||||
return true;
|
||||
|
||||
var ntf_packet = new ClientToGame();
|
||||
ntf_packet.Message = new ClientToGameMessage();
|
||||
ntf_packet.Message.NtfLandInfos = new GS2C_NTF_LAND_INFOS();
|
||||
|
||||
ntf_packet.Message.NtfLandInfos.LandInfos.Add(landInfo.LandMetaId, landInfo);
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(players, ntf_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool broadcast_S2C_NTF_LAND_INFOS(List<LandInfo> landInfos)
|
||||
{
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
var users = server_logic.getPlayerManager().getUsers();
|
||||
var players = users.Values.ToArray();
|
||||
|
||||
if (players.Length == 0)
|
||||
return true;
|
||||
|
||||
var ntf_packet = new ClientToGame();
|
||||
ntf_packet.Message = new ClientToGameMessage();
|
||||
ntf_packet.Message.NtfLandInfos = new GS2C_NTF_LAND_INFOS();
|
||||
|
||||
foreach (var landInfo in landInfos)
|
||||
{
|
||||
ntf_packet.Message.NtfLandInfos.LandInfos.Add(landInfo.LandMetaId, landInfo);
|
||||
}
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(players, ntf_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool send_GS2GS_NTF_MODIFY_LAND_INFO(List<LandInfo> landInfos)
|
||||
{
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
var message = new ServerMessage();
|
||||
|
||||
message.NtfModifyLandInfo = new GS2GS_NTF_MODIFY_LAND_INFO();
|
||||
message.NtfModifyLandInfo.ExceptServerName = server_logic.getServerName();
|
||||
message.NtfModifyLandInfo.LandInfos.AddRange(landInfos);
|
||||
|
||||
var rabbit_mq = server_logic.getRabbitMqConnector() as RabbitMQ4Game;
|
||||
NullReferenceCheckHelper.throwIfNull(rabbit_mq, () => $"rabbit_mq is null !!!");
|
||||
|
||||
rabbit_mq.sendMessageToExchangeAllGame(message);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static async Task<bool> sendNtfModifyLandInfo(Land land)
|
||||
{
|
||||
var land_info = await land.toLandInfo();
|
||||
var land_infos = new List<LandInfo>();
|
||||
land_infos.Add(land_info);
|
||||
|
||||
// 현재 서버 유저
|
||||
broadcast_S2C_NTF_LAND_INFOS(land_info);
|
||||
|
||||
// 다른 서버
|
||||
send_GS2GS_NTF_MODIFY_LAND_INFO(land_infos);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool sendNtfModifyLandInfos(List<LandInfo> landInfos)
|
||||
{
|
||||
broadcast_S2C_NTF_LAND_INFOS(landInfos);
|
||||
|
||||
send_GS2GS_NTF_MODIFY_LAND_INFO(landInfos);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user