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