Skip to content

Let a host keep out players whose ping is over a limit - #6

Draft
medic-code wants to merge 10 commits into
upstream-mainfrom
feat/host-ping-limit
Draft

medic-code wants to merge 10 commits into
upstream-mainfrom
feat/host-ping-limit

Conversation

@medic-code

@medic-code medic-code commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

Why

Hosts cannot keep players with a high ping out of their games. Today a host has to spot the number and kick each player by hand.

Hosts asked for a limit (wacko, on the OpenCE Discord).

What it does

  • A new host setting, HOST PING LIMIT under Settings > Network Setup: OFF (the default), or 100, 150, 200, 250 or 300 ms.
  • In the lobby, a player whose ping stays over the limit for about 3 seconds is removed, the same way as the host's own kick, and can try again.
  • A player who joins a match already under way is checked for their first 10 seconds only. A player who came in through the lobby is not checked again when the match starts. No one is removed in the middle of a match, and one slow moment removes no one.
  • Players on the host's own computer and on the local network are never removed.
  • The ping is measured every second, also while game traffic flows, so the host judges a current number. The server browser's ping for a direct-link game is fresher too.
  • A dedicated server can change the limit while it runs: sv_set network.host_ping_limit 150.
  • Nothing new is sent between computers, so the network version stays the same.

Screenshots

Look at the HOST PING LIMIT row in Network Setup: set to 150 MS, with its help line below.

HOST PING LIMIT in Network Setup

Details

  • Flow: network_game_server_handle_client_machines (each frame, on the host) → network_ping_limit_check for each joined client machine not on the host's machine → once a second, the tunnel's round trip for that machine's stand-in address → the median of the latest five → over the limit: the console line, then the existing kick path (_rejection_code_blacklisted_machine, drop).
  • port/linux/game/network_ping_limit.c (new): the samples per machine slot, the median and the threshold, and when a machine is judged (lobby; first 10 s of a join in progress, unless the machine was in the lobby; not while downloading). It finds the round trip through p2p_peer_key_hash and p2p_peer_ping, which already exist; stand-in addresses are 100.64.0.0/10, so a LAN address is never asked about. The notice is sent as network_distributed_kick sends a kick's.
  • source/networking/network_server_manager.c: three port: additions. The declarations; resetting the slot's samples when a machine joins (next to the vote kick's and voice chat's resets); and in the per-machine loop, the call, which sets _kick_rejoinable so that the existing kick branch tells and drops the machine in the same pass.
  • port/linux/src/p2p.c: a peer is pinged every second whether or not traffic flows, so its round trip stays current in a match.
  • port/linux/game/server_commands.c, docs/dedicated_server.md, tools/server_sim.py: sv_set accepts the setting on a dedicated server.
  • port/linux/src/port_config.c, port/linux/README.md: the setting (0, HALO_NET_HOST_PING_LIMIT) and its row in the settings table.
  • tools/port_settings.py, network_setup.xml: the HOST PING LIMIT row. The XML is regenerated from settings_files(); only network_setup.xml changed.
  • tools/harness/tests/ping_limit.c, test_ping_limit.py: the decision as compiled from the source against a fake tunnel, clock and setting, and a check that peer_send leaves the ping timer alone.

User experience

  1. The host opens Settings > Network Setup, sets HOST PING LIMIT to 150 MS, and presses OK.
  2. The host creates an internet game. Players join from the server browser or an invite.
  3. A player whose ping stays above 150 ms is in the lobby for about 3 seconds, then is back at the main menu with "Failed to join the game." The host's console, and the removed player's, show Player removed: ping 201 ms, over the host's limit of 150 ms.
  4. A player at 80 ms with one 900 ms spike stays.
  5. Players already in a match are never removed by the limit. A player who joins a match in progress is checked for its first 10 seconds.
  6. With HOST PING LIMIT OFF (the default), nothing changes.

How to test

  1. python3 configure.py && ninja linux
  2. python3 -m pytest -q tools/harness/tests/test_ping_limit.py
  3. Two copies on one Linux machine (network.address 127.0.0.2 and 127.0.0.3): the host sets HALO_NET_HOST_PING_LIMIT=100 and creates a public internet game; the client sets HALO_NET_TUNNEL_PORT=40003 and joins from the server browser. Delay the client's tunnel by 200 ms: tc qdisc add dev lo root handle 1: prio && tc qdisc add dev lo parent 1:3 handle 30: netem delay 200ms && tc filter add dev lo protocol ip parent 1:0 prio 3 u32 match ip protocol 17 0xff match ip dport 40003 0xffff flowid 1:3 (the tunnel reaches the client at the machine's own address, so a filter on 127.0.0.3 misses it).
  4. Watch the host's console or log for removed: ping; the client returns to the main menu.
  5. Set the limit to 300 (or OFF): the client stays in the lobby.

