Jump to content

[HELP] callRemote / account problem!


Ruzy

Recommended Posts

Hello,

I am currently working on my login script but i am getting stuck at a error that the account is false.

Debug:

WARNING: login_s.lua:15: Bad argument @ 'setAccountPassword' [Expected account at argument 1, got boolean] 
WARNING: login_s.lua:17: Bad argument @ 'isGuestAccount' [Expected account at argument 1, got boolean] 
WARNING: login_s.lua:20: Bad argument @ 'logIn' [Expected account at argument 2, got boolean] 
ERROR: login_s.lua:29: attempt to index global 'userIDs' (a nil value) 

Code:

local userIDs = {}; 
  
function PlayerLogin(userName,Password,checksave) 
    if not (userName == "") then 
    userName = string.lower(userName) 
        if not (password == "") then 
            callRemote("http://*****/login.php", function(response,extra,data,player,userName,Password) 
                triggerClientEvent(player,"showNotification",player, "Connecting..", "information") 
                if response == true then 
                    local acc = getAccount(userName) 
                    if not acc then 
                        acc = addAccount(tostring(userName),tostring(Password)) 
                    end 
                    if not getAccount(userName,Password) then 
                        setAccountPassword(acc,Password) 
                    end 
                    if (not isGuestAccount(acc)) then 
                        logOut(player) 
                    end 
                    logIn (player, acc, Password) 
                        if checksave == true then 
                            triggerClientEvent(player,"saveLoginToXML",getRootElement(),userName,Password) 
                        else 
                            triggerClientEvent(player,"resetSaveXML",getRootElement(),userName,Password) 
                        end 
                    setElementData(player,"getForumID",data["member_id"]) 
                    setElementData(player,"getForumName",userName) 
         
                    userIDs[player] = data["member_id"]; 
                    triggerClientEvent(player,"loginHide",player) 
                    triggerClientEvent(player,"showNotification",player, "Successfully logged in!", "success") 
                 
                elseif extra == 1 then 
                    triggerClientEvent(player,"showNotification",player, "Wrong username!", "error") 
             
                elseif extra == 2 then 
                    triggerClientEvent(player,"showNotification",player, "Wrong password!", "error") 
                end  
            end ,"verifyPasswords", userName, Password, source) 
        else 
        triggerClientEvent(source,"showNotification",source, "Please enter your password!", "error") 
        end 
    else 
    triggerClientEvent(source,"showNotification",source, "Please enter your username!", "error") 
    end 
end 
addEvent("playerWantToLogin",true) 
addEventHandler("playerWantToLogin",getRootElement(),PlayerLogin) 

Can someone help me with this?

Regards,

Ruzy

Edited by Guest
Link to comment
callRemote("http://*****/login.php",  
  function (...) 
    outputDebugString( toJSON({...}) ) 
  end 
) 

What does the PHP return to the debugstring, in JSON? (use the code above temporarily)

Already checked that, it returns nothing.

Link to comment

php code:

<?php 
// PHP 
  
include 'mta_sdk.php';  // Correct path if you use a different one 
$servername = "localhost";  // Change these details 
$username = "forum";  // Change these details 
$password = "*****";  // Change these details 
$dbname = "forum";  // Change these details 
$table = "mvp_core_members"; 
$accountColumn = "name";  // change to "email" if you prefer logging in through email 
$conn = mysqli_connect($servername, $username, $password, $dbname); 
if (!$conn) { 
    mta::doReturn(false, "Connection failed: " . mysqli_connect_error()); // Account not found 
    #die("Connection failed: " . mysqli_connect_error()); 
} 
$input = mta::getInput(); 
if (isset($input[0]) && isset($input[1]) && isset($input[2]) && $input[0] == "verifyPasswords" ) { 
    $sql = "SELECT `member_id`, `member_group_id`, `members_pass_salt`, `members_pass_hash` FROM `".$table."` WHERE `".$accountColumn."`='".strtolower($input[1])."' LIMIT 1"; 
    $result = mysqli_query($conn, $sql); 
    if (mysqli_num_rows($result) > 0) { 
        $row = mysqli_fetch_assoc($result); 
        if (crypt($input[2], '$2a$13$' . $row['members_pass_salt']) == $row['members_pass_hash']) { 
            mta::doReturn(true, 0, $row, $input[3], $input[1], $input[2]);  // Password correct 
        } else { 
            mta::doReturn(false, 1, $row, $input[3]);  // Passwords don't match 
        } 
    } else { 
        mta::doReturn(false, 2, $row, $input[3]);  // Account not found 
    } 
} 
// Author: MrTasty 
?> 

