Files
2025-05-01 07:20:41 +09:00

102 lines
3.6 KiB
C#

using Amazon.DynamoDBv2.DocumentModel;
using GameServer.PacketHandler;
using Google.Protobuf.Collections;
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 GameOptionAction : EntityActionBase
{
public GameOptionAction(EntityBase owner) : base(owner)
{
}
public override Task<Result> onInit()
{
var result = new Result();
return Task.FromResult(result);
}
public override void onClear()
{
return;
}
public async Task<Result> SaveGameOption(RepeatedField<int> gameOptionList)
{
var result = new Result();
var err_msg = string.Empty;
var player = getOwner() as Player;
NullReferenceCheckHelper.throwIfNull(player, () => "player is null !!!");
var server_logic = GameServerApp.getServerLogic();
string req_client_options = string.Empty;
try
{
byte[] byteOptions = Array.ConvertAll<int, byte>(gameOptionList.ToArray(), Convert.ToByte);
req_client_options = Convert.ToBase64String(byteOptions);
}
catch
{
err_msg = $"Convert Failed. GameOption Size is too big.";
result.setFail(ServerErrorCode.EntityAttributeIsNull, err_msg);
Log.getLogger().error(err_msg);
ChangeGameOptionPacketHandler.send_S2C_ACK_CHANGE_GAME_OPTION(player, result);
return result;
}
var fn_save_game_option = async delegate ()
{
var result = new Result();
var game_option_attribute = player.getEntityAttribute<GameOptionAttribute>();
if (game_option_attribute == null)
{
err_msg = $"Failed to get game option attribute : {nameof(GameOptionAttribute)}";
result.setFail(ServerErrorCode.EntityAttributeIsNull, err_msg);
Log.getLogger().error(err_msg);
ChangeGameOptionPacketHandler.send_S2C_ACK_CHANGE_GAME_OPTION(player, result);
return result;
}
game_option_attribute.options = req_client_options;
game_option_attribute.modifiedEntityAttribute(true);
var batch = new QueryBatchEx<QueryRunnerWithDocument>(player, LogActionType.UpdateGameOption
, server_logic.getDynamoDbClient());
{
batch.addQuery(new DBQWriteToAttributeAllWithTransactionRunner());
}
result = await QueryHelper.sendQueryAndBusinessLog(batch);
if (result.isFail())
{
ChangeGameOptionPacketHandler.send_S2C_ACK_CHANGE_GAME_OPTION(player, result);
return result;
}
ChangeGameOptionPacketHandler.send_S2C_ACK_CHANGE_GAME_OPTION(player, result);
return result;
};
result = await player.runTransactionRunnerSafely(TransactionIdType.PrivateContents, "SaveGameOption", fn_save_game_option);
if (result.isFail())
{
err_msg = $"Failed to runTransactionRunnerSafely()!!! : {result.toBasicString()} - {player.toBasicString()}";
Log.getLogger().error(err_msg);
}
return result;
}
}
}