/// <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
        public static void SendScopeExitedMessage <TPeer>(BaseServerScope <TPeer> scope, NetworkConnection connection) where TPeer : NetworkPeer
        {
            NetworkWriter writer = new NetworkWriter();

            writer.StartMessage(ScopeMsgType.ExitScope);

            // 1. msgType: Determines which channel to communicate on
            writer.Write(scope.msgType);

            writer.FinishMessage();

            SendNetworkWriter(writer, connection);
        }
示例#3
0
        public static void SendScopeEnteredMessage <TPeer>(BaseServerScope <TPeer> scope, NetworkConnection connection) where TPeer : NetworkPeer
        {
            NetworkWriter writer = new NetworkWriter();

            writer.StartMessage(ScopeMsgType.EnterScope);

            // 1. scopeIdentifier: The value which identifier the counterpart client class
            writer.Write(scope.msgType);

            // 2. msgType: Determines which channel to communicate on
            writer.Write(scope.scopeIdentifier);

            writer.FinishMessage();

            SendNetworkWriter(writer, connection);
        }
示例#4
0
        public static void SendScopeSwitchedMessage <TPeer>(BaseServerScope <TPeer> prevScope, BaseServerScope <TPeer> newScope, NetworkConnection connection) where TPeer : NetworkPeer
        {
            NetworkWriter writer = new NetworkWriter();

            writer.StartMessage(ScopeMsgType.SwitchScope);

            // 1. msgType: Send prev scope channel
            writer.Write(prevScope.msgType);

            // 2. msgType: Send new scope channel
            writer.Write(newScope.msgType);

            // 2. scopeIdentifier: The value which identifier the counterpart (new) client scope
            writer.Write(newScope.scopeIdentifier);

            writer.FinishMessage();

            SendNetworkWriter(writer, connection);
        }
        public void UnregisterScope(BaseServerScope <TPeer> scope)
        {
            // don't allow unregistering default scope
            if (defaultScope == scope)
            {
                throw new Exception("Failed to unregister Scope because it is the default Scope");
            }

            // remove from registered scopes
            if (registeredScopes.Remove(scope))
            {
                // make sure to clean-up before letting go of this scope
                scope.Dispose();
            }
            else
            {
                Debug.LogWarningFormat("Failed to remove the Scope {0} because it was not registered with the MasterServer.", scope.GetType());
            }
        }
        public TServerScope RegisterScope <TServerScope>(byte scopeIdentifier, bool setAsDefault) where TServerScope : BaseServerScope <TPeer>, new()
        {
            TServerScope scope = new TServerScope();

            scope.SetAutomaticMsgType(scopeIdentifier, msgTypeGenerator);

            // initialize the scope with the MasterServer instance
            scope.Initialize(this);

            registeredScopes.Add(scope);

            // set as default scope for newly connected players if specified
            if (setAsDefault)
            {
                defaultScope = scope;
            }

            return(scope);
        }