DaveHUN Posted February 11, 2023 Share Posted February 11, 2023 I want a script that queries the serial from a specific web, if the serial is there, it can connect to the server, essentially a whitelist system Link to comment
FLUSHBICEPS Posted February 11, 2023 Share Posted February 11, 2023 local serial = getPlayerSerial (getLocalPlayer()) local allowedSerials = { -- List of allowed serials "12345678901234567890123456789012", "23456789012345678901234567890123", "34567890123456789012345678901234" } function isSerialAllowed(serial) for i, allowedSerial in ipairs(allowedSerials) do if serial == allowedSerial then return true end end return false end addEventHandler("onClientResourceStart", resourceRoot, function() if not isSerialAllowed(serial) then -- Kick the player if their serial is not allowed kickPlayer("Your serial is not on the whitelist.") else -- Connect to the server if the serial is allowed -- Replace "server.example.com" with the address of your server triggerServerEvent("connectToServer", resourceRoot, "server.example.com") end end ) addEvent("connectToServer", true) addEventHandler("connectToServer", root, function(serverAddress) -- Connect the player to the specified server -- Replace "serverPassword" with the password for your server connect(serverAddress, "serverPassword") end ) Link to comment
DaveHUN Posted February 12, 2023 Author Share Posted February 12, 2023 1 hour ago, FLUSHBICEPS said: local serial = getPlayerSerial (getLocalPlayer()) local allowedSerials = { -- List of allowed serials "12345678901234567890123456789012", "23456789012345678901234567890123", "34567890123456789012345678901234" } function isSerialAllowed(serial) for i, allowedSerial in ipairs(allowedSerials) do if serial == allowedSerial then return true end end return false end addEventHandler("onClientResourceStart", resourceRoot, function() if not isSerialAllowed(serial) then -- Kick the player if their serial is not allowed kickPlayer("Your serial is not on the whitelist.") else -- Connect to the server if the serial is allowed -- Replace "server.example.com" with the address of your server triggerServerEvent("connectToServer", resourceRoot, "server.example.com") end end ) addEvent("connectToServer", true) addEventHandler("connectToServer", root, function(serverAddress) -- Connect the player to the specified server -- Replace "serverPassword" with the password for your server connect(serverAddress, "serverPassword") end ) not what I meant I would like you to download the serials from a website eg testpage.com/serials.txt and if it is included, it will connect Link to comment
Rilot Posted February 12, 2023 Share Posted February 12, 2023 Just create a database table for it, and query it, and check if the player's serial is there when they connect, if not, use cancelEvent on onPlayerConnect Link to comment
Shady1 Posted February 13, 2023 Share Posted February 13, 2023 (edited) 23 hours ago, DaveHUN said: not what I meant I would like you to download the serials from a website eg testpage.com/serials.txt and if it is included, it will connect hi welcome to forum, i have prepared and tested a code for you, it works,and add it to the whitelist.json one below the other like this,If you have more problems, you can open a new thread. >> Lua << local WHITELIST_API = "http://localhost/whitelist.json" --change with your url addEventHandler("onPlayerJoin", root, function() local player_ = source callRemote(WHITELIST_API, function(response) if(not isElement(player_)) then return end if(response == "ERROR") then return end local playerSerial = getPlayerSerial(player_) for _,serial in ipairs(response) do if(playerSerial == serial) then return end end kickPlayer(player_, "You are not authorized to access this server") end, player_) end ) addEventHandler("onResourceStart", resourceRoot, function() local players = getElementsByType("player") callRemote(WHITELIST_API, function(response) if(response == "ERROR") then return end for _,player in ipairs(players) do if(isElement(player)) then local playerSerial = getPlayerSerial(player) for _,serial in ipairs(response) do if(playerSerial == serial) then return end end kickPlayer(player, "You are not authorized to access this server") end end end, players) end ) >> whitelist.json << [ [ "123", --add serial you want to access serial "321",--add serial you want to access serial "132" --add serial you want to access serial ] ] Edited February 13, 2023 by Shady1 Link to comment
DaveHUN Posted February 13, 2023 Author Share Posted February 13, 2023 8 hours ago, Shady1 said: hi welcome to forum, i have prepared and tested a code for you, it works,and add it to the whitelist.json one below the other like this,If you have more problems, you can open a new thread. >> Lua << local WHITELIST_API = "http://localhost/whitelist.json" --change with your url addEventHandler("onPlayerJoin", root, function() local player_ = source callRemote(WHITELIST_API, function(response) if(not isElement(player_)) then return end if(response == "ERROR") then return end local playerSerial = getPlayerSerial(player_) for _,serial in ipairs(response) do if(playerSerial == serial) then return end end kickPlayer(player_, "You are not authorized to access this server") end, player_) end ) addEventHandler("onResourceStart", resourceRoot, function() local players = getElementsByType("player") callRemote(WHITELIST_API, function(response) if(response == "ERROR") then return end for _,player in ipairs(players) do if(isElement(player)) then local playerSerial = getPlayerSerial(player) for _,serial in ipairs(response) do if(playerSerial == serial) then return end end kickPlayer(player, "You are not authorized to access this server") end end end, players) end ) >> whitelist.json << [ [ "123", --add serial you want to access serial "321",--add serial you want to access serial "132" --add serial you want to access serial ] ] and it could be resolved that only the series would be included in the file Link to comment
Shady1 Posted February 13, 2023 Share Posted February 13, 2023 11 hours ago, DaveHUN said: and it could be resolved that only the series would be included in the file Is your problem fixed? Link to comment
Addlibs Posted February 13, 2023 Share Posted February 13, 2023 (edited) I'd point out @Shady1's solution does not scale well as the whitelist gets bigger. It would be more ideal to, on start-up, and then periodically (or on command like refreshwhitelist) download the list, store it in a Lua table in a [serial] = bool structure and look-up that table onPlayerConnect, and cancelEvent(true) if serial not present (which also benefits the server process as a good part of player join sequence is aborted earlier, including the construction of a player element). This way you don't download the whole list every time a player joins, parse it every time a player joins, and iterate thought it every time a player joins. Lua table look-ups benefit from hashing, leading to much faster lookup speeds than iterating thought the list, provided the list is large enough (could be as little as 5 entries for benefits to show up but I haven't tested it) (otherwise hashing could be more expensive). Edited February 13, 2023 by Addlibs 1 Link to comment
FernandoMTA Posted February 13, 2023 Share Posted February 13, 2023 21 minutes ago, Addlibs said: I'd point out @Shady1's solution does not scale well as the whitelist gets bigger. It would be more ideal to, on start-up, and then periodically (or on command like refreshwhitelist) download the list, store it in a Lua table in a [serial] = bool structure and look-up that table onPlayerConnect, and cancelEvent(true) if serial not present (which also benefits the server process as a good part of player join sequence is aborted earlier, including the construction of a player element). This way you don't download the whole list every time a player joins, parse it every time a player joins, and iterate thought it every time a player joins. Lua table look-ups benefit from hashing, leading to much faster lookup speeds than iterating thought the list, provided the list is large enough (could be as little as 5 entries for benefits to show up but I haven't tested it) (otherwise hashing could be more expensive). Upvoting. This way you can indeed do cancelEvent (true, "You are not whitelisted") onPlayerConnect and this will effectively prevent the player from connecting with that custom message. This is prettier than kickPlayer which you are doing with a certain delay by getting the result of callRemote. Link to comment
Shady1 Posted February 13, 2023 Share Posted February 13, 2023 (edited) 54 minutes ago, Addlibs said: I'd point out @Shady1's solution does not scale well as the whitelist gets bigger. It would be more ideal to, on start-up, and then periodically (or on command like refreshwhitelist) download the list, store it in a Lua table in a [serial] = bool structure and look-up that table onPlayerConnect, and cancelEvent(true) if serial not present (which also benefits the server process as a good part of player join sequence is aborted earlier, including the construction of a player element). This way you don't download the whole list every time a player joins, parse it every time a player joins, and iterate thought it every time a player joins. Lua table look-ups benefit from hashing, leading to much faster lookup speeds than iterating thought the list, provided the list is large enough (could be as little as 5 entries for benefits to show up but I haven't tested it) (otherwise hashing could be more expensive). you're right, I thought about that, but I chose this way to keep the list updated. Lua local WHITELIST_API = "http://localhost/whitelist.json" --change with your url local serialWhitelist = {} function updateWhitelist() for serial,_ in pairs(serialWhitelist) do serialWhitelist[serial] = nil end callRemote(WHITELIST_API, function(response) if(response == "ERROR") then outputDebugString("Unable to get to Whitelist File.", 1) return end for _,serial in ipairs(response) do serialWhitelist[serial] = true end outputDebugString("Whitelist Updated Succesfuly!") for _,player in ipairs(getElementsByType("player")) do if(isElement(player)) then local playerSerial = getPlayerSerial(player) if(not serialWhitelist[playerSerial]) then kickPlayer(player, "You are not authorized to access this server") end end end end) end addEventHandler("onResourceStart", resourceRoot, function() callRemote(WHITELIST_API, function(response) if(response == "ERROR") then return outputDebugString("Unable to get to Whitelist File.", 1) end for _,serial in ipairs(response) do serialWhitelist[serial] = true end for _,player in ipairs(getElementsByType("player")) do if(isElement(player)) then local playerSerial = getPlayerSerial(player) if(not serialWhitelist[playerSerial]) then kickPlayer(player, "You are not authorized to access this server") end end end end) end ) addEventHandler("onPlayerConnect", root, function(_, _, _, playerSerial) if(not serialWhitelist[playerSerial]) then cancelEvent(true, "You are not authorized to access this server") end end ) addCommandHandler("updatelist", function() updateWhitelist() end) On 11/02/2023 at 18:50, DaveHUN said: I want a script that queries the serial from a specific web, if the serial is there, it can connect to the server, essentially a whitelist system if you like my help, you can like my comment Edited February 13, 2023 by Shady1 Link to comment
Shady1 Posted February 14, 2023 Share Posted February 14, 2023 On 11/02/2023 at 18:50, DaveHUN said: I want a script that queries the serial from a specific web, if the serial is there, it can connect to the server, essentially a whitelist system Is your problem solved? Link to comment
DaveHUN Posted February 14, 2023 Author Share Posted February 14, 2023 https://prnt.sc/OFSql5-KZG8y Link to comment
Shady1 Posted February 14, 2023 Share Posted February 14, 2023 12 minutes ago, DaveHUN said: https://prnt.sc/OFSql5-KZG8y there is no problem when i try it, you should check again,i ran the code myself and sent you the code as it was activated successfully so something is wrong with you 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