mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2026-02-04 09:15:07 +01:00
Fix handbook server details
This commit is contained in:
@@ -64,15 +64,20 @@ export function setTargetPlayer(player: number, token: string | null = null): vo
|
||||
* @param newAddress The server's address.
|
||||
* @param newPort The server's port.
|
||||
*/
|
||||
export async function setServerDetails(newAddress: string | null, newPort: string | null): Promise<void> {
|
||||
// Apply the new details.
|
||||
if (newAddress != null) {
|
||||
address = newAddress;
|
||||
localStorage.setItem("address", newAddress);
|
||||
}
|
||||
if (newPort != null) {
|
||||
port = newPort;
|
||||
localStorage.setItem("port", newPort);
|
||||
export async function setServerDetails(newAddress: string | null, newPort: string | number | null): Promise<void> {
|
||||
if (!getWindowDetails().disable) {
|
||||
if (typeof newPort == "number")
|
||||
newPort = newPort.toString();
|
||||
|
||||
// Apply the new details.
|
||||
if (newAddress != null) {
|
||||
address = newAddress;
|
||||
localStorage.setItem("address", newAddress);
|
||||
}
|
||||
if (newPort != null) {
|
||||
port = newPort;
|
||||
localStorage.setItem("port", newPort);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the server is encrypted.
|
||||
|
||||
@@ -2,9 +2,9 @@ import React from "react";
|
||||
|
||||
import emitter from "@backend/events";
|
||||
import { targetPlayer, address, port, setServerDetails, url, setTargetPlayer } from "@backend/server";
|
||||
import { getWindowDetails } from "@app/utils";
|
||||
|
||||
import "@css/widgets/ServerSettings.scss";
|
||||
import { getWindowDetails } from "@app/utils";
|
||||
|
||||
interface IState {
|
||||
webview: boolean;
|
||||
@@ -51,7 +51,7 @@ class ServerSettings extends React.Component<{}, IState> {
|
||||
* @private
|
||||
*/
|
||||
private authenticate(): void {
|
||||
setServerDetails(null, null).then(() => {
|
||||
setServerDetails(this.state.address, this.state.port).then(() => {
|
||||
this.setState({ webview: true });
|
||||
});
|
||||
|
||||
@@ -133,7 +133,8 @@ class ServerSettings extends React.Component<{}, IState> {
|
||||
}}
|
||||
disabled={disable}
|
||||
style={{
|
||||
cursor: disable ? "not-allowed" : "text"
|
||||
cursor: disable ? "not-allowed" : "text",
|
||||
userSelect: disable ? "none" : "auto"
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
@@ -155,7 +156,8 @@ class ServerSettings extends React.Component<{}, IState> {
|
||||
}}
|
||||
disabled={disable}
|
||||
style={{
|
||||
cursor: disable ? "not-allowed" : "text"
|
||||
cursor: disable ? "not-allowed" : "text",
|
||||
userSelect: disable ? "none" : "auto"
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -174,8 +174,11 @@ export function getWindowDetails(): WindowDetails {
|
||||
const { address, port, disable } = details;
|
||||
|
||||
return {
|
||||
address: address == "{{DETAILS_ADDRESS}}" ? "127.0.0.1" : address,
|
||||
port: port == "{{DETAILS_PORT}}" ? 443 : parseInt(port),
|
||||
disable: disable == "{{DETAILS_DISABLE}}" ? false : disable == "true"
|
||||
address: (address as string).includes("DETAILS_ADDRESS")
|
||||
? "127.0.0.1" : address,
|
||||
port: (port as string).includes("DETAILS_PORT")
|
||||
? 443 : parseInt(port),
|
||||
disable: (disable as string).includes("DETAILS_DISABLE")
|
||||
? false : disable == "true"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package emu.grasscutter.server.http.documentation;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.HANDBOOK;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.auth.AuthenticationSystem.AuthenticationRequest;
|
||||
import emu.grasscutter.server.http.Router;
|
||||
@@ -13,6 +11,8 @@ import io.javalin.Javalin;
|
||||
import io.javalin.http.ContentType;
|
||||
import io.javalin.http.Context;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.HANDBOOK;
|
||||
|
||||
/** Handles requests for the new GM Handbook. */
|
||||
public final class HandbookHandler implements Router {
|
||||
private String handbook;
|
||||
@@ -32,7 +32,7 @@ public final class HandbookHandler implements Router {
|
||||
this.handbook
|
||||
.replace("{{DETAILS_ADDRESS}}", server.address)
|
||||
.replace("{{DETAILS_PORT}}", String.valueOf(server.port))
|
||||
.replace("{{DETAILS_DISABLE}}", Boolean.toString(server.canChange));
|
||||
.replace("{{DETAILS_DISABLE}}", Boolean.toString(!server.canChange));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user