Вход без пароля, права админа и F3+B

Аутентификация переделана по схеме пользователя: лаунчер — единственный
источник токена, сервер проверяет его сам и лаунчера не спрашивает.

- rsx-auth/GameToken: токен это base64url(payload) + "." + base64url(HMAC-SHA256),
  payload {uuid, nick, aud, exp, jti, typ}, typ = session или reload.
- Сессия живёт час, reload-токен полтора часа и только внутри игры. Пакет
  SessionReload продлевает сессию и выдаёт новый reload-токен.
- Сервер проверяет подпись, аудиенс, срок и совпадение uuid. HTTP-запрос к
  лаунчеру из сервера убран.
- Клиент: окно пароля убрано совсем, ник берётся из токена, клиент сам
  продлевает сессию за 5 минут до конца.
- Для локальной разработки сервер с --dev-token пишет свой токен в
  world/dev-token.txt, клиент берёт токен оттуда.
- Права админа: свой список world/admins.txt, перечитывается раз в 5 секунд,
  поэтому право снимается на лету. Пакет AdminState.
- Ванильные блоки мира ломает только админ, режим игры прав не даёт.
- F3+B только для админов: без прав показываем отказ, с правом включаются и
  ванильные хитбоксы, и наш отладочный рендер. Права сняли посреди просмотра —
  гаснут сразу.
- run-game.ps1 умеет -Token.

Проверено на живом сервере: own session ok, player in, rights of Player given.
Тесты: протокол 34, сервер 88, форк собирается чисто.
This commit is contained in:
sasheg dev committed 2026-10-22 08:51:27 +03:00
1 parent cf90f71e58
commit d2a0a7a93b
21 files changed
+1478 -543

No files matched your search

