diff --git a/CTZLauncher/Authentication/CTZAuthenticator.cs b/CTZLauncher/Authentication/CTZAuthenticator.cs new file mode 100644 index 0000000..9c02b95 --- /dev/null +++ b/CTZLauncher/Authentication/CTZAuthenticator.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows.Threading; +using KMCCC.Authentication; +using CityCraft; +using System.Threading.Tasks; +using System.Threading; + +namespace KMCCC.Authentication +{ + class CTZAuthenticator + { + /// + /// 玩家的名字 + /// + public readonly string Username; + public readonly string Password; + HttpHelper http = new HttpHelper(); + /// + /// 验证服务器地址 + /// + public readonly string Address; + /// + /// 验证服务器端口 + /// + public readonly int Port; + /// + /// 构造离线验证器 + /// + /// 玩家的名字 + public CTZAuthenticator(string username, string password, string address, int port = 25565) + { + Username = username; + Password = password; + Address = address.IndexOf("http") > 0 ? address : "http://" + address; + Port = port; + } + + /// + /// 标注外部登陆验证器 + /// + public string Type + { + get { return "KMCCC.CTZ"; } + } + + public bool isRegistered() + { + return getResult(Address + ":" + Port + "/isregistered?username=" + Username); + } + + public bool Register() + { + return getResult(Address + ":" + Port + "/register?username=" + Username + "&password=" + Password); + } + + public bool isLogin() + { + return getResult(Address + ":" + Port + "/islogin?username=" + Username); + } + + public bool Login() + { + return getResult(Address + ":" + Port + "/login?username=" + Username + "&password=" + Password); + } + + public bool getResult(string url) + { + return http.Send(HttpMethod.GET, url) == "true" ? true : false; + } + } +}