Add change password permission to old configs...

...and add optional custom join messages when authing.
This commit is contained in:
ayunami2000 2022-07-24 13:19:06 -04:00
parent ab5b8f6cb5
commit 7c1a55918d
4 changed files with 27 additions and 3 deletions

View File

@ -1,15 +1,19 @@
package net.md_5.bungee.api.config;
import java.util.List;
public class AuthServiceInfo {
private final boolean enabled;
private final String authfile;
private final int ipLimit;
private final List<String> joinMessages;
public AuthServiceInfo(boolean enabled, String authfile, int timeout) {
public AuthServiceInfo(boolean enabled, String authfile, int timeout, List<String> joinMessages) {
this.enabled = enabled;
this.authfile = authfile;
this.ipLimit = timeout;
this.joinMessages = joinMessages;
}
public boolean isEnabled() {
@ -24,4 +28,8 @@ public class AuthServiceInfo {
return ipLimit;
}
public List<String> getJoinMessages() {
return joinMessages;
}
}

View File

@ -18,6 +18,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Level;
@ -68,13 +69,15 @@ public class YamlConfig implements ConfigurationAdapter {
} catch (IOException ex) {
throw new RuntimeException("Could not load configuration!", ex);
}
final Map<String, Object> permissions = this.get("permissions", new HashMap<String, Object>());
final Map<String, List<String>> permissions = this.get("permissions", new HashMap<String, List<String>>());
if (permissions.isEmpty()) {
permissions.put("default", Arrays.asList("bungeecord.command.server", "bungeecord.command.list", "bungeecord.command.eag.domain", "bungeecord.command.eag.changepassword"));
permissions.put("admin", Arrays.asList("bungeecord.command.alert", "bungeecord.command.end", "bungeecord.command.ip", "bungeecord.command.reload",
"bungeecord.command.eag.ban", "bungeecord.command.eag.banwildcard", "bungeecord.command.eag.banip", "bungeecord.command.eag.banregex",
"bungeecord.command.eag.reloadban", "bungeecord.command.eag.banned", "bungeecord.command.eag.banlist", "bungeecord.command.eag.unban", "bungeecord.command.eag.ratelimit",
"bungeecord.command.eag.blockdomain", "bungeecord.command.eag.blockdomainname", "bungeecord.command.eag.unblockdomain"));
} else if (this.get("authservice", new HashMap<String, Object>()).isEmpty() && permissions.containsKey("default") && !permissions.get("default").contains("bungeecord.command.eag.changepassword")) {
permissions.get("default").add("bungeecord.command.eag.changepassword");
}
this.get("groups", new HashMap<String, Object>());
}
@ -275,7 +278,9 @@ public class YamlConfig implements ConfigurationAdapter {
@Override
public AuthServiceInfo getAuthSettings() {
final Map<String, Object> auth = this.get("authservice", new HashMap<String, Object>());
return new AuthServiceInfo(this.get("enabled", false, auth), this.get("authfile", "auths.db", auth), this.get("ip_limit", 0, auth));
final List<String> defaultJoinMessages = new ArrayList<String>();
defaultJoinMessages.add("&3Welcome to my &aEaglercraftBungee &3server!");
return new AuthServiceInfo(this.get("enabled", false, auth), this.get("authfile", "auths.db", auth), this.get("ip_limit", 0, auth), this.get("join_messages", defaultJoinMessages, auth));
}
@Override

View File

@ -50,6 +50,8 @@ public class AuthHandler extends PacketHandler {
this.con.unsafe().sendPacket(new Packet9Respawn(1, (byte) 0, (byte) 2, (short) 255, "END"));
this.con.unsafe().sendPacket(new Packet0DPositionAndLook(0, 0, 0, 0, 0f, 0f, true));
this.con.sendMessages(authSystem.joinMessages);
if (authSystem.isRegistered(this.username)) {
this.con.sendMessage("\u00A7cPlease login to continue! /login <password>");
} else {

View File

@ -1,6 +1,7 @@
package net.md_5.bungee.eaglercraft;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.config.AuthServiceInfo;
import java.io.File;
@ -12,15 +13,23 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AuthSystem {
private final String authFileName;
private final int ipLimit;
public final String[] joinMessages;
public AuthSystem(AuthServiceInfo authInfo) {
this.authFileName = authInfo.getAuthfile();
this.ipLimit = authInfo.getIpLimit();
List<String> listJoinMessages = authInfo.getJoinMessages();
String[] arrayJoinMessages = new String[listJoinMessages.size()];
for (int i = 0; i < listJoinMessages.size(); i++) {
arrayJoinMessages[i] = ChatColor.translateAlternateColorCodes('&', listJoinMessages.get(i));
}
this.joinMessages = arrayJoinMessages;
this.readDatabase();
}