feat: overhaul the nakama user management, leaderboard, prep for 2.1
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
extends Node
|
||||
## Global Admin Manager -- listens for F10 and handles Admin Panel instantiation.
|
||||
|
||||
var _admin_panel_instance: Control = null
|
||||
var _is_checking: bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
# Persistent across scene changes
|
||||
process_mode = PROCESS_MODE_ALWAYS
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventKey and event.pressed and event.keycode == KEY_F10:
|
||||
toggle_admin_panel()
|
||||
|
||||
func toggle_admin_panel() -> void:
|
||||
if _admin_panel_instance and _admin_panel_instance.visible:
|
||||
_admin_panel_instance.hide()
|
||||
return
|
||||
|
||||
if _is_checking: return
|
||||
_is_checking = true
|
||||
|
||||
# Verify admin status before showing
|
||||
var is_admin = await _check_admin_status()
|
||||
_is_checking = false
|
||||
|
||||
if not is_admin:
|
||||
print("[AdminManager] Access denied: Not an admin.")
|
||||
return
|
||||
|
||||
_show_panel()
|
||||
|
||||
func _show_panel() -> void:
|
||||
if not is_instance_valid(_admin_panel_instance):
|
||||
print("[AdminManager] Instantiating new Admin Panel...")
|
||||
var scene = load("res://scenes/ui/admin_panel.tscn")
|
||||
if scene:
|
||||
_admin_panel_instance = scene.instantiate()
|
||||
get_tree().root.add_child(_admin_panel_instance)
|
||||
else:
|
||||
print("[AdminManager] ERROR: Could not load admin_panel.tscn")
|
||||
return
|
||||
|
||||
if is_instance_valid(_admin_panel_instance):
|
||||
print("[AdminManager] Showing Admin Panel.")
|
||||
# Move to bottom of root's children to ensure it's on top of new scenes
|
||||
get_tree().root.move_child(_admin_panel_instance, -1)
|
||||
_admin_panel_instance.show_panel()
|
||||
else:
|
||||
print("[AdminManager] ERROR: Admin Panel instance is invalid after instantiation attempt.")
|
||||
|
||||
func _check_admin_status() -> bool:
|
||||
if not NakamaManager.client or not NakamaManager.session:
|
||||
return false
|
||||
|
||||
var account = await NakamaManager.client.get_account_async(NakamaManager.session)
|
||||
if account.is_exception():
|
||||
return false
|
||||
|
||||
var metadata_str: String = account.user.metadata if account.user.metadata else "{}"
|
||||
var metadata = JSON.parse_string(metadata_str)
|
||||
if metadata and metadata is Dictionary:
|
||||
var role = metadata.get("role", "")
|
||||
return role in ["admin", "moderator", "owner"]
|
||||
return false
|
||||
@@ -0,0 +1 @@
|
||||
uid://bgotdukmldbpx
|
||||
@@ -53,6 +53,10 @@ func _try_restore_session() -> void:
|
||||
var refresh_token: String = session_data.get("refresh_token", "")
|
||||
var saved_auth_mode: int = session_data.get("auth_mode", AuthMode.GUEST)
|
||||
|
||||
if saved_auth_mode == AuthMode.GUEST:
|
||||
print("[AuthManager] Ignoring guest session auto-restore to force login screen.")
|
||||
return
|
||||
|
||||
if token.is_empty():
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user