public override void RemoveInactiveActor(Actor actor) { RequestHandler handler = () => { try { return this.ProcessRemoveInactiveActor(actor); } catch (Exception e) { Log.ErrorFormat("Exception: {0}", e); throw; } }; var info = new LeaveGameCallInfo(this.PendingPluginContinue, this.callEnv) { ActorNr = actor.ActorNr, UserId = actor.UserId, Nickname = actor.Nickname, IsInactive = false, Reason = LeaveReason.PlayerTtlTimedOut, Request = null, Handler = handler, Peer = null, SendParams = new SendParameters(), }; try { this.Plugin.OnLeave(info); } catch (Exception e) { this.Plugin.ReportError(Photon.Hive.Plugin.ErrorCodes.UnhandledException, e); } }
protected override void HandleRemovePeerMessage(HivePeer peer, int reason, string details) { if ((reason == LeaveReason.PlayerTtlTimedOut) || (reason == LeaveReason.LeaveRequest)) { throw new ArgumentException("PlayerTtlTimeout and LeaveRequests are handled in their own routines."); } var actor = this.ActorsManager.ActorsGetActorByPeer(peer); var actorNr = actor != null ? actor.ActorNr : -1; var isInactive = reason != LeaveReason.PluginRequest && peer.JoinStage == HivePeer.JoinStages.Complete && this.PlayerTTL != 0; var mockRequest = new OperationRequest((byte)OperationCode.Leave) { Parameters = new Dictionary<byte, object> { {(byte) ParameterKey.ActorNr, actorNr}, {(byte) ParameterKey.IsInactive, isInactive} } }; var leaveRequest = new LeaveRequest(peer.Protocol, mockRequest); RequestHandler handler = () => { try { return this.ProcessHandleRemovePeerMessage(peer, isInactive); } catch (Exception e) { Log.ErrorFormat("Exception: {0}", e); throw; } }; var info = new LeaveGameCallInfo(this.PendingPluginContinue, this.callEnv) { ActorNr = actorNr, UserId = peer.UserId, Nickname = actor != null ? actor.Nickname : string.Empty, IsInactive = isInactive, Reason = reason, Details = details, Handler = handler, Peer = peer, OperationRequest = leaveRequest, SendParams = new SendParameters() }; try { this.Plugin.OnLeave(info); } catch (Exception e) { this.Plugin.ReportError(Photon.Hive.Plugin.ErrorCodes.UnhandledException, e); } }
private void CallPluginOnLeaveIfJoinFailed(byte reason, HivePeer peer, JoinGameRequest request) { if (peer.JoinStage == HivePeer.JoinStages.Connected || peer.JoinStage == Hive.HivePeer.JoinStages.CreatingOrLoadingGame) { if (Log.IsDebugEnabled) { Log.DebugFormat("Peer join stage is {0}. CallPluginOnLeaveIfJoinFailed will be skiped. p:{1}", peer.JoinStage, peer); } return; } if (Log.IsDebugEnabled) { Log.DebugFormat("Peer join stage is {0}. reason:{1}. CallPluginOnLeaveIfJoinFailed is called. p:{2}", peer.JoinStage, reason, peer); } var actor = this.GetActorByPeer(peer); RequestHandler handler = () => { try { this.RemovePeerFromGame(peer, false); } catch (Exception e) { Log.ErrorFormat("Exception: {0}", e); throw; } return true; }; var info = new LeaveGameCallInfo(this.PendingPluginContinue, this.callEnv) { ActorNr = actor != null ? actor.ActorNr : -1, UserId = actor != null ? actor.UserId : peer.UserId, Nickname = actor != null ? actor.Nickname : request.GetNickname(), IsInactive = false, Reason = reason, Request = null, Handler = handler, Peer = null, SendParams = new SendParameters(), }; try { this.Plugin.OnLeave(info); } catch (Exception e) { this.Plugin.ReportError(Photon.Hive.Plugin.ErrorCodes.UnhandledException, e); } }
/// <summary> /// Handles the <see cref="LeaveRequest"/> and calls <see cref="HiveGame.RemovePeerFromGame"/>. /// </summary> /// <param name="peer"> /// The peer. /// </param> /// <param name="sendParameters"> /// The send Parameters. /// </param> /// <param name="leaveOperation"> /// The leave Operation. /// </param> protected override void HandleLeaveOperation(HivePeer peer, SendParameters sendParameters, LeaveRequest leaveOperation) { var actor = this.GetActorByPeer(peer); if (actor != null) { RequestHandler handler = () => { try { return this.ProcessLeaveGame(actor.ActorNr, leaveOperation, sendParameters, peer); } catch (Exception e) { Log.ErrorFormat("Exception: {0}", e); throw; } }; var info = new LeaveGameCallInfo(this.PendingPluginContinue, this.callEnv) { ActorNr = actor.ActorNr, UserId = peer.UserId, Nickname = actor.Nickname, IsInactive = leaveOperation != null && leaveOperation.IsCommingBack, Reason = LeaveReason.LeaveRequest, Request = leaveOperation, Handler = handler, Peer = peer, SendParams = sendParameters, }; try { this.Plugin.OnLeave(info); } catch (Exception e) { this.Plugin.ReportError(Photon.Hive.Plugin.ErrorCodes.UnhandledException, e); } } else { this.LogQueue.Add(new LogEntry("HandleLeaveOperation", string.Format("Failed to find Actor for peer {0}", peer.ConnectionId))); } }