mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2026-05-26 13:32:14 +08:00
Format code [skip actions]
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package emu.grasscutter.utils;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.DISPATCH_INFO;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.auth.AuthenticationSystem.AuthenticationRequest;
|
||||
@@ -9,20 +11,18 @@ import emu.grasscutter.server.dispatch.IDispatcher;
|
||||
import emu.grasscutter.server.dispatch.PacketIds;
|
||||
import emu.grasscutter.server.http.handlers.GachaHandler;
|
||||
import emu.grasscutter.server.http.objects.LoginTokenRequestJson;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.net.http.HttpClient;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.DISPATCH_INFO;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public interface DispatchUtils {
|
||||
/** HTTP client used for dispatch queries. */
|
||||
HttpClient HTTP_CLIENT = HttpClient.newBuilder()
|
||||
.version(HttpClient.Version.HTTP_2)
|
||||
.followRedirects(HttpClient.Redirect.ALWAYS)
|
||||
.build();
|
||||
HttpClient HTTP_CLIENT =
|
||||
HttpClient.newBuilder()
|
||||
.version(HttpClient.Version.HTTP_2)
|
||||
.followRedirects(HttpClient.Redirect.ALWAYS)
|
||||
.build();
|
||||
|
||||
/**
|
||||
* @return The dispatch URL.
|
||||
@@ -38,22 +38,16 @@ public interface DispatchUtils {
|
||||
* @param token The token.
|
||||
* @return {@code true} if the authentication request is valid, otherwise {@code false}.
|
||||
*/
|
||||
@Nullable
|
||||
static Account authenticate(String accountId, String token) {
|
||||
@Nullable static Account authenticate(String accountId, String token) {
|
||||
return switch (Grasscutter.getRunMode()) {
|
||||
case GAME_ONLY ->
|
||||
// Use the authentication system to validate the token.
|
||||
Grasscutter.getAuthenticationSystem()
|
||||
// Use the authentication system to validate the token.
|
||||
Grasscutter.getAuthenticationSystem()
|
||||
.getSessionTokenValidator()
|
||||
.authenticate(
|
||||
AuthenticationRequest.builder()
|
||||
.tokenRequest(
|
||||
LoginTokenRequestJson.builder()
|
||||
.uid(accountId)
|
||||
.token(token)
|
||||
.build()
|
||||
).build()
|
||||
);
|
||||
AuthenticationRequest.builder()
|
||||
.tokenRequest(LoginTokenRequestJson.builder().uid(accountId).token(token).build())
|
||||
.build());
|
||||
case HYBRID, DISPATCH_ONLY -> {
|
||||
// Fetch the account from the database.
|
||||
var account = DatabaseHelper.getAccountById(accountId);
|
||||
@@ -86,8 +80,9 @@ public interface DispatchUtils {
|
||||
var future = new CompletableFuture<JsonObject>();
|
||||
// Listen for the response.
|
||||
var server = Grasscutter.getDispatchServer();
|
||||
server.registerCallback(PacketIds.GachaHistoryRsp, packet ->
|
||||
future.complete(IDispatcher.decode(packet, JsonObject.class)));
|
||||
server.registerCallback(
|
||||
PacketIds.GachaHistoryRsp,
|
||||
packet -> future.complete(IDispatcher.decode(packet, JsonObject.class)));
|
||||
|
||||
// Broadcast the request.
|
||||
server.sendMessage(PacketIds.GachaHistoryReq, request);
|
||||
@@ -104,16 +99,14 @@ public interface DispatchUtils {
|
||||
var response = new JsonObject();
|
||||
|
||||
// Get the player's ID from the account.
|
||||
var player = Grasscutter.getGameServer()
|
||||
.getPlayerByAccountId(accountId);
|
||||
var player = Grasscutter.getGameServer().getPlayerByAccountId(accountId);
|
||||
if (player == null) {
|
||||
response.addProperty("retcode", 1);
|
||||
yield response;
|
||||
}
|
||||
|
||||
// Fetch the gacha records.
|
||||
GachaHandler.fetchGachaRecords(
|
||||
player, response, page, gachaType);
|
||||
GachaHandler.fetchGachaRecords(player, response, page, gachaType);
|
||||
|
||||
yield response;
|
||||
}
|
||||
|
||||
@@ -11,13 +11,12 @@ import emu.grasscutter.data.common.DynamicFloat;
|
||||
import it.unimi.dsi.fastutil.floats.FloatArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import lombok.val;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
import lombok.val;
|
||||
|
||||
public class JsonAdapters {
|
||||
static class DynamicFloatAdapter extends TypeAdapter<DynamicFloat> {
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package emu.grasscutter.utils;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.FALLBACK_LANGUAGE;
|
||||
import static emu.grasscutter.utils.FileUtils.getCachePath;
|
||||
import static emu.grasscutter.utils.FileUtils.getResourcePath;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
@@ -13,8 +17,6 @@ import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
@@ -26,10 +28,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.FALLBACK_LANGUAGE;
|
||||
import static emu.grasscutter.utils.FileUtils.getCachePath;
|
||||
import static emu.grasscutter.utils.FileUtils.getResourcePath;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
public final class Language {
|
||||
private static final Map<String, Language> cachedLanguages = new ConcurrentHashMap<>();
|
||||
@@ -133,13 +132,13 @@ public final class Language {
|
||||
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
args[i] =
|
||||
switch (args[i].getClass().getSimpleName()) {
|
||||
case "String" -> args[i];
|
||||
case "TextStrings" -> ((TextStrings) args[i])
|
||||
.getGC(langCode)
|
||||
.replace("\\\\n", "\n"); // Note that we don't unescape \n for server console
|
||||
default -> args[i].toString();
|
||||
};
|
||||
switch (args[i].getClass().getSimpleName()) {
|
||||
case "String" -> args[i];
|
||||
case "TextStrings" -> ((TextStrings) args[i])
|
||||
.getGC(langCode)
|
||||
.replace("\\\\n", "\n"); // Note that we don't unescape \n for server console
|
||||
default -> args[i].toString();
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -1,73 +1,78 @@
|
||||
package emu.grasscutter.utils;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.*;
|
||||
|
||||
import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.Logger;
|
||||
import emu.grasscutter.BuildConfig;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.net.packet.PacketOpcodesUtils;
|
||||
import emu.grasscutter.tools.Dumpers;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.*;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/** A parser for start-up arguments. */
|
||||
public final class StartupArguments {
|
||||
/* A map of parameter -> argument handler. */
|
||||
private static final Map<String, Function<String, Boolean>> argumentHandlers = new HashMap<>() {
|
||||
{
|
||||
putAll(Map.of("-dumppacketids",
|
||||
parameter -> {
|
||||
PacketOpcodesUtils.dumpPacketIds();
|
||||
return true;
|
||||
},
|
||||
"-version", StartupArguments::printVersion,
|
||||
"-debug", StartupArguments::enableDebug,
|
||||
"-lang",
|
||||
parameter -> {
|
||||
Grasscutter.setPreferredLanguage(parameter);
|
||||
return false;
|
||||
},
|
||||
"-game",
|
||||
parameter -> {
|
||||
Grasscutter.setRunModeOverride(Grasscutter.ServerRunMode.GAME_ONLY);
|
||||
return false;
|
||||
},
|
||||
"-dispatch",
|
||||
parameter -> {
|
||||
Grasscutter.setRunModeOverride(Grasscutter.ServerRunMode.DISPATCH_ONLY);
|
||||
return false;
|
||||
},
|
||||
"-noconsole",
|
||||
parameter -> {
|
||||
Grasscutter.setNoConsole(true);
|
||||
return false;
|
||||
},
|
||||
"-test",
|
||||
parameter -> {
|
||||
// Disable the console.
|
||||
SERVER.game.enableConsole = false;
|
||||
// Disable HTTP encryption.
|
||||
SERVER.http.encryption.useEncryption = false;
|
||||
return false;
|
||||
},
|
||||
"-dump", StartupArguments::dump,
|
||||
private static final Map<String, Function<String, Boolean>> argumentHandlers =
|
||||
new HashMap<>() {
|
||||
{
|
||||
putAll(
|
||||
Map.of(
|
||||
"-dumppacketids",
|
||||
parameter -> {
|
||||
PacketOpcodesUtils.dumpPacketIds();
|
||||
return true;
|
||||
},
|
||||
"-version",
|
||||
StartupArguments::printVersion,
|
||||
"-debug",
|
||||
StartupArguments::enableDebug,
|
||||
"-lang",
|
||||
parameter -> {
|
||||
Grasscutter.setPreferredLanguage(parameter);
|
||||
return false;
|
||||
},
|
||||
"-game",
|
||||
parameter -> {
|
||||
Grasscutter.setRunModeOverride(Grasscutter.ServerRunMode.GAME_ONLY);
|
||||
return false;
|
||||
},
|
||||
"-dispatch",
|
||||
parameter -> {
|
||||
Grasscutter.setRunModeOverride(Grasscutter.ServerRunMode.DISPATCH_ONLY);
|
||||
return false;
|
||||
},
|
||||
"-noconsole",
|
||||
parameter -> {
|
||||
Grasscutter.setNoConsole(true);
|
||||
return false;
|
||||
},
|
||||
"-test",
|
||||
parameter -> {
|
||||
// Disable the console.
|
||||
SERVER.game.enableConsole = false;
|
||||
// Disable HTTP encryption.
|
||||
SERVER.http.encryption.useEncryption = false;
|
||||
return false;
|
||||
},
|
||||
"-dump",
|
||||
StartupArguments::dump,
|
||||
|
||||
// Aliases.
|
||||
"-v", StartupArguments::printVersion
|
||||
));
|
||||
putAll(Map.of(
|
||||
"-debugall",
|
||||
parameter -> {
|
||||
StartupArguments.enableDebug("all");
|
||||
return false;
|
||||
// Aliases.
|
||||
"-v",
|
||||
StartupArguments::printVersion));
|
||||
putAll(
|
||||
Map.of(
|
||||
"-debugall",
|
||||
parameter -> {
|
||||
StartupArguments.enableDebug("all");
|
||||
return false;
|
||||
}));
|
||||
}
|
||||
));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
private StartupArguments() {
|
||||
// This class is not meant to be instantiated.
|
||||
|
||||
Reference in New Issue
Block a user