private void HandleEventLeave(int actorID, EventData evLeave)
{
if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
Debug.Log("HandleEventLeave for player ID: " + actorID);
// actorNr is fetched out of event above
if (actorID < 0 || !this.mActors.ContainsKey(actorID))
{
Debug.LogError(String.Format("Received event Leave for unknown player ID: {0}", actorID));
return;
}
PhotonPlayer player = this.GetPlayerWithId(actorID);
if (player == null)
{
Debug.LogError("HandleEventLeave for player ID: " + actorID + " has no PhotonPlayer!");
}
// having a new master before calling destroy for the leaving player is important!
// so we elect a new masterclient and ignore the leaving player (who is still in playerlists).
// note: there is/was a server-side-error which sent 0 as new master instead of skipping the key/value. below is a check for 0 due to that
if (evLeave.Parameters.ContainsKey(ParameterCode.MasterClientId))
{
int newMaster = (int) evLeave[ParameterCode.MasterClientId];
if (newMaster != 0)
{
this.mMasterClientId = (int)evLeave[ParameterCode.MasterClientId];
this.UpdateMasterClient();
}
}
else if (!this.CurrentGame.serverSideMasterClient)
{
this.CheckMasterClient(actorID);
}
// destroy objects & buffered messages
if (this.CurrentGame != null && this.CurrentGame.autoCleanUp)
{
this.DestroyPlayerObjects(actorID, true);
}
RemovePlayer(actorID, player);
// finally, send notification (the playerList and masterclient are now updated)
SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerDisconnected, player);
}