Kill room

Options
In my game, players connect to a game in a lobby-way and commit to that game (no hotjoining). If the master client disconnects, i'd like all the other players to be kicked and have the room instantly removed. In my current implementation, I get some weird behavior, where the old room is still there.

I tried this:
[code2=csharp]if(PhotonNetwork.isMasterClient)
{
foreach(PhotonPlayer pp in PhotonNetwork.otherPlayers)
{
PhotonNetwork.CloseConnection(pp);
}
}


PhotonNetwork.Disconnect();[/code2]

The other player don't get kicked, probably due some timing issue (if I comment out that last line, they do get kicked, but the masterClient is obviously still connected).

Should I make some system where the master kicks the players, waits for a callback when all is done, and then disconnect himself? It seems like I'm just missing something here.

psuedo:
if(PhotonNetwork.isMasterClient)
PhotonNetwork.KillMyRoom();

or something?

Comments

  • dreamora
    Options
    thats not gonna work.
    if the master drops he drops. He will not be able to send any further messages.

    As such you would need to add such logic on each client and check for the Master Client Changed event and if so, inform the player and disconnect
  • Bankler
    Options
    That's not a bad idea. I can probably do something like that for the case where the masterClient is lost.

    Is there any particular reason why there is no function (only available for the masterClient) to kill the room he is in? I think such a feature would make a lot of sense.
  • Bankler
    Options
    Thanks for the suggestion Dreamora. I did this, and it seems to work beautiful.

    In my "PhotonManager" class where I handle the major networking stuff.

    [code2=csharp]private PhotonPlayer roomCreator;

    public void OnJoinedRoom()
    {
    roomCreator = PhotonNetwork.masterClient;
    }

    public void Update()
    {
    if(roomCreator != null)
    {
    if(!ReferenceEquals(roomCreator, PhotonNetwork.masterClient))
    {
    roomCreator = null;
    PhotonNetwork.Disconnect();
    }
    }
    }[/code2]
  • dreamora
    Options
    Glad to hear.

    I think you could also have used master client changed function that gets called, that would remove the need to check it every frame
  • Bankler
    Options
    Is this function in the documentation? I can't find it for some reason.
  • Tobias
    Options
    If I get this right, you want everyone to leave a game when the master left?
    Implement OnMasterClientSwitched(). It will be called when the current master left and is replaced. Every client gets this event anyways.
    I assume your game "starts" at some point or by user-interaction? If so, make the master close the room, so no one can join anymore.

    Also read "Random Matchmaking" here to make sure you don't run into trouble somewhere else:
    http://doc.exitgames.com/photon-cloud/M ... references
  • Bankler
    Options
    Thanks a lot for your advice and support. It's very appreciated.

    Nice to know about the Master Client Switch function (which I suppose is what Dreamora refered to as well, but I couldn't find it anywhere). Good point about closing the room. I'll need to think that one over one more time though, since it might be nice to leave some sort of opening for spectators or something. But I think that's gonna be low priority for now so. :) Thanks again.