Skip to main content

Built-in and Optional Handlers

Introduction

The framework provides several Netty Handlers, and developers can choose installation/configuration based on business needs.

NameDescriptionTags
CmdCacheHandlerExternal game server cache.

Built in by default

Smart unload

CmdCheckHandlerChecks whether route exists.

Built in by default

SocketCmdAccessAuthHandlerRoute access verification.

Built in by default

SocketIdleHandlerHeartbeat handling.

Built in by default

UserRequestHandlerForwards requests to logic servers.

Built in by default

SocketUserSessionHandlerManages UserSession.

Built in by default

WebSocketVerifyHandlerToken verification before WebSocket connection.

Built in by default

Smart unload

HttpRealIpHandlerObtains player real IP, usually used when game server is behind an nginx proxy.

Add as needed

Smart unload

SimpleLoggerHandlerPrints logs on exceptions and disconnections.

Built in by default

Configurable switch

Tags description

  • Built in by default: already configured in external server by default.
  • Smart unload: if used before but no longer needed (or never needed), it can be automatically removed from ChannelPipeline.
  • Add as needed: not configured in external server by default; developers can add when needed.
  • Configurable switch: provides related switches; effect is determined by configuration.

Retrieving Player Real IP

Use HttpRealIpHandler to obtain real player IP. Below is extension code for external server.

  • code 7: reuse parent httpHandler method.
  • code 8: add built-in HttpRealIpHandler.
private static ExternalServer ofExternalServer() {
ExternalServerBuilder externalServerBuilder = ...

externalServerBuilder.setMicroBootstrapFlow(new WebSocketMicroBootstrapFlow(){
@Override
public void httpHandler(PipelineContext context) {
super.httpHandler(context);
context.addLast("HttpRealIpHandler", new HttpRealIpHandler());
}
});

return externalServerBuilder.build();
}

nginx related configuration

proxy_http_version 1.1;
proxy_set_header Upgrade websocket;
proxy_set_header Connection "Upgrade";
# Forward client Host and IP info to target node
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host
tip

nginx configuration provided by a helpful community member Contributor: zzzzzZZZZZ

SimpleLoggerHandler

ExternalGlobalConfig.enableLoggerHandler = true;