Skip to content

Commit 2be6979

Browse files
authored
Merge pull request #272 from smoogipoo/fix-join-password
Fix not being able to join rooms with password
2 parents 71714d1 + 3b99f42 commit 2be6979

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

osu.Server.Spectator.Tests/Multiplayer/RoomInteropTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public async Task CreateRoom()
2020

2121
await Hub.CreateRoom(new MultiplayerRoom(0));
2222
LegacyIO.Verify(io => io.CreateRoomAsync(USER_ID, It.IsAny<MultiplayerRoom>()), Times.Once);
23-
LegacyIO.Verify(io => io.AddUserToRoomAsync(ROOM_ID, USER_ID), Times.Once);
23+
LegacyIO.Verify(io => io.AddUserToRoomAsync(USER_ID, ROOM_ID, It.IsAny<string>()), Times.Once);
2424

2525
using (var usage = await Hub.GetRoom(ROOM_ID))
2626
{
@@ -33,10 +33,10 @@ public async Task CreateRoom()
3333
public async Task LeaveRoom()
3434
{
3535
await Hub.JoinRoom(ROOM_ID);
36-
LegacyIO.Verify(io => io.RemoveUserFromRoomAsync(ROOM_ID, USER_ID), Times.Never);
36+
LegacyIO.Verify(io => io.RemoveUserFromRoomAsync(USER_ID, ROOM_ID), Times.Never);
3737

3838
await Hub.LeaveRoom();
39-
LegacyIO.Verify(io => io.RemoveUserFromRoomAsync(ROOM_ID, USER_ID), Times.Once);
39+
LegacyIO.Verify(io => io.RemoveUserFromRoomAsync(USER_ID, ROOM_ID), Times.Once);
4040

4141
await Assert.ThrowsAsync<KeyNotFoundException>(() => Hub.GetRoom(ROOM_ID));
4242
}

osu.Server.Spectator/Hubs/Multiplayer/MultiplayerHub.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public async Task<MultiplayerRoom> JoinRoomWithPassword(long roomId, string pass
6767
throw new InvalidStateException("Can't join a room when restricted.");
6868
}
6969

70-
await sharedInterop.AddUserToRoomAsync(roomId, Context.GetUserId());
70+
await sharedInterop.AddUserToRoomAsync(Context.GetUserId(), roomId, password);
7171

7272
using (var userUsage = await GetOrCreateLocalUserState())
7373
{
@@ -917,7 +917,7 @@ private async Task<ItemUsage<ServerMultiplayerRoom>> getLocalUserRoom(Multiplaye
917917

918918
private async Task leaveRoom(MultiplayerClientState state, bool wasKick)
919919
{
920-
await sharedInterop.RemoveUserFromRoomAsync(state.CurrentRoomID, state.UserId);
920+
await sharedInterop.RemoveUserFromRoomAsync(state.UserId, state.CurrentRoomID);
921921

922922
using (var roomUsage = await getLocalUserRoom(state))
923923
await leaveRoom(state, roomUsage, wasKick);

osu.Server.Spectator/Services/ISharedInterop.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,19 @@ public interface ISharedInterop
2525
/// <remarks>
2626
/// This performs setup tasks like adding the user to the relevant chat channel.
2727
/// </remarks>
28-
/// <param name="roomId">The ID of the room to join.</param>
2928
/// <param name="userId">The ID of the user wanting to join the room.</param>
30-
Task AddUserToRoomAsync(long roomId, int userId);
29+
/// <param name="roomId">The ID of the room to join.</param>
30+
/// <param name="password">The room's password.</param>
31+
Task AddUserToRoomAsync(int userId, long roomId, string password);
3132

3233
/// <summary>
3334
/// Parts an osu!web room.
3435
/// </summary>
3536
/// <remarks>
3637
/// This performs setup tasks like removing the user from any relevant chat channels.
3738
/// </remarks>
38-
/// <param name="roomId">The ID of the room to part.</param>
3939
/// <param name="userId">The ID of the user wanting to part the room.</param>
40-
Task RemoveUserFromRoomAsync(long roomId, int userId);
40+
/// <param name="roomId">The ID of the room to part.</param>
41+
Task RemoveUserFromRoomAsync(int userId, long roomId);
4142
}
4243
}

osu.Server.Spectator/Services/SharedInterop.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,15 @@ public async Task<long> CreateRoomAsync(int hostUserId, MultiplayerRoom room)
123123
})));
124124
}
125125

126-
public async Task AddUserToRoomAsync(long roomId, int userId)
126+
public async Task AddUserToRoomAsync(int userId, long roomId, string password)
127127
{
128-
await runCommand(HttpMethod.Put, $"multiplayer/rooms/{roomId}/users/{userId}");
128+
await runCommand(HttpMethod.Put, $"multiplayer/rooms/{roomId}/users/{userId}", new
129+
{
130+
password = password
131+
});
129132
}
130133

131-
public async Task RemoveUserFromRoomAsync(long roomId, int userId)
134+
public async Task RemoveUserFromRoomAsync(int userId, long roomId)
132135
{
133136
await runCommand(HttpMethod.Delete, $"multiplayer/rooms/{roomId}/users/{userId}");
134137
}

0 commit comments

Comments
 (0)