custom-mojang-auth
一个小型库,允许你的模组使用玩家的 Mojang 账户自动登录到你的自定义服务器。
适用于任何 Minecraft 版本。
此模组使服务器能够可靠地识别玩家,并有助于执行封禁和防止身份盗用。
MCSR Ranked 使用了此库。
用法
客户端
在你的模组初始化时设置 Authenticator:
String accessToken;
UUID uuid;
java.net.Proxy proxy;
String messagePrefix //可选
ClientAuth.initialize(accessToken, uuid, proxy, messagePrefix);
获取 accessToken、uuid 和 proxy 的方式取决于 Minecraft 版本。
获取玩家的 uuid 相当简单,通常可以通过以下方式找到:
UUID uuid = net.minecraft.client.MinecraftClient.getInstance().getSession().getProfile().getId(); //1.16.1
或者
UUID uuid = net.minecraft.client.MinecraftClient.getInstance().getSession().getUuidOrNull(); //1.20.2
获取 accessToken 也相对容易:
String accessToken= net.minecraft.client.MinecraftClient.getInstance().getSession().getAccessToken();
获取 proxy 可能会稍微困难一些。
在我所知的每个版本中,它都在 net.minecraft.client.main.Main.main(String args[]) 中初始化。只需从那里跟踪 Proxy 对象,
通常它会传递给 net.minecraft.client.MinecraftClient 构造函数,然后找到一个可以轻松获取它的位置,无论是通过方法调用、反射、mixin 等。
在 1.20.2 中,可以通过以下方式获取 proxy:
Field field =net.minecraft.client.MinecraftClient.class.getField("authenticationService");
field.setAccessible(true);
java.net.Proxy proxy =((com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService)field.get(net.minecraft.client.MinecraftClient.getInstance())).getProxy();
在 1.16.1 中,可以通过以下方式获取 proxy:
java.net.Proxy proxy = ((com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService)net.minecraft.client.MinecraftClient.getInstance().getSessionService()).getAuthenticationService().getProxy();
如果你需要帮助定位你版本中的任何字段,欢迎在 Discord 上私信我:void_x_walker
服务端
安装该库:
npm install custom-mojang-auth
使用以下函数来验证载荷是否由客户端签名。
function isValid(uuid, randomLong, data, date, publicKeyString, signatureBytes, payload)
其中 payload 是一个数组。
隐私
客户端仅使用其私钥对消息进行签名,然后可以将其发送到服务器。没有任何登录信息或其他敏感信息离开客户端机器。
custom-mojang-auth
A small library that allows your mod to automatically sign in to your custom server using the players mojang account.
Works for any minecraft version.
This mod allows a server to reliably identify a player and helps enforcing bans and prevents identity theft.
MCSR Ranked uses this library.
Usage
Client
In your mod initialize the Authenticator:
String accessToken;
UUID uuid;
java.net.Proxy proxy;
String messagePrefix //optional
ClientAuth.initialize(accessToken, uuid, proxy, messagePrefix);
The way accessToken, uuid and proxy are obtained depends on the Minecraft Version.
Obtaining the uuid of the player is pretty trivial, it can usually be found this way:
UUID uuid = net.minecraft.client.MinecraftClient.getInstance().getSession().getProfile().getId(); //1.16.1
or
UUID uuid = net.minecraft.client.MinecraftClient.getInstance().getSession().getUuidOrNull(); //1.20.2
Obtaining the accessToken is relatively easy as well:
String accessToken= net.minecraft.client.MinecraftClient.getInstance().getSession().getAccessToken();
Obtaining the proxy can be a bit more difficult.
In every version that I know of it is initialized in net.minecraft.client.mainmMian.main(String args[]). Just follow the Proxy object from here,
usually it's given to the net.minecraft.client.MinecraftClient constructor, and find a place where you can easily obtain it either via a method call, reflection, a mixin etc
In 1.20.2 the proxy can be obtained this way:
Field field =net.minecraft.client.MinecraftClient.class.getField("authenticationService");
field.setAccessible(true);
java.net.Proxy proxy =((com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService)field.get(net.minecraft.client.MinecraftClient.getInstance())).getProxy();
In 1.16.1 the proxy can be obtained this way:
java.net.Proxy proxy = ((com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService)net.minecraft.client.MinecraftClient.getInstance().getSessionService()).getAuthenticationService().getProxy();
If you need help locating any of the fields for your version, feel free to dm me on discord: void_x_walker
Server
Install the library:
npm install custom-mojang-auth
use the following function to verify that a payload has been signed by the client.
function isValid(uuid, randomLong, data, date, publicKeyString, signatureBytes, payload)
where payload is an array.
Privacy
The client simply signs messages using its private key, which can then be send to a server. No login information, or other compromising information ever leaves the client's machine.
评论 0
登录后参与评分
还没有评论,来抢沙发吧