Implement suggestion #4 and cleaning some import files

This commit is contained in:
muhammadeko 2022-05-06 07:42:40 +07:00
parent 517a8ea5b3
commit d08aba15ee
No known key found for this signature in database
GPG Key ID: 51366716C10E98B1
6 changed files with 7 additions and 40 deletions

View File

@ -10,7 +10,7 @@ sourceCompatibility = 17
targetCompatibility = 17 targetCompatibility = 17
group 'me.exzork.gcauth' group 'me.exzork.gcauth'
version '2.1.0' version '2.1.2'
repositories { repositories {
mavenCentral() mavenCentral()
@ -42,5 +42,4 @@ jar{
exclude("META-INF/NOTICE") exclude("META-INF/NOTICE")
} }
destinationDir = file(".") destinationDir = file(".")
} }

View File

@ -3,23 +3,9 @@ package me.exzork.gcauth;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.Account;
import emu.grasscutter.net.proto.QueryCurrRegionHttpRspOuterClass; import emu.grasscutter.net.proto.QueryCurrRegionHttpRspOuterClass;
import emu.grasscutter.plugin.Plugin; import emu.grasscutter.plugin.Plugin;
import emu.grasscutter.server.dispatch.DispatchHttpJsonHandler;
import emu.grasscutter.server.dispatch.json.ComboTokenReqJson;
import emu.grasscutter.server.dispatch.json.ComboTokenResJson;
import emu.grasscutter.server.dispatch.json.LoginResultJson;
import emu.grasscutter.server.dispatch.json.LoginTokenRequestJson;
import emu.grasscutter.server.event.dispatch.QueryAllRegionsEvent;
import emu.grasscutter.server.event.dispatch.QueryCurrentRegionEvent;
import express.Express;
import me.exzork.gcauth.handler.*; import me.exzork.gcauth.handler.*;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
@ -30,10 +16,12 @@ import java.nio.file.Files;
public class GCAuth extends Plugin { public class GCAuth extends Plugin {
private static Config config; private static Config config;
private static final File configFile = new File(Grasscutter.getConfig().PLUGINS_FOLDER+"GCAuth/config.json"); private File configFile;
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
@Override @Override
public void onLoad() { public void onEnable() {
configFile = new File(getDataFolder().toPath()+ "/config.json");
if (!configFile.exists()) { if (!configFile.exists()) {
try { try {
Files.createDirectories(configFile.toPath().getParent()); Files.createDirectories(configFile.toPath().getParent());
@ -42,10 +30,6 @@ public class GCAuth extends Plugin {
} }
} }
loadConfig(); loadConfig();
}
@Override
public void onEnable() {
if(Grasscutter.getDispatchServer().registerAuthHandler(new GCAuthAuthenticationHandler())) { if(Grasscutter.getDispatchServer().registerAuthHandler(new GCAuthAuthenticationHandler())) {
Grasscutter.getLogger().info("[GCAuth] GCAuth Enabled!"); Grasscutter.getLogger().info("[GCAuth] GCAuth Enabled!");
@ -64,7 +48,7 @@ public class GCAuth extends Plugin {
} }
} }
public static void loadConfig() { public void loadConfig() {
try (FileReader file = new FileReader(configFile)) { try (FileReader file = new FileReader(configFile)) {
config = gson.fromJson(file,Config.class); config = gson.fromJson(file,Config.class);
saveConfig(); saveConfig();
@ -74,23 +58,12 @@ public class GCAuth extends Plugin {
} }
} }
public static void saveConfig() { public void saveConfig() {
try (FileWriter file = new FileWriter(configFile)) { try (FileWriter file = new FileWriter(configFile)) {
file.write(gson.toJson(config)); file.write(gson.toJson(config));
} catch (Exception e) { } catch (Exception e) {
Grasscutter.getLogger().error("[GCAuth] Unable to save config file."); Grasscutter.getLogger().error("[GCAuth] Unable to save config file.");
} }
} }
public static class RegionData {
QueryCurrRegionHttpRspOuterClass.QueryCurrRegionHttpRsp parsedRegionQuery;
String Base64;
public RegionData(QueryCurrRegionHttpRspOuterClass.QueryCurrRegionHttpRsp prq, String b64) {
this.parsedRegionQuery = prq;
this.Base64 = b64;
}
}
public static Config getConfig() {return config;} public static Config getConfig() {return config;}
} }

View File

@ -6,7 +6,6 @@ import emu.grasscutter.game.Account;
import express.http.HttpContextHandler; import express.http.HttpContextHandler;
import express.http.Request; import express.http.Request;
import express.http.Response; import express.http.Response;
import me.exzork.gcauth.GCAuth;
import me.exzork.gcauth.json.AuthResponseJson; import me.exzork.gcauth.json.AuthResponseJson;
import me.exzork.gcauth.json.ChangePasswordAccount; import me.exzork.gcauth.json.ChangePasswordAccount;
import me.exzork.gcauth.utils.Authentication; import me.exzork.gcauth.utils.Authentication;

View File

@ -2,14 +2,12 @@ package me.exzork.gcauth.handler;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.Account; import emu.grasscutter.game.Account;
import emu.grasscutter.server.dispatch.authentication.AuthenticationHandler; import emu.grasscutter.server.dispatch.authentication.AuthenticationHandler;
import emu.grasscutter.server.dispatch.json.LoginAccountRequestJson; import emu.grasscutter.server.dispatch.json.LoginAccountRequestJson;
import emu.grasscutter.server.dispatch.json.LoginResultJson; import emu.grasscutter.server.dispatch.json.LoginResultJson;
import express.http.Request; import express.http.Request;
import express.http.Response; import express.http.Response;
import me.exzork.gcauth.GCAuth;
import me.exzork.gcauth.utils.Authentication; import me.exzork.gcauth.utils.Authentication;
import java.io.IOException; import java.io.IOException;

View File

@ -6,7 +6,6 @@ import emu.grasscutter.game.Account;
import express.http.HttpContextHandler; import express.http.HttpContextHandler;
import express.http.Request; import express.http.Request;
import express.http.Response; import express.http.Response;
import me.exzork.gcauth.GCAuth;
import me.exzork.gcauth.json.AuthResponseJson; import me.exzork.gcauth.json.AuthResponseJson;
import me.exzork.gcauth.json.LoginGenerateToken; import me.exzork.gcauth.json.LoginGenerateToken;
import me.exzork.gcauth.utils.Authentication; import me.exzork.gcauth.utils.Authentication;

View File

@ -7,7 +7,6 @@ import emu.grasscutter.game.Account;
import express.http.HttpContextHandler; import express.http.HttpContextHandler;
import express.http.Request; import express.http.Request;
import express.http.Response; import express.http.Response;
import me.exzork.gcauth.GCAuth;
import me.exzork.gcauth.json.AuthResponseJson; import me.exzork.gcauth.json.AuthResponseJson;
import me.exzork.gcauth.json.RegisterAccount; import me.exzork.gcauth.json.RegisterAccount;
import me.exzork.gcauth.utils.Authentication; import me.exzork.gcauth.utils.Authentication;