diff options
| author | Michael <[email protected]> | 2017-04-30 17:50:50 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-04-30 17:50:54 -0400 |
| commit | cdfba45faaa9202c69bdfe1a2f9e92140e0ecdae (patch) | |
| tree | 273464351e4bd65e60c083d4d35880fd43148dd3 /ShiftOS_TheReturn | |
| parent | 9a911c660feb1ef1177cc2bad002eb87004b6362 (diff) | |
| download | shiftos_thereturn-cdfba45faaa9202c69bdfe1a2f9e92140e0ecdae.tar.gz shiftos_thereturn-cdfba45faaa9202c69bdfe1a2f9e92140e0ecdae.tar.bz2 shiftos_thereturn-cdfba45faaa9202c69bdfe1a2f9e92140e0ecdae.zip | |
unite stuffs
Diffstat (limited to 'ShiftOS_TheReturn')
| -rw-r--r-- | ShiftOS_TheReturn/SaveSystem.cs | 7 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/ShiftOS.Engine.csproj | 2 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/UniteClient.cs | 68 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/UniteTestCommands.cs | 64 |
4 files changed, 136 insertions, 5 deletions
diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs index 3e68a70..4f4e9f5 100644 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ b/ShiftOS_TheReturn/SaveSystem.cs @@ -266,12 +266,9 @@ namespace ShiftOS.Engine { if (Utils.FileExists(Paths.GetPath("user.dat"))) { - var userdat = JsonConvert.DeserializeObject<ClientSave>(Utils.ReadAllText(Paths.GetPath("user.dat"))); + string token = Utils.ReadAllText(Paths.GetPath("user.dat")); - ServerManager.SendMessage("mud_login", $@"{{ - username: ""{userdat.Username}"", - password: ""{userdat.Password}"" -}}"); + ServerManager.SendMessage("mud_token_login", token); } else { diff --git a/ShiftOS_TheReturn/ShiftOS.Engine.csproj b/ShiftOS_TheReturn/ShiftOS.Engine.csproj index f7b730f..5cd6c68 100644 --- a/ShiftOS_TheReturn/ShiftOS.Engine.csproj +++ b/ShiftOS_TheReturn/ShiftOS.Engine.csproj @@ -131,6 +131,8 @@ <Compile Include="TerminalBackend.cs" /> <Compile Include="TerminalTextWriter.cs" /> <Compile Include="TutorialManager.cs" /> + <Compile Include="UniteClient.cs" /> + <Compile Include="UniteTestCommands.cs" /> <Compile Include="VirusEngine.cs" /> <Compile Include="WinOpenAttribute.cs" /> <EmbeddedResource Include="Infobox.resx"> diff --git a/ShiftOS_TheReturn/UniteClient.cs b/ShiftOS_TheReturn/UniteClient.cs new file mode 100644 index 0000000..8d9eef2 --- /dev/null +++ b/ShiftOS_TheReturn/UniteClient.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace ShiftOS.Unite +{ + public class UniteClient + { + public string Token { get; private set; } + public string BaseURL { get; private set; } + + public UniteClient(string baseurl, string usertoken) + { + BaseURL = baseurl; + Token = Token; + } + + 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(); + } + } + } + } + + public string GetDisplayName() + { + return MakeCall("/API/GetDisplayName"); + } + + public void SetDisplayName(string value) + { + MakeCall("/API/SetDisplayName/" + value.ToString()); + } + + public string GetFullName() + { + return MakeCall("/API/GetFullName"); + } + + public void SetFullName(string value) + { + MakeCall("/API/SetFullName/" + value.ToString()); + } + + + public long GetCodepoints() + { + return Convert.ToInt64(MakeCall("/API/GetCodepoints")); + } + + public void SetCodepoints(long value) + { + MakeCall("/API/SetCodepoints/" + value.ToString()); + } + } +} diff --git a/ShiftOS_TheReturn/UniteTestCommands.cs b/ShiftOS_TheReturn/UniteTestCommands.cs new file mode 100644 index 0000000..37ab1ee --- /dev/null +++ b/ShiftOS_TheReturn/UniteTestCommands.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace ShiftOS.Engine +{ + [Namespace("unite")] + public static class UniteTestCommands + { + [Command("login")] + [RequiresArgument("username")] + [RequiresArgument("password")] + public static bool LoginTest(Dictionary<string, object> args) + { + string u = args["username"].ToString(); + string p = args["password"].ToString(); + var webrequest = HttpWebRequest.Create("http://getshiftos.ml/Auth/Login?appname=ShiftOS&appdesc=ShiftOS+client&version=1_0_beta_2_4"); + string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{u}:{p}")); + webrequest.Headers.Add("Authentication: Basic " + base64); + var response = webrequest.GetResponse(); + var str = response.GetResponseStream(); + var reader = new System.IO.StreamReader(str); + string result = reader.ReadToEnd(); + Console.WriteLine("Server returned: " + result); + reader.Close(); + str.Close(); + str.Dispose(); + response.Dispose(); + + return true; + } + + [Command("linklogin")] + [RequiresArgument("username")] + [RequiresArgument("password")] + public static bool LinkLogin(Dictionary<string, object> args) + { + string u = args["username"].ToString(); + string p = args["password"].ToString(); + var webrequest = HttpWebRequest.Create("http://getshiftos.ml/Auth/Login?appname=ShiftOS&appdesc=ShiftOS+client&version=1_0_beta_2_4"); + string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{u}:{p}")); + webrequest.Headers.Add("Authentication: Basic " + base64); + var response = webrequest.GetResponse(); + var str = response.GetResponseStream(); + var reader = new System.IO.StreamReader(str); + string result = reader.ReadToEnd(); + //If we get this far, the token is OURS. :D + SaveSystem.CurrentSave.UniteAuthToken = result; + Console.WriteLine("Unite says \"Access Granted!\""); + SaveSystem.SaveGame(); + reader.Close(); + str.Close(); + str.Dispose(); + response.Dispose(); + + return true; + } + + + } +} |
