From 2384f7b0c132597dd88ee7e395fcbb7b8bb6ada7 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 16 May 2017 19:49:50 +0900 Subject: [PATCH 01/14] Ensure LocalUser is never null --- osu.Game/Online/API/APIAccess.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/osu.Game/Online/API/APIAccess.cs b/osu.Game/Online/API/APIAccess.cs index c4b679fc92..e56e4efe24 100644 --- a/osu.Game/Online/API/APIAccess.cs +++ b/osu.Game/Online/API/APIAccess.cs @@ -34,7 +34,7 @@ namespace osu.Game.Online.API public string Password; - public Bindable LocalUser = new Bindable(); + public Bindable LocalUser = new Bindable(createGustUser()); public string Token { @@ -295,8 +295,15 @@ namespace osu.Game.Online.API clearCredentials(); authentication.Clear(); State = APIState.Offline; + LocalUser.Value = createGustUser(); } + private static User createGustUser() => new User + { + Username = @"Guest", + Id = 1, + }; + public void Update() { Scheduler.Update(); From 23807aa3b99419447e8a4d117eb973eac6ed0984 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 16 May 2017 19:55:45 +0900 Subject: [PATCH 02/14] Better handling of logged in state --- osu.Game/Online/API/APIAccess.cs | 4 +++- osu.Game/Overlays/ChatOverlay.cs | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/osu.Game/Online/API/APIAccess.cs b/osu.Game/Online/API/APIAccess.cs index e56e4efe24..9d48c38908 100644 --- a/osu.Game/Online/API/APIAccess.cs +++ b/osu.Game/Online/API/APIAccess.cs @@ -191,7 +191,7 @@ namespace osu.Game.Online.API req.Perform(this); //we could still be in initialisation, at which point we don't want to say we're Online yet. - if (LocalUser.Value != null) + if (IsLoggedIn) State = APIState.Online; failureCount = 0; @@ -266,6 +266,8 @@ namespace osu.Game.Online.API } } + public bool IsLoggedIn => LocalUser.Value.Id > 1; + public void Queue(APIRequest request) { queue.Enqueue(request); diff --git a/osu.Game/Overlays/ChatOverlay.cs b/osu.Game/Overlays/ChatOverlay.cs index 4748eb7de6..b360417dfd 100644 --- a/osu.Game/Overlays/ChatOverlay.cs +++ b/osu.Game/Overlays/ChatOverlay.cs @@ -353,7 +353,15 @@ namespace osu.Game.Overlays { var postText = textbox.Text; - if (string.IsNullOrEmpty(postText) || api.LocalUser.Value == null) return; + if (string.IsNullOrEmpty(postText)) + return; + + if (!api.IsLoggedIn) + { + currentChannel?.AddNewMessages(new ErrorMessage("Please login to participate in chat!")); + textbox.Text = string.Empty; + return; + } if (currentChannel == null) return; From fdf0137fc2818b7dd27d297b3a022071e571fccc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 16 May 2017 16:22:11 +0900 Subject: [PATCH 03/14] Remove incorrect padding --- osu.Game/Overlays/ChatOverlay.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Overlays/ChatOverlay.cs b/osu.Game/Overlays/ChatOverlay.cs index 4748eb7de6..53a2b0170a 100644 --- a/osu.Game/Overlays/ChatOverlay.cs +++ b/osu.Game/Overlays/ChatOverlay.cs @@ -81,7 +81,6 @@ namespace osu.Game.Overlays RelativeSizeAxes = Axes.Both, Padding = new MarginPadding { - Top = padding, Bottom = textbox_height + padding }, }, From 041d4f93c0a66e84b9496b629a477965bfc983e2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 16 May 2017 20:08:22 +0900 Subject: [PATCH 04/14] Fix typo --- osu.Game/Online/API/APIAccess.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Online/API/APIAccess.cs b/osu.Game/Online/API/APIAccess.cs index 9d48c38908..032e5ccc6e 100644 --- a/osu.Game/Online/API/APIAccess.cs +++ b/osu.Game/Online/API/APIAccess.cs @@ -34,7 +34,7 @@ namespace osu.Game.Online.API public string Password; - public Bindable LocalUser = new Bindable(createGustUser()); + public Bindable LocalUser = new Bindable(createGuestUser()); public string Token { @@ -297,10 +297,10 @@ namespace osu.Game.Online.API clearCredentials(); authentication.Clear(); State = APIState.Offline; - LocalUser.Value = createGustUser(); + LocalUser.Value = createGuestUser(); } - private static User createGustUser() => new User + private static User createGuestUser() => new User { Username = @"Guest", Id = 1, From 3d74492c956d0e814c6f07988c0dabc5dfeae6d3 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 16 May 2017 21:19:34 +0900 Subject: [PATCH 05/14] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 3111d1aa4f..67f3958036 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 3111d1aa4f0d3aa1c0df03f8003b6c5c726b10d2 +Subproject commit 67f39580365f7d0a42f8788eae2b60881dde1c67 From 5a9745b492ee41e85acb95b4bb209c65d27a2aa2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 16 May 2017 21:37:55 +0900 Subject: [PATCH 06/14] Update API endpoint --- osu.Game/Online/API/APIAccess.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Online/API/APIAccess.cs b/osu.Game/Online/API/APIAccess.cs index 032e5ccc6e..2f344e0bdf 100644 --- a/osu.Game/Online/API/APIAccess.cs +++ b/osu.Game/Online/API/APIAccess.cs @@ -20,7 +20,7 @@ namespace osu.Game.Online.API { private readonly OAuth authentication; - public string Endpoint = @"https://new.ppy.sh"; + public string Endpoint = @"https://osu.ppy.sh"; private const string client_id = @"5"; private const string client_secret = @"FGc9GAtyHzeQDshWP5Ah7dega8hJACAJpQtw6OXk"; From b9a40a841b7311673c517f5f1b11bb4bd53d7a8d Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 13 May 2017 21:28:53 +0800 Subject: [PATCH 07/14] Use IsAssignableFrom. --- osu.Game/Graphics/UserInterface/RollingCounter.cs | 2 +- osu.Game/Overlays/NotificationManager.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index e98867277a..bdb2054ca4 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -181,7 +181,7 @@ namespace osu.Game.Graphics.UserInterface protected virtual void TransformCount(T currentValue, T newValue) { Debug.Assert( - TransformType.IsSubclassOf(typeof(Transform)) || TransformType == typeof(Transform), + typeof(Transform).IsAssignableFrom(TransformType), @"transformType should be a subclass of Transform." ); diff --git a/osu.Game/Overlays/NotificationManager.cs b/osu.Game/Overlays/NotificationManager.cs index b344d533ee..3ddd85cfcf 100644 --- a/osu.Game/Overlays/NotificationManager.cs +++ b/osu.Game/Overlays/NotificationManager.cs @@ -81,7 +81,7 @@ namespace osu.Game.Overlays hasCompletionTarget.CompletionTarget = Post; var ourType = notification.GetType(); - sections.Children.FirstOrDefault(s => s.AcceptTypes.Any(accept => ourType == accept || ourType.IsSubclassOf(accept)))?.Add(notification); + sections.Children.FirstOrDefault(s => s.AcceptTypes.Any(accept => accept.IsAssignableFrom(ourType)))?.Add(notification); } protected override void PopIn() From d213706d076f384734196e0475ca89f3c390ef42 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Tue, 16 May 2017 21:14:50 +0800 Subject: [PATCH 08/14] Use DateTimeOffset. --- osu.Desktop.VisualTests/Tests/TestCaseResults.cs | 2 +- osu.Game/Online/Chat/ErrorMessage.cs | 2 +- osu.Game/Rulesets/Scoring/Score.cs | 2 +- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 2 +- osu.Game/Screens/Ranking/ResultsPageScore.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseResults.cs b/osu.Desktop.VisualTests/Tests/TestCaseResults.cs index aa3a117667..f8c93e9a73 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseResults.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseResults.cs @@ -47,7 +47,7 @@ namespace osu.Desktop.VisualTests.Tests Accuracy = 0.98, MaxCombo = 123, Rank = ScoreRank.A, - Date = DateTime.Now, + Date = DateTimeOffset.Now, Statistics = new Dictionary() { { "300", 50 }, diff --git a/osu.Game/Online/Chat/ErrorMessage.cs b/osu.Game/Online/Chat/ErrorMessage.cs index a410e9044a..48557ca648 100644 --- a/osu.Game/Online/Chat/ErrorMessage.cs +++ b/osu.Game/Online/Chat/ErrorMessage.cs @@ -12,7 +12,7 @@ namespace osu.Game.Online.Chat public ErrorMessage(string message) : base(errorId--) { - Timestamp = DateTime.Now; + Timestamp = DateTimeOffset.Now; Content = message; Sender = new User diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index 15d8690322..2cca0f54af 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -46,7 +46,7 @@ namespace osu.Game.Rulesets.Scoring public long OnlineScoreID; [JsonProperty(@"created_at")] - public DateTime Date; + public DateTimeOffset Date; [JsonProperty(@"statistics")] private Dictionary jsonStats diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index 11c1c273e2..79fb34a523 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -129,7 +129,7 @@ namespace osu.Game.Rulesets.Scoring score.MaxCombo = HighestCombo; score.Accuracy = Accuracy; score.Rank = rankFrom(Accuracy); - score.Date = DateTime.Now; + score.Date = DateTimeOffset.Now; score.Health = Health; } } diff --git a/osu.Game/Screens/Ranking/ResultsPageScore.cs b/osu.Game/Screens/Ranking/ResultsPageScore.cs index fad914e9d4..4dc61b8160 100644 --- a/osu.Game/Screens/Ranking/ResultsPageScore.cs +++ b/osu.Game/Screens/Ranking/ResultsPageScore.cs @@ -116,7 +116,7 @@ namespace osu.Game.Screens.Ranking Origin = Anchor.TopCentre, Margin = new MarginPadding { Bottom = 10 }, }, - new DateDisplay(Score.Date) + new DateDisplay(Score.Date.LocalDateTime) { Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, From d929de466a2e43e52b5682f2010fa1fe585341f3 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Tue, 16 May 2017 21:16:52 +0800 Subject: [PATCH 09/14] DateDisplay -> DateTimeDisplay for more exactly. --- osu.Game/Screens/Ranking/ResultsPageScore.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/osu.Game/Screens/Ranking/ResultsPageScore.cs b/osu.Game/Screens/Ranking/ResultsPageScore.cs index 4dc61b8160..70542dab8b 100644 --- a/osu.Game/Screens/Ranking/ResultsPageScore.cs +++ b/osu.Game/Screens/Ranking/ResultsPageScore.cs @@ -116,7 +116,7 @@ namespace osu.Game.Screens.Ranking Origin = Anchor.TopCentre, Margin = new MarginPadding { Bottom = 10 }, }, - new DateDisplay(Score.Date.LocalDateTime) + new DateTimeDisplay(Score.Date.LocalDateTime) { Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, @@ -220,13 +220,13 @@ namespace osu.Game.Screens.Ranking } } - private class DateDisplay : Container + private class DateTimeDisplay : Container { - private DateTime date; + private DateTime datetime; - public DateDisplay(DateTime date) + public DateTimeDisplay(DateTime datetime) { - this.date = date; + this.datetime = datetime; AutoSizeAxes = Axes.Y; @@ -250,7 +250,7 @@ namespace osu.Game.Screens.Ranking { Origin = Anchor.CentreLeft, Anchor = Anchor.CentreLeft, - Text = date.ToString("HH:mm"), + Text = datetime.ToString("HH:mm"), Padding = new MarginPadding { Left = 10, Right = 10, Top = 5, Bottom = 5 }, Colour = Color4.White, }, @@ -258,7 +258,7 @@ namespace osu.Game.Screens.Ranking { Origin = Anchor.CentreRight, Anchor = Anchor.CentreRight, - Text = date.ToString("yyyy/MM/dd"), + Text = datetime.ToString("yyyy/MM/dd"), Padding = new MarginPadding { Left = 10, Right = 10, Top = 5, Bottom = 5 }, Colour = Color4.White, } From e911441394ad80a7871b41a1be8686f672fa76d5 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Tue, 16 May 2017 21:23:14 +0800 Subject: [PATCH 10/14] Why AbandonedMutexException? --- osu.Game/IO/Legacy/SerializationReader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/IO/Legacy/SerializationReader.cs b/osu.Game/IO/Legacy/SerializationReader.cs index 6bb6c3bbbf..c4d56641af 100644 --- a/osu.Game/IO/Legacy/SerializationReader.cs +++ b/osu.Game/IO/Legacy/SerializationReader.cs @@ -66,7 +66,7 @@ namespace osu.Game.IO.Legacy public DateTime ReadDateTime() { long ticks = ReadInt64(); - if (ticks < 0) throw new AbandonedMutexException("oops"); + if (ticks < 0) throw new IOException("Bad ticks count read!"); return new DateTime(ticks, DateTimeKind.Utc); } From aaaee5ed102e54a2fe40209e0ebe967015b29b83 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Tue, 16 May 2017 21:46:22 +0800 Subject: [PATCH 11/14] Use generic IComparable for message. --- osu.Game/Online/Chat/Channel.cs | 2 +- osu.Game/Online/Chat/Message.cs | 14 ++------------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/osu.Game/Online/Chat/Channel.cs b/osu.Game/Online/Chat/Channel.cs index 2925c3ccb4..93fd0a8956 100644 --- a/osu.Game/Online/Chat/Channel.cs +++ b/osu.Game/Online/Chat/Channel.cs @@ -23,7 +23,7 @@ namespace osu.Game.Online.Chat [JsonProperty(@"channel_id")] public int Id; - public readonly SortedList Messages = new SortedList((m1, m2) => m1.Id.CompareTo(m2.Id)); + public readonly SortedList Messages = new SortedList(Comparer.Default); //internal bool Joined; diff --git a/osu.Game/Online/Chat/Message.cs b/osu.Game/Online/Chat/Message.cs index bf53a68910..c1887e7824 100644 --- a/osu.Game/Online/Chat/Message.cs +++ b/osu.Game/Online/Chat/Message.cs @@ -8,7 +8,7 @@ using osu.Game.Users; namespace osu.Game.Online.Chat { - public class Message + public class Message : IComparable { [JsonProperty(@"message_id")] public readonly long Id; @@ -42,17 +42,7 @@ namespace osu.Game.Online.Chat Id = id; } - public override bool Equals(object obj) - { - var objMessage = obj as Message; - - return Id == objMessage?.Id; - } - - public override int GetHashCode() - { - return Id.GetHashCode(); - } + public int CompareTo(Message other) => Id.CompareTo(other.Id); } public enum TargetType From f1d5a929505419c71fcd790c37f22a70db49ccb2 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Tue, 16 May 2017 21:49:38 +0800 Subject: [PATCH 12/14] Use generic IEqutable to avoid typeless Equals. --- osu.Game/Graphics/UserInterface/OsuSliderBar.cs | 4 +++- osu.Game/Overlays/Settings/SettingsSlider.cs | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs index 027473921f..6cf7b2dfa5 100644 --- a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using OpenTK; using osu.Framework.Allocation; using osu.Framework.Audio; @@ -13,7 +14,8 @@ using osu.Framework.Input; namespace osu.Game.Graphics.UserInterface { - public class OsuSliderBar : SliderBar, IHasTooltip where T : struct + public class OsuSliderBar : SliderBar, IHasTooltip + where T : struct, IEquatable { private SampleChannel sample; private double lastSampleTime; diff --git a/osu.Game/Overlays/Settings/SettingsSlider.cs b/osu.Game/Overlays/Settings/SettingsSlider.cs index beb2bdf645..522d242f2a 100644 --- a/osu.Game/Overlays/Settings/SettingsSlider.cs +++ b/osu.Game/Overlays/Settings/SettingsSlider.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using osu.Framework.Graphics; using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics.UserInterface; @@ -8,12 +9,12 @@ using osu.Game.Graphics.UserInterface; namespace osu.Game.Overlays.Settings { public class SettingsSlider : SettingsSlider> - where T : struct + where T : struct, IEquatable { } public class SettingsSlider : SettingsItem - where T : struct + where T : struct, IEquatable where U : SliderBar, new() { protected override Drawable CreateControl() => new U() From e2a7f00a5255cc6a68f456a26ee282e0f665181e Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Tue, 16 May 2017 22:20:05 +0800 Subject: [PATCH 13/14] Remove unused namespace. --- osu.Game/IO/Legacy/SerializationReader.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/IO/Legacy/SerializationReader.cs b/osu.Game/IO/Legacy/SerializationReader.cs index c4d56641af..bad143fa6c 100644 --- a/osu.Game/IO/Legacy/SerializationReader.cs +++ b/osu.Game/IO/Legacy/SerializationReader.cs @@ -10,7 +10,6 @@ using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters; using System.Runtime.Serialization.Formatters.Binary; using System.Text; -using System.Threading; namespace osu.Game.IO.Legacy { From b22c84287a2678c954d4025bd042af9aa0eb9cc7 Mon Sep 17 00:00:00 2001 From: nyaamara Date: Tue, 16 May 2017 16:54:33 -0400 Subject: [PATCH 14/14] Fix typo. --- osu.Game/Screens/Select/BeatmapDetails.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Select/BeatmapDetails.cs b/osu.Game/Screens/Select/BeatmapDetails.cs index a0d15101e0..18288da901 100644 --- a/osu.Game/Screens/Select/BeatmapDetails.cs +++ b/osu.Game/Screens/Select/BeatmapDetails.cs @@ -156,7 +156,7 @@ namespace osu.Game.Screens.Select drainRate = new DifficultyRow("HP Drain"), overallDifficulty = new DifficultyRow("Accuracy"), approachRate = new DifficultyRow("Approach Rate"), - stars = new DifficultyRow("Star Diffculty"), + stars = new DifficultyRow("Star Difficulty"), }, }, },