mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-13 13:54:37 +01:00
Add a config option to auto create accounts
This commit is contained in:
@@ -83,6 +83,7 @@ public class Config {
|
||||
|
||||
@Getter
|
||||
public static class ServerOptions {
|
||||
public boolean autoCreateAccount = true;
|
||||
public int entitySceneLimit = 2000;
|
||||
public boolean spendStamina = true;
|
||||
public int staminaRecoveryRate = 5 * 60;
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import emu.lunarcore.LunarCore;
|
||||
import emu.lunarcore.game.account.Account;
|
||||
import emu.lunarcore.game.account.AccountHelper;
|
||||
import emu.lunarcore.server.http.objects.LoginAccountReqJson;
|
||||
import emu.lunarcore.server.http.objects.LoginResJson;
|
||||
import emu.lunarcore.server.http.objects.LoginResJson.VerifyData;
|
||||
@@ -33,13 +34,20 @@ public class UsernameLoginHandler implements Handler {
|
||||
return;
|
||||
}
|
||||
|
||||
// Login
|
||||
// Login - Get account data
|
||||
Account account = LunarCore.getAccountDatabase().getObjectByField(Account.class, "username", req.account);
|
||||
|
||||
if (account == null) {
|
||||
res.retcode = -201;
|
||||
res.message = "Username not found.";
|
||||
} else {
|
||||
// Auto create an account for the player if allowed in the config
|
||||
if (LunarCore.getConfig().getServerOptions().autoCreateAccount) {
|
||||
account = AccountHelper.createAccount(req.account, null, 0);
|
||||
} else {
|
||||
res.retcode = -201;
|
||||
res.message = "Username not found.";
|
||||
}
|
||||
}
|
||||
|
||||
if (account != null) {
|
||||
res.message = "OK";
|
||||
res.data = new VerifyData(account.getUid(), account.getEmail(), account.generateDispatchToken());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user