ValidateKickReason() static private méthode

Validates that a given kick reason is acceptable for a remote kick.
static private ValidateKickReason ( NetCloseReason reason ) : NetCloseReason
reason NetCloseReason
Résultat NetCloseReason
Exemple #1
0
        /// <summary>
        /// Notifies a peer that we are disconnecting. May not arrive.
        /// </summary>
        internal SocketError SendKick(NetPeer peer, NetCloseReason reason, byte userReason = 0)
        {
            // Skip the packet if it's a bad reason (this will cause error output)
            if (NetUtil.ValidateKickReason(reason) == NetCloseReason.INVALID)
            {
                return(SocketError.Success);
            }

            lock (sendLock)
            {
                var length = NetEncoding.PackProtocol(sendBuffer, NetPacketType.Kick, (byte)reason, userReason);
                return(TrySend(peer.EndPoint, sendBuffer, length));
            }
        }
Exemple #2
0
        /// <summary>
        /// Sends a kick (reject) message to an unconnected peer.
        /// </summary>
        internal SocketError SendReject(
            IPEndPoint destination,
            NetCloseReason reason)
        {
            // Skip the packet if it's a bad reason (this will cause error output)
            if (NetUtil.ValidateKickReason(reason) == NetCloseReason.INVALID)
            {
                return(SocketError.Success);
            }

            lock (this.sendLock)
            {
                int length =
                    NetEncoding.PackProtocol(
                        this.sendBuffer,
                        NetPacketType.Kick,
                        (byte)reason,
                        0);
                return(this.TrySend(destination, this.sendBuffer, length));
            }
        }
Exemple #3
0
        private void HandleKick(
            NetPeer peer,
            byte[] buffer,
            int length)
        {
            if (peer.IsClosed)
            {
                return;
            }

            byte rawReason;
            byte userReason;
            bool success =
                NetEncoding.ReadProtocol(
                    buffer,
                    length,
                    out rawReason,
                    out userReason);

            // Validate
            if (success == false)
            {
                NetDebug.LogError("Error reading kick");
                return;
            }

            NetCloseReason closeReason = (NetCloseReason)rawReason;

            // Skip the packet if it's a bad reason (this will cause error output)
            if (NetUtil.ValidateKickReason(closeReason) == NetCloseReason.INVALID)
            {
                return;
            }

            peer.OnReceiveOther(this.Time);
            this.ClosePeerSilent(peer);
            this.eventOut.Enqueue(
                this.CreateClosedEvent(peer, closeReason, userReason));
        }