Jump to content

[SOLVED] Multiple times


cheez3d

Recommended Posts

I have a problem. I wanted to create a little anti spam filter. If the player fails to login 5 times then he will be kicked, but the problem is that the clientside function executes more than one time and I don't get kicked after 5 invalid attempts, but 3 invalid attempts. Everything else is explained in the script. Any help is appreciated :).

SERVER SIDE EVENT (where we check the data):

  
addEventHandler("dayz:onPlayerRequestLogin",root,function(password) 
    if password then 
        local data = dbPoll(dbQuery(getElementData(resourceRoot,"dayz:resource.settings.database"),"SELECT `password` FROM `players` WHERE `serial`=?;",string.lower(getPlayerSerial(client))),-1) 
        if data then 
            if data[1]["password"] then 
                if string.lower(md5(password)) == data[1]["password"] then 
                    triggerClientEvent(client,"dayz:onClientPlayerRequestLogin",client,true) -- password is correct 
                else 
                    local event = triggerClientEvent(client,"dayz:onClientPlayerRequestLogin",client,false) -- password isn't correct 
                    outputChatBox(tostring(event),root) -- wanted to check if the problem is here, but it is not here, the event get's triggered just one time per button press 
                end 
            end 
        end 
    end 
end) 
  

CLIENT SIDE EVENT (this piece gets executed when the player presses a button).

  
        triggerServerEvent("dayz:onPlayerRequestLogin",localPlayer,guiGetText(content.box)) -- send data to server 
        addEventHandler("dayz:onClientPlayerRequestLogin",localPlayer,function(result) -- server returns the result inside this function 
            local attempts = 5 
            if result then -- if the password hashes are identical 
                register_window:destroy("fade_out") 
                register_window = nil 
            elseif not result then -- if they're not identical 
                outputChatBox("event triggered") -- this is where the problem is, this messages will output at the first press once, the at the second press twice, at the third press three times, and so on... what could be the problem? 
                attempts = attempts -1 
                guiSetText(content.output,string.format("Invalid password! Use the %s button for recovery. You have %d attempts left.","Recover",attempts)) 
                guiSetText(content.box,"") 
                guiSetPosition(content.button_login.skeleton,(width-305)/2,(height-50)-25,false) 
                if not content.button_recover then 
                    content.button_recover = GUI.Button.Normal:create((width-305)/2+155,(height-50)-25,150,50,"Recover",30,true,{91,91,91},{28,28,28},{156,156,156},function() 
                        outputChatBox("UNDER CONSTRUCTION") 
                    end,content.skeleton) 
                end 
                if attempts<=0 then 
                    triggerServerEvent("dayz:onPlayerTriggerLeave",localPlayer,"Console","You exceed the maximum login attempts",300) 
                end 
            end 
        end) 
  

Edited by Guest
Link to comment

I forgot to add the attempts part. I edited the first post. I just decrease the attempts variable by one every time an invalid password is entered. But it modifies like this:

First button press: 5-1 => 4 (function gets triggered 1 time)

Second button press: 4-1 and then 3-1 => 2 (function gets triggered 2 times)

Third button press: 2-1 and then 1-1 and then 0-1 => -1 (function gets triggered 3 times)

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