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