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 string getServerList() { string sl = http.Send(HttpMethod.GET, Address + ":" + Port + "/serverlist"); if (string.IsNullOrEmpty(sl)) throw new ArgumentNullException("服务器返回了空的字符串或网络连接异常!"); return sl; } public bool getResult(string url) { string result = http.Send(HttpMethod.GET, url); if (string.IsNullOrEmpty(result)) throw new ArgumentNullException("服务器返回了空的字符串或网络连接异常!"); return result.Contains("true") ? true : false; } } }