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 @@