-
[Unity] Unity lobby private 일때 강퇴당하면 생기는 오류 해결쾌락없는 책임 (공부)/Unity 2023. 2. 11. 12:13반응형
개요
private 한 Lobby를 만들고 강퇴를 하는 순간 아래처럼 이상하게 긴 오류가 나왔다.
[Lobby]: Forbidden, (16403). Message: lobby is private UnityEngine.Logger:LogError (string,object) Unity.Services.Lobbies.Logger:LogError (object) (at Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/Utils/Logger.cs:17) Unity.Services.Lobbies.Internal.WrappedLobbyService:ResolveErrorWrapping (Unity.Services.Lobbies.LobbyExceptionReason,System.Exception) (at Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/SDK/WrappedLobbyService.cs:417) Unity.Services.Lobbies.Internal.WrappedLobbyService/<TryCatchRequest>d__20`2<Unity.Services.Lobbies.Lobby.GetLobbyRequest, Unity.Services.Lobbies.Models.Lobby>:MoveNext () (at Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/SDK/WrappedLobbyService.cs:359) System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.Lobbies.Response`1<Unity.Services.Lobbies.Models.Lobby>>:SetException (System.Exception) Unity.Services.Lobbies.Apis.Lobby.LobbyApiClient/<GetLobbyAsync>d__9:MoveNext () (at Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/Apis/LobbyApi.cs:316) System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.Lobbies.Http.HttpClientResponse>:SetResult (Unity.Services.Lobbies.Http.HttpClientResponse) Unity.Services.Lobbies.Http.HttpClient/<MakeRequestAsync>d__3:MoveNext () (at Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/Http/HttpClient.cs:47) System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.Lobbies.Http.HttpClientResponse>:SetResult (Unity.Services.Lobbies.Http.HttpClientResponse) Unity.Services.Lobbies.Http.HttpClient/<CreateWebRequestAsync>d__7:MoveNext () (at Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/Http/HttpClient.cs:138) System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.Lobbies.Http.HttpClientResponse>:SetResult (Unity.Services.Lobbies.Http.HttpClientResponse) Unity.Services.Lobbies.Http.HttpClient/<>c__DisplayClass7_0/<<CreateWebRequestAsync>b__0>d:MoveNext () (at Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/Http/HttpClient.cs:135) System.Threading.Tasks.TaskCompletionSource`1<Unity.Services.Lobbies.Http.HttpClientResponse>:SetResult (Unity.Services.Lobbies.Http.HttpClientResponse) Unity.Services.Lobbies.Http.UnityWebRequestHelpers/<>c__DisplayClass0_0:<GetAwaiter>b__0 (UnityEngine.AsyncOperation) (at Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/Http/UnityWebRequestHelpers.cs:34) UnityEngine.AsyncOperation:InvokeCompletionEvent ()
결론은 Lobby가 private 라서 강퇴 여부를 알기 위한 'GetLobbyAsync' 함수가 동작을 하지 못했다! 라는 내용이다.
로비가 private 인 경우 로비 멤버만 GetLobbyAsync를 할 수 있다.
이는 기존의 강퇴 검사 로직과 위 제목의 원칙간 충돌 때문이다. 유니티에서 로비 제작을 이벤트 드리븐으로 하지 않아서인지 일단 로비의 변경점(멤버 변화, 강퇴 여부) 등을 알기 위해서는 로비를 계속 갱신해야 했습니다.
그런데 제목에 보이는 것처럼 private 인 경우 로비 멤버만 GetLobbyAsync 함수를 사용할 수 있고 이로 인해서 아래와 같은 오류가 나오는 것입니다.
- 나 강퇴 당했는지 GetLobbyAsync로
- 방장이 private 방에서 플레이어 강퇴
- 강퇴당한 플레이어는 강퇴 여부를 보기 위해서 GetLobbyAsync 함수 동작
- private라서 GetLobbyAsync 가 안된다! 그래서 강퇴 여부도 알 수 없고 오류가 난다!
Catch에서 따로 잡아줘야 한다
그래서 이러한 에러를 따로 잡아줘야 합니다. 일단 접근이 안된다면 Forbidden 오류가 나오게 되고 이 오류가 나오면 'private lobby에서 강퇴당한 거구나'라고 생각하고 처리해 주면 됩니다.
try { var lobby = await LobbyService.Instance.GetLobbyAsync(joinedLobby.Id); joinedLobby = lobby; } catch (LobbyServiceException e) { if(e.Reason == LobbyExceptionReason.Forbidden) { joinedLobby = null; kickedFromLobbyEvent?.Invoke(); return; } }
이런 식으로 말이죠. 원래 try문을 없애려고 했는데 결국 다시 생겨버렸습니다.
Lobby 공식 문서
Get joined lobbies
If players need to determine their current lobby membership, they can use the GetJoinedLobbies API. This API returns a list of lobby IDs for the lobbies that the active player is currently a member of. One common use for GetJoinLobbies is handling unexpect
docs.unity.com
반응형'쾌락없는 책임 (공부) > Unity' 카테고리의 다른 글
[Unity] Behaviour Tree에 관한 간단한 이야기 (0) 2023.02.09 [Unity] Unity Relay 를 통해서 P2P 연결 만들어보기 (0) 2023.02.01 [Unity] 유니티 멀티플레이를 위한 Lobby, 플레이어 매치메이킹 (0) 2023.01.30 [Unity] GPGS Android Setup Invalid classname: Object reference not set to an instance of an object 오류 날 시 (0) 2023.01.30 [Unity] 유니티 fake null과 관련한 이야기들 (0) 2023.01.16