Rejoin in photon network?
Hi all, Am doing a multiplayer game. If one player is disconnected other can continue like clashroyale. If the disconnected person came with in the session I have to make him rejoin into that room .
I don't know how to do rejoin. Can anyone help me with explain it. Just idea is enough.
Thank you
Answer by ChristianSimon · Jun 15, 2017 at 08:33 AM
Hi,
when the client is completely disconnected from Photon you can use PhotonNetwork.ReconnectAndRejoin();
to firstly reconnect to Photon and to rejoin the room afterwards. PhotonNetwork.ReJoinRoom("RoomName");
does the same but you have to reconnect to Photon before manually.
Both options requires you to set up the room correctly by using the RoomOptions. Using this options you can set PlayerTtl and EmptyRoomTtl to something else than 0. PlayerTtl describes how long the client's data will remain in the server's memory. EmptyRoomTtl does the same for the (empty) room itself.
RoomOptions options = new RoomOptions();
options.PlayerTtl = 60000; // 60 sec
options.EmptyRoomTtl = 60000; // 60 sec
PhotonNetwork.JoinOrCreateRoom("RoomName", options, null);
Thanks for your replay. i tried but i faced an error while rejoin
like..
error
Operation failed: OperationResponse 226: ReturnCode: 32748 (Actor with number 0 not found.). Parameters: {} Server: GameServer $$anonymous$$y flow is like.
in my scenario first player connects to the lobby. So i kept room options in The method Public static bool JoinOrCreateRoom().(which in photonnetwork class)
after the player disconnected from internet is anything i have to do?
If the client completely disconnects from the internet you have to reconnect to Photon first. Using PhotonNetwork.ReconnectAndRejoin();
is the easy way in this case. $$anonymous$$ake sure to set PlayerTtl and EmptyRoomTtl to values which you don't exceed before you start the rejoin process.
If you still have problems please provide some code snippets. This makes solving the problem easier in my opinion.
How do I know that the player who reconnects belongs to this room though?
Say, if a player with photonid 2 disconnects, and reconnects with photonid 4 because other players connected before he could reconnect, how do I know this player belongs to this room?
OR, does photon network maintain the player's ID for the amount of time specified by options.PlayerTtl ?
Answer by goutham12 · Jun 15, 2017 at 10:04 AM
// find match
OnBattle() {
TypedLobby loby = new TypedLobby();
loby.Name = LobbyName;
PhotonNetwork.JoinLobby(loby );
}
the above method automatically call joinorcreateroom(). in the method joinorcreate()(which is in photon networkclass) i kept room options what you gave.
// here is the code.
public static bool JoinOrCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby typedLobby, string[] expectedUsers) {
roomOptions = new RoomOptions();
roomOptions.PlayerTtl = 60000; // 60 sec
roomOptions.EmptyRoomTtl = 60000; // 60 sec
if (offlineMode)
{
//when player connectd
public void OnPhotonPlayerConnected(PhotonPlayer player) { InitAndAddOwnPlayer(); }
// in this method am getting the error public void InitAndAddOwnPlayer() { PlayerOL = new PlayersOnline[PhotonNetwork.room.maxPlayers];
PhotonPlayer[] PlayersInfoLst = PhotonNetwork.playerList;
print("PlayerInfoList.."+PhotonNetwork.playerList);
for(int i=0;i<PlayersInfoLst.Length;i++)
{
print("PlayerInfo______"+PlayersInfoLst[i]);
PlayerOL[i] = new PlayersOnline(PlayersInfoLst[i].name,"0","0");
}
CloseRoomBasedOnPlayers();
}
after that am making room.visible = false; and am starting the game for both players.
now if one was disconnected am doing..
if (LevelManager.THIS.isInternetAvailable == false && onetimecall) {
if (LevelManager.THIS.gameStatus == GameState.Playing) {
PhotonNetwork.LeaveRoom ();
PhotonNetwork.LeaveLobby ();
}
}
// rejoin
now he connects again
if(LevelManager.THIS.isInternetAvailable && onetimecall) {
if (LevelManager.THIS.gameStatus == GameState.Playing) {
PhotonNetwork.ReconnectAndRejoin();
}
}
When you call PhotonNetwork.LeaveRoom();
the client will be removed from the room as well as from the server's memory. Rejoining after calling LeaveRoom() is not possible. You can only reconnect and rejoin after you have lost and restored internet connection.