Skip to content

Commit 1c49158

Browse files
committed
Merge branch '0.16'
2 parents ed2c92b + e8b639f commit 1c49158

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2567
-3620
lines changed

.editorconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ end_of_line = lf
33
charset = utf-8
44
trim_trailing_whitespace = true
55
indent_style = space
6-
indent_size = 4
6+
indent_size = 2
77

88
[*.{js,ts}]
99
indent_style = space
1010
indent_size = 2
1111

1212
[*.{cs}]
1313
indent_style = space
14-
indent_size = 4
14+
indent_size = 2

Assets/Colyseus/Runtime/Colyseus/HTTP.cs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -120,32 +120,22 @@ public async Task<string> Request(string uriMethod, string uriPath, Dictionary<s
120120
if (req.isNetworkError || req.isHttpError)
121121
#endif
122122
{
123-
if (_settings.useSecureProtocol)
124-
{
125-
//We failed to make this call with a secure protocol, try with non-secure and if that works we'll stick with it
126-
_settings.useSecureProtocol = false;
127-
Debug.LogError($"Failed to make request to {req.url} with secure protocol, trying again without!");
128-
return await Request(uriMethod, uriPath, jsonBody, headers);
129-
}
130-
else
131-
{
132-
var errorMessage = req.error;
133-
134-
//
135-
// Parse JSON from response
136-
//
137-
if (!string.IsNullOrEmpty(req.downloadHandler.text))
123+
var errorMessage = req.error;
124+
125+
//
126+
// Parse JSON from response
127+
//
128+
if (!string.IsNullOrEmpty(req.downloadHandler.text))
129+
{
130+
var data = Json.Deserialize<ErrorResponse>(req.downloadHandler.text);
131+
if (!string.IsNullOrEmpty(data.error))
138132
{
139-
var data = Json.Deserialize<ErrorResponse>(req.downloadHandler.text);
140-
if (!string.IsNullOrEmpty(data.error))
141-
{
142-
errorMessage = data.error;
143-
throw new HttpException((int)req.responseCode, errorMessage);
144-
}
145-
}
146-
147-
throw new HttpException((int)req.responseCode, errorMessage);
148-
}
133+
errorMessage = data.error;
134+
throw new HttpException((int)req.responseCode, errorMessage);
135+
}
136+
}
137+
138+
throw new HttpException((int)req.responseCode, errorMessage);
149139
}
150140

151141
return req.downloadHandler.text;

Assets/Colyseus/Runtime/Colyseus/Models/Auth.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ public async Task<Action> OnChange<T>(Action<AuthData<T>> callback)
148148
token = Token,
149149
user = await GetUserData<T>()
150150
});
151-
} catch (Exception _)
151+
} catch (Exception e)
152152
{
153+
Debug.LogWarning(e);
153154
emitChange(new AuthData<object> { user = null, token = null });
154155
}
155156
}

Assets/Colyseus/Runtime/Colyseus/Models/ColyseusClient.cs

