This commit is contained in:
Yogi Wiguna
2026-03-17 17:38:30 +08:00
parent 1b8e411657
commit efdd8f4969
32 changed files with 320 additions and 22 deletions
+39 -20
View File
@@ -32,29 +32,48 @@ 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
# Clean up the host string
var clean_host = host.strip_edges()
# Auto-detect secure tunnels (Tailscale, ngrok, playit, cloudflare)
if host.ends_with(".ts.net") or host.ends_with(".gg") or host.begins_with("https://"):
if host.begins_with("https://"):
nakama_host = host.replace("https://", "")
if host.begins_with("http://"):
nakama_host = host.replace("http://", "")
if nakama_host.ends_with("/"):
nakama_host = nakama_host.substr(0, nakama_host.length() - 1)
nakama_port = 443
# Extract protocol if present (override everything else)
var forced_scheme = ""
if clean_host.begins_with("https://"):
forced_scheme = "https"
clean_host = clean_host.replace("https://", "")
elif clean_host.begins_with("http://"):
forced_scheme = "http"
clean_host = clean_host.replace("http://", "")
# Handle trailing slashes
if clean_host.ends_with("/"):
clean_host = clean_host.substr(0, clean_host.length() - 1)
# Extract port if explicitly provided in host string (e.g. host:port)
var explicit_port = -1
if ":" in clean_host:
var parts = clean_host.split(":")
clean_host = parts[0]
explicit_port = parts[1].to_int()
# DETECT SETTINGS
nakama_host = clean_host
if forced_scheme != "":
nakama_scheme = forced_scheme
nakama_port = explicit_port if explicit_port != -1 else (443 if forced_scheme == "https" else port)
elif clean_host.ends_with(".ts.net") and explicit_port == -1:
# Tailscale Funnel Case (No port provided, .ts.net domain)
nakama_scheme = "https"
else:
# Extract port if they typed something like 192.168.1.1:7350
if ":" in host and not host.begins_with("http"):
var parts = host.split(":")
nakama_host = parts[0]
nakama_port = parts[1].to_int()
else:
nakama_port = port
nakama_port = 443
elif clean_host.begins_with("100."):
# Standard Tailscale IP Case
nakama_scheme = "http"
nakama_port = explicit_port if explicit_port != -1 else port
else:
# Generic Case (e.g. localhost, public IP)
nakama_scheme = "http"
nakama_port = explicit_port if explicit_port != -1 else port
_init_client()
print("[NakamaManager] Server updated to: ", nakama_scheme, "://", nakama_host, ":", nakama_port)