mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-21 11:24:47 +01:00
Format code [skip actions]
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package emu.grasscutter.server.dispatch;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.DISPATCH_INFO;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
@@ -10,12 +12,6 @@ import emu.grasscutter.utils.Crypto;
|
||||
import emu.grasscutter.utils.DispatchUtils;
|
||||
import emu.grasscutter.utils.JsonUtils;
|
||||
import emu.grasscutter.utils.objects.HandbookBody;
|
||||
import lombok.Getter;
|
||||
import org.java_websocket.WebSocket;
|
||||
import org.java_websocket.client.WebSocketClient;
|
||||
import org.java_websocket.handshake.ServerHandshake;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.net.ConnectException;
|
||||
import java.net.URI;
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -26,8 +22,11 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.DISPATCH_INFO;
|
||||
import lombok.Getter;
|
||||
import org.java_websocket.WebSocket;
|
||||
import org.java_websocket.client.WebSocketClient;
|
||||
import org.java_websocket.handshake.ServerHandshake;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public final class DispatchClient extends WebSocketClient implements IDispatcher {
|
||||
@Getter private final Logger logger = Grasscutter.getLogger();
|
||||
@@ -125,13 +124,11 @@ public final class DispatchClient extends WebSocketClient implements IDispatcher
|
||||
|
||||
// Convert the fields array.
|
||||
var fieldsList = new ArrayList<String>();
|
||||
for (var field : fieldsRaw)
|
||||
fieldsList.add(field.getAsString());
|
||||
for (var field : fieldsRaw) fieldsList.add(field.getAsString());
|
||||
var fields = fieldsList.toArray(new String[0]);
|
||||
|
||||
// Return the response object.
|
||||
this.sendMessage(PacketIds.GetPlayerFieldsRsp,
|
||||
DispatchUtils.getPlayerFields(playerId, fields));
|
||||
this.sendMessage(PacketIds.GetPlayerFieldsRsp, DispatchUtils.getPlayerFields(playerId, fields));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
package emu.grasscutter.server.dispatch;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.DISPATCH_INFO;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.database.DatabaseHelper;
|
||||
import emu.grasscutter.utils.Crypto;
|
||||
import lombok.Getter;
|
||||
import org.java_websocket.WebSocket;
|
||||
import org.java_websocket.handshake.ClientHandshake;
|
||||
import org.java_websocket.server.WebSocketServer;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -19,8 +15,11 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.DISPATCH_INFO;
|
||||
import lombok.Getter;
|
||||
import org.java_websocket.WebSocket;
|
||||
import org.java_websocket.handshake.ClientHandshake;
|
||||
import org.java_websocket.server.WebSocketServer;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
/* Internal communications server. */
|
||||
public final class DispatchServer extends WebSocketServer implements IDispatcher {
|
||||
@@ -99,8 +98,7 @@ public final class DispatchServer extends WebSocketServer implements IDispatcher
|
||||
// Get the account from the database.
|
||||
var account = DatabaseHelper.getAccountById(accountId);
|
||||
// Send the account.
|
||||
this.sendMessage(socket, PacketIds.GetAccountRsp,
|
||||
JSON.toJsonTree(account));
|
||||
this.sendMessage(socket, PacketIds.GetAccountRsp, JSON.toJsonTree(account));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package emu.grasscutter.server.dispatch;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.DISPATCH_INFO;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import emu.grasscutter.utils.Crypto;
|
||||
import emu.grasscutter.utils.JsonAdapters.ByteArrayAdapter;
|
||||
import org.java_websocket.WebSocket;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -18,8 +17,8 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.DISPATCH_INFO;
|
||||
import org.java_websocket.WebSocket;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public interface IDispatcher {
|
||||
Gson JSON =
|
||||
@@ -28,8 +27,8 @@ public interface IDispatcher {
|
||||
.registerTypeAdapter(byte[].class, new ByteArrayAdapter())
|
||||
.create();
|
||||
|
||||
Function<JsonElement, JsonObject> DEFAULT_PARSER = (packet) ->
|
||||
IDispatcher.decode(packet, JsonObject.class);
|
||||
Function<JsonElement, JsonObject> DEFAULT_PARSER =
|
||||
(packet) -> IDispatcher.decode(packet, JsonObject.class);
|
||||
|
||||
/**
|
||||
* Decodes an escaped JSON message.
|
||||
@@ -78,8 +77,8 @@ public interface IDispatcher {
|
||||
* @return The fulfilled data, or null.
|
||||
* @param <T> The type of data to be returned.
|
||||
*/
|
||||
default <T> T await(JsonObject request, int requestId, int responseId,
|
||||
Function<JsonElement, T> parser) {
|
||||
default <T> T await(
|
||||
JsonObject request, int requestId, int responseId, Function<JsonElement, T> parser) {
|
||||
// Perform the setup for the request.
|
||||
var future = this.async(request, requestId, responseId, parser);
|
||||
|
||||
@@ -92,8 +91,7 @@ public interface IDispatcher {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a callback for a packet to be received.
|
||||
* Sends a packet with the provided request.
|
||||
* Registers a callback for a packet to be received. Sends a packet with the provided request.
|
||||
*
|
||||
* @param request The request object.
|
||||
* @param requestId The packet ID of the request packet.
|
||||
@@ -105,8 +103,7 @@ public interface IDispatcher {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a callback for a packet to be received.
|
||||
* Sends a packet with the provided request.
|
||||
* Registers a callback for a packet to be received. Sends a packet with the provided request.
|
||||
*
|
||||
* @param request The request object.
|
||||
* @param requestId The packet ID of the request packet.
|
||||
@@ -115,14 +112,11 @@ public interface IDispatcher {
|
||||
* @return A promise containing the parsed JSON data.
|
||||
*/
|
||||
default <T> CompletableFuture<T> async(
|
||||
JsonObject request, int requestId, int responseId,
|
||||
Function<JsonElement, T> parser
|
||||
) {
|
||||
JsonObject request, int requestId, int responseId, Function<JsonElement, T> parser) {
|
||||
// Create the future.
|
||||
var future = new CompletableFuture<T>();
|
||||
// Listen for the response.
|
||||
this.registerCallback(responseId, packet ->
|
||||
future.complete(parser.apply(packet)));
|
||||
this.registerCallback(responseId, packet -> future.complete(parser.apply(packet)));
|
||||
// Broadcast the packet.
|
||||
this.sendMessage(requestId, request);
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
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;
|
||||
@@ -11,8 +13,6 @@ 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 final byte[] handbook;
|
||||
@@ -77,8 +77,8 @@ public final class HandbookHandler implements Router {
|
||||
} else {
|
||||
// Pass the request to the authenticator.
|
||||
Grasscutter.getAuthenticationSystem()
|
||||
.getHandbookAuthenticator().presentPage(
|
||||
AuthenticationRequest.builder().context(ctx).build());
|
||||
.getHandbookAuthenticator()
|
||||
.presentPage(AuthenticationRequest.builder().context(ctx).build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,17 +93,17 @@ public final class HandbookHandler implements Router {
|
||||
ctx.status(500).result("Handbook not found.");
|
||||
} else {
|
||||
// Pass the request to the authenticator.
|
||||
var result = Grasscutter.getAuthenticationSystem()
|
||||
.getHandbookAuthenticator().authenticate(
|
||||
AuthenticationRequest.builder().context(ctx).build());
|
||||
var result =
|
||||
Grasscutter.getAuthenticationSystem()
|
||||
.getHandbookAuthenticator()
|
||||
.authenticate(AuthenticationRequest.builder().context(ctx).build());
|
||||
if (result == null) {
|
||||
ctx.status(500).result("Authentication failed.");
|
||||
} else {
|
||||
ctx
|
||||
.status(result.getStatus())
|
||||
.result(result.getBody())
|
||||
.contentType(result.getBody().contains("html") ?
|
||||
ContentType.TEXT_HTML : ContentType.TEXT_PLAIN);
|
||||
ctx.status(result.getStatus())
|
||||
.result(result.getBody())
|
||||
.contentType(
|
||||
result.getBody().contains("html") ? ContentType.TEXT_HTML : ContentType.TEXT_PLAIN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user