From 6c220236ab45f3d2b024af676ffaa40fb46ae7da Mon Sep 17 00:00:00 2001 From: j502647092 Date: Fri, 31 Jul 2015 22:27:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=A4=96=E9=83=A8=E7=99=BB?= =?UTF-8?q?=E9=99=86=E6=8E=A5=E5=8F=A3...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CTZLauncher/CTZAuth/CTZAuth.cs | 42 ++ CTZLauncher/CTZAuth/ICTZAuth.cs | 19 + CTZLauncher/CTZLauncher.csproj | 2 + CTZLauncher/HttpHelper.cs | 24 +- CTZLauncher/MainWindow.xaml | 2 +- CTZLauncher/MainWindow.xaml.cs | 11 +- .../Authentication/AuthenticationInfo.cs | 4 +- .../Authentication/OfflineAuthenticator.cs | 138 +++--- KMCCC.Shared/Launcher/LauncherCoreInternal.cs | 432 +++++++++--------- KMCCC.Shared/Tools/UsefulTools.cs | 4 +- 10 files changed, 387 insertions(+), 291 deletions(-) create mode 100644 CTZLauncher/CTZAuth/CTZAuth.cs create mode 100644 CTZLauncher/CTZAuth/ICTZAuth.cs diff --git a/CTZLauncher/CTZAuth/CTZAuth.cs b/CTZLauncher/CTZAuth/CTZAuth.cs new file mode 100644 index 0000000..fa316d2 --- /dev/null +++ b/CTZLauncher/CTZAuth/CTZAuth.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows.Threading; +using CityCraft; +namespace CTZLauncher.CTZAuth +{ + class CTZAuth : ICTZAuth + { + HttpHelper http = new HttpHelper(); + string address; + string port; + public bool isRegister(string username) + { + return getResult(address + ":" + port + "/isregister?username=" + username); + } + + public bool Register(string username, string password) + { + return false; + } + + public bool isLogin(string username) + { + return getResult(address + ":" + port + "/islogin?username=" + username); + } + + public bool Login(string username, string password) + { + return false; + } + + public bool getResult(string url) + { + string result = http.Send(HttpMethod.GET, url); + if (result == "true") + return true; + return false; + } + } +} diff --git a/CTZLauncher/CTZAuth/ICTZAuth.cs b/CTZLauncher/CTZAuth/ICTZAuth.cs new file mode 100644 index 0000000..a9487d8 --- /dev/null +++ b/CTZLauncher/CTZAuth/ICTZAuth.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace CTZLauncher.CTZAuth +{ + interface ICTZAuth + { + public abstract bool isRegister(string username); + + public abstract bool Register(string username, string password); + + public abstract bool isLogin(string username); + + public abstract bool Login(string username, string password); + + } +} diff --git a/CTZLauncher/CTZLauncher.csproj b/CTZLauncher/CTZLauncher.csproj index 5ad845e..c749904 100644 --- a/CTZLauncher/CTZLauncher.csproj +++ b/CTZLauncher/CTZLauncher.csproj @@ -65,6 +65,8 @@ App.xaml Code + + MainWindow.xaml diff --git a/CTZLauncher/HttpHelper.cs b/CTZLauncher/HttpHelper.cs index 52d0ce9..ce42cf8 100644 --- a/CTZLauncher/HttpHelper.cs +++ b/CTZLauncher/HttpHelper.cs @@ -12,6 +12,7 @@ using System.Security.Cryptography.X509Certificates; using System.Text; using System.Text.RegularExpressions; using System.Threading; +using System.Windows.Threading; namespace CityCraft { @@ -60,12 +61,33 @@ namespace CityCraft /// 请求地址 /// Cookies存储器 /// 请求返回的Stream - public void Send(HttpMethod method, string url) + public string Send(HttpMethod method, string url, bool Async = false) { readyState = HttpReadyState.载入; ParseURL(url); args.Method = method; new Thread(new ThreadStart(ReciveData)).Start(); + if (!Async) + { + while (readyState != HttpReadyState.完成) { this.DoEvent(); } + return responseBody; + } + return string.Empty; + } + + /// + /// 模仿C#的Application.Doevent函数。可以适当添加try catch 模块 + /// + public void DoEvent() + { + DispatcherFrame frame = new DispatcherFrame(); + Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(ExitFrame), frame); + Dispatcher.PushFrame(frame); + } + public object ExitFrame(object f) + { + ((DispatcherFrame)f).Continue = false; + return null; } public void ReciveData() diff --git a/CTZLauncher/MainWindow.xaml b/CTZLauncher/MainWindow.xaml index e499b27..ba49efb 100644 --- a/CTZLauncher/MainWindow.xaml +++ b/CTZLauncher/MainWindow.xaml @@ -66,7 +66,7 @@