diff options
Diffstat (limited to 'ShiftOS.Objects')
| -rw-r--r-- | ShiftOS.Objects/ChatRoom.cs | 16 | ||||
| -rw-r--r-- | ShiftOS.Objects/ClientSave.cs | 9 | ||||
| -rw-r--r-- | ShiftOS.Objects/EngineShiftnetSubscription.cs | 17 | ||||
| -rw-r--r-- | ShiftOS.Objects/Legion.cs | 12 | ||||
| -rw-r--r-- | ShiftOS.Objects/MudAttributes.cs | 14 | ||||
| -rw-r--r-- | ShiftOS.Objects/Objects.cs | 4 | ||||
| -rw-r--r-- | ShiftOS.Objects/Reputation.cs | 65 | ||||
| -rw-r--r-- | ShiftOS.Objects/Save.cs | 54 | ||||
| -rw-r--r-- | ShiftOS.Objects/ShiftFS.cs | 115 | ||||
| -rw-r--r-- | ShiftOS.Objects/ShiftOS.Objects.csproj | 8 | ||||
| -rw-r--r-- | ShiftOS.Objects/ShiftOSMenuRenderer.cs | 51 | ||||
| -rw-r--r-- | ShiftOS.Objects/Unite/Download.cs | 22 | ||||
| -rw-r--r-- | ShiftOS.Objects/Unite/ReleaseQuery.cs | 15 | ||||
| -rw-r--r-- | ShiftOS.Objects/UniteClient.cs | 236 | ||||
| -rw-r--r-- | ShiftOS.Objects/UserConfig.cs | 37 |
15 files changed, 595 insertions, 80 deletions
diff --git a/ShiftOS.Objects/ChatRoom.cs b/ShiftOS.Objects/ChatRoom.cs new file mode 100644 index 0000000..e4c89ce --- /dev/null +++ b/ShiftOS.Objects/ChatRoom.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShiftOS.Objects +{ + public class ChatRoom + { + public string Id { get; set; } + public string Name { get; set; } + + public List<ChatMessage> Messages { get; set; } + } +} diff --git a/ShiftOS.Objects/ClientSave.cs b/ShiftOS.Objects/ClientSave.cs index edbb7dc..fbe1044 100644 --- a/ShiftOS.Objects/ClientSave.cs +++ b/ShiftOS.Objects/ClientSave.cs @@ -34,5 +34,14 @@ namespace ShiftOS.Objects { public string Username { get; set; } public string Password { get; set; } + public UserPermissions Permissions { get; set; } + } + + public enum UserPermissions + { + Root, + Admin, + User, + Guest } } diff --git a/ShiftOS.Objects/EngineShiftnetSubscription.cs b/ShiftOS.Objects/EngineShiftnetSubscription.cs new file mode 100644 index 0000000..1296a98 --- /dev/null +++ b/ShiftOS.Objects/EngineShiftnetSubscription.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShiftOS.Objects +{ + public class EngineShiftnetSubscription + { + public string Name { get; set; } + public string Description { get; set; } + public int CostPerMonth { get; set; } + public int DownloadSpeed { get; set; } + public string Company { get; set; } + } +} diff --git a/ShiftOS.Objects/Legion.cs b/ShiftOS.Objects/Legion.cs index c67a11d..c5e12f3 100644 --- a/ShiftOS.Objects/Legion.cs +++ b/ShiftOS.Objects/Legion.cs @@ -58,6 +58,16 @@ namespace ShiftOS.Objects public Dictionary<string, LegionRole> Roles { get; set; } public Dictionary<LegionRole, string> RoleNames { get; set; } - //Just adding a birbb in here + public UserClass Class { get; set; } + public double RawReputation { get; set; } + + public Reputation Reputation + { + get + { + return (Reputation)((int)Math.Round(RawReputation)); + } + } + } } diff --git a/ShiftOS.Objects/MudAttributes.cs b/ShiftOS.Objects/MudAttributes.cs index 1822356..d34c40e 100644 --- a/ShiftOS.Objects/MudAttributes.cs +++ b/ShiftOS.Objects/MudAttributes.cs @@ -1,4 +1,4 @@ -/* +/* * MIT License * * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs @@ -64,6 +64,18 @@ namespace ShiftOS.Objects public string ResponseName { get; private set; } } + public class ChatLogRequest + { + public ChatLogRequest(string chan, int backtrack = 0) + { + Channel = chan; + Backtrack = backtrack; + } + + public int Backtrack { get; set; } + public string Channel { get; set; } + } + } diff --git a/ShiftOS.Objects/Objects.cs b/ShiftOS.Objects/Objects.cs index 17f40ea..c4cd67c 100644 --- a/ShiftOS.Objects/Objects.cs +++ b/ShiftOS.Objects/Objects.cs @@ -96,6 +96,10 @@ namespace ShiftOS.Objects //Don't describe this one. We want it to be hidden from the admin panel's chat editor. public string ID { get; set; } + [FriendlyName("Requires Patreon?")] + [FriendlyDescription("If checked, this chat will only be shown in the MUD Control Centre if the user's save is marked as a Patreon supporter.")] + public bool RequiresPatreon { get; set; } + [FriendlyName("Chat topic")] [FriendlyDescription("A more in-depth version of your chat name. Describe what your chat's about in a sentence.")] public string Topic { get; set; } diff --git a/ShiftOS.Objects/Reputation.cs b/ShiftOS.Objects/Reputation.cs new file mode 100644 index 0000000..0ddea0a --- /dev/null +++ b/ShiftOS.Objects/Reputation.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShiftOS.Objects +{ + public enum Reputation + { + Saint = 5, + Moral = 4, + Trustworthy = 3, + WellKnown = 2, + Respected = 1, + Neutral = 0, + Disrespected = -1, + Criminal = -2, + Untrustworthy = -3, + Immoral = -4, + Outcast = -5 + } + + public enum UserClass + { + /// <summary> + /// The user has no class. + /// </summary> + None = 0, + + /// <summary> + /// Skinners, otherwise known as "Shifters" due to their excessive use of the Shifter application, like to customize ShiftOS to look like other operating systems or even have an entirely different UI. They gain heaps of codepoints from it, and like to sell their skins for even more Codepoints. + /// </summary> + Skinner = 1, + + /// <summary> + /// Hackers are notorious for taking down large groups and individuals of which have many useful documents and Codepoints on their system. Hackers enjoy the rush of typing malicious commands into their terminals and seeing how they affect their target. + /// </summary> + Hacker = 2, + /// <summary> + /// Much like hackers, investigators are skilled with a terminal and breaching systems, but they don't do it directly for monetary gain. They will search a target's system for any files and clues that may lead to them being guilty of a crime within the digital society. Unlike Hackers, Investigators mostly have higher reputations in society, and go after those with lower reputations. + /// </summary> + Investigator = 3, + /// <summary> + /// Explorers like to venture the vast regions of the multi-user domain and Shiftnet looking for secrets, hidden tools and software, and finding the hidden truths behind their screen. Explorers don't always know how to hack, but if it involves finding a secret about ShiftOS, they will do it. They typically do not have malicious intent. + /// </summary> + Explorer = 4, + /// <summary> + /// Safety Activists are skilled with exploitation and hacking, but they only go after the worst there is in the multi-user domain. Crime rings, large hacker groups, you name it. Their primary goal is keeping the multi-user domain safe. + /// </summary> + SafetyActivist = 5, + /// <summary> + /// Penetration testers go hand-in-hand with Safety Activists. They go after the good guys, but rather than attacking them, they alert them that an exploit was found in their service and that this exploit should be fixed. They are a gray subject though - you never know if you are dealing with a genuine pen-tester or a hacker skilled with social engineering. Be careful. + /// </summary> + PenetrationTester = 6, + /// <summary> + /// Collectors go well with Explorers - however, Collectors are the ones who open shops. They like to find rare objects and sell them for Codepoints. + /// </summary> + Collector = 7, + /// <summary> + /// Programmers are the ones who write applications and services for ShiftOS and the multi-user domain. Depending on the code that they write, they can be seen as either morally wrong sentiences or morally correct sentiences, it's up to their decisions. + /// </summary> + Programmer = 8 + } +} diff --git a/ShiftOS.Objects/Save.cs b/ShiftOS.Objects/Save.cs index 3c7cb39..f4e1e09 100644 --- a/ShiftOS.Objects/Save.cs +++ b/ShiftOS.Objects/Save.cs @@ -34,8 +34,40 @@ namespace ShiftOS.Objects //Better to store this stuff server-side so we can do some neat stuff with hacking... public class Save { + + public int MusicVolume { get; set; } + public int SfxVolume { get; set; } + + [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; } - public long Codepoints { 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 Dictionary<string, bool> Upgrades { get; set; } public int StoryPosition { get; set; } public string Language { get; set; } @@ -45,6 +77,21 @@ namespace ShiftOS.Objects public int MinorVersion { get; set; } public int Revision { get; set; } + public string UniteAuthToken { get; set; } + + public bool IsPatreon { get; set; } + + public UserClass Class { get; set; } + public double RawReputation { get; set; } + + public Reputation Reputation + { + get + { + return (Reputation)((int)Math.Round(RawReputation)); + } + } + public string Password { get; set; } public bool PasswordHashed { get; set; } public string SystemName { get; set; } @@ -65,6 +112,9 @@ namespace ShiftOS.Objects } } + public int LastMonthPaid { get; set; } + public List<string> StoriesExperienced { get; set; } + public int CountUpgrades() { int count = 0; @@ -75,6 +125,8 @@ namespace ShiftOS.Objects } return count; } + + public List<ClientSave> Users { get; set; } } public class SettingsObject : DynamicObject diff --git a/ShiftOS.Objects/ShiftFS.cs b/ShiftOS.Objects/ShiftFS.cs index e14c2a8..45cdb14 100644 --- a/ShiftOS.Objects/ShiftFS.cs +++ b/ShiftOS.Objects/ShiftFS.cs @@ -32,23 +32,16 @@ using System.Threading; namespace ShiftOS.Objects.ShiftFS { - public enum Permissions - { - User, - Administrator, - Superuser, - All - } public class File { public string Name; public byte[] Data; public byte[] HeaderData; public bool ReadAccessToLowUsers; - public Permissions permissions; + public UserPermissions permissions; public System.IO.Stream GetStream() { - if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All) + if ((int)CurrentUser <= (int)permissions) { return new System.IO.MemoryStream(Data); } @@ -59,7 +52,7 @@ namespace ShiftOS.Objects.ShiftFS return null; } - public File(string name, byte[] data, bool ReadAccess_to_low_users, Permissions perm) + public File(string name, byte[] data, bool ReadAccess_to_low_users, UserPermissions perm) { Name = name; Data = data; @@ -73,31 +66,31 @@ namespace ShiftOS.Objects.ShiftFS public List<File> Files = new List<File>(); public List<Directory> Subdirectories = new List<Directory>(); public bool ReadAccessToLowUsers; - public Permissions permissions; + public UserPermissions permissions; public void AddFile(File file) { - if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All) + if ((int)CurrentUser <= (int)permissions) { Files.Add(file); } } public void RemoveFile(string name) { - if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All) + if ((int)CurrentUser <= (int)permissions) { Files.Remove(Files.Find(x => x.Name == name)); } } public void RemoveFile(File file) { - if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All) + if ((int)CurrentUser <= (int)permissions) { Files.Remove(file); } } public File FindFileByName(string name) { - if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All) + if ((int)CurrentUser <= (int)permissions) { return Files.Find(x => x.Name == name); } @@ -105,28 +98,28 @@ namespace ShiftOS.Objects.ShiftFS } public void AddDirectory(Directory dir) { - if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All) + if ((int)CurrentUser <= (int)permissions) { Subdirectories.Add(dir); } } public void RemoveDirectory(string name) { - if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All) + if ((int)CurrentUser <= (int)permissions) { Subdirectories.Remove(Subdirectories.Find(x => x.Name == name)); } } public void RemoveDirectory(Directory dir) { - if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All) + if ((int)CurrentUser <= (int)permissions) { Subdirectories.Remove(dir); } } public Directory FindDirectoryByName(string name) { - if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All) + if ((int)CurrentUser <= (int)permissions) { return Subdirectories.Find(x => x.Name == name); } @@ -136,7 +129,7 @@ namespace ShiftOS.Objects.ShiftFS public static class Utils { - public static Permissions CurrentUser { get; set; } + public static UserPermissions CurrentUser { get; set; } public static List<Directory> Mounts { get; set; } @@ -173,6 +166,11 @@ namespace ShiftOS.Objects.ShiftFS t.Start(); } + public static event Action<string> DirectoryCreated; + public static event Action<string> DirectoryDeleted; + public static event Action<string> FileWritten; + public static event Action<string> FileDeleted; + public static void CreateDirectory(string path) { @@ -190,6 +188,7 @@ namespace ShiftOS.Objects.ShiftFS Name = pathlist[pathlist.Length - 1], permissions = CurrentUser, }); + DirectoryCreated?.Invoke(path); } else { @@ -224,14 +223,18 @@ namespace ShiftOS.Objects.ShiftFS if (!FileExists(path)) { - dir.AddFile(new File(pathlist[pathlist.Length - 1], Encoding.UTF8.GetBytes(contents), false, Permissions.All)); + try + { + dir.AddFile(new File(pathlist[pathlist.Length - 1], Encoding.UTF8.GetBytes(contents), false, CurrentUser)); + } + catch { } } else { var f = dir.FindFileByName(pathlist[pathlist.Length - 1]); f.Data = Encoding.UTF8.GetBytes(contents); } - + FileWritten?.Invoke(path); } @@ -248,10 +251,12 @@ namespace ShiftOS.Objects.ShiftFS if (FileExists(path)) { dir.RemoveFile(pathlist[pathlist.Length - 1]); + FileDeleted?.Invoke(path); } else { dir.RemoveDirectory(pathlist[pathlist.Length - 1]); + DirectoryDeleted?.Invoke(path); } } @@ -269,14 +274,14 @@ namespace ShiftOS.Objects.ShiftFS if (!FileExists(path)) { - dir.AddFile(new File(pathlist[pathlist.Length - 1], contents, false, Permissions.All)); + dir.AddFile(new File(pathlist[pathlist.Length - 1], contents, false, CurrentUser)); } else { var f = dir.FindFileByName(pathlist[pathlist.Length - 1]); f.Data = contents; } - + FileWritten?.Invoke(path); } @@ -291,10 +296,13 @@ namespace ShiftOS.Objects.ShiftFS { string[] pathlist = path.Split('/'); int vol = Convert.ToInt32(pathlist[0].Replace(":", "")); + if (Mounts[vol] == null) + Mounts[vol] = new Directory(); var dir = Mounts[vol]; + for (int i = 1; i <= pathlist.Length - 1; i++) { - dir = dir.FindDirectoryByName(pathlist[i]); + dir = dir?.FindDirectoryByName(pathlist[i]); } return dir != null; @@ -390,6 +398,63 @@ namespace ShiftOS.Objects.ShiftFS return paths.ToArray(); } + /// <summary> + /// Copies a file or directory from one path to another, deleting the original. + /// </summary> + /// <param name="path">THe input path, must be a valid directory or file.</param> + /// <param name="target">The output path.</param> + public static void Move(string path, string target) + { + if (FileExists(path)) + { + WriteAllBytes(target, ReadAllBytes(path)); + Delete(path); + } + else if (DirectoryExists(path)) + { + if (!DirectoryExists(target)) + CreateDirectory(target); + foreach (var file in GetFiles(path)) + { + var name = GetFileInfo(file).Name; + Copy(file, target + "/" + name); + } + foreach (var dir in GetDirectories(path)) + { + string name = GetDirectoryInfo(dir).Name; + Copy(dir, target + "/" + name); + } + Delete(path); + } + } + + + /// <summary> + /// Copies a file or directory from one path to another. + /// </summary> + /// <param name="path">The input path, must be a valid directory or file.</param> + /// <param name="target">The output path.</param> + public static void Copy(string path, string target) + { + if (FileExists(path)) + WriteAllBytes(target, ReadAllBytes(path)); + else if (DirectoryExists(path)) + { + if (!DirectoryExists(target)) + CreateDirectory(target); + foreach(var file in GetFiles(path)) + { + var name = GetFileInfo(file).Name; + Copy(file, target + "/" + name); + } + foreach(var dir in GetDirectories(path)) + { + string name = GetDirectoryInfo(dir).Name; + Copy(dir, target + "/" + name); + } + } + } + public static string[] GetFiles(string path) { string[] pathlist = path.Split('/'); diff --git a/ShiftOS.Objects/ShiftOS.Objects.csproj b/ShiftOS.Objects/ShiftOS.Objects.csproj index 484f9df..9ed8c3b 100644 --- a/ShiftOS.Objects/ShiftOS.Objects.csproj +++ b/ShiftOS.Objects/ShiftOS.Objects.csproj @@ -45,16 +45,22 @@ <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> + <Compile Include="ChatRoom.cs" /> <Compile Include="ClientSave.cs" /> + <Compile Include="EngineShiftnetSubscription.cs" /> <Compile Include="Job.cs" /> <Compile Include="Legion.cs" /> <Compile Include="MudAttributes.cs" /> <Compile Include="Objects.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="Reputation.cs" /> <Compile Include="Save.cs" /> <Compile Include="ShiftFS.cs" /> - <Compile Include="ShiftOSMenuRenderer.cs" /> <Compile Include="Shop.cs" /> + <Compile Include="UniteClient.cs" /> + <Compile Include="Unite\Download.cs" /> + <Compile Include="Unite\ReleaseQuery.cs" /> + <Compile Include="UserConfig.cs" /> </ItemGroup> <ItemGroup> <None Include="packages.config" /> diff --git a/ShiftOS.Objects/ShiftOSMenuRenderer.cs b/ShiftOS.Objects/ShiftOSMenuRenderer.cs deleted file mode 100644 index c76bd35..0000000 --- a/ShiftOS.Objects/ShiftOSMenuRenderer.cs +++ /dev/null @@ -1,51 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace ShiftOS.Objects -{ - class ShiftOSMenuRenderer : ToolStripProfessionalRenderer - { - public ShiftOSMenuRenderer() : base(new ShiftOSColorTable()) - { - - } - - protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e) - { - - } - } - - public class ShiftOSColorTable : ProfessionalColorTable - { - - } -} diff --git a/ShiftOS.Objects/Unite/Download.cs b/ShiftOS.Objects/Unite/Download.cs new file mode 100644 index 0000000..089a98c --- /dev/null +++ b/ShiftOS.Objects/Unite/Download.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShiftOS.Objects.Unite +{ + public class Download + { + public string Id { get; set; } + public string Name { get; set; } + public string Changelog { get; set; } + public string DownloadUrl { get; set; } + public bool Obsolete { get; set; } + public DateTime PostDate { get; set; } + public string ReleasedBy { get; set; } + public string DevUpdateId { get; set; } + public string ScreenshotUrl { get; set; } + public bool IsStable { get; set; } + } +} diff --git a/ShiftOS.Objects/Unite/ReleaseQuery.cs b/ShiftOS.Objects/Unite/ReleaseQuery.cs new file mode 100644 index 0000000..253ce57 --- /dev/null +++ b/ShiftOS.Objects/Unite/ReleaseQuery.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShiftOS.Objects.Unite +{ + public class ReleaseQuery + { + public bool ShowUnstable { get; set; } + public bool ShowObsolete { get; set; } + public DateTime CurrentBuildDate { get; set; } + } +} 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 + { + /// <summary> + /// Gets a string represents the user token for this Unite Client. + /// </summary> + public string Token { get; private set; } + + /// <summary> + /// Gets the base URL used in all API calls. Retrieved from the user's servers.json file. + /// </summary> + public string BaseURL + { + get + { + return UserConfig.Get().UniteUrl; + } + } + + /// <summary> + /// Get the display name of a user. + /// </summary> + /// <param name="id">The user ID to look at.</param> + /// <returns></returns> + public string GetDisplayNameId(string id) + { + return MakeCall("/API/GetDisplayName/" + id); + } + + /// <summary> + /// Get the Pong highscore stats for all users. + /// </summary> + /// <returns></returns> + public PongHighscoreModel GetPongHighscores() + { + return JsonConvert.DeserializeObject<PongHighscoreModel>(MakeCall("/API/GetPongHighscores")); + } + + /// <summary> + /// Create a new instance of the <see cref="UniteClient"/> object. + /// </summary> + /// <param name="baseurl">Unused.</param> + /// <param name="usertoken">The user API token to use for this client (see http://getshiftos.ml/Manage and click "API" to see your tokens)</param> + public UniteClient(string baseurl, string usertoken) + { + //Handled by the servers.json file + //BaseURL = baseurl; + Token = usertoken; + } + + /// <summary> + /// Make a call to the Unite API using the current user token and base URL. + /// </summary> + /// <param name="url">The path, relative to the base URL, to call.</param> + /// <returns>The server's response.</returns> + 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(); + } + } + } + } + + /// <summary> + /// Get the Pong codepoint highscore for the current user. + /// </summary> + /// <returns>The amount of Codepoints returned by the server</returns> + public int GetPongCP() + { + return Convert.ToInt32(MakeCall("/API/GetPongCP")); + } + + /// <summary> + /// Get the pong highest level score for this user + /// </summary> + /// <returns>The highest level the user has reached.</returns> + public int GetPongLevel() + { + return Convert.ToInt32(MakeCall("/API/GetPongLevel")); + } + + /// <summary> + /// Set the user's highest level record for Pong. + /// </summary> + /// <param name="value">The level to set the record to.</param> + public void SetPongLevel(int value) + { + MakeCall("/API/SetPongLevel/" + value.ToString()); + } + + /// <summary> + /// Set the pong Codepoints record for the user + /// </summary> + /// <param name="value">The amount of Codepoints to set the record to</param> + public void SetPongCP(int value) + { + MakeCall("/API/SetPongCP/" + value.ToString()); + } + + /// <summary> + /// Get the user's email address. + /// </summary> + /// <returns>The user's email address.</returns> + public string GetEmail() + { + return MakeCall("/API/GetEmail"); + } + + /// <summary> + /// Get the user's system name. + /// </summary> + /// <returns>The user's system name.</returns> + public string GetSysName() + { + return MakeCall("/API/GetSysName"); + } + + /// <summary> + /// Set the user's system name. + /// </summary> + /// <param name="value">The system name to set the record to.</param> + public void SetSysName(string value) + { + MakeCall("/API/SetSysName/" + value); + } + + /// <summary> + /// Get the user's display name. + /// </summary> + /// <returns>The user's display name.</returns> + public string GetDisplayName() + { + return MakeCall("/API/GetDisplayName"); + } + + /// <summary> + /// Set the user's display name. + /// </summary> + /// <param name="value">The display name to set the user's account to.</param> + public void SetDisplayName(string value) + { + MakeCall("/API/SetDisplayName/" + value.ToString()); + } + + /// <summary> + /// Get the user's full name if they have set it in their profile. + /// </summary> + /// <returns>Empty string if the user hasn't set their fullname, else, a string representing their fullname.</returns> + public string GetFullName() + { + return MakeCall("/API/GetFullName"); + } + + /// <summary> + /// Set the user's fullname. + /// </summary> + /// <param name="value">The new fullname.</param> + public void SetFullName(string value) + { + MakeCall("/API/SetFullName/" + value.ToString()); + } + + /// <summary> + /// Get the user's codepoints. + /// </summary> + /// <returns>The amount of codepoints stored on the server for this user.</returns> + public long GetCodepoints() + { + return Convert.ToInt64(MakeCall("/API/GetCodepoints")); + } + + /// <summary> + /// Set the user's codepoints. + /// </summary> + /// <param name="value">The amount of codepoints to set the user's codepoints value to.</param> + public void SetCodepoints(long value) + { + MakeCall("/API/SetCodepoints/" + value.ToString()); + } + } + + /// <summary> + /// API data model for Unite pong highscores. + /// </summary> + public class PongHighscoreModel + { + /// <summary> + /// Amount of pages in this list. + /// </summary> + public int Pages { get; set; } + + /// <summary> + /// An array representing the highscores found on the server. + /// </summary> + public PongHighscore[] Highscores { get; set; } + } + + /// <summary> + /// API data model for a single Pong highscore. + /// </summary> + public class PongHighscore + { + /// <summary> + /// The user ID linked to this highscore. + /// </summary> + public string UserId { get; set; } + + /// <summary> + /// The highscore's level record. + /// </summary> + public int Level { get; set; } + + /// <summary> + /// The highscore's codepoint cashout record. + /// </summary> + public long CodepointsCashout { get; set; } + } +} diff --git a/ShiftOS.Objects/UserConfig.cs b/ShiftOS.Objects/UserConfig.cs new file mode 100644 index 0000000..61d11b8 --- /dev/null +++ b/ShiftOS.Objects/UserConfig.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace ShiftOS.Objects +{ + public class UserConfig + { + public string UniteUrl { get; set; } + public string DigitalSocietyAddress { get; set; } + public int DigitalSocietyPort { get; set; } + + public static UserConfig Get() + { + var conf = new UserConfig + { + UniteUrl = "http://getshiftos.ml", + DigitalSocietyAddress = "michaeltheshifter.me", + DigitalSocietyPort = 13370 + }; + + if (!File.Exists("servers.json")) + { + File.WriteAllText("servers.json", JsonConvert.SerializeObject(conf, Formatting.Indented)); + } + else + { + conf = JsonConvert.DeserializeObject<UserConfig>(File.ReadAllText("servers.json")); + } + return conf; + } + } +} |
