Restricting joining room with non-matching game version

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

  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @jarileon,

    Log the PhotonNetwork.NetworkingClient.AppVersion inside OnConnectedToMaster from both clients.
  • jarileon
    jarileon
    edited January 2019
    @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?
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited January 2019
    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);
        }
    }
    So you can either:

    1. set AppVersion from the Unity Editor, in the PhotonServerSettings ScriptableObject. That will be used as PhotonNetwork.GameVersion inside PhotonNetwork.ConnectUsingSettings()
    2. set PhotonNetwork.GameVersion after calling PhotonNetwork.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
  • JohnTube
    JohnTube ✭✭✭✭✭
    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.
  • @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
  • JohnTube
    JohnTube ✭✭✭✭✭
    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.
  • 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();
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @strangegames,
    According to what you're saying, we should actually be doing this then?
    Yes exactly!