diff --git a/api/src/main/java/net/azisaba/azipluginmessaging/api/AziPluginMessagingConfig.java b/api/src/main/java/net/azisaba/azipluginmessaging/api/AziPluginMessagingConfig.java index 950006b..c1a0549 100644 --- a/api/src/main/java/net/azisaba/azipluginmessaging/api/AziPluginMessagingConfig.java +++ b/api/src/main/java/net/azisaba/azipluginmessaging/api/AziPluginMessagingConfig.java @@ -16,6 +16,7 @@ public class AziPluginMessagingConfig { public static final Map saraShowServers = new ConcurrentHashMap<>(); public static final Map rankableServers = new ConcurrentHashMap<>(); + public static boolean debug = false; /** * Reloads all configuration from config file. @@ -33,12 +34,16 @@ public static void reload() { Files.write( configPath, Arrays.asList( - "saraShowServers:", + "saraShowServers: # this is meaningless in spigot", " life: life", " lifepve: life", - "rankableServers:", + "rankableServers: # this is meaningless in spigot", " life: life", - " lifepve: life" + " lifepve: life", + "", + "# Whether to enable the debug logging.", + "# If turned on, many things will be logged, including public key of a connection and packet in/out, for example.", + "debug: false" ), StandardOpenOption.CREATE ); @@ -50,6 +55,7 @@ public static void reload() { YamlObject obj = new YamlConfiguration(configPath.toAbsolutePath().toString()).asObject(); readMap(rankableServers, obj, "rankableServers"); readMap(saraShowServers, obj, "saraShowServers"); + debug = obj.getBoolean("debug", false); } catch (IOException ex) { Logger.getCurrentLogger().warn("Failed to read config.yml", ex); } diff --git a/api/src/main/java/net/azisaba/azipluginmessaging/api/protocol/Protocol.java b/api/src/main/java/net/azisaba/azipluginmessaging/api/protocol/Protocol.java index 6ecbbfc..6d6be46 100644 --- a/api/src/main/java/net/azisaba/azipluginmessaging/api/protocol/Protocol.java +++ b/api/src/main/java/net/azisaba/azipluginmessaging/api/protocol/Protocol.java @@ -1,5 +1,6 @@ package net.azisaba.azipluginmessaging.api.protocol; +import net.azisaba.azipluginmessaging.api.AziPluginMessagingConfig; import net.azisaba.azipluginmessaging.api.AziPluginMessagingProvider; import net.azisaba.azipluginmessaging.api.Logger; import net.azisaba.azipluginmessaging.api.protocol.handler.MessageHandler; @@ -23,7 +24,6 @@ import net.azisaba.azipluginmessaging.api.protocol.message.ServerboundActionResponseMessage; import net.azisaba.azipluginmessaging.api.server.PacketSender; import net.azisaba.azipluginmessaging.api.server.ServerConnection; -import net.azisaba.azipluginmessaging.api.util.Constants; import net.azisaba.azipluginmessaging.api.util.EncryptionUtil; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -130,7 +130,7 @@ public boolean sendPacket(@Nullable PacketSender sender, @NotNull M msg) { throw new RuntimeException("Could not encrypt the packet (sender: " + sender + ")", e); } } - if (Constants.DEBUG) { + if (AziPluginMessagingConfig.debug) { String hex = Integer.toString(id, 16); if (hex.length() == 1) hex = '0' + hex; Logger.getCurrentLogger().info("Sending packet {} (0x{}) to {} (encrypted: {})", id, hex, sender, sender.isEncrypted()); @@ -171,7 +171,7 @@ public static void handleProxySide(ServerConnection server, byte[] rawData) { server, id); return; } - if (Constants.DEBUG) { + if (AziPluginMessagingConfig.debug) { String hex = Integer.toString(id, 16); if (hex.length() == 1) hex = '0' + hex; Logger.getCurrentLogger().info("Received packet {} (0x{}) from server connection {} (encrypted: {})", id, hex, server, server.isEncrypted()); @@ -214,7 +214,7 @@ public static void handleServerSide(@NotNull PacketSender sender, byte[] rawData Logger.getCurrentLogger().warn("Received unknown protocol id from {}: {}", sender, id); return; } - if (Constants.DEBUG) { + if (AziPluginMessagingConfig.debug) { String hex = Integer.toString(id, 16); if (hex.length() == 1) hex = '0' + hex; Logger.getCurrentLogger().info("Received packet {} (0x{}) from {}", id, hex, sender); diff --git a/api/src/main/java/net/azisaba/azipluginmessaging/api/protocol/handler/ProxyboundEncryptionPacket.java b/api/src/main/java/net/azisaba/azipluginmessaging/api/protocol/handler/ProxyboundEncryptionPacket.java index 181bdfa..e55df37 100644 --- a/api/src/main/java/net/azisaba/azipluginmessaging/api/protocol/handler/ProxyboundEncryptionPacket.java +++ b/api/src/main/java/net/azisaba/azipluginmessaging/api/protocol/handler/ProxyboundEncryptionPacket.java @@ -1,11 +1,11 @@ package net.azisaba.azipluginmessaging.api.protocol.handler; +import net.azisaba.azipluginmessaging.api.AziPluginMessagingConfig; import net.azisaba.azipluginmessaging.api.Logger; import net.azisaba.azipluginmessaging.api.protocol.Protocol; import net.azisaba.azipluginmessaging.api.protocol.message.EncryptionMessage; import net.azisaba.azipluginmessaging.api.server.PacketSender; import net.azisaba.azipluginmessaging.api.server.ServerConnection; -import net.azisaba.azipluginmessaging.api.util.Constants; import net.azisaba.azipluginmessaging.api.util.EncryptionUtil; import org.jetbrains.annotations.NotNull; @@ -43,7 +43,7 @@ public void handle(@NotNull PacketSender sender, @NotNull EncryptionMessage msg) // Enable encryption sender.setEncrypted(true); - if (Constants.DEBUG) { + if (AziPluginMessagingConfig.debug) { Logger.getCurrentLogger().info("Encryption enabled for " + sender); } } diff --git a/api/src/main/java/net/azisaba/azipluginmessaging/api/protocol/handler/ServerboundEncryptionPacket.java b/api/src/main/java/net/azisaba/azipluginmessaging/api/protocol/handler/ServerboundEncryptionPacket.java index 1c0b736..563dc35 100644 --- a/api/src/main/java/net/azisaba/azipluginmessaging/api/protocol/handler/ServerboundEncryptionPacket.java +++ b/api/src/main/java/net/azisaba/azipluginmessaging/api/protocol/handler/ServerboundEncryptionPacket.java @@ -1,11 +1,11 @@ package net.azisaba.azipluginmessaging.api.protocol.handler; +import net.azisaba.azipluginmessaging.api.AziPluginMessagingConfig; import net.azisaba.azipluginmessaging.api.AziPluginMessagingProvider; import net.azisaba.azipluginmessaging.api.Logger; import net.azisaba.azipluginmessaging.api.entity.Player; import net.azisaba.azipluginmessaging.api.protocol.message.EncryptionMessage; import net.azisaba.azipluginmessaging.api.server.PacketSender; -import net.azisaba.azipluginmessaging.api.util.Constants; import org.jetbrains.annotations.NotNull; import java.io.DataInputStream; @@ -36,7 +36,7 @@ public void handle(@NotNull PacketSender sender, @NotNull EncryptionMessage msg) // Enable encryption sender.setEncrypted(true); - if (Constants.DEBUG) { + if (AziPluginMessagingConfig.debug) { Logger.getCurrentLogger().info("Encryption enabled for " + sender); } diff --git a/api/src/main/java/net/azisaba/azipluginmessaging/api/util/Constants.java b/api/src/main/java/net/azisaba/azipluginmessaging/api/util/Constants.java index f494336..ebfccff 100644 --- a/api/src/main/java/net/azisaba/azipluginmessaging/api/util/Constants.java +++ b/api/src/main/java/net/azisaba/azipluginmessaging/api/util/Constants.java @@ -5,5 +5,4 @@ public class Constants { public static final List SARA_GROUPS = Arrays.asList(10000, 5000, 2000, 1000, 500, 100); - public static final boolean DEBUG = true; } diff --git a/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/SpigotPlugin.java b/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/SpigotPlugin.java index 055faa5..63a8726 100644 --- a/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/SpigotPlugin.java +++ b/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/SpigotPlugin.java @@ -1,6 +1,7 @@ package net.azisaba.azipluginmessaging.spigot; import net.azisaba.azipluginmessaging.api.AziPluginMessaging; +import net.azisaba.azipluginmessaging.api.AziPluginMessagingConfig; import net.azisaba.azipluginmessaging.api.AziPluginMessagingProvider; import net.azisaba.azipluginmessaging.api.AziPluginMessagingProviderProvider; import net.azisaba.azipluginmessaging.api.protocol.Protocol; @@ -29,6 +30,7 @@ public void onLoad() { plugin = this; AziPluginMessaging api = new AziPluginMessagingSpigot(this); AziPluginMessagingProviderProvider.register(api); + AziPluginMessagingConfig.reload(); } @Override @@ -39,6 +41,9 @@ public void onEnable() { Bukkit.getMessenger().registerIncomingPluginChannel(this, Protocol.LEGACY_CHANNEL_ID, new PluginMessageReceiver()); } catch (IllegalArgumentException e) { getLogger().info("Could not register legacy channel, you can ignore this message if you're running on 1.13+"); + if (AziPluginMessagingConfig.debug) { + e.printStackTrace(); + } } Bukkit.getMessenger().registerOutgoingPluginChannel(this, Protocol.CHANNEL_ID); Bukkit.getMessenger().registerIncomingPluginChannel(this, Protocol.CHANNEL_ID, new PluginMessageReceiver());