Skip to content

Commit

Permalink
Converted the new forms
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim203 committed May 28, 2022
1 parent d4ecd2b commit 84bcadc
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 60 deletions.
4 changes: 2 additions & 2 deletions ap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<parent>
<groupId>org.geysermc</groupId>
<artifactId>geyser-parent</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
</parent>

<artifactId>ap</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
</project>
2 changes: 1 addition & 1 deletion api/base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.geysermc</groupId>
<artifactId>api-parent</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
4 changes: 2 additions & 2 deletions api/geyser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.geysermc</groupId>
<artifactId>api-parent</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -26,7 +26,7 @@
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>base-api</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.geysermc</groupId>
<artifactId>geyser-parent</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
</parent>

<artifactId>api-parent</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/bungeecord/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<parent>
<groupId>org.geysermc</groupId>
<artifactId>bootstrap-parent</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
</parent>
<artifactId>bootstrap-bungeecord</artifactId>

<dependencies>
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>core</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!-- Used for better working with internals without reflection -->
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.geysermc</groupId>
<artifactId>geyser-parent</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
</parent>
<artifactId>bootstrap-parent</artifactId>
<packaging>pom</packaging>
Expand Down Expand Up @@ -34,7 +34,7 @@
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>ap</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/spigot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.geysermc</groupId>
<artifactId>bootstrap-parent</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
</parent>
<artifactId>bootstrap-spigot</artifactId>

Expand All @@ -30,7 +30,7 @@
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>core</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/sponge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<parent>
<groupId>org.geysermc</groupId>
<artifactId>bootstrap-parent</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
</parent>
<artifactId>bootstrap-sponge</artifactId>

<dependencies>
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>core</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/standalone/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.geysermc</groupId>
<artifactId>bootstrap-parent</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
</parent>
<artifactId>bootstrap-standalone</artifactId>

Expand All @@ -18,7 +18,7 @@
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>core</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/velocity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<parent>
<groupId>org.geysermc</groupId>
<artifactId>bootstrap-parent</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
</parent>
<artifactId>bootstrap-velocity</artifactId>

<dependencies>
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>core</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.geysermc</groupId>
<artifactId>geyser-parent</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
</parent>
<artifactId>common</artifactId>

Expand All @@ -20,7 +20,7 @@
<dependency>
<groupId>org.geysermc.cumulus</groupId>
<artifactId>cumulus</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand Down
8 changes: 4 additions & 4 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.geysermc</groupId>
<artifactId>geyser-parent</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
</parent>
<artifactId>core</artifactId>

