Optimize invitation code generation

This commit is contained in:
Glavo 2021-10-16 14:47:49 +08:00 committed by Yuhui Huang
parent 59e1a470e3
commit 955a06d689

View File

@ -207,7 +207,7 @@ public final class MultiplayerManager {
} }
public static Invitation parseInvitationCode(String invitationCode) throws JsonParseException { public static Invitation parseInvitationCode(String invitationCode) throws JsonParseException {
String json = new String(Base64.getDecoder().decode(invitationCode.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8); String json = new String(Base64.getDecoder().decode(invitationCode), StandardCharsets.UTF_8);
return JsonUtils.fromNonNullJson(json, Invitation.class); return JsonUtils.fromNonNullJson(json, Invitation.class);
} }
@ -350,8 +350,8 @@ public final class MultiplayerManager {
if (id == null) { if (id == null) {
throw new IllegalStateException("id not generated"); throw new IllegalStateException("id not generated");
} }
String json = JsonUtils.GSON.toJson(new Invitation(CATO_VERSION, id, name, serverPort)); String json = JsonUtils.UGLY_GSON.toJson(new Invitation(CATO_VERSION, id, name, serverPort));
return new String(Base64.getEncoder().encode(json.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8); return Base64.getEncoder().encodeToString(json.getBytes(StandardCharsets.UTF_8));
} }
public EventManager<CatoExitEvent> onExit() { public EventManager<CatoExitEvent> onExit() {