초기커밋

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,171 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ServerCore; using ServerBase;
using ServerCommon;
using ServerCommon.BusinessLogDomain;
using META_ID = System.UInt32;
using META_TYPE = System.String;
using USER_GUID = System.String;
using System.Runtime.CompilerServices;
using Microsoft.AspNetCore.Http;
namespace GameServer
{
public static class LandAuctionBusinessLogHelper
{
public static void writeBusinessLogByLandAuctionResult( LandAuction landAuction, LandAuctionWinningResult? winningResult
, QueryExecutorBase queryExecutorBase )
{
var query_batch = queryExecutorBase.getQueryBatch();
NullReferenceCheckHelper.throwIfNull(query_batch, () => $"query_batch is null !!! - {landAuction.toBasicString()}");
query_batch.appendBusinessLog(new LandAuctionBusinessLog(query_batch.getLogAction(), landAuction.toLandAuctionLogInfo(winningResult)));
}
public static void writeBusinessLogByLandAuctionBid( LandAuction landAuction, LandAuctionBidResult bidResult
, QueryExecutorBase queryExecutorBase)
{
var query_batch = queryExecutorBase.getQueryBatch();
NullReferenceCheckHelper.throwIfNull(query_batch, () => $"query_batch is null !!! - {landAuction.toBasicString()}");
query_batch.appendBusinessLog(new LandAuctionBusinessLog(query_batch.getLogAction(), landAuction.toLandAuctionLogInfo(null)));
query_batch.appendBusinessLog(new LandAuctionBidBusinessLog(query_batch.getLogAction(), landAuction.toLandAuctionBidLogInfo(bidResult)));
}
public static void writeBusinessLogByLandAuctionBidPriceRefund( LandAuctionRefundBidPriceDoc refundBidPriceDoc, LandAuctionResult auctionResult
, QueryExecutorBase queryExecutorBase )
{
var query_batch = queryExecutorBase.getQueryBatch();
NullReferenceCheckHelper.throwIfNull(query_batch, () => $"query_batch is null !!! - {refundBidPriceDoc.toBasicString()}");
query_batch.appendBusinessLog(new LandAuctionBidPriceRefundBusinessLog(query_batch.getLogAction(), refundBidPriceDoc.toLandAuctionBidPriceRefundLogInfo(auctionResult)));
}
public static void writeBusinessLogByLandAuctionBidPriceRefund( LandAuctionRefundBidPrice refundBidPrice, LandAuctionResult auctionResult
, QueryExecutorBase queryExecutorBase )
{
var query_batch = queryExecutorBase.getQueryBatch();
NullReferenceCheckHelper.throwIfNull(query_batch, () => $"query_batch is null !!! - {refundBidPrice.toBasicString()}");
query_batch.appendBusinessLog(new LandAuctionBidPriceRefundBusinessLog(query_batch.getLogAction(), refundBidPrice.toLandAuctionBidPriceRefundLogInfo(auctionResult)));
}
public static void writeBusinessLogByLandAuctionActivity(LandAuctionActivityDoc activityDoc)
{
var activity_attrib = activityDoc.getAttrib<LandAuctionActivityAttrib>();
NullReferenceCheckHelper.throwIfNull(activity_attrib, () => $"activity_attrib is null !!!");
var log_action = new LogActionEx(LogActionType.LandAuctionActivity);
var log_info = new LandAuctionActivityLogInfo();
log_info.setLogProperty( activity_attrib.LandMetaId, activity_attrib.AuctionNumber
, activityDoc.getPK(), activityDoc.getSK()
, DateTimeHelper.Current);
var error_code = BusinessLogger.collectLog( GameServerApp.getServerLogic()
, new LandAuctionActivityBusinessLog(log_action, log_info) );
if(error_code.isFail())
{
var err_msg = $"Failed to collectLog() !!! : {error_code.toBasicString()} - {log_info.getTypeName()}";
Log.getLogger().error(err_msg);
}
}
public static LandAuctionBidPriceRefundLogInfo toLandAuctionBidPriceRefundLogInfo(this LandAuctionRefundBidPriceDoc refundBidPriceDoc, LandAuctionResult auctionResult)
{
var refund_bid_price_attrib = refundBidPriceDoc.getAttrib<LandAuctionRefundBidPriceAttrib>();
NullReferenceCheckHelper.throwIfNull(refund_bid_price_attrib, () => $"refund_bid_price_attrib is null !!! - {refundBidPriceDoc.toBasicString()}");
var log_info = new LandAuctionBidPriceRefundLogInfo();
log_info.setLogProperty( refund_bid_price_attrib.LandMetaId, refund_bid_price_attrib.AuctionNumber
, refundBidPriceDoc.getPK(), refundBidPriceDoc.getSK()
, refund_bid_price_attrib.BidUserGuid
, refund_bid_price_attrib.LastBidType, refund_bid_price_attrib.BidCurrencyType, refund_bid_price_attrib.LastBidPrice
, auctionResult
, refund_bid_price_attrib.RefundableNormalBidPrice, refund_bid_price_attrib.RefundableBlindBidPrice);
return log_info;
}
public static LandAuctionBidPriceRefundLogInfo toLandAuctionBidPriceRefundLogInfo(this LandAuctionRefundBidPrice refundBidPrice, LandAuctionResult auctionResult)
{
var refund_bid_price_attribute = refundBidPrice.getEntityAttribute<LandAuctionRefundBidPriceAttribute>();
NullReferenceCheckHelper.throwIfNull(refund_bid_price_attribute, () => $"refund_bid_price_attribute is null !!! - {refundBidPrice.toBasicString()}");
var origin_refund_bid_price_doc = refund_bid_price_attribute.getOriginDocBase<LandAuctionRefundBidPriceAttribute>() as LandAuctionRefundBidPriceDoc;
NullReferenceCheckHelper.throwIfNull(origin_refund_bid_price_doc, () => $"origin_refund_bid_price_doc is null !!! - {refundBidPrice.toBasicString()}");
var log_info = new LandAuctionBidPriceRefundLogInfo();
log_info.setLogProperty( refund_bid_price_attribute.LandMetaId, refund_bid_price_attribute.AuctionNumber
, origin_refund_bid_price_doc.getPK(), origin_refund_bid_price_doc.getSK()
, refund_bid_price_attribute.BidUserGuid
, refund_bid_price_attribute.LastBidType, refund_bid_price_attribute.BidCurrencyType, refund_bid_price_attribute.LastBidPrice
, auctionResult
, refund_bid_price_attribute.RefundableNormalBidPrice, refund_bid_price_attribute.RefundableBlindBidPrice );
return log_info;
}
public static LandAuctionBidLogInfo toLandAuctionBidLogInfo(this LandAuction landAuction, LandAuctionBidResult bidResult)
{
var highest_bid_user_attribute = landAuction.getEntityAttribute<LandAuctionHighestBidUserAttribute>();
NullReferenceCheckHelper.throwIfNull(highest_bid_user_attribute, () => $"highest_bid_user_attribute is null !!! - {landAuction.toBasicString()}");
var origin_highest_bid_user_doc = highest_bid_user_attribute.getOriginDocBase<LandAuctionHighestBidUserAttribute>() as LandAuctionHighestBidUserDoc;
NullReferenceCheckHelper.throwIfNull(origin_highest_bid_user_doc, () => $"origin_highest_bid_user_doc is null !!! - {landAuction.toBasicString()}");
var log_info = new LandAuctionBidLogInfo();
log_info.setLogProperty( highest_bid_user_attribute.LandMetaId, highest_bid_user_attribute.AuctionNumber
, origin_highest_bid_user_doc.getPK(), origin_highest_bid_user_doc.getSK()
, bidResult.CurrentBidType
, highest_bid_user_attribute.BidCurrencyType
, highest_bid_user_attribute.HighestBidPrice, highest_bid_user_attribute.HighestBidUserGuid, highest_bid_user_attribute.HighestBidUserNickname
, highest_bid_user_attribute.NormalHighestBidPrice, highest_bid_user_attribute.NormalHighestBidUserGuid, highest_bid_user_attribute.NormalHighestBidUserNickname
, bidResult.BidTime );
return log_info;
}
public static LandAuctionLogInfo toLandAuctionLogInfo(this LandAuction landAuction, LandAuctionWinningResult? winningResult)
{
var registry_attribute = landAuction.getEntityAttribute<LandAuctionRegistryAttribute>();
NullReferenceCheckHelper.throwIfNull(registry_attribute, () => $"registry_attribute is null !!! - {landAuction.toBasicString()}");
var winning_user_guid = string.Empty;
var winning_user_nickname = string.Empty;
if(null != winningResult)
{
winning_user_guid = winningResult.WinningUserGuid;
winning_user_guid = winningResult.WinningUserNickname;
}
var origin_registry_doc = registry_attribute.getOriginDocBase<LandAuctionRegistryAttribute>() as LandAuctionRegistryDoc;
NullReferenceCheckHelper.throwIfNull(origin_registry_doc, () => $"origin_registry_doc is null !!! - {landAuction.toBasicString()}");
var log_info = new LandAuctionLogInfo();
log_info.setLogProperty( registry_attribute.LandMetaId, registry_attribute.AuctionNumber
, origin_registry_doc.getPK(), origin_registry_doc.getSK()
, registry_attribute.BidCurrencyType
, registry_attribute.BidStartPrice
, registry_attribute.AuctionReservationNoticeStartTime
, registry_attribute.AuctionStartTime
, registry_attribute.AuctionEndTime
, registry_attribute.IsCancelAuction
, registry_attribute.RegisteredVersionTime
, registry_attribute.LandAuctionState
, registry_attribute.LandAuctionResult
, winning_user_guid, winning_user_nickname
, registry_attribute.ProcessVersionTime );
return log_info;
}
}
}

