Jump to content

[Help] ID Generating Login Panel


Recommended Posts

Posted (edited)

This id generating login panel connects to various systems such as inventory. However, I'm unable to resolve the error in this login panel.

https://hizliresim.com/etik01d

function getIDFromPlayer(id)
    if id then
	    local theid
		idTablo = getElementsByType("id")
	    for id,p in pairs(idTablo) do
		    if id == p then
		        theid = i
			end
		end
		return theid
	else return false end
end

function getPlayerFromID(id)
    if id then
	   id = tonumber(id)
	   local theplayer
	   idTablo = getElementsByType("id")
	   for id,p in pairs(idTablo) do
		    if theID == id then
		        theplayer = p
			end
		end	
		return theplayer
	else return false end
end

addEventHandler("onPlayerLogin", root, function(_,hesap)
	setElementData(source, "loggedin", true)
	setElementData(source,"TuningMenuTrue",false)
	local hesapID = getAccountID(hesap)
	if idTablo[hesapID] then                        -- The line where the error is indicated is here.
		ozelID = idTablo[hesapID]
		setElementID(source,ozelID)
	else
		setElementID(source,hesapID)
	end
	local oyuncu = (string.gsub(getPlayerName(source),"#%x%x%x%x%x%x",""))
	local id = getElementID(source) or "-1"
end)

addEventHandler("onResourceStart", resourceRoot, function()
    if id then
	    id = tonumber(id)
	    local theplayer
	    idTablo = getElementsByType("id")
	    for id,p in ipairs(getElementsByType("player")) do
		  setElementData(player, "loggedin", not isGuestAccount(getPlayerAccount(player)))
		  setElementData(player, "TuningMenuTrue", isGuestAccount(getPlayerAccount(player)))
		    if getPlayerAccount(player) then 
			    local hesapID = getAccountID(getPlayerAccount(player))
			    if idTablo[hesapID] then
				  ozelID = idTablo[hesapID]
				  setElementID(player,ozelID)
				end
			end
		end
	end
end)

 

Edited by #nofear
Link to comment
  • Moderators
On 04/07/2024 at 17:44, #nofear said:

However, I'm unable to resolve the error in this login panel.

There are a lot of things wrong with this code. I also noticed that the code contains both tabs and spaces, which mean two different users have been messing with this code (80% sure). And on top of that 50% of the code is broken... 🤦‍♂️

I have fixed the spaces/tabs for you, and showed you where mistakes are located. But the rest is up to you, especially since I have not clue how this is suppose to be working.

 

function getIDFromPlayer(id)
	if id then
		local theid                 -- Issue: not defined
		idTablo = getElementsByType("id") -- Issue: Returns a table of elements, the order can vary and the index does not necessary means it's the correct it.
		for id, p in pairs(idTablo) do
			if id == p then         -- Issue: Comparing integer with an element
				theid = i           -- Issue: `i` not defined
				-- Issue: loop should have been broken with `break`
			end
		end
		return theid
	else
		return false
	end
end

function getPlayerFromID(id)
	if id then
		id = tonumber(id)             -- Issue: tonumber should be before the `if id then`
		local theplayer               -- Issue: Value is nil
		idTablo = getElementsByType("id") -- Issue: Returns a table of elements, the order can vary and the index does not necessary means it's the correct it.
		for id, p in pairs(idTablo) do
			if theID == id then       -- Issue: theID is not defined, comparing nil with integer
				theplayer = p
				-- Issue: loop should have been broken with `break`
			end
		end
		return theplayer
	else
		return false
	end
end

addEventHandler("onPlayerLogin", root, function(_, hesap)
	setElementData(source, "loggedin", true)
	setElementData(source, "TuningMenuTrue", false)
	local hesapID = getAccountID(hesap)
	if idTablo[hesapID] then  -- Issue: idTablo might not be defined
		ozelID = idTablo[hesapID]
		setElementID(source, ozelID) -- ozelID if from getElementsByType is an element, not an integer/string
	else
		setElementID(source, hesapID)
	end
	local oyuncu = (string.gsub(getPlayerName(source), "#%x%x%x%x%x%x", ""))
	local id = getElementID(source) or "-1"
	-- Variable `oyuncu` and `id` not being used
end)

