초기커밋
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user