View File

@@ -0,0 +1,479 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StackExchange.Redis;
using ServerCore; using ServerBase;
using ServerCommon;
using ServerCommon.Cache;
using META_ID = System.UInt32;
using REQUESTOR_ID = System.String;
namespace GameServer
{
public static class LandAuctionCacheHelper
{
public static async Task<Result> trySaveToCache(this LandAuction landAuction, REQUESTOR_ID requestorId)
{
var server_logic = GameServerApp.getServerLogic();
var redis_connector = server_logic.getRedisConnector();
var result = new Result();
var land_auction_action = landAuction.getEntityAction<LandAuctionAction>();
NullReferenceCheckHelper.throwIfNull(land_auction_action, () => $"land_auction_action is null !!! - {landAuction.toBasicString()}");
var registry_attribute = landAuction.getEntityAttribute<LandAuctionRegistryAttribute>();
NullReferenceCheckHelper.throwIfNull(registry_attribute, () => $"registry_attribute is null !!! - {landAuction.toBasicString()}");
var highest_bid_user_attribute = landAuction.getEntityAttribute<LandAuctionHighestBidUserAttribute>();
NullReferenceCheckHelper.throwIfNull(highest_bid_user_attribute, () => $"highest_bid_user_attribute is null !!! - {landAuction.toBasicString()}");
var land_auction_cache = new LandAuctionCache();
land_auction_cache.LandMetaId = registry_attribute.LandMetaId;
land_auction_cache.AuctionNumber = registry_attribute.AuctionNumber;
land_auction_cache.LandAuctionState = registry_attribute.LandAuctionState;
land_auction_cache.LandAuctionResult = registry_attribute.LandAuctionResult;
land_auction_cache.ProcessVersionTime = registry_attribute.ProcessVersionTime;
var land_auction_cache_request = new LandAuctionCacheRequest(land_auction_cache, redis_connector);
result = await land_auction_cache_request.upsertLandAuction(DateTimeHelper.toRemainingTimeMin(registry_attribute.AuctionEndTime));
if (result.isFail())
{
return result;
}
if (LandAuctionState.Started == land_auction_cache.LandAuctionState)
{
await landAuction.tryRemoveLandAuctionTopBidderBlockFromCache();
}
land_auction_action.resetCacheSaveStep();
var is_success = await landAuction.tryReleaseWriteLockWithLandAuction(requestorId);
if (false == is_success)
{
var err_msg = $"Failed to tryReleaseWriteLockWithLandAuction() !!! - {landAuction.toBasicString()}";
Log.getLogger().warn(err_msg);
}
Log.getLogger().debug($"Called trySaveToCache() - {landAuction.toBasicString()}");
return result;
}
public static async Task<bool> tryAcquireWriteLockWithLandAuctionBidders(this LandAuction landAuction, REQUESTOR_ID requestorId, Int16 ttlSec)
{
var result = new Result();
var server_logic = GameServerApp.getServerLogic();
var redis_connector = server_logic.getRedisConnector();
var redis_lua_executor = server_logic.getRedisWithLuaScriptExecutor();
var land_auction_registry_attribute = landAuction.getEntityAttribute<LandAuctionRegistryAttribute>();
NullReferenceCheckHelper.throwIfNull(land_auction_registry_attribute, () => $"land_auction_registry_attribute is null !!! - requestorId:{requestorId}");
var land_meta_id = land_auction_registry_attribute.LandMetaId;
var bid_price_order_cache_request = new LandAuctionBidPriceOrderCacheRequest(land_meta_id, redis_connector);
var lock_key = $"lock:{bid_price_order_cache_request.toKey()}";
var locker_id = $"locker_id:{requestorId}";
var is_success = await redis_lua_executor.tryAcquireLock(lock_key, locker_id, ttlSec);
if (false == is_success)
{
var err_msg = $"Failed to tryAcquireLock() !!! : LockKey:{lock_key}, LockerId:{locker_id}, TTLSec:{ttlSec} - {landAuction.toBasicString()}";
Log.getLogger().error(err_msg);
return false;
}
return true;
}
public static async Task<bool> tryReleaseWriteLockWithLandAuctionBidders(this LandAuction landAuction, REQUESTOR_ID requestorId)
{
var result = new Result();
var server_logic = GameServerApp.getServerLogic();
var redis_connector = server_logic.getRedisConnector();
var redis_lua_executor = server_logic.getRedisWithLuaScriptExecutor();
var land_auction_attribute = landAuction.getEntityAttribute<LandAuctionRegistryAttribute>();
NullReferenceCheckHelper.throwIfNull(land_auction_attribute, () => $"land_auction_attribute is null !!! - requestorId:{requestorId}");
var land_meta_id = land_auction_attribute.LandMetaId;
var bid_price_order_cache_request = new LandAuctionBidPriceOrderCacheRequest(land_meta_id, redis_connector);
var lock_key = $"lock:{bid_price_order_cache_request.toKey()}";
var locker_id = $"locker_id:{requestorId}";
var is_success = await redis_lua_executor.tyrReleaseLock(lock_key, locker_id);
if (false == is_success)
{
var err_msg = $"Failed to tyrReleaseLock() !!! : LockKey:{lock_key}, LockerId:{locker_id} - {landAuction.toBasicString()}";
Log.getLogger().warn(err_msg);
return false;
}
return true;
}
public static async Task<(bool, LandAuctionTopBidderCache?, LandAuctionTopBidderCache?, bool)> tryRankLandAuctionTopBidderCache(this LandAuction landAuction, REQUESTOR_ID requestorId, double bidPrice)
{
var server_logic = GameServerApp.getServerLogic();
var redis_connector = server_logic.getRedisConnector();
var redis_lua_executor = server_logic.getRedisWithLuaScriptExecutor();
var land_auction_action = landAuction.getEntityAction<LandAuctionAction>();
NullReferenceCheckHelper.throwIfNull(land_auction_action, () => $"land_auction_action is null !!! - requestorId:{requestorId}");
var land_meta_id = land_auction_action.getLandMetaId();
var bid_price_order_cache_request = new LandAuctionBidPriceOrderCacheRequest(land_meta_id, redis_connector);
( var is_success
, var curr_ranker_id, var curr_ranker_score
, var old_ranker_id, var old_ranker_score
, var is_top_change ) = await redis_lua_executor.tryPlaceTopRankOnly( bid_price_order_cache_request.toKey()
, requestorId
, bidPrice, bid_price_order_cache_request.toBlockKey());
if (false == is_success)
{
var err_msg = $"Failed to tryPlaceTopRankOnly() !!! : {bid_price_order_cache_request.toKeyAll()} - {landAuction.toBasicString()}";
Log.getLogger().error(err_msg);
return (false, null, null, false);
}
var curr_top_bidder = new LandAuctionTopBidderCache();
curr_top_bidder.LandMetaId = land_meta_id;
curr_top_bidder.HighestBidUserGuid = curr_ranker_id;
curr_top_bidder.HighestBidPrice = curr_ranker_score;
if (true == is_top_change)
{
if(false == old_ranker_id.isNullOrWhiteSpace())
{
var old_top_bidder = new LandAuctionTopBidderCache();
old_top_bidder.LandMetaId = land_meta_id;
old_top_bidder.HighestBidUserGuid = old_ranker_id;
old_top_bidder.HighestBidPrice = old_ranker_score;
return (true, curr_top_bidder, old_top_bidder, is_top_change);
}
}
return (true, curr_top_bidder, null, is_top_change);
}
public static async Task<(bool, LandAuctionTopBidderCache?)> tryGetLandAuctionTopBidderCacheWithBlock(this LandAuction landAuction)
{
var server_logic = GameServerApp.getServerLogic();
var redis_connector = server_logic.getRedisConnector();
var redis_lua_executor = server_logic.getRedisWithLuaScriptExecutor();
var land_auction_action = landAuction.getEntityAction<LandAuctionAction>();
NullReferenceCheckHelper.throwIfNull(land_auction_action, () => $"land_auction_action is null !!! - {landAuction.toBasicString()}");
var err_msg = string.Empty;
var land_meta_id = land_auction_action.getLandMetaId();
var bid_price_order_cache_request = new LandAuctionBidPriceOrderCacheRequest(land_meta_id, redis_connector);
( var is_success
, var is_top_found
, var top_ranker_id, var top_ranker_score ) = await redis_lua_executor.tryGetTopRankAndSetBlock( bid_price_order_cache_request.toKey()
, bid_price_order_cache_request.toBlockKey() );
if (false == is_success)
{
err_msg = $"Failed to tryGetTopRankAndSetBlock() !!! : {bid_price_order_cache_request.toKeyAll()} - {landAuction.toBasicString()}";
Log.getLogger().error(err_msg);
return (false, null);
}
if (true == is_top_found)
{
var curr_top_bidder = new LandAuctionTopBidderCache();
curr_top_bidder.LandMetaId = land_meta_id;
curr_top_bidder.HighestBidUserGuid = top_ranker_id;
curr_top_bidder.HighestBidPrice = top_ranker_score;
return (true, curr_top_bidder);
}
return (true, null);
}
public static async Task<(Result, LandAuctionTopBidderCache?)> tryGetLandAuctionTopBidderCache(this LandAuction landAuction)
{
var result = new Result();
var err_msg = string.Empty;
var server_logic = GameServerApp.getServerLogic();
var redis_connector = server_logic.getRedisConnector();
var redis_db = redis_connector.getDatabase();
NullReferenceCheckHelper.throwIfNull(redis_db, () => $"redis_db is null !!!");
var land_auction_attribute = landAuction.getEntityAttribute<LandAuctionRegistryAttribute>();
NullReferenceCheckHelper.throwIfNull(land_auction_attribute, () => $"land_auction_attribute is null !!!");
var top_bidder = new LandAuctionTopBidderCache();
var land_meta_id = land_auction_attribute.LandMetaId;
var bid_price_order_cache_request = new LandAuctionBidPriceOrderCacheRequest(land_meta_id, redis_connector);
try
{
var top_ranker = await redis_db.SortedSetRangeByRankWithScoresAsync(bid_price_order_cache_request.toKey(), 0, 0, Order.Descending);
if (top_ranker.Length == 0)
{
return (result, null);
}
top_bidder.LandMetaId = land_meta_id;
top_bidder.HighestBidUserGuid = top_ranker[0].Element.ToString();
top_bidder.HighestBidPrice = top_ranker[0].Score;
return (result, top_bidder);
}
catch (Exception e)
{
var error_code = ServerErrorCode.TryCatchException;
err_msg = $"Exception !!!, Failed to perfom in tryGetLandAuctionTopBidderCache() !!! : exception:{e}, errorCode:{error_code}, key:{bid_price_order_cache_request.toKey()} - {landAuction.toBasicString()}";
result.setFail(error_code, err_msg);
Log.getLogger().error(result.toBasicString());
}
return (result, null);
}
public static async Task<bool> tryRemoveLandAuctionTopBidderBlockFromCache(this LandAuction landAuction)
{
var server_logic = GameServerApp.getServerLogic();
var redis_connector = server_logic.getRedisConnector();
var redis_lua_executor = server_logic.getRedisWithLuaScriptExecutor();
var err_msg = string.Empty;
var land_auction_action = landAuction.getEntityAction<LandAuctionAction>();
NullReferenceCheckHelper.throwIfNull(land_auction_action, () => $"land_auction_action is null !!! - {landAuction.toBasicString()}");
var land_meta_id = land_auction_action.getLandMetaId();
var bid_price_order_cache_request = new LandAuctionBidPriceOrderCacheRequest(land_meta_id, redis_connector);
var is_success = await redis_lua_executor.tryRemoveTopRankAndBlock( bid_price_order_cache_request.toKey()
, bid_price_order_cache_request.toBlockKey() );
if (false == is_success)
{
err_msg = $"Failed to tryRemoveTopRankAndBlock() !!! : {bid_price_order_cache_request.toKeyAll()} - {landAuction.toBasicString()}";
Log.getLogger().warn(err_msg);
return false;
}
return true;
}
public static async Task<bool> isExistTopBidderFromCache(this LandAuction landAuction)
{
var server_logic = GameServerApp.getServerLogic();
var redis_connector = server_logic.getRedisConnector();
var land_auction_attribute = landAuction.getEntityAttribute<LandAuctionRegistryAttribute>();
NullReferenceCheckHelper.throwIfNull(land_auction_attribute, () => $"land_auction_attribute is null !!! - {landAuction.toBasicString()}");
var land_meta_id = land_auction_attribute.LandMetaId;
var bid_price_order_cache_request = new LandAuctionBidPriceOrderCacheRequest(land_meta_id, redis_connector);
var is_exist_key = await bid_price_order_cache_request.isExistKey();
if (false == is_exist_key)
{
return false;
}
return true;
}
public static async Task<bool> IsExistLandAuctionFromCache(this LandAuction landAuction, REQUESTOR_ID requestorId)
{
var server_logic = GameServerApp.getServerLogic();
var redis_connector = server_logic.getRedisConnector();
var redis_lua_executor = server_logic.getRedisWithLuaScriptExecutor();
var land_auction_attribute = landAuction.getEntityAttribute<LandAuctionRegistryAttribute>();
NullReferenceCheckHelper.throwIfNull(land_auction_attribute, () => $"land_auction_attribute is null !!! - requstorId:{requestorId}");
var land_meta_id = land_auction_attribute.LandMetaId;
var land_auction_cache_request = new LandAuctionCacheRequest(land_meta_id, redis_connector);
var is_exist_key = await land_auction_cache_request.isExistKey();
if (false == is_exist_key)
{
return false;
}
return true;
}
public static async Task<(bool, string)> tryGetLandAuctionWithWriteLock(this LandAuction landAuction, REQUESTOR_ID requestorId, Int16 ttlSec)
{
var result = new Result();
var err_msg = string.Empty;
var server_logic = GameServerApp.getServerLogic();
var redis_connector = server_logic.getRedisConnector();
var redis_lua_executor = server_logic.getRedisWithLuaScriptExecutor();
var land_auction_attribute = landAuction.getEntityAttribute<LandAuctionRegistryAttribute>();
NullReferenceCheckHelper.throwIfNull(land_auction_attribute, () => $"land_auction_attribute is null !!! - requstorId:{requestorId}");
var land_meta_id = land_auction_attribute.LandMetaId;
var land_auction_cache_request = new LandAuctionCacheRequest(land_meta_id, redis_connector);
var lock_key = $"lock:{land_auction_cache_request.toKey()}";
var locker_id = $"locker_id:{requestorId}";
(var is_success, var read_data) = await redis_lua_executor.tryReadWithLock( lock_key, locker_id
, land_auction_cache_request.toKey(), ttlSec );
if (false == is_success)
{
err_msg = $"Failed to tryReadWithLock() !!! : LockKey:{land_auction_cache_request.toKey()}, LockerId:{locker_id}, TTLSec:{ttlSec} - {landAuction.toBasicString()}";
Log.getLogger().warn(err_msg);
return (false, string.Empty);
}
if(null == read_data)
{
return (true, string.Empty);
}
return (true, read_data);
}
public static async Task<bool> tryAcquireWriteLockWithLandAuction(this LandAuction landAuction, REQUESTOR_ID requestorId, Int16 ttlSec)
{
var result = new Result();
var err_msg = string.Empty;
var server_logic = GameServerApp.getServerLogic();
var redis_connector = server_logic.getRedisConnector();
var redis_lua_executor = server_logic.getRedisWithLuaScriptExecutor();
var land_auction_attribute = landAuction.getEntityAttribute<LandAuctionRegistryAttribute>();
NullReferenceCheckHelper.throwIfNull(land_auction_attribute, () => $"land_auction_attribute is null !!! - requestorId:{requestorId}");
var land_meta_id = land_auction_attribute.LandMetaId;
var land_auction_cache_request = new LandAuctionCacheRequest(land_meta_id, redis_connector);
var lock_key = $"lock:{land_auction_cache_request.toKey()}";
var locker_id = $"locker_id:{requestorId}";
var is_success = await redis_lua_executor.tryAcquireLock(lock_key, locker_id, ttlSec);
if (false == is_success)
{
err_msg = $"Failed to tryAcquireLock() !!! : LockKey:{land_auction_cache_request.toKey()}, LockerId:{locker_id}, TTLSec:{ttlSec} - {landAuction.toBasicString()}";
Log.getLogger().warn(err_msg);
return false;
}
return true;
}
public static async Task<bool> tryReleaseWriteLockWithLandAuction(this LandAuction landAuction, REQUESTOR_ID requestorid)
{
var result = new Result();
var err_msg = string.Empty;
var server_logic = GameServerApp.getServerLogic();
var redis_connector = server_logic.getRedisConnector();
var redis_lua_executor = server_logic.getRedisWithLuaScriptExecutor();
var land_auction_attribute = landAuction.getEntityAttribute<LandAuctionRegistryAttribute>();
NullReferenceCheckHelper.throwIfNull(land_auction_attribute, () => $"land_auction_attribute is null !!! - requstorId:{requestorid}");
var land_meta_id = land_auction_attribute.LandMetaId;
var land_auction_cache_request = new LandAuctionCacheRequest(land_meta_id, redis_connector);
var lock_key = $"lock:{land_auction_cache_request.toKey()}";
var locker_id = $"locker_id:{requestorid}";
var is_success = await redis_lua_executor.tyrReleaseLock(lock_key, locker_id);
if (false == is_success)
{
err_msg = $"Failed to tyrReleaseLock() !!! : LockKey:{land_auction_cache_request.toKey()}, LockerId:{locker_id} - {landAuction.toBasicString()}";
Log.getLogger().warn(err_msg);
return false;
}
return true;
}
public static async Task<bool> tryAcquireWriteLockWithLandAuctionReservation(REQUESTOR_ID requestorId, Int16 ttlSec)
{
var result = new Result();
var err_msg = string.Empty;
var server_logic = GameServerApp.getServerLogic();
var redis_connector = server_logic.getRedisConnector();
var redis_lua_executor = server_logic.getRedisWithLuaScriptExecutor();
var lock_key = $"land_auction_reservation:write_lock";
var locker_id = $"land_auction_reservation:locker_id:{requestorId}";
var is_success = await redis_lua_executor.tryAcquireLock(lock_key, locker_id, ttlSec);
if (false == is_success)
{
err_msg = $"Failed to tryAcquireLock() !!! : LockKey:{lock_key}, LockerId:{locker_id}, TTLSec:{ttlSec} - requstorId:{requestorId}";
Log.getLogger().warn(err_msg);
return false;
}
return true;
}
public static async Task<bool> tryReleaseWriteLockWithLandAuctionReservation(REQUESTOR_ID requestorId)
{
var result = new Result();
var err_msg = string.Empty;
var server_logic = GameServerApp.getServerLogic();
var redis_connector = server_logic.getRedisDb();
var redis_lua_executor = server_logic.getRedisWithLuaScriptExecutor();
var lock_key = $"land_auction_reservation:write_lock";
var locker_id = $"land_auction_reservation:locker_id:{requestorId}";
var is_success = await redis_lua_executor.tyrReleaseLock(lock_key, locker_id);
if (false == is_success)
{
err_msg = $"Failed to tyrReleaseLock() !!! : LockKey:{lock_key}, LockerId:{locker_id} - requstorId:{requestorId}";
Log.getLogger().warn(err_msg);
return false;
}
return true;
}
}
}

