Log player command usage

This commit is contained in:
Melledy
2023-10-09 20:26:22 -07:00
parent 861feafa08
commit a26b3792d9
5 changed files with 29 additions and 12 deletions

View File

@@ -1,6 +1,5 @@
package emu.lunarcore;
import java.util.HashSet;
import java.util.Set;
import lombok.Getter;
@@ -19,12 +18,11 @@ 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 {
@@ -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;

View File

@@ -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) {

View File

@@ -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());
}
}

View File

@@ -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();

View File

@@ -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()));