초기커밋
This commit is contained in:
1314
GameServer/Contents/BeaconShop/Action/BeaconShopAction.cs
Normal file
1314
GameServer/Contents/BeaconShop/Action/BeaconShopAction.cs
Normal file
File diff suppressed because it is too large
Load Diff
266
GameServer/Contents/BeaconShop/BeaconShopCheat.cs
Normal file
266
GameServer/Contents/BeaconShop/BeaconShopCheat.cs
Normal file
@@ -0,0 +1,266 @@
|
||||
using ServerCommon;
|
||||
using ServerCore; using ServerBase;
|
||||
using System.Net.WebSockets;
|
||||
using static ServerCommon.MetaHelper;
|
||||
|
||||
namespace GameServer;
|
||||
|
||||
[ChatCommandAttribute("beaconshopregisteritem", typeof(CheatBeaconShopregisterItem), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
|
||||
internal class CheatBeaconShopregisterItem : ChatCommandBase
|
||||
{
|
||||
public override async Task invoke(Player player, string token, string[] args)
|
||||
{
|
||||
Log.getLogger().info($"CheatBeaconShopregisterItem");
|
||||
|
||||
if (args.Length < 1)
|
||||
{
|
||||
Log.getLogger().error($"Invalid Argument");
|
||||
return;
|
||||
}
|
||||
|
||||
if (uint.TryParse(args[0], out uint item_meta_id) == false)
|
||||
return;
|
||||
|
||||
var beacon_shop_action = player.getEntityAction<BeaconShopAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(beacon_shop_action, () => $"beacon_shop_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
var inventory_action = player.getEntityAction<InventoryActionBase>();
|
||||
NullReferenceCheckHelper.throwIfNull(inventory_action, () => $"inventory_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
var item_list = inventory_action.tryGetItemAllByItemMetaId(item_meta_id);
|
||||
if (item_list.Count == 0)
|
||||
return;
|
||||
|
||||
var item_attribute = item_list[0].getEntityAttribute<ItemAttributeBase>();
|
||||
NullReferenceCheckHelper.throwIfNull(item_attribute, () => $"item_attribute is null !!! - {player.toBasicString()}");
|
||||
|
||||
var player_action = player.getEntityAction<PlayerAction>();
|
||||
var ugc_npc_dictionary = player_action.getHadUgcNpcs();
|
||||
if (ugc_npc_dictionary.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var npc_attribute = ugc_npc_dictionary.First().Value.getEntityAttribute<UgcNpcAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(npc_attribute, () => $"npc_attribute is null !!! - {player.toBasicString()}");
|
||||
|
||||
var result = await beacon_shop_action.tryRegisterItemToBeaconShop(item_attribute.ItemGuid, 1, 0.1, npc_attribute.UgcNpcMetaGuid);
|
||||
if (result.isFail())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[ChatCommandAttribute("beaconshopreturn", typeof(CheatBeaconShopReturn), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
|
||||
internal class CheatBeaconShopReturn : ChatCommandBase
|
||||
{
|
||||
public override async Task invoke(Player player, string token, string[] args)
|
||||
{
|
||||
Log.getLogger().info($"CheatBeaconShopReturn");
|
||||
|
||||
if (args.Length < 2)
|
||||
{
|
||||
Log.getLogger().error($"Invalid Argument");
|
||||
return;
|
||||
}
|
||||
|
||||
var itemGuid = args[0];
|
||||
var beaconGuid = args[1];
|
||||
|
||||
var beacon_shop_action = player.getEntityAction<BeaconShopAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(beacon_shop_action, () => $"beacon_shop_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
var result = await beacon_shop_action.BeaconShopReturnItem(itemGuid, beaconGuid);
|
||||
if (result.isFail())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[ChatCommandAttribute("beaconshoppurchaseitem", typeof(CheatBeaconShopPurchaseItem), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
|
||||
internal class CheatBeaconShopPurchaseItem : ChatCommandBase
|
||||
{
|
||||
public override async Task invoke(Player player, string token, string[] args)
|
||||
{
|
||||
Log.getLogger().info($"CheatBeaconShopreturn");
|
||||
|
||||
if (args.Length < 4)
|
||||
{
|
||||
Log.getLogger().error($"Invalid Argument");
|
||||
return;
|
||||
}
|
||||
|
||||
var itemGuid = args[0];
|
||||
|
||||
if (ushort.TryParse(args[1], out ushort itemAmount) == false)
|
||||
return;
|
||||
|
||||
var beaconGuid = args[2];
|
||||
var beaconOwnerGuid = args[3];
|
||||
|
||||
var beacon_shop_action = player.getEntityAction<BeaconShopAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(beacon_shop_action, () => $"beacon_shop_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
var result = await beacon_shop_action.BeaconShopPurchaseItem(itemGuid, itemAmount, beaconGuid, beaconOwnerGuid);
|
||||
if (result.isFail())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[ChatCommandAttribute("beaconshopreceivepayment", typeof(CheatBeaconShopReceivePayment), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
|
||||
internal class CheatBeaconShopReceivePayment : ChatCommandBase
|
||||
{
|
||||
public override async Task invoke(Player player, string token, string[] args)
|
||||
{
|
||||
Log.getLogger().info($"CheatBeaconShopReceivePayment");
|
||||
|
||||
if (args.Length < 1)
|
||||
{
|
||||
Log.getLogger().error($"Invalid Argument");
|
||||
return;
|
||||
}
|
||||
|
||||
var beaconGuid = args[0];
|
||||
|
||||
var beacon_shop_action = player.getEntityAction<BeaconShopAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(beacon_shop_action, () => $"beacon_shop_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
var result = await beacon_shop_action.BeaconShopReceivePaymentForSales(beaconGuid);
|
||||
if (result.isFail())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[ChatCommandAttribute("beaconshopitemtimechange", typeof(CheatBeaconShopItemTimeChange), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
|
||||
internal class CheatBeaconShopItemTimeChange : ChatCommandBase
|
||||
{
|
||||
public override async Task invoke(Player player, string token, string[] args)
|
||||
{
|
||||
Log.getLogger().info($"CheatBeaconShopItemTimeChange");
|
||||
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
if (args.Length < 1)
|
||||
{
|
||||
Log.getLogger().error($"Invalid Argument");
|
||||
return;
|
||||
}
|
||||
|
||||
if (int.TryParse(args[0], out int minutes) == false)
|
||||
return;
|
||||
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
var fn_start = async delegate ()
|
||||
{
|
||||
var player_action = player.getEntityAction<PlayerAction>();
|
||||
|
||||
var npcs = player_action.getHadUgcNpcs();
|
||||
foreach (var npc in npcs)
|
||||
{
|
||||
var ugc_npc_beacon_shop_action = npc.Value.getEntityAction<UgcNpcBeaconShopAction>();
|
||||
var beaconShopItems = ugc_npc_beacon_shop_action.getHasBeaconShopItem();
|
||||
foreach (var beaconShopItem in beaconShopItems)
|
||||
{
|
||||
var beacon_shop_item_attribute = beaconShopItem.getEntityAttribute<BeaconShopItemAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(beacon_shop_item_attribute, () => $"beacon_shop_item_attribute is null !!!");
|
||||
|
||||
var cheat_selling_finish_time = DateTime.UtcNow.AddMinutes(minutes);
|
||||
|
||||
beacon_shop_item_attribute.SellingFinishTime = cheat_selling_finish_time;
|
||||
beacon_shop_item_attribute.modifiedEntityAttribute();
|
||||
}
|
||||
}
|
||||
|
||||
var batch = new QueryBatchEx<QueryRunnerWithDocument>(player, LogActionType.CheatCommandBeaconShopItemTimeChange
|
||||
, server_logic.getDynamoDbClient());
|
||||
{
|
||||
batch.addQuery(new DBQWriteToAttributeAllWithTransactionRunner());
|
||||
}
|
||||
|
||||
var result = await QueryHelper.sendQueryAndBusinessLog(batch);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
result = await player.runTransactionRunnerSafely(TransactionIdType.PrivateContents, "CheatBeaconShopItemTimeChange", fn_start);
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to runTransactionRunnerSafely() !!! : {result.toBasicString()} - {player.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[ChatCommandAttribute("beaconshopdailylimitinit", typeof(CheatBeaconShopDailyLimitInit), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
|
||||
internal class CheatBeaconShopDailyLimitInit : ChatCommandBase
|
||||
{
|
||||
public override async Task invoke(Player player, string token, string[] args)
|
||||
{
|
||||
Log.getLogger().info($"CheatBeaconShopdailylimitinit");
|
||||
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
var fn_start = async delegate ()
|
||||
{
|
||||
var player_action = player.getEntityAction<PlayerAction>();
|
||||
|
||||
var npcs = player_action.getHadUgcNpcs();
|
||||
foreach (var npc in npcs)
|
||||
{
|
||||
var beacon_shop_profile_attribute = npc.Value.getEntityAttribute<BeaconShopProfileAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(beacon_shop_profile_attribute, () => $"beacon_shop_item_attribute is null !!!");
|
||||
|
||||
beacon_shop_profile_attribute.DailyRegisterCount = 0;
|
||||
beacon_shop_profile_attribute.modifiedEntityAttribute();
|
||||
}
|
||||
|
||||
var batch = new QueryBatchEx<QueryRunnerWithDocument>(player, LogActionType.CheatCommandDailyLimitInit
|
||||
, server_logic.getDynamoDbClient());
|
||||
{
|
||||
batch.addQuery(new DBQWriteToAttributeAllWithTransactionRunner());
|
||||
}
|
||||
|
||||
var result = await QueryHelper.sendQueryAndBusinessLog(batch);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
result = await player.runTransactionRunnerSafely(TransactionIdType.PrivateContents, "CheatBeaconShopdailylimitinit", fn_start);
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to runTransactionRunnerSafely() !!! : {result.toBasicString()} - {player.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
140
GameServer/Contents/BeaconShop/BeaconShopItem.cs
Normal file
140
GameServer/Contents/BeaconShop/BeaconShopItem.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using ServerCommon;
|
||||
using ServerCore; using ServerBase;
|
||||
|
||||
using BEACON_GUID = System.String;
|
||||
using USER_GUID = System.String;
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
public class BeaconShopItem : Item
|
||||
{
|
||||
public BeaconShopItem(UgcNpc owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task<Result> onInit()
|
||||
{
|
||||
var direct_parent = getDirectParent();
|
||||
NullReferenceCheckHelper.throwIfNull(direct_parent, () => $"direct_parent is null !!!");
|
||||
addEntityAttribute(new BeaconShopItemAttribute(this, direct_parent));
|
||||
return await base.onInit();
|
||||
}
|
||||
|
||||
public override string toBasicString()
|
||||
{
|
||||
return $"{this.getTypeName()} - {getRootParent().toBasicString()}";
|
||||
}
|
||||
|
||||
public override string toSummaryString()
|
||||
{
|
||||
return $"{this.getTypeName()} - {getRootParent().toBasicString()}";
|
||||
}
|
||||
|
||||
public static async Task<(Result, BeaconShopItem?)> createBeaconShopFromDoc(UgcNpc owner, BeaconShopItemDoc doc)
|
||||
{
|
||||
var beacon_shop_item = new BeaconShopItem(owner);
|
||||
var result = await beacon_shop_item.onInit();
|
||||
if (result.isFail())
|
||||
{
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var beacon_shop_attribute = beacon_shop_item.getEntityAttribute<BeaconShopItemAttribute>();
|
||||
if (beacon_shop_attribute == null)
|
||||
{
|
||||
err_msg = $"Failed to get beacon shop attribute : {nameof(BeaconShopItemAttribute)}";
|
||||
result.setFail(ServerErrorCode.EntityAttributeIsNull, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
if (beacon_shop_attribute.copyEntityAttributeFromDoc(doc) == false)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeFromDoc !!! : doc_type {doc.GetType()} - {beacon_shop_item.getRootParent().toBasicString()}";
|
||||
result.setFail(ServerErrorCode.DynamoDbDocCopyToEntityAttributeFailed, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
return (result, beacon_shop_item);
|
||||
}
|
||||
|
||||
public static async Task<(Result, BeaconShopItem?)> createBeaconShop(UgcNpc owner, USER_GUID user_guid, BEACON_GUID beacon_guid, DateTime selling_finish_time, double price_for_unit, ushort amount, ItemAttributeBase deleted_item_attribute)
|
||||
{
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var beacon_shop_item = new BeaconShopItem(owner);
|
||||
var result = await beacon_shop_item.onInit();
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to create onInit!!";
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
var beacon_shop_attribute = beacon_shop_item.getEntityAttribute<BeaconShopItemAttribute>();
|
||||
if (beacon_shop_attribute == null)
|
||||
{
|
||||
err_msg = $"Failed to get beacon shop attribute : {nameof(BeaconShopItemAttribute)}";
|
||||
result.setFail(ServerErrorCode.EntityAttributeIsNull, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
beacon_shop_attribute.UserGuid = user_guid;
|
||||
beacon_shop_attribute.BeaconGuid = beacon_guid;
|
||||
beacon_shop_attribute.SellingFinishTime = selling_finish_time;
|
||||
beacon_shop_attribute.PriceForUnit = price_for_unit;
|
||||
|
||||
beacon_shop_attribute.ItemMetaId = deleted_item_attribute.ItemMetaId;
|
||||
beacon_shop_attribute.ItemStackCount = amount;
|
||||
beacon_shop_attribute.Level = deleted_item_attribute.Level;
|
||||
beacon_shop_attribute.Attributes = deleted_item_attribute.Attributes.Select(x => x).ToList();
|
||||
beacon_shop_attribute.EquipedIvenType = deleted_item_attribute.EquipedIvenType;
|
||||
beacon_shop_attribute.EquipedPos = deleted_item_attribute.EquipedPos;
|
||||
|
||||
beacon_shop_attribute.newEntityAttribute();
|
||||
|
||||
return (result, beacon_shop_item);
|
||||
}
|
||||
|
||||
public override MetaAssets.ItemMetaData? getItemMeta()
|
||||
{
|
||||
var parent = getRootParent();
|
||||
NullReferenceCheckHelper.throwIfNull(parent, () => $"parent is null !!!");
|
||||
|
||||
var beacon_shop_item_attribute = getEntityAttribute<BeaconShopItemAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(beacon_shop_item_attribute, () => $"beacon_shop_item_attribute is null !!! - {parent.toBasicString()}");
|
||||
|
||||
if (!MetaData.Instance._ItemTable.TryGetValue((int)beacon_shop_item_attribute.ItemMetaId, out var found_item_meta_data))
|
||||
{
|
||||
var err_msg = $"Not found meta of Item !!! : itemMetaId:{beacon_shop_item_attribute.ItemMetaId} - {parent.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return null;
|
||||
}
|
||||
|
||||
return found_item_meta_data;
|
||||
}
|
||||
|
||||
public BeaconShopInfo toBeaconShopData4Client()
|
||||
{
|
||||
var beacon_shop_4_client = new BeaconShopInfo();
|
||||
|
||||
var beacon_shop_attribute = getEntityAttribute<BeaconShopItemAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(beacon_shop_attribute, () => $"beacon_shop_attribute is null !!!");
|
||||
|
||||
beacon_shop_4_client.BeaconGuid = beacon_shop_attribute.BeaconGuid;
|
||||
beacon_shop_4_client.ItemGuid = beacon_shop_attribute.ItemGuid;
|
||||
beacon_shop_4_client.ItemMetaid = (int)beacon_shop_attribute.ItemMetaId;
|
||||
beacon_shop_4_client.SellingFinishTime = Timestamp.FromDateTime(beacon_shop_attribute.SellingFinishTime);
|
||||
beacon_shop_4_client.PriceForUnit = beacon_shop_attribute.PriceForUnit;
|
||||
beacon_shop_4_client.Amount = beacon_shop_attribute.ItemStackCount;
|
||||
|
||||
return beacon_shop_4_client;
|
||||
}
|
||||
}
|
||||
}
|
||||
62
GameServer/Contents/BeaconShop/BeaconShopSoldPrice.cs
Normal file
62
GameServer/Contents/BeaconShop/BeaconShopSoldPrice.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
|
||||
|
||||
namespace GameServer;
|
||||
|
||||
public class BeaconShopSoldPrice : EntityBase
|
||||
{
|
||||
public BeaconShopSoldPrice(EntityBase owner)
|
||||
: base(EntityType.BeaconShopSoldPrice, owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task<Result> onInit()
|
||||
{
|
||||
addEntityAttribute(new BeaconShopSoldPriceAttribute(this));
|
||||
return await base.onInit();
|
||||
}
|
||||
|
||||
public override string toBasicString()
|
||||
{
|
||||
return $"{this.getTypeName()} - {getRootParent().toBasicString()}";
|
||||
}
|
||||
|
||||
public override string toSummaryString()
|
||||
{
|
||||
return $"{this.getTypeName()} - {getRootParent().toBasicString()}";
|
||||
}
|
||||
|
||||
public static async Task<(Result, BeaconShopSoldPrice?)> createBeaconShopSoldPriceFromDoc(Player owner, BeaconShopSoldPriceDoc doc)
|
||||
{
|
||||
var beacon_shop_sold_price = new BeaconShopSoldPrice(owner);
|
||||
var result = await beacon_shop_sold_price.onInit();
|
||||
if (result.isFail())
|
||||
{
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var beacon_shop_sold_price_attribute = beacon_shop_sold_price.getEntityAttribute<BeaconShopSoldPriceAttribute>();
|
||||
if (beacon_shop_sold_price_attribute == null)
|
||||
{
|
||||
err_msg = $"Failed to get beacon shop sold price attribute : {nameof(BeaconShopSoldPriceAttribute)}";
|
||||
result.setFail(ServerErrorCode.EntityAttributeIsNull, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
if (beacon_shop_sold_price_attribute.copyEntityAttributeFromDoc(doc) == false)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeFromDoc !!! : doc_type {doc.GetType()} - {beacon_shop_sold_price.getRootParent().toBasicString()}";
|
||||
result.setFail(ServerErrorCode.DynamoDbDocCopyToEntityAttributeFailed, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
return (result, beacon_shop_sold_price);
|
||||
}
|
||||
}
|
||||
83
GameServer/Contents/BeaconShop/BeaconShopSoldRecord.cs
Normal file
83
GameServer/Contents/BeaconShop/BeaconShopSoldRecord.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using ServerCommon;
|
||||
using ServerCore; using ServerBase;
|
||||
|
||||
using BEACON_GUID = System.String;
|
||||
using META_ID = System.UInt32;
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
public class BeaconShopSoldRecord : EntityBase
|
||||
{
|
||||
public BeaconShopSoldRecord(EntityBase owner)
|
||||
: base(EntityType.BeaconShopSoldRecord, owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task<Result> onInit()
|
||||
{
|
||||
addEntityAttribute(new BeaconShopSoldRecordAttribute(this));
|
||||
return await base.onInit();
|
||||
}
|
||||
|
||||
public override string toBasicString()
|
||||
{
|
||||
return $"{this.getTypeName()} - {getRootParent().toBasicString()}";
|
||||
}
|
||||
|
||||
public override string toSummaryString()
|
||||
{
|
||||
return $"{this.getTypeName()} - {getRootParent().toBasicString()}";
|
||||
}
|
||||
|
||||
public static async Task<(Result, BeaconShopSoldRecord?)> createBeaconShopSoldRecordFromDoc(Player owner, BeaconShopSoldRecordDoc doc)
|
||||
{
|
||||
var beacon_shop_sold_record_item = new BeaconShopSoldRecord(owner);
|
||||
var result = await beacon_shop_sold_record_item.onInit();
|
||||
if (result.isFail())
|
||||
{
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var beacon_shop_sold_record_attribute = beacon_shop_sold_record_item.getEntityAttribute<BeaconShopSoldRecordAttribute>();
|
||||
if (beacon_shop_sold_record_attribute == null)
|
||||
{
|
||||
err_msg = $"Failed to get beacon shop sold record attribute : {nameof(BeaconShopSoldRecordAttribute)}";
|
||||
result.setFail(ServerErrorCode.EntityAttributeIsNull, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
if (beacon_shop_sold_record_attribute.copyEntityAttributeFromDoc(doc) == false)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeFromDoc !!! : doc_type {doc.GetType()} - {beacon_shop_sold_record_item.getRootParent().toBasicString()}";
|
||||
result.setFail(ServerErrorCode.DynamoDbDocCopyToEntityAttributeFailed, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
return (result, beacon_shop_sold_record_item);
|
||||
}
|
||||
|
||||
public BeaconShopSoldRecordInfo toBeaconShopSoldRecordData4Client()
|
||||
{
|
||||
var beacon_shop_sold_record_4_client = new BeaconShopSoldRecordInfo();
|
||||
|
||||
var beacon_shop_sold_record_attribute = getEntityAttribute<BeaconShopSoldRecordAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(beacon_shop_sold_record_attribute, () => $"beacon_shop_sold_record_attribute is null !!!");
|
||||
|
||||
beacon_shop_sold_record_4_client.BeaconGuid = beacon_shop_sold_record_attribute.BeaconGuid;
|
||||
beacon_shop_sold_record_4_client.ItemMetaid = (int)beacon_shop_sold_record_attribute.ItemMetaId;
|
||||
beacon_shop_sold_record_4_client.BuyerNickName = beacon_shop_sold_record_attribute.BuyerNickName;
|
||||
beacon_shop_sold_record_4_client.PriceForUnit = beacon_shop_sold_record_attribute.PriceForUnit;
|
||||
beacon_shop_sold_record_4_client.Amount = beacon_shop_sold_record_attribute.Amount;
|
||||
beacon_shop_sold_record_4_client.SoldPrice = beacon_shop_sold_record_attribute.SoldPrice;
|
||||
beacon_shop_sold_record_4_client.TaxPrice = beacon_shop_sold_record_attribute.TaxPrice;
|
||||
beacon_shop_sold_record_4_client.GivenPrice = beacon_shop_sold_record_attribute.GivenPrice;
|
||||
|
||||
return beacon_shop_sold_record_4_client;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
using System.Globalization;
|
||||
|
||||
|
||||
using Amazon.DynamoDBv2;
|
||||
using Amazon.DynamoDBv2.DocumentModel;
|
||||
using Amazon.DynamoDBv2.Model;
|
||||
|
||||
|
||||
using ServerCore; using ServerBase;
|
||||
using ServerCommon;
|
||||
|
||||
|
||||
|
||||
namespace GameServer;
|
||||
|
||||
public class DBQBeaconShopItemDelete : QueryExecutorBase
|
||||
{
|
||||
private string m_combination_key_for_pk = string.Empty;
|
||||
|
||||
private string m_combination_key_for_sk = string.Empty;
|
||||
private double m_item_count { get; set; }
|
||||
|
||||
private PrimaryKey m_primary_key = new();
|
||||
|
||||
public DBQBeaconShopItemDelete(string combinationKeyForPK, string combinationKeyForSK, int itemCount) : base(nameof(DBQBeaconShopItemDelete))
|
||||
{
|
||||
m_item_count = itemCount;
|
||||
m_combination_key_for_pk = combinationKeyForPK;
|
||||
m_combination_key_for_sk = combinationKeyForSK;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// DB 쿼리 직전에 준비해야 할 로직들을 작성한다.
|
||||
//=====================================================================================
|
||||
public override async Task<Result> onPrepareQuery()
|
||||
{
|
||||
var owner = getOwner();
|
||||
|
||||
var (result, make_primary_key) = await DynamoDBDocBaseHelper.makePrimaryKey<BeaconShopItemDoc>(m_combination_key_for_pk, m_combination_key_for_sk);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
NullReferenceCheckHelper.throwIfNull(make_primary_key, () => $"make_primary_key is null !!! - {owner.toBasicString()}");
|
||||
|
||||
m_primary_key = make_primary_key;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// onPrepareQuery()를 성공할 경우 호출된다.
|
||||
//=====================================================================================
|
||||
public override async Task<Result> onQuery()
|
||||
{
|
||||
var owner = getOwner();
|
||||
|
||||
var query_batch = getQueryBatch() as QueryBatch<QueryRunnerWithItemRequest>;
|
||||
NullReferenceCheckHelper.throwIfNull(query_batch, () => $"query_batch is null !!! - {owner.toBasicString()}");
|
||||
|
||||
var query_runner_with_item_request = query_batch.getQueryRunner();
|
||||
NullReferenceCheckHelper.throwIfNull(query_runner_with_item_request, () => $"query_runner_with_item_request is null !!! - {owner.toBasicString()}");
|
||||
|
||||
var db_connector = query_batch.getDynamoDbConnector();
|
||||
|
||||
var table = db_connector.getTableByDoc<BeaconShopItemDoc>();
|
||||
var delete = makeDeleteItemRequestBeaconShopItem(table, m_primary_key.toKeyWithAttributeValue(), JsonHelper.getJsonPropertyName<BeaconShopItemAttrib>(nameof(BeaconShopItemAttrib.ItemStackCount)));
|
||||
if (delete.result.isFail()) return delete.result;
|
||||
NullReferenceCheckHelper.throwIfNull(delete.deleteRequest, () => $"deleteRequest is null !!! - {owner.toBasicString()}");
|
||||
|
||||
var exception_handler = new DynamoDbQueryExceptionNotifier.ExceptionHandler(DynamoDbQueryExceptionNotifier.ConditionalCheckFailed, ServerErrorCode.BeaconShopUpdateNewData);
|
||||
|
||||
var query_context = delete.deleteRequest.createItemRequestQueryContext(QueryType.Delete, exception_handler);
|
||||
var result = await query_runner_with_item_request.tryRegisterQueryContext(query_context);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// 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;
|
||||
}
|
||||
|
||||
private (Result result, DeleteItemRequest? deleteRequest) makeDeleteItemRequestBeaconShopItem( Table table
|
||||
, Dictionary<string, AttributeValue> attributeValueWithPrimaryKey
|
||||
, string targetAttribName )
|
||||
{
|
||||
var result = new Result();
|
||||
string err_msg;
|
||||
|
||||
if (string.IsNullOrEmpty(targetAttribName))
|
||||
{
|
||||
err_msg = $"Failed to DynamoDbClientHelper.toAttributeExpressionFromJson() !!! : targetAttribName - {targetAttribName}";
|
||||
result.setFail(ServerErrorCode.AttribPathMakeFailed, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
var query_builder = new DynamoDbItemRequestHelper.DeleteItemRequestBuilder(table.TableName);
|
||||
query_builder.withKeys(attributeValueWithPrimaryKey);
|
||||
query_builder.withConditionExpression($"attribute_exists({PrimaryKey.PK_Define}) AND attribute_exists({PrimaryKey.SK_Define})");
|
||||
|
||||
var target_doc = new BeaconShopItemDoc();
|
||||
var attrib_path_json_string = target_doc.toJsonStringOfAttribs();
|
||||
(var is_success, var attribute_expression) = DynamoDbClientHelper.toAttributeExpressionFromJson(attrib_path_json_string, targetAttribName);
|
||||
if (false == is_success)
|
||||
{
|
||||
err_msg = $"Failed to DynamoDbClientHelper.toAttributeExpressionFromJson() !!! : attribPath:{attrib_path_json_string}, targetKey:{targetAttribName}";
|
||||
result.setFail(ServerErrorCode.AttribPathMakeFailed, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
var attribute_names = DynamoDbClientHelper.toExpressionAttributeNamesFromJson(attrib_path_json_string, targetAttribName);
|
||||
query_builder.withExpressionAttributeNames(attribute_names);
|
||||
query_builder.withConditionExpression($"{attribute_expression} = :changeValue");
|
||||
|
||||
var expression_attribute_values = new Dictionary<string, AttributeValue>
|
||||
{
|
||||
{ ":changeValue", new AttributeValue { N = Math.Abs(m_item_count).ToString(CultureInfo.InvariantCulture) } }
|
||||
};
|
||||
query_builder.withExpressionAttributeValues(expression_attribute_values);
|
||||
|
||||
query_builder.withReturnValues(ReturnValue.ALL_NEW);
|
||||
|
||||
return (result, query_builder.build());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
using System.Globalization;
|
||||
|
||||
|
||||
using Amazon.DynamoDBv2;
|
||||
using Amazon.DynamoDBv2.DocumentModel;
|
||||
using Amazon.DynamoDBv2.Model;
|
||||
|
||||
|
||||
using ServerCore; using ServerBase;
|
||||
using ServerCommon;
|
||||
|
||||
|
||||
|
||||
namespace GameServer;
|
||||
|
||||
public class DBQBeaconShopItemUpdate : QueryExecutorBase
|
||||
{
|
||||
private string m_combination_key_for_pk = string.Empty;
|
||||
|
||||
private string m_combination_key_for_sk = string.Empty;
|
||||
private double m_delta { get; set; }
|
||||
|
||||
private PrimaryKey m_primary_key = new();
|
||||
|
||||
//=====================================================================================
|
||||
// 0 < deltaCount => 증가
|
||||
// 0 > deltaCount => 감소
|
||||
//=====================================================================================
|
||||
|
||||
public DBQBeaconShopItemUpdate(string combinationKeyForPK, string combinationKeyForSK, double delta) : base(nameof(DBQBeaconShopItemUpdate))
|
||||
{
|
||||
m_delta = delta;
|
||||
m_combination_key_for_pk = combinationKeyForPK;
|
||||
m_combination_key_for_sk = combinationKeyForSK;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// DB 쿼리 직전에 준비해야 할 로직들을 작성한다.
|
||||
//=====================================================================================
|
||||
public override async Task<Result> onPrepareQuery()
|
||||
{
|
||||
var owner = getOwner();
|
||||
|
||||
var (result, make_primary_key) = await DynamoDBDocBaseHelper.makePrimaryKey<BeaconShopItemDoc>(m_combination_key_for_pk, m_combination_key_for_sk);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
NullReferenceCheckHelper.throwIfNull(make_primary_key, () => $"make_primary_key is null !!! - {owner.toBasicString()}");
|
||||
|
||||
m_primary_key = make_primary_key;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// onPrepareQuery()를 성공할 경우 호출된다.
|
||||
//=====================================================================================
|
||||
public override async Task<Result> onQuery()
|
||||
{
|
||||
var owner = getOwner();
|
||||
|
||||
var query_batch = getQueryBatch() as QueryBatch<QueryRunnerWithItemRequest>;
|
||||
NullReferenceCheckHelper.throwIfNull(query_batch, () => $"query_batch is null !!! - {owner.toBasicString()}");
|
||||
|
||||
var query_runner_with_item_request = query_batch.getQueryRunner();
|
||||
NullReferenceCheckHelper.throwIfNull(query_runner_with_item_request, () => $"query_runner_with_item_request is null !!! - {owner.toBasicString()}");
|
||||
|
||||
var db_connector = query_batch.getDynamoDbConnector();
|
||||
|
||||
var table = db_connector.getTableByDoc<BeaconShopItemDoc>();
|
||||
var update = makeUpdateItemRequestUpdateBeaconShopItemCount(table, m_primary_key.toKeyWithAttributeValue(), JsonHelper.getJsonPropertyName<BeaconShopItemAttrib>(nameof(BeaconShopItemAttrib.ItemStackCount)));
|
||||
if (update.result.isFail()) return update.result;
|
||||
NullReferenceCheckHelper.throwIfNull(update.updateRequest, () => $"update_request is null !!! - {owner.toBasicString()}");
|
||||
|
||||
var exception_handler = new DynamoDbQueryExceptionNotifier.ExceptionHandler(DynamoDbQueryExceptionNotifier.ConditionalCheckFailed, ServerErrorCode.BeaconShopUpdateNewData);
|
||||
|
||||
var query_context = update.updateRequest.createItemRequestQueryContext(QueryType.Update, exception_handler);
|
||||
var result = await query_runner_with_item_request.tryRegisterQueryContext(query_context);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// 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;
|
||||
}
|
||||
|
||||
private (Result result, UpdateItemRequest? updateRequest) makeUpdateItemRequestUpdateBeaconShopItemCount( Table table
|
||||
, Dictionary<string, AttributeValue> attributeValueWithPrimaryKey
|
||||
, string targetAttribName )
|
||||
{
|
||||
var result = new Result();
|
||||
string err_msg;
|
||||
|
||||
if (string.IsNullOrEmpty(targetAttribName))
|
||||
{
|
||||
err_msg = $"Failed to DynamoDbClientHelper.toAttributeExpressionFromJson() !!! : targetAttribName - {targetAttribName}";
|
||||
result.setFail(ServerErrorCode.AttribPathMakeFailed, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
var query_builder = new DynamoDbItemRequestHelper.UpdateItemRequestBuilder(table.TableName);
|
||||
query_builder.withKeys(attributeValueWithPrimaryKey);
|
||||
|
||||
var target_doc = new BeaconShopItemDoc();
|
||||
var attrib_path_json_string = target_doc.toJsonStringOfAttribs();
|
||||
(var is_success, var attribute_expression) = DynamoDbClientHelper.toAttributeExpressionFromJson(attrib_path_json_string, targetAttribName);
|
||||
if (false == is_success)
|
||||
{
|
||||
err_msg = $"Failed to DynamoDbClientHelper.toAttributeExpressionFromJson() !!! : attribPath:{attrib_path_json_string}, targetKey:{targetAttribName}";
|
||||
result.setFail(ServerErrorCode.AttribPathMakeFailed, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
var attribute_names = DynamoDbClientHelper.toExpressionAttributeNamesFromJson(attrib_path_json_string, targetAttribName);
|
||||
query_builder.withExpressionAttributeNames(attribute_names);
|
||||
|
||||
var update_expression = (m_delta >= 0)
|
||||
? $"SET {attribute_expression} = if_not_exists({attribute_expression}, :start) + :changeValue"
|
||||
: $"SET {attribute_expression} = if_not_exists({attribute_expression}, :start) - :changeValue";
|
||||
|
||||
query_builder.withUpdateExpression(update_expression);
|
||||
|
||||
if (m_delta < 0)
|
||||
{
|
||||
query_builder.withConditionExpression($"{attribute_expression} >= :changeValue");
|
||||
}
|
||||
|
||||
var expression_attribute_values = new Dictionary<string, AttributeValue>
|
||||
{
|
||||
{ ":changeValue", new AttributeValue { N = Math.Abs(m_delta).ToString(CultureInfo.InvariantCulture) } },
|
||||
{ ":start", new AttributeValue { N = "0" } }
|
||||
};
|
||||
query_builder.withExpressionAttributeValues(expression_attribute_values);
|
||||
|
||||
query_builder.withReturnValues(ReturnValue.ALL_NEW);
|
||||
|
||||
return query_builder.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
using Amazon.DynamoDBv2.DocumentModel;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
|
||||
|
||||
namespace GameServer;
|
||||
|
||||
public class DBQBeaconShopSoldReadAll : QueryExecutorBase
|
||||
{
|
||||
private string m_combination_key_for_pk = string.Empty;
|
||||
|
||||
private string m_recoed_pk = string.Empty;
|
||||
private string m_price_pk = string.Empty;
|
||||
|
||||
private List<BeaconShopSoldRecordDoc> m_to_read_beacon_shop_sold_record_docs = new();
|
||||
private List<BeaconShopSoldPriceDoc> m_to_read_beacon_shop_sold_price_docs = new();
|
||||
|
||||
public DBQBeaconShopSoldReadAll(string combinationKeyForPK)
|
||||
: base(typeof(DBQBeaconShopSoldReadAll).Name)
|
||||
{
|
||||
m_combination_key_for_pk = combinationKeyForPK;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// DB 쿼리 직전에 준비해야 할 로직들을 작성한다.
|
||||
//=====================================================================================
|
||||
public override Task<Result> onPrepareQuery()
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => "owner is null !!!");
|
||||
|
||||
var record_doc = new BeaconShopSoldRecordDoc();
|
||||
record_doc.setCombinationKeyForPK(m_combination_key_for_pk);
|
||||
|
||||
var error_code = record_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 Task.FromResult(result);
|
||||
}
|
||||
|
||||
m_recoed_pk = record_doc.getPK();
|
||||
|
||||
var price_doc = new BeaconShopSoldPriceDoc();
|
||||
price_doc.setCombinationKeyForPK(m_combination_key_for_pk);
|
||||
|
||||
error_code = price_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 Task.FromResult(result);
|
||||
}
|
||||
|
||||
m_price_pk = price_doc.getPK();
|
||||
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// onPrepareQuery()를 성공할 경우 호출된다.
|
||||
//=====================================================================================
|
||||
public override async Task<Result> onQuery()
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var owner = getOwner();
|
||||
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_recoed_pk);
|
||||
|
||||
(result, var record_read_docs) = await db_connector.simpleQueryDocTypesWithQueryOperationConfig<BeaconShopSoldRecordDoc>(query_config, eventTid: query_batch.getTransId());
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var beacon_shop_inventory_action = owner.getEntityAction<BeaconShopAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(beacon_shop_inventory_action, () => "beacon_shop_inventory_action is null !!!");
|
||||
|
||||
result = await beacon_shop_inventory_action.AddBeaconShopSoldRecordsFromDocs(record_read_docs);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var price_query_config = db_connector.makeQueryConfigForReadByPKOnly(m_price_pk);
|
||||
|
||||
(result, var price_read_docs) = await db_connector.simpleQueryDocTypesWithQueryOperationConfig<BeaconShopSoldPriceDoc>(price_query_config, eventTid: query_batch.getTransId());
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
result = await beacon_shop_inventory_action.AddBeaconShopSoldPriceFromDocs(price_read_docs);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
result = await beacon_shop_inventory_action.ProcessBeaconShopDeleteRecord();
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
m_to_read_beacon_shop_sold_record_docs = record_read_docs;
|
||||
m_to_read_beacon_shop_sold_price_docs = price_read_docs;
|
||||
|
||||
return await Task.FromResult(result);
|
||||
}
|
||||
|
||||
public List<BeaconShopSoldRecordDoc> getToReadItemDocs() => m_to_read_beacon_shop_sold_record_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;
|
||||
}
|
||||
|
||||
public new Player? getOwner() => getQueryBatch()?.getLogActor() as Player;
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
using Amazon.DynamoDBv2.DocumentModel;
|
||||
using GameServer;
|
||||
using ServerCommon;
|
||||
using ServerCore; using ServerBase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
public class DBQBeaconShopSoldRecordReadAll : QueryExecutorBase
|
||||
{
|
||||
private string m_combination_key_for_pk = string.Empty;
|
||||
|
||||
private string m_pk = string.Empty;
|
||||
|
||||
private List<BeaconShopSoldRecordDoc> m_to_read_beacon_shop_sold_record_docs = new();
|
||||
|
||||
public DBQBeaconShopSoldRecordReadAll(string combinationKeyForPK)
|
||||
: base(typeof(DBQBeaconShopSoldRecordReadAll).Name)
|
||||
{
|
||||
m_combination_key_for_pk = combinationKeyForPK;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// DB 쿼리 직전에 준비해야 할 로직들을 작성한다.
|
||||
//=====================================================================================
|
||||
public override Task<Result> onPrepareQuery()
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => "owner is null !!!");
|
||||
|
||||
var doc = new BeaconShopSoldRecordDoc();
|
||||
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 Task.FromResult(result);
|
||||
}
|
||||
|
||||
m_pk = doc.getPK();
|
||||
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// onPrepareQuery()를 성공할 경우 호출된다.
|
||||
//=====================================================================================
|
||||
public override async Task<Result> onQuery()
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var owner = getOwner();
|
||||
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<BeaconShopSoldRecordDoc>(query_config, eventTid: query_batch.getTransId());
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var beacon_shop_inventory_action = owner.getEntityAction<BeaconShopAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(beacon_shop_inventory_action, () => "beacon_shop_inventory_action is null !!!");
|
||||
|
||||
result = await beacon_shop_inventory_action.AddBeaconShopSoldRecordsFromDocs(read_docs);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
m_to_read_beacon_shop_sold_record_docs = read_docs;
|
||||
|
||||
return await Task.FromResult(result);
|
||||
}
|
||||
|
||||
public List<BeaconShopSoldRecordDoc> getToReadItemDocs() => m_to_read_beacon_shop_sold_record_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;
|
||||
}
|
||||
|
||||
public new Player? getOwner() => getQueryBatch()?.getLogActor() as Player;
|
||||
}
|
||||
}
|
||||
121
GameServer/Contents/BeaconShop/Helper/BeaconShopHelper.cs
Normal file
121
GameServer/Contents/BeaconShop/Helper/BeaconShopHelper.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using ServerCommon;
|
||||
using USER_GUID = System.String;
|
||||
using BEACON_GUID = System.String;
|
||||
using META_ID = System.UInt32;
|
||||
using ServerCore; using ServerBase;
|
||||
using static ServerMessage.Types;
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
internal static class BeaconShopHelper
|
||||
{
|
||||
public static BeaconShopItemBoardInfo toBeaconShopItemMongoDataClient(this BeaconShopMongoDoc beaconShopMongoDoc)
|
||||
{
|
||||
var beacon_shop_4_client = new BeaconShopItemBoardInfo();
|
||||
|
||||
beacon_shop_4_client.ItemGuid = beaconShopMongoDoc.ItemGuid;
|
||||
beacon_shop_4_client.ItemMetaid = (int)beaconShopMongoDoc.TagId;
|
||||
beacon_shop_4_client.BeaconGuid = beaconShopMongoDoc.BeaconGuid;
|
||||
beacon_shop_4_client.BeaconNickName = beaconShopMongoDoc.BeaconNickName;
|
||||
beacon_shop_4_client.BeaconTitle = beaconShopMongoDoc.BeaconTitle;
|
||||
beacon_shop_4_client.BeaconBodyItemMetaId = beaconShopMongoDoc.BeaconBodyItemMetaId;
|
||||
beacon_shop_4_client.PriceForUnit = beaconShopMongoDoc.PriceForUnit;
|
||||
beacon_shop_4_client.Amount = beaconShopMongoDoc.Amount;
|
||||
beacon_shop_4_client.OwnerGuid = beaconShopMongoDoc.OwnerGuid;
|
||||
beacon_shop_4_client.OwnerNickName = beaconShopMongoDoc.OwnerNickName;
|
||||
beacon_shop_4_client.BeaconMyHomeGuid = beaconShopMongoDoc.BeaconMyHomeGuid;
|
||||
beacon_shop_4_client.SellingFinishTime = Timestamp.FromDateTime(beaconShopMongoDoc.SellingFinishTime);
|
||||
|
||||
return beacon_shop_4_client;
|
||||
}
|
||||
|
||||
public async static Task<BeaconShopSoldRecordDoc?> CreateBeaconShopSoldRecord(BeaconShopItemAttribute beaconShopItemAttribute, string buyerNickName, int amount, double soldPrice, double taxPrice, double givenPrice)
|
||||
{
|
||||
DateTime now = DateTimeHelper.Current;
|
||||
|
||||
var beacon_shop_sold_record_doc = new BeaconShopSoldRecordDoc(beaconShopItemAttribute.UserGuid, now);
|
||||
|
||||
var beacon_shop_sold_record_attrib = beacon_shop_sold_record_doc.getAttrib<BeaconShopSoldRecordAttrib>();
|
||||
if (beacon_shop_sold_record_attrib == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
beacon_shop_sold_record_attrib.UserGuid = beaconShopItemAttribute.UserGuid;
|
||||
beacon_shop_sold_record_attrib.BeaconGuid = beaconShopItemAttribute.BeaconGuid;
|
||||
beacon_shop_sold_record_attrib.ItemMetaId = beaconShopItemAttribute.ItemMetaId;
|
||||
beacon_shop_sold_record_attrib.BuyerNickName = buyerNickName;
|
||||
beacon_shop_sold_record_attrib.PriceForUnit = beaconShopItemAttribute.PriceForUnit;
|
||||
beacon_shop_sold_record_attrib.Amount = amount;
|
||||
beacon_shop_sold_record_attrib.SalesTime = now;
|
||||
beacon_shop_sold_record_attrib.SoldPrice = soldPrice;
|
||||
beacon_shop_sold_record_attrib.TaxPrice = taxPrice;
|
||||
beacon_shop_sold_record_attrib.GivenPrice = givenPrice;
|
||||
|
||||
var result = await beacon_shop_sold_record_doc.newDoc4Query();
|
||||
if (result.isFail())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return beacon_shop_sold_record_doc;
|
||||
}
|
||||
|
||||
public static void send_GS2GS_NTF_UPDATE_SOLD_RECORD(string targetServer, USER_GUID targetUserGuid)
|
||||
{
|
||||
ConditionValidCheckHelper.throwIfFalseWithCondition(() => true != targetServer.isNullOrWhiteSpace()
|
||||
, () => $"targetServer is NullOrWhiteSpace !!! - targetServer:{targetServer}, targetUserGuid:{targetUserGuid}");
|
||||
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
var rabbit_mq_4_game = server_logic.getRabbitMqConnector() as RabbitMQ4Game;
|
||||
NullReferenceCheckHelper.throwIfNull(rabbit_mq_4_game, () => $"rabbit_mq_4_game is null !!");
|
||||
|
||||
var ntf_packet = new ServerMessage();
|
||||
var ntf_update_sold_record = new GS2GS_NTF_UPDATE_SOLD_RECORD();
|
||||
ntf_packet.NtfUpdateSoldRecord = ntf_update_sold_record;
|
||||
|
||||
ntf_update_sold_record.TargetUserGuid = targetUserGuid;
|
||||
|
||||
rabbit_mq_4_game.SendMessage(targetServer, ntf_packet);
|
||||
}
|
||||
|
||||
public static void send_GS2GS_NTF_UPDATE_BEACON_SHOP_ITEM(USER_GUID targetUserGuid, BEACON_GUID targetBeaconGuid)
|
||||
{
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
var rabbit_mq_4_game = server_logic.getRabbitMqConnector() as RabbitMQ4Game;
|
||||
NullReferenceCheckHelper.throwIfNull(rabbit_mq_4_game, () => $"rabbit_mq_4_game is null !!");
|
||||
|
||||
var ntf_packet = new ServerMessage();
|
||||
var ntf_update_beacon_shop_item = new GS2GS_NTF_UPDATE_BEACON_SHOP_ITEM();
|
||||
ntf_packet.NtfUpdateBeaconShopItem = ntf_update_beacon_shop_item;
|
||||
|
||||
ntf_update_beacon_shop_item.TargetUserGuid = targetUserGuid;
|
||||
ntf_update_beacon_shop_item.TargetBeaconGuid = targetBeaconGuid;
|
||||
|
||||
rabbit_mq_4_game.sendMessageToExchangeAllGame(ntf_packet);
|
||||
}
|
||||
|
||||
public static ItemDoc toItemDocFromBeaconShopItemDoc(BeaconShopItemDoc beaconShopItemDoc, ushort itemStackCount)
|
||||
{
|
||||
var beacon_shop_item_attrib = beaconShopItemDoc.getAttrib<BeaconShopItemAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(beacon_shop_item_attrib, () => $"beacon_shop_item_attrib is null !!");
|
||||
|
||||
var item_guid = Guid.NewGuid().ToString("N");
|
||||
var itemDoc = new ItemDoc(beacon_shop_item_attrib.OwnerEntityType, beacon_shop_item_attrib.UserGuid, item_guid);
|
||||
|
||||
var item_attrib = itemDoc.getAttrib<ItemAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(item_attrib, () => $"item_attrib is null !!!");
|
||||
item_attrib.ItemMetaId = beacon_shop_item_attrib.ItemMetaId;
|
||||
item_attrib.ItemStackCount = itemStackCount;
|
||||
item_attrib.Level = beacon_shop_item_attrib.Level;
|
||||
item_attrib.Attributes = beacon_shop_item_attrib.Attributes.Select(x => x).ToList();
|
||||
item_attrib.EquipedIvenType = beacon_shop_item_attrib.EquipedIvenType;
|
||||
item_attrib.EquipedPos = beacon_shop_item_attrib.EquipedPos;
|
||||
|
||||
return itemDoc;
|
||||
}
|
||||
}
|
||||
}
|
||||
33
GameServer/Contents/BeaconShop/Log/BeaconShopBusinessLog.cs
Normal file
33
GameServer/Contents/BeaconShop/Log/BeaconShopBusinessLog.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
|
||||
namespace GameServer;
|
||||
|
||||
public class BeaconShopBusinessLog : ILogInvokerEx
|
||||
{
|
||||
private BeaconShopLogData m_data_to_log;
|
||||
public BeaconShopBusinessLog(BeaconShopLogData log_data_param)
|
||||
: base(LogDomainType.BeaconShop)
|
||||
{
|
||||
m_data_to_log = log_data_param;
|
||||
}
|
||||
|
||||
public override bool hasLog()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void fillup(ref BusinessLog.LogBody body)
|
||||
{
|
||||
body.append(new BeaconShopLogData(this, m_data_to_log));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using ServerCommon;
|
||||
using META_ID = System.UInt32;
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
static public class BeaconShopBusinessLogHelper
|
||||
{
|
||||
static public BeaconShopLogData toLogInfo(BeaconShopMongoDoc beaconShopMongoDoc)
|
||||
{
|
||||
var logData = new BeaconShopLogData();
|
||||
logData.setInfo(beaconShopMongoDoc);
|
||||
return logData;
|
||||
}
|
||||
|
||||
static public void setInfo(this BeaconShopLogData logData, BeaconShopMongoDoc beaconShopMongoDoc)
|
||||
{
|
||||
logData.ItemGuid = beaconShopMongoDoc.ItemGuid;
|
||||
logData.TagId = beaconShopMongoDoc.TagId;
|
||||
logData.BeaconGuid = beaconShopMongoDoc.BeaconGuid;
|
||||
logData.BeaconNickName = beaconShopMongoDoc.BeaconNickName;
|
||||
logData.BeaconTitle = beaconShopMongoDoc.BeaconTitle;
|
||||
logData.BeaconBodyItemMetaId = beaconShopMongoDoc.BeaconBodyItemMetaId;
|
||||
logData.PriceForUnit = beaconShopMongoDoc.PriceForUnit;
|
||||
logData.Amount = beaconShopMongoDoc.Amount;
|
||||
logData.OwnerGuid = beaconShopMongoDoc.OwnerGuid;
|
||||
logData.OwnerNickName = beaconShopMongoDoc.OwnerNickName;
|
||||
logData.BeaconMyHomeGuid = beaconShopMongoDoc.BeaconMyHomeGuid;
|
||||
logData.SellingFinishTime = beaconShopMongoDoc.SellingFinishTime;
|
||||
logData.BuyerGuid = string.Empty;
|
||||
}
|
||||
|
||||
static public BeaconShopLogData toLogInfo(BeaconShopItemAttribute beaconShopItemAttribute, UgcNpcAttribute ugcNpcAttribute, string buyerGuid)
|
||||
{
|
||||
var logData = new BeaconShopLogData();
|
||||
logData.setInfo(beaconShopItemAttribute, ugcNpcAttribute, buyerGuid);
|
||||
return logData;
|
||||
}
|
||||
|
||||
static public void setInfo(this BeaconShopLogData logData, BeaconShopItemAttribute beaconShopItemAttribute, UgcNpcAttribute ugcNpcAttribute, string buyerGuid)
|
||||
{
|
||||
logData.ItemGuid = beaconShopItemAttribute.ItemGuid;
|
||||
logData.TagId = (int)beaconShopItemAttribute.ItemMetaId;
|
||||
logData.BeaconGuid = beaconShopItemAttribute.BeaconGuid;
|
||||
logData.BeaconNickName = ugcNpcAttribute.Nickname;
|
||||
logData.BeaconTitle = ugcNpcAttribute.Title;
|
||||
logData.BeaconBodyItemMetaId = (int)ugcNpcAttribute.BodyItemMetaId;
|
||||
logData.PriceForUnit = beaconShopItemAttribute.PriceForUnit;
|
||||
logData.Amount = beaconShopItemAttribute.ItemStackCount;
|
||||
logData.OwnerGuid = beaconShopItemAttribute.UserGuid;
|
||||
logData.BeaconMyHomeGuid = ugcNpcAttribute.LocatedInstanceGuid;
|
||||
logData.SellingFinishTime = beaconShopItemAttribute.SellingFinishTime;
|
||||
logData.BuyerGuid = buyerGuid;
|
||||
}
|
||||
|
||||
static public BeaconShopSoldRecordLogData toLogInfo(BeaconShopSoldRecordAttribute beaconShopSoldRecordAttribute)
|
||||
{
|
||||
var logData = new BeaconShopSoldRecordLogData();
|
||||
logData.setInfo(beaconShopSoldRecordAttribute);
|
||||
return logData;
|
||||
}
|
||||
|
||||
static public void setInfo(this BeaconShopSoldRecordLogData logData, BeaconShopSoldRecordAttribute beaconShopSoldRecordAttribute)
|
||||
{
|
||||
logData.UserGuid = beaconShopSoldRecordAttribute.UserGuid;
|
||||
logData.BeaconGuid = beaconShopSoldRecordAttribute.BeaconGuid;
|
||||
logData.ItemMetaId = beaconShopSoldRecordAttribute.ItemMetaId;
|
||||
logData.BuyerNickName = beaconShopSoldRecordAttribute.BuyerNickName;
|
||||
logData.PriceForUnit = beaconShopSoldRecordAttribute.PriceForUnit;
|
||||
logData.Amount = beaconShopSoldRecordAttribute.Amount;
|
||||
logData.SalesTime = beaconShopSoldRecordAttribute.SalesTime;
|
||||
}
|
||||
|
||||
static public BeaconShopSoldPriceLogData toLogInfo(string userGuid, string beaconGuid, double deltaPrice, double deltaTaxPrice)
|
||||
{
|
||||
var logData = new BeaconShopSoldPriceLogData();
|
||||
logData.setInfo(userGuid, beaconGuid, deltaPrice, deltaTaxPrice);
|
||||
return logData;
|
||||
}
|
||||
|
||||
static public void setInfo(this BeaconShopSoldPriceLogData logData, string userGuid, string beaconGuid, double deltaPrice, double deltaTaxPrice)
|
||||
{
|
||||
logData.UserGuid = userGuid;
|
||||
logData.BeaconGuid = beaconGuid;
|
||||
logData.deltaPrice = deltaPrice;
|
||||
logData.deltaTaxPrice = deltaTaxPrice;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
|
||||
|
||||
namespace GameServer;
|
||||
|
||||
public class BeaconShopSoldPriceBusinessLog : ILogInvokerEx
|
||||
{
|
||||
private BeaconShopSoldPriceLogData m_data_to_log;
|
||||
public BeaconShopSoldPriceBusinessLog(BeaconShopSoldPriceLogData log_data_param)
|
||||
: base(LogDomainType.BeaconShopSoldPrice)
|
||||
{
|
||||
m_data_to_log = log_data_param;
|
||||
}
|
||||
|
||||
public override bool hasLog()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void fillup(ref BusinessLog.LogBody body)
|
||||
{
|
||||
body.append(new BeaconShopSoldPriceLogData(this, m_data_to_log));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
namespace GameServer;
|
||||
|
||||
public class BeaconShopSoldRecordBusinessLog : ILogInvokerEx
|
||||
{
|
||||
private BeaconShopSoldRecordLogData m_data_to_log;
|
||||
public BeaconShopSoldRecordBusinessLog(BeaconShopSoldRecordLogData log_data_param)
|
||||
: base(LogDomainType.BeaconShopSoldRecord)
|
||||
{
|
||||
m_data_to_log = log_data_param;
|
||||
}
|
||||
|
||||
public override bool hasLog()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void fillup(ref BusinessLog.LogBody body)
|
||||
{
|
||||
body.append(new BeaconShopSoldRecordLogData(this, m_data_to_log));
|
||||
}
|
||||
}
|
||||
26
GameServer/Contents/BeaconShop/MongoDb/BeaconShopMongoDoc.cs
Normal file
26
GameServer/Contents/BeaconShop/MongoDb/BeaconShopMongoDoc.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
|
||||
namespace GameServer;
|
||||
|
||||
|
||||
public class BeaconShopMongoDoc
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public string Id { get; set; } = null!;
|
||||
public string ItemGuid { get; set; } = null!;
|
||||
public int TagId { get; set; } = 0;
|
||||
public string BeaconGuid { get; set; } = null!;
|
||||
public string BeaconNickName { get; set; } = null!;
|
||||
public string BeaconTitle { get; set; } = string.Empty;
|
||||
public int BeaconBodyItemMetaId { get; set; } = 0;
|
||||
public double PriceForUnit { get; set; } = 0;
|
||||
public int Amount { get; set; } = 0;
|
||||
public string OwnerGuid { get; set; } = null!;
|
||||
public string OwnerNickName { get; set; } = null!;
|
||||
public string BeaconMyHomeGuid { get; set; } = null!;
|
||||
[BsonRequired]
|
||||
public DateTime SellingFinishTime { get; set; } = new();
|
||||
}
|
||||
|
||||
134
GameServer/Contents/BeaconShop/MongoDb/BeaconShopRepository.cs
Normal file
134
GameServer/Contents/BeaconShop/MongoDb/BeaconShopRepository.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
|
||||
using MongoDB.Driver;
|
||||
|
||||
|
||||
using ServerBase;
|
||||
using ServerCore;
|
||||
|
||||
|
||||
using BEACON_GUID = System.String;
|
||||
using META_ID = System.UInt32;
|
||||
using USER_GUID = System.String;
|
||||
using ITEM_GUID = System.String;
|
||||
|
||||
|
||||
namespace GameServer;
|
||||
|
||||
public class BeaconShopRepository : MongoDbRepository<BeaconShopMongoDoc>
|
||||
{
|
||||
private const string CollectionName = "BeaconShop";
|
||||
|
||||
public BeaconShopRepository(IMongoClient mongoClient, MongoDbConf settings) :
|
||||
base(mongoClient, settings.DatabaseName, CollectionName)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<(Result, List<BeaconShopMongoDoc>?)> get(int tagId)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var builder = Builders<BeaconShopMongoDoc>.Filter;
|
||||
var filter = builder.Eq(x => x.TagId, tagId);
|
||||
|
||||
try
|
||||
{
|
||||
var findData = await m_collection.FindAsync(filter);
|
||||
return (result, findData.ToList());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
err_msg = $"MongoDB Write Exception Error: {ex.Message}";
|
||||
result.setFail(ServerErrorCode.BeaconShopFailedGetBoardItem, err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Result> insert(BeaconShopMongoDoc beaconShopEntity)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
await m_collection.InsertOneAsync(beaconShopEntity);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
err_msg = $"MongoDB Write Exception Error: {ex.Message}";
|
||||
result.setFail(ServerErrorCode.BeaconShopFailedRegisterBoard, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<(Result, BeaconShopMongoDoc?)> updateAmount(string id, int amount)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
var filter = Builders<BeaconShopMongoDoc>.Filter
|
||||
.Eq(x => x.ItemGuid, id);
|
||||
|
||||
var update = Builders<BeaconShopMongoDoc>.Update
|
||||
.Inc(x => x.Amount, amount);
|
||||
|
||||
var options = new FindOneAndUpdateOptions<BeaconShopMongoDoc>
|
||||
{
|
||||
ReturnDocument = ReturnDocument.After,
|
||||
};
|
||||
|
||||
var updated = await m_collection.FindOneAndUpdateAsync(filter, update, options);
|
||||
|
||||
if (updated == null)
|
||||
{
|
||||
err_msg = $"MongoDB is already empty. Error";
|
||||
result.setFail(ServerErrorCode.BeaconShopFailedToFindOrUpdate, err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
if (updated.Amount == 0)
|
||||
{
|
||||
return (await delete(id), updated);
|
||||
}
|
||||
return (result, updated);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
err_msg = $"MongoDB Write Exception Error: {ex.Message}";
|
||||
result.setFail(ServerErrorCode.BeaconShopDbException, err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Result> delete(ITEM_GUID item_guid)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var builder = Builders<BeaconShopMongoDoc>.Filter;
|
||||
var filter = builder.Eq(x => x.ItemGuid, item_guid);
|
||||
|
||||
try
|
||||
{
|
||||
var db_result = await m_collection.DeleteOneAsync(filter);
|
||||
if (db_result.DeletedCount == 0)
|
||||
{
|
||||
result.setFail(ServerErrorCode.BeaconShopNotFoundItemFromBoard, err_msg);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
err_msg = $"MongoDB Delete Exception Error : {ex.Message}";
|
||||
result.setFail(ServerErrorCode.BeaconShopFailedDeleteBoard, err_msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
using Google.Protobuf;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
|
||||
|
||||
using static ClientToGameRes.Types;
|
||||
|
||||
|
||||
using META_ID = System.UInt32;
|
||||
|
||||
|
||||
namespace GameServer.PacketHandler;
|
||||
|
||||
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.C2GS_REQ_BEACON_SHOP_GET_ITEM_INFOS), typeof(BeaconShopGetItemInfosPacketHandler), typeof(GameLoginListener))]
|
||||
public class BeaconShopGetItemInfosPacketHandler : PacketRecvHandler
|
||||
{
|
||||
public static bool send_S2C_ACK_BEACON_SHOP_GET_ITEM_INFOS(Player player, Result result, List<BeaconShopItem>? beaconShopItem = null, int dailyRegisterCount = 0, int numOfReceiptNotReceived = 0)
|
||||
{
|
||||
var ack_packet = new ClientToGame();
|
||||
ack_packet.Response = new ClientToGameRes();
|
||||
|
||||
ack_packet.Response.ErrorCode = result.ErrorCode;
|
||||
ack_packet.Response.AckBeaconShopGetItemInfos = new GS2C_ACK_BEACON_SHOP_GET_ITEM_INFOS();
|
||||
|
||||
if (result.isSuccess() && beaconShopItem != null)
|
||||
{
|
||||
ack_packet.Response.AckBeaconShopGetItemInfos.BeaconShopInfos.AddRange(beaconShopItem.Select<BeaconShopItem, BeaconShopInfo>(x => x.toBeaconShopData4Client()).ToList());
|
||||
ack_packet.Response.AckBeaconShopGetItemInfos.DailyRegisterCount = dailyRegisterCount;
|
||||
ack_packet.Response.AckBeaconShopGetItemInfos.NumOfReceiptNotReceived = numOfReceiptNotReceived;
|
||||
}
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(player, ack_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task<Result> onProcessPacket(ISession entityWithSession, IMessage recvMessage)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var entity_player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(entity_player, () => $"entity_player is null !!!");
|
||||
|
||||
var beacon_shop_action = entity_player.getEntityAction<BeaconShopAction>();
|
||||
if (beacon_shop_action == null)
|
||||
{
|
||||
err_msg = $"Failed to get beacon shop action : {nameof(BeaconShopAction)}";
|
||||
result.setFail(ServerErrorCode.EntityActionNotFound, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_GET_ITEM_INFOS(entity_player, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
var game_msg = recvMessage as ClientToGame;
|
||||
if (game_msg == null)
|
||||
{
|
||||
err_msg = $"Failed to cast ClientToGame !!! : {nameof(ClientToGame.Request.ReqBeaconShopGetItemInfos)}";
|
||||
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_GET_ITEM_INFOS(entity_player, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
var request = game_msg.Request.ReqBeaconShopGetItemInfos;
|
||||
|
||||
if (request.BeaconGuid == string.Empty && request.BeaconOwnerGuid == string.Empty)
|
||||
{
|
||||
err_msg = $"Invalid Request Argument !!! : BeaconGuid : {request.BeaconGuid}, BeaconOwnerGuid : {request.BeaconOwnerGuid}";
|
||||
result.setFail(ServerErrorCode.BeaconShopInvalidArgument, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_GET_ITEM_INFOS(entity_player, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
result = await beacon_shop_action.BeaconShopGetItemInfos(request.BeaconGuid, request.BeaconOwnerGuid);
|
||||
if (result.isFail())
|
||||
{
|
||||
send_S2C_ACK_BEACON_SHOP_GET_ITEM_INFOS(entity_player, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override async Task onProcessPacketException(ISession entityWithSession, IMessage recvMessage
|
||||
, Result errorResult)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
var player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!! - {entityWithSession.toBasicString()}");
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_GET_ITEM_INFOS(player, errorResult);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using ServerCore; using ServerBase;
|
||||
using BEACON_GUID = System.String;
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
public static class BeaconShopNotifyHelper
|
||||
{
|
||||
public static bool send_S2C_NTF_BEACON_SHOP_REFRESH(this Player player, BEACON_GUID beaconGuid)
|
||||
{
|
||||
var noti_packet = makeAckBeaconShopRefreshPacket(beaconGuid);
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(player, noti_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static ClientToGame makeAckBeaconShopRefreshPacket(BEACON_GUID beaconGuid)
|
||||
{
|
||||
var noti_packet = new ClientToGame();
|
||||
noti_packet.Message = new();
|
||||
noti_packet.Message.NtfBeaconShopRefresh = new();
|
||||
|
||||
noti_packet.Message.NtfBeaconShopRefresh.BeaconGuid = beaconGuid;
|
||||
|
||||
return noti_packet;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
using Google.Protobuf;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
|
||||
|
||||
using static ClientToGameRes.Types;
|
||||
|
||||
|
||||
namespace GameServer.PacketHandler;
|
||||
|
||||
|
||||
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.C2GS_REQ_BEACON_SHOP_PURCHASE_ITEM), typeof(BeaconShopPurchaseItemPacketHandler), typeof(GameLoginListener))]
|
||||
public class BeaconShopPurchaseItemPacketHandler : PacketRecvHandler
|
||||
{
|
||||
public static bool send_S2C_ACK_BEACON_SHOP_PURCHASE_ITEM(Player player, Result result, string itemGuid = "", string beaconGuid = "", int itemAmount = 0, CommonResult? commonResult = null)
|
||||
{
|
||||
var ack_packet = new ClientToGame();
|
||||
ack_packet.Response = new ClientToGameRes();
|
||||
|
||||
ack_packet.Response.ErrorCode = result.ErrorCode;
|
||||
ack_packet.Response.AckBeaconShopPurchaseItem = new GS2C_ACK_BEACON_SHOP_PURCHASE_ITEM();
|
||||
|
||||
if (result.isSuccess())
|
||||
{
|
||||
ack_packet.Response.AckBeaconShopPurchaseItem.ItemGuid = itemGuid;
|
||||
ack_packet.Response.AckBeaconShopPurchaseItem.BeaconGuid = beaconGuid;
|
||||
ack_packet.Response.AckBeaconShopPurchaseItem.ItemAmount = itemAmount;
|
||||
ack_packet.Response.AckBeaconShopPurchaseItem.CommonResult = commonResult;
|
||||
}
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(player, ack_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task<Result> onProcessPacket(ISession entityWithSession, IMessage recvMessage)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var entity_player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(entity_player, () => $"entity_player is null !!!" );
|
||||
|
||||
var beacon_shop_action = entity_player.getEntityAction<BeaconShopAction>();
|
||||
if (beacon_shop_action == null)
|
||||
{
|
||||
err_msg = $"Failed to get beacon shop action : {nameof(BeaconShopAction)}";
|
||||
result.setFail(ServerErrorCode.EntityActionNotFound, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_PURCHASE_ITEM(entity_player, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
var game_msg = recvMessage as ClientToGame;
|
||||
if (game_msg == null)
|
||||
{
|
||||
err_msg = $"Failed to cast ClientToGame !!! : {nameof(ClientToGame.Request.ReqBeaconShopPurchaseItem)}";
|
||||
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_PURCHASE_ITEM(entity_player, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
var request = game_msg.Request.ReqBeaconShopPurchaseItem;
|
||||
|
||||
if(request.ItemGuid == string.Empty ||
|
||||
request.BeaconGuid == string.Empty ||
|
||||
request.ItemAmount <= 0 ||
|
||||
request.BeaconOwnerGuid == string.Empty)
|
||||
{
|
||||
err_msg = $"Invalid Request Argument !!! : ItemGuid : {request.ItemGuid}, BeaconGuid : {request.BeaconGuid}, ItemAmount : {request.ItemAmount}";
|
||||
result.setFail(ServerErrorCode.BeaconShopInvalidArgument, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_PURCHASE_ITEM(entity_player, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
result = await beacon_shop_action.BeaconShopPurchaseItem(request.ItemGuid, (UInt16)request.ItemAmount, request.BeaconGuid, request.BeaconOwnerGuid);
|
||||
if (result.isFail())
|
||||
{
|
||||
send_S2C_ACK_BEACON_SHOP_PURCHASE_ITEM(entity_player, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override async Task onProcessPacketException(ISession entityWithSession, IMessage recvMessage
|
||||
, Result errorResult)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
var player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!! - {entityWithSession.toBasicString()}");
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_PURCHASE_ITEM(player, errorResult);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
using Google.Protobuf;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
|
||||
|
||||
using static ClientToGameReq.Types;
|
||||
using static ClientToGameRes.Types;
|
||||
|
||||
|
||||
namespace GameServer.PacketHandler;
|
||||
|
||||
|
||||
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.C2GS_REQ_BEACON_SHOP_RECEIVE_PAYMENT_FOR_SALES), typeof(BeaconShopReceivePaymentForSalesPacketHandler), typeof(GameLoginListener))]
|
||||
public class BeaconShopReceivePaymentForSalesPacketHandler : PacketRecvHandler
|
||||
{
|
||||
public static bool send_S2C_ACK_BEACON_SHOP_RECEIVE_PAYMENT_FOR_SALES(Player player, Result result, string beaconGuid = "", CommonResult? commonResult = null)
|
||||
{
|
||||
var ack_packet = new ClientToGame();
|
||||
ack_packet.Response = new ClientToGameRes();
|
||||
|
||||
ack_packet.Response.ErrorCode = result.ErrorCode;
|
||||
ack_packet.Response.AckBeaconShopReceivePaymentForSales = new GS2C_ACK_BEACON_SHOP_RECEIVE_PAYMENT_FOR_SALES();
|
||||
|
||||
if (result.isSuccess())
|
||||
{
|
||||
ack_packet.Response.AckBeaconShopReceivePaymentForSales.BeaconGuid = beaconGuid;
|
||||
ack_packet.Response.AckBeaconShopReceivePaymentForSales.CommonResult = commonResult;
|
||||
}
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(player, ack_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task<Result> onProcessPacket(ISession entityWithSession, IMessage recvMessage)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var entity_player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(entity_player, () => $"entity_player is null !!!" );
|
||||
|
||||
var beacon_shop_action = entity_player.getEntityAction<BeaconShopAction>();
|
||||
if (beacon_shop_action == null)
|
||||
{
|
||||
err_msg = $"Failed to get beacon shop action : {nameof(BeaconShopAction)}";
|
||||
result.setFail(ServerErrorCode.EntityActionNotFound, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_RECEIVE_PAYMENT_FOR_SALES(entity_player, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
var game_msg = recvMessage as ClientToGame;
|
||||
if (game_msg == null)
|
||||
{
|
||||
err_msg = $"Failed to cast ClientToGame !!! : {nameof(ClientToGame.Request.ReqBeaconShopReceivePaymentForSales)}";
|
||||
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_RECEIVE_PAYMENT_FOR_SALES(entity_player, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
var request = game_msg.Request.ReqBeaconShopReceivePaymentForSales;
|
||||
|
||||
if (request.BeaconGuid == string.Empty)
|
||||
{
|
||||
err_msg = $"Invalid Request Argument !!! : BeaconGuid : {request.BeaconGuid}";
|
||||
result.setFail(ServerErrorCode.BeaconShopInvalidArgument, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_RECEIVE_PAYMENT_FOR_SALES(entity_player, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
result = await beacon_shop_action.BeaconShopReceivePaymentForSales(request.BeaconGuid);
|
||||
if (result.isFail())
|
||||
{
|
||||
send_S2C_ACK_BEACON_SHOP_RECEIVE_PAYMENT_FOR_SALES(entity_player, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override async Task onProcessPacketException(ISession entityWithSession, IMessage recvMessage
|
||||
, Result errorResult)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
var player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!! - {entityWithSession.toBasicString()}");
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_RECEIVE_PAYMENT_FOR_SALES(player, errorResult);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
|
||||
|
||||
using static ClientToGameReq.Types;
|
||||
using static ClientToGameRes.Types;
|
||||
|
||||
|
||||
|
||||
|
||||
namespace GameServer.PacketHandler;
|
||||
|
||||
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.C2GS_REQ_BEACON_SHOP_REGISTER_ITEM), typeof(BeaconShopRegisterItemPacketHandler), typeof(GameLoginListener))]
|
||||
public class BeaconShopRegisterItemPacketHandler : PacketRecvHandler
|
||||
{
|
||||
public static bool send_S2C_ACK_BEACON_SHOP_REGISTER_ITEM(Player player, Result result, BeaconShopItem? beaconShopItem, CommonResult? commonResult = null)
|
||||
{
|
||||
var ack_packet = new ClientToGame();
|
||||
ack_packet.Response = new ClientToGameRes();
|
||||
|
||||
ack_packet.Response.ErrorCode = result.ErrorCode;
|
||||
ack_packet.Response.AckBeaconShopRegisterItem = new GS2C_ACK_BEACON_SHOP_REGISTER_ITEM();
|
||||
|
||||
if (result.isSuccess() && beaconShopItem != null)
|
||||
{
|
||||
var beacon_shop_attribute = beaconShopItem.getEntityAttribute<BeaconShopItemAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(beacon_shop_attribute, () => $"beacon_shop_attribute is null !!!");
|
||||
|
||||
ack_packet.Response.AckBeaconShopRegisterItem.ItemGuid = beacon_shop_attribute.ItemGuid;
|
||||
ack_packet.Response.AckBeaconShopRegisterItem.ItemMetaId = (int)beacon_shop_attribute.ItemMetaId;
|
||||
ack_packet.Response.AckBeaconShopRegisterItem.ItemAmount = beacon_shop_attribute.ItemStackCount;
|
||||
ack_packet.Response.AckBeaconShopRegisterItem.SellingPrice = beacon_shop_attribute.PriceForUnit;
|
||||
ack_packet.Response.AckBeaconShopRegisterItem.BeaconGuid = beacon_shop_attribute.BeaconGuid;
|
||||
ack_packet.Response.AckBeaconShopRegisterItem.SellingFinishTime = Timestamp.FromDateTime(beacon_shop_attribute.SellingFinishTime);
|
||||
ack_packet.Response.AckBeaconShopRegisterItem.CommonResult = commonResult;
|
||||
}
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(player, ack_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task<Result> onProcessPacket(ISession entityWithSession, IMessage recvMessage)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var entity_player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(entity_player, () => $"entity_player is null !!!" );
|
||||
|
||||
var beacon_shop_action = entity_player.getEntityAction<BeaconShopAction>();
|
||||
if (beacon_shop_action == null)
|
||||
{
|
||||
err_msg = $"Failed to get beacon shop action : {nameof(BeaconShopAction)}";
|
||||
result.setFail(ServerErrorCode.EntityActionNotFound, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_REGISTER_ITEM(entity_player, result, null);
|
||||
return result;
|
||||
}
|
||||
|
||||
var game_msg = recvMessage as ClientToGame;
|
||||
if (game_msg == null)
|
||||
{
|
||||
err_msg = $"Failed to cast ClientToGame !!! : {nameof(ClientToGame.Request.ReqBeaconShopRegisterItem)}";
|
||||
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_REGISTER_ITEM(entity_player, result, null);
|
||||
return result;
|
||||
}
|
||||
|
||||
var request = game_msg.Request.ReqBeaconShopRegisterItem;
|
||||
|
||||
if (request.ItemGuid == string.Empty ||
|
||||
request.BeaconGuid == string.Empty ||
|
||||
request.ItemAmount <= 0 ||
|
||||
request.SellingPrice <= 0)
|
||||
{
|
||||
err_msg = $"Invalid Request Argument !!! : ItemGuid : {request.ItemGuid}, BeaconGuid : {request.BeaconGuid}, ItemAmount : {request.ItemAmount}, SellingPrice : {request.SellingPrice}";
|
||||
result.setFail(ServerErrorCode.BeaconShopInvalidArgument, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_REGISTER_ITEM(entity_player, result, null);
|
||||
return result;
|
||||
}
|
||||
|
||||
result = await beacon_shop_action.tryRegisterItemToBeaconShop(request.ItemGuid, (UInt16)request.ItemAmount, request.SellingPrice, request.BeaconGuid);
|
||||
if (result.isFail())
|
||||
{
|
||||
send_S2C_ACK_BEACON_SHOP_REGISTER_ITEM(entity_player, result, null);
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override async Task onProcessPacketException(ISession entityWithSession, IMessage recvMessage
|
||||
, Result errorResult)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
var player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!! - {entityWithSession.toBasicString()}");
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_REGISTER_ITEM(player, errorResult, null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
|
||||
using static ClientToGameReq.Types;
|
||||
using static ClientToGameRes.Types;
|
||||
|
||||
|
||||
namespace GameServer.PacketHandler;
|
||||
|
||||
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.C2GS_REQ_BEACON_SHOP_RETURN_ITEM), typeof(BeaconShopReturnItemPacketHandler), typeof(GameLoginListener))]
|
||||
public class BeaconShopReturnItemPacketHandler : PacketRecvHandler
|
||||
{
|
||||
public static bool send_S2C_ACK_BEACON_SHOP_RETURN_ITEM(Player player, Result result, string itemGuid = "", string beaconGuid = "", CommonResult? commonResult = null)
|
||||
{
|
||||
var ack_packet = new ClientToGame();
|
||||
ack_packet.Response = new ClientToGameRes();
|
||||
|
||||
ack_packet.Response.ErrorCode = result.ErrorCode;
|
||||
ack_packet.Response.AckBeaconShopReturnItem = new GS2C_ACK_BEACON_SHOP_RETURN_ITEM();
|
||||
|
||||
if (result.isSuccess())
|
||||
{
|
||||
ack_packet.Response.AckBeaconShopReturnItem.ItemGuid = itemGuid;
|
||||
ack_packet.Response.AckBeaconShopReturnItem.BeaconGuid = beaconGuid;
|
||||
ack_packet.Response.AckBeaconShopReturnItem.CommonResult = commonResult;
|
||||
}
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(player, ack_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task<Result> onProcessPacket(ISession entityWithSession, IMessage recvMessage)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var entity_player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(entity_player, () => $"entity_player is null !!!" );
|
||||
|
||||
var beacon_shop_action = entity_player.getEntityAction<BeaconShopAction>();
|
||||
if (beacon_shop_action == null)
|
||||
{
|
||||
err_msg = $"Failed to get beacon shop action : {nameof(BeaconShopAction)}";
|
||||
result.setFail(ServerErrorCode.EntityActionNotFound, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_RETURN_ITEM(entity_player, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
var game_msg = recvMessage as ClientToGame;
|
||||
if (game_msg == null)
|
||||
{
|
||||
err_msg = $"Failed to cast ClientToGame !!! : {nameof(ClientToGame.Request.ReqBeaconShopReturnItem)}";
|
||||
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_RETURN_ITEM(entity_player, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
var request = game_msg.Request.ReqBeaconShopReturnItem;
|
||||
|
||||
if (request.ItemGuid == string.Empty ||
|
||||
request.BeaconGuid == string.Empty)
|
||||
{
|
||||
err_msg = $"Invalid Request Argument !!! : ItemGuid : {request.ItemGuid}, BeaconGuid : {request.BeaconGuid}";
|
||||
result.setFail(ServerErrorCode.BeaconShopInvalidArgument, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_RETURN_ITEM(entity_player, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
result = await beacon_shop_action.BeaconShopReturnItem(request.ItemGuid, request.BeaconGuid);
|
||||
if (result.isFail())
|
||||
{
|
||||
send_S2C_ACK_BEACON_SHOP_RETURN_ITEM(entity_player, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override async Task onProcessPacketException(ISession entityWithSession, IMessage recvMessage
|
||||
, Result errorResult)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
var player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!! - {entityWithSession.toBasicString()}");
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_RETURN_ITEM(player, errorResult);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
|
||||
|
||||
using static ClientToGameReq.Types;
|
||||
using static ClientToGameRes.Types;
|
||||
|
||||
|
||||
using META_ID = System.UInt32;
|
||||
|
||||
|
||||
namespace GameServer.PacketHandler;
|
||||
|
||||
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.C2GS_REQ_BEACON_SHOP_SEARCH_ITEM), typeof(BeaconShopSearchItemPacketHandler), typeof(GameLoginListener))]
|
||||
public class BeaconShopSearchItemPacketHandler : PacketRecvHandler
|
||||
{
|
||||
public static bool send_S2C_ACK_BEACON_SHOP_SEARCH_ITEM(Player player, Result result, List<BeaconShopMongoDoc>? beaconShopMongoDocs)
|
||||
{
|
||||
var ack_packet = new ClientToGame();
|
||||
ack_packet.Response = new ClientToGameRes();
|
||||
|
||||
ack_packet.Response.ErrorCode = result.ErrorCode;
|
||||
ack_packet.Response.AckBeaconShopSearchItem = new GS2C_ACK_BEACON_SHOP_SEARCH_ITEM();
|
||||
|
||||
if (result.isSuccess() && beaconShopMongoDocs != null)
|
||||
{
|
||||
ack_packet.Response.AckBeaconShopSearchItem.BeaconShopItemBoardInfos.AddRange(beaconShopMongoDocs.Select<BeaconShopMongoDoc, BeaconShopItemBoardInfo>(x => x.toBeaconShopItemMongoDataClient()).ToList());
|
||||
}
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(player, ack_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task<Result> onProcessPacket(ISession entityWithSession, IMessage recvMessage)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var entity_player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(entity_player, () => $"entity_player is null !!!" );
|
||||
|
||||
var beacon_shop_action = entity_player.getEntityAction<BeaconShopAction>();
|
||||
if (beacon_shop_action == null)
|
||||
{
|
||||
err_msg = $"Failed to get beacon shop action : {nameof(BeaconShopAction)}";
|
||||
result.setFail(ServerErrorCode.EntityActionNotFound, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_SEARCH_ITEM(entity_player, result, null);
|
||||
return result;
|
||||
}
|
||||
|
||||
var game_msg = recvMessage as ClientToGame;
|
||||
if (game_msg == null)
|
||||
{
|
||||
err_msg = $"Failed to cast ClientToGame !!! : {nameof(ClientToGame.Request.ReqBeaconShopSearchItem)}";
|
||||
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_SEARCH_ITEM(entity_player, result, null);
|
||||
return result;
|
||||
}
|
||||
|
||||
var request = game_msg.Request.ReqBeaconShopSearchItem;
|
||||
|
||||
if (request.ItemMetaid == 0)
|
||||
{
|
||||
err_msg = $"Invalid Request Argument !!! : ItemMetaid : {request.ItemMetaid}";
|
||||
result.setFail(ServerErrorCode.BeaconShopInvalidArgument, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_SEARCH_ITEM(entity_player, result, null);
|
||||
return result;
|
||||
}
|
||||
|
||||
result = await beacon_shop_action.BeaconShopSearchItem((META_ID)request.ItemMetaid);
|
||||
if (result.isFail())
|
||||
{
|
||||
send_S2C_ACK_BEACON_SHOP_SEARCH_ITEM(entity_player, result, null);
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override async Task onProcessPacketException(ISession entityWithSession, IMessage recvMessage
|
||||
, Result errorResult)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
var player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!! - {entityWithSession.toBasicString()}");
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_SEARCH_ITEM(player, errorResult, null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
using Google.Protobuf;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
|
||||
|
||||
using static ClientToGameRes.Types;
|
||||
|
||||
|
||||
using META_ID = System.UInt32;
|
||||
|
||||
|
||||
|
||||
namespace GameServer.PacketHandler;
|
||||
|
||||
|
||||
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.C2GS_REQ_BEACON_SHOP_GET_SOLD_RECORDS), typeof(BeaconShopSoldRecordInfoPacketHandler), typeof(GameLoginListener))]
|
||||
public class BeaconShopSoldRecordInfoPacketHandler : PacketRecvHandler
|
||||
{
|
||||
public static bool send_S2C_ACK_BEACON_SHOP_GET_SOLD_RECORDS(Player player, Result result, List<BeaconShopSoldRecord>? beaconShopSoldRecords, double totalGivenPrice = 0)
|
||||
{
|
||||
var ack_packet = new ClientToGame();
|
||||
ack_packet.Response = new ClientToGameRes();
|
||||
|
||||
ack_packet.Response.ErrorCode = result.ErrorCode;
|
||||
ack_packet.Response.AckBeaconShopGetSoldRecords = new GS2C_ACK_BEACON_SHOP_GET_SOLD_RECORDS();
|
||||
|
||||
if (result.isSuccess() && beaconShopSoldRecords != null)
|
||||
{
|
||||
ack_packet.Response.AckBeaconShopGetSoldRecords.BeaconShopSoldRecordInfos.AddRange(beaconShopSoldRecords.Select<BeaconShopSoldRecord, BeaconShopSoldRecordInfo>(x => x.toBeaconShopSoldRecordData4Client()).ToList());
|
||||
ack_packet.Response.AckBeaconShopGetSoldRecords.TotalGivenPrice = totalGivenPrice;
|
||||
}
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(player, ack_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task<Result> onProcessPacket(ISession entityWithSession, IMessage recvMessage)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var entity_player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(entity_player, () => $"entity_player is null !!!");
|
||||
|
||||
var beacon_shop_action = entity_player.getEntityAction<BeaconShopAction>();
|
||||
if (beacon_shop_action == null)
|
||||
{
|
||||
err_msg = $"Failed to get beacon shop action : {nameof(BeaconShopAction)}";
|
||||
result.setFail(ServerErrorCode.EntityActionNotFound, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_GET_SOLD_RECORDS(entity_player, result, null);
|
||||
return result;
|
||||
}
|
||||
|
||||
var game_msg = recvMessage as ClientToGame;
|
||||
if (game_msg == null)
|
||||
{
|
||||
err_msg = $"Failed to cast ClientToGame !!! : {nameof(ClientToGame.Request.ReqBeaconShopGetSoldRecords)}";
|
||||
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_GET_SOLD_RECORDS(entity_player, result, null);
|
||||
return result;
|
||||
}
|
||||
|
||||
var request = game_msg.Request.ReqBeaconShopGetSoldRecords;
|
||||
|
||||
if (request.BeaconGuid == string.Empty)
|
||||
{
|
||||
err_msg = $"Invalid Request Argument !!! : BeaconGuid : {request.BeaconGuid}";
|
||||
result.setFail(ServerErrorCode.BeaconShopInvalidArgument, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_GET_SOLD_RECORDS(entity_player, result, null);
|
||||
return result;
|
||||
}
|
||||
|
||||
result = await beacon_shop_action.BeaconShopGetSoldRecords(request.BeaconGuid);
|
||||
if (result.isFail())
|
||||
{
|
||||
send_S2C_ACK_BEACON_SHOP_GET_SOLD_RECORDS(entity_player, result, null);
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override async Task onProcessPacketException(ISession entityWithSession, IMessage recvMessage
|
||||
, Result errorResult)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
var player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!! - {entityWithSession.toBasicString()}");
|
||||
|
||||
send_S2C_ACK_BEACON_SHOP_GET_SOLD_RECORDS(player, errorResult, null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user