95 lines
3.2 KiB
C#
95 lines
3.2 KiB
C#
using Google.Protobuf;
|
|
using Google.Protobuf.WellKnownTypes;
|
|
|
|
|
|
using ServerCore;
|
|
using ServerBase;
|
|
using ServerCommon;
|
|
using ServerCommon.BusinessLogDomain;
|
|
using MetaAssets;
|
|
|
|
|
|
using static ClientToGameRes.Types;
|
|
|
|
|
|
namespace GameServer.PacketHandler;
|
|
|
|
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.C2GS_REQ_BUY_CHARGED_SEASON_PASS), typeof(BuyChargedSeasonPassPacketHandler), typeof(GameLoginListener))]
|
|
public class BuyChargedSeasonPassPacketHandler : PacketRecvHandler
|
|
{
|
|
public static bool send_S2C_ACK_BUY_CHARGED_SEASON_PASS(Player player, Result result, CommonResult? commonResult = null)
|
|
{
|
|
var ack_packet = new ClientToGame();
|
|
ack_packet.Response = new ClientToGameRes();
|
|
|
|
ack_packet.Response.ErrorCode = result.ErrorCode;
|
|
ack_packet.Response.AckBuyChargedSeasonPass = new GS2C_ACK_BUY_CHARGED_SEASON_PASS();
|
|
|
|
if (result.isSuccess() && commonResult != null)
|
|
{
|
|
ack_packet.Response.AckBuyChargedSeasonPass.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 season_pass_action = entity_player.getEntityAction<SeasonPassAction>();
|
|
if (season_pass_action == null)
|
|
{
|
|
err_msg = $"Failed to get season pass action : {nameof(SeasonPassAction)}";
|
|
result.setFail(ServerErrorCode.EntityActionNotFound, err_msg);
|
|
Log.getLogger().error(err_msg);
|
|
|
|
send_S2C_ACK_BUY_CHARGED_SEASON_PASS(entity_player, result);
|
|
return result;
|
|
}
|
|
|
|
var game_msg = recvMessage as ClientToGame;
|
|
if (game_msg == null)
|
|
{
|
|
err_msg = $"Failed to cast ClientToGame !!! : {nameof(ClientToGame.Request.ReqBuyChargedSeasonPass)}";
|
|
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
send_S2C_ACK_BUY_CHARGED_SEASON_PASS(entity_player, result);
|
|
return result;
|
|
}
|
|
|
|
var request = game_msg.Request.ReqBuyChargedSeasonPass;
|
|
|
|
result = await season_pass_action.tryBuyChargedPass();
|
|
if (result.isFail() == true)
|
|
{
|
|
err_msg = $"Failed to tryBuyChargedPass() !!! : {result.toBasicString()} - {entity_player.toBasicString()}";
|
|
Log.getLogger().error(err_msg);
|
|
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_BUY_CHARGED_SEASON_PASS(player, errorResult);
|
|
}
|
|
}
|