4

关于 Minecraft 的正版验证

 3 years ago
source link: https://ipotato.me/article/3
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

关于 Minecraft 的正版验证

2013-08-17

最近用C#写了个Minecraft的启动器,基本功能都有,但是各种坑,代码也很乱,打算重构。重要的一些东西,就记在博客里了。

首先说一下Minecraft的正版验证的原理,官方有一个专门验证帐号和密码的URL

https://login.minecraft.net/?user=帐号&password=密码&version=13

比如说我的账号是[email protected] 密码是XXOO 我们就可以向Mojang的服务器发起一个post请求

https://login.minecraft.net/[email protected]&password=XXOO&version=13

可以利用C#的System.NetSystem.IO命名空间,在导入之后,利用以下代码向服务器发起请求。

string username = "[email protected]";
string password = "XXOO";
string url = "https://login.minecraft.net/?user=" + username + "&password=" + password + "&version=13";

WebClient Login = new WebClient();
Stream data = Login.OpenRead(url);
StreamReader LoginResult = new StreamReader(data);
string s = reader.ReadToEnd();
data.Close();
reader.Close();

于是,我们就可以得到服务器返回的一个结果,如果帐号和密码正确,会得到以下字段。但如果登录失败,会返回Bad Login字段,这时就可以提醒用户账户或密码错误。

一段数字:deprecated:游戏名称:密码的md5值

这时,我们就可以利用C#的字符串的截取功能,利用字符串中的:将我们需要的用户名和密码的md5值截取下来。

string[] LoginParameter = s.Split(':');
result = "\"" + LoginParameter[2] + "\" \"" + LoginParameter[3] + "\"";

在启动时将变量result的内容附加到启动参数后面,便可以实现正版启动了。


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK