OperationResponse 230: ReturnCode: 32755 (Custom authentication deserialization failed: Unexpected C

Options
I have created a simple PHP login system integrated into PUN (Custom Authentication)

Here is my code within the game:
    public class DBTest : MonoBehaviourPunCallbacks
        {
            public TMP_InputField txtUsername, txtPassword;
            public Button btnSubmit;

        [SerializeField]
        private TMP_Text lblStat;

        public string player_username;
        public string player_password;

        public void SignInButton()
        {
            player_username = txtUsername.text;
            player_password = txtPassword.text;

            PhotonNetwork.AuthValues = new AuthenticationValues();
            PhotonNetwork.AuthValues.AuthType = CustomAuthenticationType.Custom;

            //BE SURE THAT THE FIRST VAR IN THE AUTH PARAMETER IS THE SAME WITH THE VAR NAME IN THE PHP FILE!
            // e.g. "player_username"
            PhotonNetwork.AuthValues.AddAuthParameter("player_username", player_username);
            PhotonNetwork.AuthValues.AddAuthParameter("player_password", player_password);
            PhotonNetwork.ConnectUsingSettings();
        }

        public override void OnJoinedLobby()
        {
            base.OnJoinedLobby();
            Debug.Log("Success");
        }


        public override void OnCustomAuthenticationFailed(string debugMessage)
        {
            base.OnCustomAuthenticationFailed(debugMessage);
            Debug.Log(debugMessage);
        }


    } //End: Class



And for my php file:


<?php
    include("connection.php");


    //Fetch the values form Unity
    $gusername = $_GET['player_username'];
    $gpassword = $_GET['player_password'];

    $player_username = mysqli_real_escape_string($connection, htmlentities($gusername));
    $player_password = mysqli_real_escape_string($connection, htmlentities($gpassword));


    $sql = "SELECT * FROM users WHERE username = '$player_username' AND password = '$player_password' ";
    $result = mysqli_query($connection, $sql);
    $count = mysqli_num_rows($result);

    if($count == 1)
    {
        /*
        // User matched
        //Create Array result
        $login_success = array (
        "ResultCode" => 1,
        "Message" => "Success",
        );

        //Pass json
        $json_success = json_encode($login_success);
        echo $json_success;
        */
        
        $loginresult = new stdClass();
        $loginresult->ResultCode = 1;
        $loginresult->UserId = $player_username;
        
        $jsonresult = json_encode($loginresult);
        echo $jsonresult;
    }
    else
    {
        /*
        //User doesnt match
        //Create array result
        $login_fail = array (
        "ResultCode" => 2,
        "Message" => "Failed",
        );

        //Pass json
        $json_fail = json_encode($login_fail);
        echo $json_fail;
        */
        
        $loginresult = new stdClass();
        $loginresult->ResultCode = 2;
        //$loginresult->message = "failed";
        
        $jsonresult = json_encode($loginresult);
        echo $jsonresult;
    }
    
    /*
    echo "<br/><br/>";
    echo $player_username;
    echo "<br/>";
    echo $player_password;
    echo "<br/>";
    echo $count;
    */

?>



I have already placed the custom url path on my app's dashboard
'https://mysite.com/authenticate.php'


Yet I keep getting this error:

OperationResponse 230: ReturnCode: 32755 (Custom authentication deserialization failed: Unexpected character encountered while parsing value: C. Path '', line 0, position 0.). Parameters: {} Server: NameServer Address: ns.exitgames.com:5058
UnityEngine.Debug:LogError(Object)
Photon.Realtime.LoadBalancingClient:DebugReturn(DebugLevel, String) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2008)
Photon.Realtime.LoadBalancingClient:OnOperationResponse(OperationResponse) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2082)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(StreamBuffer) (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PeerBase.cs:619)
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands() (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/EnetPeer.cs:550)
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands() (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PhotonPeer.cs:1504)
Photon.Pun.PhotonHandler:FixedUpdate() (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:116)


I also tried creating a separate php file to test if my initial php connector works, and it did. Here is the dummy php file:


<code class="CodeInline"> <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>Test Username</title> </head> <body> <form action = "mariadbtest.php" method = "get" id = "test_signup"> <input type = "text" name = "player_username" placeholder = "Username" autocomplete = "off" required/><br/> <input type = "password" name = "player_password" placeholder="Password" required /><br/> <input type = "submit" id = "btn_submit" name = "btn_submit" value = "Submit"><br/> </form> </body> </html>
How can I solve this? I'm really stuck at this point. I tried googling but got no decent answer (rarely does a custom authentication tutorial for pun exists) so I really got nothing.

Anything that might help me solve this is much appreciated.

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @DKReigns,

    Make sure the returned response from the server is a valid JSON string.
  • DKReigns
    Options
    JohnTube said:

    Hi @DKReigns,

    Make sure the returned response from the server is a valid JSON string.

    Forgive me for being naive, but how can I achieve something like that?
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited May 2019
    Options
    My PHP knowledge is very basic.

    Maybe the PHP script is returning something before this line
        if($count == 1)
    
    Check if you have other echo calls somewhere.
    Probably something that starts with "C" (hint in the error message) maybe "Connection"?
    Check "connection.php" or maybe an error/exception is thrown in
        $result = mysqli_query($connection, $sql);
    
    or
        $count = mysqli_num_rows($result);
  • DKReigns
    Options
    JohnTube said:

    My PHP knowledge is very basic.

    Maybe the PHP script is returning something before this line

        if($count == 1)
    
    Check if you have other echo calls somewhere.
    Probably something that starts with "C" (hint in the error message) maybe "Connection"?
    Check "connection.php" or maybe an error/exception is thrown in
        $result = mysqli_query($connection, $sql);
    
    or
        $count = mysqli_num_rows($result);
    Thanks! It was on my connection.php where I placed a debug message that says 'echo "Connection Successful!"

    I managed to get it working now.

    One more question though, how can I get the returned parameters from the server?
    As of the moment, I only use Debug.log to display a "successful" message once I got connected to the server. I want to get the returned value from the server, namely the 'UserId'

    I have:

    $loginresult = new stdClass(); $loginresult->ResultCode = 1; $loginresult->UserId = $player_username; $loginresult->message = "Login Successful!"; $jsonresult = json_encode($loginresult); echo $jsonresult;

    on my php.

    I tried:

    public override void OnCustomAuthenticationResponse(Dictionary<string, object> data) { base.OnCustomAuthenticationResponse(data); Debug.Log(data); }


    But it doesn't display anything.
  • DKReigns
    Options
    I also tried putting a debug message on the OnCustomAuthenticationResponse but it did not display the message once I got connected to the server. Does this mean the server is not returning anything?
  • DKReigns
    Options
    Nevermind, I managed to solve it.

    In your php code:

    $loginresult = new stdClass(); $loginresult->ResultCode = 1; $loginresult->Data = ["name"=>"name here","some data"=>"data content"]; $jsonresult = json_encode($loginresult); echo $jsonresult;

    And in accessing in unity:

    public override void OnCustomAuthenticationResponse(Dictionary<string, object> data) { base.OnCustomAuthenticationResponse(data); Debug.Log(data["name"]); }

    You should really add more examples in the Documentation. It's like out of 100% information, only 40% were explained in the Documentation page - that is very frustrating to other developers who are just starting with Photon. The examples provided in the page are sometimes too complex for starters to understand. The sending of Data from the web server to the client was only mentioned rarely (also as an "optional"), it wasn't elaborated or have an example snippit. I had to research, did a lot of trial and error, tested it on another web page, before passing it to Unity.

    At least I learned a lot from that, but you should really revise your Documentation page to be honest. Make it a bit more user-friendly and provide a lot of examples - W3schools is a great example.

    Thanks for the help.
    Still even though, I am enjoying Photon and am looking forward to using it more.
    You really just have to revise the documentation page.