Add standalone lobby House selector and key-backed Mentat welcome

This commit is contained in:
unimatrixgit 2026-11-21 14:39:50 +01:00
commit 51f67bd1ba

View file

@ -0,0 +1,32 @@
package com.dunerealms.gui;
import com.google.gson.*;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.*;
import java.net.URI;
import java.net.http.*;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.UUID;
/** Uses the existing private game bridge credential. Never logs it or returns codes. */
final class HouseBridge {
private final HttpClient http=HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).followRedirects(HttpClient.Redirect.NEVER).build();
private final File config;
HouseBridge(File config){this.config=config;}
JsonObject request(UUID player,String faction,int version,UUID requestId) throws Exception {
var settings=YamlConfiguration.loadConfiguration(config);
String origin=settings.getString("origin",""),secret=settings.getString("secret","");
if(!origin.equals("https://cp.dunerealms.com")||secret.length()<32)throw new IOException("House bridge unavailable");
JsonObject data=new JsonObject();data.addProperty("action",faction==null?"read":"choose");data.addProperty("uuid",player.toString());
if(faction!=null){data.addProperty("faction",faction);data.addProperty("version",version);data.addProperty("confirmed",true);data.addProperty("requestId",requestId.toString());}
var req=HttpRequest.newBuilder(URI.create(origin+"/internal/game/house")).timeout(Duration.ofSeconds(10)).header("Authorization","Bearer "+secret).header("Content-Type","application/json").POST(HttpRequest.BodyPublishers.ofString(data.toString())).build();
var response=http.send(req,HttpResponse.BodyHandlers.ofInputStream());
byte[] body;try(var in=response.body()){body=in.readNBytes(32769);}
if(body.length>32768)throw new IOException("House response too large");
JsonObject result=JsonParser.parseString(new String(body,StandardCharsets.UTF_8)).getAsJsonObject();
if(response.statusCode()!=200)throw new IOException(response.statusCode()==403?"Link your personal Minecraft account at cp.dunerealms.com first.":response.statusCode()==409?"Your House record changed. Reopen the menu.":"The House register is temporarily unavailable. Please retry.");
if(!result.has("ok")||!result.get("ok").getAsBoolean()||!result.has("choices")||result.getAsJsonArray("choices").size()!=5)throw new IOException("Invalid House response");
return result;
}
}