Jump to content

[APORTE] Editor de archivo acl.xml | Con GUI DX


Recommended Posts

nxsLkGa.png

Bueno, en esta ocasión vengo a aportar un script, bastante sencillo pero útil a la hora de manejar nuestro archivo acl.xml, en cuanto a refrescar, guardar o añadir nuevos elementos a un grupo ACL. Esta versión cuenta también con un panel DX personalizado el cual podremos modificar sin ningún problema, así también con animaciones de 'hover' y agrandamiento de texto cuando el ratón esté por encima de los botones.

El comando para abrir el panel se puede modificar en el archivo meta.xml, así también tenemos la posibilidad de ver quién ha usado el comando y para qué, teniendo un almacenamiento interno en una tabla, que podremos ver su contenido con el comando /viewTasks

Clickea aquí para ir a la descarga directa del archivo, con las imágenes y todo lo necesario para iniciarlo correctamente

Código meta.xml

<meta>

	<script src="server.lua" type="server"/>
	<script src="client.lua" type="client"/>
	
	<file src="files/logo.png"/>

	<settings>
		<setting name="command" value="acleditor"/>
	</settings>
	<!-- Dont touch this. Are the permissions to use this script. We need specific permissions
		to reload and set permissions to acl -->
	<aclrequest>
        <right name="general.ModifyOtherObjects" access="true" />
		<right name="function.aclReload" access="true" />
		<right name="function.aclSetRight" access="true" />
		<right name="function.aclGroupAddObject" access="true" />
		<right name="function.aclGroupRemoveObject" access="true" />
		<right name="function.aclGetGroup" access="true" />
		<right name="function.aclSave" access="true" />
	</aclrequest>
	
</meta>

 

Código client.lua

local sx, sy = guiGetScreenSize( )
local sourceX, sourceY = 1366, 768
local open 

function isMouseInPosition ( x, y, width, height )
    if ( not isCursorShowing ( ) ) then
        return false
    end
 
    local sx, sy = guiGetScreenSize ( )
    local cx, cy = getCursorPosition ( )
    local cx, cy = ( cx * sx ), ( cy * sy )
    if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then
        return true
    else
        return false
    end
end

function drawEdits ( )
    playerAccount = guiCreateEdit((626/sourceX)*sx, (495/sourceY)*sy, (225/sourceX)*sx, (24/sourceY)*sy, "", false)
    playerPermission = guiCreateEdit((626/sourceX)*sx, (529/sourceY)*sy, (225/sourceX)*sx, (24/sourceY)*sy, "", false)    
end

