The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

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

DKReigns
2019-05-14 06:55:24

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:
 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 "

"; echo $player_username; echo "
"; echo $player_password; echo "
"; 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:

  
  
  
      
          
        Test Username  
      
      
        




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
2019-05-14 11:17:39

Hi @DKReigns,

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

DKReigns
2019-05-14 11:44:55

@JohnTube wrote:

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
2019-05-14 12:05:22

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
2019-05-15 04:52:05

@JohnTube wrote:

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!";

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
2019-05-15 05:00:54

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
2019-05-15 06:50:27

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"];

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.

Back to top