Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions osu.Server.Spectator/Database/DatabaseAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Dapper;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -500,6 +501,32 @@ public async Task<IEnumerable<multiplayer_room>> GetActiveDailyChallengeRoomsAsy
new { scoreId = scoreId });
}

public async Task WaitForRoomScoreSubmissionComplete(long playlistItemId)
{
var connection = await getConnectionAsync();

int tokenCount = await connection.QuerySingleAsync<int>("SELECT COUNT(*) FROM `score_tokens` WHERE playlist_item_id = @playlistItemId", new
{
playlistItemId = playlistItemId
});

using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10)))
{
while (!cts.IsCancellationRequested)
{
int scoreCount = await connection.QuerySingleAsync<int>("SELECT COUNT(*) FROM `multiplayer_score_links` WHERE playlist_item_id = @playlistItemId", new
{
playlistItemId = playlistItemId
});

if (scoreCount == tokenCount)
return;
}

logger.Log(LogLevel.Warning, $"Score submission for playlist item {playlistItemId} did not complete in the allotted time period (10 seconds)!");
}
}

/// <summary>
/// Retrieves ALL score data for scores on a playlist item.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions osu.Server.Spectator/Database/IDatabaseAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ public interface IDatabaseAccess : IDisposable
/// </summary>
Task<(long roomID, long playlistItemID)?> GetMultiplayerRoomIdForScoreAsync(long scoreId);

/// <summary>
/// Waits for all score submissions on a given playlist item to complete, up to a maximum of 10 seconds.
/// </summary>
/// <param name="playlistItemId">The playlist item.</param>
Task WaitForRoomScoreSubmissionComplete(long playlistItemId);

/// <summary>
/// Retrieve all scores for a specified playlist item.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,21 @@ public async Task HandleGameplayCompleted()
{
using (var db = dbFactory.GetInstance())
{
await db.WaitForRoomScoreSubmissionComplete(CurrentItem.ID);

// Expire and let clients know that the current item has finished.
await db.MarkPlaylistItemAsPlayedAsync(room.RoomID, CurrentItem.ID);
room.Playlist[room.Playlist.IndexOf(CurrentItem)] = (await db.GetPlaylistItemAsync(room.RoomID, CurrentItem.ID)).ToMultiplayerPlaylistItem();
await hub.NotifyPlaylistItemChanged(room, CurrentItem, true);
}

Dictionary<int, SoloScore> scores = new Dictionary<int, SoloScore>();

using (var db = dbFactory.GetInstance())
{
// Update the room results with the player scores.
Dictionary<int, SoloScore> scores = new Dictionary<int, SoloScore>();
foreach (var score in await db.GetAllScoresForPlaylistItem(CurrentItem.ID))
scores[(int)score.user_id] = score;
}
state.RecordScores(scores.Values.Select(s => s.ToScoreInfo()).ToArray(), placement_points);

state.RecordScores(scores.Values.Select(s => s.ToScoreInfo()).ToArray(), placement_points);

await stageResultsDisplaying();
await stageResultsDisplaying();
}
}

public async Task HandleUserRequest(MultiplayerRoomUser user, MatchUserRequest request)
Expand Down