cheez3d Posted March 29, 2014 Share Posted March 29, 2014 (edited) 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 March 29, 2014 by Guest Link to comment
Castillo Posted March 29, 2014 Share Posted March 29, 2014 Are you sure the problem is in that code? if your check to see if attempts are 0 or lower returns true, it means that the problem is where you decrease attempts variable. Link to comment
cheez3d Posted March 29, 2014 Author Share Posted March 29, 2014 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
cheez3d Posted March 29, 2014 Author Share Posted March 29, 2014 After I looked into the code several times I realised that I was adding the event handler every time the player pressed the button and that's why it got triggered more and more times per press. Problem solved! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now