Link to comment

Use fetchRemote instead? I don't use callremote so I don't know about your problem

but fetchRemote works fine the whole time for me (I mean you'll be able to pass the player element and the other things)

And use echo "false"; and echo "true"; instead of mta::doReturn

Link to comment
  • 2 weeks later...

I tried using fetchRemote , but now getting a error that the username or password are invalid.

Code:

<?php 
    $dbHost = "***"; 
    $dbUser = "forum"; 
    $dbPass = "***"; 
    $dbDB = "forum"; 
    $dbTable = "core_members"; 
    $dbAccount = "name"; 
     
    $input = json_decode(file_get_contents("php://input"), true); 
     
    if(is_array($input)): 
        $dbCon = new PDO(sprintf("mysql:dbname=%s;host=%s;cahrset=utf8", $dbDB, $dbHost), $dbUser, $dbPass); 
         
        if($dbCon): 
            try 
            { 
                $sql= "SELECT `member_id`, `member_group_id`, `members_pass_hash`, `members_pass_salt` FROM `".$dbTable."` WHERE `".$dbAccount."`= '?' LIMIT 1"; 
                $stmt = $dbCon->prepare($sql); 
                $stmt->execute(array($input[0])); 
                 
                $result = $stmt->fetch(PDO::FETCH_ASSOC); 
                 
                if (crypt($input[1], '$2a$13$' . $result["members_pass_salt"]) == $result["members_pass_hash"]): 
                    echo sprintf('[ [ "succes", %d, %d ] ]', $result["member_id"], $result["memer_group_id"]); 
                else: 
                    echo '[ [ "invalid" ] ]'; 
                endif; 
            } catch(PDOException $e) { } 
        endif; 
         
        $dbCon = NULL; 
    endif; 
?> 

function PlayerLogin(strUsername, strPassword, checksave) 
    if not (strUsername == "") then 
        if not (Password == "") then 
            triggerClientEvent(source,"showNotification",getRootElement(), "Loging In...", "information") 
            fetchRemote("[link]", 10, CheckLoginCallback, ('["%s","%s"]'):format(strUsername, strPassword), false, source, strUsername, strPassword, checksave) 
        else 
        triggerClientEvent(source,"showNotification",getRootElement(), "Please enter your password!", "error") 
        end 
    else 
    triggerClientEvent(source,"showNotification",getRootElement(), "Please enter your username!", "error") 
    end 
end 
addEvent("playerWantToLogin",true) 
addEventHandler("playerWantToLogin",getRootElement(),PlayerLogin) 
  
  
function CheckLoginCallback(strResponseData, iError, uPlayer, strUsername, strPassword, checksave) 
    if(not isElement(uPlayer)) then return; end 
     
    if(strResponseData == "ERROR") then 
        triggerClientEvent(uPlayer,"showNotification",getRootElement(), "Unable to Log In (Failed to contact Server) (Error: " .. iError .. ")", "error") 
        return; 
    end 
  
    local tblResult = fromJSON(strResponseData); 
     
    if(tblResult[1] == "invalid" or tblResult[1] == "system") then 
        if(tblResult[1] == "invalid") then 
            triggerClientEvent(uPlayer,"showNotification",getRootElement(), "Invalid username or password specified!", "error") 
        else 
            triggerClientEvent(uPlayer,"showNotification",getRootElement(), "Unable to Log In! (System " ..tblResult[2] .. ")", "error") 
        end 
         
    elseif(tblResult[1] == "succes") then 
        if checksave == true then 
            triggerClientEvent(uPlayer,"saveLoginToXML",getRootElement(),strUsername,strPassword) 
        else 
            triggerClientEvent(uPlayer,"resetSaveXML",getRootElement(),strUsername,strPassword) 
        end 
         
        setElementData(uPlayer,"getForumID",tblResult[2]) 
        setElementData(uPlayer,"getForumName",strUsername) 
         
        triggerClientEvent(uPlayer,"showNotification",getRootElement(), "Successfully logged in!", "success") 
        triggerClientEvent(uPlayer,"loginHide",getRootElement()) 
     
    end 
end 

Link to comment
How else should i set the source and get the userName then? i have tried many ways. because callremote is triggering another function it can't get the source, so i used callremote to return it

You could instead, send the serial of the player, and create a function to get the player element from the serial.

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