mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2026-04-03 06:22:28 +02:00
Merge unstable into development (#2173)
* Remove more scene synchronized
* Fix worktop options not appearing
* Format code [skip actions]
* Fix delay with server tasks
* Format code [skip actions]
* Fully fix fairy clock (#2146)
* Fix scene transition
* fully fix fairy clock
* Re-add call to `Player#updatePlayerGameTime`
* Format code [skip actions]
* Initialize the script loader in `ResourceLoader#loadAll`
* Fix region removal checking
* Format code [skip actions]
* Use Lombok's `EqualsAndHashCode` for comparing scene regions
* Format code [skip actions]
* Move 'invalid gather object' to `trace`
* Add more information to the 'unknown condition handler' message
* Move invalid ability action to trace
* Make `KcpTunnel` public
* Validate the NPC being talked to
* Format code [skip actions]
* NPCs are not spawned server side; change logic to handle it
* Format code [skip actions]
* unload scene when there are no players (#2147)
* unload scene when there are no players
* Update src/main/java/emu/grasscutter/game/world/Scene.java
Co-authored-by: Magix <27646710+KingRainbow44@users.noreply.github.com>
---------
Co-authored-by: Magix <27646710+KingRainbow44@users.noreply.github.com>
* Check if a command should be copied or HTTP should be used
* Lint Code [skip actions]
* Fix character names rendering incorrectly
* Add basic troubleshooting command
* Implement handbook teleporting
also a few formatting changes and sort data by logical sense
* Fix listener `ConcurrentModificationException` issue
* Add color change to `Join the Community!`
* Lint Code [skip actions]
* Make clickable buttons appear clickable
* Remove 'Mechanicus' entities from the list of entities
* Format code [skip actions]
* Fix going back returning a blank screen
* Implement entity spawning
* Add setting level to entity card
* Add support for 'plain text' mode
* Make descriptions of objects scrollable
* Lint Code [skip actions]
* Format code [skip actions]
* Change the way existing hooks work
* Format code [skip actions]
* Upgrade Javalin to 5.5.0 & Fix project warnings
* Upgrade logging libraries
* Fix gacha mappings static file issue
* Add temporary backwards compatability for `ServerHelper`
* Format code [skip actions]
* Remove artifact signatures from VCS
* Fix forge queue data protocol definition
* Run `spotlessApply`
* Format code [skip actions]
* Download data required for building artifacts
* Add call for Facebook logins
* Add the wiki page as a submodule
* Format code [skip actions]
* Update translation (#2150)
* Update translation
* Update translation
* Separate the dispatch and game servers (pt. 1)
gacha is still broken, handbook still needs to be done
* Format code [skip actions]
* Separate the dispatch and game servers (pt. 2)
this commit fixes the gacha page
* Add description for '/troubleshoot'
* Set default avatar talent level to 10
* Separate the dispatch and game servers (pt. 3)
implement handbook across servers!
* Format code [skip actions]
* Update GitHub Actions to use 'download-file' over 'wget'
* Gm handbook lmao (#2149)
* Fix font issue
* Fix avatars
* Fix text overflow in commands
* Fix virtualized lists and items page 😭😭
* magix why 💀
* use hover style in all minicards
* button
* remove console.log
* lint
* Add icons
* magix asked
* Fix overflow padding issue
* Fix achievement text overflow
* remove icons from repo
* Change command icon
* Add the wiki page as a submodule
* total magix moment
* fix text overflow in commands
* Fix discord button
* Make text scale on Minicard
* import icons and font from another source
* Add hover effects to siebar buttons
* move font and readme to submodule repo
* Make data folder a submodule
* import icons and font from data submodule
* Update README.md
* total magix moment
* magix moment v2
* submodule change
* Import `.webp` files
* Resize `HomeButton`
* Fix 'Copy Command' reappearing after changing pages
---------
Co-authored-by: KingRainbow44 <kobedo11@gmail.com>
* Lint Code [skip actions]
* Download data for the build, not for the lint
* format imports
this is really just to see if build handbook works kek
* Implement proper handbook authentication (pt. 1)
* Implement proper handbook authentication (pt. 2)
* Format code [skip actions]
* Add quest data dumping for the handbook
* Change colors to fit _something suitable_
* Format code [skip actions]
* Fix force pushing to branches after linting
* Fix logic of `SetPlayerPropReq`
* Move more group loading to `trace`
* Add handbook IP authentication in hybrid mode
* Fix player level up not displaying on the client properly
* Format code [skip actions]
* Fix game time locking
* Format code [skip actions]
* Update player properties
* Format code [skip actions]
* Move `warn`s for groups to `debug`
* Fix player pausing
* Move more logs to `trace`
* Use `removeItemById` for deleting items via quests
* Clean up logger more
* Pause in-game time when the world is paused
* Format code [skip actions]
* More player property documentation
* Multi-threaded resource loading
* Format code [skip actions]
* Add quest widgets
* Add quests page (basic impl.)
* Add/fix colors
also fix tailwind
* Remove banned packets
client modifications already perform the job of blocking malicious packets from being executed, no point in having this if self-windy is wanted
* Re-add `BeginCameraSceneLookNotify`
* Fix being unable to attack (#2157)
* Add `PlayerOpenChestEvent`
* Add methods to get players from the server
* Add static methods to register an event handler
* Add `PlayerEnterDungeonEvent`
* Remove legacy documentation from `PlayerMoveEvent`
* Add `PlayerChatEvent`
* Add defaults to `Position`
* Clean up `.utils`
* Revert `Multi-threaded resource loading`
* Fix changing target UID when talking to the server
* Lint Code [skip actions]
* Format code [skip actions]
* fix NPC talk triggering main quest in 46101 (#2158)
Make it so that only talks where the param matches the talkId are checked.
* Format code [skip actions]
* Partially fix Chasing Shadows (#2159)
* Partially fix Chasing Shadows
* Go ahead and move it before the return before Magix tells me to.
* Format code [skip actions]
* Bring back period lol (#2160)
* Disable SNI for the HTTPS server
* Add `EntityCreationEvent`
* Add initial startup message
this is so the server appears like its preparing to start
* Format code [skip actions]
* Enable debug mode for plugin loggers if enabled for the primary logger
* Add documentation about `WorldAreaConfigData`
* Make more fields in excels accessible
* Remove deprecated fields from `GetShopRsp`
* Run `spotlessApply` on definitions
* Add `PlayerEnterAreaEvent`
* Optimize event calls
* Fix event invokes
* Format code [skip actions]
* Remove manual autofinish for main quests. (#2162)
* Add world areas to the textmap cache
* Format code [skip actions]
* Don't overdefine variables in extended classes (#2163)
* Add dumper for world areas
* Format code [skip actions]
* instantiate personalLineList (#2165)
* Fix protocol definitions
thank you Nazrin! (+ hiro for raw definitions)
* Fix the background color leaking from the character widget
* Change HTML spacing to 2 spaces
* Implement hiding widgets
* Change scrollbar to a vibrant color
* Add _some_ scaling to the home buttons and its text
* Build the handbook with Gradle
* Fix the 'finer details' with the handbook UI
* Lint Code [skip actions]
* Fix target destination for the Gradle-built handbook
* Implement fetching a player across servers & Add a chainable JsonObject
useful for plugins! might be used in grasscutter eventually
* Fix GitHub actions
* Fix event calling & canceling
* Run `spotlessApply`
* Rename fields (might be wrong)
* Add/update all/more protocol definitions
* Add/update all/more protocol definitions
* Remove outdated packet
* Fix protocol definitions
* Format code [skip actions]
* Implement some lua variables for less console spam (#2172)
* Implement some lua variables for less console spam
* Add GetHostQuestState
This fixes some chapter 3 stuff.
* Format code [skip actions]
* Fix merge import
* Format code [skip actions]
* Fully fix fairy clock for real this time (#2167)
* Fully fix fairy clock For real this time
* Make it so relogging keeps the time lock state.
* Refactor out questLockTime
* Per Hartie, the client packet needs to be changed too
* Update src/main/java/emu/grasscutter/game/world/World.java
Co-authored-by: Magix <27646710+KingRainbow44@users.noreply.github.com>
* Update src/main/java/emu/grasscutter/server/packet/recv/HandlerClientLockGameTimeNotify.java
* Remove all code not needed to get clock working
---------
Co-authored-by: Magix <27646710+KingRainbow44@users.noreply.github.com>
* Implement a proper ability system (#2166)
* Apply fix `21dec2fe`
* Apply fix `89d01d5f`
* Apply fix `d900f154`
this one was already implemented; updated to use call from previous commit
* Ability changing commit
TODO: change info to debug
* Remove use of deprecated methods/fields
* Temp commit v2
(Adding LoseHP and some fixes)
* Oopsie
* Probably fix monster battle
* Fix issue with reflecting into fields
* Fix some things
* Fix ability names for 3.6 resources
* Improve logging
---------
Co-authored-by: StartForKiller <jesussanz2003@gmail.com>
* Format code [skip actions]
* Add system for sending messages between servers
* Format some code
* Remove protocol definitions from Spotless
* Default debug to false; enable with `-debug`
* Implement completely useless global value copying
* HACK: Return the avatar which holds the weapon when the weapon is referred to by ID
* Add properties to `AbilityModifier`
* Change the way HTML is served after authentication
* Use thread executors to speed up the database loading process
* Format code [skip actions]
* Add system for setting handbook address and port
* Lint Code [skip actions]
* Format code [skip actions]
* Fix game-related data not saving
* Format code [skip actions]
* Fix handbook server details
* Lint Code [skip actions]
* Format code [skip actions]
* Use the headers provided by a context to get the IP address
should acknowledge #1975
* Format code [skip actions]
* Move more logs to `trace`
* Format code [skip actions]
* more trace
* Fix something and implement weapon entities
* Format code [skip actions]
* Fix `EntityWeapon`
* Remove deprecated API & Fix resource checking
* Fix unnecessary warning for first-time setup
* Implement handbook request limiting
* Format code [skip actions]
* Fix new avatar weapons being null
* Format code [skip actions]
* Fix issue with 35303 being un-completable & Try to fix fulfilled quest conditions being met
* Load activity config on server startup
* Require plugins to specify an API version and match with the server
* Add default open state ignore list
* Format code [skip actions]
* Quick fix for questing, needs more investigation
This would make the questing work again
* Remove existing hack for 35303
* Fix ignored open states from being set
* Format code [skip actions]
* fix the stupidest bug ive ever seen
* Optimize player kicking on server close
* Format code [skip actions]
* Re-add hack to fix 35303
* Update GitHub actions
* Format code [skip actions]
* Potentially fix issues with regions
* Download additional handbook data
* Revert "Potentially fix issues with regions"
This reverts commit 84e3823695.
---------
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: scooterboo <lewasite@yahoo.com>
Co-authored-by: Tesutarin <105267106+Tesutarin@users.noreply.github.com>
Co-authored-by: Scald <104459145+Arikatsu@users.noreply.github.com>
Co-authored-by: StartForKiller <jesussanz2003@gmail.com>
This commit is contained in:
@@ -2,116 +2,47 @@ package emu.grasscutter.auth;
|
||||
|
||||
import emu.grasscutter.game.Account;
|
||||
import emu.grasscutter.server.http.objects.*;
|
||||
import emu.grasscutter.utils.DispatchUtils;
|
||||
import io.javalin.http.Context;
|
||||
import javax.annotation.Nullable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Defines an authenticator for the server.
|
||||
* Can be changed by plugins.
|
||||
*/
|
||||
/** Defines an authenticator for the server. Can be changed by plugins. */
|
||||
public interface AuthenticationSystem {
|
||||
|
||||
/**
|
||||
* Called when a user requests to make an account.
|
||||
* @param username The provided username.
|
||||
* @param password The provided password. (SHA-256'ed)
|
||||
*/
|
||||
void createAccount(String username, String password);
|
||||
|
||||
/**
|
||||
* Called when a user requests to reset their password.
|
||||
* @param username The username of the account to reset.
|
||||
*/
|
||||
void resetPassword(String username);
|
||||
|
||||
/**
|
||||
* Called by plugins to internally verify a user's identity.
|
||||
* @param details A unique identifier to identify the user. (For example: a JWT token)
|
||||
* @return The user's account if the verification was successful, null if the user was unable to be verified.
|
||||
*/
|
||||
Account verifyUser(String details);
|
||||
|
||||
/**
|
||||
* This is the authenticator used for password authentication.
|
||||
* @return An authenticator.
|
||||
*/
|
||||
Authenticator<LoginResultJson> getPasswordAuthenticator();
|
||||
|
||||
/**
|
||||
* This is the authenticator used for token authentication.
|
||||
* @return An authenticator.
|
||||
*/
|
||||
Authenticator<LoginResultJson> getTokenAuthenticator();
|
||||
|
||||
/**
|
||||
* This is the authenticator used for session authentication.
|
||||
* @return An authenticator.
|
||||
*/
|
||||
Authenticator<ComboTokenResJson> getSessionKeyAuthenticator();
|
||||
|
||||
/**
|
||||
* This is the authenticator used for handling external authentication requests.
|
||||
* @return An authenticator.
|
||||
*/
|
||||
ExternalAuthenticator getExternalAuthenticator();
|
||||
|
||||
/**
|
||||
* This is the authenticator used for handling OAuth authentication requests.
|
||||
* @return An authenticator.
|
||||
*/
|
||||
OAuthAuthenticator getOAuthAuthenticator();
|
||||
|
||||
/**
|
||||
* A data container that holds relevant data for authenticating a client.
|
||||
*/
|
||||
@Builder @AllArgsConstructor @Getter
|
||||
class AuthenticationRequest {
|
||||
private final Context context;
|
||||
|
||||
@Nullable private final LoginAccountRequestJson passwordRequest;
|
||||
@Nullable private final LoginTokenRequestJson tokenRequest;
|
||||
@Nullable private final ComboTokenReqJson sessionKeyRequest;
|
||||
@Nullable private final ComboTokenReqJson.LoginTokenData sessionKeyData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an authentication request from a {@link LoginAccountRequestJson} object.
|
||||
*
|
||||
* @param ctx The Javalin context.
|
||||
* @param jsonData The JSON data.
|
||||
* @return An authentication request.
|
||||
*/
|
||||
static AuthenticationRequest fromPasswordRequest(Context ctx, LoginAccountRequestJson jsonData) {
|
||||
return AuthenticationRequest.builder()
|
||||
.context(ctx)
|
||||
.passwordRequest(jsonData)
|
||||
.build();
|
||||
return AuthenticationRequest.builder().context(ctx).passwordRequest(jsonData).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an authentication request from a {@link LoginTokenRequestJson} object.
|
||||
*
|
||||
* @param ctx The Javalin context.
|
||||
* @param jsonData The JSON data.
|
||||
* @return An authentication request.
|
||||
*/
|
||||
static AuthenticationRequest fromTokenRequest(Context ctx, LoginTokenRequestJson jsonData) {
|
||||
return AuthenticationRequest.builder()
|
||||
.context(ctx)
|
||||
.tokenRequest(jsonData)
|
||||
.build();
|
||||
return AuthenticationRequest.builder().context(ctx).tokenRequest(jsonData).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an authentication request from a {@link ComboTokenReqJson} object.
|
||||
*
|
||||
* @param ctx The Javalin context.
|
||||
* @param jsonData The JSON data.
|
||||
* @return An authentication request.
|
||||
*/
|
||||
static AuthenticationRequest fromComboTokenRequest(Context ctx, ComboTokenReqJson jsonData,
|
||||
ComboTokenReqJson.LoginTokenData tokenData) {
|
||||
static AuthenticationRequest fromComboTokenRequest(
|
||||
Context ctx, ComboTokenReqJson jsonData, ComboTokenReqJson.LoginTokenData tokenData) {
|
||||
return AuthenticationRequest.builder()
|
||||
.context(ctx)
|
||||
.sessionKeyRequest(jsonData)
|
||||
@@ -121,10 +52,101 @@ public interface AuthenticationSystem {
|
||||
|
||||
/**
|
||||
* Generates an authentication request from a {@link Context} object.
|
||||
*
|
||||
* @param ctx The Javalin context.
|
||||
* @return An authentication request.
|
||||
*/
|
||||
static AuthenticationRequest fromExternalRequest(Context ctx) {
|
||||
return AuthenticationRequest.builder().context(ctx).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a user requests to make an account.
|
||||
*
|
||||
* @param username The provided username.
|
||||
* @param password The provided password. (SHA-256'ed)
|
||||
*/
|
||||
void createAccount(String username, String password);
|
||||
|
||||
/**
|
||||
* Called when a user requests to reset their password.
|
||||
*
|
||||
* @param username The username of the account to reset.
|
||||
*/
|
||||
void resetPassword(String username);
|
||||
|
||||
/**
|
||||
* Called by plugins to internally verify a user's identity.
|
||||
*
|
||||
* @param details A unique identifier to identify the user. (For example: a JWT token)
|
||||
* @return The user's account if the verification was successful, null if the user was unable to
|
||||
* be verified.
|
||||
*/
|
||||
Account verifyUser(String details);
|
||||
|
||||
/**
|
||||
* This is the authenticator used for password authentication.
|
||||
*
|
||||
* @return An authenticator.
|
||||
*/
|
||||
Authenticator<LoginResultJson> getPasswordAuthenticator();
|
||||
|
||||
/**
|
||||
* This is the authenticator used for token authentication.
|
||||
*
|
||||
* @return An authenticator.
|
||||
*/
|
||||
Authenticator<LoginResultJson> getTokenAuthenticator();
|
||||
|
||||
/**
|
||||
* This is the authenticator used for session authentication.
|
||||
*
|
||||
* @return An authenticator.
|
||||
*/
|
||||
Authenticator<ComboTokenResJson> getSessionKeyAuthenticator();
|
||||
|
||||
/**
|
||||
* This is the authenticator used for validating session tokens. This is a part of the logic in
|
||||
* {@link DispatchUtils#authenticate(String, String)}.
|
||||
*
|
||||
* <p>Plugins can override this authenticator to add support for alternate session authentication
|
||||
* methods.
|
||||
*
|
||||
* @return {@code true} if the session token is valid, {@code false} otherwise.
|
||||
*/
|
||||
Authenticator<Account> getSessionTokenValidator();
|
||||
|
||||
/**
|
||||
* This is the authenticator used for handling external authentication requests.
|
||||
*
|
||||
* @return An authenticator.
|
||||
*/
|
||||
ExternalAuthenticator getExternalAuthenticator();
|
||||
|
||||
/**
|
||||
* This is the authenticator used for handling OAuth authentication requests.
|
||||
*
|
||||
* @return An authenticator.
|
||||
*/
|
||||
OAuthAuthenticator getOAuthAuthenticator();
|
||||
|
||||
/**
|
||||
* This is the authenticator used for handling handbook authentication requests.
|
||||
*
|
||||
* @return An authenticator.
|
||||
*/
|
||||
HandbookAuthenticator getHandbookAuthenticator();
|
||||
|
||||
/** A data container that holds relevant data for authenticating a client. */
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
class AuthenticationRequest {
|
||||
@Nullable private final Context context;
|
||||
|
||||
@Nullable private final LoginAccountRequestJson passwordRequest;
|
||||
@Nullable private final LoginTokenRequestJson tokenRequest;
|
||||
@Nullable private final ComboTokenReqJson sessionKeyRequest;
|
||||
@Nullable private final ComboTokenReqJson.LoginTokenData sessionKeyData;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
package emu.grasscutter.auth;
|
||||
|
||||
import emu.grasscutter.server.http.objects.*;
|
||||
import emu.grasscutter.server.http.objects.ComboTokenResJson;
|
||||
import emu.grasscutter.server.http.objects.LoginResultJson;
|
||||
|
||||
/**
|
||||
* Handles username/password authentication from the client.
|
||||
* @param <T> The response object type. Should be {@link LoginResultJson} or {@link ComboTokenResJson}
|
||||
*
|
||||
* @param <T> The response object type. Should be {@link LoginResultJson} or {@link
|
||||
* ComboTokenResJson}
|
||||
*/
|
||||
public interface Authenticator<T> {
|
||||
|
||||
|
||||
/**
|
||||
* Attempt to authenticate the client with the provided credentials.
|
||||
* @param request The authentication request wrapped in a {@link AuthenticationSystem.AuthenticationRequest} object.
|
||||
*
|
||||
* @param request The authentication request wrapped in a {@link
|
||||
* AuthenticationSystem.AuthenticationRequest} object.
|
||||
* @return The result of the login in an object.
|
||||
*/
|
||||
T authenticate(AuthenticationSystem.AuthenticationRequest request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
package emu.grasscutter.auth;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.ACCOUNT;
|
||||
import static emu.grasscutter.utils.lang.Language.translate;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.auth.DefaultAuthenticators.*;
|
||||
import emu.grasscutter.game.Account;
|
||||
import emu.grasscutter.server.http.objects.ComboTokenResJson;
|
||||
import emu.grasscutter.server.http.objects.LoginResultJson;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.ACCOUNT;
|
||||
import static emu.grasscutter.utils.Language.translate;
|
||||
|
||||
/**
|
||||
* The default Grasscutter authentication implementation.
|
||||
* Allows all users to access any account.
|
||||
* The default Grasscutter authentication implementation. Allows all users to access any account.
|
||||
*/
|
||||
public final class DefaultAuthentication implements AuthenticationSystem {
|
||||
private Authenticator<LoginResultJson> passwordAuthenticator;
|
||||
private Authenticator<LoginResultJson> tokenAuthenticator = new TokenAuthenticator();
|
||||
private Authenticator<ComboTokenResJson> sessionKeyAuthenticator = new SessionKeyAuthenticator();
|
||||
private ExternalAuthenticator externalAuthenticator = new ExternalAuthentication();
|
||||
private OAuthAuthenticator oAuthAuthenticator = new OAuthAuthentication();
|
||||
private final Authenticator<LoginResultJson> passwordAuthenticator;
|
||||
private final Authenticator<LoginResultJson> tokenAuthenticator = new TokenAuthenticator();
|
||||
private final Authenticator<ComboTokenResJson> sessionKeyAuthenticator =
|
||||
new SessionKeyAuthenticator();
|
||||
private final Authenticator<Account> sessionTokenValidator = new SessionTokenValidator();
|
||||
private final ExternalAuthenticator externalAuthenticator = new ExternalAuthentication();
|
||||
private final OAuthAuthenticator oAuthAuthenticator = new OAuthAuthentication();
|
||||
private final HandbookAuthenticator handbookAuthenticator = new HandbookAuthentication();
|
||||
|
||||
public DefaultAuthentication() {
|
||||
if (ACCOUNT.EXPERIMENTAL_RealPassword) {
|
||||
@@ -40,7 +42,8 @@ public final class DefaultAuthentication implements AuthenticationSystem {
|
||||
|
||||
@Override
|
||||
public Account verifyUser(String details) {
|
||||
Grasscutter.getLogger().info(translate("messages.dispatch.authentication.default_unable_to_verify"));
|
||||
Grasscutter.getLogger()
|
||||
.info(translate("messages.dispatch.authentication.default_unable_to_verify"));
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -59,6 +62,11 @@ public final class DefaultAuthentication implements AuthenticationSystem {
|
||||
return this.sessionKeyAuthenticator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Authenticator<Account> getSessionTokenValidator() {
|
||||
return this.sessionTokenValidator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExternalAuthenticator getExternalAuthenticator() {
|
||||
return this.externalAuthenticator;
|
||||
@@ -68,4 +76,9 @@ public final class DefaultAuthentication implements AuthenticationSystem {
|
||||
public OAuthAuthenticator getOAuthAuthenticator() {
|
||||
return this.oAuthAuthenticator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandbookAuthenticator getHandbookAuthenticator() {
|
||||
return this.handbookAuthenticator;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,29 @@
|
||||
package emu.grasscutter.auth;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.ACCOUNT;
|
||||
import static emu.grasscutter.utils.lang.Language.translate;
|
||||
|
||||
import at.favre.lib.crypto.bcrypt.BCrypt;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.Grasscutter.ServerRunMode;
|
||||
import emu.grasscutter.auth.AuthenticationSystem.AuthenticationRequest;
|
||||
import emu.grasscutter.database.DatabaseHelper;
|
||||
import emu.grasscutter.game.Account;
|
||||
import emu.grasscutter.server.dispatch.*;
|
||||
import emu.grasscutter.server.http.objects.*;
|
||||
import emu.grasscutter.utils.FileUtils;
|
||||
import emu.grasscutter.utils.Utils;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import emu.grasscutter.utils.*;
|
||||
import io.javalin.http.ContentType;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.interfaces.RSAPrivateKey;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.util.concurrent.*;
|
||||
import javax.crypto.Cipher;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.*;
|
||||
import static emu.grasscutter.utils.Language.translate;
|
||||
|
||||
/**
|
||||
* A class containing default authenticators.
|
||||
*/
|
||||
/** A class containing default authenticators. */
|
||||
public final class DefaultAuthenticators {
|
||||
|
||||
/**
|
||||
* Handles the authentication request from the username and password form.
|
||||
*/
|
||||
/** Handles the authentication request from the username and password form. */
|
||||
public static class PasswordAuthenticator implements Authenticator<LoginResultJson> {
|
||||
@Override
|
||||
public LoginResultJson authenticate(AuthenticationRequest request) {
|
||||
@@ -33,42 +31,39 @@ public final class DefaultAuthenticators {
|
||||
|
||||
var requestData = request.getPasswordRequest();
|
||||
assert requestData != null; // This should never be null.
|
||||
int playerCount = Grasscutter.getGameServer().getPlayers().size();
|
||||
|
||||
boolean successfulLogin = false;
|
||||
String address = request.getContext().ip();
|
||||
String address = Utils.address(request.getContext());
|
||||
String responseMessage = translate("messages.dispatch.account.username_error");
|
||||
String loggerMessage = "";
|
||||
|
||||
// Get account from database.
|
||||
Account account = DatabaseHelper.getAccountByName(requestData.account);
|
||||
if (ACCOUNT.maxPlayer <= -1 || playerCount < ACCOUNT.maxPlayer) {
|
||||
// Check if account exists.
|
||||
if (account == null && ACCOUNT.autoCreate) {
|
||||
// This account has been created AUTOMATICALLY. There will be no permissions added.
|
||||
account = DatabaseHelper.createAccountWithUid(requestData.account, 0);
|
||||
// Check if account exists.
|
||||
if (account == null && ACCOUNT.autoCreate) {
|
||||
// This account has been created AUTOMATICALLY. There will be no permissions added.
|
||||
account = DatabaseHelper.createAccountWithUid(requestData.account, 0);
|
||||
|
||||
// Check if the account was created successfully.
|
||||
if (account == null) {
|
||||
responseMessage = translate("messages.dispatch.account.username_create_error");
|
||||
Grasscutter.getLogger().info(translate("messages.dispatch.account.account_login_create_error", address));
|
||||
} else {
|
||||
// Continue with login.
|
||||
successfulLogin = true;
|
||||
|
||||
// Log the creation.
|
||||
Grasscutter.getLogger().info(translate("messages.dispatch.account.account_login_create_success", address, response.data.account.uid));
|
||||
}
|
||||
} else if (account != null)
|
||||
// Check if the account was created successfully.
|
||||
if (account == null) {
|
||||
responseMessage = translate("messages.dispatch.account.username_create_error");
|
||||
Grasscutter.getLogger()
|
||||
.info(translate("messages.dispatch.account.account_login_create_error", address));
|
||||
} else {
|
||||
// Continue with login.
|
||||
successfulLogin = true;
|
||||
else
|
||||
loggerMessage = translate("messages.dispatch.account.account_login_exist_error", address);
|
||||
|
||||
} else {
|
||||
responseMessage = translate("messages.dispatch.account.server_max_player_limit");
|
||||
loggerMessage = translate("messages.dispatch.account.login_max_player_limit", address);
|
||||
}
|
||||
|
||||
// Log the creation.
|
||||
Grasscutter.getLogger()
|
||||
.info(
|
||||
translate(
|
||||
"messages.dispatch.account.account_login_create_success",
|
||||
address,
|
||||
response.data.account.uid));
|
||||
}
|
||||
} else if (account != null) successfulLogin = true;
|
||||
else
|
||||
loggerMessage = translate("messages.dispatch.account.account_login_exist_error", address);
|
||||
|
||||
// Set response data.
|
||||
if (successfulLogin) {
|
||||
@@ -77,11 +72,11 @@ public final class DefaultAuthenticators {
|
||||
response.data.account.token = account.generateSessionKey();
|
||||
response.data.account.email = account.getEmail();
|
||||
|
||||
loggerMessage = translate("messages.dispatch.account.login_success", address, account.getId());
|
||||
loggerMessage =
|
||||
translate("messages.dispatch.account.login_success", address, account.getId());
|
||||
} else {
|
||||
response.retcode = -201;
|
||||
response.message = responseMessage;
|
||||
|
||||
}
|
||||
Grasscutter.getLogger().info(loggerMessage);
|
||||
|
||||
@@ -96,10 +91,9 @@ public final class DefaultAuthenticators {
|
||||
|
||||
var requestData = request.getPasswordRequest();
|
||||
assert requestData != null; // This should never be null.
|
||||
int playerCount = Grasscutter.getGameServer().getPlayers().size();
|
||||
|
||||
boolean successfulLogin = false;
|
||||
String address = request.getContext().ip();
|
||||
String address = Utils.address(request.getContext());
|
||||
String responseMessage = translate("messages.dispatch.account.username_error");
|
||||
String loggerMessage = "";
|
||||
String decryptedPassword = "";
|
||||
@@ -113,7 +107,10 @@ public final class DefaultAuthenticators {
|
||||
|
||||
cipher.init(Cipher.DECRYPT_MODE, private_key);
|
||||
|
||||
decryptedPassword = new String(cipher.doFinal(Utils.base64Decode(request.getPasswordRequest().password)), StandardCharsets.UTF_8);
|
||||
decryptedPassword =
|
||||
new String(
|
||||
cipher.doFinal(Utils.base64Decode(request.getPasswordRequest().password)),
|
||||
StandardCharsets.UTF_8);
|
||||
} catch (Exception ignored) {
|
||||
decryptedPassword = request.getPasswordRequest().password;
|
||||
}
|
||||
@@ -126,54 +123,58 @@ public final class DefaultAuthenticators {
|
||||
|
||||
// Get account from database.
|
||||
Account account = DatabaseHelper.getAccountByName(requestData.account);
|
||||
if (ACCOUNT.maxPlayer <= -1 || playerCount < ACCOUNT.maxPlayer) {
|
||||
// Check if account exists.
|
||||
if (account == null && ACCOUNT.autoCreate) {
|
||||
// This account has been created AUTOMATICALLY. There will be no permissions added.
|
||||
if (decryptedPassword.length() >= 8) {
|
||||
account = DatabaseHelper.createAccountWithUid(requestData.account, 0);
|
||||
account.setPassword(BCrypt.withDefaults().hashToString(12, decryptedPassword.toCharArray()));
|
||||
account.save();
|
||||
// Check if account exists.
|
||||
if (account == null && ACCOUNT.autoCreate) {
|
||||
// This account has been created AUTOMATICALLY. There will be no permissions added.
|
||||
if (decryptedPassword.length() >= 8) {
|
||||
account = DatabaseHelper.createAccountWithUid(requestData.account, 0);
|
||||
account.setPassword(
|
||||
BCrypt.withDefaults().hashToString(12, decryptedPassword.toCharArray()));
|
||||
account.save();
|
||||
|
||||
// Check if the account was created successfully.
|
||||
if (account == null) {
|
||||
responseMessage = translate("messages.dispatch.account.username_create_error");
|
||||
loggerMessage = translate("messages.dispatch.account.account_login_create_error", address);
|
||||
} else {
|
||||
// Continue with login.
|
||||
successfulLogin = true;
|
||||
// Check if the account was created successfully.
|
||||
if (account == null) {
|
||||
responseMessage = translate("messages.dispatch.account.username_create_error");
|
||||
loggerMessage =
|
||||
translate("messages.dispatch.account.account_login_create_error", address);
|
||||
} else {
|
||||
// Continue with login.
|
||||
successfulLogin = true;
|
||||
|
||||
// Log the creation.
|
||||
Grasscutter.getLogger().info(translate("messages.dispatch.account.account_login_create_success", address, response.data.account.uid));
|
||||
}
|
||||
// Log the creation.
|
||||
Grasscutter.getLogger()
|
||||
.info(
|
||||
translate(
|
||||
"messages.dispatch.account.account_login_create_success",
|
||||
address,
|
||||
response.data.account.uid));
|
||||
}
|
||||
} else {
|
||||
successfulLogin = false;
|
||||
loggerMessage = translate("messages.dispatch.account.login_password_error", address);
|
||||
responseMessage = translate("messages.dispatch.account.password_length_error");
|
||||
}
|
||||
} else if (account != null) {
|
||||
if (account.getPassword() != null && !account.getPassword().isEmpty()) {
|
||||
if (BCrypt.verifyer()
|
||||
.verify(decryptedPassword.toCharArray(), account.getPassword())
|
||||
.verified) {
|
||||
successfulLogin = true;
|
||||
} else {
|
||||
successfulLogin = false;
|
||||
loggerMessage = translate("messages.dispatch.account.login_password_error", address);
|
||||
responseMessage = translate("messages.dispatch.account.password_length_error");
|
||||
}
|
||||
} else if (account != null) {
|
||||
if (account.getPassword() != null && !account.getPassword().isEmpty()) {
|
||||
if (BCrypt.verifyer().verify(decryptedPassword.toCharArray(), account.getPassword()).verified) {
|
||||
successfulLogin = true;
|
||||
} else {
|
||||
successfulLogin = false;
|
||||
loggerMessage = translate("messages.dispatch.account.login_password_error", address);
|
||||
responseMessage = translate("messages.dispatch.account.password_error");
|
||||
}
|
||||
} else {
|
||||
successfulLogin = false;
|
||||
loggerMessage = translate("messages.dispatch.account.login_password_storage_error", address);
|
||||
responseMessage = translate("messages.dispatch.account.password_storage_error");
|
||||
responseMessage = translate("messages.dispatch.account.password_error");
|
||||
}
|
||||
} else {
|
||||
loggerMessage = translate("messages.dispatch.account.account_login_exist_error", address);
|
||||
successfulLogin = false;
|
||||
loggerMessage =
|
||||
translate("messages.dispatch.account.login_password_storage_error", address);
|
||||
responseMessage = translate("messages.dispatch.account.password_storage_error");
|
||||
}
|
||||
} else {
|
||||
responseMessage = translate("messages.dispatch.account.server_max_player_limit");
|
||||
loggerMessage = translate("messages.dispatch.account.login_max_player_limit", address);
|
||||
loggerMessage = translate("messages.dispatch.account.account_login_exist_error", address);
|
||||
}
|
||||
|
||||
|
||||
// Set response data.
|
||||
if (successfulLogin) {
|
||||
response.message = "OK";
|
||||
@@ -181,11 +182,11 @@ public final class DefaultAuthenticators {
|
||||
response.data.account.token = account.generateSessionKey();
|
||||
response.data.account.email = account.getEmail();
|
||||
|
||||
loggerMessage = translate("messages.dispatch.account.login_success", address, account.getId());
|
||||
loggerMessage =
|
||||
translate("messages.dispatch.account.login_success", address, account.getId());
|
||||
} else {
|
||||
response.retcode = -201;
|
||||
response.message = responseMessage;
|
||||
|
||||
}
|
||||
Grasscutter.getLogger().info(loggerMessage);
|
||||
|
||||
@@ -193,9 +194,7 @@ public final class DefaultAuthenticators {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the authentication request from the game when using a registry token.
|
||||
*/
|
||||
/** Handles the authentication request from the game when using a registry token. */
|
||||
public static class TokenAuthenticator implements Authenticator<LoginResultJson> {
|
||||
@Override
|
||||
public LoginResultJson authenticate(AuthenticationRequest request) {
|
||||
@@ -205,43 +204,35 @@ public final class DefaultAuthenticators {
|
||||
assert requestData != null;
|
||||
|
||||
boolean successfulLogin;
|
||||
String address = request.getContext().ip();
|
||||
String address = Utils.address(request.getContext());
|
||||
String loggerMessage;
|
||||
int playerCount = Grasscutter.getGameServer().getPlayers().size();
|
||||
|
||||
// Log the attempt.
|
||||
Grasscutter.getLogger().info(translate("messages.dispatch.account.login_token_attempt", address));
|
||||
Grasscutter.getLogger()
|
||||
.info(translate("messages.dispatch.account.login_token_attempt", address));
|
||||
|
||||
if (ACCOUNT.maxPlayer <= -1 || playerCount < ACCOUNT.maxPlayer) {
|
||||
// Get account from database.
|
||||
Account account = DatabaseHelper.getAccountById(requestData.uid);
|
||||
|
||||
// Get account from database.
|
||||
Account account = DatabaseHelper.getAccountById(requestData.uid);
|
||||
// Check if account exists/token is valid.
|
||||
successfulLogin = account != null && account.getSessionKey().equals(requestData.token);
|
||||
|
||||
// Check if account exists/token is valid.
|
||||
successfulLogin = account != null && account.getSessionKey().equals(requestData.token);
|
||||
|
||||
// Set response data.
|
||||
if (successfulLogin) {
|
||||
response.message = "OK";
|
||||
response.data.account.uid = account.getId();
|
||||
response.data.account.token = account.getSessionKey();
|
||||
response.data.account.email = account.getEmail();
|
||||
|
||||
// Log the login.
|
||||
loggerMessage = translate("messages.dispatch.account.login_token_success", address, requestData.uid);
|
||||
} else {
|
||||
response.retcode = -201;
|
||||
response.message = translate("messages.dispatch.account.account_cache_error");
|
||||
|
||||
// Log the failure.
|
||||
loggerMessage = translate("messages.dispatch.account.login_token_error", address);
|
||||
}
|
||||
// Set response data.
|
||||
if (successfulLogin) {
|
||||
response.message = "OK";
|
||||
response.data.account.uid = account.getId();
|
||||
response.data.account.token = account.getSessionKey();
|
||||
response.data.account.email = account.getEmail();
|
||||
|
||||
// Log the login.
|
||||
loggerMessage =
|
||||
translate("messages.dispatch.account.login_token_success", address, requestData.uid);
|
||||
} else {
|
||||
response.retcode = -201;
|
||||
response.message = translate("messages.dispatch.account.server_max_player_limit");
|
||||
response.message = translate("messages.dispatch.account.account_cache_error");
|
||||
|
||||
loggerMessage = translate("messages.dispatch.account.login_max_player_limit", address);
|
||||
// Log the failure.
|
||||
loggerMessage = translate("messages.dispatch.account.login_token_error", address);
|
||||
}
|
||||
|
||||
Grasscutter.getLogger().info(loggerMessage);
|
||||
@@ -249,9 +240,7 @@ public final class DefaultAuthenticators {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the authentication request from the game when using a combo token/session key.
|
||||
*/
|
||||
/** Handles the authentication request from the game when using a combo token/session key. */
|
||||
public static class SessionKeyAuthenticator implements Authenticator<ComboTokenResJson> {
|
||||
@Override
|
||||
public ComboTokenResJson authenticate(AuthenticationRequest request) {
|
||||
@@ -263,39 +252,31 @@ public final class DefaultAuthenticators {
|
||||
assert loginData != null;
|
||||
|
||||
boolean successfulLogin;
|
||||
String address = request.getContext().ip();
|
||||
String address = Utils.address(request.getContext());
|
||||
String loggerMessage;
|
||||
int playerCount = Grasscutter.getGameServer().getPlayers().size();
|
||||
|
||||
if (ACCOUNT.maxPlayer <= -1 || playerCount < ACCOUNT.maxPlayer) {
|
||||
// Get account from database.
|
||||
Account account = DatabaseHelper.getAccountById(loginData.uid);
|
||||
// Get account from database.
|
||||
Account account = DatabaseHelper.getAccountById(loginData.uid);
|
||||
|
||||
// Check if account exists/token is valid.
|
||||
successfulLogin = account != null && account.getSessionKey().equals(loginData.token);
|
||||
// Check if account exists/token is valid.
|
||||
successfulLogin = account != null && account.getSessionKey().equals(loginData.token);
|
||||
|
||||
// Set response data.
|
||||
if (successfulLogin) {
|
||||
response.message = "OK";
|
||||
response.data.open_id = account.getId();
|
||||
response.data.combo_id = "157795300";
|
||||
response.data.combo_token = account.generateLoginToken();
|
||||
// Set response data.
|
||||
if (successfulLogin) {
|
||||
response.message = "OK";
|
||||
response.data.open_id = account.getId();
|
||||
response.data.combo_id = "157795300";
|
||||
response.data.combo_token = account.generateLoginToken();
|
||||
|
||||
// Log the login.
|
||||
loggerMessage = translate("messages.dispatch.account.combo_token_success", address);
|
||||
// Log the login.
|
||||
loggerMessage = translate("messages.dispatch.account.combo_token_success", address);
|
||||
|
||||
} else {
|
||||
response.retcode = -201;
|
||||
response.message = translate("messages.dispatch.account.session_key_error");
|
||||
|
||||
// Log the failure.
|
||||
loggerMessage = translate("messages.dispatch.account.combo_token_error", address);
|
||||
}
|
||||
} else {
|
||||
response.retcode = -201;
|
||||
response.message = translate("messages.dispatch.account.server_max_player_limit");
|
||||
response.message = translate("messages.dispatch.account.session_key_error");
|
||||
|
||||
loggerMessage = translate("messages.dispatch.account.login_max_player_limit", address);
|
||||
// Log the failure.
|
||||
loggerMessage = translate("messages.dispatch.account.combo_token_error", address);
|
||||
}
|
||||
|
||||
Grasscutter.getLogger().info(loggerMessage);
|
||||
@@ -303,43 +284,161 @@ public final class DefaultAuthenticators {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles authentication requests from external sources.
|
||||
*/
|
||||
/** Handles authentication requests from external sources. */
|
||||
public static class ExternalAuthentication implements ExternalAuthenticator {
|
||||
@Override
|
||||
public void handleLogin(AuthenticationRequest request) {
|
||||
request.getContext().result("Authentication is not available with the default authentication method.");
|
||||
request
|
||||
.getContext()
|
||||
.result("Authentication is not available with the default authentication method.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleAccountCreation(AuthenticationRequest request) {
|
||||
request.getContext().result("Authentication is not available with the default authentication method.");
|
||||
request
|
||||
.getContext()
|
||||
.result("Authentication is not available with the default authentication method.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePasswordReset(AuthenticationRequest request) {
|
||||
request.getContext().result("Authentication is not available with the default authentication method.");
|
||||
request
|
||||
.getContext()
|
||||
.result("Authentication is not available with the default authentication method.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles authentication requests from OAuth sources.Zenlith
|
||||
*/
|
||||
/** Handles authentication requests from OAuth sources.Zenlith */
|
||||
public static class OAuthAuthentication implements OAuthAuthenticator {
|
||||
@Override
|
||||
public void handleLogin(AuthenticationRequest request) {
|
||||
request.getContext().result("Authentication is not available with the default authentication method.");
|
||||
request
|
||||
.getContext()
|
||||
.result("Authentication is not available with the default authentication method.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRedirection(AuthenticationRequest request, ClientType type) {
|
||||
request.getContext().result("Authentication is not available with the default authentication method.");
|
||||
request
|
||||
.getContext()
|
||||
.result("Authentication is not available with the default authentication method.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleTokenProcess(AuthenticationRequest request) {
|
||||
request.getContext().result("Authentication is not available with the default authentication method.");
|
||||
request
|
||||
.getContext()
|
||||
.result("Authentication is not available with the default authentication method.");
|
||||
}
|
||||
}
|
||||
|
||||
/** Validates a session token during game login. */
|
||||
public static class SessionTokenValidator implements Authenticator<Account> {
|
||||
@Override
|
||||
public Account authenticate(AuthenticationRequest request) {
|
||||
var tokenRequest = request.getTokenRequest();
|
||||
if (tokenRequest == null) {
|
||||
Grasscutter.getLogger().warn("Invalid session token validator request.");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Prepare the request.
|
||||
var client = Grasscutter.getGameServer().getDispatchClient();
|
||||
var future = new CompletableFuture<Account>();
|
||||
|
||||
client.registerCallback(
|
||||
PacketIds.TokenValidateRsp,
|
||||
packet -> {
|
||||
var data = IDispatcher.decode(packet);
|
||||
|
||||
// Check if the token is valid.
|
||||
var valid = data.get("valid").getAsBoolean();
|
||||
if (!valid) {
|
||||
future.complete(null);
|
||||
return;
|
||||
}
|
||||
|
||||
// Return the account data.
|
||||
future.complete(IDispatcher.decode(data.get("account"), Account.class));
|
||||
});
|
||||
client.sendMessage(PacketIds.TokenValidateReq, tokenRequest);
|
||||
|
||||
try {
|
||||
return future.get(5, TimeUnit.SECONDS);
|
||||
} catch (Exception ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Handles authentication for the web GM Handbook. */
|
||||
public static class HandbookAuthentication implements HandbookAuthenticator {
|
||||
private final String authPage;
|
||||
|
||||
public HandbookAuthentication() {
|
||||
try {
|
||||
this.authPage = new String(FileUtils.readResource("/html/handbook_auth.html"));
|
||||
} catch (Exception ignored) {
|
||||
throw new RuntimeException("Failed to load handbook auth page.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void presentPage(AuthenticationRequest request) {
|
||||
var ctx = request.getContext();
|
||||
if (ctx == null) return;
|
||||
|
||||
// Check to see if an IP authentication can be performed.
|
||||
if (Grasscutter.getRunMode() == ServerRunMode.HYBRID) {
|
||||
var player = Grasscutter.getGameServer().getPlayerByIpAddress(Utils.address(ctx));
|
||||
if (player != null) {
|
||||
// Get the player's session token.
|
||||
var sessionKey = player.getAccount().getSessionKey();
|
||||
// Respond with the handbook auth page.
|
||||
ctx.status(200)
|
||||
.result(
|
||||
this.authPage
|
||||
.replace("{{VALUE}}", "true")
|
||||
.replace("{{SESSION_TOKEN}}", sessionKey)
|
||||
.replace("{{PLAYER_ID}}", String.valueOf(player.getUid())));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Respond with the handbook auth page.
|
||||
ctx.contentType(ContentType.TEXT_HTML).result(this.authPage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response authenticate(AuthenticationRequest request) {
|
||||
var ctx = request.getContext();
|
||||
if (ctx == null) return null;
|
||||
|
||||
// Get the body data.
|
||||
var playerId = ctx.formParam("playerid");
|
||||
if (playerId == null) {
|
||||
return Response.builder().status(400).body("Invalid player ID.").build();
|
||||
}
|
||||
|
||||
try {
|
||||
// Get the player's session token.
|
||||
var sessionKey = DispatchUtils.fetchSessionKey(Integer.parseInt(playerId));
|
||||
if (sessionKey == null) {
|
||||
return Response.builder().status(400).body("Invalid player ID.").build();
|
||||
}
|
||||
|
||||
// Check if the account is banned.
|
||||
return Response.builder()
|
||||
.status(200)
|
||||
.body(
|
||||
this.authPage
|
||||
.replace("{{VALUE}}", "true")
|
||||
.replace("{{SESSION_TOKEN}}", sessionKey)
|
||||
.replace("{{PLAYER_ID}}", playerId))
|
||||
.build();
|
||||
} catch (NumberFormatException ignored) {
|
||||
return Response.builder().status(500).body("Invalid player ID.").build();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,32 +2,31 @@ package emu.grasscutter.auth;
|
||||
|
||||
import emu.grasscutter.auth.AuthenticationSystem.AuthenticationRequest;
|
||||
|
||||
/**
|
||||
* Handles authentication via external routes.
|
||||
*/
|
||||
/** Handles authentication via external routes. */
|
||||
public interface ExternalAuthenticator {
|
||||
|
||||
/**
|
||||
* Called when an external login request is made.
|
||||
*
|
||||
* @param request The authentication request.
|
||||
*/
|
||||
void handleLogin(AuthenticationRequest request);
|
||||
|
||||
/**
|
||||
* Called when an external account creation request is made.
|
||||
* @param request The authentication request.
|
||||
*
|
||||
* For developers: Use AuthenticationRequest#getRequest() to get the request body.
|
||||
* Use AuthenticationRequest#getResponse() to get the response body.
|
||||
* @param request The authentication request.
|
||||
* <p>For developers: Use AuthenticationRequest#getRequest() to get the request body. Use
|
||||
* AuthenticationRequest#getResponse() to get the response body.
|
||||
*/
|
||||
void handleAccountCreation(AuthenticationRequest request);
|
||||
|
||||
/**
|
||||
* Called when an external password reset request is made.
|
||||
* @param request The authentication request.
|
||||
*
|
||||
* For developers: Use AuthenticationRequest#getRequest() to get the request body.
|
||||
* Use AuthenticationRequest#getResponse() to get the response body.
|
||||
* @param request The authentication request.
|
||||
* <p>For developers: Use AuthenticationRequest#getRequest() to get the request body. Use
|
||||
* AuthenticationRequest#getResponse() to get the response body.
|
||||
*/
|
||||
void handlePasswordReset(AuthenticationRequest request);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package emu.grasscutter.auth;
|
||||
|
||||
import emu.grasscutter.auth.AuthenticationSystem.AuthenticationRequest;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
/** Handles player authentication for the web GM handbook. */
|
||||
public interface HandbookAuthenticator {
|
||||
@Getter
|
||||
@Builder
|
||||
class Response {
|
||||
private final int status;
|
||||
private final String body;
|
||||
@Builder.Default private boolean html = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when the user requests to authenticate. This should respond with a page that allows the
|
||||
* user to authenticate.
|
||||
*
|
||||
* @route GET /handbook/authenticate
|
||||
* @param request The authentication request.
|
||||
*/
|
||||
void presentPage(AuthenticationRequest request);
|
||||
|
||||
/**
|
||||
* Invoked when the user requests to authenticate. This is called when the user submits the
|
||||
* authentication form. This should respond with HTML that sends a message to the GM Handbook. See
|
||||
* the default handbook authentication page for an example.
|
||||
*
|
||||
* @param request The authentication request.
|
||||
* @return The response to send to the client.
|
||||
*/
|
||||
Response authenticate(AuthenticationRequest request);
|
||||
}
|
||||
@@ -2,34 +2,33 @@ package emu.grasscutter.auth;
|
||||
|
||||
import emu.grasscutter.auth.AuthenticationSystem.AuthenticationRequest;
|
||||
|
||||
/**
|
||||
* Handles authentication via OAuth routes.
|
||||
*/
|
||||
/** Handles authentication via OAuth routes. */
|
||||
public interface OAuthAuthenticator {
|
||||
|
||||
/**
|
||||
* Called when an OAuth login request is made.
|
||||
*
|
||||
* @param request The authentication request.
|
||||
*/
|
||||
void handleLogin(AuthenticationRequest request);
|
||||
|
||||
/**
|
||||
* Called when a client requests to redirect to login page.
|
||||
*
|
||||
* @param request The authentication request.
|
||||
*/
|
||||
void handleRedirection(AuthenticationRequest request, ClientType clientType);
|
||||
|
||||
/**
|
||||
* Called when an OAuth login requests callback.
|
||||
*
|
||||
* @param request The authentication request.
|
||||
*/
|
||||
void handleTokenProcess(AuthenticationRequest request);
|
||||
|
||||
/**
|
||||
* The type of the client.
|
||||
* Used for handling redirection.
|
||||
*/
|
||||
/** The type of the client. Used for handling redirection. */
|
||||
enum ClientType {
|
||||
DESKTOP, MOBILE
|
||||
DESKTOP,
|
||||
MOBILE
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user