Built-in and Optional Handlers
Introduction
The framework provides several Netty Handlers, and developers can choose installation/configuration based on business needs.
| Name | Description | Tags |
|---|---|---|
| CmdCacheHandler | External game server cache. | Built in by default Smart unload |
| CmdCheckHandler | Checks whether route exists. | Built in by default |
| SocketCmdAccessAuthHandler | Route access verification. | Built in by default |
| SocketIdleHandler | Heartbeat handling. | Built in by default |
| UserRequestHandler | Forwards requests to logic servers. | Built in by default |
| SocketUserSessionHandler | Manages UserSession. | Built in by default |
| WebSocketVerifyHandler | Token verification before WebSocket connection. | Built in by default Smart unload |
| HttpRealIpHandler | Obtains player real IP, usually used when game server is behind an nginx proxy. | Add as needed Smart unload |
| SimpleLoggerHandler | Prints 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
httpHandlermethod. - 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;