Minecraft server and HAProxy

Hello can you please help me with understanding and fixing HAProxy redirection from subdomain to minecraft server, more precisely with fixing IF condition without IF condition everything works as it should.

here is the log when trying to connect to the server from the subdomain

tomik520i@tomik520i:~$ sudo tcpdump -i any port 25565 -A
tcpdump: data link type LINUX_SLL2
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
05:44:55.076954 eth0  In  IP _gateway.4995 > tomik520i.25565: Flags [S], seq 4037262724, win 64240, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
E..4..@.}.............c..............|..............
05:44:55.077045 eth0  Out IP tomik520i.25565 > _gateway.4995: Flags [S.], seq 1381928981, ack 4037262725, win 64240, options [mss 1460,nop,nop,sackOK,nop,wscale 7], length 0
E..4..@.@...........c...R^...........@..............
05:44:55.078584 eth0  In  IP _gateway.4995 > tomik520i.25565: Flags [.], ack 1, win 1026, length 0
E..(..@.}.............c.....R^..P.............
05:44:55.078585 eth0  In  IP _gateway.4995 > tomik520i.25565: Flags [P.], seq 1:30, ack 1, win 1026, length 29
E..E..@...............c.....R^..P....F.......minecraft.opicebot.czc..
05:44:55.078585 eth0  In  IP _gateway.4995 > tomik520i.25565: Flags [P.], seq 30:32, ack 1, win 1026, length 2
E..*..@...............c.....R^..P.............
05:44:55.078753 eth0  Out IP tomik520i.25565 > _gateway.4995: Flags [.], ack 30, win 502, length 0
E..(k.@.@.J.........c...R^......P....4..
05:44:55.078773 eth0  Out IP tomik520i.25565 > _gateway.4995: Flags [.], ack 32, win 502, length 0
E..(k.@.@.J.........c...R^......P....4..
05:45:00.081512 eth0  Out IP tomik520i.25565 > _gateway.4995: Flags [F.], seq 1, ack 32, win 502, length 0
E..(k.@.@.J.........c...R^......P....4..
05:45:00.082956 eth0  In  IP _gateway.4995 > tomik520i.25565: Flags [.], ack 2, win 1026, length 0
E..(..@...............c.....R^..P.............
05:45:00.082956 eth0  In  IP _gateway.4995 > tomik520i.25565: Flags [F.], seq 32, ack 2, win 1026, length 0
E..(..@.}.............c.....R^..P.............
05:45:00.083080 eth0  Out IP tomik520i.25565 > _gateway.4995: Flags [.], ack 33, win 502, length 0
E..(..@.@...........c...R^......P...!...
05:45:00.105553 eth0  In  IP _gateway.5003 > tomik520i.25565: Flags [S], seq 1168363033, win 64240, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
E..4..@.}.............c.E...........d...............
05:45:00.105638 eth0  Out IP tomik520i.25565 > _gateway.5003: Flags [S.], seq 795733300, ack 1168363034, win 64240, options [mss 1460,nop,nop,sackOK,nop,wscale 7], length 0
E..4..@.@...........c.../m.4E........@..............
05:45:00.107122 eth0  In  IP _gateway.5003 > tomik520i.25565: Flags [.], ack 1, win 1026, length 0
E..(..@.}.............c.E.../m.5P.............
05:45:00.107122 eth0  In  IP _gateway.5003 > tomik520i.25565: Flags [P.], seq 1:79, ack 1, win 1026, length 78
E..v..@...............c.E.../m.5P.............M.C.|.P.i.n.g.H.o.s.t.1....m.i.n.e.c.r.a.f.t...o.p.i.c.e.b.o.t...c.z..c.
05:45:00.107122 eth0  In  IP _gateway.5003 > tomik520i.25565: Flags [F.], seq 79, ack 1, win 1026, length 0
E..(..@.}.............c.E..h/m.5P.............
05:45:00.107274 eth0  Out IP tomik520i.25565 > _gateway.5003: Flags [.], ack 79, win 502, length 0
E..(:.@.@.{.........c.../m.5E..hP....4..
05:45:00.107890 eth0  Out IP tomik520i.25565 > _gateway.5003: Flags [F.], seq 1, ack 80, win 502, length 0
E..(:.@.@.{.........c.../m.5E..iP....4..
05:45:00.109063 eth0  In  IP _gateway.5003 > tomik520i.25565: Flags [.], ack 2, win 1026, length 0
E..(..@.}.............c.E..i/m.6P.............
^C
19 packets captured
21 packets received by filter
0 packets dropped by kernel

here I am attaching an extract from sudo tail -f /var/log/haproxy.log where it can be seen that haproxy did not assign the frontend to the backend

2024-10-22T05:45:00.081927+00:00 tomik520i haproxy[10301]: 192.168.1.1:4995 [22/Oct/2024:05:44:55.078] minecraft minecraft/<NOSRV> -1/-1/5002 0 SC 3/1/0/0/0 0/0
2024-10-22T05:45:00.107939+00:00 tomik520i haproxy[10301]: 192.168.1.1:5003 [22/Oct/2024:05:45:00.107] minecraft minecraft/<NOSRV> -1/-1/0 0 SC 3/1/0/0/0 0/0

here is my current setup of these two dependencies, a lot of it is copied from chatgpt something like this I’m really trying to do for the first time but I’m trying to start a home server where I’m going to run multiple things at once and this redirection through subdomains seems most ideal to me. https://bluemap.opicebot.cz here I’m already running the server view where you can see that the server is live and is reachable

frontend minecraft
    bind *:25565
    mode tcp
    tcp-request inspect-delay 5s
tcp-request content accept if WAIT_END
    

use_backend minecraft_server if { req.payload(0,100) -m str "minecraft.opicebot.cz" }


backend minecraft_server
    mode tcp
    server mc_server 192.168.1.159:25565

AFAIK it is not possible do perform hostname-based routing for minecraft protocol. Common way to achieve this is to use SRV records to give hint to the minecraft client how to connect to the server.