From 75ed7e9215ba88358d9b838dd82fa3841f78ae5a Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 8 May 2017 11:31:20 -0400 Subject: Fix softlocks on pre-user OOBE. --- ShiftOS_TheReturn/UniteClient.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'ShiftOS_TheReturn/UniteClient.cs') diff --git a/ShiftOS_TheReturn/UniteClient.cs b/ShiftOS_TheReturn/UniteClient.cs index 1136b5c..8d6a58d 100644 --- a/ShiftOS_TheReturn/UniteClient.cs +++ b/ShiftOS_TheReturn/UniteClient.cs @@ -5,13 +5,20 @@ using System.Net; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; +using ShiftOS.Objects; namespace ShiftOS.Unite { public class UniteClient { public string Token { get; private set; } - public string BaseURL { get; private set; } + public string BaseURL + { + get + { + return UserConfig.Get().UniteUrl; + } + } public string GetDisplayNameId(string id) { @@ -25,7 +32,8 @@ namespace ShiftOS.Unite public UniteClient(string baseurl, string usertoken) { - BaseURL = baseurl; + //Handled by the servers.json file + //BaseURL = baseurl; Token = usertoken; } -- cgit v1.2.3 From c0015d369da4ab0b8e2303b74d9843883fd88828 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 19 May 2017 08:52:21 -0400 Subject: document unite API wrapper --- ShiftOS_TheReturn/UniteClient.cs | 103 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 1 deletion(-) (limited to 'ShiftOS_TheReturn/UniteClient.cs') diff --git a/ShiftOS_TheReturn/UniteClient.cs b/ShiftOS_TheReturn/UniteClient.cs index 8d6a58d..d8e34b7 100644 --- a/ShiftOS_TheReturn/UniteClient.cs +++ b/ShiftOS_TheReturn/UniteClient.cs @@ -11,7 +11,14 @@ namespace ShiftOS.Unite { public class UniteClient { + /// + /// Gets a string represents the user token for this Unite Client. + /// public string Token { get; private set; } + + /// + /// Gets the base URL used in all API calls. Retrieved from the user's servers.json file. + /// public string BaseURL { get @@ -20,16 +27,30 @@ namespace ShiftOS.Unite } } + /// + /// Get the display name of a user. + /// + /// The user ID to look at. + /// public string GetDisplayNameId(string id) { return MakeCall("/API/GetDisplayName/" + id); } + /// + /// Get the Pong highscore stats for all users. + /// + /// public PongHighscoreModel GetPongHighscores() { return JsonConvert.DeserializeObject(MakeCall("/API/GetPongHighscores")); } + /// + /// Create a new instance of the object. + /// + /// Unused. + /// The user API token to use for this client (see http://getshiftos.ml/Manage and click "API" to see your tokens) public UniteClient(string baseurl, string usertoken) { //Handled by the servers.json file @@ -37,6 +58,11 @@ namespace ShiftOS.Unite Token = usertoken; } + /// + /// Make a call to the Unite API using the current user token and base URL. + /// + /// The path, relative to the base URL, to call. + /// The server's response. internal string MakeCall(string url) { var webrequest = WebRequest.Create(BaseURL + url); @@ -53,83 +79,158 @@ namespace ShiftOS.Unite } } + /// + /// Get the Pong codepoint highscore for the current user. + /// + /// The amount of Codepoints returned by the server public int GetPongCP() { return Convert.ToInt32(MakeCall("/API/GetPongCP")); } + /// + /// Get the pong highest level score for this user + /// + /// The highest level the user has reached. public int GetPongLevel() { return Convert.ToInt32(MakeCall("/API/GetPongLevel")); } + /// + /// Set the user's highest level record for Pong. + /// + /// The level to set the record to. public void SetPongLevel(int value) { MakeCall("/API/SetPongLevel/" + value.ToString()); } + /// + /// Set the pong Codepoints record for the user + /// + /// The amount of Codepoints to set the record to public void SetPongCP(int value) { MakeCall("/API/SetPongCP/" + value.ToString()); } + /// + /// Get the user's email address. + /// + /// The user's email address. public string GetEmail() { return MakeCall("/API/GetEmail"); } + /// + /// Get the user's system name. + /// + /// The user's system name. public string GetSysName() { return MakeCall("/API/GetSysName"); } + /// + /// Set the user's system name. + /// + /// The system name to set the record to. public void SetSysName(string value) { MakeCall("/API/SetSysName/" + value); } + /// + /// Get the user's display name. + /// + /// The user's display name. public string GetDisplayName() { return MakeCall("/API/GetDisplayName"); } + /// + /// Set the user's display name. + /// + /// The display name to set the user's account to. public void SetDisplayName(string value) { MakeCall("/API/SetDisplayName/" + value.ToString()); } + /// + /// Get the user's full name if they have set it in their profile. + /// + /// Empty string if the user hasn't set their fullname, else, a string representing their fullname. public string GetFullName() { return MakeCall("/API/GetFullName"); } + /// + /// Set the user's fullname. + /// + /// The new fullname. public void SetFullName(string value) { MakeCall("/API/SetFullName/" + value.ToString()); } - + /// + /// Get the user's codepoints. + /// + /// The amount of codepoints stored on the server for this user. public long GetCodepoints() { return Convert.ToInt64(MakeCall("/API/GetCodepoints")); } + /// + /// Set the user's codepoints. + /// + /// The amount of codepoints to set the user's codepoints value to. public void SetCodepoints(long value) { MakeCall("/API/SetCodepoints/" + value.ToString()); } } + /// + /// API data model for Unite pong highscores. + /// public class PongHighscoreModel { + /// + /// Amount of pages in this list. + /// public int Pages { get; set; } + + /// + /// An array representing the highscores found on the server. + /// public PongHighscore[] Highscores { get; set; } } + /// + /// API data model for a single Pong highscore. + /// public class PongHighscore { + /// + /// The user ID linked to this highscore. + /// public string UserId { get; set; } + + /// + /// The highscore's level record. + /// public int Level { get; set; } + + /// + /// The highscore's codepoint cashout record. + /// public long CodepointsCashout { get; set; } } } -- cgit v1.2.3 From 6eb764bd5c1342fc7d3d6f2bd46069462b2a48db Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 21 May 2017 08:31:48 -0400 Subject: Hmmmmmm --- ShiftOS.Objects/Save.cs | 27 +++- ShiftOS.Objects/ShiftOS.Objects.csproj | 1 + ShiftOS.Objects/UniteClient.cs | 236 ++++++++++++++++++++++++++++++++ ShiftOS_TheReturn/ShiftOS.Engine.csproj | 1 - ShiftOS_TheReturn/UniteClient.cs | 236 -------------------------------- 5 files changed, 263 insertions(+), 238 deletions(-) create mode 100644 ShiftOS.Objects/UniteClient.cs delete mode 100644 ShiftOS_TheReturn/UniteClient.cs (limited to 'ShiftOS_TheReturn/UniteClient.cs') diff --git a/ShiftOS.Objects/Save.cs b/ShiftOS.Objects/Save.cs index cc19c79..f4e1e09 100644 --- a/ShiftOS.Objects/Save.cs +++ b/ShiftOS.Objects/Save.cs @@ -41,8 +41,33 @@ namespace ShiftOS.Objects [Obsolete("This save variable is no longer used in Beta 2.4 and above of ShiftOS. Please use ShiftOS.Engine.SaveSystem.CurrentUser.Username to access the current user's username.")] public string Username { get; set; } + private long _cp = 0; + + public long Codepoints + { + get + { + if (!string.IsNullOrWhiteSpace(UniteAuthToken)) + { + var uc = new ShiftOS.Unite.UniteClient("", UniteAuthToken); + return uc.GetCodepoints(); + } + else + return _cp; + } + set + { + if (!string.IsNullOrWhiteSpace(UniteAuthToken)) + { + var uc = new ShiftOS.Unite.UniteClient("", UniteAuthToken); + uc.SetCodepoints(value); + } + else + _cp = value; + + } + } - public long Codepoints { get; set; } public Dictionary Upgrades { get; set; } public int StoryPosition { get; set; } public string Language { get; set; } diff --git a/ShiftOS.Objects/ShiftOS.Objects.csproj b/ShiftOS.Objects/ShiftOS.Objects.csproj index c2ef5ed..3c36d8c 100644 --- a/ShiftOS.Objects/ShiftOS.Objects.csproj +++ b/ShiftOS.Objects/ShiftOS.Objects.csproj @@ -56,6 +56,7 @@ + diff --git a/ShiftOS.Objects/UniteClient.cs b/ShiftOS.Objects/UniteClient.cs new file mode 100644 index 0000000..d8e34b7 --- /dev/null +++ b/ShiftOS.Objects/UniteClient.cs @@ -0,0 +1,236 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using ShiftOS.Objects; + +namespace ShiftOS.Unite +{ + public class UniteClient + { + /// + /// Gets a string represents the user token for this Unite Client. + /// + public string Token { get; private set; } + + /// + /// Gets the base URL used in all API calls. Retrieved from the user's servers.json file. + /// + public string BaseURL + { + get + { + return UserConfig.Get().UniteUrl; + } + } + + /// + /// Get the display name of a user. + /// + /// The user ID to look at. + /// + public string GetDisplayNameId(string id) + { + return MakeCall("/API/GetDisplayName/" + id); + } + + /// + /// Get the Pong highscore stats for all users. + /// + /// + public PongHighscoreModel GetPongHighscores() + { + return JsonConvert.DeserializeObject(MakeCall("/API/GetPongHighscores")); + } + + /// + /// Create a new instance of the object. + /// + /// Unused. + /// The user API token to use for this client (see http://getshiftos.ml/Manage and click "API" to see your tokens) + public UniteClient(string baseurl, string usertoken) + { + //Handled by the servers.json file + //BaseURL = baseurl; + Token = usertoken; + } + + /// + /// Make a call to the Unite API using the current user token and base URL. + /// + /// The path, relative to the base URL, to call. + /// The server's response. + internal string MakeCall(string url) + { + var webrequest = WebRequest.Create(BaseURL + url); + webrequest.Headers.Add("Authentication: Token " + Token); + using (var response = webrequest.GetResponse()) + { + using (var stream = response.GetResponseStream()) + { + using (var reader = new System.IO.StreamReader(stream)) + { + return reader.ReadToEnd(); + } + } + } + } + + /// + /// Get the Pong codepoint highscore for the current user. + /// + /// The amount of Codepoints returned by the server + public int GetPongCP() + { + return Convert.ToInt32(MakeCall("/API/GetPongCP")); + } + + /// + /// Get the pong highest level score for this user + /// + /// The highest level the user has reached. + public int GetPongLevel() + { + return Convert.ToInt32(MakeCall("/API/GetPongLevel")); + } + + /// + /// Set the user's highest level record for Pong. + /// + /// The level to set the record to. + public void SetPongLevel(int value) + { + MakeCall("/API/SetPongLevel/" + value.ToString()); + } + + /// + /// Set the pong Codepoints record for the user + /// + /// The amount of Codepoints to set the record to + public void SetPongCP(int value) + { + MakeCall("/API/SetPongCP/" + value.ToString()); + } + + /// + /// Get the user's email address. + /// + /// The user's email address. + public string GetEmail() + { + return MakeCall("/API/GetEmail"); + } + + /// + /// Get the user's system name. + /// + /// The user's system name. + public string GetSysName() + { + return MakeCall("/API/GetSysName"); + } + + /// + /// Set the user's system name. + /// + /// The system name to set the record to. + public void SetSysName(string value) + { + MakeCall("/API/SetSysName/" + value); + } + + /// + /// Get the user's display name. + /// + /// The user's display name. + public string GetDisplayName() + { + return MakeCall("/API/GetDisplayName"); + } + + /// + /// Set the user's display name. + /// + /// The display name to set the user's account to. + public void SetDisplayName(string value) + { + MakeCall("/API/SetDisplayName/" + value.ToString()); + } + + /// + /// Get the user's full name if they have set it in their profile. + /// + /// Empty string if the user hasn't set their fullname, else, a string representing their fullname. + public string GetFullName() + { + return MakeCall("/API/GetFullName"); + } + + /// + /// Set the user's fullname. + /// + /// The new fullname. + public void SetFullName(string value) + { + MakeCall("/API/SetFullName/" + value.ToString()); + } + + /// + /// Get the user's codepoints. + /// + /// The amount of codepoints stored on the server for this user. + public long GetCodepoints() + { + return Convert.ToInt64(MakeCall("/API/GetCodepoints")); + } + + /// + /// Set the user's codepoints. + /// + /// The amount of codepoints to set the user's codepoints value to. + public void SetCodepoints(long value) + { + MakeCall("/API/SetCodepoints/" + value.ToString()); + } + } + + /// + /// API data model for Unite pong highscores. + /// + public class PongHighscoreModel + { + /// + /// Amount of pages in this list. + /// + public int Pages { get; set; } + + /// + /// An array representing the highscores found on the server. + /// + public PongHighscore[] Highscores { get; set; } + } + + /// + /// API data model for a single Pong highscore. + /// + public class PongHighscore + { + /// + /// The user ID linked to this highscore. + /// + public string UserId { get; set; } + + /// + /// The highscore's level record. + /// + public int Level { get; set; } + + /// + /// The highscore's codepoint cashout record. + /// + public long CodepointsCashout { get; set; } + } +} diff --git a/ShiftOS_TheReturn/ShiftOS.Engine.csproj b/ShiftOS_TheReturn/ShiftOS.Engine.csproj index f0993a8..8b48023 100644 --- a/ShiftOS_TheReturn/ShiftOS.Engine.csproj +++ b/ShiftOS_TheReturn/ShiftOS.Engine.csproj @@ -132,7 +132,6 @@ - diff --git a/ShiftOS_TheReturn/UniteClient.cs b/ShiftOS_TheReturn/UniteClient.cs deleted file mode 100644 index d8e34b7..0000000 --- a/ShiftOS_TheReturn/UniteClient.cs +++ /dev/null @@ -1,236 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; -using ShiftOS.Objects; - -namespace ShiftOS.Unite -{ - public class UniteClient - { - /// - /// Gets a string represents the user token for this Unite Client. - /// - public string Token { get; private set; } - - /// - /// Gets the base URL used in all API calls. Retrieved from the user's servers.json file. - /// - public string BaseURL - { - get - { - return UserConfig.Get().UniteUrl; - } - } - - /// - /// Get the display name of a user. - /// - /// The user ID to look at. - /// - public string GetDisplayNameId(string id) - { - return MakeCall("/API/GetDisplayName/" + id); - } - - /// - /// Get the Pong highscore stats for all users. - /// - /// - public PongHighscoreModel GetPongHighscores() - { - return JsonConvert.DeserializeObject(MakeCall("/API/GetPongHighscores")); - } - - /// - /// Create a new instance of the object. - /// - /// Unused. - /// The user API token to use for this client (see http://getshiftos.ml/Manage and click "API" to see your tokens) - public UniteClient(string baseurl, string usertoken) - { - //Handled by the servers.json file - //BaseURL = baseurl; - Token = usertoken; - } - - /// - /// Make a call to the Unite API using the current user token and base URL. - /// - /// The path, relative to the base URL, to call. - /// The server's response. - internal string MakeCall(string url) - { - var webrequest = WebRequest.Create(BaseURL + url); - webrequest.Headers.Add("Authentication: Token " + Token); - using (var response = webrequest.GetResponse()) - { - using (var stream = response.GetResponseStream()) - { - using (var reader = new System.IO.StreamReader(stream)) - { - return reader.ReadToEnd(); - } - } - } - } - - /// - /// Get the Pong codepoint highscore for the current user. - /// - /// The amount of Codepoints returned by the server - public int GetPongCP() - { - return Convert.ToInt32(MakeCall("/API/GetPongCP")); - } - - /// - /// Get the pong highest level score for this user - /// - /// The highest level the user has reached. - public int GetPongLevel() - { - return Convert.ToInt32(MakeCall("/API/GetPongLevel")); - } - - /// - /// Set the user's highest level record for Pong. - /// - /// The level to set the record to. - public void SetPongLevel(int value) - { - MakeCall("/API/SetPongLevel/" + value.ToString()); - } - - /// - /// Set the pong Codepoints record for the user - /// - /// The amount of Codepoints to set the record to - public void SetPongCP(int value) - { - MakeCall("/API/SetPongCP/" + value.ToString()); - } - - /// - /// Get the user's email address. - /// - /// The user's email address. - public string GetEmail() - { - return MakeCall("/API/GetEmail"); - } - - /// - /// Get the user's system name. - /// - /// The user's system name. - public string GetSysName() - { - return MakeCall("/API/GetSysName"); - } - - /// - /// Set the user's system name. - /// - /// The system name to set the record to. - public void SetSysName(string value) - { - MakeCall("/API/SetSysName/" + value); - } - - /// - /// Get the user's display name. - /// - /// The user's display name. - public string GetDisplayName() - { - return MakeCall("/API/GetDisplayName"); - } - - /// - /// Set the user's display name. - /// - /// The display name to set the user's account to. - public void SetDisplayName(string value) - { - MakeCall("/API/SetDisplayName/" + value.ToString()); - } - - /// - /// Get the user's full name if they have set it in their profile. - /// - /// Empty string if the user hasn't set their fullname, else, a string representing their fullname. - public string GetFullName() - { - return MakeCall("/API/GetFullName"); - } - - /// - /// Set the user's fullname. - /// - /// The new fullname. - public void SetFullName(string value) - { - MakeCall("/API/SetFullName/" + value.ToString()); - } - - /// - /// Get the user's codepoints. - /// - /// The amount of codepoints stored on the server for this user. - public long GetCodepoints() - { - return Convert.ToInt64(MakeCall("/API/GetCodepoints")); - } - - /// - /// Set the user's codepoints. - /// - /// The amount of codepoints to set the user's codepoints value to. - public void SetCodepoints(long value) - { - MakeCall("/API/SetCodepoints/" + value.ToString()); - } - } - - /// - /// API data model for Unite pong highscores. - /// - public class PongHighscoreModel - { - /// - /// Amount of pages in this list. - /// - public int Pages { get; set; } - - /// - /// An array representing the highscores found on the server. - /// - public PongHighscore[] Highscores { get; set; } - } - - /// - /// API data model for a single Pong highscore. - /// - public class PongHighscore - { - /// - /// The user ID linked to this highscore. - /// - public string UserId { get; set; } - - /// - /// The highscore's level record. - /// - public int Level { get; set; } - - /// - /// The highscore's codepoint cashout record. - /// - public long CodepointsCashout { get; set; } - } -} -- cgit v1.2.3