Restricting joining room with non-matching game version
The whole answer can be found below.
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).
Restricting joining room with non-matching game version
jarileon
2019-01-24 12:45:03
I have a simple online game created with Unity. Now, I wanted to test joining the same game room from a build from totally different Unity project (but the Photon app ID is the same in both projects) - and to my surprise, it worked - even though I have PhotonNetwork.GameVersion set to different values in each project.
The docs for PUN2 says: "In the Photon Cloud, the GameVersion string is used as simple way to isolate builds (and players) from one another, without changing the AppId. Change the GameVersion when when making breaking changes to the network logic to keep players of different versions apart."
What am I missing? I would have supposed that it is not possible to join if the GameVersion does not match.
I set the GameVersion just before I call ConnectUsingSettings(). I am using pre-named non-visible room which I join with PhotonNetwork.JoinRoom("SecretRoom");
Comments
Hi @jarileon,
Log the PhotonNetwork.NetworkingClient.AppVersion
inside OnConnectedToMaster
from both clients.
@JohnTube I did that. Both clients print "0_2.5" So they match, which explains why joining the room is possible. But it seems the version appended to the AppVersion (0) is the PUN version (2.5) and not whatever I have set to the GameVersion (which is "v1" for the other one and "v2" for the other). Is this a bug in PUN2 or am I missing something?
Hi @jarileon,
Find all references to PhotonNetwork.GameVersion
to see when this value is changed.
I did a quick test:
using Photon.Pun;
using UnityEngine;
public class testAppVersion : MonoBehaviourPunCallbacks
{
// Use this for initialization
private void Start ()
{
PhotonNetwork.PhotonServerSettings.AppSettings.AppVersion = "editor";
PhotonNetwork.GameVersion = "before";
PhotonNetwork.ConnectUsingSettings();
PhotonNetwork.GameVersion = "after";
}
public override void OnConnectedToMaster()
{
Debug.LogFormat("Connected AppVersion={0}", PhotonNetwork.AppVersion);
}
}
- set AppVersion from the Unity Editor, in the PhotonServerSettings ScriptableObject. That will be used as
PhotonNetwork.GameVersion
insidePhotonNetwork.ConnectUsingSettings()
- set
PhotonNetwork.GameVersion
after callingPhotonNetwork.ConnectUsingSettings()
We will address this in PUN2 either in docs or in a future update.
@JohnTube ok I did some more testing. Like you said, it seems that GameVersion only matters (= allows joining a room only if they match) only if you set it AFTER calling ConnectUsingSettings(). I would say this is somewhat weird and unexpected behavior, as usually you set values before you call a function that does something with those values. Also having both AppVersion and GameVersion is somewhat confusing, maybe there is room for simplification in this.
Just ran into the same issue.
The sample code provided by photon is then incorrect :
LogFeedback("Connecting...");
// #Critical, we must first and foremost connect to Photon Online Server.
PhotonNetwork.GameVersion = this.gameVersion;
PhotonNetwork.ConnectUsingSettings();
Please fix the product that some of us pay for
Hi
I'm experiencing the same issue, different game versions can join. I tried many things, like define game version in the PhotonServerSettings ScriptableObject, set it before and after calling PhotonNetwork.ConnecUsingSettings(). I debug client version and it is different but they can join the same room. I am not using Photon Cloud for hosting but a personnal server.
Someone found any solution ?
I am with Unity 2020.2 and Photon 2.30
Hi @Jerem,
Thank you for choosing Photon!
This is not available in self-hosted Photon Server. Only on Photon Cloud.
You can check the full differences here.
You could try to add this yourself in server code.
strangegames
2021-05-14 14:28:23
@JohnTube I found this while looking up when to set PhotonNetwork.GameVersion. Your comment about this being fixed in Pun2 which I'm now using makes me wonder if we still should set it after calling connect.
As someone else mentioned, this seems wrong to set an important parameter after calling connect() so I wanted to make sure this is still how we're supposed to do this.
Thanks
Hi @strangegames,
The correct proper expected way is to set it before connection call in ServerSettings either via Unity Editor in compile time by changing the respective field in PhotonServerSettings ScriptableObject inspector or via code PhotonNetwork.PhotonServerSettings.AppSettings.AppVersion.
strangegames
2021-05-14 15:35:02
Hi @JohnTube
Thanks for the quick reply. We have multiple Unity projects (one for each build platforms) so setting it via code is better since version control populates it correctly across all platforms. This was our old way.
PhotonNetwork.ConnectUsingSettings();
PhotonNetwork.GameVersion = sgs_MP.GAME_VERSION;
According to what you're saying, we should actually be doing this then?
PhotonNetwork.PhotonServerSettings.AppSettings.AppVersion = sgs_MP.GAME_VERSION;
PhotonNetwork.ConnectUsingSettings();
Hi @strangegames,
According to what you're saying, we should actually be doing this then?
Yes exactly!
Back to top