Abschlusskorrekturen M1c: Schläge der Gäste, Figuren und Fragebogen

- Der Host hält einen Schlag eines Gastes, der während der Abklingzeit
  ankommt, bis zum ersten Takt danach. Übers Internet ging sonst etwa
  jeder fünfte Schlag eines Gastes verloren.
- ENet drosselt die Figuren nie mehr; sonst konnten die Figuren eines
  von zwei Gästen dauerhaft stehen bleiben. Figuren gehen geordnet, und
  eine stille Verbindung gilt nach höchstens acht Sekunden als verloren.
- Positionen, die keine Zahlen sind, und Figuren von Spielern, die
  nicht online sind, werden verworfen.
- Ein Host mit angehaltener Simulation sagt das in der Statuszeile.
- Neue Tests: Schlag während der Abklingzeit, Zielauswahl von NetLink,
  verworfene Figuren, Neuabgleich über die Brücke.
- Der Fragebogen sagt, was jeder Rechner braucht, und die Freigabe in
  der Firewall gehört zum Host. CLAUDE.md beschreibt das Halten der
  Schläge, die Drosselung und die Zeitüberschreitung und ergänzt die
  Vertrauensregel um die Schlüssel.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
Steven Wroblewski
2026-10-02 01:22:36 +02:00
parent 7f4bbd9606
commit be22e9f358
13 changed files with 258 additions and 27 deletions
+1 -1
View File
@@ -333,7 +333,7 @@ func test_a_host_that_stops_sharing_lets_its_guests_go() -> void:
# session, _process calls what this test calls.
host._stop_sharing()
check(host.link == null, "the host no longer listens")
check_eq(host.hud.status_text(), "", "and no longer says that it does")
check_eq(host.hud.status_text(), tr("SIMULATION_STOPPED"), "its status line says why")
check(await _wait_until(func() -> bool: return guest.session == null), "the guest's session ends")
check_eq(guest.menu.status(), tr("HOST_LEFT"), "and the guest learns why")
_clean_up([host_dir, guest_dir])
+55
View File
@@ -26,6 +26,13 @@ func _first(link: NetLink, type: String) -> Dictionary:
return {}
## The bytes of every event of `type` that `link` got, each as an Array.
func _received(link: NetLink, type: String) -> Array:
return _events.get(link, []).filter(func(event: Dictionary) -> bool: return event["type"] == type).map(
func(event: Dictionary) -> Array: return Array(event["bytes"])
)
## A host and a guest that have connected.
func _connected_pair() -> Array[NetLink]:
var host := NetLink.new()
@@ -139,6 +146,54 @@ func test_nothing_is_sent_to_connections_that_are_gone_or_closing() -> void:
link.close()
## A packet goes to the connection it is addressed to, to every connection
## for peer 0, and to every connection but one for a negative peer.
func test_packets_go_only_where_they_are_addressed() -> void:
var host := NetLink.new()
check_eq(host.host(0, "127.0.0.1"), OK, "the host listens")
var guests: Array[NetLink] = []
var everyone: Array[NetLink] = [host]
for i in 3:
var guest := NetLink.new()
guest.join("127.0.0.1", host.local_port())
guests.append(guest)
everyone.append(guest)
await _pump(everyone, 15)
# Each guest says who it is, so that the host's id for it is known.
for i in 3:
guests[i].send(GwSession.HOST_PEER, PackedByteArray([i]))
await _pump(everyone, 10)
var peer_of: Array[int] = [0, 0, 0]
for event: Dictionary in _events[host]:
if event["type"] == "message":
peer_of[event["bytes"][0]] = event["peer"]
check(not peer_of.has(0), "the host knows all three guests")
_events.clear()
# Repeated, because a position that gets lost is no failure of the link.
for repeat in 5:
host.send(peer_of[0], PackedByteArray([10]))
host.send_figure(peer_of[2], PackedByteArray([20]))
host.send_figure(-peer_of[1], PackedByteArray([30]))
host.send_figure(0, PackedByteArray([40]))
await _pump(everyone, 2)
await _pump(everyone, 10)
check_eq(_received(guests[0], "message").size(), 5, "the first guest got the messages to it")
check_eq(_received(guests[1], "message"), [], "the second guest got none")
check_eq(_received(guests[2], "message"), [], "the third guest got none")
var first := _received(guests[0], "figure")
var second := _received(guests[1], "figure")
var third := _received(guests[2], "figure")
check(not first.has([20]), "the first guest got nothing for the third")
check(first.has([30]) and first.has([40]), "the first guest got 'all but the second' and 'all'")
check(not second.has([20]) and not second.has([30]), "the second guest got neither the one for the third nor 'all but itself'")
check(second.has([40]), "the second guest got 'all'")
check(third.has([20]) and third.has([30]) and third.has([40]), "the third guest got all three kinds")
for link in everyone:
link.close()
func test_a_guest_gives_up_when_nobody_answers() -> void:
# A port that was free a moment ago and has nobody listening now.
var probe := NetLink.new()
+21
View File
@@ -219,6 +219,27 @@ func test_the_hit_of_a_guest_becomes_a_message_to_the_host() -> void:
check_eq(host.damage_codes()[rock.y * host.map_width() + rock.x], 1, "and so does the host")
func test_a_guest_that_missed_a_tick_gets_the_world_again() -> void:
var pair := _host_and_guest()
var host := pair[0]
var guest := pair[1]
host.step()
# The message with this tick gets lost on the way.
host.take_messages()
host.step()
_carry(host, guest)
for i in guest.pending_ticks():
guest.step()
check_eq(_carry(host, guest), [{"type": "world_received", "resync": true}], "the guest gets the host's world again")
check_eq(host.take_divergences().size(), 1, "the host hears of it")
check(guest.take_diverged_recording().size() > 0, "the guest keeps the recording of the world that went astray")
host.step()
_carry(host, guest)
for i in guest.pending_ticks():
guest.step()
check_eq(guest.state_hash_hex(), host.state_hash_hex(), "both worlds are the same again")
func test_a_guest_learns_why_it_is_turned_away() -> void:
var host := _joined_session()
host.connect_peer(5)
+17
View File
@@ -109,6 +109,23 @@ func test_figures_travel_to_the_other_machines() -> void:
_close([host, guest, other])
func test_figures_that_cannot_be_shown_are_dropped() -> void:
_start_host()
var guest := _start_guest(guest_key, "Grace")
var other := _start_guest(PackedByteArray([3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]), "Linus")
await _play([guest, other], 30)
# A position that is no number, as a broken or changed client may send.
guest.link.send_figure(GwSession.HOST_PEER, guest._position_bytes(Vector2(NAN, 1.0)))
# A position of a player who is not online, as it can arrive late.
host.link.send_figure(0, host._figure_bytes(5, Vector2(1.0, 2.0)))
await _play([guest, other], 10)
check(not _types(host).has("figure"), "the host drops the position that is no number")
check(not _types(other).has("figure"), "passes nothing on, and nobody shows the player who is not online")
check(not _types(guest).has("figure"), "not even the guest that sent it")
_close([host, guest, other])
func test_a_guest_with_the_key_of_a_player_in_the_world_is_turned_away() -> void:
_start_host()
var twin := _start_guest(host_key, "Host")