Skip to content

Commit

Permalink
Add debug to config.yml and load config.yml on spigot
Browse files Browse the repository at this point in the history
  • Loading branch information
acrylic-style committed May 19, 2022
1 parent 5c00abf commit cb80d0e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
public class AziPluginMessagingConfig {
public static final Map<String, String> saraShowServers = new ConcurrentHashMap<>();
public static final Map<String, String> rankableServers = new ConcurrentHashMap<>();
public static boolean debug = false;

/**
* Reloads all configuration from config file.
Expand All @@ -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
);
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@

public class Constants {
public static final List<Integer> SARA_GROUPS = Arrays.asList(10000, 5000, 2000, 1000, 500, 100);
public static final boolean DEBUG = true;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -29,6 +30,7 @@ public void onLoad() {
plugin = this;
AziPluginMessaging api = new AziPluginMessagingSpigot(this);
AziPluginMessagingProviderProvider.register(api);
AziPluginMessagingConfig.reload();
}

@Override
Expand All @@ -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());
Expand Down

0 comments on commit cb80d0e

Please sign in to comment.