11using System ;
22using System . Collections . Generic ;
33using System . Threading . Tasks ;
4- using Unity . BossRoom . Infrastructure ;
54using Unity . Services . Lobbies ;
65using Unity . Services . Lobbies . Models ;
76using UnityEngine ;
8- using VContainer ;
97
108namespace Unity . BossRoom . UnityServices . Lobbies
119{
@@ -16,15 +14,11 @@ public class LobbyAPIInterface
1614 {
1715 const int k_MaxLobbiesToShow = 16 ; // If more are necessary, consider retrieving paginated results or using filters.
1816
19- readonly IPublisher < UnityServiceErrorMessage > m_UnityServiceErrorMessagePublisher ;
2017 readonly List < QueryFilter > m_Filters ;
2118 readonly List < QueryOrder > m_Order ;
2219
23- [ Inject ]
24- public LobbyAPIInterface ( IPublisher < UnityServiceErrorMessage > unityServiceErrorMessagePublisher )
20+ public LobbyAPIInterface ( )
2521 {
26- m_UnityServiceErrorMessagePublisher = unityServiceErrorMessagePublisher ;
27-
2822 // Filter for open lobbies only
2923 m_Filters = new List < QueryFilter > ( )
3024 {
@@ -43,34 +37,6 @@ public LobbyAPIInterface(IPublisher<UnityServiceErrorMessage> unityServiceErrorM
4337 } ;
4438 }
4539
46- async Task < T > ExceptionHandling < T > ( Task < T > task )
47- {
48- try
49- {
50- return await task ;
51- }
52- catch ( Exception e )
53- {
54- var reason = $ "{ e . Message } ({ e . InnerException ? . Message } )"; // Lobby error type, then HTTP error type.
55- m_UnityServiceErrorMessagePublisher . Publish ( new UnityServiceErrorMessage ( "Lobby Error" , reason , UnityServiceErrorMessage . Service . Lobby , e ) ) ;
56- throw ;
57- }
58- }
59-
60- async Task ExceptionHandling ( Task task )
61- {
62- try
63- {
64- await task ;
65- }
66- catch ( Exception e )
67- {
68- var reason = $ "{ e . Message } ({ e . InnerException ? . Message } )"; // Lobby error type, then HTTP error type.
69- m_UnityServiceErrorMessagePublisher . Publish ( new UnityServiceErrorMessage ( "Lobby Error" , reason , UnityServiceErrorMessage . Service . Lobby , e ) ) ;
70- throw ;
71- }
72- }
73-
7440 public async Task < Lobby > CreateLobby ( string requesterUasId , string lobbyName , int maxPlayers , bool isPrivate , Dictionary < string , PlayerDataObject > hostUserData , Dictionary < string , DataObject > lobbyData )
7541 {
7642 CreateLobbyOptions createOptions = new CreateLobbyOptions
@@ -80,24 +46,24 @@ public async Task<Lobby> CreateLobby(string requesterUasId, string lobbyName, in
8046 Data = lobbyData
8147 } ;
8248
83- return await ExceptionHandling ( LobbyService . Instance . CreateLobbyAsync ( lobbyName , maxPlayers , createOptions ) ) ;
49+ return await LobbyService . Instance . CreateLobbyAsync ( lobbyName , maxPlayers , createOptions ) ;
8450 }
8551
8652 public async Task DeleteLobby ( string lobbyId )
8753 {
88- await ExceptionHandling ( LobbyService . Instance . DeleteLobbyAsync ( lobbyId ) ) ;
54+ await LobbyService . Instance . DeleteLobbyAsync ( lobbyId ) ;
8955 }
9056
9157 public async Task < Lobby > JoinLobbyByCode ( string requesterUasId , string lobbyCode , Dictionary < string , PlayerDataObject > localUserData )
9258 {
9359 JoinLobbyByCodeOptions joinOptions = new JoinLobbyByCodeOptions { Player = new Player ( id : requesterUasId , data : localUserData ) } ;
94- return await ExceptionHandling ( LobbyService . Instance . JoinLobbyByCodeAsync ( lobbyCode , joinOptions ) ) ;
60+ return await LobbyService . Instance . JoinLobbyByCodeAsync ( lobbyCode , joinOptions ) ;
9561 }
9662
9763 public async Task < Lobby > JoinLobbyById ( string requesterUasId , string lobbyId , Dictionary < string , PlayerDataObject > localUserData )
9864 {
9965 JoinLobbyByIdOptions joinOptions = new JoinLobbyByIdOptions { Player = new Player ( id : requesterUasId , data : localUserData ) } ;
100- return await ExceptionHandling ( LobbyService . Instance . JoinLobbyByIdAsync ( lobbyId , joinOptions ) ) ;
66+ return await LobbyService . Instance . JoinLobbyByIdAsync ( lobbyId , joinOptions ) ;
10167 }
10268
10369 public async Task < Lobby > QuickJoinLobby ( string requesterUasId , Dictionary < string , PlayerDataObject > localUserData )
@@ -108,19 +74,19 @@ public async Task<Lobby> QuickJoinLobby(string requesterUasId, Dictionary<string
10874 Player = new Player ( id : requesterUasId , data : localUserData )
10975 } ;
11076
111- return await ExceptionHandling ( LobbyService . Instance . QuickJoinLobbyAsync ( joinRequest ) ) ;
77+ return await LobbyService . Instance . QuickJoinLobbyAsync ( joinRequest ) ;
11278 }
11379
11480 public async Task < Lobby > ReconnectToLobby ( string lobbyId )
11581 {
116- return await ExceptionHandling ( LobbyService . Instance . ReconnectToLobbyAsync ( lobbyId ) ) ;
82+ return await LobbyService . Instance . ReconnectToLobbyAsync ( lobbyId ) ;
11783 }
11884
11985 public async Task RemovePlayerFromLobby ( string requesterUasId , string lobbyId )
12086 {
12187 try
12288 {
123- await ExceptionHandling ( LobbyService . Instance . RemovePlayerAsync ( lobbyId , requesterUasId ) ) ;
89+ await LobbyService . Instance . RemovePlayerAsync ( lobbyId , requesterUasId ) ;
12490 }
12591 catch ( LobbyServiceException e )
12692 when ( e is { Reason : LobbyExceptionReason . PlayerNotFound } )
@@ -138,18 +104,18 @@ public async Task<QueryResponse> QueryAllLobbies()
138104 Order = m_Order
139105 } ;
140106
141- return await ExceptionHandling ( LobbyService . Instance . QueryLobbiesAsync ( queryOptions ) ) ;
107+ return await LobbyService . Instance . QueryLobbiesAsync ( queryOptions ) ;
142108 }
143109
144110 public async Task < Lobby > GetLobby ( string lobbyId )
145111 {
146- return await ExceptionHandling ( LobbyService . Instance . GetLobbyAsync ( lobbyId ) ) ;
112+ return await LobbyService . Instance . GetLobbyAsync ( lobbyId ) ;
147113 }
148114
149115 public async Task < Lobby > UpdateLobby ( string lobbyId , Dictionary < string , DataObject > data , bool shouldLock )
150116 {
151117 UpdateLobbyOptions updateOptions = new UpdateLobbyOptions { Data = data , IsLocked = shouldLock } ;
152- return await ExceptionHandling ( LobbyService . Instance . UpdateLobbyAsync ( lobbyId , updateOptions ) ) ;
118+ return await LobbyService . Instance . UpdateLobbyAsync ( lobbyId , updateOptions ) ;
153119 }
154120
155121 public async Task < Lobby > UpdatePlayer ( string lobbyId , string playerId , Dictionary < string , PlayerDataObject > data , string allocationId , string connectionInfo )
@@ -160,12 +126,12 @@ public async Task<Lobby> UpdatePlayer(string lobbyId, string playerId, Dictionar
160126 AllocationId = allocationId ,
161127 ConnectionInfo = connectionInfo
162128 } ;
163- return await ExceptionHandling ( LobbyService . Instance . UpdatePlayerAsync ( lobbyId , playerId , updateOptions ) ) ;
129+ return await LobbyService . Instance . UpdatePlayerAsync ( lobbyId , playerId , updateOptions ) ;
164130 }
165131
166132 public async void SendHeartbeatPing ( string lobbyId )
167133 {
168- await ExceptionHandling ( LobbyService . Instance . SendHeartbeatPingAsync ( lobbyId ) ) ;
134+ await LobbyService . Instance . SendHeartbeatPingAsync ( lobbyId ) ;
169135 }
170136 }
171137}
0 commit comments