From 7c1a55918d76ea35784d435e52b27dd5cac2775a Mon Sep 17 00:00:00 2001 From: ayunami2000 Date: Sun, 24 Jul 2022 13:19:06 -0400 Subject: [PATCH] Add change password permission to old configs... ...and add optional custom join messages when authing. --- .../net/md_5/bungee/api/config/AuthServiceInfo.java | 10 +++++++++- .../main/java/net/md_5/bungee/config/YamlConfig.java | 9 +++++++-- .../java/net/md_5/bungee/eaglercraft/AuthHandler.java | 2 ++ .../java/net/md_5/bungee/eaglercraft/AuthSystem.java | 9 +++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/eaglercraftbungee/src/main/java/net/md_5/bungee/api/config/AuthServiceInfo.java b/eaglercraftbungee/src/main/java/net/md_5/bungee/api/config/AuthServiceInfo.java index a971f7c..454026b 100644 --- a/eaglercraftbungee/src/main/java/net/md_5/bungee/api/config/AuthServiceInfo.java +++ b/eaglercraftbungee/src/main/java/net/md_5/bungee/api/config/AuthServiceInfo.java @@ -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 joinMessages; - public AuthServiceInfo(boolean enabled, String authfile, int timeout) { + public AuthServiceInfo(boolean enabled, String authfile, int timeout, List 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 getJoinMessages() { + return joinMessages; + } + } diff --git a/eaglercraftbungee/src/main/java/net/md_5/bungee/config/YamlConfig.java b/eaglercraftbungee/src/main/java/net/md_5/bungee/config/YamlConfig.java index 06a5d89..e57144e 100644 --- a/eaglercraftbungee/src/main/java/net/md_5/bungee/config/YamlConfig.java +++ b/eaglercraftbungee/src/main/java/net/md_5/bungee/config/YamlConfig.java @@ -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 permissions = this.get("permissions", new HashMap()); + final Map> permissions = this.get("permissions", new HashMap>()); 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()).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()); } @@ -275,7 +278,9 @@ public class YamlConfig implements ConfigurationAdapter { @Override public AuthServiceInfo getAuthSettings() { final Map auth = this.get("authservice", new HashMap()); - return new AuthServiceInfo(this.get("enabled", false, auth), this.get("authfile", "auths.db", auth), this.get("ip_limit", 0, auth)); + final List defaultJoinMessages = new ArrayList(); + 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 diff --git a/eaglercraftbungee/src/main/java/net/md_5/bungee/eaglercraft/AuthHandler.java b/eaglercraftbungee/src/main/java/net/md_5/bungee/eaglercraft/AuthHandler.java index d94c281..60f0597 100644 --- a/eaglercraftbungee/src/main/java/net/md_5/bungee/eaglercraft/AuthHandler.java +++ b/eaglercraftbungee/src/main/java/net/md_5/bungee/eaglercraft/AuthHandler.java @@ -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 "); } else { diff --git a/eaglercraftbungee/src/main/java/net/md_5/bungee/eaglercraft/AuthSystem.java b/eaglercraftbungee/src/main/java/net/md_5/bungee/eaglercraft/AuthSystem.java index cbd881b..1c8f40d 100644 --- a/eaglercraftbungee/src/main/java/net/md_5/bungee/eaglercraft/AuthSystem.java +++ b/eaglercraftbungee/src/main/java/net/md_5/bungee/eaglercraft/AuthSystem.java @@ -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 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(); }