Documentation
¶
Overview ¶
Package handler contains transport-layer adapters for the gateway feature (WS-A): the gnet TCP event handler and the WebSocket upgrade handler for the kRO / roBrowser client ingress.
Index ¶
- type TCPHandler
- func (h *TCPHandler) Engine() gnet.Engine
- func (h *TCPHandler) OnBoot(eng gnet.Engine) gnet.Action
- func (h *TCPHandler) OnClose(c gnet.Conn, err error) gnet.Action
- func (h *TCPHandler) OnOpen(c gnet.Conn) ([]byte, gnet.Action)
- func (h *TCPHandler) OnShutdown(eng gnet.Engine)
- func (h *TCPHandler) OnTraffic(c gnet.Conn) gnet.Action
- type WSHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TCPHandler ¶
type TCPHandler struct {
gnet.BuiltinEventEngine
// contains filtered or unexported fields
}
TCPHandler implements gnet.EventHandler for the gateway's kRO TCP ingress.
One TCPHandler owns the packet DB (shared, read-only after construction) and a single PacketHandler that owns the business dispatch. Per-connection state — a login-mode Decoder and a connection-id counter — lives in gnet.Conn.SetContext / Context, never in TCPHandler fields, so gnet's multicore event-loop model remains safe.
func NewTCPHandler ¶
func NewTCPHandler(db *packet.DB, handler domain.PacketHandler, logger zerolog.Logger) *TCPHandler
NewTCPHandler constructs a gnet TCP event handler. The packet DB and PacketHandler must already be configured; TCPHandler does not own their lifecycle.
func (*TCPHandler) Engine ¶
func (h *TCPHandler) Engine() gnet.Engine
Engine returns the gnet.Engine captured at OnBoot. It is nil before the engine boots. Used by the composition root to invoke Engine.Stop for graceful shutdown (gnet.Stop is deprecated in v2).
func (*TCPHandler) OnBoot ¶
func (h *TCPHandler) OnBoot(eng gnet.Engine) gnet.Action
OnBoot logs the engine start and captures the engine handle for later graceful shutdown. gnet calls this once per process.
func (*TCPHandler) OnOpen ¶
OnOpen creates a per-connection login-mode Decoder and stores it in gnet.Conn context. The connection id is monotonic; gnet does not guarantee uniqueness across restarts but does guarantee uniqueness within a process — which is what handlers need.
func (*TCPHandler) OnShutdown ¶
func (h *TCPHandler) OnShutdown(eng gnet.Engine)
OnShutdown logs the engine stop. gnet calls this when the listener exits cleanly (gnet.Stop or signal).
func (*TCPHandler) OnTraffic ¶
func (h *TCPHandler) OnTraffic(c gnet.Conn) gnet.Action
OnTraffic drains the inbound buffer into the connection's Decoder, extracts as many packets as are available, and dispatches each to the PacketHandler. Returns gnet.Close on any non-ErrIncomplete decoder error so a malformed or unknown packet tears the connection down (matches rathena/src/map/clif.cpp:25718-25744).
type WSHandler ¶
type WSHandler struct {
// contains filtered or unexported fields
}
WSHandler accepts roBrowser WebSocket connections at the configured path, receives kRO packets as binary WebSocket messages, and decodes them through the same codec pipeline as TCPHandler.
One WSHandler owns the packet DB (shared, read-only after construction) and a single PacketHandler that owns the business dispatch. Per- connection state — a login-mode Decoder and a connection-id counter — lives on the WSHandler. Read loops for each connection run in their own goroutines; WSHandler is safe to use with concurrent connections.
func NewWSHandler ¶
func NewWSHandler(db *packet.DB, handler domain.PacketHandler, addr, path string, logger zerolog.Logger, allowedOrigins []string) *WSHandler
NewWSHandler constructs an HTTP/WebSocket upgrade handler. The packet DB and PacketHandler must already be configured; WSHandler does not own their lifecycle. addr is the listen address (e.g. ":6901") and path is the URL path that triggers the upgrade (e.g. "/ws/"). allowedOrigins is the CSWSH origin allowlist applied to the upgrade; when empty, origin verification is disabled and a warning is logged per connection (dev default). Production deployments must pass a non-empty allowlist.
func (*WSHandler) ServeHTTP ¶
func (h *WSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP upgrades the HTTP connection to WebSocket and runs the read loop until the peer closes or a decode error tears the connection down. roBrowser sends kRO packets as binary WS messages; each message may contain one or more complete packets, or a partial packet — the codec's internal buffer handles framing.