I developed a game like 8 ball pool. I am using photon network for multiplayer feature. The game works fine except in some conditions:
- Photon network disconnects suddenly.
- If a user try to switch network for example WiFi to mobile data then Photon network could no longer be connected (due to IP address changed).
To solve this I tried this:
public override void OnDisconnectedFromPhoton() {
Debug.Log("Disconnected from photon");
PhotonNetwork.ReconnectAndRejoin();
}
But it's not working properly.
For matchmaking I wrote like this:
public void JoinRoomAndStartGame()
{
ExitGames.Client.Photon.Hashtable expectedCustomRoomProperties = new ExitGames.Client.Photon.Hashtable() { { "tbl", GameManager.Instance.tableNumber }, { "isAvailable", true} };
PhotonNetwork.JoinRandomRoom(expectedCustomRoomProperties, 0);
}
public void OnPhotonRandomJoinFailed()
{
RoomOptions roomOptions = new RoomOptions();
roomOptions.PlayerTtl = 15000;
roomOptions.CustomRoomPropertiesForLobby = new String[] { "tbl", "isAvailable" };
roomOptions.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable() { { "tbl", GameManager.Instance.tableNumber }, { "isAvailable", true} };
roomOptions.MaxPlayers = 2;
roomOptions.IsVisible = true;
PhotonNetwork.CreateRoom(null, roomOptions, TypedLobby.Default);
}
I am new in photon. How to reconnect properly in those conditions?