addEventHandler("onResourceStart", resourceRoot, function()
	-- Issue: `id` is not defined
	if id then
		id = tonumber(id) -- Issue: tonumber should be before the `if id then`
		local theplayer -- Issue: Value is nil
		idTablo = getElementsByType("id")
		for id, p in ipairs(getElementsByType("player")) do
			-- Issue: neither variable `id` nor `p` are being used
			-- Issue: player is not defined. (shouldn't have been variable `p`?)
			setElementData(player, "loggedin", not isGuestAccount(getPlayerAccount(player)))
			setElementData(player, "TuningMenuTrue", isGuestAccount(getPlayerAccount(player)))
			if getPlayerAccount(player) then
				local hesapID = getAccountID(getPlayerAccount(player))
				if idTablo[hesapID] then
					ozelID = idTablo[hesapID] -- Issue: Should be a local, ozelID is an element, not an id
					setElementID(player, ozelID) -- ozelID if from getElementsByType is an element, not an integer/string
				end
			end
		end
	end
end)

 

Link to comment
4 hours ago, IIYAMA said:

Bu kodda çok fazla yanlış şey var. Ayrıca kodun hem sekmeler hem de boşluklar içerdiğini fark ettim , bu da iki farklı kullanıcının bu kodla uğraştığı anlamına geliyor (%80 eminim). Ve bunun üstüne kodun %50'si bozuk... 🤦‍♂️

Boşlukları/sekmeleri sizin için düzelttim ve hataların nerede olduğunu gösterdim. Ama gerisi size kalmış, özellikle de bunun nasıl çalışması gerektiği hakkında hiçbir fikrim olmadığı için.

 

 
	  
		                  
		   
			                      
				
			
		
		 
		 
	


 
	  
		                
		   
			         
			
		
		 
		 
	


	 
	   
	
	
	 
	  
	


	
	  
		  
		   
			
			 
			 
				 
				 
				
			
		
	

 

Yes, you're right. I have changed some things in the project. When I get home, I will upload the original version so that I'm sure some things will be smoother. However, even in the original version, I couldn't get the project to run.

Link to comment
  • Moderators
3 minutes ago, #nofear said:

I will upload the original version so that I'm sure some things will be smoother.

We might have more luck with that one. 👍

Link to comment
4 hours ago, IIYAMA said:

There are a lot of things wrong with this code. I also noticed that the code contains both tabs and spaces, which mean two different users have been messing with this code (80% sure). And on top of that 50% of the code is broken... 🤦‍♂️

I have fixed the spaces/tabs for you, and showed you where mistakes are located. But the rest is up to you, especially since I have not clue how this is suppose to be working.

 

function getIDFromPlayer(id)
	if id then
		local theid                 -- Issue: not defined
		idTablo = getElementsByType("id") -- Issue: Returns a table of elements, the order can vary and the index does not necessary means it's the correct it.
		for id, p in pairs(idTablo) do
			if id == p then         -- Issue: Comparing integer with an element
				theid = i           -- Issue: `i` not defined
				-- Issue: loop should have been broken with `break`
			end
		end
		return theid
	else
		return false
	end
end

function getPlayerFromID(id)
	if id then
		id = tonumber(id)             -- Issue: tonumber should be before the `if id then`
		local theplayer               -- Issue: Value is nil
		idTablo = getElementsByType("id") -- Issue: Returns a table of elements, the order can vary and the index does not necessary means it's the correct it.
		for id, p in pairs(idTablo) do
			if theID == id then       -- Issue: theID is not defined, comparing nil with integer
				theplayer = p
				-- Issue: loop should have been broken with `break`
			end
		end
		return theplayer
	else
		return false
	end
end

addEventHandler("onPlayerLogin", root, function(_, hesap)
	setElementData(source, "loggedin", true)
	setElementData(source, "TuningMenuTrue", false)
	local hesapID = getAccountID(hesap)
	if idTablo[hesapID] then  -- Issue: idTablo might not be defined
		ozelID = idTablo[hesapID]
		setElementID(source, ozelID) -- ozelID if from getElementsByType is an element, not an integer/string
	else
		setElementID(source, hesapID)
	end
	local oyuncu = (string.gsub(getPlayerName(source), "#%x%x%x%x%x%x", ""))
	local id = getElementID(source) or "-1"
	-- Variable `oyuncu` and `id` not being used
end)

addEventHandler("onResourceStart", resourceRoot, function()
	-- Issue: `id` is not defined
	if id then
		id = tonumber(id) -- Issue: tonumber should be before the `if id then`
		local theplayer -- Issue: Value is nil
		idTablo = getElementsByType("id")
		for id, p in ipairs(getElementsByType("player")) do
			-- Issue: neither variable `id` nor `p` are being used
			-- Issue: player is not defined. (shouldn't have been variable `p`?)
			setElementData(player, "loggedin", not isGuestAccount(getPlayerAccount(player)))
			setElementData(player, "TuningMenuTrue", isGuestAccount(getPlayerAccount(player)))
			if getPlayerAccount(player) then
				local hesapID = getAccountID(getPlayerAccount(player))
				if idTablo[hesapID] then
					ozelID = idTablo[hesapID] -- Issue: Should be a local, ozelID is an element, not an id
					setElementID(player, ozelID) -- ozelID if from getElementsByType is an element, not an integer/string
				end
			end
		end
	end
end)

 

Please evaluate the original version of the Server.lua section of the Login Panel.
 


local function do_login(player, username, password, save_log)
	setElementData(source, "loggedin", true)
	triggerClientEvent(source, "closeLogin", source)
	if save_log then
		triggerClientEvent(source, "saveLoginToXML", root, username, password)
	else
		triggerClientEvent(source, "resetSaveXML", root, username, password)
	end
end

addEvent("onAccountManage", true)
addEventHandler("onAccountManage", root, function(typ, username, password, save_log)
	if not hasObjectPermissionTo(getThisResource(), "function.addAccount", true) then
		triggerClientEvent(source, "setInfoText", source, 9)
		return
	end
	if typ == "register" then
		if getAccount(username) then
			triggerClientEvent(source, "setInfoText", source, 5)
			return
		end
		addAccount(username, password)
		if save_log then
			logIn(source, getAccount(username), password)
			setElementData(source, "loggedin", true)
			triggerClientEvent(source, "closeLogin", source)
			return
		end
		triggerClientEvent(source, "setInfoText", source, 11)
	elseif typ == "login" then
		if not getAccount(username) then
			triggerClientEvent(source, "setInfoText", source, 6)
			return
		end
		if not getAccount(username, password) then
			triggerClientEvent(source, "setInfoText", source, 7)
			return
		end
		
		if logIn(source, getAccount(username), password) then
			do_login(source, username, password, save_log)
		else
			if getAccount(username) and getAccountPlayer(getAccount(username)) == source then
				do_login(source, username, password, save_log)
				return
			end
			triggerClientEvent(source, "setInfoText", source, 12)
		end
	end
end)

addEventHandler("onPlayerLogout", root, function()
	setElementData(source," loggedin", false)
	setElementData(source,"TuningMenuTrue",true)
end)


function getAccountRealID(id)
	for i,v in pairs(idTablo) do
		if v == id then
			return i
		end
	end
end

function getAccountOzelID(id)
	for i,v in pairs(idTablo) do
		if i == id then
			return v
		end
	end
end

addEventHandler("onPlayerLogin", root, function(_,hesap)
	setElementData(source, "loggedin", true)
	setElementData(source,"TuningMenuTrue",false)
	local hesapID = getAccountID(hesap)
	if idTablo[hesapID] then
		ozelID = idTablo[hesapID]
		setElementID(source,ozelID)
	else
		setElementID(source,hesapID)
	end
	local oyuncu = (string.gsub(getPlayerName(source),"#%x%x%x%x%x%x",""))
	local id = getElementID(source) or "-1"
end)


addEventHandler("onResourceStart", resourceRoot, function()
	for i, player in ipairs(getElementsByType("player")) do
		setElementData(player, "loggedin", not isGuestAccount(getPlayerAccount(player)))
		setElementData(player,"TuningMenuTrue", isGuestAccount(getPlayerAccount(player)))
		if getPlayerAccount(player) then
			local hesapID = getAccountID(getPlayerAccount(player))
			if idTablo[hesapID] then
				ozelID = idTablo[hesapID]
				setElementID(player,ozelID)
			end
		end
	end
end)

addEventHandler('onPlayerJoin', root,function ()
	outputChatBox(' ', source, 0, 255, 0, true)
	outputChatBox(' ', source, 0, 255, 0, true)
	outputChatBox(' ', source, 0, 255, 0, true)
	outputChatBox(' ', source, 0, 255, 0, true)
	outputChatBox(' ', source, 0, 255, 0, true)
	outputChatBox(' ', source, 0, 255, 0, true)
	outputChatBox(' ', source, 255, 255, 255, true)
	outputChatBox(' ', source, 255, 255, 255, true)
	outputChatBox('#FFFFFFHoş Geldiniz. #1878FFİyi Oyunlar...', source, 0, 255, 0, true)  
	outputChatBox('#FFFFFFDiscord için #1878FF/dc #ffffffyazınız.', source, 0, 255, 0, true)
end)

addEventHandler("onPlayerCommand",root,function(cmd)
	if cmd == "logout" then 
        cancelEvent()
    end
end)

addEventHandler("onPlayerJoin",root,function()
    setPlayerBlurLevel(source,0)
end)

addEventHandler("onResourceStart",resourceRoot,function ()
    setPlayerBlurLevel(root,0)
end)

 

Link to comment
  • Moderators
2 hours ago, #nofear said:

Please evaluate the original version of the Server.lua section of the Login Panel.

 

Here is a fix for a vulnerability for cheaters to abuse (else cheaters can create accounts for other players):

addEvent("onAccountManage", true)
addEventHandler("onAccountManage", root, function(typ, username, password, save_log)
	if source ~= client then return end -- Fix vulnerability

 

The addAccount function returns the new created account, but can fail. Not the end of the world.

addAccount(username, password)

 

Are there any errors in this code?

I can't find the variable declaration of idTablo, is this one located in another file?

 

 

Link to comment
Posted (edited)
On 06/07/2024 at 23:15, IIYAMA said:

 

Here is a fix for a vulnerability for cheaters to abuse (else cheaters can create accounts for other players):

addEvent("onAccountManage", true)
addEventHandler("onAccountManage", root, function(typ, username, password, save_log)
	if source ~= client then return end -- Fix vulnerability

 

The addAccount function returns the new created account, but can fail. Not the end of the world.

addAccount(username, password)

 

Are there any errors in this code?

I can't find the variable declaration of idTablo, is this one located in another file?

 

 

 
addEventHandler("onPlayerLogin", root, function(_,hesap)
	setElementData(source, "loggedin", true)
	setElementData(source,"TuningMenuTrue",false)
	local hesapID = getAccountID(hesap)
	if idTablo[hesapID] then                                   --"The place where the error occurred."
		ozelID = idTablo[hesapID]
		setElementID(source,ozelID)
	else
		setElementID(source,hesapID)
	end
	local oyuncu = (string.gsub(getPlayerName(source),"#%x%x%x%x%x%x",""))
	local id = getElementID(source) or "-1"
end)


addEventHandler("onResourceStart", resourceRoot, function()
	for i, player in ipairs(getElementsByType("player")) do
		setElementData(player, "loggedin", not isGuestAccount(getPlayerAccount(player)))
		setElementData(player,"TuningMenuTrue", isGuestAccount(getPlayerAccount(player)))
		if getPlayerAccount(player) then
			local hesapID = getAccountID(getPlayerAccount(player))
			if idTablo[hesapID] then                                   -- "The place where the error occurred."
				ozelID = idTablo[hesapID]
				setElementID(player,ozelID)
			end
		end
	end
end)

The issue I'm experiencing actually lies within these lines.

Edited by #nofear
Link to comment
  • Moderators
5 hours ago, #nofear said:

The issue I'm experiencing actually lies within these lines.

Have you searched in your other files for `idTablo` ?

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