improve network error handling

This commit is contained in:
2025-02-11 00:08:03 +10:00
parent 95eeab0dfe
commit dc30ad4afc
4 changed files with 95 additions and 18 deletions

View File

@@ -1,14 +1,21 @@
extends Panel
@onready var name_edit: LineEdit = $MarginContainer/GridContainer/NameEdit
@onready var ip_edit: LineEdit = $MarginContainer/GridContainer/IpEdit
@onready var host_button: Button = $MarginContainer/GridContainer/HostButton
@onready var join_button: Button = $MarginContainer/GridContainer/JoinButton
@onready var _name_edit: LineEdit = $MarginContainer/GridContainer/NameEdit
@onready var _ip_edit: LineEdit = $MarginContainer/GridContainer/IpEdit
@onready var _host_button: Button = $MarginContainer/GridContainer/HostButton
@onready var _join_button: Button = $MarginContainer/GridContainer/JoinButton
@onready var _error_label: Label = $ErrorLabel
func _ready() -> void:
host_button.pressed.connect(_on_host_button_pressed)
join_button.pressed.connect(_on_join_button_pressed)
_host_button.pressed.connect(_on_host_button_pressed)
_join_button.pressed.connect(_on_join_button_pressed)
Networker.network_error.connect(_on_networker_network_error)
_error_label.text = ""
func _display_error(message: String) -> void:
_error_label.text = message
func _on_host_button_pressed() -> void:
@@ -16,4 +23,18 @@ func _on_host_button_pressed() -> void:
func _on_join_button_pressed() -> void:
Networker.join_game(ip_edit.text)
var ip: String = _ip_edit.text
if not ip.is_valid_ip_address():
_display_error("Invalid IP address")
return
_join_button.disabled = true
_host_button.disabled = true
Networker.join_game(_ip_edit.text)
func _on_networker_network_error(message: String) -> void:
_join_button.disabled = false
_host_button.disabled = false
_display_error(message)