using Google.Protobuf; using Google.Protobuf.WellKnownTypes; using ServerCore; using ServerBase; using ServerCommon; using ServerCommon.BusinessLogDomain; using MetaAssets; namespace GameServer; public class NotifyInvitePartySendHandler { public async Task recvInvitePartySend(ServerMessage.Types.InvitePartyNoti notify) { var player_manager = GameServerApp.getServerLogic().getPlayerManager(); ArgumentNullException.ThrowIfNull(player_manager); // 0. client login 체크 if (!player_manager.tryGetUserByPrimaryKey(notify.InviteUserGuid, out var player)) { // 0-1. login_cache 가져오기 var login_cache = await PartyHelper.getOtherUserLoginCache(notify.InviteUserGuid); if (null == login_cache) { await sendMessageToPartyLeader(notify, ServerErrorCode.UserNotLogin); return; } // 0-2. 해당 서버로 mq 날리기 var server_message = new ServerMessage { InvitePartyNoti = new() { InvitePartyLeaderGuid = notify.InvitePartyLeaderGuid, InvitePartyGuid = notify.InvitePartyGuid, InviteUserGuid = notify.InviteUserGuid } }; var rabbit_mq = GameServerApp.getServerLogic().getRabbitMqConnector() as RabbitMqConnector; NullReferenceCheckHelper.throwIfNull(rabbit_mq, () => $"rabbit_mq is null !!!"); rabbit_mq.SendMessage(login_cache.CurrentServer, server_message); return; } // 1. client party 가입 체크 var result = await checkJoinPartyCondition(player); if (result.isFail()) { await sendMessageToPartyLeader(notify, result.ErrorCode); return; } // 2. recv 저장 var party_recv_action = player.getEntityAction(); ArgumentNullException.ThrowIfNull(party_recv_action); result = await party_recv_action.addInvitePartyRecv(notify.InvitePartyGuid); if (result.isFail()) { await sendMessageToPartyLeader(notify, ServerErrorCode.FailToSendInviteMember); return; } // 2. client 전달 var client_message = new ClientToGame(); client_message.Message = new(); client_message.Message.InvitePartyNoti = new(); client_message.Message.InvitePartyNoti.InviteHostUserGuid = notify.InvitePartyLeaderGuid; client_message.Message.InvitePartyNoti.InviteHostUserNickname = await PartyHelper.getUserNicknameFromGuid(notify.InvitePartyLeaderGuid); PartyHelper.sendToClient(client_message, player.getHostId()); } private async Task sendMessageToPartyLeader(ServerMessage.Types.InvitePartyNoti notify, ServerErrorCode err_code) { var login_cache = await PartyHelper.getOtherUserLoginCache(notify.InvitePartyLeaderGuid); if (null == login_cache) return; var message = new ServerMessage { NtfInvitePartyRecvResult = new ServerMessage.Types.GS2C_NTF_PARTY_INVITE_RESULT() { InvitePartyGuid = notify.InvitePartyGuid, InviteHostGuid = notify.InvitePartyLeaderGuid, InviteUserGuid = notify.InviteUserGuid, ErrorCode = err_code } }; var rabbit_mq = GameServerApp.getServerLogic().getRabbitMqConnector() as RabbitMqConnector; NullReferenceCheckHelper.throwIfNull(rabbit_mq, () => $"rabbit_mq is null !!!"); rabbit_mq.SendMessage(login_cache.CurrentServer, message); } private async Task checkJoinPartyCondition(Player player) { var result = new Result(); var personal_party_action = player.getEntityAction(); ArgumentNullException.ThrowIfNull(personal_party_action); var party_guid = personal_party_action.getPersonalParty()?.getPartyGuid(); if (string.IsNullOrEmpty(party_guid)) return result; // 1. party 정보 획득 var global_party = GameServerApp.getServerLogic().findGlobalEntity(); ArgumentNullException.ThrowIfNull(global_party); var party = global_party.getParty(party_guid); if (null == party) return result; // 2. 파티원 수 체크 var party_member_action = party.getEntityAction(); ArgumentNullException.ThrowIfNull(party_member_action); var member_count = party_member_action.getMemberCount(); if (member_count < 2) return result; result.setFail(ServerErrorCode.AlreadyPartyMember, $"Already Party Member !!! {player.getUserGuid()} / {party_guid}"); return await Task.FromResult(result); } }