egorkoltyshev Posted April 4, 2022 Share Posted April 4, 2022 I do authorization, I made a check so that two players with the same login could not log in at the same time. How to check if the case of the login entered in the game matches the login in the database? "test" (game) - "test" (base) = the player will not be skipped, since the player with this login is already in the game. "Test" (game) - "test" (base) = will skip the player and there will be 2 players in the game under one account. addEvent('playerLogged', true) addEventHandler('playerLogged', root, function(login, password) local check = exports.mysql:mysql_query_single("SELECT * FROM `players` WHERE `login` = ?", login) for _, p in pairs(getElementsByType("Player")) do if(getElementData(p, "login") == login) then outputChatBox("The player under this login is on the server.", source) return end end ..... Link to comment
Addlibs Posted April 11, 2022 Share Posted April 11, 2022 You don't seem to be using the result of local check = exports.mysql:mysql_query_single("SELECT * FROM `players` WHERE `login` = ?", login) anywhere in the snippet, you might want to move it closer to where you use it for more readability, and either way, its not relevant to this snippet so it could have been omitted. Now if you want to do a case insensitive comparison between people's logins, your best bet is to lowercase or uppercase both sides of the comparison, or ensure one of the sides is always lowercase/uppercase and case fold the other side: -- turn both sides to lowercase if(string.lower(getElementData(p, "login")) == string.lower(login)) then -- ... end -- or -- lowercase the user input local lowercaseLogin = string.lower(login) for _, p in --[[...]] do if(getElementData(p, "login") == lowercaseLogin) then -- compare stored -- ... end end --- ... -- ensure the login value in element data is always stored in lowercase setElementData(p, "login", lowercaseLogin) The second option is slightly more efficient since you only need to lowercase it once per player when logging in, rather than for every player when one player logs in, essentially a O(1) vs O(n) difference. Link to comment
egorkoltyshev Posted April 12, 2022 Author Share Posted April 12, 2022 (edited) Thanks. This is exactly what I did as a temporary solution. But I need to compare the player's login case sensitive. Unfortunately, I did not find a function for this. if(getPlayerCount() > 1) then for _, p in pairs(getElementsByType("Player")) do if(hasElementData(p, "isLogged")) then if(string.lower(login) == string.lower(getElementData(p, "login"))) then outputChatBox("The player under this login is on the server.", source) return end end end end Edited April 12, 2022 by egorkoltyshev Link to comment
Moderators Citizen Posted April 13, 2022 Moderators Share Posted April 13, 2022 I think you removed a lot of the actual code but your loop should work if you fix the typo here (everything you did is case sensitive already): for _, p in pairs(getElementsByType("player")) do -- "player" not "Player" If that's not the issue in your code, then there has to be an error in the logs ? (playerLogged is the server event called from the login GUI form right ?) 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