Eshtiz Posted January 29, 2012 Share Posted January 29, 2012 I encountered a new problem, for some reason, I can't enable registrations. They're enabled in settings.xml, all there's left is registration.lau Here's the script:[registration.lau] local allowRegistration = get('allow_registration') and true or false local registrationErrorMessage = get( 'registration_error_message' ) if registrationErrorMessage then -- fix for newlines in message registrationErrorMessage = registrationErrorMessage:gsub( "\\n", "\n" ) end addEventHandler( "onResourceStart", resourceRoot, function( ) setElementData( source, "allowRegistration", allowRegistration ) setElementData( source, "registrationErrorMessage", registrationErrorMessage ) end ) local function trim( str ) return str:gsub("^%s*(.-)%s*$", "%1") end addEvent( getResourceName( resource ) .. ":register", true ) addEventHandler( getResourceName( resource ) .. ":register", root, function( username, password ) if source == client then if allowRegistration then if username and password then username = trim( username ) password = trim( password ) -- client length checks are the same if #username >= 3 and #password >= 8 then -- see if that username is free at all local info = exports.sql:query_assoc_single( "SELECT COUNT(userID) AS usercount FROM wcf1_user WHERE username = '%s'", username ) if not info then triggerClientEvent( source, getResourceName( resource ) .. ":registrationResult", source, 1 ) elseif info.usercount == 0 then -- generate a salt (SHA1) local salt = '' local chars = { 'a', 'b', 'c', 'd', 'e', 'f', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } for i = 1, 40 do salt = salt .. chars[ math.random( 1, #chars ) ] end -- create the user if exports.sql:query_free( "INSERT INTO wcf1_user (username,salt,password) VALUES ('%s', '%s', SHA1(CONCAT('%s', SHA1(CONCAT('%s', '" .. sha1( password ) .. "')))))", username, salt, salt, salt ) then triggerClientEvent( source, getResourceName( resource ) .. ":registrationResult", source, 0 ) -- will automatically login when this is sent else triggerClientEvent( source, getResourceName( resource ) .. ":registrationResult", source, 4 ) end else triggerClientEvent( source, getResourceName( resource ) .. ":registrationResult", source, 3 ) end else -- shouldn't happen triggerClientEvent( source, getResourceName( resource ) .. ":registrationResult", source, 1 ) end else -- can't do much without a username and password triggerClientEvent( source, getResourceName( resource ) .. ":registrationResult", source, 1 ) end else triggerClientEvent( source, getResourceName( resource ) .. ":registrationResult", source, 2, registrationErrorMessage ) end end end ) Here's the line in settings.xml: It's tagged, no worries. -- MySQL Configuration --> "@sql.username" value="xxxx" /> "@sql.password" value="xxxx" /> "@sql.database" value="xxxx" /> "@sql.hostname" value="xxxx" /> "@sql.port" value="3306" /> "@sql.socket" value="/var/run/mysql/mysql.sock" /> -- Registration --> "@players.allow_registration" value="1" /> -- Change to 0 to disable registration and show an error message --> "@players.registration_error_message" value="Edit this to show the user a message when registration is disabled" /> EDIT: I don't know if it's important or not regarding this, but it's a problem, I manually created an account in the internal.db, when I started the server, it deleted the account, I either missed out on something or am stupid, anyways. I need urgent help, PM me for skype if you can't find the words for it here. 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