초기커밋

This commit is contained in:
2025-05-01 07:20:41 +09:00
commit 98bb2e3c5c
2747 changed files with 646947 additions and 0 deletions

View File

@@ -0,0 +1,124 @@
using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
using ServerCore;
using ServerBase;
using ServerCommon;
namespace GameServer;
public class RoomAction : EntityActionBase
{
private readonly ConcurrentDictionary<int, Room> m_rooms = new();
public RoomAction(Player owner) : base(owner)
{}
public override async Task<Result> onInit()
{
await Task.CompletedTask;
var result = new Result();
return result;
}
public override void onClear()
{
return;
}
private Room? getRoom(int room_id) => m_rooms.GetValueOrDefault(room_id);
public bool IsExist(int roomId)
{
return m_rooms.ContainsKey(roomId);
}
public async Task<Result> setRoomFromDoc(RoomDoc docBase)
{
var result = new Result();
string err_msg;
var owner = getOwner() as Player;
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
var doc_attr = docBase.getAttrib<RoomAttrib>();
if (null == doc_attr)
{
err_msg = $"Fail to get doc attrib : {nameof(RoomAttrib)} is null";
result.setFail(ServerErrorCode.EntityAttributeNotFound, err_msg);
Log.getLogger().error(err_msg);
return result;
}
// db 에서 설정하는 것으로, 없으면 생성해야 한다.
var room = getRoom(doc_attr.RoomId);
if (null == room)
{
room = new Room(owner);
m_rooms.TryAdd(doc_attr.RoomId, room);
}
var room_attribute = room.getEntityAttribute<RoomAttribute>();
if (null == room_attribute)
{
err_msg = $"Fail to get entity attribute : {nameof(RoomAttribute)} is null";
result.setFail(ServerErrorCode.EntityAttributeIsNull, err_msg);
Log.getLogger().error(err_msg);
return result;
}
// doc 에서 직접 copy 된 경우 pk, sk 를 셋팅해야 한다.
docBase.setCombinationKeyForPK(owner.getUserGuid());
docBase.setCombinationKeyForSK(doc_attr.RoomId.ToString());
var is_apply = docBase.onApplyPKSK();
if (ServerErrorCode.Success != is_apply)
{
err_msg = $"Fail to copy to attribute from doc : invalid argument {nameof(setRoomFromDoc)}";
result.setFail(is_apply, err_msg);
Log.getLogger().error(err_msg);
return result;
}
var is_success = room_attribute.copyEntityAttributeFromDoc(docBase);
if (false == is_success)
{
err_msg = $"Fail to copy room attribute : to {nameof(RoomAttribute)} from {nameof(RoomDoc)}";
result.setFail(ServerErrorCode.DynamoDbDocCopyToEntityAttributeFailed, err_msg);
Log.getLogger().error(err_msg);
}
return await Task.FromResult(result);
}
public async Task<Result> notifyRoomsToClient()
{
var owner = getOwner() as Player;
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
var notify_packet = new ClientToGame
{
Message = new ClientToGameMessage
{
OwnedRoomNoti = new ClientToGameMessage.Types.OwnedRoomNoti()
}
};
foreach (var room in m_rooms)
{
var room_content_action = room.Value.getEntityAction<RoomContentAction>();
var data = room_content_action?.toRoomData4Client();
if (null == data) continue;
notify_packet.Message.OwnedRoomNoti.RoomList.Add(data);
}
GameServerApp.getServerLogic().onSendPacket(owner, notify_packet);
return await Task.FromResult(new Result());
}
}

View File

@@ -0,0 +1,71 @@
using Google.Protobuf;
using Google.Protobuf.WellKnownTypes;
using ServerCore;
using ServerBase;
using ServerCommon;
using ServerCommon.BusinessLogDomain;
using MetaAssets;
namespace GameServer;
public class RoomContentAction : EntityActionBase
{
public RoomContentAction(Room owner) : base(owner)
{
}
public override async Task<Result> onInit()
{
await Task.CompletedTask;
var result = new Result();
return result;
}
public override void onClear()
{
return;
}
public RoomInfo? toRoomData4Client()
{
var attribute = getOwner().getEntityAttribute<RoomAttribute>();
if (null == attribute)
{
return null;
}
var data = new RoomInfo
{
Id = attribute.RoomId,
Owner = attribute.Owner,
Name = attribute.Name,
Description = attribute.Description
};
foreach (var info in attribute.PropInfo)
{
var prop = new PropInfo();
prop.AnchorGuid = info.Key;
prop.TableId = info.Value.TableId;
data.PropList.Add(prop);
}
return data;
}
public async Task<Result> notifyChangeRoomToClientAndServers()
{
// todo (sangyeob.kim) : 값이 변경되면, 해당 데이터를 참조하는 곳에 notify 를 해줘야 한다.
// Client, 타 Servers , Building Contents 에서 관리하고 있는 Rooms
// ....
return await Task.FromResult(new Result());
}
}