public async UniTaskVoid HandleRequestKickMemberFromParty(RequestHandlerData requestHandler, RequestKickMemberFromPartyMessage request, RequestProceedResultDelegate <ResponseKickMemberFromPartyMessage> result) { #if UNITY_STANDALONE && !CLIENT_BUILD await UniTask.Yield(); IPlayerCharacterData playerCharacter; if (!GameInstance.ServerUserHandlers.TryGetPlayerCharacter(requestHandler.ConnectionId, out playerCharacter)) { result.InvokeError(new ResponseKickMemberFromPartyMessage() { message = UITextKeys.UI_ERROR_NOT_LOGGED_IN, }); return; } ValidatePartyRequestResult validateResult = GameInstance.ServerPartyHandlers.CanKickMemberFromParty(playerCharacter, request.memberId); if (!validateResult.IsSuccess) { result.InvokeError(new ResponseKickMemberFromPartyMessage() { message = validateResult.GameMessage, }); return; } // Save to database AsyncResponseData <EmptyMessage> updateResp = await DbServiceClient.ClearCharacterPartyAsync(new ClearCharacterPartyReq() { CharacterId = request.memberId }); if (!updateResp.IsSuccess) { result.InvokeError(new ResponseKickMemberFromPartyMessage() { message = UITextKeys.UI_ERROR_INTERNAL_SERVER_ERROR, }); return; } // Delete from cache IPlayerCharacterData memberCharacter; long memberConnectionId; if (GameInstance.ServerUserHandlers.TryGetPlayerCharacterById(request.memberId, out memberCharacter) && GameInstance.ServerUserHandlers.TryGetConnectionId(request.memberId, out memberConnectionId)) { memberCharacter.ClearParty(); GameInstance.ServerGameMessageHandlers.SendClearPartyData(memberConnectionId, validateResult.PartyId); } validateResult.Party.RemoveMember(request.memberId); GameInstance.ServerPartyHandlers.SetParty(validateResult.PartyId, validateResult.Party); // Broadcast via chat server if (ClusterClient.IsNetworkActive) { ClusterClient.SendRemoveSocialMember(MMOMessageTypes.UpdatePartyMember, validateResult.PartyId, request.memberId); } GameInstance.ServerGameMessageHandlers.SendRemovePartyMemberToMembers(validateResult.Party, request.memberId); result.InvokeSuccess(new ResponseKickMemberFromPartyMessage()); #endif }
public async UniTaskVoid HandleRequestLeaveParty(RequestHandlerData requestHandler, EmptyMessage request, RequestProceedResultDelegate <ResponseLeavePartyMessage> result) { #if UNITY_STANDALONE && !CLIENT_BUILD await UniTask.Yield(); IPlayerCharacterData playerCharacter; if (!GameInstance.ServerUserHandlers.TryGetPlayerCharacter(requestHandler.ConnectionId, out playerCharacter)) { result.InvokeError(new ResponseLeavePartyMessage() { message = UITextKeys.UI_ERROR_NOT_LOGGED_IN, }); return; } ValidatePartyRequestResult validateResult = GameInstance.ServerPartyHandlers.CanLeaveParty(playerCharacter); if (!validateResult.IsSuccess) { result.InvokeError(new ResponseLeavePartyMessage() { message = validateResult.GameMessage, }); return; } // If it is leader kick all members and terminate party if (validateResult.Party.IsLeader(playerCharacter.Id)) { // Delete from database AsyncResponseData <EmptyMessage> deleteResp = await DbServiceClient.DeletePartyAsync(new DeletePartyReq() { PartyId = validateResult.PartyId }); if (!deleteResp.IsSuccess) { result.InvokeError(new ResponseLeavePartyMessage() { message = UITextKeys.UI_ERROR_INTERNAL_SERVER_ERROR, }); return; } IPlayerCharacterData memberCharacter; long memberConnectionId; foreach (string memberId in validateResult.Party.GetMemberIds()) { // Save to database _ = DbServiceClient.ClearCharacterPartyAsync(new ClearCharacterPartyReq() { CharacterId = memberId }); // Update cache if (GameInstance.ServerUserHandlers.TryGetPlayerCharacterById(memberId, out memberCharacter) && GameInstance.ServerUserHandlers.TryGetConnectionId(memberId, out memberConnectionId)) { memberCharacter.ClearParty(); GameInstance.ServerGameMessageHandlers.SendClearPartyData(memberConnectionId, validateResult.PartyId); } // Broadcast via chat server if (ClusterClient.IsNetworkActive) { ClusterClient.SendRemoveSocialMember(MMOMessageTypes.UpdatePartyMember, validateResult.PartyId, memberId); } } GameInstance.ServerPartyHandlers.RemoveParty(validateResult.PartyId); // Broadcast via chat server if (ClusterClient.IsNetworkActive) { ClusterClient.SendPartyTerminate(MMOMessageTypes.UpdateParty, validateResult.PartyId); } } else { // Save to database AsyncResponseData <EmptyMessage> updateResp = await DbServiceClient.ClearCharacterPartyAsync(new ClearCharacterPartyReq() { CharacterId = playerCharacter.Id }); if (!updateResp.IsSuccess) { result.InvokeError(new ResponseLeavePartyMessage() { message = UITextKeys.UI_ERROR_INTERNAL_SERVER_ERROR, }); return; } // Update cache playerCharacter.ClearParty(); validateResult.Party.RemoveMember(playerCharacter.Id); GameInstance.ServerPartyHandlers.SetParty(validateResult.PartyId, validateResult.Party); GameInstance.ServerGameMessageHandlers.SendRemovePartyMemberToMembers(validateResult.Party, playerCharacter.Id); GameInstance.ServerGameMessageHandlers.SendClearPartyData(requestHandler.ConnectionId, validateResult.PartyId); // Broadcast via chat server if (ClusterClient.IsNetworkActive) { ClusterClient.SendRemoveSocialMember(MMOMessageTypes.UpdatePartyMember, validateResult.PartyId, playerCharacter.Id); } } result.InvokeSuccess(new ResponseLeavePartyMessage()); #endif }