function drawPanel ( )
		-- Principal drawing:
        dxDrawRectangle((616/sourceX)*sx, (230/sourceY)*sy, (398/sourceX)*sx, (380/sourceY)*sy, tocolor(249, 115, 7, 45), false) -- Main window
        dxDrawImage((616/sourceX)*sx, (230/sourceY)*sy, (98/sourceX)*sx, (90/sourceY)*sy, ":acleditor/files/logo.png", 0, 0, 0, tocolor(255, 255, 255, 128), false) -- Script logo.png
        dxDrawText("ACL Editor | ACL manager tool\nEdit here your acl.xml file without\ncommands", (712/sourceX)*sx, (236/sourceY)*sy, (1014/sourceX)*sx, (320/sourceY)*sy, tocolor(255, 255, 255, 255), (sy/sourceY) * 0.39, "bankgothic", "center", "center", false, false, false, false, false)
		-- Button: reloadAcl
		if isMouseInPosition( (621/sourceX)*sx, (330/sourceY)*sy, (91/sourceX)*sx, (40/sourceY)*sy ) then
			dxDrawRectangle((621/sourceX)*sx, (330/sourceY)*sy, (91/sourceX)*sx, (40/sourceY)*sy, tocolor(249, 115, 70, 111), false)
			dxDrawText("Reload ACL", (621/sourceX)*sx, (331/sourceY)*sy, (712/sourceX)*sx, (370/sourceY)*sy, tocolor(255, 255, 255, 255), (sy/sourceY) * 0.32, "bankgothic", "center", "center", false, false, false, false, false)			
		else
			dxDrawRectangle((621/sourceX)*sx, (330/sourceY)*sy, (91/sourceX)*sx, (40/sourceY)*sy, tocolor(249, 115, 7, 111), false)
			dxDrawText("Reload ACL", (621/sourceX)*sx, (331/sourceY)*sy, (712/sourceX)*sx, (370/sourceY)*sy, tocolor(255, 255, 255, 255), (sy/sourceY) * 0.29, "bankgothic", "center", "center", false, false, false, false, false)
		end
		-- Button: saveACL
		if isMouseInPosition( (621/sourceX)*sx, (389/sourceY)*sy, (91/sourceX)*sx, (40/sourceY)*sy ) then
			dxDrawRectangle((621/sourceX)*sx, (389/sourceY)*sy, (91/sourceX)*sx, (40/sourceY)*sy, tocolor(249, 115, 70, 111), false)
			dxDrawText("Save ACL", (621/sourceX)*sx, (390/sourceY)*sy, (712/sourceX)*sx, (429/sourceY)*sy, tocolor(255, 255, 255, 255), (sy/sourceY) * 0.32, "bankgothic", "center", "center", false, false, false, false, false)		
		else
			dxDrawRectangle((621/sourceX)*sx, (389/sourceY)*sy, (91/sourceX)*sx, (40/sourceY)*sy, tocolor(249, 115, 7, 111), false)
			dxDrawText("Save ACL", (621/sourceX)*sx, (390/sourceY)*sy, (712/sourceX)*sx, (429/sourceY)*sy, tocolor(255, 255, 255, 255), (sy/sourceY) * 0.29, "bankgothic", "center", "center", false, false, false, false, false)		
		end
		-- Button: addaclpermission
		if isMouseInPosition( (850/sourceX)*sx, (450/sourceY)*sy, (159/sourceX)*sx, (39/sourceY)*sy ) then
			dxDrawRectangle((850/sourceX)*sx, (450/sourceY)*sy, (159/sourceX)*sx, (39/sourceY)*sy, tocolor(249, 115, 70, 111), false)
			dxDrawText("Add acl group", (882/sourceX)*sx, (450/sourceY)*sy, (973/sourceX)*sx, (489/sourceY)*sy, tocolor(255, 255, 255, 255), (sy/sourceY) * 0.32, "bankgothic", "center", "center", false, false, false, false, false)
		else	
			dxDrawRectangle((850/sourceX)*sx, (450/sourceY)*sy, (159/sourceX)*sx, (39/sourceY)*sy, tocolor(249, 115, 7, 111), false)
			dxDrawText("Add acl group", (882/sourceX)*sx, (450/sourceY)*sy, (973/sourceX)*sx, (489/sourceY)*sy, tocolor(255, 255, 255, 255), (sy/sourceY) * 0.29, "bankgothic", "center", "center", false, false, false, false, false)
		end
		-- Button: removeaclpermission
		if isMouseInPosition( (626/sourceX)*sx, (450/sourceY)*sy, (159/sourceX)*sx, (39/sourceY)*sy ) then
			dxDrawRectangle((626/sourceX)*sx, (450/sourceY)*sy, (159/sourceX)*sx, (39/sourceY)*sy, tocolor(249, 115, 70, 111), false)
			dxDrawText("Remove acl group", (660/sourceX)*sx, (450/sourceY)*sy, (751/sourceX)*sx, (489/sourceY)*sy, tocolor(255, 255, 255, 255), (sy/sourceY) * 0.32, "bankgothic", "center", "center", false, false, false, false, false)
		else		
			dxDrawRectangle((626/sourceX)*sx, (450/sourceY)*sy, (159/sourceX)*sx, (39/sourceY)*sy, tocolor(249, 115, 7, 111), false)
			dxDrawText("Remove acl group", (660/sourceX)*sx, (450/sourceY)*sy, (751/sourceX)*sx, (489/sourceY)*sy, tocolor(255, 255, 255, 255), (sy/sourceY) * 0.29, "bankgothic", "center", "center", false, false, false, false, false)
		end
		-- Button: close panel
		if isMouseInPosition( (765/sourceX)*sx, (559/sourceY)*sy, (91/sourceX)*sx, (40/sourceY)*sy ) then
			dxDrawRectangle((765/sourceX)*sx, (559/sourceY)*sy, (91/sourceX)*sx, (40/sourceY)*sy, tocolor(249, 115, 70, 111), false)
			dxDrawText("Close panel", (907/sourceX)*sx, (730/sourceY)*sy, (712/sourceX)*sx, (432/sourceY)*sy, tocolor(255, 255, 255, 255), (sy/sourceY) * 0.35, "bankgothic", "center", "center", false, false, false, false, false)		
		else
			dxDrawRectangle((765/sourceX)*sx, (559/sourceY)*sy, (91/sourceX)*sx, (40/sourceY)*sy, tocolor(249, 115, 7, 111), false)
			dxDrawText("Close panel", (907/sourceX)*sx, (730/sourceY)*sy, (712/sourceX)*sx, (432/sourceY)*sy, tocolor(255, 255, 255, 255), (sy/sourceY) * 0.35, "bankgothic", "center", "center", false, false, false, false, false)	
		end
		-- Info
        dxDrawText("Account", (856/sourceX)*sx, (495/sourceY)*sy, (1009/sourceX)*sx, (516/sourceY)*sy, tocolor(255, 255, 255, 255), (sy/sourceY) * 0.59, "bankgothic", "center", "center", false, false, false, false, false)
        dxDrawText("ACL Group", (856/sourceX)*sx, (529/sourceY)*sy, (1009/sourceX)*sx, (550/sourceY)*sy, tocolor(255, 255, 255, 255), (sy/sourceY) * 0.59, "bankgothic", "center", "center", false, false, false, false, false)
        dxDrawText("Using this button you can reload your acl\nto add the new permissions inside the file", (715/sourceX)*sx, (330/sourceY)*sy, (1014/sourceX)*sx, (370/sourceY)*sy, tocolor(255, 255, 255, 255), (sy/sourceY) * 0.29, "bankgothic", "center", "center", false, false, false, false, false)
        dxDrawText("Using this button you can save your acl\nfile ingame", (715/sourceX)*sx, (389/sourceY)*sy, (1014/sourceX)*sx, (429/sourceY)*sy, tocolor(255, 255, 255, 255), (sy/sourceY) * 0.29, "bankgothic", "center", "center", false, false, false, false, false)
