mirror of
https://github.com/osukey/osukey.git
synced 2025-05-29 01:17:35 +09:00
Read from (and allow reloading) IPC source
This commit is contained in:
parent
3b52e7c724
commit
47a89231ad
@ -9,6 +9,7 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Framework.Platform.Windows;
|
using osu.Framework.Platform.Windows;
|
||||||
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Beatmaps.Legacy;
|
using osu.Game.Beatmaps.Legacy;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
@ -26,103 +27,120 @@ namespace osu.Game.Tournament.IPC
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
protected RulesetStore Rulesets { get; private set; }
|
protected RulesetStore Rulesets { get; private set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private GameHost host { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private LadderInfo ladder { get; set; }
|
||||||
|
|
||||||
private int lastBeatmapId;
|
private int lastBeatmapId;
|
||||||
|
private ScheduledDelegate scheduled;
|
||||||
|
|
||||||
|
public Storage Storage { get; private set; }
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(LadderInfo ladder, GameHost host)
|
private void load()
|
||||||
{
|
{
|
||||||
StableStorage stable;
|
LocateStableStorage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Storage LocateStableStorage()
|
||||||
|
{
|
||||||
|
scheduled?.Cancel();
|
||||||
|
|
||||||
|
Storage = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
stable = new StableStorage(host as DesktopGameHost);
|
Storage = new StableStorage(host as DesktopGameHost);
|
||||||
|
|
||||||
|
const string file_ipc_filename = "ipc.txt";
|
||||||
|
const string file_ipc_state_filename = "ipc-state.txt";
|
||||||
|
const string file_ipc_scores_filename = "ipc-scores.txt";
|
||||||
|
const string file_ipc_channel_filename = "ipc-channel.txt";
|
||||||
|
|
||||||
|
if (Storage.Exists(file_ipc_filename))
|
||||||
|
scheduled = Scheduler.AddDelayed(delegate
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var stream = Storage.GetStream(file_ipc_filename))
|
||||||
|
using (var sr = new StreamReader(stream))
|
||||||
|
{
|
||||||
|
var beatmapId = int.Parse(sr.ReadLine());
|
||||||
|
var mods = int.Parse(sr.ReadLine());
|
||||||
|
|
||||||
|
if (lastBeatmapId != beatmapId)
|
||||||
|
{
|
||||||
|
lastBeatmapId = beatmapId;
|
||||||
|
|
||||||
|
var existing = ladder.CurrentMatch.Value?.Round.Value?.Beatmaps.FirstOrDefault(b => b.ID == beatmapId && b.BeatmapInfo != null);
|
||||||
|
|
||||||
|
if (existing != null)
|
||||||
|
Beatmap.Value = existing.BeatmapInfo;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = beatmapId });
|
||||||
|
req.Success += b => Beatmap.Value = b.ToBeatmap(Rulesets);
|
||||||
|
API.Queue(req);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Mods.Value = (LegacyMods)mods;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// file might be in use.
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var stream = Storage.GetStream(file_ipc_channel_filename))
|
||||||
|
using (var sr = new StreamReader(stream))
|
||||||
|
{
|
||||||
|
ChatChannel.Value = sr.ReadLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
// file might be in use.
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var stream = Storage.GetStream(file_ipc_state_filename))
|
||||||
|
using (var sr = new StreamReader(stream))
|
||||||
|
{
|
||||||
|
State.Value = (TourneyState)Enum.Parse(typeof(TourneyState), sr.ReadLine());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
// file might be in use.
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var stream = Storage.GetStream(file_ipc_scores_filename))
|
||||||
|
using (var sr = new StreamReader(stream))
|
||||||
|
{
|
||||||
|
Score1.Value = int.Parse(sr.ReadLine());
|
||||||
|
Score2.Value = int.Parse(sr.ReadLine());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
// file might be in use.
|
||||||
|
}
|
||||||
|
}, 250, true);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.Error(e, "Stable installation could not be found; disabling file based IPC");
|
Logger.Error(e, "Stable installation could not be found; disabling file based IPC");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const string file_ipc_filename = "ipc.txt";
|
return Storage;
|
||||||
const string file_ipc_state_filename = "ipc-state.txt";
|
|
||||||
const string file_ipc_scores_filename = "ipc-scores.txt";
|
|
||||||
const string file_ipc_channel_filename = "ipc-channel.txt";
|
|
||||||
|
|
||||||
if (stable.Exists(file_ipc_filename))
|
|
||||||
Scheduler.AddDelayed(delegate
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var stream = stable.GetStream(file_ipc_filename))
|
|
||||||
using (var sr = new StreamReader(stream))
|
|
||||||
{
|
|
||||||
var beatmapId = int.Parse(sr.ReadLine());
|
|
||||||
var mods = int.Parse(sr.ReadLine());
|
|
||||||
|
|
||||||
if (lastBeatmapId != beatmapId)
|
|
||||||
{
|
|
||||||
lastBeatmapId = beatmapId;
|
|
||||||
|
|
||||||
var existing = ladder.CurrentMatch.Value?.Round.Value?.Beatmaps.FirstOrDefault(b => b.ID == beatmapId && b.BeatmapInfo != null);
|
|
||||||
|
|
||||||
if (existing != null)
|
|
||||||
Beatmap.Value = existing.BeatmapInfo;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = beatmapId });
|
|
||||||
req.Success += b => Beatmap.Value = b.ToBeatmap(Rulesets);
|
|
||||||
API.Queue(req);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Mods.Value = (LegacyMods)mods;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
// file might be in use.
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var stream = stable.GetStream(file_ipc_channel_filename))
|
|
||||||
using (var sr = new StreamReader(stream))
|
|
||||||
{
|
|
||||||
ChatChannel.Value = sr.ReadLine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
// file might be in use.
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var stream = stable.GetStream(file_ipc_state_filename))
|
|
||||||
using (var sr = new StreamReader(stream))
|
|
||||||
{
|
|
||||||
State.Value = (TourneyState)Enum.Parse(typeof(TourneyState), sr.ReadLine());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
// file might be in use.
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var stream = stable.GetStream(file_ipc_scores_filename))
|
|
||||||
using (var sr = new StreamReader(stream))
|
|
||||||
{
|
|
||||||
Score1.Value = int.Parse(sr.ReadLine());
|
|
||||||
Score2.Value = int.Parse(sr.ReadLine());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
// file might be in use.
|
|
||||||
}
|
|
||||||
}, 250, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1,9 +1,24 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Game.Tournament.IPC;
|
||||||
|
|
||||||
namespace osu.Game.Tournament.Screens
|
namespace osu.Game.Tournament.Screens
|
||||||
{
|
{
|
||||||
public class SetupScreen : TournamentScreen
|
public class SetupScreen : TournamentScreen
|
||||||
{
|
{
|
||||||
|
[Resolved]
|
||||||
|
private MatchIPCInfo ipc { get; set; }
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
AddInternal(new SpriteText
|
||||||
|
{
|
||||||
|
Text = (ipc as FileBasedIPC)?.Storage.GetFullPath(string.Empty)
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user