Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party Photon nicknames and chat

Discussion in 'Multiplayer' started by ArrSoft, Apr 14, 2014.

  1. ArrSoft

    ArrSoft

    Joined:
    Apr 14, 2014
    Posts:
    10
    Hello!
    I use PUN and DB in my game.
    I parse nicknames from DB via PHP, and write values in variable "namechar".
    After I replaced value "PhotonNetwork.playerName".
    Code (csharp):
    1.  
    2. PhotonNetwork.playerName = namechar;
    3.  
    Then I write this in my chat script.
    Code (csharp):
    1.  
    2. AddMessage(PhotonNetwork.playerName + ": " + text);
    3.  
    In this line somehow playerName == ""
    And I use variable from menu script:
    Code (csharp):
    1.  
    2. AddMessage(MainMenu.namechar + ": " + text);
    3.  
    If I use this that different players have one nickname.

    Please help me decide this problem.
    P.S. Sorry me for my bad english
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    I am not aware of a bug that will reset the playerName to "". It might be in your code or something I didn't notice yet.
    You should check all usages of PhotonNetwork.playerName and see if you set it in some code that might run more than once (Start(), Awake() or similar).

    Are you using the latest PUN version 1.25?
     
  3. ArrSoft

    ArrSoft

    Joined:
    Apr 14, 2014
    Posts:
    10
    I already check all use of PhotonNetwork.playerName and nothing found.
    I use 1.0.
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    Please refer to PhotonNetwork.versionPUN for your current PUN version. v1.0 would be really old.
     
  5. ArrSoft

    ArrSoft

    Joined:
    Apr 14, 2014
    Posts:
    10
    Ok.
    I fully tested to get the values ​​of PHP, it turned out that the values ​​are not empty only within IEnumerator. Here's the code IEnumerator and variables.
    Code (csharp):
    1.  
    2.     public static string namechar;
    3.     public static string goldchar;
    4.     public static string hpchar;
    5.     public static string mpchar;
    6.     public static float xpos;
    7.     public static float ypos;
    8.     public static float zpos;
    9.     public static string acc_id;
    10.     public static string char_id;
    11.  
    12.         IEnumerator HandleLogin(string login, string password) {
    13.  
    14.         WWWForm form = new WWWForm();
    15.         form.AddField("mylogin", login);
    16.         form.AddField("mypassword", password);
    17.         WWW Login = new WWW(url, form);
    18.         yield return Login;
    19.        
    20.         string a = Login.text;       //get echo from php
    21.     string[] all = a.Split('|');
    22.     namechar = all[1];
    23.     goldchar = all[2];
    24.     hpchar = all[3];
    25.     mpchar = all[4];
    26.     xpos = float.Parse(all[5]);
    27.     ypos = float.Parse(all[6]);
    28.     zpos = float.Parse(all[7]);
    29.     acc_id = all[8];
    30.     char_id = all[9];
    31.     print(a);
    32.  
    33.     if (all[0] == "Ok") {
    34.         LogIn = false;
    35.         chooseChar = true;
    36.         }
    37.     }
    38.  
     
  6. ArrSoft

    ArrSoft

    Joined:
    Apr 14, 2014
    Posts:
    10
    I think I understood why PhotonNetwork.playerName variable to the empty string. The fact that the variable PhotonNetwork.playerName created before the database will record data in a variable after entering the username and password. It remains to understand how to fix it.
     
  7. ArrSoft

    ArrSoft

    Joined:
    Apr 14, 2014
    Posts:
    10
    I fixed it by moving "PhotonNetwork.playerName = namechar;" in Update.
    Now displayed nickname someone who stands in the first table in the DB.
     
  8. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    This sounds like you found a solution. Very good.

    You might want to take a look at Photon's "Custom Authentication" feature. It allows you to use Photon API to authenticate a user and will encrypt username and password from client to server.
    More about that:
    http://doc.exitgames.com/en/realtime/current/reference/custom-authentication

    On the other hand: As this is working for you now, there is no need to change a running system :)