support regex and player name sniff

This commit is contained in:
iceBear67
2026-07-15 21:26:50 +08:00
parent 3a5ad7e318
commit ada07e0e36
11 changed files with 250 additions and 49 deletions
+4 -2
View File
@@ -191,7 +191,8 @@ func (c *Client) dispatchControl(payload []byte) {
pattern, _ := r.String()
ip, _ := r.String()
port, _ := r.U16()
go c.handleControlRequest(cid, pattern, ip, int(port))
username, _ := r.String()
go c.handleControlRequest(cid, pattern, ip, int(port), username)
case CtlPong:
// ignore
default:
@@ -217,12 +218,13 @@ func (c *Client) pingLoop(ctx context.Context, fc *wire.FramedConn) {
// handleControlRequest reacts to a matched player: allocate a worker stream,
// SYN it, and bridge it to the mapped destination.
func (c *Client) handleControlRequest(cid []byte, pattern, ip string, port int) {
func (c *Client) handleControlRequest(cid []byte, pattern, ip string, port int, username string) {
mapping, ok := c.mappings[NormalizeAddress(pattern)]
if !ok {
log.Printf("control-request for unmapped pattern %q; ignoring", pattern)
return
}
log.Printf("player %s:%d joined as %q via pattern %q -> %s", ip, port, username, pattern, mapping.Destination)
wc, sid, err := c.pool.Allocate()
if err != nil {
log.Printf("worker allocate failed: %v", err)