/// <summary> /// Kicks the actor from the world (event WorldExited is sent to the client) and then disconnects the client. /// </summary> /// <remarks> /// Called by DisconnectByOtherPeer after being enqueued to the PeerBase.RequestFiber. /// It kicks the actor from the world (event WorldExited) and then continues the original request by calling the original peer's OnOperationRequest method. /// </remarks> public void OnDisconnectByOtherPeer(PeerBase otherPeer, OperationRequest otherRequest, SendParameters sendParameters) { this.ExitWorld(); // disconnect peer after the exit world event is sent this.Peer.RequestFiber.Enqueue(() => this.Peer.RequestFiber.Enqueue(this.Peer.Disconnect)); // continue execution of other request PeerHelper.InvokeOnOperationRequest(otherPeer, otherRequest, sendParameters); }
private void OnPeerHandshaked(object sender, EventArgs e) { string clientName; string clientVersion; if (PeerHelper.TryGetPeerClientInfo(peerID, out clientName, out clientVersion)) { this.clientName = clientName; this.clientVersion = clientVersion; Log.LogInfo("[Peer][{0}] We handshaked with client: {1} (v{2})", endPoint, clientName, clientVersion); } else { Log.LogInfo("[Peer][{0}] We handshaked with an unknown client with peer ID: {1}", endPoint, peerID.ToHexString()); } Handshaked.SafeInvoke(this, e); }
/// <summary> /// Returns the text-representation of this peer ID. /// </summary> /// <returns>The peer client info with ID.</returns> public override string ToString() { if (id != null) { string idHex = HexHelper.BytesToHex(id); string clientName; string clientVersion; if (PeerHelper.TryGetPeerClientInfo(this, out clientName, out clientVersion)) { return(string.Format("[{0} (v{1}), RAW:{2}]", clientName, clientVersion, idHex)); } else { return(string.Format("[UNKNOWN, RAW:{0}]", idHex)); } } else { return("<NONE>"); } }
/// <summary> /// Called by <see cref="M:Photon.SocketServer.Rpc.Peer.DisconnectByOtherPeer(Photon.SocketServer.PeerBase,Photon.SocketServer.OperationRequest,Photon.SocketServer.SendParameters)">DisconnectByOtherPeer</see> after being enqueued to the <see cref="P:Photon.SocketServer.PeerBase.RequestFiber"/>. /// It calls <see cref="M:Photon.SocketServer.Rpc.IOperationHandler.OnDisconnectByOtherPeer(Photon.SocketServer.PeerBase)">CurrentOperationHandler.OnDisconnectByOtherPeer</see> and /// then continues the <paramref name="otherRequest">original request</paramref> by calling the <paramref name="otherPeer">original peer's</paramref> <see cref="M:Photon.SocketServer.PeerBase.OnOperationRequest(Photon.SocketServer.OperationRequest,Photon.SocketServer.SendParameters)">OnOperationRequest</see> method. /// </summary> /// <param name="otherPeer">The original peer.</param> /// <param name="otherRequest">The original request.</param> /// <param name="sendParameters">The send Parameters.</param> protected virtual void OnDisconnectByOtherPeer(PeerBase otherPeer, OperationRequest otherRequest, SendParameters sendParameters) { this.CurrentOperationHandler.OnDisconnectByOtherPeer(this); PeerHelper.InvokeOnOperationRequest(otherPeer, otherRequest, sendParameters); }
public void SendOperation(OperationRequest request) { Interlocked.Increment(ref eventsReceivedSent); PeerHelper.InvokeOnOperationRequest(this.peer, request, new SendParameters()); }
public void Disconnect() { PeerHelper.SimulateDisconnect(this.peer); }
public void JoinAndJoin() { var peerOne = new DummyPeer { SessionId = "#1" }; var peerTwo = new DummyPeer { SessionId = "#2" }; var peerLobby = new DummyPeer { SessionId = "#L" }; var litePeerOne = new LiteLobbyPeer(peerOne.Protocol, peerOne); var litePeerTwo = new LiteLobbyPeer(peerTwo.Protocol, peerTwo); var litePeerLobby = new LiteLobbyPeer(peerLobby.Protocol, peerLobby); try { // peer lobby: join OperationRequest request = GetJoinLobbyRequest(); PeerHelper.InvokeOnOperationRequest(litePeerLobby, request, new SendParameters()); Assert.IsTrue(peerLobby.WaitForNextResponse(WaitTimeout)); List <OperationResponse> responseList = peerLobby.GetResponseList(); Assert.AreEqual(1, responseList.Count); // peer lobby: receive lobby games Assert.IsTrue(peerLobby.WaitForNextEvent(WaitTimeout)); List <EventData> eventList = peerLobby.GetEventList(); Assert.AreEqual(1, eventList.Count); EventData eventData = eventList[0]; Assert.AreEqual((byte)LiteLobbyEventCode.GameList, eventData.Code); // peer 1: join request = GetJoinRequest(); PeerHelper.InvokeOnOperationRequest(litePeerOne, request, new SendParameters()); Assert.IsTrue(peerOne.WaitForNextResponse(WaitTimeout)); responseList = peerOne.GetResponseList(); Assert.AreEqual(1, responseList.Count); OperationResponse response = responseList[0]; Assert.AreEqual(1, response.Parameters[(byte)ParameterKey.ActorNr]); // peer 1: receive own join event Assert.IsTrue(peerOne.WaitForNextEvent(WaitTimeout)); eventList = peerOne.GetEventList(); Assert.AreEqual(1, eventList.Count); eventData = eventList[0]; Assert.AreEqual(LiteOpCode.Join, eventData.Code); Assert.AreEqual(1, eventData.Parameters[(byte)ParameterKey.ActorNr]); // peer lobby: wait for lobby update (all 2 sec) Assert.IsTrue(peerLobby.WaitForNextEvent(2000 + WaitTimeout)); eventList = peerLobby.GetEventList(); Assert.AreEqual(1, eventList.Count); eventData = eventList[0]; var games = (Hashtable)eventData.Parameters[(byte)ParameterKey.Data]; Assert.AreEqual(1, games.Count); Assert.AreEqual("1", games["testGame"]); // peer 2: join request = GetJoinRequest(); PeerHelper.InvokeOnOperationRequest(litePeerTwo, request, new SendParameters()); Assert.IsTrue(peerTwo.WaitForNextResponse(WaitTimeout)); responseList = peerTwo.GetResponseList(); Assert.AreEqual(1, responseList.Count); response = responseList[0]; Assert.AreEqual(2, response.Parameters[(byte)ParameterKey.ActorNr]); // peer 2: receive own join event Assert.IsTrue(peerTwo.WaitForNextEvent(WaitTimeout)); eventList = peerTwo.GetEventList(); Assert.AreEqual(1, eventList.Count); eventData = eventList[0]; Assert.AreEqual(LiteOpCode.Join, eventData.Code); Assert.AreEqual(2, eventData.Parameters[(byte)ParameterKey.ActorNr]); // peer 1: receive join event of peer 2 Assert.IsTrue(peerOne.WaitForNextEvent(WaitTimeout)); eventList = peerOne.GetEventList(); Assert.AreEqual(1, eventList.Count); eventData = eventList[0]; Assert.AreEqual(LiteOpCode.Join, eventData.Code); Assert.AreEqual(2, eventData.Parameters[(byte)ParameterKey.ActorNr]); // peer lobby: wait for lobby update (all 2 sec) Assert.IsTrue(peerLobby.WaitForNextEvent(2000 + WaitTimeout)); eventList = peerLobby.GetEventList(); Assert.AreEqual(1, eventList.Count); eventData = eventList[0]; games = (Hashtable)eventData.Parameters[(byte)ParameterKey.Data]; Assert.AreEqual(1, games.Count); Assert.AreEqual("2", games["testGame"]); // peer 2: join again request = GetJoinRequest(); PeerHelper.InvokeOnOperationRequest(litePeerTwo, request, new SendParameters()); Assert.IsTrue(peerTwo.WaitForNextResponse(WaitTimeout)); responseList = peerTwo.GetResponseList(); Assert.AreEqual(1, responseList.Count); // peer 2: do not receive own leave event, receive own join event Assert.IsTrue(peerTwo.WaitForNextEvent(WaitTimeout)); eventList = peerTwo.GetEventList(); Assert.AreEqual(1, eventList.Count); eventData = eventList[0]; Assert.AreEqual(LiteOpCode.Join, eventData.Code); Assert.AreEqual(3, eventData.Parameters[(byte)ParameterKey.ActorNr]); // peer 1: receive leave and event of peer 2 Assert.IsTrue(peerOne.WaitForNextEvent(WaitTimeout)); eventList = peerOne.GetEventList(); Assert.GreaterOrEqual(eventList.Count, 1); eventData = eventList[0]; Assert.AreEqual(LiteOpCode.Leave, eventData.Code); Assert.AreEqual(2, eventData.Parameters[(byte)ParameterKey.ActorNr]); if (eventList.Count == 1) { // waiting for join event Assert.IsTrue(peerOne.WaitForNextEvent(WaitTimeout)); eventList = peerOne.GetEventList(); Assert.AreEqual(1, eventList.Count); eventData = eventList[0]; } else { eventData = eventList[1]; } Assert.AreEqual(LiteOpCode.Join, eventData.Code); Assert.AreEqual(3, eventData.Parameters[(byte)ParameterKey.ActorNr]); // peer lobby: wait for lobby update (all 2 sec) Assert.IsTrue(peerLobby.WaitForNextEvent(2000 + WaitTimeout)); eventList = peerLobby.GetEventList(); Assert.AreEqual(1, eventList.Count); eventData = eventList[0]; games = (Hashtable)eventData.Parameters[(byte)ParameterKey.Data]; Assert.AreEqual(1, games.Count); Assert.AreEqual("2", games["testGame"]); } finally { PeerHelper.SimulateDisconnect(litePeerOne); PeerHelper.SimulateDisconnect(litePeerTwo); PeerHelper.SimulateDisconnect(litePeerLobby); } }