fCraft.Player.Kick C# (CSharp) Method

Kick() public method

Kick (asynchronous). Immediately blocks all client input, but waits until client thread has sent the kick packet.
public Kick ( [ message, LeaveReason leaveReason ) : void
message [
leaveReason LeaveReason
return void
        public void Kick( [NotNull] string message, LeaveReason leaveReason )
        {
            if ( message == null )
                throw new ArgumentNullException( "message" );
            if ( !Enum.IsDefined( typeof( LeaveReason ), leaveReason ) ) {
                throw new ArgumentOutOfRangeException( "leaveReason" );
            }
            State = SessionState.PendingDisconnect;
            LeaveReason = leaveReason;

            canReceive = false;
            canQueue = false;

            // clear all pending output to be written to client (it won't matter after the kick)
            ClearLowPriotityOutputQueue();
            ClearPriorityOutputQueue();

            // bypassing Send() because canQueue is false
            priorityOutputQueue.Enqueue( PacketWriter.MakeDisconnect( message ) );
        }

Usage Example

Example #1
0
        public Map AcceptPlayer([NotNull] Player player, bool announce)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }

            lock ( SyncRoot ) {
                if (IsFull)
                {
                    if (player.Info.Rank.ReservedSlot)
                    {
                        Player idlestPlayer = Players.Where(p => p.Info.Rank.IdleKickTimer != 0)
                                              .OrderBy(p => p.LastActiveTime)
                                              .FirstOrDefault();
                        if (idlestPlayer != null)
                        {
                            idlestPlayer.Kick(Player.Console, "Auto-kicked to make room (idle).",
                                              LeaveReason.IdleKick, false, false, false);
                            Server.Message("Player {0}&S was auto-kicked to make room for {1}",
                                           idlestPlayer.ClassyName, player.ClassyName);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }

                if (playerIndex.ContainsKey(player.Name.ToLower()))
                {
                    Logger.Log(LogType.Error,
                               "This world already contains the player by name ({0}). " +
                               "Some sort of state corruption must have occured.",
                               player.Name);
                    playerIndex.Remove(player.Name.ToLower());
                }

                playerIndex.Add(player.Name.ToLower(), player);

                // load the map, if it's not yet loaded
                IsPendingMapUnload = false;
                Map = LoadMap();

                if (ConfigKey.BackupOnJoin.Enabled() && (Map.HasChangedSinceBackup || !ConfigKey.BackupOnlyWhenChanged.Enabled()))
                {
                    string backupFileName = String.Format(JoinBackupFormat,
                                                          Name, DateTime.Now, player.Name);   // localized
                    Map.SaveBackup(MapFileName,
                                   Path.Combine(Paths.BackupPath, backupFileName));
                }

                UpdatePlayerList();

                if (announce && ConfigKey.ShowJoinedWorldMessages.Enabled())
                {
                    Server.Players.CanSee(player)
                    .Message("&SPlayer {0}&S joined {1}",
                             player.ClassyName, ClassyName);
                }

                Logger.Log(LogType.UserActivity,
                           "Player {0} joined world {1}.",
                           player.Name, Name);

                if (IsLocked)
                {
                    player.Message("&WThis map is currently locked (read-only).");
                }

                if (player.Info.IsHidden)
                {
                    player.Message("&8Reminder: You are still hidden.");
                }

                return(Map);
            }
        }
All Usage Examples Of fCraft.Player::Kick