Skip to content

Commit

Permalink
Merge pull request #85 from satoshinm/nettylog
Browse files Browse the repository at this point in the history
Add netty_log_info, reduce Netty log by default, log join. Closes GH-84
  • Loading branch information
satoshinm authored Jun 3, 2017
2 parents 6f3a71e + 7031187 commit 5d0ccff
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public SettingsBukkit(Plugin plugin) {
config.addDefault("http.unbind_method", this.unbindMethod);

config.addDefault("mc.debug", this.debug);
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);
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void run() {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.INFO))
.handler(settings.nettyLogInfo ? new LoggingHandler(LogLevel.INFO) : new LoggingHandler())
.childHandler(new WebSocketServerInitializer(sslCtx, this,
settings.pluginDataFolder));

Expand Down

0 comments on commit 5d0ccff

Please sign in to comment.