コード例 #1
0
ファイル: ServerLobby.cs プロジェクト: BigETI/TetriEngine
        /// <summary>
        /// Disconnect user
        /// </summary>
        /// <param name="user">User</param>
        /// <param name="disconnectReason">Disconnect reason</param>
        /// <returns>"true" if disconnected, otherwise "false"</returns>
        public bool DisconnectUser(IUser user, EDisconnectReason disconnectReason)
        {
            bool ret = false;

            if (user != null)
            {
                lock (users)
                {
                    if (IsRealUser(user))
                    {
                        IUser real_user = GetRealUser(user);
                        if (real_user != null)
                        {
                            if (real_user is ServerUser)
                            {
                                ServerUser server_user = (ServerUser)real_user;
                                ret = (disconnectReason == (EDisconnectReason.Banned) ? Bans.AddPattern(Regex.Escape(server_user.ServerConnection.IPAddress.ToString())) : true);
                                serverListener.Disconnect(server_user.ServerConnection);
                            }
                            else if (real_user is BotUser)
                            {
                                ret = true;
                            }
                            if (ret)
                            {
                                users.Remove(real_user.ID);
                                switch (disconnectReason)
                                {
                                case EDisconnectReason.Left:
                                    OnUserLeft?.Invoke(real_user);
                                    break;

                                case EDisconnectReason.Kicked:
                                    OnUserKicked?.Invoke(real_user);
                                    break;

                                case EDisconnectReason.Banned:
                                    OnUserBanned?.Invoke(real_user);
                                    break;

                                case EDisconnectReason.TimedOut:
                                    OnUserTimedOut?.Invoke(real_user);
                                    break;
                                }
                                foreach (IUser u in users)
                                {
                                    ServerUser server_user = u as ServerUser;
                                    if (server_user != null)
                                    {
                                        server_user.ServerConnection.SendUserLeftMessageAsync(real_user);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(ret);
        }
コード例 #2
0
 private void PublishUserTimedoutEvent(UserTimedoutEvent e) => OnUserTimedOut?.Invoke(e);