92 lines
3.1 KiB
C#
92 lines
3.1 KiB
C#
using Google.Protobuf;
|
|
using Google.Protobuf.WellKnownTypes;
|
|
|
|
|
|
using ServerCore;
|
|
using ServerBase;
|
|
using ServerCommon;
|
|
using ServerCommon.BusinessLogDomain;
|
|
using MetaAssets;
|
|
|
|
|
|
using static ClientToGameReq.Types;
|
|
using static ClientToGameRes.Types;
|
|
|
|
|
|
namespace GameServer.PacketHandler;
|
|
|
|
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.ChangeGameOptionReq), typeof(ChangeGameOptionPacketHandler), typeof(GameLoginListener))]
|
|
public class ChangeGameOptionPacketHandler : PacketRecvHandler
|
|
{
|
|
public static bool send_S2C_ACK_CHANGE_GAME_OPTION(Player player, Result result)
|
|
{
|
|
var ack_packet = new ClientToGame();
|
|
ack_packet.Response = new ClientToGameRes();
|
|
|
|
ack_packet.Response.ErrorCode = result.ErrorCode;
|
|
ack_packet.Response.ChangeGameOptionRes = new ChangeGameOptionRes();
|
|
|
|
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 server_logic = GameServerApp.getServerLogic();
|
|
|
|
var game_option_action = entity_player.getEntityAction<GameOptionAction>();
|
|
if (game_option_action == null)
|
|
{
|
|
err_msg = $"Failed to get game option action : {nameof(GameOptionAction)}";
|
|
result.setFail(ServerErrorCode.EntityActionNotFound, err_msg);
|
|
Log.getLogger().error(err_msg);
|
|
|
|
send_S2C_ACK_CHANGE_GAME_OPTION(entity_player, result);
|
|
return result;
|
|
}
|
|
|
|
var game_msg = recvMessage as ClientToGame;
|
|
if (game_msg == null)
|
|
{
|
|
err_msg = $"Failed to cast ClientToGame !!! : {nameof(ClientToGame.Request.ChangeGameOptionReq)}";
|
|
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
send_S2C_ACK_CHANGE_GAME_OPTION(entity_player, result);
|
|
return result;
|
|
}
|
|
|
|
var request = game_msg.Request.ChangeGameOptionReq;
|
|
|
|
result = await game_option_action.SaveGameOption(request.ValuesList);
|
|
if (result.isFail())
|
|
{
|
|
err_msg = $"Failed to SaveGameOption() !!! : {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_CHANGE_GAME_OPTION(player, errorResult);
|
|
}
|
|
}
|