コード例 #1
0
        /// <summary>
        /// Removes the Peer from this Scope and adds them to the specified targetScope.
        /// </summary>
        /// <param name="peer">The Peer.</param>
        /// <param name="targetScope">The Scope to handover the Peer to.</param>
        public void HandoverPeer(TPeer peer, BaseServerScope <TPeer> targetScope)
        {
            // tell the peer about this handover
            ScopeUtils.SendScopeSwitchedMessage(this, targetScope, peer);

            // remove peer from this scope
            RemovePeer(peer, false);

            // add peer to target scope
            targetScope.AddPeer(peer, false);
        }
コード例 #2
0
        /// <summary>
        /// Forces the Peer to disconnect, raising the OnDisconnect event in the process.
        /// This method is also called when a peer disconnects or loses connection normally.
        /// </summary>
        public void DisconnectWithMessage(byte disconnectMsgIdentifier)
        {
            NetworkWriter writer = new NetworkWriter();

            writer.StartMessage(ScopeMsgType.DisconnectMessage);
            writer.Write(disconnectMsgIdentifier);
            writer.FinishMessage();

            ScopeUtils.SendNetworkWriter(writer, this);

            // trigger early disconnection
            ForceDisconnect(false);
        }
コード例 #3
0
        /// <summary>
        /// Sends instructions to reconnect to the specified host.
        /// </summary>
        /// <param name="hostname">IP Address or Host.</param>
        /// <param name="port">Server port.</param>
        public void Redirect(string hostname, int port)
        {
            NetworkWriter writer = new NetworkWriter();

            writer.StartMessage(ScopeMsgType.RedirectMessage);
            writer.Write(hostname);
            writer.Write(port);
            writer.FinishMessage();

            ScopeUtils.SendNetworkWriter(writer, this);

            // trigger early disconnection
            ForceDisconnect(false);
        }
コード例 #4
0
        /// <summary>
        /// Adds the Peer to the Scope, allowing Signal communication with the Client.
        /// NOTE: Sends an EnterScope message to the Peer.
        /// </summary>
        /// <param name="peer">The target Peer.</param>
        public void AddPeer(TPeer peer, bool sendEnterMsg)
        {
//			UnityEngine.Debug.LogFormat("<color=cyan>ADDING {0}</color> to {1}", peer, GetType().Name);
            Peers.Add(peer);

            // register for disconnection to clean up after this peer
            peer.OnDisconnect += OnPeerDisconnected;

            if (sendEnterMsg)
            {
                ScopeUtils.SendScopeEnteredMessage(this, peer);
            }

            // notify derived class that the peer has entered the scope and is able to receive Signals from the client
            OnPeerEnteredScope(peer);
        }
コード例 #5
0
        void INetworkSender.PrepareAndSendWriter(NetworkWriter writer)
        {
            writer.FinishMessage();

                        #if UNITY_EDITOR && SCOPE_DEBUGGING
            // log outgoing signal
            ScopeDebugger.AddOutgoingSignal(this, typeof(TClientScope), new NetworkReader(writer));
                        #endif

            if (!IsTargetGroup)
            {
                ScopeUtils.SendNetworkWriter(writer, TargetPeer);
            }
            else
            {
                ScopeUtils.SendNetworkWriter(writer, TargetPeerGroup);
            }
        }
コード例 #6
0
        public void RemovePeer(TPeer peer, bool sendExitMsg)
        {
            // we don't care about d/c events from this peer anymore
            peer.OnDisconnect -= OnPeerDisconnected;

            // attempt to remove the peer associated with the peer's connection
            if (Peers.Remove(peer))
            {
                if (sendExitMsg && peer.isConnected)
                {
                    ScopeUtils.SendScopeExitedMessage(this, peer);
                }

                // notify derived class that the peer has exited the scope and can no longer receive Signals from the client
                OnPeerExitedScope(peer);
            }
            else
            {
                Debug.LogFormat("Failed to remove non-existent peer {0} from scope {1}", peer.ToString(), GetType().Name);
            }
        }