end

function closeAll( )
	if isElement(playerAccount) then destroyElement( playerAccount ) end
	if isElement(playerPermission) then destroyElement( playerPermission ) end
	removeEventHandler( "onClientRender", getRootElement( ), drawPanel )
	open = nil
	showCursor( false )
end

addEventHandler( "onClientClick", getRootElement( ),
	function( button, state )
		if button == "left" and state == "down" and open == true then
			local boton_reloadACL = isMouseInPosition( (621/sourceX)*sx, (330/sourceY)*sy, (91/sourceX)*sx, (40/sourceY)*sy )
			local boton_saveACL = isMouseInPosition( (621/sourceX)*sx, (389/sourceY)*sy, (91/sourceX)*sx, (40/sourceY)*sy )
			local boton_close = isMouseInPosition( (765/sourceX)*sx, (559/sourceY)*sy, (91/sourceX)*sx, (40/sourceY)*sy )
			local boton_addAcl = isMouseInPosition( (850/sourceX)*sx, (450/sourceY)*sy, (159/sourceX)*sx, (39/sourceY)*sy )
			local boton_removeAcl = isMouseInPosition( (626/sourceX)*sx, (450/sourceY)*sy, (159/sourceX)*sx, (39/sourceY)*sy )
			-- Edits
			local account_name = guiGetText( playerAccount )
			local group_name = guiGetText( playerPermission )
			if boton_reloadACL then
				triggerServerEvent( "acleditor:reloadACL", getLocalPlayer( ), getLocalPlayer( ) )
			elseif boton_saveACL then
				triggerServerEvent( "acleditor:saveACL", getLocalPlayer( ), getLocalPlayer( ) )
			elseif boton_addAcl then
				if #account_name > 1 then
					if #group_name > 0 then
						triggerServerEvent( "acleditor:givePermission", getLocalPlayer( ), getLocalPlayer( ), account_name, group_name )
					else
						outputChatBox( "You need to add the name of the group you wanna add", 255, 145, 0 )
					end
				else
					outputChatBox( "Add the account name you need to set", 255, 145, 0 )
				end
			elseif boton_removeAcl then
				if #account_name > 1 then
					if #group_name > 0 then
						triggerServerEvent( "acleditor:removePermission", getLocalPlayer( ), getLocalPlayer( ), account_name, group_name )
					else
						outputChatBox( "You need to add the name of the group you wanna remove from", 255, 145, 0 )
					end
				else
					outputChatBox( "Add the account name you need to remove", 255, 145, 0 )
				end				
			elseif boton_close then
				closeAll( )
			end
		end
	end
)

addEvent( "acleditor:openPanel", true )
addEventHandler( "acleditor:openPanel", getRootElement( ),
	function( )
		if open == nil then
			drawEdits( )
			addEventHandler( "onClientRender", getRootElement( ), drawPanel )
			open = true
			showCursor( true )
		end
	end
)

bindKey( "m", "down",
	function( )
		if isCursorShowing( ) then
			showCursor( false )
		else
			showCursor( true )
		end
	end
)

 

Código server.lua

local _aclRequestTimer = { }
local _aclTasks = { }
local commandName = get( "command" ) -- This gets the commandName setting from meta.xml

addCommandHandler( commandName,
	function( player )
		local account = getPlayerAccount( player )
		local permission = isObjectInACLGroup( "user."..getAccountName(account), aclGetGroup( "Admin" ) )  
		if account then
			if permission then
				triggerClientEvent( player, "acleditor:openPanel", player )
				table.insert( _aclTasks, { task = "ACLOpen", name = getPlayerName( player ) } )
			end
		else
			outputChatBox( "Fatal error, you dont have an account on this server.", player, 255, 145, 0 )
		end
	end
)

addCommandHandler( "viewTasks",
	function( player )
		local tasks = _aclTasks
		local havePermissions = hasObjectPermissionTo( player, "command.viewTasks" ) or isObjectInACLGroup( "user."..getAccountName( player ), aclGetGroup( "Admin" ) )
		if havePermissions then
			outputChatBox( "Tasks: ", player, 255, 255, 255 )
			for i=1, #tasks do
				local data = tasks[i]
				outputChatBox( "• Task: "..data.task.." | Player: "..data.name, player, 255, 145, 0 )
			end
		end
	end
)

addEvent( "acleditor:givePermission", true )
addEventHandler( "acleditor:givePermission", getRootElement( ),
	function( player, accountName, groupName )
		local accountName = table.concat( { accountName }, " " )
		local groupName = table.concat( { groupName }, " " )
		if accountName and groupName then
			local exists = aclGetGroup( groupName ) 
			if exists then
				local is_in_group = isObjectInACLGroup( "user."..accountName, exists )
				if is_in_group then
					outputChatBox( "• The account is currently in the ACL", player, 0, 255, 0 )
				else
					outputChatBox( "• Added user."..accountName.." to group "..groupName.." succefully.", player, 0, 255, 0 )
					aclGroupAddObject( exists, "user."..accountName )
					table.insert( _aclTasks, { task = "ACLAdd", name = getPlayerName( player ) } )
				end
			else
				outputChatBox( "• The specified group dont exists in your acl.xml", player, 255, 145, 0 )
			end
		end
	end
)

addEvent( "acleditor:removePermission", true )
addEventHandler( "acleditor:removePermission", getRootElement( ),
	function( player, accountName, groupName )
		local accountName = table.concat( { accountName }, " " )
		local groupName = table.concat( { groupName }, " " )
		if accountName and groupName then
			local exists = aclGetGroup( groupName )
			if exists then
				local is_in_group = isObjectInACLGroup( "user."..accountName, exists )
				if is_in_group then
					aclGroupRemoveObject( exists, "user."..accountName )
					outputChatBox( "• Removed user."..accountName.." from group "..groupName.." succefully.", player, 0, 255, 0 )
					table.insert( _aclTasks, { task = "ACLRemove", name = getPlayerName( player ) } )
				else
					outputChatBox( "• The account user."..accountName.." is not in the specified group.", player, 255, 145, 0 )
				end
			else
				outputChatBox( "• The specified group dont exists in your acl.xml", player, 255, 145, 0 )
			end
		end
	end
)

addEvent( "acleditor:reloadACL", true )
addEventHandler( "acleditor:reloadACL", getRootElement( ),
	function( player )
		local name = getPlayerName( player )
		local success = aclReload( )
		if success then
			if _aclRequestTimer[ player ] == nil then
				outputChatBox( "Reloaded acl.xml file succefully.", player, 255, 145, 0 )
				_aclRequestTimer[ player ] = setTimer( function( ) _aclRequestTimer[ player ] = nil end, 2000, 1 )
				table.insert( _aclTasks, { task = "Reload", name = name } )
			else
				outputChatBox( "Do not flood the button, please. Wait "..math.floor(getTimerDetails( _aclRequestTimer[ player ] )/1000).." seconds.", player, 255, 145, 0 ) 
			end
		else
			outputChatBox( "An error ocurred. Check if the acl.xml file exists", player, 255, 145, 0 )
		end
	end
)

addEvent( "acleditor:saveACL", true )
addEventHandler( "acleditor:saveACL", getRootElement( ),
	function( player )
		local name = getPlayerName( player )
		local success = aclSave()
		if success then
			if _aclRequestTimer[ player ] == nil then
				outputChatBox( "Saved acl.xml file succefully.", player, 255, 145, 0 )
				_aclRequestTimer[ player ] = setTimer( function( ) _aclRequestTimer[ player ] = nil end, 2000, 1 )
				table.insert( _aclTasks, { task = "Save", name = name } )
			else
				outputChatBox( "Do not flood the button, please. Wait "..math.floor(getTimerDetails( _aclRequestTimer[ player ] )/1000).." seconds.", player, 255, 145, 0 ) 			
			end
		else
			outputChatBox( "An error ocurred. Check if the acl.xml file exists", player, 255, 145, 0 )
		end
	end
)

 

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...