mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-14 14:24:37 +01:00
Log player command usage
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package emu.lunarcore;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import lombok.Getter;
|
||||
@@ -19,13 +18,12 @@ public class Config {
|
||||
public GameServerConfig gameServer = new GameServerConfig("127.0.0.1", 23301);
|
||||
|
||||
public ServerOptions serverOptions = new ServerOptions();
|
||||
public LogOptions logOptions = new LogOptions();
|
||||
public DownloadData downloadData = new DownloadData();
|
||||
|
||||
public String resourceDir = "./resources";
|
||||
public String dataDir = "./data";
|
||||
|
||||
public boolean logPackets = false;
|
||||
|
||||
@Getter
|
||||
public static class DatabaseInfo {
|
||||
public String uri = "mongodb://localhost:27017";
|
||||
@@ -80,6 +78,13 @@ public class Config {
|
||||
public Set<String> defaultPermissions = Set.of("*");
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static class LogOptions {
|
||||
public boolean commands = true;
|
||||
public boolean connections = true;
|
||||
public boolean packets = false;
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static class DownloadData {
|
||||
public String assetBundleUrl = null;
|
||||
|
||||
@@ -112,16 +112,20 @@ public class CommandManager {
|
||||
Command command = handler.getClass().getAnnotation(Command.class);
|
||||
// Check permission
|
||||
if (this.checkPermission(sender, command)) {
|
||||
// Check targetted permission
|
||||
// Check targeted permission
|
||||
CommandArgs cmdArgs = new CommandArgs(sender, args);
|
||||
if (sender != cmdArgs.getTarget() && !this.checkTargetPermission(sender, command)) {
|
||||
handler.sendMessage(sender, "You do not have permission to use this command on another player");
|
||||
handler.sendMessage(sender, "You do not have permission to use this command on another player.");
|
||||
return;
|
||||
}
|
||||
// Log
|
||||
if (sender != null && LunarRail.getConfig().getLogOptions().commands) {
|
||||
LunarRail.getLogger().info("[UID: " + sender.getUid() + "] " + sender.getName() + " used command: " + message);
|
||||
}
|
||||
// Run command
|
||||
handler.execute(sender, cmdArgs);
|
||||
} else {
|
||||
handler.sendMessage(sender, "You do not have permission to use this command");
|
||||
handler.sendMessage(sender, "You do not have permission to use this command.");
|
||||
}
|
||||
} else {
|
||||
if (sender != null) {
|
||||
|
||||
@@ -65,11 +65,15 @@ public class GameSession {
|
||||
}
|
||||
|
||||
public void onConnect() {
|
||||
LunarRail.getLogger().info("Client connected from " + address.getHostString());
|
||||
if (LunarRail.getConfig().getLogOptions().connections) {
|
||||
LunarRail.getLogger().info("Client connected from " + address.getHostString());
|
||||
}
|
||||
}
|
||||
|
||||
public void onDisconnect() {
|
||||
LunarRail.getLogger().info("Client disconnected from " + address.getHostString());
|
||||
if (LunarRail.getConfig().getLogOptions().connections) {
|
||||
LunarRail.getLogger().info("Client disconnected from " + address.getHostString());
|
||||
}
|
||||
|
||||
this.state = SessionState.INACTIVE;
|
||||
|
||||
@@ -116,7 +120,7 @@ public class GameSession {
|
||||
}
|
||||
|
||||
// Log packet
|
||||
if (LunarRail.getConfig().logPackets) {
|
||||
if (LunarRail.getConfig().getLogOptions().packets) {
|
||||
logPacket("RECV", opcode, data);
|
||||
}
|
||||
|
||||
@@ -141,7 +145,7 @@ public class GameSession {
|
||||
this.send(packet.build());
|
||||
|
||||
// Log
|
||||
if (LunarRail.getConfig().logPackets) {
|
||||
if (LunarRail.getConfig().getLogOptions().packets) {
|
||||
logPacket("SEND", packet.getOpcode(), packet.getData());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,9 @@ public class QueryDispatchHandler implements Handler {
|
||||
@Override
|
||||
public void handle(@NotNull Context ctx) throws Exception {
|
||||
// Log
|
||||
LunarRail.getLogger().info("Client request: query_dispatch");
|
||||
if (LunarRail.getConfig().getLogOptions().connections) {
|
||||
LunarRail.getLogger().info("Client request: query_dispatch");
|
||||
}
|
||||
|
||||
// Build region list
|
||||
DispatchRegionData regions = DispatchRegionData.newInstance();
|
||||
|
||||
@@ -44,7 +44,9 @@ public class QueryGatewayHandler implements Handler {
|
||||
}
|
||||
|
||||
// Log
|
||||
LunarRail.getLogger().info("Client request: query_gateway");
|
||||
if (LunarRail.getConfig().getLogOptions().connections) {
|
||||
LunarRail.getLogger().info("Client request: query_gateway");
|
||||
}
|
||||
|
||||
// Encode to base64 and send to client
|
||||
ctx.result(Utils.base64Encode(gateserver.toByteArray()));
|
||||
|
||||
Reference in New Issue
Block a user