초기커밋
This commit is contained in:
@@ -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