100 lines
3.2 KiB
C#
100 lines
3.2 KiB
C#
using Google.Protobuf;
|
|
using Google.Protobuf.WellKnownTypes;
|
|
|
|
|
|
using ServerCore;
|
|
using ServerBase;
|
|
using ServerCommon;
|
|
|
|
using static ClientToGameReq.Types;
|
|
using static ClientToGameRes.Types;
|
|
|
|
|
|
using ANCHOR_GUID = System.String;
|
|
|
|
|
|
namespace GameServer.PacketHandler;
|
|
|
|
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.C2GS_REQ_FINISH_CRAFT), typeof(FinishCraftPacketHandler), typeof(GameLoginListener))]
|
|
public class FinishCraftPacketHandler : PacketRecvHandler
|
|
{
|
|
public static bool send_S2C_ACK_FINISH_CRAFT(Player player, Result result, ANCHOR_GUID anchor_guid = "", string beacon_guid = "", List<Item>? add_changed_items = null)
|
|
{
|
|
var ack_packet = new ClientToGame();
|
|
ack_packet.Response = new ClientToGameRes();
|
|
|
|
ack_packet.Response.ErrorCode = result.ErrorCode;
|
|
ack_packet.Response.AckFinishCraft = new GS2C_ACK_FINISH_CRAFT();
|
|
|
|
if (result.isSuccess())
|
|
{
|
|
if (add_changed_items != null)
|
|
{
|
|
ack_packet.Response.AckFinishCraft.Items.AddRange(add_changed_items.Select(item => item.toItemData4Client()));
|
|
}
|
|
|
|
ack_packet.Response.AckFinishCraft.AnchorGuid = anchor_guid;
|
|
ack_packet.Response.AckFinishCraft.BeaconGuid = beacon_guid;
|
|
}
|
|
|
|
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 craft_action = entity_player.getEntityAction<CraftAction>();
|
|
if (craft_action == null)
|
|
{
|
|
err_msg = $"Failed to get craft action : {nameof(CraftAction)}";
|
|
result.setFail(ServerErrorCode.EntityActionNotFound, err_msg);
|
|
Log.getLogger().error(err_msg);
|
|
|
|
send_S2C_ACK_FINISH_CRAFT(entity_player, result);
|
|
return result;
|
|
}
|
|
|
|
var game_msg = recvMessage as ClientToGame;
|
|
if (game_msg == null)
|
|
{
|
|
err_msg = $"Failed to cast ClientToGame !!! : {nameof(ClientToGame.Request.ReqFinishCraft)}";
|
|
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
send_S2C_ACK_FINISH_CRAFT(entity_player, result);
|
|
return result;
|
|
}
|
|
|
|
var request = game_msg.Request.ReqFinishCraft;
|
|
|
|
result = await craft_action.FinishCraftProcess(request.AnchorGuid);
|
|
if (result.isFail())
|
|
{
|
|
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_FINISH_CRAFT(player, errorResult);
|
|
}
|
|
}
|