mirror of
https://github.com/ppy/osu.git
synced 2025-03-05 07:02:55 +08:00
Update test room manager to not return passwords
This commit is contained in:
parent
c6bc95767d
commit
063f14da98
@ -9,23 +9,23 @@ namespace osu.Game.Online.Rooms
|
||||
{
|
||||
public class JoinRoomRequest : APIRequest
|
||||
{
|
||||
private readonly Room room;
|
||||
private readonly string password;
|
||||
public readonly Room Room;
|
||||
public readonly string Password;
|
||||
|
||||
public JoinRoomRequest(Room room, string password)
|
||||
{
|
||||
this.room = room;
|
||||
this.password = password;
|
||||
Room = room;
|
||||
Password = password;
|
||||
}
|
||||
|
||||
protected override WebRequest CreateWebRequest()
|
||||
{
|
||||
var req = base.CreateWebRequest();
|
||||
req.Method = HttpMethod.Put;
|
||||
req.AddParameter("password", password);
|
||||
req.AddParameter("password", Password);
|
||||
return req;
|
||||
}
|
||||
|
||||
protected override string Target => $"rooms/{room.RoomID.Value}/users/{User.Id}";
|
||||
protected override string Target => $"rooms/{Room.RoomID.Value}/users/{User.Id}";
|
||||
}
|
||||
}
|
||||
|
@ -45,21 +45,33 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
switch (req)
|
||||
{
|
||||
case CreateRoomRequest createRoomRequest:
|
||||
var createdRoom = new APICreatedRoom();
|
||||
var apiRoom = new Room();
|
||||
|
||||
createdRoom.CopyFrom(createRoomRequest.Room);
|
||||
createdRoom.RoomID.Value ??= currentRoomId++;
|
||||
apiRoom.CopyFrom(createRoomRequest.Room);
|
||||
apiRoom.RoomID.Value ??= currentRoomId++;
|
||||
for (int i = 0; i < apiRoom.Playlist.Count; i++)
|
||||
apiRoom.Playlist[i].ID = currentPlaylistItemId++;
|
||||
|
||||
for (int i = 0; i < createdRoom.Playlist.Count; i++)
|
||||
createdRoom.Playlist[i].ID = currentPlaylistItemId++;
|
||||
var responseRoom = new APICreatedRoom();
|
||||
responseRoom.CopyFrom(createResponseRoom(apiRoom, false));
|
||||
|
||||
Rooms.Add(createdRoom);
|
||||
createRoomRequest.TriggerSuccess(createdRoom);
|
||||
Rooms.Add(apiRoom);
|
||||
createRoomRequest.TriggerSuccess(responseRoom);
|
||||
return true;
|
||||
|
||||
case JoinRoomRequest joinRoomRequest:
|
||||
{
|
||||
var room = Rooms.Single(r => r.RoomID.Value == joinRoomRequest.Room.RoomID.Value);
|
||||
|
||||
if (joinRoomRequest.Password != room.Password.Value)
|
||||
{
|
||||
joinRoomRequest.TriggerFailure(new InvalidOperationException("Invalid password."));
|
||||
return true;
|
||||
}
|
||||
|
||||
joinRoomRequest.TriggerSuccess();
|
||||
return true;
|
||||
}
|
||||
|
||||
case PartRoomRequest partRoomRequest:
|
||||
partRoomRequest.TriggerSuccess();
|
||||
@ -69,20 +81,13 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
var roomsWithoutParticipants = new List<Room>();
|
||||
|
||||
foreach (var r in Rooms)
|
||||
{
|
||||
var newRoom = new Room();
|
||||
|
||||
newRoom.CopyFrom(r);
|
||||
newRoom.RecentParticipants.Clear();
|
||||
|
||||
roomsWithoutParticipants.Add(newRoom);
|
||||
}
|
||||
roomsWithoutParticipants.Add(createResponseRoom(r, false));
|
||||
|
||||
getRoomsRequest.TriggerSuccess(roomsWithoutParticipants);
|
||||
return true;
|
||||
|
||||
case GetRoomRequest getRoomRequest:
|
||||
getRoomRequest.TriggerSuccess(Rooms.Single(r => r.RoomID.Value == getRoomRequest.RoomId));
|
||||
getRoomRequest.TriggerSuccess(createResponseRoom(Rooms.Single(r => r.RoomID.Value == getRoomRequest.RoomId), true));
|
||||
return true;
|
||||
|
||||
case GetBeatmapSetRequest getBeatmapSetRequest:
|
||||
@ -118,6 +123,16 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
};
|
||||
}
|
||||
|
||||
private Room createResponseRoom(Room room, bool withParticipants)
|
||||
{
|
||||
var responseRoom = new Room();
|
||||
responseRoom.CopyFrom(room);
|
||||
responseRoom.Password.Value = null;
|
||||
if (!withParticipants)
|
||||
responseRoom.RecentParticipants.Clear();
|
||||
return responseRoom;
|
||||
}
|
||||
|
||||
public new void ClearRooms() => base.ClearRooms();
|
||||
|
||||
public new void Schedule(Action action) => base.Schedule(action);
|
||||
|
Loading…
Reference in New Issue
Block a user