Expand All @@ -21,19 +21,19 @@
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>ap</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>geyser-api</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>common</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!-- Jackson JSON and YAML serialization -->
Expand Down
22 changes: 12 additions & 10 deletions core/src/main/java/org/geysermc/geyser/session/cache/FormCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,29 @@
@RequiredArgsConstructor
public class FormCache {
private final FormDefinitions formDefinitions = FormDefinitions.instance();
private final AtomicInteger formId = new AtomicInteger(0);
private final AtomicInteger formIdCounter = new AtomicInteger(0);
private final Int2ObjectMap<Form> forms = new Int2ObjectOpenHashMap<>();
private final GeyserSession session;

public int addForm(Form form) {
int windowId = formId.getAndIncrement();
forms.put(windowId, form);
return windowId;
int formId = formIdCounter.getAndIncrement();
forms.put(formId, form);
return formId;
}

public void showForm(Form form) {
int windowId = addForm(form);
int formId = addForm(form);

if (session.getUpstream().isInitialized()) {
sendForm(windowId, form);
sendForm(formId, form);
}
}

private void sendForm(int windowId, Form form) {
private void sendForm(int formId, Form form) {
String jsonData = formDefinitions.codecFor(form).jsonData(form);

ModalFormRequestPacket formRequestPacket = new ModalFormRequestPacket();
formRequestPacket.setFormId(windowId);
formRequestPacket.setFormId(formId);
formRequestPacket.setFormData(jsonData);
session.sendUpstreamPacket(formRequestPacket);

Expand All @@ -74,8 +74,10 @@ private void sendForm(int windowId, Form form) {
NetworkStackLatencyPacket latencyPacket = new NetworkStackLatencyPacket();
latencyPacket.setFromServer(true);
latencyPacket.setTimestamp(-System.currentTimeMillis());
session.scheduleInEventLoop(() -> session.sendUpstreamPacket(latencyPacket),
500, TimeUnit.MILLISECONDS);
session.scheduleInEventLoop(
() -> session.sendUpstreamPacket(latencyPacket),
500, TimeUnit.MILLISECONDS
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
import org.geysermc.cumulus.form.CustomForm;
import org.geysermc.cumulus.form.ModalForm;
import org.geysermc.cumulus.form.SimpleForm;
import org.geysermc.cumulus.response.SimpleFormResponse;
import org.geysermc.cumulus.response.result.FormResponseResult;
import org.geysermc.cumulus.response.result.ResultType;
import org.geysermc.cumulus.response.result.ValidFormResponseResult;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.session.GeyserSession;
Expand All @@ -59,6 +62,7 @@
import java.security.spec.ECGenParameterSpec;
import java.util.Iterator;
import java.util.UUID;
import java.util.function.BiConsumer;

public class LoginEncryptionUtils {
private static final ObjectMapper JSON_MAPPER = new ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
Expand Down Expand Up @@ -264,42 +268,49 @@ public static void buildAndShowLoginWindow(GeyserSession session) {
* Build a window that explains the user's credentials will be saved to the system.
*/
public static void buildAndShowConsentWindow(GeyserSession session) {
String locale = session.getLocale();
session.sendForm(
SimpleForm.builder()
.translator(LoginEncryptionUtils::translate, session.getLocale())
.title("%gui.signIn")
.content(GeyserLocale.getPlayerLocaleString("geyser.auth.login.save_token.warning", locale) +
"\n\n" +
GeyserLocale.getPlayerLocaleString("geyser.auth.login.save_token.proceed", locale))
.content("""
geyser.auth.login.save_token.warning
geyser.auth.login.save_token.proceed""")
.button("%gui.ok")
.button("%gui.decline")
.responseHandler((form, responseData) -> {
SimpleFormResponse response = form.parseResponse(responseData);
if (response.isCorrect() && response.getClickedButtonId() == 0) {
session.authenticateWithMicrosoftCode(true);
} else {
session.disconnect("%disconnect.quitting");
}
}));
.resultHandler(
authenticateOrKickHandler(session),
ResultType.CLOSED, ResultType.INVALID, ResultType.VALID
)
);
}

public static void buildAndShowTokenExpiredWindow(GeyserSession session) {
String locale = session.getLocale();
session.sendForm(
SimpleForm.builder()
.title(GeyserLocale.getPlayerLocaleString("geyser.auth.login.form.expired", locale))
.content(GeyserLocale.getPlayerLocaleString("geyser.auth.login.save_token.expired", locale) +
"\n\n" +
GeyserLocale.getPlayerLocaleString("geyser.auth.login.save_token.proceed", locale))
.translator(LoginEncryptionUtils::translate, session.getLocale())
.title("geyser.auth.login.form.expired")
.content("""
geyser.auth.login.save_token.expired
geyser.auth.login.save_token.proceed""")
.button("%gui.ok")
.responseHandler((form, responseData) -> {
SimpleFormResponse response = form.parseResponse(responseData);
if (response.isCorrect()) {
session.authenticateWithMicrosoftCode(true);
} else {
session.disconnect("%disconnect.quitting");
}
}));
.resultHandler(
authenticateOrKickHandler(session),
ResultType.CLOSED, ResultType.INVALID, ResultType.VALID
)
);
}

private static BiConsumer<SimpleForm, FormResponseResult<SimpleFormResponse>> authenticateOrKickHandler(GeyserSession session) {
return (form, genericResult) -> {
if (genericResult instanceof ValidFormResponseResult<SimpleFormResponse> result &&
result.response().clickedButtonId() == 0) {
session.authenticateWithMicrosoftCode(true);
} else {
session.disconnect("%disconnect.quitting");
}
};
}

public static void buildAndShowLoginDetailsWindow(GeyserSession session) {
Expand Down Expand Up @@ -378,4 +389,30 @@ public static void buildAndShowMicrosoftCodeWindow(GeyserSession session, MsaAut
})
);
}

/*
This checks per line if there is something to be translated, and it skips Bedrock translation keys (%)
*/
private static String translate(String key, String locale) {
StringBuilder newValue = new StringBuilder();
int previousIndex = 0;
while (previousIndex < key.length()) {
int nextIndex = key.indexOf('\n', previousIndex);
int endIndex = nextIndex == -1 ? key.length() : nextIndex;

// if there is more to this line than just a new line char
if (endIndex - previousIndex > 1) {
String substring = key.substring(previousIndex, endIndex);
if (key.charAt(previousIndex) != '%') {
newValue.append(GeyserLocale.getPlayerLocaleString(substring, locale));
} else {
newValue.append(substring);
}
}
newValue.append('\n');

previousIndex = endIndex + 1;
}
return newValue.toString();
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.geysermc</groupId>
<artifactId>geyser-parent</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3-cumulus-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Geyser</name>
<description>Allows for players from Minecraft Bedrock Edition to join Minecraft Java Edition servers.</description>
Expand Down

0 comments on commit 84bcadc

Please sign in to comment.