Files
tekton/server/nakama/lua/utils.lua
T
adtpdn 15043b5655 feat: take_powerup VFX, rank fix, admin chat management
- Wire take_powerup AnimatedSprite3D on powerup pickup via add_powerup_from_item()
- Make take_powerup animation one-shot (loop: false)
- Fix rank Position label hidden at game start (visible = false, only shows when score > 0)
- Competition ranking for tied scores in main.gd
- Lobby Chat admin tab: system prefix, max messages, wipe, purge old, save config
- Chat Storage admin tab: list/browse/delete individual channel messages
- Backend RPCs: admin_get_chat_config, admin_set_chat_config, admin_purge_old_messages,
  admin_list_channel_messages, admin_delete_channel_message
- Chat config applied on lobby join (max_messages, prefix injection)
2026-06-19 17:13:24 +08:00

54 lines
1.6 KiB
Lua

local nk = require("nakama")
local utils = {}
utils.ADMIN_ROLES = { ["admin"] = true, ["moderator"] = true, ["owner"] = true }
utils.SYSTEM_USER_ID = "00000000-0000-0000-0000-000000000000"
function utils.is_admin(context)
if not context.user_id then return false end
local status, account = pcall(nk.account_get_id, context.user_id)
if not status or not account then return false end
local metadata = {}
if type(account.user.metadata) == "string" then
status, metadata = pcall(nk.json_decode, account.user.metadata)
if not status then metadata = {} end
else
metadata = account.user.metadata or {}
end
local role = metadata.role or ""
return utils.ADMIN_ROLES[role] == true
end
function utils.is_match_host(context, match_id)
if not context.user_id or not match_id then return false end
local status, match = pcall(nk.match_get, match_id)
if not status or not match then return false end
-- Needs to decode match.state if you're using authoritative matches
-- Simplified for lua translation:
local state = {}
if match.state then
status, state = pcall(nk.json_decode, match.state)
if not status then state = {} end
end
return state.hostUserId == context.user_id
end
function utils.require_admin(context)
if not utils.is_admin(context) then
error("Admin privileges required")
end
end
function utils.require_admin_or_host(context, match_id)
if not utils.is_admin(context) and not utils.is_match_host(context, match_id) then
error("Admin or host privileges required")
end
end
return utils