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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user