초기커밋
This commit is contained in:
101
GameServer/Contents/GameOption/Action/GameOptionAction.cs
Normal file
101
GameServer/Contents/GameOption/Action/GameOptionAction.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
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 static class GameOptionNotifyHelper
|
||||
{
|
||||
public static bool send_S2C_NTF_GAME_OPTION(this Player player)
|
||||
{
|
||||
var game_option_attribute = player.getEntityAttribute<GameOptionAttribute>();
|
||||
ArgumentNullReferenceCheckHelper.throwIfNull(game_option_attribute, () => "game_option_attribute is null !!!");
|
||||
|
||||
var noti_packet = new ClientToGame();
|
||||
noti_packet.Message = new();
|
||||
noti_packet.Message.GameOptionNoti = new();
|
||||
|
||||
byte[] byteOptions = Convert.FromBase64String(game_option_attribute.options);
|
||||
noti_packet.Message.GameOptionNoti.ValuesList.AddRange(Array.ConvertAll<byte, int>(byteOptions, Convert.ToInt32).ToList());
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(player, noti_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user