View File

@@ -0,0 +1,499 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Amazon.DynamoDBv2.Model;
using Amazon.DynamoDBv2;
using ServerCore; using ServerBase;
using ServerCommon;
using static ServerCommon.MetaHelper;
using META_ID = System.UInt32;
using USER_GUID = System.String;
using LAND_AUCTION_NUMBER = System.Int32;
namespace GameServer
{
public static class LandAuctionDbHelper
{
public static async Task<(Result, bool)> isExistHighestBidderFromDb(this LandAuction landAuction, USER_GUID toCheckHighestBidUserGuid, double toCheckHighestBidPrice)
{
var server_logic = GameServerApp.getServerLogic();
var db_connector = server_logic.getDynamoDbClient();
var registry_attribute = landAuction.getEntityAttribute<LandAuctionRegistryAttribute>();
NullReferenceCheckHelper.throwIfNull(registry_attribute, () => $"registry_attribute is null !!! - {landAuction.toBasicString()}");
var highest_bid_user_doc = new LandAuctionHighestBidUserDoc(registry_attribute.LandMetaId, registry_attribute.AuctionNumber);
var get_request = new TransactGetItem
{
Get = new Get
{
TableName = db_connector.getTableFullName(highest_bid_user_doc.TableName),
Key = highest_bid_user_doc.getPrimaryKey().toKeyWithAttributeValue()
}
};
(var result, var found_highest_bid_user_item_doc) = await db_connector.simpleQueryTransactReadDocWithItemRequest<LandAuctionHighestBidUserDoc>(get_request, isFailOnEmptyData: false);
if (result.isFail())
{
var err_msg = $"Failed to simpleQueryTransactReadDocWithItemRequest<LandAuctionHighestBidUserDoc>() !!! : {get_request.Get.toBasicString()} - {landAuction.toBasicString()}";
Log.getLogger().error(err_msg);
return (result, false);
}
if( null == found_highest_bid_user_item_doc)
{
var err_msg = $"Not found LandAuctionHighestBidUserDoc at simpleQueryTransactReadDocWithItemRequest<LandAuctionHighestBidUserDoc>() !!! : {get_request.Get.toBasicString()} - {landAuction.toBasicString()}";
Log.getLogger().error(err_msg);
return (result, false);
}
var heighest_bid_user_attrib = found_highest_bid_user_item_doc.getAttrib<LandAuctionHighestBidUserAttrib>();
NullReferenceCheckHelper.throwIfNull(heighest_bid_user_attrib, () => $"heighest_bid_user_attrib is null !!! - {landAuction.toBasicString()}");
if ( heighest_bid_user_attrib.HighestBidUserGuid == toCheckHighestBidUserGuid
&& heighest_bid_user_attrib.HighestBidPrice == toCheckHighestBidPrice )
{
return (result, true);
}
return (result, false);
}
public static async Task<(Result, LandAuctionHighestBidUserDoc?)> tryGetLandAuctionHighestBidUserDoc(this LandAuction landAuction, META_ID landMetaId, LAND_AUCTION_NUMBER auctionNumber)
{
var server_logic = GameServerApp.getServerLogic();
var db_client = server_logic.getDynamoDbClient();
var result = new Result();
var err_msg = string.Empty;
(result, var found_highest_bid_user_doc) = await readLandAuctionHighestBidUserDocFromDb(landMetaId, auctionNumber);
if (result.isFail())
{
err_msg = $"Failed to readLandAuctionHighestBidUserDocFromDb() !!! : {result.toBasicString()} - landMetaId:{landMetaId}, auctionNumber:{auctionNumber}";
Log.getLogger().error(err_msg);
return (result, null);
}
return (result, found_highest_bid_user_doc);
}
public static async Task<Result> tryLoadLandAuctionActivityDoc(this LandAuction landAuction, META_ID landMetaId)
{
var server_logic = GameServerApp.getServerLogic();
var db_client = server_logic.getDynamoDbClient();
var result = new Result();
var err_msg = string.Empty;
var activity_attribute = landAuction.getEntityAttribute<LandAuctionActivityAttribute>();
NullReferenceCheckHelper.throwIfNull(activity_attribute, () => $"activity_attribute is null !!! - landMetaId:{landMetaId}");
(result, var found_activity_doc) = await readLandAuctionActivityDocFromDb(landMetaId);
if (result.isFail())
{
err_msg = $"Failed to readLandAuctionActivityDocFromDb() !!! : {result.toBasicString()} - landMetaId:{landMetaId}";
Log.getLogger().error(err_msg);
return result;
}
NullReferenceCheckHelper.throwIfNull(found_activity_doc, () => $"found_activity_doc is null !!! - landMetaId:{landMetaId}");
result = await landAuction.copyDocToEntityAttributeForLandAuction(activity_attribute, found_activity_doc, false);
if(result.isFail())
{
err_msg = $"Failed to copyDocToEntityAttributeForLandAuction() !!! : {result.toBasicString()} - landMetaId:{landMetaId}";
Log.getLogger().error(err_msg);
return result;
}
return result;
}
public static async Task<Result> tryLoadLandAuctionRegistryDoc(this LandAuction landAuction, META_ID landMetaId, LAND_AUCTION_NUMBER auctionNumber)
{
var server_logic = GameServerApp.getServerLogic();
var db_client = server_logic.getDynamoDbClient();
var result = new Result();
var err_msg = string.Empty;
var registry_attribute = landAuction.getEntityAttribute<LandAuctionRegistryAttribute>();
NullReferenceCheckHelper.throwIfNull(registry_attribute, () => $"registry_attribute is null !!! - landMetaId:{landMetaId}, auctionNumber:{auctionNumber}");
var auction_aution = landAuction.getEntityAction<LandAuctionAction>();
NullReferenceCheckHelper.throwIfNull(auction_aution, () => $"auction_aution is null !!! - landMetaId:{landMetaId}, auctionNumber:{auctionNumber}");
(result, var found_registry_doc) = await readLandAuctionRegistryDocFromDb(landMetaId, auctionNumber);
if (result.isFail())
{
err_msg = $"Failed to parse readLandAuctionRegistryDocFromDb() !!! : {result.toBasicString()} - landMetaId:{landMetaId}, auctionNumber:{auctionNumber}";
Log.getLogger().error(err_msg);
return result;
}
NullReferenceCheckHelper.throwIfNull(found_registry_doc, () => $"found_registry_doc is null !!!");
result = await landAuction.copyDocToEntityAttributeForLandAuction(registry_attribute, found_registry_doc, false);
if (result.isFail())
{
err_msg = $"Failed to copyDocToEntityAttributeForLandAuction() !!! : {result.toBasicString()} - landMetaId:{landMetaId}";
Log.getLogger().error(err_msg);
return result;
}
return result;
}
public static async Task<(Result, bool)> tryLoadLandAuctionHighestBidUserDoc(this LandAuction landAuction, META_ID landMetaId, LAND_AUCTION_NUMBER auctionNumber)
{
var server_logic = GameServerApp.getServerLogic();
var db_client = server_logic.getDynamoDbClient();
var result = new Result();
var err_msg = string.Empty;
var highest_bid_user_attribute = landAuction.getEntityAttribute<LandAuctionHighestBidUserAttribute>();
NullReferenceCheckHelper.throwIfNull(highest_bid_user_attribute, () => $"highest_bid_user_attribute is null !!! - landMetaId:{landMetaId}, auctionNumber:{auctionNumber}");
(result, var found_highest_bid_user_doc) = await readLandAuctionHighestBidUserDocFromDb(landMetaId, auctionNumber);
if (result.isFail())
{
err_msg = $"Failed to parse readLandAuctionHighestBidUserDocFromDb() !!! : {result.toBasicString()} - landMetaId:{landMetaId}, auctionNumber:{auctionNumber}";
Log.getLogger().error(err_msg);
return (result, false);
}
if (null != found_highest_bid_user_doc)
{
result = await landAuction.copyDocToEntityAttributeForLandAuction(highest_bid_user_attribute, found_highest_bid_user_doc, false);
if (result.isFail())
{
err_msg = $"Failed to copyDocToEntityAttributeForLandAuction() !!! : {result.toBasicString()} - landMetaId:{landMetaId}";
Log.getLogger().error(err_msg);
return (result, false);
}
}
return (result, false);
}
public static async Task<Result> tryFillupLandAuctionActivityFromDb(this LandAuction landAuction, META_ID landMetaId)
{
var server_logic = GameServerApp.getServerLogic();
var db_client = server_logic.getDynamoDbClient();
var result = new Result();
var err_msg = string.Empty;
var activity_attribute = landAuction.getEntityAttribute<LandAuctionActivityAttribute>();
NullReferenceCheckHelper.throwIfNull(activity_attribute, () => $"activity_attribute is null !!! - landMetaId:{landMetaId}");
(result, var found_activity_doc) = await readLandAuctionActivityDocFromDb(landMetaId);
if (result.isFail())
{
err_msg = $"Failed to readLandAuctionActivityDocFromDb() !!! : {result.toBasicString()} - landMetaId:{landMetaId}";
Log.getLogger().error(err_msg);
return result;
}
NullReferenceCheckHelper.throwIfNull(found_activity_doc, () => $"found_activity_doc is null !!!");
result = await landAuction.copyDocToEntityAttributeForLandAuction(activity_attribute, found_activity_doc, true);
if (result.isFail())
{
err_msg = $"Failed to copyDocToEntityAttributeForLandAuction() !!! : {result.toBasicString()} - landMetaId:{landMetaId}";
Log.getLogger().error(err_msg);
return result;
}
return result;
}
public static async Task<Result> tryFillupLandAuctionRegistryFromDb(this LandAuction landAuction, META_ID landMetaId, LAND_AUCTION_NUMBER auctionNumber)
{
var server_logic = GameServerApp.getServerLogic();
var db_client = server_logic.getDynamoDbClient();
var result = new Result();
var err_msg = string.Empty;
var registry_attribute = landAuction.getEntityAttribute<LandAuctionRegistryAttribute>();
NullReferenceCheckHelper.throwIfNull(registry_attribute, () => $"land_auction_registry_attribute is null !!! - landMetaId:{landMetaId}, auctionNumber:{auctionNumber}");
(result, var found_registry_doc) = await readLandAuctionRegistryDocFromDb(landMetaId, auctionNumber);
if (result.isFail())
{
err_msg = $"Failed to parse readLandAuctionRegistryDocFromDb() !!! : {result.toBasicString()} - landMetaId:{landMetaId}, auctionNumber:{auctionNumber}";
Log.getLogger().error(err_msg);
return result;
}
NullReferenceCheckHelper.throwIfNull(found_registry_doc, () => $"found_registry_doc is null !!!");
result = await landAuction.copyDocToEntityAttributeForLandAuction(registry_attribute, found_registry_doc, true);
if(result.isFail())
{
return result;
}
return result;
}
public static async Task<(Result, List<LandAuctionActivityDoc>?)> readLandAuctionActivityDocsFromDb()
{
var server_logic = GameServerApp.getServerLogic();
var db_connector = server_logic.getDynamoDbClient();
var result = new Result();
var err_msg = string.Empty;
(result, var make_primary_key) = await DynamoDBDocBaseHelper.makePrimaryKey<LandAuctionActivityDoc>(DynamoDbClient.PK_GLOBAL);
if (result.isFail())
{
err_msg = $"Failed to makePrimaryKey<LandAuctionActivityDoc>() !!! : {result.toBasicString()}";
Log.getLogger().error(err_msg);
return (result, null);
}
NullReferenceCheckHelper.throwIfNull(make_primary_key, () => $"make_primary_key is null !!!");
var query_config = db_connector.makeQueryConfigForReadByPKOnly(make_primary_key.PK);
(result, var found_land_auction_activity_docs) = await db_connector.simpleQueryDocTypesWithQueryOperationConfig<LandAuctionActivityDoc>(query_config, false);
if (result.isFail())
{
err_msg = $"Failed to simpleQueryDocTypesWithQueryOperationConfig<LandAuctionActivityDoc>() !!! : {result.toBasicString()}, {make_primary_key.toBasicString()}";
Log.getLogger().error(err_msg);
return (result, null);
}
NullReferenceCheckHelper.throwIfNull(found_land_auction_activity_docs, () => $"found_land_auction_activity_docs is null !!!");
return (result, found_land_auction_activity_docs);
}
public static async Task<(Result, LandAuctionActivityDoc?)> readLandAuctionActivityDocFromDb(META_ID landMetaId, bool isFailOnEmptyDoc = true)
{
var server_logic = GameServerApp.getServerLogic();
var db_connector = server_logic.getDynamoDbClient();
var result = new Result();
var err_msg = string.Empty;
(result, var make_primary_key) = await DynamoDBDocBaseHelper.makePrimaryKey<LandAuctionActivityDoc>(DynamoDbClient.PK_GLOBAL, landMetaId.ToString());
if (result.isFail())
{
err_msg = $"Failed to makePrimaryKey<LandAuctionActivityDoc>() !!! : {result.toBasicString()} - landMetaId:{landMetaId}";
Log.getLogger().error(err_msg);
return (result, null);
}
NullReferenceCheckHelper.throwIfNull(make_primary_key, () => $"make_primary_key is null !!!");
var query_config = db_connector.makeQueryConfigForReadByPKSK(make_primary_key.PK, make_primary_key.SK);
(result, var found_land_auction_activity_doc) = await db_connector.simpleQueryDocTypeWithQueryOperationConfig<LandAuctionActivityDoc>(query_config, isFailOnEmptyDoc);
if (result.isFail())
{
err_msg = $"Failed to simpleQueryDocTypeWithQueryOperationConfig<LandAuctionActivityDoc>() !!! : {result.toBasicString()}, {make_primary_key.toBasicString()} - landMetaId:{landMetaId}";
Log.getLogger().error(err_msg);
return (result, null);
}
return (result, found_land_auction_activity_doc);
}
public static async Task<(Result, LandAuctionRegistryDoc?)> readLandAuctionRegistryDocFromDb(META_ID landMetaId, LAND_AUCTION_NUMBER auctionNumber, bool isFailOnEmptyDoc = true)
{
var server_logic = GameServerApp.getServerLogic();
var db_connector = server_logic.getDynamoDbClient();
var result = new Result();
var err_msg = string.Empty;
(result, var make_primary_key) = await DynamoDBDocBaseHelper.makePrimaryKey<LandAuctionRegistryDoc>( DynamoDbClient.PK_GLOBAL
, LandAuctionRegistryDoc.makeCombinationKeyForSK(landMetaId, auctionNumber));
if (result.isFail())
{
err_msg = $"Failed to makePrimaryKey<LandAuctionRegistryDoc>() !!! : {result.toBasicString()} - landMetaId:{landMetaId}";
Log.getLogger().error(err_msg);
return (result, null);
}
NullReferenceCheckHelper.throwIfNull(make_primary_key, () => $"make_primary_key is null !!!");
var query_config = db_connector.makeQueryConfigForReadByPKSK(make_primary_key.PK, make_primary_key.SK);
(result, var found_land_auction_registry_doc) = await db_connector.simpleQueryDocTypeWithQueryOperationConfig<LandAuctionRegistryDoc>(query_config, isFailOnEmptyDoc);
if (result.isFail())
{
err_msg = $"Failed to simpleQueryDocTypeWithQueryOperationConfig<LandAuctionRegistryDoc>() !!! : {result.toBasicString()}, {make_primary_key.toBasicString()} - landMetaId:{landMetaId}, auctionNumber:{auctionNumber}";
Log.getLogger().error(err_msg);
return (result, null);
}
return (result, found_land_auction_registry_doc);
}
public static async Task<(Result, LandAuctionHighestBidUserDoc?)> readLandAuctionHighestBidUserDocFromDb(META_ID landMetaId, LAND_AUCTION_NUMBER auctionNumber)
{
var server_logic = GameServerApp.getServerLogic();
var db_connector = server_logic.getDynamoDbClient();
var result = new Result();
var err_msg = string.Empty;
(result, var make_primary_key) = await DynamoDBDocBaseHelper.makePrimaryKey<LandAuctionHighestBidUserDoc>( DynamoDbClient.PK_GLOBAL
, LandAuctionHighestBidUserDoc.makeCombinationKeyForSK(landMetaId, auctionNumber) );
if (result.isFail())
{
err_msg = $"Failed to makePrimaryKey<LandAuctionHighestBidUserDoc>() !!! : {result.toBasicString()} - landMetaId:{landMetaId}";
Log.getLogger().error(err_msg);
return (result, null);
}
NullReferenceCheckHelper.throwIfNull(make_primary_key, () => $"make_primary_key is null !!!");
var query_config = db_connector.makeQueryConfigForReadByPKSK(make_primary_key.PK, make_primary_key.SK);
(result, var found_land_auction_highest_bid_user_doc) = await db_connector.simpleQueryDocTypeWithQueryOperationConfig<LandAuctionHighestBidUserDoc>(query_config, false);
if (result.isFail())
{
err_msg = $"Failed to simpleQueryDocTypeWithQueryOperationConfig<LandAuctionHighestBidUserDoc>() !!! : {result.toBasicString()}, {make_primary_key.toBasicString()} - landMetaId:{landMetaId}, auctionNumber:{auctionNumber}";
Log.getLogger().error(err_msg);
return (result, null);
}
return (result, found_land_auction_highest_bid_user_doc);
}
public static async Task<(Result, LandAuctionRefundBidPriceDoc?)> readLandAuctionRefundBidPriceDocFromDb( Player player
, META_ID landMetaId, LAND_AUCTION_NUMBER auctionNumber )
{
var server_logic = GameServerApp.getServerLogic();
var db_connector = server_logic.getDynamoDbClient();
var result = new Result();
var err_msg = string.Empty;
(result, var found_refund_bid_price_doc) = await readLandAuctionRefundBidPriceDocFromDb( player.getUserGuid()
, landMetaId, auctionNumber );
if (result.isFail())
{
err_msg = $"Failed to readLandAuctionRefundBidPriceDocFromDb() !!! : {result.toBasicString()}, landMetaId:{landMetaId}, auctionNumber:{auctionNumber} - {player.toBasicString()}";
Log.getLogger().error(err_msg);
return (result, null);
}
return (result, found_refund_bid_price_doc);
}
public static async Task<(Result, LandAuctionRefundBidPriceDoc?)> readLandAuctionRefundBidPriceDocFromDb( USER_GUID userGuid
, META_ID landMetaId, LAND_AUCTION_NUMBER auctionNumber )
{
var server_logic = GameServerApp.getServerLogic();
var db_connector = server_logic.getDynamoDbClient();
var result = new Result();
var err_msg = string.Empty;
(result, var make_primary_key) = await DynamoDBDocBaseHelper.makePrimaryKey<LandAuctionRefundBidPriceDoc>(userGuid, LandAuctionRefundBidPriceDoc.makeCombinationKeyForSK(landMetaId, auctionNumber));
if (result.isFail())
{
err_msg = $"Failed to makePrimaryKey<LandAuctionRefundBidPriceDoc>() !!! : {result.toBasicString()} - userGuid:{userGuid}";
Log.getLogger().error(err_msg);
return (result, null);
}
NullReferenceCheckHelper.throwIfNull(make_primary_key, () => $"make_primary_key is null !!!");
var query_config = db_connector.makeQueryConfigForReadByPKSK(make_primary_key.PK, make_primary_key.SK);
(result, var found_refund_bid_price_doc) = await db_connector.simpleQueryDocTypeWithQueryOperationConfig<LandAuctionRefundBidPriceDoc>(query_config);
if (result.isFail())
{
err_msg = $"Failed to simpleQueryDocTypesWithQueryOperationConfig<LandAuctionRefundBidPriceDoc>() !!! : {result.toBasicString()}, {make_primary_key.toBasicString()} - userGuid:{userGuid}";
Log.getLogger().error(err_msg);
return (result, null);
}
return (result, found_refund_bid_price_doc);
}
public static async Task<(Result, List<LandAuctionRefundBidPriceDoc>?)> readLandAuctionRefundBidPriceDocsFromDb(Player player)
{
var server_logic = GameServerApp.getServerLogic();
var db_connector = server_logic.getDynamoDbClient();
var result = new Result();
var err_msg = string.Empty;
(result, var make_primary_key) = await DynamoDBDocBaseHelper.makePrimaryKey<LandAuctionRefundBidPriceDoc>(player.getUserGuid());
if (result.isFail())
{
err_msg = $"Failed to makePrimaryKey<LandAuctionRefundBidPriceDoc>() !!! : {result.toBasicString()} - {player.toBasicString()}";
Log.getLogger().error(err_msg);
return (result, null);
}
NullReferenceCheckHelper.throwIfNull(make_primary_key, () => $"make_primary_key is null !!!");
var query_config = db_connector.makeQueryConfigForReadByPKOnly(make_primary_key.PK);
(result, var found_land_auction_bid_price_docs) = await db_connector.simpleQueryDocTypesWithQueryOperationConfig<LandAuctionRefundBidPriceDoc>(query_config);
if (result.isFail())
{
err_msg = $"Failed to simpleQueryDocTypesWithQueryOperationConfig<LandAuctionRefundBidPriceDoc>() !!! : {result.toBasicString()}, {make_primary_key.toBasicString()} - {player.toBasicString()}";
Log.getLogger().error(err_msg);
return (result, null);
}
NullReferenceCheckHelper.throwIfNull(found_land_auction_bid_price_docs, () => $"found_land_auction_bid_price_docs is null !!! - {player.toBasicString()}");
return (result, found_land_auction_bid_price_docs);
}
public static async Task<(Result, List<LandAuctionRecordDoc>?)> readLandAuctionRecordDocsFromDb()
{
var server_logic = GameServerApp.getServerLogic();
var db_connector = server_logic.getDynamoDbClient();
var result = new Result();
var err_msg = string.Empty;
(result, var make_primary_key) = await DynamoDBDocBaseHelper.makePrimaryKey<LandAuctionRecordDoc>(DynamoDbClient.PK_GLOBAL);
if (result.isFail())
{
err_msg = $"Failed to makePrimaryKey<LandAuctionRecordDoc>() !!! : {result.toBasicString()}";
Log.getLogger().error(err_msg);
return (result, null);
}
NullReferenceCheckHelper.throwIfNull(make_primary_key, () => $"make_primary_key is null !!!");
var query_config = db_connector.makeQueryConfigForReadByPKOnly(make_primary_key.PK);
(result, var found_land_auction_record_docs) = await db_connector.simpleQueryDocTypesWithQueryOperationConfig<LandAuctionRecordDoc>(query_config);
if (result.isFail())
{
err_msg = $"Failed to simpleQueryDocTypesWithQueryOperationConfig<LandAuctionRecordDoc>() !!! : {result.toBasicString()}, {make_primary_key.toBasicString()}";
Log.getLogger().error(err_msg);
return (result, null);
}
NullReferenceCheckHelper.throwIfNull(found_land_auction_record_docs, () => $"found_docs is null !!!");
return (result, found_land_auction_record_docs);
}
}
}

