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
+15 -3
View File
@@ -2,8 +2,9 @@ class_name NetLink
extends RefCounted
## The network connection of a session, over ENet. A host listens for guests;
## a guest connects to its host. Messages of the core travel on a reliable,
## ordered channel. Positions of figures travel on a second, unreliable
## channel, because a lost one is soon replaced by the next.
## ordered channel. Positions of figures travel on a second channel that is
## unreliable but ordered: a lost position is soon replaced by the next, and
## an older one that arrives after a newer one is dropped.
## Port a host listens on unless told otherwise.
const DEFAULT_PORT := 24680
@@ -14,6 +15,10 @@ const CHANNEL_CORE := 0
const CHANNEL_FIGURES := 1
## Seconds a guest waits for its host to answer before it gives up.
const CONNECT_SECONDS := 8.0
## Milliseconds after which a connection whose packets stay unanswered counts
## as lost. ENet's own limit of 30 seconds would leave a guest whose host
## vanished in a standing world for that long.
const TIMEOUT_MSEC := 8000
## Seconds this guest waits for its host. Tests shorten it.
var connect_seconds := CONNECT_SECONDS
@@ -77,6 +82,13 @@ func _start() -> void:
func _on_connected(peer: int) -> void:
_peers[peer] = true
var connection := _peer.get_peer(peer)
# ENet slows unreliable packets down after a spike in the round trip and
# can keep them at nothing for the rest of a session, so that the figures
# of one guest stop. Positions are a few bytes ten times a second; they
# are never slowed down.
connection.throttle_configure(5000, ENetPacketPeer.PACKET_THROTTLE_SCALE, 0)
connection.set_timeout(32, 5000, TIMEOUT_MSEC)
_events.append({"type": "connected", "peer": peer})
@@ -131,7 +143,7 @@ func send(peer: int, bytes: PackedByteArray) -> void:
## Sends the position of a figure to `peer`, to every connection if `peer`
## is 0, or to every connection but one if `peer` is that one negated.
func send_figure(peer: int, bytes: PackedByteArray) -> void:
_put(peer, bytes, CHANNEL_FIGURES, MultiplayerPeer.TRANSFER_MODE_UNRELIABLE)
_put(peer, bytes, CHANNEL_FIGURES, MultiplayerPeer.TRANSFER_MODE_UNRELIABLE_ORDERED)
func _put(peer: int, bytes: PackedByteArray, channel: int, mode: MultiplayerPeer.TransferMode) -> void: