Jump to content

مساعدة


Recommended Posts

السلآم عليكم 

آليوم حملت مود وجربته ف السيرفر بس م رضي

المود عبارة عن اخر تسجيل دخول للادمنية ادري قديم

بس لما افتح اللوحة م يطلع الحساب ولا أخر دخول

كود سيرفر

--[[function out( string )
    outputDebugString( string )
end]]

addEventHandler( 'onResourceStart', resourceRoot, 
    function( )
        --out( ' 1 ' )
        if not ( xmlLoadFile( 'LastLogin.xml' ) ) then
            --out( ' 2 ' )
            xmlSaveFile( xmlCreateFile( 'LastLogin.xml', 'LastLogin' ) )
        end
        --out( ' 3 ' )
        getAllAdminsAccounts( )
    end
)

function getTimeNow( )
    local time = getRealTime( )
    return string.format(
        '%04d-%02d-%02d %02d:%02d',
        time.year + 1900,
        time.month + 1,
        time.monthday,
        time.hour,
        time.minute 
    )
end

function setUserName( sName, sData )
    local lFile = xmlLoadFile( 'LastLogin.xml' )
    if ( lFile ) then
        local aChild = xmlCreateChild( lFile, 'aLastLogin' )
        xmlNodeSetAttribute( aChild, 'sName', sName )
        xmlNodeSetAttribute( aChild, 'sData', sData )
        xmlSaveFile( lFile )
        xmlUnloadFile( lFile )
    end
end

function getUserName( sName )
    local lFile = xmlLoadFile( 'LastLogin.xml' )
    if ( lFile ) then
        for _, gChildren in ipairs( xmlNodeGetChildren( lFile ) ) do
            local gName = xmlNodeGetAttribute( gChildren, 'sName' )
            if ( gName == sName ) then
                xmlUnloadFile( lFile )
                return true
            end
        end
        xmlUnloadFile( lFile )
        return false
    end
end

function destoryUserName( sName )
    local lFile = xmlLoadFile( 'LastLogin.xml' )
    if ( lFile ) then
        for _, gChildren in ipairs( xmlNodeGetChildren( lFile ) ) do
            local gName = xmlNodeGetAttribute( gChildren, 'sName' )
            if ( gName == sName ) then
                xmlDestroyNode( gChildren )
                xmlSaveFile( lFile )
                xmlUnloadFile( lFile )
                return true
            end
        end
        xmlUnloadFile( lFile )
    end
end

function updateUserName( sName, sData )
    local lFile = xmlLoadFile( 'LastLogin.xml' )
    if ( lFile ) then
        for _, gChildren in ipairs( xmlNodeGetChildren( lFile ) ) do
            local gName = xmlNodeGetAttribute( gChildren, 'sName' )
            if ( gName == sName ) then
                xmlDestroyNode( gChildren )
                xmlSaveFile( lFile )
                xmlUnloadFile( lFile )
                setUserName( sName, sData )
                return true
            end
        end
        xmlUnloadFile( lFile )
    end
end

function getAllAdminsAccounts( )
    for _, aAccounts in next, getAccounts( ) do
        if hasObjectPermissionTo( 'user.' .. getAccountName( aAccounts ), 'general.adminpanel', true ) then
            if not( getUserName( getAccountName( aAccounts ) ) ) then
            --out( getAccountName( aAccounts ) )
            setUserName( getAccountName( aAccounts ), getTimeNow( ) )
            end
        end
    end
end

function isHGAP( aAccountName )
    if hasObjectPermissionTo( 'user.' .. aAccountName, 'general.adminpanel', true ) then
        return true
    end
    return false
end

addEventHandler( 'onPlayerLogin', getRootElement( ),
    function( _, theCurrentAccount )
        if getUserName( getAccountName( theCurrentAccount ) ) and isHGAP( getAccountName( theCurrentAccount ) ) then
            updateUserName( getAccountName( theCurrentAccount ), 'online' )
            --out( ' 1 ' )
        elseif not getUserName( getAccountName( theCurrentAccount ) ) and isHGAP( getAccountName( theCurrentAccount ) ) then
            setUserName( getAccountName( theCurrentAccount ), 'online' )
            --out( ' 2 ' )
        elseif getUserName( getAccountName( theCurrentAccount ) ) and not isHGAP( getAccountName( theCurrentAccount ) ) then
            destoryUserName( getAccountName( theCurrentAccount ) )
            --out( ' 3 ' )
        end
    end
)

addEventHandler( 'onPlayerQuit', getRootElement( ),
    function( )
        local pAccount = getPlayerAccount( source )
        if getUserName( getAccountName( pAccount ) ) and isHGAP( getAccountName( pAccount ) ) then
            updateUserName( getAccountName( pAccount ), getTimeNow( ) )
            --out( ' 1 ' )
        elseif getUserName( getAccountName( pAccount ) ) and not isHGAP( getAccountName( pAccount ) ) then
            destoryUserName( getAccountName( pAccount ) )
            --out( ' 2 ' )
        end
    end
)

addEventHandler( 'onPlayerLogout', getRootElement( ),
    function( thePreviousAccount )
        if getUserName( getAccountName( thePreviousAccount ) ) and isHGAP( getAccountName( thePreviousAccount ) ) then
            updateUserName( getAccountName( thePreviousAccount ), getTimeNow( ) )
            --out( ' 1 ' )
        elseif getUserName( getAccountName( thePreviousAccount ) ) and not isHGAP( getAccountName( thePreviousAccount ) ) then
            destoryUserName( getAccountName( thePreviousAccount ) )
            --out( ' 2 ' )
        end
    end
)

function getDataTime( time )
    --out( time )
    if ( time ~= 'online' ) then
    local aYear, aMonth, aDay = string.match( time, '^(.-)-(.-)-(.-) (.-):(.-)$' )
    local aYear1, aMonth1, aDay1 = string.match( getTimeNow( ), '^(.-)-(.-)-(.-) (.-):(.-)$' )
        if ( aYear == aYear1 ) and ( aMonth == aMonth1 ) and ( aDay == aDay1 ) then
            return 'Today'
        elseif ( aYear == aYear1 ) and ( aMonth == aMonth1 ) and ( aDay ~= aDay1 ) then
            local aDay = ( aDay - 1 )
            if ( aDay1 == string.format( '%02d', aDay ) ) then
                return 'Yesterday'
            elseif ( aMonth == aMonth1 ) and ( aDay1 ~= aDay ) then
                local aDay = ( aDay1 - aDay )
                return math.abs( aDay ).. ' Day ago'
            end
        elseif ( aMonth ~= aMonth1 ) then
            return 'months ago'
        end
    end
    return ' '
end

function getColorData( sData )
    if ( sData == 'online' ) then
        return 0, 255, 0
    elseif ( getDataTime( sData ) == 'Today' ) then 
        return 255, 255, 0
    elseif ( getDataTime( sData ) == 'Yesterday' ) then
        return 255, 255, 0
    else
        return 255, 0, 0
    end
end

function getAllData( )
    local lFile = xmlLoadFile( 'LastLogin.xml' )
    if ( lFile ) then
        for _, gChildren in ipairs( xmlNodeGetChildren( lFile ) ) do
            getCountOnlineAOtherwise( )
            local gName = xmlNodeGetAttribute( gChildren, 'sName' )
            local gData = xmlNodeGetAttribute( gChildren, 'sData' )
            triggerClientEvent( 'onGetAllData', source, gName, gData, nOnline, nOfline, getColorData( gData ) )
        end
        xmlUnloadFile( lFile )
    end
end
addEvent( "aButtonRefresh", true )
addEventHandler( "aButtonRefresh", getRootElement( ), getAllData )


function getCountOnlineAOtherwise( )
    local lFile = xmlLoadFile( 'LastLogin.xml' )
    if ( lFile ) then
        nOnline = 0
        nOfline = 0
        for _, gChildren in ipairs( xmlNodeGetChildren( lFile ) ) do
            local gName = xmlNodeGetAttribute( gChildren, 'sData' )
            if ( gName == 'online' ) then
                nOnline = ( nOnline + 1 )
                --out( nOnline )
            else
                nOfline = ( nOfline + 1 )
                --out( nOfline )
            end
        end
        xmlUnloadFile( lFile )
    end
end

function delUsers ( )
    for _, aAccounts in next, getAccounts( ) do
        if getUserName( getAccountName( aAccounts ) ) and not isHGAP( getAccountName( aAccounts ) ) then
            destoryUserName( getAccountName( aAccounts ) )
        end
    end
end
delUsers ( )

وشكرا

Link to comment
--[[function out( string )
	outputDebugString( string )
end]]

addEventHandler( 'onResourceStart', resourceRoot, 
	function( )
		--out( ' 1 ' )
		if not ( xmlLoadFile( 'LastLogin.xml' ) ) then
			--out( ' 2 ' )
			xmlSaveFile( xmlCreateFile( 'LastLogin.xml', 'LastLogin' ) )
		end
		--out( ' 3 ' )
		getAllAdminsAccounts( )
	end
)

function getTimeNow( )
	local time = getRealTime( )
	return string.format(
		'%04d-%02d-%02d %02d:%02d',
		time.year + 1900,
		time.month + 1,
		time.monthday,
		time.hour,
		time.minute 
	)
end

function setUserName( sName, sData )
	local lFile = xmlLoadFile( 'LastLogin.xml' )
	if ( lFile ) then
		local aChild = xmlCreateChild( lFile, 'aLastLogin' )
		xmlNodeSetAttribute( aChild, 'sName', sName )
		xmlNodeSetAttribute( aChild, 'sData', sData )
		xmlSaveFile( lFile )
		xmlUnloadFile( lFile )
	end
end

function getUserName( sName )
	local lFile = xmlLoadFile( 'LastLogin.xml' )
	if ( lFile ) then
		for _, gChildren in ipairs( xmlNodeGetChildren( lFile ) ) do
			local gName = xmlNodeGetAttribute( gChildren, 'sName' )
			if ( gName == sName ) then
				xmlUnloadFile( lFile )
				return true
			end
		end
		xmlUnloadFile( lFile )
		return false
	end
end

function destoryUserName( sName )
	local lFile = xmlLoadFile( 'LastLogin.xml' )
	if ( lFile ) then
		for _, gChildren in ipairs( xmlNodeGetChildren( lFile ) ) do
			local gName = xmlNodeGetAttribute( gChildren, 'sName' )
			if ( gName == sName ) then
				xmlDestroyNode( gChildren )
				xmlSaveFile( lFile )
				xmlUnloadFile( lFile )
				return true
			end
		end
		xmlUnloadFile( lFile )
	end
end

function updateUserName( sName, sData )
	local lFile = xmlLoadFile( 'LastLogin.xml' )
	if ( lFile ) then
		for _, gChildren in ipairs( xmlNodeGetChildren( lFile ) ) do
			local gName = xmlNodeGetAttribute( gChildren, 'sName' )
			if ( gName == sName ) then
				xmlDestroyNode( gChildren )
				xmlSaveFile( lFile )
				xmlUnloadFile( lFile )
				setUserName( sName, sData )
				return true
			end
		end
		xmlUnloadFile( lFile )
	end
end

function getAllAdminsAccounts( )
	for _, aAccounts in next, getAccounts( ) do
		if hasObjectPermissionTo( 'user.' .. getAccountName( aAccounts ), 'general.adminpanel', true ) then
			if not( getUserName( getAccountName( aAccounts ) ) ) then
			--out( getAccountName( aAccounts ) )
			setUserName( getAccountName( aAccounts ), getTimeNow( ) )
			end
		end
	end
end

function isHGAP( aAccountName )
	if hasObjectPermissionTo( 'user.' .. aAccountName, 'general.adminpanel', true ) then
		return true
	end
	return false
end

addEventHandler( 'onPlayerLogin', getRootElement( ),
	function( _, theCurrentAccount )
		if getUserName( getAccountName( theCurrentAccount ) ) and isHGAP( getAccountName( theCurrentAccount ) ) then
			updateUserName( getAccountName( theCurrentAccount ), 'online' )
			--out( ' 1 ' )
		elseif not getUserName( getAccountName( theCurrentAccount ) ) and isHGAP( getAccountName( theCurrentAccount ) ) then
			setUserName( getAccountName( theCurrentAccount ), 'online' )
			--out( ' 2 ' )
		elseif getUserName( getAccountName( theCurrentAccount ) ) and not isHGAP( getAccountName( theCurrentAccount ) ) then
			destoryUserName( getAccountName( theCurrentAccount ) )
			--out( ' 3 ' )
		end
	end
)

addEventHandler( 'onPlayerQuit', getRootElement( ),
	function( )
		local pAccount = getPlayerAccount( source )
		if getUserName( getAccountName( pAccount ) ) and isHGAP( getAccountName( pAccount ) ) then
			updateUserName( getAccountName( pAccount ), getTimeNow( ) )
			--out( ' 1 ' )
		elseif getUserName( getAccountName( pAccount ) ) and not isHGAP( getAccountName( pAccount ) ) then
			destoryUserName( getAccountName( pAccount ) )
			--out( ' 2 ' )
		end
	end
)

addEventHandler( 'onPlayerLogout', getRootElement( ),
	function( thePreviousAccount )
		if getUserName( getAccountName( thePreviousAccount ) ) and isHGAP( getAccountName( thePreviousAccount ) ) then
			updateUserName( getAccountName( thePreviousAccount ), getTimeNow( ) )
			--out( ' 1 ' )
		elseif getUserName( getAccountName( thePreviousAccount ) ) and not isHGAP( getAccountName( thePreviousAccount ) ) then
			destoryUserName( getAccountName( thePreviousAccount ) )
			--out( ' 2 ' )
		end
	end
)

function getDataTime( time )
	--out( time )
	if ( time ~= 'online' ) then
	local aYear, aMonth, aDay = string.match( time, '^(.-)-(.-)-(.-) (.-):(.-)$' )
	local aYear1, aMonth1, aDay1 = string.match( getTimeNow( ), '^(.-)-(.-)-(.-) (.-):(.-)$' )
		if ( aYear == aYear1 ) and ( aMonth == aMonth1 ) and ( aDay == aDay1 ) then
			return 'Today'
		elseif ( aYear == aYear1 ) and ( aMonth == aMonth1 ) and ( aDay ~= aDay1 ) then
			local aDay = ( aDay - 1 )
			if ( aDay1 == string.format( '%02d', aDay ) ) then
				return 'Yesterday'
			elseif ( aMonth == aMonth1 ) and ( aDay1 ~= aDay ) then
				local aDay = ( aDay1 - aDay )
				return math.abs( aDay ).. ' Day ago'
			end
		elseif ( aMonth ~= aMonth1 ) then
			return 'months ago'
		end
	end
	return ' '
end

function getColorData( sData )
	if ( sData == 'online' ) then
		return 0, 255, 0
	elseif ( getDataTime( sData ) == 'Today' ) then 
		return 255, 255, 0
	elseif ( getDataTime( sData ) == 'Yesterday' ) then
		return 255, 255, 0
	else
		return 255, 0, 0
	end
end

function getAllData( )
	local lFile = xmlLoadFile( 'LastLogin.xml' )
	if ( lFile ) then
		for _, gChildren in ipairs( xmlNodeGetChildren( lFile ) ) do
			getCountOnlineAOtherwise( )
			local gName = xmlNodeGetAttribute( gChildren, 'sName' )
			local gData = xmlNodeGetAttribute( gChildren, 'sData' )
			triggerClientEvent( 'onGetAllData', source, gName, gData, nOnline, nOfline, getColorData( gData ) )
		end
		xmlUnloadFile( lFile )
	end
end
addEvent( "aButtonRefresh", true )
addEventHandler( "aButtonRefresh", getRootElement( ), getAllData )


function getCountOnlineAOtherwise( )
	local lFile = xmlLoadFile( 'LastLogin.xml' )
	if ( lFile ) then
		nOnline = 0
		nOfline = 0
		for _, gChildren in ipairs( xmlNodeGetChildren( lFile ) ) do
			local gName = xmlNodeGetAttribute( gChildren, 'sData' )
			if ( gName == 'online' ) then
				nOnline = ( nOnline + 1 )
				--out( nOnline )
			else
				nOfline = ( nOfline + 1 )
				--out( nOfline )
			end
		end
		xmlUnloadFile( lFile )
	end
end

function delUsers ( )
	for _, aAccounts in next, getAccounts( ) do
		if getUserName( getAccountName( aAccounts ) ) and not isHGAP( getAccountName( aAccounts ) ) then
			destoryUserName( getAccountName( aAccounts ) )
		end
	end
end
delUsers ( )

 

2 minutes ago, #,xiRocKyz said:

عشان نقدر نشوف الاكواد

.

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...