1
0
mirror of https://e.coding.net/circlecloud/CTZLauncher.git synced 2024-11-14 00:48:48 +00:00

添加外部服务器登录模块...

This commit is contained in:
j502647092 2015-08-03 20:57:03 +08:00
parent cb5b7ffd22
commit 79a53284b0

View File

@ -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
{
/// <summary>
/// 玩家的名字
/// </summary>
public readonly string Username;
public readonly string Password;
HttpHelper http = new HttpHelper();
/// <summary>
/// 验证服务器地址
/// </summary>
public readonly string Address;
/// <summary>
/// 验证服务器端口
/// </summary>
public readonly int Port;
/// <summary>
/// 构造离线验证器
/// </summary>
/// <param name="username">玩家的名字</param>
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;
}
/// <summary>
/// 标注外部登陆验证器
/// </summary>
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;
}
}
}