\ : admin_rename
\ 	"rename" check-access
\ 	?dup "" = if
\ 		"jbforth/admin/players/rename.htm" show
\ 		exit
\ 	then
\ 	target-or-me@ player_rename
\ ;

: smart-find  ( name/npc_id/empty -- object_id | null )
	depth 0= if target-or-me@ exit then
	?dup "" = if target-or-me@ exit then

	dup find_player ?dup if nip exit then
	dup find-by-npc_id ?dup if nip exit then
	"Not found player or NPC [  ]" parse type
	null
;

: admin_to_char  ( name -- )
	"to-char" check-access
	smart-find ?dup null? if exit then
	"Teleport to [ dup ]" parse type
	coords@ 50 coords-randomize jump
;

: admin_character_list  ( name -- )
	"players-data-view" check-access
	smart-find ?dup null? if exit then
	to object
    object player@ c.target!
	"jbforth/admin/players/character_list.htm" show
;

: admin_banchat
	"banchat" check-access
	smart-find ?dup null? if exit then
	dup "AccessLevel" p@ 0 > if drop "Это ГМ!" . exit then
	"Change access level for [ dup ]" parse
	" from [ over 'AccessLevel' p@ ]" parse s+
	-1 2 pick "setAccessLevel" { int.class } jexec
	" to [ swap 'AccessLevel' p@ ]" parse s+
	dup "bans" >log .
;

: admin_unbanchat
	"banchat" check-access
	smart-find ?dup null? if exit then
	dup "AccessLevel" p@ 0 > if drop "Это ГМ!" . exit then
	"Change access level for [ dup ]" parse
	" from [ over 'AccessLevel' p@ ]" parse s+
	0 2 pick "setAccessLevel" { int.class } jexec
	" to [ swap 'AccessLevel' p@ ]" parse s+
	dup "bans" >log .
;