View File

@@ -0,0 +1,375 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ServerCore; using ServerBase;
using ServerCommon;
using ServerCommon.Cache;
using Amazon.DynamoDBv2.Model;
using META_ID = System.UInt32;
using USER_GUID = System.String;
using LAND_OWNER_GUID = System.String;
namespace GameServer
{
public static class LandAuctionHelper
{
public static string getWinningBidValue(this LandAuction landAuction)
{
var land_auction_action = landAuction.getEntityAction<LandAuctionAction>();
NullReferenceCheckHelper.throwIfNull(land_auction_action, () => $"land_auction_action is null !!! - {landAuction.toBasicString()}");
return land_auction_action.getHighestBidPrice().ToString("N0"); // 천 단위 구분 기호 포함, 소숫점은 없다 !!! - kangms
}
public static Result copyDocToEntityAttributeForRefundBidPrice( this LandAuctionRefundBidPrice refundBidPrice
, EntityAttributeBase toClonedAttributeBase, DynamoDbDocBase fromDoc )
{
var result = new Result();
var err_msg = string.Empty;
var refund_bid_price_attribute = toClonedAttributeBase as LandAuctionRefundBidPriceAttribute;
if (null != refund_bid_price_attribute)
{
var is_success = refund_bid_price_attribute.copyEntityAttributeFromDoc(fromDoc);
if (false == is_success)
{
err_msg = $"Failed to copyEntityAttributeFromDoc() !!! : docType:{fromDoc.getTypeName()} - {refundBidPrice.toBasicString()}";
result.setFail(ServerErrorCode.DynamoDbDocCopyToEntityAttributeFailed, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
var origin_attribute = refundBidPrice.getOriginEntityAttribute<LandAuctionRefundBidPriceAttribute>();
NullReferenceCheckHelper.throwIfNull(origin_attribute, () => $"origin_attribute is null !!! - {refundBidPrice.toBasicString()}");
origin_attribute.copyEntityAttributeFromDoc(fromDoc);
return result;
}
ConditionValidCheckHelper.throwIfFalseWithCondition(() => false
, () => $"Failed to copy EntityAttribute from Doc !!! : attributeType:{toClonedAttributeBase.getTypeName()} <= docType:{fromDoc.getTypeName()}"
+ $" - {refundBidPrice.toBasicString()}");
return result;
}
public static Result copyCacheToEntityAttributeForLandAuction( this LandAuction landAuction
, EntityAttributeBase toClonedAttributeBase, CacheBase fromCache )
{
var result = new Result();
var err_msg = string.Empty;
var auction_action = landAuction.getEntityAction<LandAuctionAction>();
NullReferenceCheckHelper.throwIfNull(auction_action, () => $"auction_action is null !!! - {landAuction.toBasicString()}");
var registry_attribute = toClonedAttributeBase as LandAuctionRegistryAttribute;
if (null != registry_attribute)
{
var origin_attribute = landAuction.getOriginEntityAttribute<LandAuctionRegistryAttribute>();
NullReferenceCheckHelper.throwIfNull(origin_attribute);
var land_auction_cache = fromCache as LandAuctionCache;
if (null != land_auction_cache)
{
registry_attribute.copyProcessInfoFromCache(land_auction_cache);
origin_attribute.copyProcessInfoFromCache(land_auction_cache);
auction_action.updateProcessVersion(land_auction_cache.ProcessVersionTime);
}
return result;
}
var highest_bid_user_attribute = toClonedAttributeBase as LandAuctionHighestBidUserAttribute;
if (null != highest_bid_user_attribute)
{
var origin_attribute = landAuction.getOriginEntityAttribute<LandAuctionHighestBidUserAttribute>();
NullReferenceCheckHelper.throwIfNull(origin_attribute);
var normal_bid_highest_user_cache = fromCache as NormalBidHighestUserCache;
if (null != normal_bid_highest_user_cache)
{
highest_bid_user_attribute.copyEntityAttributeFromCache(normal_bid_highest_user_cache);
origin_attribute.copyEntityAttributeFromCache(normal_bid_highest_user_cache);
auction_action.updateHighestRankVersion(normal_bid_highest_user_cache.HighestRankVersionTime);
}
var top_bidder_cache = fromCache as LandAuctionTopBidderCache;
if (null != top_bidder_cache)
{
highest_bid_user_attribute.copyEntityAttributeFromCache(top_bidder_cache);
origin_attribute.copyEntityAttributeFromCache(top_bidder_cache);
}
return result;
}
ConditionValidCheckHelper.throwIfFalseWithCondition( () => false
, () => $"Failed to copy EntityAttribute from Cache !!! : attributeType:{toClonedAttributeBase.getTypeName()} <= cacheType:{fromCache.getTypeName()}"
+ $" - {landAuction.toBasicString()}");
return result;
}
public static async Task<Result> copyDocToEntityAttributeForLandAuction( this LandAuction landAuction
, EntityAttributeBase toClonedAttributeBase, DynamoDbDocBase fromDoc
, bool isWithLock )
{
var result = new Result();
var err_msg = string.Empty;
var auction_action = landAuction.getEntityAction<LandAuctionAction>();
NullReferenceCheckHelper.throwIfNull(auction_action, () => $"auction_action is null !!! - {landAuction.toBasicString()}");
var activity_attribute = toClonedAttributeBase as LandAuctionActivityAttribute;
if(null != activity_attribute)
{
var is_success = activity_attribute.copyEntityAttributeFromDoc(fromDoc);
if(false == is_success)
{
err_msg = $"Failed to copyEntityAttributeFromDoc() !!! : docType:{fromDoc.getTypeName()} - {landAuction.toBasicString()}";
result.setFail(ServerErrorCode.DynamoDbDocCopyToEntityAttributeFailed, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
var origin_attribute = landAuction.getOriginEntityAttribute<LandAuctionActivityAttribute>();
NullReferenceCheckHelper.throwIfNull(origin_attribute, () => $"origin_attribute is null !!! - {landAuction.toBasicString()}");
origin_attribute.copyEntityAttributeFromDoc(fromDoc);
return result;
}
var registry_attribute = toClonedAttributeBase as LandAuctionRegistryAttribute;
if (null != registry_attribute)
{
var origin_attribute = landAuction.getOriginEntityAttribute<LandAuctionRegistryAttribute>();
NullReferenceCheckHelper.throwIfNull(origin_attribute);
var registry_doc = fromDoc as LandAuctionRegistryDoc;
NullReferenceCheckHelper.throwIfNull(registry_doc, () => $"registry_doc is null !!! : docType:{fromDoc.getTypeName()} - {landAuction.toBasicString()}");
var registry_attrib = registry_doc.getAttrib<LandAuctionRegistryAttrib>();
NullReferenceCheckHelper.throwIfNull(registry_attrib, () => $"registry_attrib is null !!! - {landAuction.toBasicString()}");
result = registry_attrib.checkValidLandAuctionRegistry();
if (result.isFail())
{
return result;
}
var fn_copy_to_attribute = delegate ()
{
if (origin_attribute.RegisteredVersionTime < registry_attrib.RegisteredVersionTime)
{
registry_attribute.copyRegisteredInfoFromDoc(registry_doc);
origin_attribute.copyRegisteredInfoFromDoc(registry_doc);
}
if (origin_attribute.ProcessVersionTime < registry_attrib.ProcessVersionTime)
{
registry_attribute.copyProcessInfoFromDoc(registry_doc);
origin_attribute.copyProcessInfoFromDoc(registry_doc);
}
auction_action.updateRegistryVersion( registry_attrib.RegisteredVersionTime, registry_attrib.ProcessVersionTime );
};
if (true == isWithLock)
{
using (var releaser = await landAuction.getAsyncLock())
{
fn_copy_to_attribute();
}
}
else
{
fn_copy_to_attribute();
}
return result;
}
var highest_bid_user_attribute = toClonedAttributeBase as LandAuctionHighestBidUserAttribute;
if (null != highest_bid_user_attribute)
{
var origin_attribute = landAuction.getOriginEntityAttribute<LandAuctionHighestBidUserAttribute>();
NullReferenceCheckHelper.throwIfNull(origin_attribute);
var highest_bid_user_doc = fromDoc as LandAuctionHighestBidUserDoc;
NullReferenceCheckHelper.throwIfNull(highest_bid_user_doc, () => $"highest_bid_user_doc is null !!! : docType:{fromDoc.getTypeName()} - {landAuction.toBasicString()}");
var highest_bid_user_attrib = highest_bid_user_doc.getAttrib<LandAuctionHighestBidUserAttrib>();
NullReferenceCheckHelper.throwIfNull(highest_bid_user_attrib, () => $"highest_bid_user_attrib is null !!! - {landAuction.toBasicString()}");
if (origin_attribute.HighestRankVersionTime < highest_bid_user_attrib.HighestRankVersionTime)
{
highest_bid_user_attribute.copyEntityAttributeFromDoc(highest_bid_user_doc);
origin_attribute.copyEntityAttributeFromDoc(highest_bid_user_doc);
}
auction_action.updateHighestRankVersion(highest_bid_user_attrib.HighestRankVersionTime);
return result;
}
ConditionValidCheckHelper.throwIfFalseWithCondition( () => false
, () => $"Failed to copy EntityAttribute from Doc !!! : attributeType:{toClonedAttributeBase.getTypeName()} <= docType:{fromDoc.getTypeName()}"
+ $" - {landAuction.toBasicString()}");
return result;
}
public static (bool, LandAuctionVersion?) checkChangedVersion( this LandAuctionVersion preVersion
, DateTime registeredVersionTime, DateTime processVersionTime, DateTime highestRankVersionTime )
{
var version = new LandAuctionVersion(registeredVersionTime, processVersionTime, highestRankVersionTime);
if (true == preVersion.checkChangedVersion(version))
{
return (true, version);
}
return (false, null);
}
public static bool checkChangedVersion(this LandAuctionVersion preVersion, LandAuctionVersion currVersion)
{
if( preVersion.RegisteredVersionTime < currVersion.RegisteredVersionTime
|| preVersion.ProcessVersionTime < currVersion.ProcessVersionTime
|| preVersion.HighestRankVersionTime < currVersion.HighestRankVersionTime )
{
Log.getLogger().info( $"changed Version !!! "
+ $" : prevVersion.RegisteredVersion:{preVersion.RegisteredVersionTime} < currVersion.RegisteredVersion:{currVersion.RegisteredVersionTime}"
+ $", prevVersion.ProcessVersion:{preVersion.ProcessVersionTime} < currVersion.ProcessVersion:{currVersion.ProcessVersionTime}"
+ $", prevVersion.HighestRankVersion:{preVersion.HighestRankVersionTime} < currVersion.HighestRankVersion:{currVersion.HighestRankVersionTime}" );
if(preVersion.RegisteredVersionTime > currVersion.RegisteredVersionTime) { currVersion.RegisteredVersionTime = preVersion.RegisteredVersionTime; }
if(preVersion.ProcessVersionTime > currVersion.ProcessVersionTime) { currVersion.ProcessVersionTime = preVersion.ProcessVersionTime; }
if(preVersion.HighestRankVersionTime > currVersion.HighestRankVersionTime) { currVersion.HighestRankVersionTime = preVersion.HighestRankVersionTime; }
currVersion.IsSyncRequried = true;
return true;
}
return false;
}
public static bool isLandAuctionStateByTime(this LandAuctionCheckResult checkResult, LandAuctionState state)
{
var land_auction_info = checkResult.LandAuctionInfo;
NullReferenceCheckHelper.throwIfNull(land_auction_info, () => $"land_auction_info is null !!!");
if (LandAuctionState.Waiting == state)
{
if (false == DateTimeHelper.hasTimeReached(land_auction_info.AuctionReservationNoticeStartTime.ToDateTime()))
{
return true;
}
}
else if (LandAuctionState.Scheduled == state)
{
if ( true == DateTimeHelper.hasTimeReached(land_auction_info.AuctionReservationNoticeStartTime.ToDateTime())
&& false == DateTimeHelper.hasTimeReached(land_auction_info.AuctionStartTime.ToDateTime()))
{
return true;
}
}
else if (LandAuctionState.Started == state)
{
if (true == DateTimeHelper.isBetween(land_auction_info.AuctionStartTime.ToDateTime(), land_auction_info.AuctionEndTime.ToDateTime()))
{
return true;
}
}
else if (LandAuctionState.Ended == state)
{
if (true == DateTimeHelper.hasTimeReached(land_auction_info.AuctionEndTime.ToDateTime()))
{
return true;
}
}
else
{
var err_msg = $"Invalid LandAuctionState !!! : {state}";
Log.getLogger().warn(err_msg);
}
return false;
}
public static bool isLandAuctionState(this LandAuctionCheckResult checkResult, LandAuctionState state)
{
var land_auction_info = checkResult.LandAuctionInfo;
NullReferenceCheckHelper.throwIfNull(land_auction_info, () => $"land_auction_info is null !!!");
if ( state == land_auction_info.LandAuctionState )
{
return true;
}
return false;
}
public static string toBasicString(this LandAuctionCheckResult checkResult)
{
return $"{checkResult.getTypeName()}: LandAuctionInfo:{checkResult.LandAuctionInfo.toBasicString()}, BidType:{checkResult.LandAuctionBidType}"
+ $", CurrencyType:{checkResult.MyBidCurrencyType}, MyBidPrice:{checkResult.MyBidPrice}, {checkResult.Version.toBasicString()}";
}
public static string toBasicString(this LandAuctionBidResult bidResult)
{
return $"{bidResult.getTypeName()}: TargetLandAuction:{bidResult.TargetLandAuction?.toBasicString()}, BidType:{bidResult.CurrentBidType}"
+ $", BidTime:{bidResult.BidTime}";
}
public static bool isLandAuctionStateByTime(this LandAuctionRegistryAttribute registryAttribute, LandAuctionState state)
{
if (LandAuctionState.Waiting == state)
{
if (false == DateTimeHelper.hasTimeReached(registryAttribute.AuctionReservationNoticeStartTime))
{
return true;
}
}
else if (LandAuctionState.Scheduled == state)
{
if ( true == DateTimeHelper.hasTimeReached(registryAttribute.AuctionReservationNoticeStartTime)
&& false == DateTimeHelper.hasTimeReached(registryAttribute.AuctionStartTime) )
{
return true;
}
}
else if (LandAuctionState.Started == state)
{
if (true == DateTimeHelper.isBetween( registryAttribute.AuctionStartTime, registryAttribute.AuctionEndTime) )
{
return true;
}
}
else if (LandAuctionState.Ended == state)
{
if (true == DateTimeHelper.hasTimeReached(registryAttribute.AuctionEndTime))
{
return true;
}
}
else
{
var err_msg = $"Invalid LandAuctionState !!! : {state}";
Log.getLogger().warn(err_msg);
}
return false;
}
}
}

View File

@@ -0,0 +1,146 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ServerCore; using ServerBase;
using ServerCommon;
using MetaAssets;
using static ServerCommon.MetaHelper;
using META_ID = System.UInt32;
namespace GameServer
{
public static class LandAuctionMetaHelper
{
public static string getStringKeyOfLandName(this LandMetaData landMetaData)
{
var err_msg = string.Empty;
if (false == MetaData.Instance._textTable.TryGetValue(landMetaData.LandName, out var found_text_string_meta))
{
err_msg = $"Failed to MetaData.TextTable.TryGetValue() !!! : LandName:{landMetaData.LandName} - LandMetaId:{landMetaData.LandId}";
Log.getLogger().error(err_msg);
return err_msg;
}
return found_text_string_meta.Key;
}
public static Result checkValidLandAuctionRegistry(this LandAuctionRegistryAttrib attrib)
{
var result = new Result();
var err_msg = string.Empty;
var is_invalid = false;
var land_meta_id = attrib.LandMetaId;
if (false == MetaData.Instance._LandTable.TryGetValue((Int32)land_meta_id, out var land_meta_data))
{
err_msg = $"Not found LandMeta !!! : landMetaId:{land_meta_id} - {attrib.toBasicString()}";
result.setFail(ServerErrorCode.LandMetaDataNotFound, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
if (EditorType.USER != land_meta_data.Editor)
{
err_msg = $"Invalid EditorType !!! : EditorType.USER == {land_meta_data.Editor} landMetaId:{land_meta_id} - {attrib.toBasicString()}";
result.setFail(ServerErrorCode.LandAuctionEditorTypeInvalid, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
if (0 >= land_meta_data.LinkedItem)
{
err_msg = $"Not set LinkedItem of LandItem : landMetaId:{land_meta_id} - {attrib.toBasicString()}";
result.setFail(ServerErrorCode.LandAuctionLandItemNotSet, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
var bid_currency_type = attrib.BidCurrencyType;
if (CurrencyType.None == bid_currency_type)
{
err_msg = $"invalid CurrencyType !!! : bidCurrencyType:{bid_currency_type} != CurrencyType.None - {attrib.toBasicString()}";
Log.getLogger().error(err_msg);
is_invalid = true;
}
var notice_start_time = attrib.AuctionReservationNoticeStartTime;
if (false == notice_start_time.isValidTime())
{
err_msg = $"invalid AuctionReservationNoticeStartTime !!! : setTime:{notice_start_time} - {attrib.toBasicString()}";
Log.getLogger().error(err_msg);
is_invalid = true;
}
var start_time = attrib.AuctionStartTime;
if (false == start_time.isValidTime())
{
err_msg = $"invalid AuctionStartTime !!! : setTime:{start_time} - {attrib.toBasicString()}";
Log.getLogger().error(err_msg);
is_invalid = true;
}
var end_time = attrib.AuctionEndTime;
if (false == end_time.isValidTime())
{
err_msg = $"invalid AuctionEndTime !!! : setTime:{end_time} - {attrib.toBasicString()}";
Log.getLogger().error(err_msg);
is_invalid = true;
}
if (start_time >= end_time)
{
err_msg = $"invalid AuctionEndTime !!!, AuctionEndTime must be greater than AuctionStartTime !!! : setEndTime:{end_time} > setStartTime:{start_time} - {attrib.toBasicString()}";
Log.getLogger().error(err_msg);
is_invalid = true;
}
var bid_start_price = attrib.BidStartPrice;
if (0 >= bid_start_price)
{
err_msg = $"invalid BidStartPrice !!! : BidStartPrice:{bid_start_price} > 0 - {attrib.toBasicString()}";
Log.getLogger().error(err_msg);
is_invalid = true;
}
if (true == is_invalid)
{
result.setFail(ServerErrorCode.LandAuctionRegistryInfoInvalid, err_msg);
}
return result;
}
public static LandAuctionBidType toCurrentBidType(DateTime auctionEndTime)
{
// 블라인드 입찰 시점인지 체크 한다.
var time_span_before_auction_end_time = TimeSpan.FromMinutes(ServerCommon.MetaHelper.GameConfigMeta.BlindBidStartBeforeLandAuctionEndMinutes);
var blind_bid_start_time = auctionEndTime.Subtract(time_span_before_auction_end_time);
// 시간을 기준으로 입찰 종료 예외 체크
if(DateTimeHelper.Current >= auctionEndTime)
{
return LandAuctionBidType.None;
}
// 일반 입찰
if (DateTimeHelper.Current < blind_bid_start_time)
{
return LandAuctionBidType.Normal;
}
// 블라인드 입찰
return LandAuctionBidType.Blind;
}
}
}