200 lines
7.6 KiB
C#
200 lines
7.6 KiB
C#
using Google.Protobuf;
|
|
using Google.Protobuf.WellKnownTypes;
|
|
|
|
|
|
using ServerCore;
|
|
using ServerBase;
|
|
using ServerCommon;
|
|
using ServerCommon.BusinessLogDomain;
|
|
using MetaAssets;
|
|
|
|
|
|
using PARTY_GUID = System.String;
|
|
using USER_GUID = System.String;
|
|
|
|
|
|
namespace GameServer;
|
|
|
|
public class GlobalPartyInvitePartySendAction : EntityActionBase
|
|
{
|
|
private readonly PartyInvitePartySendCacheRequest m_party_invite_party_send_cache_request;
|
|
|
|
public GlobalPartyInvitePartySendAction(GlobalPartyDetail owner) : base(owner)
|
|
{
|
|
m_party_invite_party_send_cache_request =
|
|
new PartyInvitePartySendCacheRequest(owner.PartyGuid, GameServerApp.getServerLogic().getRedisConnector());
|
|
}
|
|
|
|
public override async Task<Result> onInit()
|
|
{
|
|
await Task.CompletedTask;
|
|
|
|
var result = new Result();
|
|
|
|
return result;
|
|
}
|
|
|
|
public override void onClear()
|
|
{
|
|
return;
|
|
}
|
|
|
|
public async Task<Result> keep()
|
|
{
|
|
return await m_party_invite_party_send_cache_request.keepInvitePartySendCache();
|
|
}
|
|
|
|
public async Task<Result> loadPartyInvitePartySend(PARTY_GUID party_guid)
|
|
{
|
|
var result = new Result();
|
|
if (PARTY_GUID.IsNullOrEmpty(party_guid))
|
|
{
|
|
var err_msg = $"Fail to load party invite party send !!! : argument is null - {nameof(loadPartyInvitePartySend)}";
|
|
result.setFail(ServerErrorCode.InvalidArgument, err_msg);
|
|
Log.getLogger().error(err_msg);
|
|
|
|
return result;
|
|
}
|
|
|
|
var party_invite_party_send = getOwner().getEntityAttribute<PartyInvitePartySendsAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(party_invite_party_send, () => $"PartyInvitePartySendsAttribute is null !! - {getOwner().toBasicString()}");
|
|
|
|
result = await m_party_invite_party_send_cache_request.fetchInvitePartySendCache();
|
|
if (result.isFail()) return result;
|
|
|
|
result = await ServerBase.DataCopyHelper.copyEntityAttributeFromCaches(party_invite_party_send, new List<CacheBase> { m_party_invite_party_send_cache_request.getPartyInvitePartySendCache()! });
|
|
if (result.isFail())
|
|
{
|
|
Log.getLogger().error(result.toBasicString());
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public async Task<Result> deleteInvitePartySends()
|
|
{
|
|
// 1. cache 제거
|
|
var result = await m_party_invite_party_send_cache_request.deleteAllInvitePartySendCache();
|
|
if (result.isFail())
|
|
{
|
|
Log.getLogger().error(result.toBasicString());
|
|
}
|
|
|
|
// 2. attribute 수정
|
|
var party_invite_send_attribute = getOwner().getEntityAttribute<PartyInvitePartySendsAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(party_invite_send_attribute, () => $"PartyInvitePartySendsAttribute is null !! - {getOwner().toBasicString()}");
|
|
|
|
party_invite_send_attribute.onClear();
|
|
|
|
return result;
|
|
}
|
|
|
|
public async Task<Result> deleteInvitePartySend(USER_GUID invitee_guid)
|
|
{
|
|
// 1. attribute 수정
|
|
var party_invite_send_attribute = getOwner().getEntityAttribute<PartyInvitePartySendsAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(party_invite_send_attribute, () => $"PartyInvitePartySendsAttribute is null !! - {getOwner().toBasicString()}");
|
|
|
|
party_invite_send_attribute.deleteInvitePartySend(invitee_guid);
|
|
|
|
// 2. cache 에서 제거
|
|
var result = await m_party_invite_party_send_cache_request.deleteInvitePartySendCache(new List<string> { invitee_guid });
|
|
return result;
|
|
}
|
|
|
|
public async Task<bool> isExistCheck(string user_guid)
|
|
{
|
|
await organizeSendAttribute();
|
|
|
|
var party_invite_party_send = getOwner().getEntityAttribute<PartyInvitePartySendsAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(party_invite_party_send, () => $"PartyInvitePartySendsAttribute is null !! - {getOwner().toBasicString()}");
|
|
|
|
var sends = party_invite_party_send.getPartyInvitePartySends();
|
|
return sends.Any(send => send.Key == user_guid);
|
|
}
|
|
|
|
public async Task<int> getInviteSendsCount()
|
|
{
|
|
var list = await getPartyInvitePartySends();
|
|
return list.Count;
|
|
}
|
|
|
|
public async Task<Dictionary<string, DateTime>> getPartyInvitePartySends()
|
|
{
|
|
await organizeSendAttribute();
|
|
|
|
var attribute = getOwner().getEntityAttribute<PartyInvitePartySendsAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(attribute, () => $"PartyInvitePartySendsAttribute is null !! - {getOwner().toBasicString()}");
|
|
|
|
var sends = attribute.getPartyInvitePartySends();
|
|
var list = sends.ToDictionary(send => send.Key, send => send.Value);
|
|
return list;
|
|
}
|
|
|
|
public async Task<Result> sendInviteParty(IReadOnlyDictionary<string, string>? invite_users)
|
|
{
|
|
var result = new Result();
|
|
var party = getOwner() as GlobalPartyDetail;
|
|
NullReferenceCheckHelper.throwIfNull(party, () => $"global party detail is null !! ");
|
|
|
|
var send_users = invite_users?.Select(invitee => invitee.Key).ToList();
|
|
if (null == send_users)
|
|
{
|
|
var err_msg = $"Failed to send invite party !!! : invite_users is null - {nameof(sendInviteParty)}";
|
|
result.setFail(ServerErrorCode.FailToSendInviteMember, err_msg);
|
|
Log.getLogger().error(err_msg);
|
|
return result;
|
|
}
|
|
|
|
// 2. redis 저장
|
|
result = await m_party_invite_party_send_cache_request.addInvitePartySendCache(send_users);
|
|
if (result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
// 3. attribute 변경
|
|
var party_invite_party_send = getOwner().getEntityAttribute<PartyInvitePartySendsAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(party_invite_party_send, () => $"PartyInvitePartySendsAttribute is null !! - {party.toBasicString()}");
|
|
|
|
party_invite_party_send.addInvitePartySends(send_users);
|
|
|
|
// 1. mq message 생성
|
|
var message = new ServerMessage();
|
|
message.InvitePartyNoti = new();
|
|
message.InvitePartyNoti.InvitePartyLeaderGuid = getPartyLeaderGuid();
|
|
message.InvitePartyNoti.InvitePartyGuid = party.PartyGuid;
|
|
|
|
var rabbit_mq = GameServerApp.getServerLogic().getRabbitMqConnector() as RabbitMqConnector;
|
|
ArgumentNullException.ThrowIfNull(rabbit_mq);
|
|
|
|
// 4. invite 유저에게 메시지 전달
|
|
NullReferenceCheckHelper.throwIfNull(invite_users, () => $"party invite users is null !!! - {party.toBasicString()}");
|
|
foreach (var invitee in invite_users)
|
|
{
|
|
message.InvitePartyNoti.InviteUserGuid = invitee.Key;
|
|
rabbit_mq.SendMessage(invitee.Value, message);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
private USER_GUID getPartyLeaderGuid()
|
|
{
|
|
var party_attribute = getOwner().getEntityAttribute<PartyAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(party_attribute, () => $"PartyAttribute is null !! - {getOwner().toBasicString()}");
|
|
|
|
return party_attribute.PartyLeaderCharGuid;
|
|
}
|
|
|
|
private async Task organizeSendAttribute()
|
|
{
|
|
var delete_sends = await m_party_invite_party_send_cache_request.organizeInvitePartySendCache();
|
|
if (null == delete_sends) return;
|
|
|
|
var party_invite_party_send = getOwner().getEntityAttribute<PartyInvitePartySendsAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(party_invite_party_send, () => $"PartyInvitePartySendsAttribute is null !! - {getOwner().toBasicString()}");
|
|
|
|
party_invite_party_send.deleteInvitePartySends(delete_sends);
|
|
}
|
|
} |