Jump to content

Authentication by IP adress in my script.


rusztamas

Recommended Posts

Hi! I started writing a script, and i don't know what the problem is.
 

function adminauth()
	local ips = {
	["192.168.56.1"] = true
	}
	local p_IP = tostring(getPlayerIP(source))
	if tostring(p_IP) == tostring(ips) then
		setElementData (source, "administrator", true)
		outputChatBox ("correct! #FFFFFF"..p_IP.."", getRootElement(), 0, 255, 0, true)
		else
		outputChatBox ("wrong! #FFFFFF"..p_IP.."", getRootElement(), 255, 0, 0, true)	
		end
	end
addEventHandler ("onPlayerJoin", getRootElement(), adminauth)

When i join the game it outputs wrong.
I'm playing this on local server, i tried to use it with serials but none of them worked.
When you join it should output correct, and set "administrator" element data true, on you. What the problem could be? Please help me!

Link to comment
function adminauth()
	local ips = {
		["192.168.56.1"] = true
	}
	local p_IP = tostring(getPlayerIP(source))
	if ips[p_IP] then
		setElementData (source, "administrator", true)
		outputChatBox ("correct! #FFFFFF"..p_IP.."", getRootElement(), 0, 255, 0, true)
	else
		outputChatBox ("wrong! #FFFFFF"..p_IP.."", getRootElement(), 255, 0, 0, true)	
	end
end
addEventHandler ("onPlayerJoin", getRootElement(), adminauth)

 

  • Like 1
Link to comment

It's about indexing the table. You just set the table's value at the index of "192.168.56.1" to true. You can call that value by just indexing the table (tableName[indexName]). As you have true at that index, it will be like "if true then", so it goes into the true  part, and outputs the "correct text". But, if you can't index the table, so it doesn't have somone elses IP registered in the table, it'll always return false, so it'll be like "if false then", so it goes into the false part. I hope you can understand it. It was just indexing a table with the corrected code, but at the original code you were comparing a table with a string value, and two different type of variables can't be equal.

Edited by NeXuS™
  • 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...