Tested

  • ninja linux at each of the 10 commits, in the halo-toolchain container on the NAS.
  • tools/harness/tests/test_ping_limit.py: 18 cases (median, one spike, at the limit, off, kicked at the third second, staying under, once a second, byte order, LAN exempt, no round trip, first 10 s of a join in progress, after them, from the lobby into the match, downloading, a new machine at the slot, a slow first sample, recovery after a download, recovery after the limit is turned off) and 12 negative controls, each failing its case; the default, the server's guards, and peer_send leaving the ping timer alone.
  • At the tip, tools/harness, tools/test_touch_menu.py and tools/test_server_sim.py: 1679 passed, 1 skipped.
  • Before the last four commits, python3 -m pytest -q tools/test_linux_port.py tools/test_web_build.py tools/harness: 913 passed, 2 skipped, 2 failed. The two failures (test_retail_maps_need_no_corrections, test_tag_validator_survives_damaged_maps: "map_validate: the Custom Edition tag cache's address (40440000) is taken") fail the same way on origin/main in the same container.
  • Network Setup's XML written by port_settings.settings_files() reproduces the committed files on origin/main; after the change only network_setup.xml differs.
  • Stale ping, two copies on the NAS: before the p2p.c change the host timed 0 round trips during the match (about 14 s apart in the lobby); after it, 85 round trips 1000 to 1009 ms apart, 34 in the lobby and 51 in the match.
  • Before the last four commits, two copies on loopback (null renderer, network_test host and browse, a local MQTT broker), the client's tunnel port delayed 200 ms with tc netem, the host's samples logged by a throwaway instrumented copy:
    • Limit off: the client joins and stays to the end, about 58 s.
    • Limit 100, client at 201 ms: three samples of 201 ms, kicked 2.0 s after joining the lobby; the client logs the host: Player removed: ping 201 ms, over the host's limit of 100 ms and reason= #6/_rejection_code_blacklisted_machine.
    • Limit 300, client at 201 ms: 56 samples, median 201, stays to the end.
    • Limit 100, system link client at 201 ms: no round trip timed, stays.
    • Limit 100, client at 201 ms joins a game in progress: kicked 2.0 s after joining. The kick ended that match, and the host then crashed 8 s later: the crash at every match end in test runs without a window, fixed by Keep the postgame scoreboard from drawing hi-res sprites without GL OpenCommunityEdition/OpenCE#483, not by this change.
    • Limit 100, the delay added as the match starts: in-game round trips of 244 to 282 ms, no kick, the player in the match to the end.
  • A real internet game between two machines.
  • The notice on screen over the lobby's menus (the runs had no renderer; the line is in the removed machine's log).
  • ninja android, ninja web: built by fork CI at 7f8dbb7, not locally.
  • Network Setup's new row seen and changed in the menus.
  • CI on the fork at 7f8dbb7: Linux, Android, web and Windows.

