1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Threading . Tasks ;
4
- using Unity . BossRoom . Infrastructure ;
5
4
using Unity . Services . Lobbies ;
6
5
using Unity . Services . Lobbies . Models ;
7
6
using UnityEngine ;
8
- using VContainer ;
9
7
10
8
namespace Unity . BossRoom . UnityServices . Lobbies
11
9
{
@@ -16,15 +14,11 @@ public class LobbyAPIInterface
16
14
{
17
15
const int k_MaxLobbiesToShow = 16 ; // If more are necessary, consider retrieving paginated results or using filters.
18
16
19
- readonly IPublisher < UnityServiceErrorMessage > m_UnityServiceErrorMessagePublisher ;
20
17
readonly List < QueryFilter > m_Filters ;
21
18
readonly List < QueryOrder > m_Order ;
22
19
23
- [ Inject ]
24
- public LobbyAPIInterface ( IPublisher < UnityServiceErrorMessage > unityServiceErrorMessagePublisher )
20
+ public LobbyAPIInterface ( )
25
21
{
26
- m_UnityServiceErrorMessagePublisher = unityServiceErrorMessagePublisher ;
27
-
28
22
// Filter for open lobbies only
29
23
m_Filters = new List < QueryFilter > ( )
30
24
{
@@ -43,34 +37,6 @@ public LobbyAPIInterface(IPublisher<UnityServiceErrorMessage> unityServiceErrorM
43
37
} ;
44
38
}
45
39
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
-
74
40
public async Task < Lobby > CreateLobby ( string requesterUasId , string lobbyName , int maxPlayers , bool isPrivate , Dictionary < string , PlayerDataObject > hostUserData , Dictionary < string , DataObject > lobbyData )
75
41
{
76
42
CreateLobbyOptions createOptions = new CreateLobbyOptions
@@ -80,24 +46,24 @@ public async Task<Lobby> CreateLobby(string requesterUasId, string lobbyName, in
80
46
Data = lobbyData
81
47
} ;
82
48
83
- return await ExceptionHandling ( LobbyService . Instance . CreateLobbyAsync ( lobbyName , maxPlayers , createOptions ) ) ;
49
+ return await LobbyService . Instance . CreateLobbyAsync ( lobbyName , maxPlayers , createOptions ) ;
84
50
}
85
51
86
52
public async Task DeleteLobby ( string lobbyId )
87
53
{
88
- await ExceptionHandling ( LobbyService . Instance . DeleteLobbyAsync ( lobbyId ) ) ;
54
+ await LobbyService . Instance . DeleteLobbyAsync ( lobbyId ) ;
89
55
}
90
56
91
57
public async Task < Lobby > JoinLobbyByCode ( string requesterUasId , string lobbyCode , Dictionary < string , PlayerDataObject > localUserData )
92
58
{
93
59
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 ) ;
95
61
}
96
62
97
63
public async Task < Lobby > JoinLobbyById ( string requesterUasId , string lobbyId , Dictionary < string , PlayerDataObject > localUserData )
98
64
{
99
65
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 ) ;
101
67
}
102
68
103
69
public async Task < Lobby > QuickJoinLobby ( string requesterUasId , Dictionary < string , PlayerDataObject > localUserData )
@@ -108,19 +74,19 @@ public async Task<Lobby> QuickJoinLobby(string requesterUasId, Dictionary<string
108
74
Player = new Player ( id : requesterUasId , data : localUserData )
109
75
} ;
110
76
111
- return await ExceptionHandling ( LobbyService . Instance . QuickJoinLobbyAsync ( joinRequest ) ) ;
77
+ return await LobbyService . Instance . QuickJoinLobbyAsync ( joinRequest ) ;
112
78
}
113
79
114
80
public async Task < Lobby > ReconnectToLobby ( string lobbyId )
115
81
{
116
- return await ExceptionHandling ( LobbyService . Instance . ReconnectToLobbyAsync ( lobbyId ) ) ;
82
+ return await LobbyService . Instance . ReconnectToLobbyAsync ( lobbyId ) ;
117
83
}
118
84
119
85
public async Task RemovePlayerFromLobby ( string requesterUasId , string lobbyId )
120
86
{
121
87
try
122
88
{
123
- await ExceptionHandling ( LobbyService . Instance . RemovePlayerAsync ( lobbyId , requesterUasId ) ) ;
89
+ await LobbyService . Instance . RemovePlayerAsync ( lobbyId , requesterUasId ) ;
124
90
}
125
91
catch ( LobbyServiceException e )
126
92
when ( e is { Reason : LobbyExceptionReason . PlayerNotFound } )
@@ -138,18 +104,18 @@ public async Task<QueryResponse> QueryAllLobbies()
138
104
Order = m_Order
139
105
} ;
140
106
141
- return await ExceptionHandling ( LobbyService . Instance . QueryLobbiesAsync ( queryOptions ) ) ;
107
+ return await LobbyService . Instance . QueryLobbiesAsync ( queryOptions ) ;
142
108
}
143
109
144
110
public async Task < Lobby > GetLobby ( string lobbyId )
145
111
{
146
- return await ExceptionHandling ( LobbyService . Instance . GetLobbyAsync ( lobbyId ) ) ;
112
+ return await LobbyService . Instance . GetLobbyAsync ( lobbyId ) ;
147
113
}
148
114
149
115
public async Task < Lobby > UpdateLobby ( string lobbyId , Dictionary < string , DataObject > data , bool shouldLock )
150
116
{
151
117
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 ) ;
153
119
}
154
120
155
121
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
160
126
AllocationId = allocationId ,
161
127
ConnectionInfo = connectionInfo
162
128
} ;
163
- return await ExceptionHandling ( LobbyService . Instance . UpdatePlayerAsync ( lobbyId , playerId , updateOptions ) ) ;
129
+ return await LobbyService . Instance . UpdatePlayerAsync ( lobbyId , playerId , updateOptions ) ;
164
130
}
165
131
166
132
public async void SendHeartbeatPing ( string lobbyId )
167
133
{
168
- await ExceptionHandling ( LobbyService . Instance . SendHeartbeatPingAsync ( lobbyId ) ) ;
134
+ await LobbyService . Instance . SendHeartbeatPingAsync ( lobbyId ) ;
169
135
}
170
136
}
171
137
}
0 commit comments