Пример #1
0
        /// <summary> Unfreezes this player. Throws PlayerOpException on problems. </summary>
        /// <param name="player"> Player who is doing the unfreezing. </param>
        /// <param name="options"> Unfreezing options. See <see cref="fCraft.FreezeOptions"/>. </param>
        public void Unfreeze([NotNull] Player player, FreezeOptions options) {
            if (player == null) throw new ArgumentNullException("player");

            bool announce = (options & FreezeOptions.Announce) != 0;
            bool raiseEvents = (options & FreezeOptions.RaiseEvents) != 0;

            // Check if player is trying to freeze self
            if (player.Info == this) {
                PlayerOpException.ThrowCannotTargetSelf(player, this, "unfreeze");
            }

            lock (actionLock) {
                // Check if player can freeze in general
                if (!player.Can(Permission.Freeze)) {
                    PlayerOpException.ThrowPermissionMissing(player, this, "unfreeze", Permission.Freeze);
                }

                // Check if target is already frozen
                if (!IsFrozen) {
                    string msg = String.Format("Player {0} is not currently frozen.", Name);
                    string colorMsg = String.Format("&SPlayer {0}&S is not currently frozen.", ClassyName);
                    throw new PlayerOpException(player, this, PlayerOpExceptionCode.NoActionNeeded, msg, colorMsg);
                }

                // Check if player has sufficient rank permissions
                if (!player.Can(Permission.Freeze, Rank)) {
                    PlayerOpException.ThrowPermissionLimit(player, this, "unfreeze", Permission.Freeze);
                }

                // Raise PlayerInfo.FreezeChanging event
                if (raiseEvents && RaiseFreezeChangingEvent(this, player, true, announce)) {
                    PlayerOpException.ThrowCancelled(player, this);
                }

                // Actually unfreeze
                Unfreeze();

                // Log and announce unfreeze
                Logger.Log(LogType.UserActivity,
                           "{0} unfroze {1}",
                           player.Name,
                           Name);
                if (announce) {
                    Player target = PlayerObject;
                    if (target != null) {
                        target.Message("&WYou were unfrozen by {0}", player.ClassyName);
                    }
                    Server.Message(target,
                                   "&SPlayer {0}&S was unfrozen by {1}",
                                   ClassyName,
                                   player.ClassyName);
                }

                // Raise PlayerInfo.FreezeChanged event
                if (raiseEvents) RaiseFreezeChangedEvent(this, player, true, announce);
            }
        }
Пример #2
0
        /// <summary> Freezes this player (prevents from moving, building, and from using most commands).
        /// Throws PlayerOpException on problems. </summary>
        /// <param name="player"> Player who is doing the freezing. </param>
        /// <param name="options"> Freezing options. See <see cref="fCraft.FreezeOptions"/>. </param>
        public void Freeze([NotNull] Player player, FreezeOptions options) {
            if (player == null) throw new ArgumentNullException("player");

            bool announce = (options & FreezeOptions.Announce) != 0;
            bool raiseEvents = (options & FreezeOptions.RaiseEvents) != 0;

            // Check if player is trying to freeze self
            if (player.Info == this) {
                PlayerOpException.ThrowCannotTargetSelf(player, this, "freeze");
            }

            lock (actionLock) {
                // Check if player can freeze in general
                if (!player.Can(Permission.Freeze)) {
                    PlayerOpException.ThrowPermissionMissing(player, this, "freeze", Permission.Freeze);
                }

                // Check if player has sufficient rank permissions
                if (!player.Can(Permission.Freeze, Rank)) {
                    PlayerOpException.ThrowPermissionLimit(player, this, "freeze", Permission.Freeze);
                }

                // Check if target is already frozen
                if (IsFrozen) {
                    string msg = String.Format("Player {0} is already frozen (by {1}).", Name, FrozenBy);
                    string colorMsg = String.Format("&SPlayer {0}&S is already frozen (by {1}&S).",
                                                    ClassyName,
                                                    FrozenByClassy);
                    throw new PlayerOpException(player, this, PlayerOpExceptionCode.NoActionNeeded, msg, colorMsg);
                }

                // Raise PlayerInfo.FreezeChanging event
                if (raiseEvents && RaiseFreezeChangingEvent(this, player, false, announce)) {
                    PlayerOpException.ThrowCancelled(player, this);
                }

                // Actually freeze
                IsFrozen = true;
                IsHidden = false;
                FrozenOn = DateTime.UtcNow;
                FrozenBy = player.Name;
                LastModified = DateTime.UtcNow;

                // Apply side effects
                Player target = PlayerObject;
                if (target != null) {
                    target.IsDeaf = false;
                    target.StopSpectating();
                }

                // Log and announce
                Logger.Log(LogType.UserActivity,
                           "{0} froze {1}",
                           player.Name,
                           Name);
                if (announce) {
                    if (target != null) {
                        target.Message("&WYou were frozen by {0}", player.ClassyName);
                    }
                    Server.Message(target,
                                   "&SPlayer {0}&S was frozen by {1}",
                                   ClassyName,
                                   player.ClassyName);
                }

                // Raise PlayerInfo.FreezeChanged event
                if (raiseEvents) RaiseFreezeChangedEvent(this, player, false, announce);
            }
        }