Lines changed: 28 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ public ColyseusSettings Settings
9494
/// <param name="headers">Dictionary of headers to pass to the server when we create/join the room</param>
9595
/// <typeparam name="T">Type of <see cref="ColyseusRoom{T}" /> we want to join or create</typeparam>
9696
/// <returns><see cref="ColyseusRoom{T}" /> via async task</returns>
97-
public async Task<ColyseusRoom<T>> JoinOrCreate<T>(string roomName, Dictionary<string, object> options = null,
98-
Dictionary<string, string> headers = null)
97+
public async Task<ColyseusRoom<T>> JoinOrCreate<T>(string roomName, Dictionary<string, object> options = null, Dictionary<string, string> headers = null)
98+
where T : Schema.Schema
9999
{
100100
return await CreateMatchMakeRequest<T>("joinOrCreate", roomName, options, headers);
101101
}
@@ -108,8 +108,8 @@ public async Task<ColyseusRoom<T>> JoinOrCreate<T>(string roomName, Dictionary<s
108108
/// <param name="headers">Dictionary of headers to pass to the server when we create the room</param>
109109
/// <typeparam name="T">Type of <see cref="ColyseusRoom{T}" /> we want to create</typeparam>
110110
/// <returns><see cref="ColyseusRoom{T}" /> via async task</returns>
111-
public async Task<ColyseusRoom<T>> Create<T>(string roomName, Dictionary<string, object> options = null,
112-
Dictionary<string, string> headers = null)
111+
public async Task<ColyseusRoom<T>> Create<T>(string roomName, Dictionary<string, object> options = null, Dictionary<string, string> headers = null)
112+
where T : Schema.Schema
113113
{
114114
return await CreateMatchMakeRequest<T>("create", roomName, options, headers);
115115
}
@@ -122,8 +122,8 @@ public async Task<ColyseusRoom<T>> Create<T>(string roomName, Dictionary<string,
122122
/// <param name="headers">Dictionary of headers to pass to the server when we join the room</param>
123123
/// <typeparam name="T">Type of <see cref="ColyseusRoom{T}" /> we want to join</typeparam>
124124
/// <returns><see cref="ColyseusRoom{T}" /> via async task</returns>
125-
public async Task<ColyseusRoom<T>> Join<T>(string roomName, Dictionary<string, object> options = null,
126-
Dictionary<string, string> headers = null)
125+
public async Task<ColyseusRoom<T>> Join<T>(string roomName, Dictionary<string, object> options = null, Dictionary<string, string> headers = null)
126+
where T : Schema.Schema
127127
{
128128
return await CreateMatchMakeRequest<T>("join", roomName, options, headers);
129129
}
@@ -136,8 +136,8 @@ public async Task<ColyseusRoom<T>> Join<T>(string roomName, Dictionary<string, o
136136
/// <param name="headers">Dictionary of headers to pass to the server when we join the room</param>
137137
/// <typeparam name="T">Type of <see cref="ColyseusRoom{T}" /> we want to join</typeparam>
138138
/// <returns><see cref="ColyseusRoom{T}" /> via async task</returns>
139-
public async Task<ColyseusRoom<T>> JoinById<T>(string roomId, Dictionary<string, object> options = null,
140-
Dictionary<string, string> headers = null)
139+
public async Task<ColyseusRoom<T>> JoinById<T>(string roomId, Dictionary<string, object> options = null, Dictionary<string, string> headers = null)
140+
where T : Schema.Schema
141141
{
142142
return await CreateMatchMakeRequest<T>("joinById", roomId, options, headers);
143143
}
@@ -149,8 +149,8 @@ public async Task<ColyseusRoom<T>> JoinById<T>(string roomId, Dictionary<string,
149149
/// <param name="headers">Dictionary of headers to pass to the server when we reconnect to the room</param>
150150
/// <typeparam name="T">Type of <see cref="ColyseusRoom{T}" /> we want to reconnect with</typeparam>
151151
/// <returns><see cref="ColyseusRoom{T}" /> via async task</returns>
152-
public async Task<ColyseusRoom<T>> Reconnect<T>(ReconnectionToken reconnectionToken,
153-
Dictionary<string, string> headers = null)
152+
public async Task<ColyseusRoom<T>> Reconnect<T>(ReconnectionToken reconnectionToken, Dictionary<string, string> headers = null)
153+
where T : Schema.Schema
154154
{
155155
Dictionary<string, object> options = new Dictionary<string, object>();
156156
options.Add("reconnectionToken", reconnectionToken.Token);
@@ -167,11 +167,9 @@ public async Task<ColyseusRoom<T>> Reconnect<T>(ReconnectionToken reconnectionTo
167167
/// <param name="options">Dictionary of options to pass to the room upon creation/joining</param>
168168
/// <param name="headers">Dictionary of headers to pass to the server when we create/join the room</param>
169169
/// <returns><see cref="ColyseusRoom{T}" /> via async task</returns>
170-
public async Task<ColyseusRoom<dynamic>> JoinOrCreate(string roomName,
171-
Dictionary<string, object> options = null,
172-
Dictionary<string, string> headers = null)
170+
public async Task<ColyseusRoom<NoState>> JoinOrCreate(string roomName, Dictionary<string, object> options = null, Dictionary<string, string> headers = null)
173171
{
174-
return await CreateMatchMakeRequest<dynamic>("joinOrCreate", roomName, options, headers);
172+
return await CreateMatchMakeRequest<NoState>("joinOrCreate", roomName, options, headers);
175173
}
176174

177175
/// <summary>
@@ -181,10 +179,10 @@ public async Task<ColyseusRoom<dynamic>> JoinOrCreate(string roomName,
181179
/// <param name="options">Dictionary of options to pass to the room upon creation</param>
182180
/// <param name="headers">Dictionary of headers to pass to the server when we create the room</param>
183181
/// <returns><see cref="ColyseusRoom{T}" /> via async task</returns>
184-
public async Task<ColyseusRoom<dynamic>> Create(string roomName, Dictionary<string, object> options = null,
182+
public async Task<ColyseusRoom<NoState>> Create(string roomName, Dictionary<string, object> options = null,
185183
Dictionary<string, string> headers = null)
186184
{
187-
return await CreateMatchMakeRequest<dynamic>("create", roomName, options, headers);
185+
return await CreateMatchMakeRequest<NoState>("create", roomName, options, headers);
188186
}
189187

190188
/// <summary>
@@ -194,10 +192,10 @@ public async Task<ColyseusRoom<dynamic>> Create(string roomName, Dictionary<stri
194192
/// <param name="options">Dictionary of options to pass to the room upon joining</param>
195193
/// <param name="headers">Dictionary of headers to pass to the server when we join the room</param>
196194
/// <returns><see cref="ColyseusRoom{T}" /> via async task</returns>
197-
public async Task<ColyseusRoom<dynamic>> Join(string roomName, Dictionary<string, object> options = null,
195+
public async Task<ColyseusRoom<NoState>> Join(string roomName, Dictionary<string, object> options = null,
198196
Dictionary<string, string> headers = null)
199197
{
200-
return await CreateMatchMakeRequest<dynamic>("join", roomName, options, headers);
198+
return await CreateMatchMakeRequest<NoState>("join", roomName, options, headers);
201199
}
202200

203201
/// <summary>
@@ -207,10 +205,10 @@ public async Task<ColyseusRoom<dynamic>> Join(string roomName, Dictionary<string
207205
/// <param name="options">Dictionary of options to pass to the room upon joining</param>
208206
/// <param name="headers">Dictionary of headers to pass to the server when we join the room</param>
209207
/// <returns><see cref="ColyseusRoom{T}" /> via async task</returns>
210-
public async Task<ColyseusRoom<dynamic>> JoinById(string roomId, Dictionary<string, object> options = null,
208+
public async Task<ColyseusRoom<NoState>> JoinById(string roomId, Dictionary<string, object> options = null,
211209
Dictionary<string, string> headers = null)
212210
{
213-
return await CreateMatchMakeRequest<dynamic>("joinById", roomId, options, headers);
211+
return await CreateMatchMakeRequest<NoState>("joinById", roomId, options, headers);
214212
}
215213

216214
/// <summary>
@@ -220,41 +218,12 @@ public async Task<ColyseusRoom<dynamic>> JoinById(string roomId, Dictionary<stri
220218
/// <param name="sessionId">Previously connected sessionId</param>
221219
/// <param name="headers">Dictionary of headers to pass to the server when we reconnect to the room</param>
222220
/// <returns><see cref="ColyseusRoom{T}" /> via async task</returns>
223-
public async Task<ColyseusRoom<dynamic>> Reconnect(string roomId, string sessionId,
221+
public async Task<ColyseusRoom<NoState>> Reconnect(string roomId, string sessionId,
224222
Dictionary<string, string> headers = null)
225223
{
226224
Dictionary<string, object> options = new Dictionary<string, object>();
227225
options.Add("sessionId", sessionId);
228-
return await CreateMatchMakeRequest<dynamic>("joinById", roomId, options, headers);
229-
}
230-
231-
/// <summary>
232-
/// Get all available rooms
233-
/// </summary>
234-
/// <param name="roomName">Room identifier</param>
235-
/// <param name="headers">Dictionary of headers to pass to the server</param>
236-
/// <returns><see cref="ColyseusRoomAvailable" /> array via async task</returns>
237-
public async Task<ColyseusRoomAvailable[]> GetAvailableRooms(string roomName = "")
238-
{
239-
return await GetAvailableRooms<ColyseusRoomAvailable>(roomName);
240-
}
241-
242-
/// <summary>
243-
/// Get all available rooms with provided custom type <typeparamref name="T" />
244-
/// </summary>
245-
/// <param name="roomName">Name of the room</param>
246-
/// <returns><see cref="CSACSARoomAvailableCollection{T}" /> array via async task</returns>
247-
public async Task<T[]> GetAvailableRooms<T>(string roomName = "")
248-
{
249-
string json = await Http.Request("GET", $"matchmake/{roomName}");
250-
251-
if (json.StartsWith("[", StringComparison.CurrentCulture))
252-
{
253-
json = "{\"rooms\":" + json + "}";
254-
}
255-
256-
CSARoomAvailableCollection<T> response = JsonUtility.FromJson<CSARoomAvailableCollection<T>>(json);
257-
return response.rooms;
226+
return await CreateMatchMakeRequest<NoState>("joinById", roomId, options, headers);
258227
}
259228

260229
/// <summary>
@@ -265,17 +234,19 @@ public async Task<T[]> GetAvailableRooms<T>(string roomName = "")
265234
/// <param name="previousRoom">Previous ColyseusRoom{T} instance to re-establish the server connection: Please do not use this devMode param for general purposes</param>
266235
/// <typeparam name="T">Type of <see cref="ColyseusRoom{T}" /> we're consuming the seat from</typeparam>
267236
/// <returns><see cref="ColyseusRoom{T}" /> in which we now have a seat via async task</returns>
268-
public async Task<ColyseusRoom<T>> ConsumeSeatReservation<T>(ColyseusMatchMakeResponse response,
269-
Dictionary<string, string> headers = null, ColyseusRoom<T> previousRoom = null)
237+
public async Task<ColyseusRoom<T>> ConsumeSeatReservation<T>(ColyseusMatchMakeResponse response, Dictionary<string, string> headers = null, ColyseusRoom<T> previousRoom = null)
238+
where T : Schema.Schema
270239
{
271240
ColyseusRoom<T> room = new ColyseusRoom<T>(response.room.name)
272241
{
273242
RoomId = response.room.roomId,
274243
SessionId = response.sessionId
275244
};
276245

277-
Dictionary<string, object> queryString = new Dictionary<string, object>();
278-
queryString.Add("sessionId", room.SessionId);
246+
Dictionary<string, object> queryString = new Dictionary<string, object>
247+
{
248+
{ "sessionId", room.SessionId }
249+
};
279250

280251
// forward reconnection token
281252
if (response.reconnectionToken != null)
@@ -361,8 +332,8 @@ void OnJoin()
361332
/// <returns><see cref="ColyseusRoom{T}" /> we have matched with via async task</returns>
362333
/// <exception cref="Exception">Thrown if there is a network related error</exception>
363334
/// <exception cref="MatchMakeException">Thrown if there is an error in the match making process on the server side</exception>
364-
protected async Task<ColyseusRoom<T>> CreateMatchMakeRequest<T>(string method, string roomName,
365-
Dictionary<string, object> options, Dictionary<string, string> headers)
335+
protected async Task<ColyseusRoom<T>> CreateMatchMakeRequest<T>(string method, string roomName, Dictionary<string, object> options, Dictionary<string, string> headers)
336+
where T : Schema.Schema
366337
{
367338
if (options == null)
368339
{

0 commit comments

Comments
 (0)