update network

This commit is contained in:
2026-02-04 16:31:18 +08:00
parent 4ccf789421
commit 08b0493c06
10 changed files with 203 additions and 22 deletions
+14 -5
View File
@@ -1,10 +1,10 @@
extends Node
# Standard Nakama Configuration
const NAKAMA_SERVER_KEY = "defaultkey"
const NAKAMA_HOST = "localhost"
const NAKAMA_PORT = 7350
const NAKAMA_SCHEME = "http"
var nakama_server_key = "defaultkey"
var nakama_host = "localhost"
var nakama_port = 7350
var nakama_scheme = "http"
# Core Nakama Variables
var client: NakamaClient
@@ -23,11 +23,20 @@ var current_match_id: String = ""
func _ready():
# Initialize the Nakama Client
client = Nakama.create_client(NAKAMA_SERVER_KEY, NAKAMA_HOST, NAKAMA_PORT, NAKAMA_SCHEME)
_init_client()
# Ensure we process network events
set_process(true)
func _init_client():
client = Nakama.create_client(nakama_server_key, nakama_host, nakama_port, nakama_scheme)
func set_server(host: String, port: int = 7350):
nakama_host = host
nakama_port = port
_init_client()
print("[NakamaManager] Server updated to: ", nakama_host, ":", nakama_port)
func _process(_delta):
# If using the standard socket adapter, it needs polling in some versions
if socket:
+79 -2
View File
@@ -31,9 +31,14 @@ extends Control
var is_loading: bool = false
# Server Selection Controls
var server_option: OptionButton
var server_ip_input: LineEdit
func _ready() -> void:
_connect_signals()
_setup_ui()
_setup_server_config_ui()
# Check if already authenticated
if AuthManager.is_logged_in():
@@ -165,6 +170,78 @@ func _on_facebook_pressed() -> void:
# When you have the access token from Facebook SDK:
# AuthManager.login_with_facebook(access_token)
func _setup_server_config_ui() -> void:
"""Inject server configuration controls into MainPanel."""
if not main_panel: return
var vbox = main_panel.get_node_or_null("VBox")
if not vbox: return
# Find where to insert (before GuestButton)
var insert_pos = 3 # Default position
if guest_button:
insert_pos = guest_button.get_index()
# Create Server Section
var server_section = VBoxContainer.new()
server_section.name = "ServerSelectionSection"
server_section.add_theme_constant_override("separation", 10)
vbox.add_child(server_section)
vbox.move_child(server_section, insert_pos)
# Server Label
var label = Label.new()
label.text = "NAKAMA SERVER"
label.add_theme_color_override("font_color", Color(0.69, 0.529, 0.357, 1))
label.add_theme_font_size_override("font_size", 13)
server_section.add_child(label)
# Server OptionButton
server_option = OptionButton.new()
server_option.name = "ServerOption"
server_option.custom_minimum_size = Vector2(0, 44)
server_option.add_item("Localhost (Testing)")
server_option.add_item("Remote Server (Host IP)")
# Set initial state based on NakamaManager
if NakamaManager.nakama_host == "localhost":
server_option.selected = 0
else:
server_option.selected = 1
server_option.item_selected.connect(_on_server_option_selected)
server_section.add_child(server_option)
# Server IP Input
server_ip_input = LineEdit.new()
server_ip_input.name = "ServerIPInput"
server_ip_input.custom_minimum_size = Vector2(0, 44)
server_ip_input.placeholder_text = "Enter Server IP Address..."
server_ip_input.text = NakamaManager.nakama_host if NakamaManager.nakama_host != "localhost" else "127.0.0.1"
server_ip_input.visible = server_option.selected == 1
server_ip_input.text_submitted.connect(_on_server_ip_submitted)
server_ip_input.focus_exited.connect(func(): _on_server_ip_submitted(server_ip_input.text))
server_section.add_child(server_ip_input)
# Add a separator after the section
var separator = HSeparator.new()
vbox.add_child(separator)
vbox.move_child(separator, insert_pos + 1)
func _on_server_option_selected(index: int) -> void:
if index == 0:
# Localhost
server_ip_input.visible = false
NakamaManager.set_server("localhost")
else:
# Remote
server_ip_input.visible = true
NakamaManager.set_server(server_ip_input.text)
func _on_server_ip_submitted(new_text: String) -> void:
if server_option.selected == 1:
NakamaManager.set_server(new_text.strip_edges())
# =============================================================================
# Registration Handlers
# =============================================================================
@@ -239,7 +316,7 @@ func _check_password_strength(password: String) -> void:
password_strength.add_theme_stylebox_override("fill", style)
func _calculate_password_strength(password: String) -> int:
var strength := 0
var strength: float = 0.0
if password.length() >= 8:
strength += 1
@@ -269,7 +346,7 @@ func _calculate_password_strength(password: String) -> int:
if has_special:
strength += 0.5
return mini(int(strength), 4)
return clampi(int(strength), 0, 4)
# =============================================================================
# Auth Manager Callbacks