AGENT_STEELMEAT Posted August 2, 2011 Share Posted August 2, 2011 So, I was just wondering if someone with more experience with MySQL / MySQL-based gamemodes can tell me if I have any bugs / flaws left in this system that I should fix. In other words, Did I Do It Right? addEvent("registerRequest", true) function processReqisterRequest(username, password) if client and source ~= client then return end local databaseNode = databaseConnection() if not databaseNode then return end local username = mysql_escape_string(databaseNode, username) local origPassword = password local password = mysql_escape_string(databaseNode, password) local accountQuery = mysql_query(databaseNode, "SELECT * FROM accounts WHERE username = \'"..string.lower(username).."\'") if accountQuery then if mysql_num_rows(accountQuery) == 0 then local serialCheck = mysql_query(databaseNode, "SELECT * FROM accounts WHERE firstSerial = \'"..getPlayerSerial(source).."\'") if serialCheck then if mysql_num_rows(serialCheck) < 3 then --local newAccount = mysql_query(databaseNode, "INSERT INTO accounts (username, password, registerDate, firstSerial) VALUES (\'"..string.lower(username).."\', \'"..password.."\', NOW(), \'"..getPlayerSerial(source).."\')") local newAccount = true if newAccount then triggerClientEvent(source, "registerSuccess", RESOURCE_ROOT, "You have successfully registered an account! You may now login.") mysql_free_result(newAccount) else --ERROR CODE REG1 triggerClientEvent(source, "registerFailure", RESOURCE_ROOT, "Unable to perform the registration query! Please contact an admin. [ERROR CODE: REG1]") end else triggerClientEvent(source, "registerFailure", RESOURCE_ROOT, "You may only register up to 3 accounts here! Contact [email protected] for account recovery instructions.") return end mysql_free_result(serialCheck) else --ERROR CODE REG2 triggerClientEvent(source, "registerFailure", RESOURCE_ROOT, "Unable to perform the registration query! Please contact an admin. [ERROR CODE: REG2]") return end else triggerClientEvent(source, "registerFailure", RESOURCE_ROOT, "An account with this name already exists!") end mysql_free_result(accountQuery) else --ERROR CODE REG3 triggerClientEvent(source, "registerFailure", RESOURCE_ROOT, "Unable to perform the registration query! Please contact an admin. [ERROR CODE: REG3]") return end end Link to comment
AGENT_STEELMEAT Posted August 3, 2011 Author Share Posted August 3, 2011 *** Shameless self-bump *** Can anyone give any input on this? Link to comment
Jaysds1 Posted August 3, 2011 Share Posted August 3, 2011 Don't double post and it looks like it good enough. Link to comment
AGENT_STEELMEAT Posted August 3, 2011 Author Share Posted August 3, 2011 One - it was a shameless self bump, thats the whole point. Two - I was looking for someone with lots of mysql experience to look at this. Link to comment
JR10 Posted August 3, 2011 Share Posted August 3, 2011 (edited) Are you sure there is databaseConnection() No there isn't you must use "mysql_connect" If it's a custom function you made then try: addEvent("registerRequest", true) function processReqisterRequest(username, password) local databaseNode = databaseConnection() if not databaseNode then return end username = mysql_escape_string(databaseNode, username) local origPassword = password password = mysql_escape_string(databaseNode, password) local accountQuery = mysql_query(databaseNode, "SELECT * FROM accounts WHERE username = '"..string.lower(username).."'") if accountQuery then if mysql_num_rows(accountQuery) == 0 then local serialCheck = mysql_query(databaseNode, "SELECT * FROM accounts WHERE firstSerial = '"..getPlayerSerial(source).."'") if serialCheck then if mysql_num_rows(serialCheck) < 3 then --local newAccount = mysql_query(databaseNode, "INSERT INTO accounts (username, password, registerDate, firstSerial) VALUES ('"..string.lower(username).."', '"..password.."', NOW(), '"..getPlayerSerial(source).."')") local newAccount = true if newAccount then triggerClientEvent(source, "registerSuccess", source, "You have successfully registered an account! You may now login.") mysql_free_result(newAccount) else --ERROR CODE REG1 triggerClientEvent(source, "registerFailure", source, "Unable to perform the registration query! Please contact an admin. [ERROR CODE: REG1]") end else triggerClientEvent(source, "registerFailure", source, "You may only register up to 3 accounts here! Contact [email protected] for account recovery instructions.") return end mysql_free_result(serialCheck) else --ERROR CODE REG2 triggerClientEvent(source, "registerFailure", source, "Unable to perform the registration query! Please contact an admin. [ERROR CODE: REG2]") return end else triggerClientEvent(source, "registerFailure", source, "An account with this name already exists!") end mysql_free_result(accountQuery) else --ERROR CODE REG3 triggerClientEvent(source, "registerFailure", source, "Unable to perform the registration query! Please contact an admin. [ERROR CODE: REG3]") return end end Edited August 3, 2011 by Guest Link to comment
AGENT_STEELMEAT Posted August 3, 2011 Author Share Posted August 3, 2011 ... You removed local from 'username' and 'password' ...? Then you removed if 'client and source ~= client then return end'? Ohh, and then you changed the source of the event from RESOURCE_ROOT to source? None of those changes make sense... Link to comment
JR10 Posted August 3, 2011 Share Posted August 3, 2011 Why don't you understand first, there is already 2 variables called 'username' and 'password' so removing local from username and password is required, and if i'm right it might gives an error. Yes i removed source ~= client because if i'm right source == client if you triggered the server event right. And i also edited your triggerClientEvent replaced RESOURCE_ROOT (which i didn't find a define for it) to source which is the player. Did you even test it?, i'm not a post count seeker, i'm just trying to help. Link to comment
AGENT_STEELMEAT Posted August 3, 2011 Author Share Posted August 3, 2011 Ehhm, the function works - as I stated above, I'm just looking for someone who is good with the MySQL aspect of it to tell me if I've left out something important. And "if client and source ~= client then return end" is a small form of anticheat. Link to comment
JR10 Posted August 3, 2011 Share Posted August 3, 2011 You haven't done anything wrong with mysql functions. And yes every change i did makes sense, removing local is actually critical, because you can't use local on a defined variable, And changing RESOURCE_ROOT is important because why using resourceRoot on the base Element in triggerClientEvent, which is not even defined. Link to comment
AGENT_STEELMEAT Posted August 3, 2011 Author Share Posted August 3, 2011 RESOURCE_ROOT is defined in my main server script. It's global. Using local in this case works just fine. My main concern is if I left a typo or something in the mysql stuff. 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