Jump to content

MTA Paradise Registration Problem


cameron354

Recommended Posts

Hi, I'm using Mabako's MTA Paradise to experiment with scripting. The problem is though is that although register is enabled in settings.xml, there still is no register button. Before posting this I used the search button and most of the topics didn't have a proper solution.

Here is my settings.xml file which has registration set to 1:

<settings></settings> 
  
    <settings> 
        <!-- MySQL Configuration --> 
        <setting name="@sql.user" value="username"/> 
        <setting name="@sql.password" value="password"/> 
        <setting name="@sql.database" value="database"/> 
        <setting name="@sql.hostname" value="localhost"/> 
        <setting name="@sql.port" value="3306"/> 
        <!-- Only use this on Linux if the normal connection does fail even though using the correct username & password. --> 
        <setting name="@sql.socket" value="/var/run/mysqld/mysqld.sock"/> 
         
        <!-- Registration --> 
        <setting name="@players.allow_registration" value="1"/><!-- Change to 0 to disable registration and show an error message --> 
        <setting name="@players.registration_error_message" value="Edit this to show the user a message when registration is disabled"/> 
    </settings> 

Also here is the registration.lua:

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 
) 

Link to comment
  • 2 weeks later...

EDIT:

Hey, you have two setting tags there, try this first.

<settings> 
        <!-- MySQL Configuration --> 
        <setting name="@sql.user" value="username"/> 
        <setting name="@sql.password" value="password"/> 
        <setting name="@sql.database" value="database"/> 
        <setting name="@sql.hostname" value="localhost"/> 
        <setting name="@sql.port" value="3306"/> 
        <!-- Only use this on Linux if the normal connection does fail even though using the correct username & password. --> 
        <setting name="@sql.socket" value="/var/run/mysqld/mysqld.sock"/> 
        
        <!-- Registration --> 
        <setting name="@players.allow_registration" value="1"/><!-- Change to 0 to disable registration and show an error message --> 
        <setting name="@players.registration_error_message" value="Edit this to show the user a message when registration is disabled"/> 
    </settings> 

OLD:

There might be a slight problem with the MySQL, but what I prefer the most if to get the latest copy from the GitHub page.

However, here should be the working one.

local allowRegistration = tonumber( get( 'allow_registration' ) ) == 1 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 
) 

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