From bcda075b509acb4345bfb074656cf317fb45219c Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Thu, 1 Jun 2017 00:29:45 -0700 Subject: [PATCH 1/3] Change Netty log level to debug --- .../github/satoshinm/WebSandboxMC/ws/WebSocketServerThread.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/satoshinm/WebSandboxMC/ws/WebSocketServerThread.java b/src/main/java/io/github/satoshinm/WebSandboxMC/ws/WebSocketServerThread.java index 48c2349..6729dce 100644 --- a/src/main/java/io/github/satoshinm/WebSandboxMC/ws/WebSocketServerThread.java +++ b/src/main/java/io/github/satoshinm/WebSandboxMC/ws/WebSocketServerThread.java @@ -110,7 +110,7 @@ public void run() { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) - .handler(new LoggingHandler(LogLevel.INFO)) + .handler(new LoggingHandler()) .childHandler(new WebSocketServerInitializer(sslCtx, this, settings.pluginDataFolder)); From 689ba2215d866b57788286b9556bcd7687cbba52 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 3 Jun 2017 16:14:24 -0700 Subject: [PATCH 2/3] Add netty_log_info config option --- README.md | 1 + src/main/java/io/github/satoshinm/WebSandboxMC/Settings.java | 1 + .../io/github/satoshinm/WebSandboxMC/bukkit/SettingsBukkit.java | 2 ++ .../github/satoshinm/WebSandboxMC/ws/WebSocketServerThread.java | 2 +- 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3487eaf..851ee37 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ Configures the HTTP and WebSocket server: Configures what part of your world to expose: * `debug` (false): if true, enables vast amounts of additional logging with FINEST log level +* `netty_log_info` (false): if true, enables Netty connection logging at INFO level instead of DEBUG * `use_permissions` (false): if false, `/websandbox` command requires op; if true, checks for `websandbox.command.`+subcommand permission node * `world` (""): name of world for web clients to spawn in, or an empty string to use the first available * `x_center` (0): specifies the center of the world from the web client's perspective, X coordinate diff --git a/src/main/java/io/github/satoshinm/WebSandboxMC/Settings.java b/src/main/java/io/github/satoshinm/WebSandboxMC/Settings.java index 3b94c6b..80d152b 100644 --- a/src/main/java/io/github/satoshinm/WebSandboxMC/Settings.java +++ b/src/main/java/io/github/satoshinm/WebSandboxMC/Settings.java @@ -15,6 +15,7 @@ abstract public class Settings { public String unbindMethod = "console.getServerConnection.b"; public boolean debug = false; + public boolean nettyLogInfo = false; public boolean usePermissions = false; public String entityClassName = "Sheep"; public boolean setCustomNames = true; diff --git a/src/main/java/io/github/satoshinm/WebSandboxMC/bukkit/SettingsBukkit.java b/src/main/java/io/github/satoshinm/WebSandboxMC/bukkit/SettingsBukkit.java index ac31af8..0c0ff50 100644 --- a/src/main/java/io/github/satoshinm/WebSandboxMC/bukkit/SettingsBukkit.java +++ b/src/main/java/io/github/satoshinm/WebSandboxMC/bukkit/SettingsBukkit.java @@ -26,6 +26,7 @@ public SettingsBukkit(Plugin plugin) { config.addDefault("http.unbind_method", this.unbindMethod); config.addDefault("mc.debug", this.debug); + config.addDefault("mc.nettyLogInfo", this.nettyLogInfo); config.addDefault("mc.use_permissions", this.usePermissions); config.addDefault("mc.entity", this.entityClassName); config.addDefault("mc.entity_custom_names", this.setCustomNames); @@ -60,6 +61,7 @@ public SettingsBukkit(Plugin plugin) { this.unbindMethod = plugin.getConfig().getString("http.unbind_method"); this.debug = plugin.getConfig().getBoolean("mc.debug"); + this.nettyLogInfo = plugin.getConfig().getBoolean("mc.netty_log_info"); this.usePermissions = plugin.getConfig().getBoolean("mc.use_permissions"); this.entityClassName = plugin.getConfig().getString("mc.entity"); diff --git a/src/main/java/io/github/satoshinm/WebSandboxMC/ws/WebSocketServerThread.java b/src/main/java/io/github/satoshinm/WebSandboxMC/ws/WebSocketServerThread.java index 6729dce..f50a141 100644 --- a/src/main/java/io/github/satoshinm/WebSandboxMC/ws/WebSocketServerThread.java +++ b/src/main/java/io/github/satoshinm/WebSandboxMC/ws/WebSocketServerThread.java @@ -110,7 +110,7 @@ public void run() { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) - .handler(new LoggingHandler()) + .handler(settings.nettyLogInfo ? new LoggingHandler(LogLevel.INFO) : new LoggingHandler()) .childHandler(new WebSocketServerInitializer(sslCtx, this, settings.pluginDataFolder)); From 7031187d59510d7a26d5744c4b86372691ed1491 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 3 Jun 2017 16:24:29 -0700 Subject: [PATCH 3/3] Log when a new client joins --- .../satoshinm/WebSandboxMC/bridge/WebPlayerBridge.java | 8 +++++++- .../satoshinm/WebSandboxMC/bukkit/SettingsBukkit.java | 2 +- .../satoshinm/WebSandboxMC/ws/WebSocketFrameHandler.java | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/satoshinm/WebSandboxMC/bridge/WebPlayerBridge.java b/src/main/java/io/github/satoshinm/WebSandboxMC/bridge/WebPlayerBridge.java index 2cd51dd..3edef05 100644 --- a/src/main/java/io/github/satoshinm/WebSandboxMC/bridge/WebPlayerBridge.java +++ b/src/main/java/io/github/satoshinm/WebSandboxMC/bridge/WebPlayerBridge.java @@ -20,6 +20,7 @@ import org.json.simple.JSONObject; import java.math.BigInteger; +import java.net.InetSocketAddress; import java.security.SecureRandom; import java.util.Collection; import java.util.HashMap; @@ -90,11 +91,12 @@ public WebPlayerBridge(WebSocketServerThread webSocketServerThread, Settings set public boolean newPlayer(final Channel channel, String proposedUsername, String token) { String theirName; + boolean wantsAnonymous = proposedUsername.equals(""); // blank = anonymous if (validateClientAuthKey(proposedUsername, token)) { theirName = proposedUsername; // TODO: more features when logging in as an authenticated user: move to their last spawn? } else { - if (!proposedUsername.equals("")) { // blank = anonymous + if (!wantsAnonymous) { webSocketServerThread.sendLine(channel, "T,Failed to login as "+proposedUsername); } @@ -106,6 +108,10 @@ public boolean newPlayer(final Channel channel, String proposedUsername, String int theirID = ++this.lastPlayerID; theirName = "webguest" + theirID; } + String ip = ((InetSocketAddress) channel.remoteAddress()).getHostString() + + ":" + ((InetSocketAddress) channel.remoteAddress()).getPort(); + webSocketServerThread.log(Level.INFO, "New web client joined: " + theirName + + (!wantsAnonymous ? " (authenticated)" : " (anonymous)") + " from " + ip); this.channelId2name.put(channel.id(), theirName); this.name2channel.put(theirName, channel); diff --git a/src/main/java/io/github/satoshinm/WebSandboxMC/bukkit/SettingsBukkit.java b/src/main/java/io/github/satoshinm/WebSandboxMC/bukkit/SettingsBukkit.java index 0c0ff50..b41d1af 100644 --- a/src/main/java/io/github/satoshinm/WebSandboxMC/bukkit/SettingsBukkit.java +++ b/src/main/java/io/github/satoshinm/WebSandboxMC/bukkit/SettingsBukkit.java @@ -26,7 +26,7 @@ public SettingsBukkit(Plugin plugin) { config.addDefault("http.unbind_method", this.unbindMethod); config.addDefault("mc.debug", this.debug); - config.addDefault("mc.nettyLogInfo", this.nettyLogInfo); + config.addDefault("mc.netty_log_info", this.nettyLogInfo); config.addDefault("mc.use_permissions", this.usePermissions); config.addDefault("mc.entity", this.entityClassName); config.addDefault("mc.entity_custom_names", this.setCustomNames); diff --git a/src/main/java/io/github/satoshinm/WebSandboxMC/ws/WebSocketFrameHandler.java b/src/main/java/io/github/satoshinm/WebSandboxMC/ws/WebSocketFrameHandler.java index b685307..c74661d 100644 --- a/src/main/java/io/github/satoshinm/WebSandboxMC/ws/WebSocketFrameHandler.java +++ b/src/main/java/io/github/satoshinm/WebSandboxMC/ws/WebSocketFrameHandler.java @@ -34,6 +34,8 @@ public WebSocketFrameHandler(WebSocketServerThread webSocketServerThread) { @Override public void channelRead0(final ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception { webSocketServerThread.log(Level.FINEST, "channel read, frame="+frame); + // TODO: log at INFO level if this the first data we received from a client (new first connection), to + // help detect clients connecting but not sending authentication commands (in newPlayer) if (frame instanceof BinaryWebSocketFrame) { ByteBuf content = frame.content();