@@ -6,55 +6,43 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiDisconnected;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.util.text.TextComponentTranslation;
import net.rustnotmc.client.gui.RsxPasswordField;
import net.rustnotmc.auth.GameToken;
import net.rustnotmc.client.net.RsxNetworkManager;
import net.rustnotmc.client.net.RsxWorldBridge;
/**
* The screen that gets the player into a server.
*
* The launcher is where accounts live, so the launcher signs the player in and
* hands the game a token. This screen then has nothing to ask: it takes the
* token out of the session the launcher built and offers it to the server.
* There is nothing to fill in here. The launcher asked the auth server
* whether the player may play, and when the answer was yes it gave the game a
* token and a uuid. The game shows both to the server, the server checks them
* itself, and the player is in.
*
* When the game was started without a launcher there is no session and
* somebody has to say who they are, so the screen asks for a name and a
* password. That is the way in for a server of our own and the way in for
* development; a server with a launcher in front of it does not accept it.
*
* This replaces the game's own connecting screen, which is where the player
* already is when they press "join server", so the flow stays the one they
* know.
* So this screen has no account field and no password field: a password is
* something the launcher knows, not something the game asks for. All it does
* is open the socket and say what is happening.
*/
public class GuiConnecting extends GuiScreen {
/** What the launcher leaves in the session when nobody signed in. */
private static final String NO_TOKEN = "0";
private final GuiScreen previousGuiScreen;
private final String host;
private final int port;
private final GuiScreen previousGuiScreen;
private GuiTextField accountField;
private RsxPasswordField passwordField;
private RsxNetworkManager networkManager;
private volatile String status = "";
/** The launcher's session, if the game was started by the launcher. */
private String launcherAccount;
private String launcherUuid;
private String launcherToken;
private String launcherAccount = "";
private String launcherUuid = "";
private String launcherToken = "";
private String status = "";
public GuiConnecting(GuiScreen guiscreen, Minecraft minecraft, ServerData serverdata) {
this.mc = minecraft;
this.previousGuiScreen = guiscreen;
ServerAddress serveraddress = ServerAddress.fromString(serverdata.serverIP);
minecraft.loadWorld((WorldClient) null);
minecraft.setServerData(serverdata);
this.host = serveraddress.getIP();
this.port = serveraddress.getPort();
this(guiscreen, minecraft, ServerAddress.fromString(serverdata.serverIP));
}
public GuiConnecting(GuiScreen guiscreen, Minecraft minecraft, ServerAddress address) {
this(guiscreen, minecraft, address.getIP(), address.getPort());
}
public GuiConnecting(GuiScreen guiscreen, Minecraft minecraft, String s, int i) {
@@ -68,34 +56,18 @@ public class GuiConnecting extends GuiScreen {
public void initGui() {
this.buttonList.clear();
// The launcher built the session: the name, the identity and the token.
this.launcherAccount = sessionValue(this.mc, 0);
this.launcherUuid = sessionValue(this.mc, 1);
this.launcherToken = sessionValue(this.mc, 2);
this.accountField = new GuiTextField(0, this.fontRenderer, this.width / 2 - 100,
this.height / 4 + 20, 200, 20);
this.accountField.setMaxStringLength(32);
this.accountField.setText(this.launcherAccount == null
? this.mc.getSession().getProfile().getName() : this.launcherAccount);
this.passwordField = new RsxPasswordField(1, this.fontRenderer, this.width / 2 - 100,
this.height / 4 + 50, 200, 20);
this.passwordField.setMaxStringLength(128);
// two buttons side by side, and they must not lie on top of each other:
// the plain constructor makes a button two hundred wide
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 90,
98, 20, "Connect"));
this.buttonList.add(new GuiButton(1, this.width / 2 + 2, this.height / 4 + 90,
98, 20, "Cancel"));
this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 90,
200, 20, "Cancel"));
if (this.hasLauncherSession()) {
// the launcher already signed the player in, so there is nothing to
// ask for and nothing to wait for
this.passwordField.setFocused(true);
this.start();
} else {
this.passwordField.setFocused(true);
this.status = "the launcher did not give a session";
}
}
@@ -115,32 +87,8 @@ public class GuiConnecting extends GuiScreen {
reason == null ? "the connection was closed" : reason})));
}
protected void keyTyped(char c0, int i) {
if (c0 == '\r' || c0 == '\n') {
this.start();
return;
}
if (this.accountField.isFocused()) {
this.accountField.textboxKeyTyped(c0, i);
return;
}
if (this.passwordField.isFocused()) {
this.passwordField.textboxKeyTyped(c0, i);
}
}
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
super.mouseClicked(mouseX, mouseY, mouseButton);
this.accountField.mouseClicked(mouseX, mouseY, mouseButton);
this.passwordField.mouseClicked(mouseX, mouseY, mouseButton);
}
protected void actionPerformed(GuiButton guibutton) {
if (guibutton.id == 0) {
this.start();
} else if (guibutton.id == 1) {
if (guibutton.id == 1) {
this.mc.displayGuiScreen(this.previousGuiScreen);
}
}
@@ -151,15 +99,8 @@ public class GuiConnecting extends GuiScreen {
this.height / 4 - 20, 16777215);
if (this.hasLauncherSession()) {
this.drawCenteredString(this.fontRenderer, "signed in as " + this.launcherAccount,
this.drawCenteredString(this.fontRenderer, "signed in as " + account(),
this.width / 2, this.height / 4 + 10, 8421504);
} else {
this.drawString(this.fontRenderer, "Account", this.width / 2 - 100,
this.height / 4 + 10, 8421504);
this.accountField.drawTextBox();
this.drawString(this.fontRenderer, "Password", this.width / 2 - 100,
this.height / 4 + 40, 8421504);
this.passwordField.drawTextBox();
}
if (!this.status.isEmpty()) {
@@ -170,6 +111,20 @@ public class GuiConnecting extends GuiScreen {
super.drawScreen(i, j, f);
}
/**
* The name of the player.
*
* It is inside the token: the launcher gives the game a token and a uuid
* without a name, and the name is read out of the token.
*/
private String account() {
java.util.Map<String, String> claims = GameToken.peek(this.launcherToken);
if (claims != null && claims.get("nick") != null && !claims.get("nick").isEmpty()) {
return claims.get("nick");
}
return this.launcherAccount == null ? "" : this.launcherAccount;
}
/**
* Starts the connection.
*
@@ -180,36 +135,22 @@ public class GuiConnecting extends GuiScreen {
if (this.networkManager != null) {
return;
}
String account;
String token = null;
String uuid = null;
char[] password = new char[0];
if (this.hasLauncherSession()) {
account = this.launcherAccount;
token = this.launcherToken;
uuid = this.launcherUuid;
} else {
account = this.accountField.getText().trim();
password = this.passwordField.getText().toCharArray();
if (account.isEmpty()) {
this.status = "an account name is needed";
return;
}
if (password.length == 0) {
this.status = "a password is needed";
return;
}
this.passwordField.setText("");
if (!this.hasLauncherSession()) {
this.status = "the launcher did not give a session";
return;
}
String account = account();
String token = this.launcherToken;
String uuid = this.launcherUuid;
this.status = "connecting to " + this.host + ":" + this.port;
System.out.println("[rsx] connecting to " + this.host + ":" + this.port + " as " + account);
System.out.println("[rsx] connecting to " + this.host + ":" + this.port
+ " as " + account);
final RsxNetworkManager manager = new RsxNetworkManager(this.mc, this.previousGuiScreen,
new GameProfile(RsxWorldBridge.uuidFor(account), account),
account, password, token, uuid);
account, new char[0], token, uuid);
this.networkManager = manager;
(new Thread("Rsx Connect") {