Merge pull request #54 from Grasscutters/auto-account

Fix permission issues when new users create an account
This commit is contained in:
Melledy 2022-04-20 07:53:24 -07:00 committed by GitHub
commit e4b622800e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 5 deletions

View File

@ -53,5 +53,6 @@ public final class Config {
public int MaxEntityLimit = 1000; // Max entity limit per world. // TODO: Enforce later. public int MaxEntityLimit = 1000; // Max entity limit per world. // TODO: Enforce later.
public int[] WelcomeEmotes = {2007, 1002, 4010}; public int[] WelcomeEmotes = {2007, 1002, 4010};
public String WelcomeMotd = "Welcome to Grasscutter emu"; public String WelcomeMotd = "Welcome to Grasscutter emu";
public boolean AutomaticallyCreateAccounts = false;
} }
} }

View File

@ -91,7 +91,7 @@ public final class CommandMap {
public void invoke(GenshinPlayer player, String rawMessage) { public void invoke(GenshinPlayer player, String rawMessage) {
rawMessage = rawMessage.trim(); rawMessage = rawMessage.trim();
if(rawMessage.length() == 0) { if(rawMessage.length() == 0) {
CommandHandler.sendMessage(player, "No command specified."); CommandHandler.sendMessage(player, "No command specified."); return;
} }
// Remove prefix if present. // Remove prefix if present.
@ -113,7 +113,7 @@ public final class CommandMap {
if(player != null) { if(player != null) {
String permissionNode = this.annotations.get(label).permission(); String permissionNode = this.annotations.get(label).permission();
Account account = player.getAccount(); Account account = player.getAccount();
if(permissionNode != "" && !account.hasPermission(permissionNode)) { if(!permissionNode.isEmpty() && !account.hasPermission(permissionNode)) {
CommandHandler.sendMessage(player, "You do not have permission to run this command."); return; CommandHandler.sendMessage(player, "You do not have permission to run this command."); return;
} }
} }

View File

@ -188,6 +188,7 @@ public final class ServerCommands {
} else { } else {
CommandHandler.sendMessage(null, "Account created with UID " + account.getPlayerId() + "."); CommandHandler.sendMessage(null, "Account created with UID " + account.getPlayerId() + ".");
account.addPermission("*"); // Grant the player superuser permissions. account.addPermission("*"); // Grant the player superuser permissions.
account.save(); // Save account to database.
} }
return; return;
case "delete": case "delete":

View File

@ -225,11 +225,23 @@ public final class DispatchServer {
// Login // Login
Account account = DatabaseHelper.getAccountByName(requestData.account); Account account = DatabaseHelper.getAccountByName(requestData.account);
// Test // Check if account exists, else create a new one.
if (account == null) { if (account == null) {
responseData.retcode = -201; // Account doesnt exist, so we can either auto create it if the config value is set
responseData.message = "Username not found."; if (Grasscutter.getConfig().ServerOptions.AutomaticallyCreateAccounts) {
// This account has been created AUTOMATICALLY. There will be no permissions added.
account = DatabaseHelper.createAccountWithId(requestData.account, 0);
responseData.message = "OK";
responseData.data.account.uid = account.getId();
responseData.data.account.token = account.generateSessionKey();
responseData.data.account.email = account.getEmail();
} else {
responseData.retcode = -201;
responseData.message = "Username not found.";
}
} else { } else {
// Account was found, log the player in
responseData.message = "OK"; responseData.message = "OK";
responseData.data.account.uid = account.getId(); responseData.data.account.uid = account.getId();
responseData.data.account.token = account.generateSessionKey(); responseData.data.account.token = account.generateSessionKey();