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.

Duplicate UserIDs

Ufando
2018-01-11 05:27:06

Hi!

So I've been working with photon for a bit over a year now and am loving it, when I first started using it I had setup so that the Photon NickName would be a person's steam name, so when they joined I'd just need to access that. In order to prevent duplicate names I hard-coded in something that checks each player in the room, and if their name was the same it'd add a "(1)" to the end of their name (then repeat for 2,3,4,5,etc.) Now it'd been a while since I had updated (didn't want to risk breaking anything) so I did that today and found out that i can no longer join rooms with a player in there who already has my name, making my workaround obsolete (since that was done after connection).

I've been digging through to see what I can do and short of re-coding any display to just show the steam name and setting the UserID to the unique steamID I can't seem to find anything else. Before I jump into recoding all of that is there any other way I can work around this?

The error I get when joining a room is this: Operation failed: OperationResponse 226: ReturnCode: 32746 (Join failed: UserId '(Omitted Username)' already joined the specified game (JoinMode=0).). Parameters: {} Server: GameServer

Thanks for any assistance!

Comments

Ufando
2018-01-12 00:50:14

UPDATE: So I did a bit more on this today and tried the following;

Added the "OnPhotonJoinRoomFailed ( object[] codeAndMsg)" function, and if the returncode was the duplicate id, it called another function in "OnConnectedToMaster" that set their name (temporarily for a workaround) to their username + "(1)" then attempted to join the room again (stored the room name locally if they received the error)

I printed out the userid and username when it begun to reconnect and it shows the updated Username(1), however the error is still thrown, showing the old username ("Username") instead of "Username(1)". Any insight/ideas to why that's happening?

JohnTube
2018-01-12 23:36:43

Hi @Ufando,

Thank you for choosing Photon!

There are differences between:

  1. UserID (or UserId, userId, userID, userid)
  • should not be null or empty.
  • should be unique inside the same room per player.
  • cannot be changed once the player is authenticated/connected.
  • if not set during authentication by the client or by third-party authentication provider (e.g. Steam), Photon server will assign a GUID.
  • used to identify the player when rejoining a room.

and

  1. Nickname (or NickName, nickName, nickname, Name, name, PlayerName, Playername, playerName, playername, UserName, Username, userName, username, etc.)
  • can be left null or empty.
  • more than one player can share the same value inside the same room.
  • can be changed at any time by the player using SetProperties operation/method(s).

So I think that you should assign Steam ID (or whatever that is called) as UserID and Steam's DisplayName (or whatever they call it if it exists) as Nickname.
Please send an email to [email protected] to request access to Steam Authentication if you need it.

Ufando
2018-01-13 00:00:46

Thanks for the reply! I can't believe how simple the fix was, I just messed up the order when trying something similar earlier. I set the PhotonNetwork.playername to the steam id, then in OnJoinedLobby changed the nickname to the steam display name and it all works! Thanks so much!

tataygames
2019-12-16 08:46:31

Is there a way to get the nickname by just using user id?

JohnTube
2019-12-16 13:19:07

Hi @tataygames,

Thank you for choosing Photon!

If you want the Nickname to match the UserId then just set the Nickname to the same value as the UserId.

tataygames
2019-12-16 23:06:30

Oh I never think of that, I can connect the name to username, then I will just use substring.

thank you very much for the idea!

JohnTube
2019-12-17 10:57:13

Hi @tataygames,

then I will just use substring

Not sure we understand each other.

I did not mean that you embed the Nickname in the UserID directly. Although that could work and you need to enable RoomOptions.PubishUserId to exchange UserIDs between actors joined to the same room.

What I meant is rather set the PhotonNetwork.LocalPlayer.Nickname = PhotonNetwork.LocalPlayer.UserId; once connected.

tataygames
2019-12-17 12:59:54

Oh okay,

So PhotonNetwork.LocalPlayer refers to me? or to the friend I want to play with?

sorry i dont understand it yet, first time in multiplayer

JohnTube
2019-12-17 13:05:42

PhotonNetwork.LocalPlayer refers to me?

"me" : local player.

Nickname is automatically synchronized inside rooms.

UserId exchange is optional.

Outside rooms, you need something other than PUN to exchange UserId/Nickname.

tataygames
2019-12-17 22:56:16

Oh okay thanks

Back to top