Hosts asked to keep players with a high ping out of their games. This
is the judgement the host will make, not yet called: one round trip a
second from the internet play tunnel (the same ping the server
browser's PING column shows), the median of the latest five once there
are three, over the limit or not. One slow round trip kicks no one. A
machine is judged in the lobby and in its first ten seconds in a game
it joined in progress, never while it downloads the maps, and never if
the tunnel does not reach it (a system link machine).

Checked: tools/harness/tests/test_ping_limit.py, 17 cases and 10
negative controls, in the halo-toolchain container.
Hosts asked to keep players with a high ping out of their games. With
network.host_ping_limit set (milliseconds; 0, the default, is no
limit), the host's server judges each joined client machine not its own
once a second, in the lobby until the start is sent and in a machine's
first ten seconds in a game it joined in progress, and kicks one whose
median round trip is over the limit as the host's kick does: told
_rejection_code_blacklisted_machine, dropped, free to join again. A
notice names the players, their ping and the limit, sent as a kick's
is. No player is kicked mid-match, where it would lose a match it is
playing.

Nothing new is sent: the kick is the existing message and value, so
the network version stays 41.

Checked: test_ping_limit.py (17 cases, 10 negative controls, the
default and the server's guards) and ninja linux in the halo-toolchain
container; two copies on loopback with the client's tunnel delayed
200 ms by netem: at a limit of 100 the client was kicked 2 s after
joining the lobby and 2 s after joining a game in progress, and the
notice reached its console; at 300, or off, it stayed; a system link
client at 200 ms stayed; a client whose ping rose at the match's start
stayed in the match.
A host sets network.host_ping_limit in the menus: OFF, 100, 150, 200,
250 or 300 MS. Server Setup has no free row (its twelve fill the
screen, as do Teamplay Options'), so the row goes on Network Setup with
this machine's other network settings; its pages in a game are
unchanged.

With it the desktop's Network Setup has ten places, and at the 30px
step the last (DISCORD ACCOUNT, 343 to 371) would cover the help (from
350). Network Setup steps 28px with the help at 358, as Video Setup
does since 860c8d5: its last place ends at 353, the help at 412, clear
of the buttons (414).

Checked: tools/ce_menus.py --settings-only reproduces origin/main's
XML unchanged, and after the change writes only network_setup.xml.
The ring kept a count and a next place that every reset had to clear
together. One count of round trips taken gives both (the place is the
count modulo five, the number judged at most five), so each reset is one
line. The round trips are kept as longs, as the tunnel gives them, so
the 9999 ms cap and its casts go, and the median is worked out once
before it is judged against the limit.

Checked: test_ping_limit.py gives the same results as before the
change (built 64-bit on macOS, where the byte-order cases fail before
and after; the 32-bit run is on the NAS).
recovery-download and recovery-disabled cover the reset when a machine
starts downloading the maps or the limit is turned off, but no fault
showed they would see it removed. pause-keeps-samples drops the reset
and expects recovery-download to fail.
The header keeps why a machine is judged only early in a game, why a
system link machine has none, why downloads pause it and why the kick
reuses the blacklisted reason; the byte order and the notice length
keep theirs. Comments that restated names, fields or parameters go,
and the port: markers in network_server_manager.c are shortened.
peer_send reset sent_time on every send, so a connected peer was
pinged only after a second with nothing sent. With a client joined,
the host timed a round trip about every 14 s in the lobby and none in
a match, and the ping limit judged one stale value five times over.
Connected peers now ping once a second regardless.

Checked on the NAS with a host and a joined client, counting the
host's pongs before and after. The packets are unchanged and every
build already answers pings, so the network version stays 41.
The in-game admission window ran from the machine's join, so a
machine that joined the lobby shortly before the start was still
judged through loading and its first seconds of the match. A machine
seen in the lobby is now judged there only; a machine that joins a
match in progress keeps its first 10 seconds.

lobby-into-game covers it, with a negative control.
The README and config.toml said the median of 5 seconds, but a player
is judged from the third round trip, so a host got about 3 s of grace,
not 5. The config text also said every player's first 10 seconds in a
match, which holds only for a player who joins in progress.
A dedicated server reads network.host_ping_limit from its config.toml
like the other network.* keys, and it is the only ping check such a
server has: the server browser does not ping master-listed servers.
Its operator changes the other hosting limits, the vote kick's and
the chat's, live with sv_set and the web page's settings. This adds
the ping limit to that list, to the docs' list and to server_sim.py's
copy of it. A dedicated server's own machine has no player, so the
limit's exemption for the host's machine skips no one there.

Checked before the rebase, as 81d80e98e: ninja linux; in the
halo-toolchain container, a dedicated server and a client joining by
its invite over the tunnel, the client's tunnel delayed 200 ms by netem:
with host_ping_limit = 100 in config.toml the client was removed 1.7 s
after joining ("ping 207 ms, over the host's limit of 100 ms"); with 0
it stayed until "sv_set network.host_ping_limit 100", then was removed
2.6 s later; after "sv_set network.host_ping_limit 300" a client stayed
20 s, and sv_settings listed 300; test_server_sim.py passes (44).

Re-applied by hand on the rebased branch (the settings list had grown):
test_server_sim.py passes (45).
@medic-code
medic-code force-pushed the feat/host-ping-limit branch from c072a45 to 7f8dbb7 Compare November 8, 2026 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant